reading samples list

This commit is contained in:
tth 2019-10-31 15:47:54 +01:00
parent 5bb5ae987f
commit af13698209
5 changed files with 75 additions and 22 deletions

View File

@ -1,9 +1,11 @@
CC = gcc CC = gcc
CCOPT = -Wall -g -DDEBUG_LEVEL=1 CCOPT = -Wall -g -DDEBUG_LEVEL=1
ffuncs.o: ffuncs.c ffuncs.h Makefile
$(CC) ${CCOPT} -c $<
LIBS = LIBS =
OBJS = ffuncs.o
t: t.c ${OBJS} Makefile t: t.c ${OBJS} Makefile
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@ $(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@

View File

@ -11,6 +11,7 @@
#include "ffuncs.h" #include "ffuncs.h"
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
extern int verbosity; extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
@ -28,9 +29,9 @@ fputs("\n", stderr);
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
char *rtrim(char *src) char *rtrim(char *src)
{ {
int foo = strlen(src)-1; int foo;
for (foo; src[foo]==' '|| src[foo]=='\t'; foo--) { for (foo=strlen(src)-1; src[foo]==' '|| src[foo]=='\t'; foo--) {
src[foo] = '\0'; src[foo] = '\0';
} }
@ -53,7 +54,7 @@ while (src[foo]!='\0') {
bar++; bar++;
} }
strcpy(src,tmp); strcpy(src, tmp);
return src; return src;
} }

View File

@ -1,7 +1,23 @@
/* /*
* various functions * various file functions
*/ */
/* --------------------------------------------------------------------- */
/* two arbitrary magic number */
#define SZ_TEXT 20
#define SZ_PATH 400
typedef struct {
char key;
int flags;
char text[SZ_TEXT+1];
char path[SZ_PATH+1];
} SampleRef;
/* --------------------------------------------------------------------- */
void dump(unsigned char *ptr); void dump(unsigned char *ptr);
char *rtrim(char *src); char *rtrim(char *src);

View File

@ -1,2 +1,3 @@
a | bla bla | ../AK14V-ORDRES.wav a | bla bla | ../AK14V-ORDRES.wav
z |znare|znare.wav
B | plop ! | ../AK14V-ORDRES.wav B | plop ! | ../AK14V-ORDRES.wav

View File

@ -6,39 +6,71 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "ffuncs.h"
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int verbosity; int verbosity;
typedef struct { /* --------------------------------------------------------------------- */
char key; void affiche_un_sample(SampleRef *sref)
char text[100]; {
char path[200]; printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text,
} SampleRef; sref->path);
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int decode_la_ligne(char *line, SampleRef *sref) static int decode_la_ligne(char *line, SampleRef *sref)
{ {
char *ptr; char *ptr, *cp;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref); fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref);
// dump(line);
#endif #endif
/* /*
* ON THE WAY TO PARSING HELL * ON THE WAY TO PARSING HELL
*/ */
ptr = strtok(line, "|"); ptr = strtok(line, "|");
fprintf(stderr, "[%s]\n", ptr); cp = ltrim(rtrim(ptr));
ptr = strtok(NULL, "|"); fprintf(stderr, "key [%s]\n", cp);
fprintf(stderr, "[%s]\n", ptr); if ( ! isalpha(*cp)) {
ptr = strtok(NULL, "|"); fprintf(stderr, "invalid key 0x%02x\n", *cp);
fprintf(stderr, "[%s]\n", ptr); return -2;
}
sref->key = toupper(*cp);
return -1; ptr = strtok(NULL, "|");
if (NULL==ptr) {
fprintf(stderr, "line to short\n");
return -3;
}
cp = ltrim(rtrim(ptr));
fprintf(stderr, "text [%s]\n", cp);
if (strlen(cp) > SZ_TEXT) {
fprintf(stderr, "text too long\n");
return -4;
}
strcpy(sref->text, cp);
ptr = strtok(NULL, "|");
if (NULL==ptr) {
fprintf(stderr, "line to short\n");
return -6;
}
fprintf(stderr, "path [%s]\n", ltrim(rtrim(ptr)));
if (strlen(ptr) > SZ_TEXT) {
fprintf(stderr, "path too long\n");
return -5;
}
strcpy(sref->path, ptr);
return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define T_LINE 200 #define T_LINE 300
int essai_lecture_liste(char *fname) int essai_lecture_liste(char *fname)
{ {
@ -60,7 +92,7 @@ if (NULL==(fp=fopen(fname, "r"))) {
ln = 1; ln = 1;
while (NULL != fgets(line, T_LINE, fp)) { while (NULL != fgets(line, T_LINE, fp)) {
fprintf(stderr, "%3d = %s", ln, line); // fprintf(stderr, "%3d = %s", ln, line);
/* degommer l'eventuel \n */ /* degommer l'eventuel \n */
bar = strlen(line); bar = strlen(line);
@ -71,9 +103,10 @@ while (NULL != fgets(line, T_LINE, fp)) {
bar--; /* backspace one char */ bar--; /* backspace one char */
if ('\n' == line[bar]) line[bar]='\0'; if ('\n' == line[bar]) line[bar]='\0';
memset(&sample, 0, sizeof(SampleRef));
foo = decode_la_ligne(line, &sample); foo = decode_la_ligne(line, &sample);
fprintf(stderr, "decode la ligne -> %d\n", foo); fprintf(stderr, "decode la ligne -> %d\n\n", foo);
affiche_un_sample(&sample);
ln++; ln++;
} }