示例#1
0
int main()
{
   char string[5120];

   while (!feof(stdin))
   {
      /* input entire line from stdin */
      scanf ("%s", string);
      if (feof(stdin)) continue;
      /* parse line into separate 'tokens' */
      /* pass each token to processing function */
      analyze_token (string);
   }

   return 0;
}
示例#2
0
command_stream_t
make_command_stream (int (*get_next_byte) (void *),
		     void *get_next_byte_argument)
{
  size_t size = 1000;
  char *buf = (char*) checked_malloc(size); 
  size_t i = 0;
  char c = get_next_byte(get_next_byte_argument);
  while(c != EOF)
  { 
     if(i >= size)
	checked_grow_alloc(buf, &size);
     buf[i]=c;
     c = get_next_byte(get_next_byte_argument);
     i += sizeof(char);
  }
  
  buf[i] = '\0';
  char* err_buf = checked_malloc(size);
  strcpy(err_buf, buf);
  //printf("%s\n", buf);
  // char delimiters  = 'a';
  char* token = strtok(buf, "\n"); 
  size = 1000;
  i = 0;
  // printf("here\n");
  command_stream_t result = checked_malloc(sizeof(command_stream_t));
  result->my_commands = checked_malloc(size);
  result->size = 0;
  result->next_pos = 0;

  while(token != NULL)
  {
    
     //printf("%s\n", token);
     if(analyze_token(token))
     {	
        //printf("%s\n", token);
  	result->my_commands[result->size] = process_buffer(token);
	//printf("Finished: %s\n", token);
	if(result->my_commands[result->size] == NULL)
	{}
	else if(result->my_commands[result->size]->status <= -2)
	{
	   // printf("BUF: %s\n", err_buf);
	   output_error(err_buf, token,
			result->my_commands[result->size]->status);
	}
	else
	{
	// print_command(result->my_commands[command_count]);
           result->size++;
        }
        token = strtok(NULL, "\n"); 
     //   printf("%s\n", token);
     }
     else
     {
       // printf("%s\n", token);
	char *temp = strtok(NULL, "\n");
	//printf("NEXT TOKEN: %s\n", temp);
	if(temp!=NULL)
	{
		strcat(token,temp);
        	printf("%s\n", token);
	}
	else
	   output_error(err_buf, token,0);
     }
  }


/*ONE COMMAND TESTING PURPOSES ONLY
  command_t e1 =  process_buffer(set_of_tokens[0]);
  if(e1==NULL)
  {
	printf("NULL command, comment");
	return result;
  }
  // printf("Word 1: %s %d\n", e1->u.word[2], strlen(e1->u.word[0]));
  print_command(e1);
  // while(e1->u.word[index] != NULL)
  result->my_commands[0] = e1;
*/
  return result;

}