/* print CONFIG_ prerequisite */ static void update_prereq(const char *m, int slen){ int i; // return if already hashed if(hashtbl_add(m, slen)) return; printf(" \\\n $(wildcard %s", conf_dir); for(i=0; i<slen; i++){ if(m[i] == '_') putchar('/'); else putchar(tolower(m[i])); } printf(".h)"); }
/* * Function: * hash_create * Arguments: * (htbl) Pointer to a pointer to a hash_table structure. * Purpose: * This function is our most important function. From this * hash table, all other searches depend. This function will * grab all the definitions, parse them, also each functions * description, AND what it returns. It will build a new * 'chain_node' for each, and add it to it's proper 'bucket' * in our hash table. * Returns: * -1 - On error, call err_GetLastError for more information. * 0 - If everything went planned. */ int hashtbl_create( hashtbl **htbl ) { chain_node *tmp; char definition[CORE_MAX_DEF] = {0}; char description[CORE_MAX_DESC] = {0}; char returns[CORE_MAX_RET] = {0}; /* If this is still 0 they didn't call: core_start(); big no-no!!! */ if( !core_startup ) { err_setError( FUNC_HASHTBL_CREATE, FILE_HASH_C, ERR_CORE_STARTUP, __LINE__ ); return -1; } if( !htbl ) { err_setError( FUNC_HASHTBL_CREATE, FILE_HASH_C, ERR_NULL_PARAM, __LINE__ ); return -1; } *htbl = malloc( sizeof(**htbl) ); if( *htbl == NULL ) { err_setError( FUNC_HASHTBL_CREATE, FILE_HASH_C, ERR_MALLOC, __LINE__ ); return -1; } memset( *htbl, 0, sizeof(**htbl) ); /* If you mess w/ my data files you'll f**k this all up. Leave 'em alone */ while( fgets(definition, sizeof definition, def) != NULL && fgets(description, sizeof description, desc) != NULL && fgets(returns, sizeof returns, ret) != NULL ) { tmp = malloc( sizeof(*tmp) ); if( tmp == NULL ) goto error1; memset( tmp, 0, sizeof(*tmp) ); core_convertNewLines( description ); core_convertNewLines( returns ); tmp->name = malloc( (strlen(definition) + 1) * sizeof(*tmp->name) ); if( tmp->name == NULL ) { free( tmp ); goto error1; } tmp->description = malloc( (strlen(description) + 1) * sizeof(*tmp->description) ); if( tmp->description == NULL ) goto error; tmp->returns = malloc( (strlen(returns) + 1) * sizeof(*tmp->returns) ); if( tmp->returns == NULL ) goto error; strncpy( tmp->name, definition, strlen(definition) + 1 ); strncpy( tmp->description, description, strlen(description) + 1 ); strncpy( tmp->returns, returns, strlen(returns) + 1 ); if( core_parseDefinition(tmp->name, &tmp->name, &tmp->section, &tmp->prototype) ) goto error; core_convertNewLines( tmp->prototype ); if( hashtbl_add(*htbl, tmp) ) goto error; } return 0; error: if( tmp->description ) free( tmp->description ); if( tmp->returns ) free( tmp->returns ); if( tmp->name ) free( tmp->name ); free( tmp ); error1: hashtbl_destroy( htbl ); return -1; }