/* Appends S to the stream of data items whose format G is guessing. */ void fmt_guesser_add (struct fmt_guesser *g, struct substring s) { if (ss_length (s) > g->width) g->width = ss_length (s); ss_trim (&s, ss_cstr (CC_SPACES)); if (ss_is_empty (s) || ss_equals (s, ss_cstr ("."))) { /* Can't guess anything from an empty string or a missing value. */ return; } g->count++; if (!add_numeric (g, s)) add_date_time (g, s); }
/* Actually load the configuration file. * You will almost certainly want to replace this with something better. */ static int load_config(void) { FILE *fd = NULL; char buffer[256]; char *extname = NULL; char *threadname = NULL; char *directive = NULL; char *check = NULL; int matches = 0; /* Belt and braces - if already loaded, don't re-load */ if( cfg_loaded ) return cfg_loaded; /* Find out where we load from */ char const *filename = get_config_filename(); if ( !filename ) return 0; LOG("Load Config from %s", filename); /* Try and open that file */ fd = fopen(filename, "r"); if( !fd ) { LOG_E("Opening file \"%s\" failed (error %d: %s)", filename, errno, strerror(errno)); return -errno; } /* Loop over the file */ while( !feof(fd) ) { check = fgets(buffer, 255, fd); /* Check nothing went wrong */ if( ferror(fd) || (!check && !feof(fd)) ) LOG_E("Reading file \"%s\" failed: %d %s", filename, errno, strerror(errno)); buffer[255] = '\0'; /* sscanf isn't particularly safe - a real application should use a better parser */ matches = sscanf(buffer, "%ms%ms%ms", &directive, &threadname, &extname); if( matches < 3 ) break; LOG("Read: %s %s %s", directive, threadname, extname); if( !strncasecmp("set", directive, 4) ) directive_set(threadname, atoi(extname)); else if( !strncasecmp("name", directive, 5) ) add_mapping(threadname, extname); else if( !strncasecmp("num", directive, 4) ) add_numeric(atoi(threadname), extname); else LOG_E("Invalid directive: %s", directive); free(directive); free(threadname); free(extname); } LOG("Load Complete"); fclose(fd); /* Debug print the loaded table */ dump_table(); return 1; }