Beispiel #1
0
int main(int argc, char **argv)
{
	int l = 0, v = 0, a = 0;
	int j;
	for (j = 0; j < argc; j++)
	{
		if (strcmp(argv[j], "-l") == 0)
			l = 1;
		if (strcmp(argv[j], "-a") == 0)
			a = 1;
		if (strcmp(argv[j], "-v") == 0)
			v = 1;
	}
	
	int error_found = 0;
	
	initialize_la();
	
	error_found = program();
	if (error_found == 1)
	{
        int z = 0;
        for( z = 0; z < errorI ;z++){
             printf("%s", errorList[errors[errorI]]);
             }   
		return 0;
	}
	printf("No errors, program is syntactically correct\n\n");
	
	initialize_stack();
	
	if (l == 1)
		print_token_table();
	if (a == 1)
		print_list();
	if (v == 1)
		print_stack_list();
		
	print_token_table();
	print_list();
	print_stack_list();
	
	return 0;
}
static process_content(FILE *f, FILE *output, FILE* outputHeader)
{
  char token[MAX_START_NAME+1]; /* Must be big enough to hold a 
                                   tag/attr start string */
  char name[MAX_NAME+1];
  char optional[MAX_LINE+1];
  char *tag_code_page = "";
  char *attr_code_page = "";
  char processing_tag = 2;  /* processing state: 1 = tag, 0 = attribute, 2 = init */
  int n = 0;
  int use_strings = 1;

  for(;;) {

    if ((get_tuple(f, token, name, optional)) != 1) {
      break;
    }

    if (!strcmp(token, TAG_TABLE_HEADING)) {
      use_strings = strcmp(optional, NO_STRINGS);
      if (processing_tag == 1) {
        /* Process the current tag table */
        print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings);
        print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings);
        cache_codepage(tag_codepages, tag_code_page, n);
        n = 0;
      } else if (processing_tag == 0) {
        /* Process the current attribute table */
        print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings);
        print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings);
        cache_codepage(attr_codepages, attr_code_page, n);
        n = 0;
      }
      tag_code_page = strdup(name);
      processing_tag = 1;
    }
    else if (!strcmp(token, ATTR_TABLE_HEADING)) {
      use_strings = strcmp(optional, NO_STRINGS);
      if (processing_tag == 1) {
        /* Process the current tag table */
        print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings);
        print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings);
        cache_codepage(tag_codepages, tag_code_page, n);
        n = 0;
      } else if (processing_tag == 0) {
        /* Process the current attribute table */
        print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings);
        print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings);
        cache_codepage(attr_codepages, attr_code_page, n);
        n = 0;
      }
      attr_code_page = strdup(name);
      processing_tag = 0;
    } else {
      process_entry(n, token, name);
      n++;
    }
  }

  if (processing_tag == 2) {
    fprintf(stderr, 
            "ERROR: Could not find tag or attribute table starts in file.\n"
            "       Input file syntax has changed.\n"
            "       See usage by executing this program with no arguments.\n");
    exit_error(1);
  }

  /*
   * If anything is left, process it
   */
  if (n > 0) {
    if (processing_tag == 1) {
      print_token_table(output, outputHeader, TAG_NAME, "token", tag_code_page, n, use_strings);
      print_name_table(output, TAG_NAME, "name", tag_code_page, n, use_strings);
      cache_codepage(tag_codepages, tag_code_page, n);
    } else if (processing_tag == 0) {
      print_token_table(output, outputHeader, ATTR_NAME, "token", attr_code_page, n, use_strings);
      print_name_table(output, ATTR_NAME, "name", attr_code_page, n, use_strings);
      cache_codepage(attr_codepages, attr_code_page, n);
    }
  }
}