dernier commit avant travaux...

This commit is contained in:
2019-11-03 18:58:21 +01:00
parent ec27a42dc1
commit db3d7283df
15 changed files with 321 additions and 147 deletions

View File

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

View File

@@ -2,19 +2,6 @@
* 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;
/* --------------------------------------------------------------------- */

View File

@@ -1,3 +1,4 @@
a | bla bla | ../AK14V-ORDRES.wav
z |znare|znare.wav
B | plop ! | ../AK14V-ORDRES.wav
c | classic | foo.wav

139
files/smpllist.c Normal file
View File

@@ -0,0 +1,139 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "../nclooper.h"
#include "ffuncs.h"
#include "smpllist.h"
/* --------------------------------------------------------------------- */
extern int verbosity;
/* --------------------------------------------------------------------- */
void affiche_un_sample(SampleRef *sref, int options)
{
printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text,
sref->path);
}
/* --------------------------------------------------------------------- */
int decode_la_ligne(char *line, SampleRef *sref)
{
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, "|");
if (NULL==ptr) {
fprintf(stderr, "fubarized\n");
return -1;
}
cp = ltrim(rtrim(ptr));
if (verbosity) 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, "|");
if (NULL==ptr) {
fprintf(stderr, "line to short\n");
return -3;
}
cp = ltrim(rtrim(ptr));
if (verbosity) 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;
}
cp = ltrim(rtrim(ptr));
if (verbosity) fprintf(stderr, "path [%s]\n", cp);
if (strlen(ptr) > SZ_PATH) {
fprintf(stderr, "path too long\n");
return -5;
}
strcpy(sref->path, cp);
return 0;
}
/* --------------------------------------------------------------------- */
#define T_LINE 500
int lecture_liste_des_samples(char *fname, SampleRef *samples)
{
FILE *fp;
char line[T_LINE+1];
int ln; /* line number */
int foo, bar, idx;
SampleRef sample;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname);
#endif
/*
* first step : clean the current list
*/
for (foo=0; foo<26; foo++) {
memset(samples+foo, 0, sizeof(SampleRef));
}
if (NULL==(fp=fopen(fname, "r"))) {
perror(fname);
exit(1);
}
ln = 1;
while (NULL != fgets(line, T_LINE, fp)) {
/* 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';
memset(&sample, 0, sizeof(SampleRef));
foo = decode_la_ligne(line, &sample);
#if DEBUG_LEVEL
fprintf(stderr, "decode la ligne -> %d\n\n", foo);
#endif
if (!foo) {
affiche_un_sample(&sample, 0);
idx = tolower(sample.key) - 'a';
if (idx<0 || idx>25) {
/* serious bug here */
break;
}
memcpy(samples+idx, &sample, sizeof(SampleRef));
}
ln++;
}
fclose(fp);
return -1;
}
/* --------------------------------------------------------------------- */

12
files/smpllist.h Normal file
View File

@@ -0,0 +1,12 @@
/* --------------------------------------------------------------------- */
void affiche_un_sample(SampleRef *sref, int options);
int decode_la_ligne(char *line, SampleRef *sref);
int lecture_liste_des_samples(char *fname, SampleRef *array);

118
files/t.c
View File

@@ -8,116 +8,16 @@
#include <string.h>
#include <ctype.h>
#include "../nclooper.h"
#include "smpllist.h"
#include "ffuncs.h"
/* --------------------------------------------------------------------- */
int verbosity;
/* --------------------------------------------------------------------- */
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, *cp;
SampleRef the_samples[26];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref);
// dump(line);
#endif
/*
* ON THE WAY TO PARSING HELL
*/
ptr = strtok(line, "|");
cp = ltrim(rtrim(ptr));
if (verbosity) 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, "|");
if (NULL==ptr) {
fprintf(stderr, "line to short\n");
return -3;
}
cp = ltrim(rtrim(ptr));
if (verbosity) 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;
}
cp = ltrim(rtrim(ptr));
if (verbosity) fprintf(stderr, "path [%s]\n", cp);
if (strlen(ptr) > SZ_PATH) {
fprintf(stderr, "path too long\n");
return -5;
}
strcpy(sref->path, cp);
return 0;
}
/* --------------------------------------------------------------------- */
#define T_LINE 300
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';
memset(&sample, 0, sizeof(SampleRef));
foo = decode_la_ligne(line, &sample);
#if DEBUG_LEVEL
fprintf(stderr, "decode la ligne -> %d\n\n", foo);
#endif
affiche_un_sample(&sample);
ln++;
}
fclose(fp);
return -1;
}
/* --------------------------------------------------------------------- */
void help(int k)
{
@@ -132,10 +32,11 @@ int foo;
int opt;
char *listname = "samples.list";
while ((opt = getopt(argc, argv, "hv")) != -1) {
while ((opt = getopt(argc, argv, "hl:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'v': verbosity++; break;
case 'l': listname = optarg; break;
}
}
@@ -143,8 +44,13 @@ while ((opt = getopt(argc, argv, "hv")) != -1) {
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
#endif
foo = essai_lecture_liste(listname);
fprintf(stderr,"essai lecture '%s' -> %d\n", listname, foo);
foo = lecture_liste_des_samples(listname, the_samples);
fprintf(stderr,"retour lecture liste '%s' -> %d\n", listname, foo);
for (foo=0; foo<26; foo++) {
printf("%3d %02x %s\n", foo, the_samples[foo].key,
the_samples[foo].text);
}
return 0;
}