int main(int argc, char* argv[]) { int i = 1; FILE* fp; int temp = 0; string filename; initSymbolTable(labelTABLE); initSymbolTable(entryTABLE); initSymbolTable(externTABLE); QUE_initiate(); for(;argv[i] != NULL; i++){ temp = strlen(argv[i]); filename = argv[i]; if((fp = fopen(strcat(filename, asEndOfFile), "r")) == NULL ) fprintf(stderr, "\nError opening file %s ", argv[i]); else{ filename[temp] = '\0'; firstStep(fp); secondStep(); printMemory(strcat(filename,obEndOfFile)); filename[temp] = '\0'; printGuideLines(strcat(filename,obEndOfFile)); filename[temp] = '\0'; printEntryTable(entryTABLE, strcat(filename,entEndOfFile)); filename[temp] = '\0'; printExternTable(strcat(filename,extEndOfFile)); } freeSymbolTable(labelTABLE); freeSymbolTable(entryTABLE); freeSymbolTable(externTABLE); freeQueue(); } return 1; }
void destroyDefaultSyntaxContext( SyntaxContext* ctx ) { freeSymbolTable( ctx->globalSymbols ); freeSymbolTable( ctx->localSymbols ); free( ctx->globalSymbols ); free( ctx->localSymbols ); ctx->globalSymbols = NULL; ctx->localSymbols = NULL; }
void delSymbolTable(){ int i; for(i=0; i<counter; i++){ freeSymbolTable(S[i]); } counter=0; }
/* exe_commande Descr: Execute les différentes opérations demandés par l'utilisateur Param: - c: Commande (voir #define ci dessus) - nomfichier: Nom du fichier à lire - nm_index: Argument de l'option -x, NULL si l'option n'a pas été choisis Return: Etat de sortie de la fonction: - -1: Impossible d'ouvrir le fichier donné - 0: Ouverture du fichier réussi */ int exe_commande(unsigned char c, char *nomfichier,char* nm_index) { if (nomfichier==NULL) return NOMFICHIERNULL; FILE *f; Elf32_Ehdr header; Elf32_Shdr *section_header_table; Elf32_Sym *symbol_tab; sectioncontent section; int nbSym = 0; int valid = 0; f = fopen(nomfichier,"r"); // Ouverture du fichier nomfichier if(f == NULL) { // Echec d'ouverture return FICHIERINEXISTANT; } else { /* Lecture Header */ header = read_header(f,&valid); if(valid==1) { // Header valide /* Lecture Table de section header */ section_header_table = read_section_header_table(f,header); /* Lecture Table des symboles */ symbol_tab = read_symbol_table(f ,section_header_table, header, &nbSym); if(c&COMMANDE_HEAD) //COMMANDE_HEAD { printf("ELF Header:\n"); print_header(header); printf("\n"); } if(c&COMMANDE_SECTIONTAB)//COMMANDE_SECTIONTAB { printf("Section Headers:\n"); print_section_header_table(f,section_header_table,header); printf("\n"); } if(c&COMMANDE_CONTENT)//COMMANDE_CONTENT { printf("Section %s content:\n", nm_index); section = read_section_content(f,nm_index, section_header_table, header); if(section.content==NULL) { printf("Warning, section : %s,was not dumped because it does not exist \n",nm_index); } else { print_section_content(section); } } if(c&COMMANDE_RELOC)//COMMANDE_RELOC { print_all_reloc_table(f, header, section_header_table, symbol_tab); printf("\n"); } if(c&COMMANDE_SYM)//COMMANDE_SYM { printf("Symbol table\n"); print_symbol_table(symbol_tab, nbSym, f, section_header_table, header); freeSymbolTable(symbol_tab); } } else // Header non valide { if(valid ==-1) { // Fichier non valid (vide ou autre) return FILEEMPTY;fprintf(stderr, "%s : Error while reading the file (possibly empty)\n",nomfichier); } else if(valid==0) { //Fichier pas au format elf32 return NOTELF32; } else { // Cas normalement impossible fprintf(stderr, "Impossible error append\n"); } } fclose(f); // Fermeture du fichier } return 0; }