void dblist(void) { char *next, *wfdb = getwfdb(); int first = 1; while (*wfdb) { /* Isolate the next component of the WFDB path. */ for (next = wfdb; *next && next - wfdb < MFNLEN - 6; next++) if (*next == ' ') { *next++ = '\0'; break; } /* Look for a "DBS" file in the next possible location. */ sprintf(wfdb_filename, "%s/DBS", wfdb); if ((ifile = wfdb_fopen(wfdb_filename, "rb")) != NULL) { if (first) printf("{ \"database\": [\n"); while (wfdb_fgets(buf, sizeof(buf), ifile)) { char *p, *name, *desc; for (p = buf; p < buf + sizeof(buf) && *p != '\t'; p++) ; if (*p != '\t') continue; *p++ = '\0'; while (p < buf + sizeof(buf) - 1 && *p == '\t') p++; p[strlen(p)-1] = '\0'; if (!first) printf(",\n"); else first = 0; name = strjson(buf); desc = strjson(p); printf(" { \"name\": %s,\n \"desc\": %s\n }", name, desc); SFREE(desc); SFREE(name); } wfdb_fclose(ifile); first = 0; /* ensure that the database array will be closed in the output even if the DBS file was empty */ } wfdb = next; /* prepare to search the next location in the WFDB path */ } if (!first) { printf("\n ],\n"); printf(" \"version\": \"%s\",\n", LWVER); lwpass(); } else { lwfail("The list of databases could not be read"); } }
INTEGER getwfdb_(char *string) { strcpy(string, getwfdb()); cfstring(string); return (0L); }