Compare commits

..

No commits in common. "af13698209976fa8eef62d42e0140d84efff2de8" and "d721ea674c1506d95ac9ce686cd5d93cef5abd05" have entirely different histories.

5 changed files with 16 additions and 139 deletions

View File

@ -1,11 +1,9 @@
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

@ -1,61 +0,0 @@
/*
* various functions
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "ffuncs.h"
/* --------------------------------------------------------------------- */
extern int verbosity;
/* --------------------------------------------------------------------- */
void dump(unsigned char *ptr)
{
int foo;
for (foo=0; foo<24; foo++) fprintf(stderr, "%02x ", ptr[foo]);
fputs("\n", stderr);
for (foo=0; foo<24; foo++) fprintf(stderr, "%c ",
isgraph(ptr[foo])?ptr[foo]:' ');
fputs("\n", stderr);
}
/* --------------------------------------------------------------------- */
char *rtrim(char *src)
{
int foo;
for (foo=strlen(src)-1; src[foo]==' '|| src[foo]=='\t'; foo--) {
src[foo] = '\0';
}
return src;
}
/* --------------------------------------------------------------------- */
char *ltrim(char *src)
{
int foo, bar;
char *tmp;
tmp = alloca(strlen(src));
for (foo=0; src[foo]==' ' || src[foo]=='\t'; foo++);
bar = 0;
while (src[foo]!='\0') {
tmp[bar]=src[foo];
foo++;
bar++;
}
strcpy(src, tmp);
return src;
}
/* --------------------------------------------------------------------- */

View File

@ -1,26 +0,0 @@
/*
* 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);
char *ltrim(char *src);
/* --------------------------------------------------------------------- */

View File

@ -1,3 +1,2 @@
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,71 +6,39 @@
#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 {
void affiche_un_sample(SampleRef *sref) char key;
{ char text[100];
printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text, char path[200];
sref->path); } SampleRef;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int decode_la_ligne(char *line, SampleRef *sref) static int decode_la_ligne(char *line, SampleRef *sref)
{ {
char *ptr, *cp; char *ptr;
#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, "|");
cp = ltrim(rtrim(ptr)); fprintf(stderr, "[%s]\n", ptr);
fprintf(stderr, "key [%s]\n", cp);
if ( ! isalpha(*cp)) {
fprintf(stderr, "invalid key 0x%02x\n", *cp);
return -2;
}
sref->key = toupper(*cp);
ptr = strtok(NULL, "|"); ptr = strtok(NULL, "|");
if (NULL==ptr) { fprintf(stderr, "[%s]\n", 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, "|"); ptr = strtok(NULL, "|");
if (NULL==ptr) { fprintf(stderr, "[%s]\n", 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; return -1;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define T_LINE 300 #define T_LINE 200
int essai_lecture_liste(char *fname) int essai_lecture_liste(char *fname)
{ {
@ -92,7 +60,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);
@ -103,10 +71,9 @@ 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\n", foo); fprintf(stderr, "decode la ligne -> %d\n", foo);
affiche_un_sample(&sample);
ln++; ln++;
} }