/* * NcLooper test des fonctions fichier (???) */ #include #include #include #include /* --------------------------------------------------------------------- */ int verbosity; typedef struct { char key; char text[100]; char path[200]; } SampleRef; /* --------------------------------------------------------------------- */ static int decode_la_ligne(char *line, SampleRef *sref) { char *ptr; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref); #endif /* * ON THE WAY TO PARSING HELL */ ptr = strtok(line, "|"); fprintf(stderr, "[%s]\n", ptr); ptr = strtok(NULL, "|"); fprintf(stderr, "[%s]\n", ptr); ptr = strtok(NULL, "|"); fprintf(stderr, "[%s]\n", ptr); return -1; } /* --------------------------------------------------------------------- */ #define T_LINE 200 int essai_lecture_liste(char *fname) { FILE *fp; char line[T_LINE+1]; int ln; /* line number */ int foo, bar; SampleRef sample; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname); #endif if (NULL==(fp=fopen(fname, "r"))) { perror(fname); exit(1); } ln = 1; while (NULL != fgets(line, T_LINE, fp)) { fprintf(stderr, "%3d = %s", ln, line); /* degommer l'eventuel \n */ bar = strlen(line); if (0==bar) { fprintf(stderr,"line %d very short\n", ln); continue; } bar--; /* backspace one char */ if ('\n' == line[bar]) line[bar]='\0'; foo = decode_la_ligne(line, &sample); fprintf(stderr, "decode la ligne -> %d\n", foo); ln++; } fclose(fp); return -1; } /* --------------------------------------------------------------------- */ void help(int k) { puts("Test des fonctions de gestion des fichiers"); exit(0); } /* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int foo; int opt; char *listname = "samples.list"; while ((opt = getopt(argc, argv, "hv")) != -1) { switch(opt) { case 'h': help(0); break; case 'v': verbosity++; break; } } #if DEBUG_LEVEL fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); #endif foo = essai_lecture_liste(listname); fprintf(stderr,"essai lecture '%s' -> %d\n", listname, foo); return 0; } /* --------------------------------------------------------------------- */