Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields  

main.c

00001 /***************************************************************************
00002                           main.c
00003 
00004     Main program that creates and manipulates a Toy Memory Manager.
00005 
00006                              -------------------
00007     begin                : Sat Jan 25 2003
00008     copyright            : (C) 2003 by Tyler Montbriand
00009     student #            : 200200370
00010     class                : CS330
00011     email                : monttyle@heavyspace.ca
00012 ***************************************************************************/
00013 
00014 #ifdef HAVE_CONFIG_H
00015 #include <config.h>
00016 #endif
00017 
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include "ToyMem.h"
00026 
00027 extern const char *ErrMessages[];
00028 
00030 #define MEMORY_SIZE 1000
00031 
00040 int main(int argc, char *argv[])
00041 {
00042   ToyMM *tm=NULL;
00043   int memsize=MEMORY_SIZE;
00044 
00045   tm=TMM_Create(memsize);
00046   
00047   if(tm==NULL)
00048   {
00049     printf("Couldn't create ToyMM\n");
00050     return(1);
00051   }
00052 
00053   if(argc==1)
00054   {
00055     int running=1;
00056     int line=1;
00057     printf("[No input file specified - assuming commandline input]\n");
00058 
00059     while(running&&!feof(stdin))
00060     {
00061       ErrMessage_t errval=ERR_NONE;
00062       char ibuf[300];
00063       ibuf[0]='\0';     /* Mark buffer as empty */
00064 
00065       printf("%03d> ",line); /* Print console prompt */
00066 
00067       if(fgets(ibuf,299,stdin)==NULL) /* Read text from console */
00068       {
00069         printf("[Input error - unexpected EOF]\n");
00070         running=0;
00071         continue;
00072       }
00073       else if(strcmp(ibuf,"END\n")==0)
00074       {
00075         printf("[END found - normal termination]\n");
00076         running=0;
00077         continue;
00078       }
00079 
00080       errval=TMM_ParseLine(ibuf,tm,line++);
00081       if(errval==ERR_NONE)
00082       {
00083         printf("[OK]\n");
00084       }
00085       else if(errval==ERR_UNKNOWN)
00086       {
00087         printf("[Unknown error]\n");
00088       }
00089       else
00090       {
00091         printf("[ERROR: %s]\n",ErrMessages[errval]);
00092       }
00093 
00094     }
00095 
00096   }
00097   else if(argc==2) /*  Backwards compatibility - don't print filenames when
00098                   there's only one parameter                            */
00099   {
00100     if(TMM_ParseFile(argv[1],tm)<0)
00101       printf("---------------Couldn't parse %s-----------------\n",argv[1]);
00102   }
00103   else
00104   {
00105     int n;
00106     for(n=1; n<argc; n++)
00107     {
00108       printf("---------------Parsing %s------------------------\n",argv[n]);
00109 
00110       if(TMM_ParseFile(argv[n],tm)<0)
00111         printf("---------------Couldn't parse %s-----------------\n",argv[n]);
00112       else
00113         printf("---------------Parsed %s-------------------------\n",argv[n]);
00114     }
00115   }
00116 
00117   TMM_Free(tm);
00118 
00119   return EXIT_SUCCESS;
00120 }
00121 

Generated on Fri Apr 4 14:29:07 2003 for ToyMem by doxygen1.3-rc3