struct genePred *genePredReaderNext(struct genePredReader* gpr) /* Read the next genePred, returning NULL if no more */ { if (gpr->lf != NULL) return fileNext(gpr); else return queryNext(gpr); }
struct psl *pslReaderNext(struct pslReader* pr) /* Read the next psl, returning NULL if no more */ { if (pr->lf != NULL) return fileNext(pr); else return queryNext(pr); }
static int getMapNames(char *nameBuffer) { // Look in the keymap directory for keymap files. int status = 0; file theFile; char *fileName = NULL; keyMap *map = NULL; int bufferChar = 0; int count; fileName = malloc(MAX_PATH_NAME_LENGTH); map = malloc(sizeof(keyMap)); if (!fileName || !map) return (status = ERR_MEMORY); nameBuffer[0] = '\0'; numMapNames = 0; // Loop through the files in the keymap directory for (count = 0; ; count ++) { if (count) status = fileNext(cwd, &theFile); else status = fileFirst(cwd, &theFile); if (status < 0) break; if (theFile.type != fileT) continue; if (strcmp(cwd, "/")) { snprintf(fileName, MAX_PATH_NAME_LENGTH, "%s/%s", cwd, theFile.name); } else { snprintf(fileName, MAX_PATH_NAME_LENGTH, "/%s", theFile.name); } status = readMap(fileName, map); if (status < 0) // Not a keymap file we can read. continue; strncpy((nameBuffer + bufferChar), map->name, sizeof(map->name)); bufferChar += (strlen(map->name) + 1); numMapNames += 1; } free(fileName); free(map); return (status = 0); }
static int findMapFile(const char *mapName, char *fileName) { // Look in the current directory for the keymap file with the supplied map // name int status = 0; file theFile; keyMap *map = NULL; int count; map = malloc(sizeof(keyMap)); if (!map) return (status = ERR_MEMORY); memset(&theFile, 0, sizeof(file)); // Loop through the files in the keymap directory for (count = 0; ; count ++) { if (count) status = fileNext(cwd, &theFile); else status = fileFirst(cwd, &theFile); if (status < 0) // No more files. break; if (theFile.type != fileT) continue; if (strcmp(cwd, "/")) snprintf(fileName, MAX_PATH_NAME_LENGTH, "%s/%s", cwd, theFile.name); else snprintf(fileName, MAX_PATH_NAME_LENGTH, "/%s", theFile.name); status = readMap(fileName, map); if (status < 0) continue; if (!strncmp(map->name, mapName, sizeof(map->name))) { status = 0; goto out; } } // If we fall through to here, it wasn't found. fileName[0] = '\0'; status = ERR_NOSUCHENTRY; out: free(map); return (status); }
void loadconfig() { // Clear the feeds list frist clear_feedlist(); FileParser* f; char* config_path = g_strconcat(USER_DIR,"config",NULL); if (config_path) { f = fileOpen(config_path); if (f) { while(fileNext(f)) { if (!strcmp("browser",fileGetKey(f))) set_browser(fileGetVal(f)); else if (!strcmp("update_interval",fileGetKey(f))) UPDATE_INTERVAL = atoi(fileGetVal(f)); else if (!strcmp("max_articles",fileGetKey(f))) MAX_ARTICLES = atoi(fileGetVal(f)); else if (!strcmp("feed",fileGetKey(f))) { char *name = fileEatNextVal(f); char *url = fileEatNextVal(f); if (url) { add_feed(name,url); } } } fileClose(f); } else { fprintf(stderr,"feedreader: Couldn't load config file at \"%s\".\n", config_path); FILE *out_file = fopen(config_path, "w+"); if (out_file) { fprintf(out_file, "# settings\n"); fprintf(out_file, "browser=%s\n", BROWSER); fprintf(out_file, "update_interval=%u\n", UPDATE_INTERVAL); fprintf(out_file, "max_articles=%u\n", MAX_ARTICLES); fprintf(out_file, "\n# feeds\n"); } } free(config_path); } }