#include #include #include #include #include #include "permut.h" #include "nadoc.m" /* Libère espace dans un NAP_LIST */ PUBLIC NAP_LIST::~NAP_LIST() { int nb = nbfct; NAP_FCT *e = tbelm; for (int i=0; inom); free (e->desc); } free (tbelm); tbelm = NULL; nbfct = 0; } /* Ouvre un fichier nap et construit la liste de toutes les fonctions Ne retourne pas si erreur Retourne le nombre de fonction lue */ PUBLIC int NAP_LIST::parse (const char *fname) { FILE *fin = vfopen_err (fname,"r",1); char accbuf[20000]; char *ptacc = accbuf; char fctname[100]; char buf[400]; bool accum = false; while (fgets (buf,sizeof(buf)-1,fin) != NULL){ if (strncmp(buf,"/*~",3)==0){ if (accum){ NAP_FCT *elm = tbelm + nbfct; nbfct++; elm->flag = 0; elm->nom = strdup_err (fctname,1); elm->desc = strdup_err (accbuf,1); } ptacc = accbuf; accum = false; accbuf[0] = '\0'; if (!isdigit(buf[4])){ char *pt = strchr(buf,'!'); if (pt==NULL){ fprintf (stderr,MSG_B(E_IVLDFORMAT ,"Fichier %s: Format invalide\n" ,"Invalid format for file %s\n"),fname); exit (-1); }else{ *pt = '\0'; strcpy (fctname,buf+3); accum=true; } } }else if (accum){ if (ptacc-accbuf > 19000){ fprintf (stderr,MSG_B(E_TOOLONG ,"Commentaire trop long pour la fonction %s\n" ,"Comment too long for function %s\n") ,fctname); exit (-1); }else{ ptacc = stpcpy (ptacc,buf); } } } if (accum){ NAP_FCT *elm = tbelm + nbfct; nbfct++; elm->nom = strdup_err (fctname,1); elm->desc = strdup_err (accbuf,1); } fclose (fin); return nbfct; } PRIVATE void NAP_LIST::init() { tbelm = (NAP_FCT*)malloc_err (10000*sizeof(NAP_FCT),1); nbfct = 0; } PUBLIC NAP_LIST::NAP_LIST(const char *fname) { init(); parse (fname); } PUBLIC NAP_LIST::NAP_LIST() { init(); } PUBLIC int NAP_LIST::getnb() { return nbfct; } PUBLIC NAP_FCT *NAP_LIST::getitem(int no) { NAP_FCT *ret = NULL; if (no >=0 && no < nbfct) ret = tbelm + no; return ret; } /* Localise la description d'une fonction Retourne NULL si trouve pas */ PRIVATE NAP_FCT * NAP_LIST::locate0 ( const char *fctname, int pos) { int nb = nbfct; NAP_FCT *ret = NULL; NAP_FCT *elm = tbelm+pos; for (int i=pos; inom)==0){ ret = elm; break; } } return ret; } /* Localise la première description d'une fonction Retourne NULL si trouve pas */ PUBLIC NAP_FCT *NAP_LIST::locate (const char *fctname) { return locate0 (fctname,0); } /* Localise une autre description d'une fonction Retourne NULL si trouve pas */ PUBLIC NAP_FCT *NAP_LIST::locatenext (NAP_FCT *info) { int pos = (int)(info-tbelm)+1; return locate0 (info->nom,pos); } static int cmp_nap_fct (const void *pt1, const void *pt2) { NAP_FCT *p1 = *(NAP_FCT**)pt1; NAP_FCT *p2 = *(NAP_FCT**)pt2; return strcmp (p1->nom,p2->nom); } /* Tri un tableau de NAP_FCT */ void nap_sort (NAP_FCT **tb, int nb) { hsort (tb,nb,sizeof(tb[0]),cmp_nap_fct); } static int cmp_nap_fctmem (const void *pt1, const void *pt2) { NAP_FCT *p1 = *(NAP_FCT**)pt1; NAP_FCT *p2 = *(NAP_FCT**)pt2; char *m1 = strchr (p1->nom,':'); if (m1 == NULL) m1 = p1->nom; char *m2 = strchr (p2->nom,':'); if (m2 == NULL) m2 = p2->nom; return strcmp (m1,m2); } /* Tri un tableau de NAP_FCT (fonction membre) */ void nap_sortmem (NAP_FCT **tb, int nb) { hsort (tb,nb,sizeof(tb[0]),cmp_nap_fctmem); } /* Localise la prochaine (première) fonction membre d'une classe Si fct == NULL, commence au début, sinon retourne le suivant */ PUBLIC NAP_FCT *NAP_LIST::locatemember (const char *cls, NAP_FCT *fct) { char str[100]; int lenstr = sprintf (str,"%s::",cls); int pos = 0; if (fct != NULL) pos = (int)(fct-tbelm)+1; NAP_FCT *elm = tbelm+pos; int nb = nbfct; NAP_FCT *ret = NULL; for (int i=pos; inom,lenstr)==0){ ret = elm; break; } } return ret; } #ifdef TEST void main (void) { NAP_LIST lst; int i; nap_parse (&lst,"permut.nap"); for (i=0; inom); printf ("Description:\n%s\n",elm->desc); } } #endif