#include #include #include #include #include struct CROSSENTRY { char *file; char *entry; CROSSENTRY *next; }; static CROSSENTRY *tbhash[1024]; static int crosstbl_dohash (const char *entry) { int ret = 0; while (*entry != '\0'){ ret = (ret << 1) ^ *entry; entry++; } return ret & (1024-1); } /* Charge un fichier de référence croisée. Cette fonction peut être appelée plusieurs fois. Les fichiers sont accumulés. */ void crosstbl_load (const char *fname) { FILE *fin = fopen_err (fname,"r",1); char file[PATH_MAX],entry[PATH_MAX]; char *lastfile = ""; // NOTE: CROSSENTRY::file is shared by several entry (using lastfile) // We do not free these struct anyway (the program end simply). while (fscanf (fin,"%s %s\n",file,entry)==2){ CROSSENTRY *e = new CROSSENTRY; e->entry = strdup(entry); if (strcmp(file,lastfile)!=0){ lastfile = strdup(file); } e->file = lastfile; int hash = crosstbl_dohash (entry); e->next = tbhash[hash]; tbhash[hash] = e; } fclose (fin); } /* Locate the file which may have an entry point for "entry". Most of the time, this function return NULL (no file). nadoc blindly ask for every single word if there is an entry. */ const char *crosstbl_getfile (const char *entry) { const char *ret = NULL; int hash = crosstbl_dohash (entry); CROSSENTRY *e = tbhash[hash]; while (e != NULL){ if (strcmp(e->entry,entry)==0){ ret = e->file; break; } e = e->next; } return ret; } void crosstbl_filter ( const char *buf, FILE *fout, void (*fct)(char, FILE *, bool), void (*fcturl)(const char *, const char *, FILE *), bool &sgml_aware) { while (*buf != '\0'){ char car = *buf++; if (car == '<'){ if (strncmp(buf,"sgml>",5)==0){ sgml_aware = true; buf += 5; }else if (strncmp(buf,"/sgml>",6)==0){ sgml_aware = false; buf += 6; }else{ (*fct) (car,fout,sgml_aware); } }else if (car > ' ' && car != '(' && car != ')' && car != '>' && car != ',' && car != '.'){ if (isalpha(car)){ // Maybe an identifier. Lets find out if there is a crossref char entry[200]; entry[0] = car; char *pte = entry+1; while (*buf > ' ' && *buf != '(' && *buf != ')' && *buf != '>' && *buf != ',' && *buf != '.' && (unsigned)(pte-entry)