symbolTable* enterScope(scopeType scope, int line, char* filename, symbolTable* parent) { //printf("enterScope=%i\n", scope); struct symbolTable *table; if(!(table = malloc(sizeof(symbolTable)))) { fprintf(stderr, "Error: could not allocate memory for symbol table.\n"); return NULL; } table->scope = scope; table->line = line; table->filename = strdup(filename); table->parent = parent; table->mainTable = new_hashTable(HT_SIZE); table->labelTable = new_hashTable(HT_SIZE); table->tagTable = new_hashTable(HT_SIZE); return table; }
/**START - Funzioni utilizzate la creazione della socket del server e i thread handler e writer*/ int creating_main_structures(int *sockets, hashTable_t **allworker, queue **coda, pthread_t **tid_writer, pthread_t **tid_worker, pthread_t **tid_handler, void *(*handler)(), void *(*writer)()) { int tmp; if (CreateServerChannel(sockets, "./tmp/msgsock")) return 1; /*Faccio partire in thread dell'handler*/ if (PthreadCreate(tid_handler, handler, NULL)) { closeSocket(*sockets); return 1; } /*Eseguo il writer, il quale si pone in attesa di tutti gli eventuali messaggi di log dai vari worker*/ *coda = malloc(sizeof(queue)); tmp = initialize(*coda); if ((tmp == 1 || *coda == NULL)) { fprintf(stderr, "ERROR : msgserv : creazione della coda dei messaggi non riuscita.\n"); free(*tid_handler); closeSocket(*sockets); return 1; } if (PthreadCreate(tid_writer, writer, NULL)) { closeSocket(*sockets); free(coda); free(*tid_handler); return 1; } /*Creo la tabella hash destinata a contenere tutti i worker attivi*/ if ((*allworker = new_hashTable(SIZEH, compare_string_hash, copy_string_hash, copy_int_hash, hash_string)) == NULL) { fprintf(stderr, "ERROR : msgserv : allworker = new_hashTable.\n"); /*start free*/ closeSocket(*sockets); free(*coda); free(*tid_handler); free(*tid_writer); /*End free*/ return 1; } return 0; }
/**START - Funzioni utilizzate per preparare le strutture dati necessarie al server*/ int preparing_data_structures(int argc, char *argv[], hashTable_t **hashaut, FILE **faut, FILE **flog, pthread_mutex_t mtx_autor) { if (argc != 3) { fprintf(stderr, "ERROR : msgserv : (argc != 3), argc = %d.\n", argc); return 1; } /* * Apertura del file delle autorizzazioni, in caso di errore "return 1" * In assenza di errori procedo con la creazione (controllata) della tabella Hash * delle autorizzazioni */ errno = 0; if (openfile(faut, argv[1], "r")) return 1; if ((*hashaut = new_hashTable(SIZEH, compare_string_hash, copy_string_hash, copy_int_hash, hash_string)) == NULL) { fclose(*faut); return 1; } /*Scanzione del file e salvataggio dei nomi degli utenti autorizzati nella tabella Hash*/ if (preparing_hash_aut(*faut, hashaut, mtx_autor)) return 1; /* * Apertura del filelog, in caso di errore return 1 */ if (openfile(flog, argv[2], "w")) { fprintf(stderr, ERRLOGFILE); ; pthread_mutex_lock(&mtx_autor); if (*hashaut != NULL) free_hashTable(&(*hashaut)); free(*hashaut); return 1; } return 0; }