#include #include #include #include "vfs.h" #define MAX_MACRO 20 static int nbmacro; static char *tbmacro[MAX_MACRO]; static char *tbval[MAX_MACRO]; #define KITOMBRE "/kit/ombre" #define KITBUILD "/kit/build" #define KITGROUPE "/kit/groupe" #define KITLIVRE "/kit/livre" #define KITSYNC "/kit/sync" /* recherche un fichier ou un repertoire en revenant vers la racine Si le fichier n'est dans le path fournis, remonte d'un repertoire et essai. Retourne 0 si ok, -1 si erreur. */ static int file_findanc ( const char *path, /* path ou on pense trouver le fichier */ /* "" -> path courant */ const char *nom, /* nom du fichier ou du repertoire */ char *filepath) /* contiendra le path trouve pour ce fichier */ /* peut ˆtre NULL */ { int ret = -1; char wpath[MAXSIZ_PATH]; char tmpfpath[MAXSIZ_PATH]; if (filepath == NULL) filepath = tmpfpath; path_addback (path,wpath); if (path_setabs (wpath,wpath)!=-1){ while (1){ path_make (wpath,nom,filepath); if (file_type(filepath) >= 0){ ret = 0; break; }else if(path_isroot(wpath)){ break; }else{ char dummy[MAXSIZ_NAME]; int len = strlen(wpath); path_stripsep (wpath,wpath); path_splitlex (wpath,wpath,dummy); if ((int)strlen(wpath)==len) break; } } } return (ret); } /* Enregistre d‚finitions par d‚faut pour r‚solution r‚pertoires virtuels. */ static void near macrodir_init (void) { if (nbmacro == 0){ macrodir_setdef("KITOMBRE" ,KITOMBRE); macrodir_setdef("KITBUILD" ,KITBUILD); macrodir_setdef("KITGROUPE",KITGROUPE); macrodir_setdef("KITLIVRE",KITLIVRE); macrodir_setdef("KITSYNC",KITSYNC); /* #Spécification: makefile.dat / macros / fichier archive.cfg Le fichier archive.cfg (optionnel) contient des valeurs alternatives pour les variables (macros) utilisés dans les makefile.dat. Ce fichier, si présent, a la plus haute priorité. Ce fichier est localisé en cherchant dans le répertoire courant et son parent, et le parent de son parent. Le but de ce fichier est, entre autre, de permettre la coexistance de deux système d'archivage en parallèle. */ char path[MAXSIZ_PATH]; if (file_findanc(".","archive.cfg",path)==0){ FILE *fin = fopen (path,"r"); if (fin != NULL){ char buf[300]; int noline = 0; while (fgets_strip (buf,sizeof(buf)-1,fin,'#','\\' ,&noline)!=NULL){ if (buf[0] != '\0'){ char *pt = strchr(buf,'='); if (pt != NULL){ *pt++ = '\0'; strip_end (buf); strip_end (pt); macrodir_set (buf,pt); }else{ fprintf (stderr,"fichier %s: ligne %d invalide\n" ,path,noline); } } } fclose (fin); } } } } /* Retourne la valeur d'une macro. La valeur est trouvé dans le fichier archive.cfg. Si ne trouve pas, retourne la valeur par défaut. */ export const char *macrodir_getval (const char *macro, const char *def) { macrodir_init(); const char *ret = def; for (int i=0; i