static psf_tag * process_tags( char * buffer ) { psf_tag * tags = NULL; char * line_end; if ( !buffer || !*buffer ) return NULL; line_end = strpbrk( buffer, "\n\r" ); while ( line_end ) { *line_end++ = '\0'; tags = process_tag_line( tags, buffer ); while ( *line_end && ( *line_end == '\n' || *line_end == '\r' ) ) line_end++; buffer = line_end; line_end = strpbrk( buffer, "\n\r" ); } if ( *buffer ) tags = process_tag_line( tags, buffer ); return tags; }
void read_args_file(const char *infile) { char *line; FILE *fp = fopen(infile,"r"); if(fp == NULL){ fprintf(GlobalState.logfile,"Cannot open %s for reading.\n",infile); exit(1); } else{ ArgType linetype = NO_ARGUMENT_MATCH; ArgType nexttype; while((line = read_line(fp)) != NULL){ if(blank_line(line)){ (void) free(line); continue; } nexttype = classify_arg(line); if(nexttype == NO_ARGUMENT_MATCH){ if(*line == argument_prefix[0]){ /* Treat the line as a source file name. */ add_filename_to_source_list(&line[1],NORMALFILE); } else if(linetype != NO_ARGUMENT_MATCH){ /* Handle the line. */ switch(linetype){ case MOVES_ARGUMENT: add_textual_variation_from_line(line); break; case POSITIONS_ARGUMENT: add_positional_variation_from_line(line); break; case TAGS_ARGUMENT: process_tag_line(infile,line); break; case TAG_ROSTER_ARGUMENT: process_roster_line(line); break; case ENDINGS_ARGUMENT: process_ending_line(line); (void) free(line); break; default: fprintf(GlobalState.logfile, "Internal error: unknown linetype %d in read_args_file\n", linetype); (void) free(line); exit(-1); } } else{ /* It should have been a line applying to the * current linetype. */ fprintf(GlobalState.logfile, "Missing argument type for line %s in the argument file.\n", line); exit(1); } } else{ switch(nexttype){ /* Arguments with a possible additional * argument value. * All of these apply only to the current * line in the argument file. */ case WRITE_TO_OUTPUT_FILE_ARGUMENT: case APPEND_TO_OUTPUT_FILE_ARGUMENT: case WRITE_TO_LOG_FILE_ARGUMENT: case APPEND_TO_LOG_FILE_ARGUMENT: case DUPLICATES_FILE_ARGUMENT: case USE_ECO_FILE_ARGUMENT: case CHECK_FILE_ARGUMENT: case FILE_OF_FILES_ARGUMENT: case BOUNDS_ARGUMENT: case GAMES_PER_FILE_ARGUMENT: case ECO_OUTPUT_LEVEL_ARGUMENT: case FILE_OF_ARGUMENTS_ARGUMENT: case NON_MATCHING_GAMES_ARGUMENT: case TAG_EXTRACTION_ARGUMENT: case LINE_WIDTH_ARGUMENT: case OUTPUT_FORMAT_ARGUMENT: process_argument(line[argument_prefix_len], &line[argument_prefix_len+1]); linetype = NO_ARGUMENT_MATCH; break; case LONG_FORM_ARGUMENT: { char *arg = &line[argument_prefix_len+1]; char *space = strchr(arg, ' '); if(space != NULL) { /* We need to drop an associated value from arg. */ int arglen = space - arg; char *just_arg = (char *) MallocOrDie(arglen + 1); strncpy(just_arg, arg, arglen); just_arg[arglen] = '\0'; process_long_form_argument(just_arg, skip_leading_spaces(space)); } else { process_long_form_argument(arg, ""); linetype = NO_ARGUMENT_MATCH; } } break; /* Arguments with no additional * argument value. * All of these apply only to the current * line in the argument file. */ case SEVEN_TAG_ROSTER_ARGUMENT: case HELP_ARGUMENT: case ALTERNATIVE_HELP_ARGUMENT: case DONT_KEEP_COMMENTS_ARGUMENT: case DONT_KEEP_DUPLICATES_ARGUMENT: case DONT_MATCH_PERMUTATIONS_ARGUMENT: case DONT_KEEP_NAGS_ARGUMENT: case OUTPUT_FEN_STRING_ARGUMENT: case CHECK_ONLY_ARGUMENT: case KEEP_SILENT_ARGUMENT: case USE_SOUNDEX_ARGUMENT: case MATCH_CHECKMATE_ARGUMENT: case SUPPRESS_ORIGINALS_ARGUMENT: case DONT_KEEP_VARIATIONS_ARGUMENT: case USE_VIRTUAL_HASH_TABLE_ARGUMENT: process_argument(line[argument_prefix_len],""); linetype = NO_ARGUMENT_MATCH; break; /* Arguments whose values persist beyond * the current line. */ case MOVES_ARGUMENT: case POSITIONS_ARGUMENT: case ENDINGS_ARGUMENT: case TAGS_ARGUMENT: case TAG_ROSTER_ARGUMENT: process_argument(line[argument_prefix_len], &line[argument_prefix_len+1]); /* Apply this type to subsequent lines. */ linetype = nexttype; break; default: linetype = nexttype; break; } (void) free(line); } } (void) fclose(fp); } }