reading samples list

This commit is contained in:
Tonton Th 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
CCOPT = -Wall -g -DDEBUG_LEVEL=1
ffuncs.o: ffuncs.c ffuncs.h Makefile
$(CC) ${CCOPT} -c $<
LIBS =
OBJS = ffuncs.o
t: t.c ${OBJS} Makefile
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@

View File

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

View File

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

View File

@ -6,39 +6,71 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "ffuncs.h"
/* --------------------------------------------------------------------- */
int verbosity;
typedef struct {
char key;
char text[100];
char path[200];
} SampleRef;
/* --------------------------------------------------------------------- */
void affiche_un_sample(SampleRef *sref)
{
printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text,
sref->path);
}
/* --------------------------------------------------------------------- */
static int decode_la_ligne(char *line, SampleRef *sref)
{
char *ptr;
char *ptr, *cp;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref);
// dump(line);
#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);
cp = ltrim(rtrim(ptr));
fprintf(stderr, "key [%s]\n", cp);
if ( ! isalpha(*cp)) {
fprintf(stderr, "invalid key 0x%02x\n", *cp);
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)
{
@ -60,7 +92,7 @@ if (NULL==(fp=fopen(fname, "r"))) {
ln = 1;
while (NULL != fgets(line, T_LINE, fp)) {
fprintf(stderr, "%3d = %s", ln, line);
// fprintf(stderr, "%3d = %s", ln, line);
/* degommer l'eventuel \n */
bar = strlen(line);
@ -71,9 +103,10 @@ while (NULL != fgets(line, T_LINE, fp)) {
bar--; /* backspace one char */
if ('\n' == line[bar]) line[bar]='\0';
memset(&sample, 0, sizeof(SampleRef));
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++;
}