stage1_2/stage1_2.cc
changeset 136 32bd7ef40897
parent 86 1988bf1634da
child 139 668a54686827
equal deleted inserted replaced
135:0f3f6714b938 136:32bd7ef40897
   176   if (!res)
   176   if (!res)
   177     return NULL;
   177     return NULL;
   178   return strcat(strcat(strcpy(res, a), b), c);  /* safe, actually */
   178   return strcat(strcat(strcpy(res, a), b), c);  /* safe, actually */
   179 }
   179 }
   180 
   180 
   181 
   181 /*************************/
   182 
   182 /* Tracking Functions... */
   183 
   183 /*************************/
   184 
   184 
   185 
   185 extern tracking_t* current_tracking;
   186 /***********************************************************************/
   186 
   187 /***********************************************************************/
   187 /*--------------------------------------------------------------------
   188 /***********************************************************************/
   188  * GetNextChar
   189 /***********************************************************************/
   189  * 
   190 /***********************************************************************/
   190  * reads a character from input for flex
   191 /***********************************************************************/
   191  *------------------------------------------------------------------*/
   192 /***********************************************************************/
   192 int GetNextChar(char *b, int maxBuffer) {
   193 /***********************************************************************/
   193   char *p;
   194 /***********************************************************************/
   194   
   195 /***********************************************************************/
   195   if (  current_tracking->eof  )
   196 
   196     return 0;
   197 
   197   
   198 int stage1_2__(const char *filename, const char *includedir, symbol_c **tree_root_ref);
   198   while (  current_tracking->currentChar >= current_tracking->lineLength  ) {
   199 
   199     current_tracking->currentChar = 0;
   200 
   200     current_tracking->currentTokenStart = 1;
   201 int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root_ref) {
   201     current_tracking->eof = false;
   202   return stage1_2__(filename, includedir, tree_root_ref);
   202     
   203 }
   203     p = fgets(current_tracking->buffer, MAX_BUFFER_LENGTH, current_tracking->in_file);
   204 
   204     if (  p == NULL  ) {
       
   205       if (  ferror(current_tracking->in_file)  )
       
   206         return 0;
       
   207       current_tracking->eof = true;
       
   208       return 0;
       
   209     }
       
   210     
       
   211     current_tracking->lineNumber++;
       
   212     current_tracking->lineLength = strlen(current_tracking->buffer);
       
   213   }
       
   214   
       
   215   b[0] = current_tracking->buffer[current_tracking->currentChar];
       
   216   if (b[0] == ' ' || b[0] == '\t')
       
   217     current_tracking->currentTokenStart++;
       
   218   current_tracking->currentChar++;
       
   219 
       
   220   return b[0]==0?0:1;
       
   221 }
       
   222 
       
   223 tracking_t* GetNewTracking(FILE* in_file) {
       
   224   tracking_t* new_env = new tracking_t;
       
   225   new_env->eof = 0;
       
   226   new_env->lineNumber = 0;
       
   227   new_env->currentChar = 0;
       
   228   new_env->lineLength = 0;
       
   229   new_env->currentTokenStart = 0;
       
   230   new_env->buffer = (char*)malloc(MAX_BUFFER_LENGTH);
       
   231   new_env->in_file = in_file;
       
   232   return new_env;
       
   233 }
       
   234 
       
   235 /***********************************************************************/
       
   236 /***********************************************************************/
       
   237 /***********************************************************************/
       
   238 /***********************************************************************/
       
   239 /***********************************************************************/
       
   240 /***********************************************************************/
       
   241 /***********************************************************************/
       
   242 /***********************************************************************/
       
   243 /***********************************************************************/
       
   244 /***********************************************************************/
       
   245 
       
   246 
       
   247 int stage1_2__(const char *filename, const char *includedir, symbol_c **tree_root_ref, bool full);
       
   248 
       
   249 
       
   250 int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root_ref, bool full) {
       
   251   return stage1_2__(filename, includedir, tree_root_ref, full);
       
   252 }
       
   253