void tokenize_variable_array( const wchar_t *val, array_list_t *out ) { if( val ) { wchar_t *cpy = wcsdup( val ); wchar_t *pos, *start; wchar_t *next; if( !cpy ) { DIE_MEM(); } for( start=pos=cpy; *pos; pos++ ) { if( *pos == ARRAY_SEP ) { *pos=0; next = start==cpy?cpy:wcsdup(start); if( !next ) DIE_MEM(); al_push( out, next ); start=pos+1; } } next = start==cpy?cpy:wcsdup(start); if( !next ) DIE_MEM(); al_push( out, next ); } }
void history_add( const wchar_t *str ) { item_t *i; if( !current_mode ) return; i = halloc( current_mode->item_context, sizeof(item_t)); i->data = (wchar_t *)halloc_wcsdup( current_mode->item_context, str ); i->timestamp = time(0); al_push( ¤t_mode->item, i ); hash_put( ¤t_mode->session_item, i, i ); al_truncate( ¤t_mode->used, 0 ); current_mode->pos = al_get_count( ¤t_mode->item ); current_mode->new_count++; if( (time(0) > current_mode->save_timestamp+SAVE_INTERVAL) || (current_mode->new_count >= SAVE_COUNT) ) { history_save_mode( 0, current_mode ); } }
/** Push hash value into array_list_t */ static void hash_put_data( void *key, void *data, void *al ) { al_push( (array_list_t *)al, data ); }
void input_mapping_add( const wchar_t *sequence, const wchar_t *command ) { int i; CHECK( sequence, ); CHECK( command, ); // debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) ); for( i=0; i<al_get_count( &mappings); i++ ) { input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i ); if( wcscmp( m->seq, sequence ) == 0 ) { m->command = intern(command); return; } } input_mapping_t *m = malloc( sizeof( input_mapping_t ) ); m->seq = intern( sequence ); m->command = intern(command); al_push( &mappings, m ); }
int al_push_all( array_list_t *a, array_list_t *b ) { int k; for( k=0; k<al_get_count( b ); k++ ) { if( !al_push( a, al_get( b, k ) ) ) return 0; } return 1; }
void halloc_register_function( void *context, void (*func)(void *), void *data ) { halloc_t *me; if( !context ) return; me = halloc_from_data( context ); al_push_func( &me->children, func ); al_push( &me->children, data ); }
void input_mapping_get_names( array_list_t *list ) { int i; for( i=0; i<al_get_count( &mappings ); i++ ) { input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i ); al_push( list, m->seq ); } }
void input_function_get_names( array_list_t *lst ) { int i; CHECK( lst, ); for( i=0; i<(sizeof(name_arr)/sizeof(wchar_t *)); i++ ) { al_push( lst, name_arr[i] ); } }
void input_terminfo_get_names( array_list_t *lst, int skip_null ) { int i; CHECK( lst, ); input_init(); for( i=0; i<al_get_count( terminfo_mappings ); i++ ) { terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i ); if( skip_null && !m->seq ) { continue; } al_push( lst, m->name ); } }
/** Create a new completion entry */ void completion_allocate( array_list_t *context, const wchar_t *comp, const wchar_t *desc, int flags ) { completion_t *res = halloc( context, sizeof( completion_t) ); res->completion = halloc_wcsdup( context, comp ); if( desc ) res->description = halloc_wcsdup( context, desc ); if( flags & COMPLETE_AUTO_SPACE ) { int len = wcslen(comp); flags = flags & (~COMPLETE_AUTO_SPACE); if( ( len > 0 ) && ( wcschr( L"/=@:", comp[ len - 1 ] ) != 0 ) ) flags |= COMPLETE_NO_SPACE; } res->flags = flags; al_push( context, res ); }
/** The complete builtin. Used for specifying programmable tab-completions. Calls the functions in complete.c for any heavy lifting. Defined in builtin_complete.c */ static int builtin_complete( wchar_t **argv ) { int res=0; int argc=0; int result_mode=SHARED; int remove = 0; int authoritative = -1; int flags = COMPLETE_AUTO_SPACE; string_buffer_t short_opt; array_list_t gnu_opt, old_opt; wchar_t *comp=L"", *desc=L"", *condition=L""; wchar_t *do_complete = 0; array_list_t cmd; array_list_t path; static int recursion_level=0; if( !is_interactive_session ) { debug( 1, _(L"%ls: Command only available in interactive sessions"), argv[0] ); } al_init( &cmd ); al_init( &path ); sb_init( &short_opt ); al_init( &gnu_opt ); al_init( &old_opt ); argc = builtin_count_args( argv ); woptind=0; while( res == 0 ) { const static struct woption long_options[] = { { L"exclusive", no_argument, 0, 'x' } , { L"no-files", no_argument, 0, 'f' } , { L"require-parameter", no_argument, 0, 'r' } , { L"path", required_argument, 0, 'p' } , { L"command", required_argument, 0, 'c' } , { L"short-option", required_argument, 0, 's' } , { L"long-option", required_argument, 0, 'l' } , { L"old-option", required_argument, 0, 'o' } , { L"description", required_argument, 0, 'd' } , { L"arguments", required_argument, 0, 'a' } , { L"erase", no_argument, 0, 'e' } , { L"unauthoritative", no_argument, 0, 'u' } , { L"authoritative", no_argument, 0, 'A' } , { L"condition", required_argument, 0, 'n' } , { L"do-complete", optional_argument, 0, 'C' } , { L"help", no_argument, 0, 'h' } , { 0, 0, 0, 0 } } ; int opt_index = 0; int opt = wgetopt_long( argc, argv, L"a:c:p:s:l:o:d:frxeuAn:C::h", long_options, &opt_index ); if( opt == -1 ) break; switch( opt ) { case 0: if(long_options[opt_index].flag != 0) break; sb_printf( sb_err, BUILTIN_ERR_UNKNOWN, argv[0], long_options[opt_index].name ); builtin_print_help( argv[0], sb_err ); res = 1; break; case 'x': result_mode |= EXCLUSIVE; break; case 'f': result_mode |= NO_FILES; break; case 'r': result_mode |= NO_COMMON; break; case 'p': case 'c': { wchar_t *a = unescape( woptarg, 1); if( a ) { al_push( (opt=='p'?&path:&cmd), a ); } else { sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg ); res = 1; } break; } case 'd': desc = woptarg; break; case 'u': authoritative=0; break; case 'A': authoritative=1; break; case 's': sb_append( &short_opt, woptarg ); break; case 'l': al_push( &gnu_opt, woptarg ); break; case 'o': al_push( &old_opt, woptarg ); break; case 'a': comp = woptarg; break; case 'e': remove = 1; break; case 'n': condition = woptarg; break; case 'C': do_complete = woptarg?woptarg:reader_get_buffer(); break; case 'h': builtin_print_help( argv[0], sb_out ); return 0; case '?': builtin_unknown_option( argv[0], argv[woptind-1] ); res = 1; break; } } if( !res ) { if( condition && wcslen( condition ) ) { if( parser_test( condition, 0, 0, 0 ) ) { sb_printf( sb_err, L"%ls: Condition '%ls' contained a syntax error\n", argv[0], condition ); parser_test( condition, 0, sb_err, argv[0] ); res = 1; } } } if( !res ) { if( comp && wcslen( comp ) ) { if( parser_test_args( comp, 0, 0 ) ) { sb_printf( sb_err, L"%ls: Completion '%ls' contained a syntax error\n", argv[0], comp ); parser_test_args( comp, sb_err, argv[0] ); res = 1; } } } if( !res ) { if( do_complete ) { array_list_t *comp; int i; const wchar_t *prev_temporary_buffer = temporary_buffer; wchar_t *token; parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 ); temporary_buffer = do_complete; if( recursion_level < 1 ) { recursion_level++; comp = al_halloc( 0 ); complete( do_complete, comp ); for( i=0; i<al_get_count( comp ); i++ ) { completion_t *next = (completion_t *)al_get( comp, i ); wchar_t *prepend; if( next->flags & COMPLETE_NO_CASE ) { prepend = L""; } else { prepend = token; } if( next->description ) { sb_printf( sb_out, L"%ls%ls\t%ls\n", prepend, next->completion, next->description ); } else { sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion ); } } halloc_free( comp ); recursion_level--; } temporary_buffer = prev_temporary_buffer; } else if( woptind != argc ) { sb_printf( sb_err, _( L"%ls: Too many arguments\n" ), argv[0] ); builtin_print_help( argv[0], sb_err ); res = 1; } else if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) ) { /* No arguments specified, meaning we print the definitions of * all specified completions to stdout.*/ complete_print( sb_out ); } else { if( remove ) { builtin_complete_remove( &cmd, &path, (wchar_t *)short_opt.buff, &gnu_opt, &old_opt ); } else { builtin_complete_add( &cmd, &path, (wchar_t *)short_opt.buff, &gnu_opt, &old_opt, result_mode, authoritative, condition, comp, desc, flags ); } } } al_foreach( &cmd, &free ); al_foreach( &path, &free ); al_destroy( &cmd ); al_destroy( &path ); sb_destroy( &short_opt ); al_destroy( &gnu_opt ); al_destroy( &old_opt ); return res; }
/** Push hash key into array_list_t */ static void hash_put_key( void *key, void *data, void *al ) { al_push( (array_list_t *)al, key ); }
int main() { ArrayList* arrayListC=al_newArrayList(); ArrayList* DeleteHistory=al_newArrayList(); ArrayList* Backup=al_newArrayList(); eEmployee* employeeAux; int id=0; int auxInt; int option; char continueDo='s'; // loadCant(arrayListC); loadFile(arrayListC,"Nomina.dat"); loadFile(DeleteHistory,"Exempl.dat"); // loader(arrayListC); do { getInt(&option,"######CASO DE USO ARRAYLIST###\n\n1-Agregar un empleado\n2-Modificar empleado\n3-Eliminar empleado" "\n4-Tamaño de la nomina\n5-Informes\n6-Salir" "\n10-Salir\noption:","Opcion no valida\n",1,8); switch(option) { case 1: employeeAux=loadEmployee(arrayListC); auxInt=findByName(DeleteHistory,employeeAux->name,employeeAux->lastName); if(auxInt==-1) { id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } else { getInt(&option,"\nEl empleado ya pertenecia a la empresa, desea agregarlo nuevamente?? \n1-Si\n2-No","Error opcion no valida",1,2); switch(option) { case 1: employeeAux=(ArrayList*)arrayListC->get(DeleteHistory,auxInt); al_push(arrayListC,(employeeAux->id-1),(void*)employeeAux); al_remove(DeleteHistory,auxInt); break; case 2: id++; if(al_add(arrayListC,(void*)employeeAux)) { id--; } } break; } break; case 2: modifyEmployee(arrayListC); break; case 3: deleteEmployee(arrayListC,DeleteHistory); break; case 4: printf("\n\n@@@@@@@@ HISTORIAL @@@@@@@\n\n"); PrintEmployees(DeleteHistory); break; case 5: informes(arrayListC); break; case 6: continueDo='n'; saveToFileActive(arrayListC,"Nomina.dat"); saveToFileActive(DeleteHistory,"Exempl.dat"); break; case 7: break; case 8: al_push(arrayListC,2,loadEmployee(arrayListC)); break; default: break; } } while(continueDo!='n'); // saveCant(arrayListC); return 0; }
void anna_hash_add_method(anna_function_t *fun) { al_push(&anna_hash_additional_methods, fun); hash_foreach2(&anna_hash_specialization, &add_hash_method, fun); }
/** Go through the mmaped region and insert pointers to suitable loacations into the item list */ static void history_populate_from_mmap( history_mode_t *m ) { char *begin = m->mmap_start; char *end = begin + m->mmap_length; char *pos; array_list_t old_item; array_list_t session_item_list; int ignore_newline = 0; int do_push = 1; al_init( &old_item ); al_init( &session_item_list ); al_push_all( &old_item, &m->item ); al_truncate( &m->item, 0 ); for( pos = begin; pos <end; pos++ ) { if( do_push ) { item_t *i; item_t *i_orig; ignore_newline = *pos == '#'; i = item_get( m, pos ); if( (i_orig=hash_get( ¤t_mode->session_item, i ) ) ) { /* This item comes from this session. Insert the original item at the end of the item list. */ al_push( &session_item_list, i_orig ); } else { /* Old item. Insert pointer directly to the item list */ al_push( &m->item, pos ); } do_push = 0; } switch( *pos ) { case '\\': { pos++; break; } case '\n': { if( ignore_newline ) { ignore_newline = 0; } else { do_push = 1; } break; } } } al_push_all( &m->item, &session_item_list ); m->pos += al_get_count( &m->item ); al_push_all( &m->item, &old_item ); al_destroy( &session_item_list ); al_destroy( &old_item ); }
/** Try to find the specified file in any of the possible directories where mime files can be located. This code is shamelessly stolen from xdg_run_command_on_dirs. \param list Full file paths will be appended to this list. \param f The relative filename search for the the data directories. \param all If zero, then stop after the first filename. \return The number of filenames added to the list. */ static int append_filenames( array_list_t *list, char *f, int all ) { int prev_count = al_get_count( list ); char *result; const char *xdg_data_home; const char *xdg_data_dirs; const char *ptr; xdg_data_home = getenv ("XDG_DATA_HOME"); if (xdg_data_home) { result = file_exists( xdg_data_home, f ); if ( result ) { al_push( list, result ); if ( !all ) return 1; } } else { const char *home; home = getenv ("HOME"); if (home != NULL) { char *guessed_xdg_home; guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share") + 1); if( !guessed_xdg_home ) return 0; strcpy (guessed_xdg_home, home); strcat (guessed_xdg_home, "/.local/share"); result = file_exists( guessed_xdg_home, f ); free (guessed_xdg_home); if ( result ) { al_push( list, result ); if ( !all ) return 1; } } } xdg_data_dirs = getenv ("XDG_DATA_DIRS"); if (xdg_data_dirs == NULL) xdg_data_dirs = "/usr/local/share:/usr/share"; ptr = xdg_data_dirs; while (*ptr != '\000') { const char *end_ptr; char *dir; int len; end_ptr = ptr; while (*end_ptr != ':' && *end_ptr != '\000') end_ptr ++; if (end_ptr == ptr) { ptr++; continue; } len = end_ptr - ptr; dir = my_malloc (len + 1); if( !dir ) return 0; strncpy (dir, ptr, len); dir[len] = '\0'; result = file_exists( dir, f ); free (dir); if ( result ) { al_push( list, result ); if ( !all ) { return 1; } } ptr = end_ptr; } return al_get_count( list ) - prev_count; }
/** Main function. Parses options and calls helper function for any heavy lifting. */ int main (int argc, char *argv[]) { int input_type=FILEDATA; int output_type=MIMETYPE; const char *mimetype; char *output=0; int i; hash_table_t launch_hash; locale_init(); /* Parse options */ while( 1 ) { static struct option long_options[] = { { "input-file-data", no_argument, 0, 't' } , { "input-filename", no_argument, 0, 'f' } , { "input-mime", no_argument, 0, 'i' } , { "output-mime", no_argument, 0, 'm' } , { "output-description", no_argument, 0, 'd' } , { "output-action", no_argument, 0, 'a' } , { "help", no_argument, 0, 'h' } , { "version", no_argument, 0, 'v' } , { "launch", no_argument, 0, 'l' } , { 0, 0, 0, 0 } } ; int opt_index = 0; int opt = getopt_long( argc, argv, GETOPT_STRING, long_options, &opt_index ); if( opt == -1 ) break; switch( opt ) { case 0: break; case 't': input_type=FILEDATA; break; case 'f': input_type=FILENAME; break; case 'i': input_type=MIMETYPE; break; case 'm': output_type=MIMETYPE; break; case 'd': output_type=DESCRIPTION; break; case 'a': output_type=ACTION; break; case 'l': output_type=LAUNCH; break; case 'h': print_help( argv[0], 1 ); exit(0); case 'v': printf( _("%s, version %s\n"), MIMEDB, PACKAGE_VERSION ); exit( 0 ); case '?': return 1; } } if( ( output_type == LAUNCH )&&(input_type==MIMETYPE)) { fprintf( stderr, _("%s: Can not launch a mimetype\n"), MIMEDB ); print_help( argv[0], 2 ); exit(1); } if( output_type == LAUNCH ) hash_init( &launch_hash, &hash_str_func, &hash_str_cmp ); /* Loop over all non option arguments and do the specified lookup */ //fprintf( stderr, "Input %d, output %d\n", input_type, output_type ); for (i = optind; (i < argc)&&(!error); i++) { /* Convert from filename to mimetype, if needed */ if( input_type == FILENAME ) { mimetype = xdg_mime_get_mime_type_from_file_name(argv[i]); } else if( input_type == FILEDATA ) { mimetype = xdg_mime_get_mime_type_for_file(argv[i]); } else mimetype = xdg_mime_is_valid_mime_type(argv[i])?argv[i]:0; mimetype = xdg_mime_unalias_mime_type (mimetype); if( !mimetype ) { fprintf( stderr, _( "%s: Could not parse mimetype from argument '%s'\n"), MIMEDB, argv[i] ); error=1; return 1; } /* Convert from mimetype to whatever, if needed */ switch( output_type ) { case MIMETYPE: { output = (char *)mimetype; break; } case DESCRIPTION: { output = get_description( mimetype ); if( !output ) output = strdup( _("Unknown") ); break; } case ACTION: { output = get_action( mimetype ); break; } case LAUNCH: { /* There may be more files using the same launcher, we add them all up in little array_list_ts and launched them together after all the arguments have been parsed. */ array_list_t *l= (array_list_t *)hash_get( &launch_hash, mimetype ); output = 0; if( !l ) { l = my_malloc( sizeof( array_list_t ) ); if( l == 0 ) { break; } al_init( l ); hash_put( &launch_hash, mimetype, l ); } al_push( l, argv[i] ); } } /* Print the glorious result */ if( output ) { printf( "%s\n", output ); if( output != mimetype ) free( output ); } output = 0; } /* Perform the actual launching */ if( output_type == LAUNCH && !error ) { int i; array_list_t mimes; al_init( &mimes ); hash_get_keys( &launch_hash, &mimes ); for( i=0; i<al_get_count( &mimes ); i++ ) { char *mimetype = (char *)al_get( &mimes, i ); array_list_t *files = (array_list_t *)hash_get( &launch_hash, mimetype ); if( !files ) { fprintf( stderr, _( "%s: Unknown error\n"), MIMEDB ); error=1; break; } char *launcher = get_action( mimetype ); if( launcher ) { launch( launcher, files, 0 ); free( launcher ); } } hash_foreach( &launch_hash, &clear_entry ); hash_destroy( &launch_hash ); al_destroy( &mimes ); } if( launch_buff ) free( launch_buff ); if( start_re ) { regfree( start_re ); regfree( stop_re ); free( start_re ); free( stop_re ); } xdg_mime_shutdown(); return error; }
int exec_subshell( const wchar_t *cmd, array_list_t *lst ) { char *begin, *end; char z=0; int prev_subshell = is_subshell; int status, prev_status; io_data_t *io_buffer; const wchar_t *ifs; char sep=0; CHECK( cmd, -1 ); ifs = env_get(L"IFS"); if( ifs && ifs[0] ) { if( ifs[0] < 128 ) { sep = '\n';//ifs[0]; } else { sep = 0; debug( 0, L"Warning - invalid command substitution separator '%lc'. Please change the firsta character of IFS", ifs[0] ); } } is_subshell=1; io_buffer= io_buffer_create( 0 ); prev_status = proc_get_last_status(); if( eval( cmd, io_buffer, SUBST ) ) { status = -1; } else { status = proc_get_last_status(); } io_buffer_read( io_buffer ); proc_set_last_status( prev_status ); is_subshell = prev_subshell; b_append( io_buffer->param2.out_buffer, &z, 1 ); begin=end=io_buffer->param2.out_buffer->buff; if( lst ) { while( 1 ) { if( *end == 0 ) { if( begin != end ) { wchar_t *el = str2wcs( begin ); if( el ) { al_push( lst, el ); } else { debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); } } io_buffer_destroy( io_buffer ); return status; } else if( *end == sep ) { wchar_t *el; *end=0; el = str2wcs( begin ); if( el ) { al_push( lst, el ); } else { debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); } begin = end+1; } end++; } } io_buffer_destroy( io_buffer ); return status; }
int complete_is_valid_option( const wchar_t *str, const wchar_t *opt, array_list_t *errors ) { complete_entry_t *i; complete_entry_opt_t *o; wchar_t *cmd, *path; int found_match = 0; int authoritative = 1; int opt_found=0; hash_table_t gnu_match_hash; int is_gnu_opt=0; int is_old_opt=0; int is_short_opt=0; int is_gnu_exact=0; int gnu_opt_len=0; char *short_validated; void *context; CHECK( str, 0 ); CHECK( opt, 0 ); /* Check some generic things like -- and - options. */ switch( wcslen(opt ) ) { case 0: case 1: { return 1; } case 2: { if( wcscmp( L"--", opt ) == 0 ) { return 1; } break; } } if( opt[0] != L'-' ) { if( errors ) { al_push( errors, wcsdup(L"Option does not begin with a '-'") ); } return 0; } context = halloc( 0, 0 ); if( !(short_validated = halloc( context, wcslen( opt ) ))) { DIE_MEM(); } memset( short_validated, 0, wcslen( opt ) ); hash_init( &gnu_match_hash, &hash_wcs_func, &hash_wcs_cmp ); is_gnu_opt = opt[1]==L'-'; if( is_gnu_opt ) { wchar_t *opt_end = wcschr(opt, L'=' ); if( opt_end ) { gnu_opt_len = (opt_end-opt)-2; } else { gnu_opt_len = wcslen(opt)-2; } } parse_cmd_string( context, str, &path, &cmd ); /* Make sure completions are loaded for the specified command */ complete_load( cmd, 0 ); for( i=first_entry; i; i=i->next ) { wchar_t *match = i->cmd_type?path:cmd; const wchar_t *a; if( !wildcard_match( match, i->cmd ) ) { continue; } found_match = 1; if( !i->authoritative ) { authoritative = 0; break; } if( is_gnu_opt ) { for( o = i->first_option; o; o=o->next ) { if( o->old_mode ) { continue; } if( wcsncmp( &opt[2], o->long_opt, gnu_opt_len )==0) { hash_put( &gnu_match_hash, o->long_opt, L"" ); if( (wcsncmp( &opt[2], o->long_opt, wcslen( o->long_opt) )==0) ) { is_gnu_exact=1; } } } } else { /* Check for old style options */ for( o = i->first_option; o; o=o->next ) { if( !o->old_mode ) continue; if( wcscmp( &opt[1], o->long_opt )==0) { opt_found = 1; is_old_opt = 1; break; } } if( is_old_opt ) break; for( a = &opt[1]; *a; a++ ) { wchar_t *str_pos = wcschr(i->short_opt_str, *a); if (str_pos ) { if( *(str_pos +1)==L':' ) { /* This is a short option with an embedded argument, call complete_is_valid_argument on the argument. */ wchar_t nopt[3]; nopt[0]=L'-'; nopt[1]=opt[1]; nopt[2]=L'\0'; short_validated[a-opt] = complete_is_valid_argument( str, nopt, &opt[2]); } else { short_validated[a-opt]=1; } } } } } if( authoritative ) { if( !is_gnu_opt && !is_old_opt ) is_short_opt = 1; if( is_short_opt ) { int j; opt_found=1; for( j=1; j<wcslen(opt); j++) { if ( !short_validated[j]) { if( errors ) { wchar_t str[2]; str[0] = opt[j]; str[1]=0; al_push( errors, wcsdupcat(_( L"Unknown option: " ), L"'", str, L"'" ) ); } opt_found = 0; break; } } } if( is_gnu_opt ) { opt_found = is_gnu_exact || (hash_get_count( &gnu_match_hash )==1); if( errors && !opt_found ) { if( hash_get_count( &gnu_match_hash )==0) { al_push( errors, wcsdupcat( _(L"Unknown option: "), L"'", opt, L"\'" ) ); } else { al_push( errors, wcsdupcat( _(L"Multiple matches for option: "), L"'", opt, L"\'" ) ); } } } } hash_destroy( &gnu_match_hash ); halloc_free( context ); return (authoritative && found_match)?opt_found:1; }
void *halloc( void *context, size_t size ) { halloc_t *me, *parent; if( context ) { char *res; char *aligned; #ifdef HALLOC_DEBUG if( !child_count ) { pid = getpid(); atexit( &halloc_report ); } child_count++; child_size += size; #endif parent = halloc_from_data( context ); /* Align memory address */ aligned = align_ptr( parent->scratch ); parent->scratch_free -= (aligned-parent->scratch); if( parent->scratch_free < 0 ) parent->scratch_free=0; parent->scratch = aligned; if( size <= parent->scratch_free ) { res = parent->scratch; parent->scratch_free -= size; parent->scratch = ((char *)parent->scratch)+size; } else { #ifdef HALLOC_DEBUG alloc_count++; #endif if( parent->scratch_free < HALLOC_SCRAP_SIZE ) { #ifdef HALLOC_DEBUG alloc_spill += parent->scratch_free; #endif res = calloc( 1, size + HALLOC_BLOCK_SIZE ); if( !res ) DIE_MEM(); parent->scratch = (char *)res + size; parent->scratch_free = HALLOC_BLOCK_SIZE; } else { res = calloc( 1, size ); if( !res ) DIE_MEM(); } al_push_func( &parent->children, &late_free ); al_push( &parent->children, res ); } return res; } else { me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE ); if( !me ) DIE_MEM(); #ifdef HALLOC_DEBUG parent_count++; #endif me->scratch = ((char *)me) + align_sz(sizeof(halloc_t)) + align_sz(size); me->scratch_free = HALLOC_BLOCK_SIZE; al_init( &me->children ); return ((char *)me) + align_sz(sizeof(halloc_t)); } }