static void InitWinListConfig (ASModuleConfig *asm_config, Bool free_resources) { WinListConfig *config = AS_WINLIST_CONFIG(asm_config); if( config ) { if( free_resources ) { int i ; destroy_string(&(config->UnfocusedStyle)); destroy_string(&(config->FocusedStyle)); destroy_string(&(config->StickyStyle)); destroy_string(&(config->UrgentStyle)); for (i = 0; i < MAX_MOUSE_BUTTONS; ++i) if (config->Action[i]) destroy_string_list(config->Action[i],0); #define FREE_COLLIDES(type) do { \ destroy_string_list(&(config->type##Collides[0]),config->type##Collides_nitems); \ if( config->type##Collides_wrexp ) { \ for( i = 0 ; i < config->type##Collides_nitems ; ++i ) destroy_wild_reg_exp(config->type##Collides_wrexp[i]); \ free( config->type##Collides_wrexp ); \ }}while(0) if( config->NoCollides_nitems > 0 ) FREE_COLLIDES(No); if( config->AllowCollides_nitems > 0 ) FREE_COLLIDES(Allow); } // memset( config, 0x00, sizeof(WinListConfig)); config->flags = WINLIST_ShowIcon|WINLIST_ScaleIconToTextHeight ; init_asgeometry (&(config->Geometry)); config->gravity = StaticGravity; config->MaxRows = 1; config->UseName = ASN_Name; config->Align = ALIGN_CENTER; config->HSpacing = DEFAULT_TBAR_HSPACING; config->VSpacing = DEFAULT_TBAR_VSPACING; config->FBevel = config->UBevel = config->SBevel = DEFAULT_TBAR_HILITE ; config->IconAlign = NO_ALIGN ; config->IconLocation = 0 ; config->ShowHints = WINLIST_DEFAULT_ShowHints ; if( !free_resources ) { config->NoCollides = safecalloc(2, sizeof(char*)); ; config->NoCollides[0] = mystrdup(CLASS_PAGER); config->NoCollides[1] = mystrdup(CLASS_WHARF); config->NoCollides_nitems = 2 ; } config->NoCollidesSpacing = 1 ; } }
void DestroyWharfButton (WharfButton ** pbtn) { WharfButton *btn = *pbtn; if (btn == NULL) return; *pbtn = btn->next; /* delete members */ if (btn->title != NULL) free (btn->title); if (btn->comment != NULL) free (btn->comment); if (btn->contents) { int k; for (k = 0; k < btn->contents_num; ++k) { char **icon = btn->contents[k].icon; FunctionData *function = btn->contents[k].function; if (icon != NULL) destroy_string_list (icon, 0); if (function) { free_func_data (function); free (function); } } free (btn->contents); } while (btn->folder) DestroyWharfButton (&(btn->folder)); free (btn); }
void ParseWharfItem (FreeStorageElem * storage, WharfButton ** folder) { WharfButton *wb = *folder, **insert = folder; Bool no_title; WharfButtonContent wbc = { NULL, NULL }; if (storage == NULL || folder == NULL) return; if (storage->argc < 2) return; no_title = (storage->argv[0][0] == '-' && storage->argv[0][1] == '\0') || (mystrcasecmp (storage->argv[0], "nil") == 0); insert = folder; if (!no_title) { while (wb != NULL && (wb->title == NULL || strcmp (wb->title, storage->argv[0]) != 0)) { insert = &(wb->next); wb = wb->next; } } else while (wb != NULL) { insert = &(wb->next); wb = wb->next; } if (wb == NULL) { if ((wb = CreateWharfButton ()) == NULL) return; *insert = wb; } if (wb->title) free (wb->title); wb->title = mystrdup (storage->argv[0]); { char **new_icon_list = comma_string2list (storage->argv[1]); if (new_icon_list) { register char *ptr; register int null_icon = 0; if ((ptr = new_icon_list[0]) == NULL) null_icon++; else if (*(ptr) == '-' && *(ptr + 1) == '\0') null_icon++; else if (mystrcasecmp (ptr, "nil") == 0) null_icon++; if (null_icon > 0) { destroy_string_list (new_icon_list, 0); new_icon_list = NULL; } } wbc.icon = new_icon_list; } LOCAL_DEBUG_OUT ("wharf button \"%s\" has substorage set to %p", wb->title, storage->sub); if (storage->sub) { FreeStorageElem *pstorage = storage->sub; register TermDef *pterm = pstorage->term; if (pterm != NULL) { LOCAL_DEBUG_OUT ("term for keyword \"%s\" found in substorage", pterm->keyword); if (pterm->id == F_Folder) { if (pstorage->sub) { pstorage = pstorage->sub; ParseWharfFolder (&pstorage, &(wb->folder)); } } else if (pterm->id == F_Transient) { set_flags (wb->set_flags, WHARF_BUTTON_TRANSIENT); } else if (pterm->type == TT_FUNCTION) { ConfigItem item; item.memory = NULL; if (ReadConfigItem (&item, pstorage)) { if (pterm->id == F_Size) { set_flags (wb->set_flags, WHARF_BUTTON_SIZE); wb->width = item.data.function->func_val[0]; wb->height = item.data.function->func_val[1]; item.ok_to_free = 1; } else { wbc.function = item.data.function; item.ok_to_free = 0; } ReadConfigItem (&item, NULL); } } } } if (wbc.function != NULL || wbc.icon != NULL) { int c = wb->contents_num; ++(wb->contents_num); wb->contents = realloc (wb->contents, wb->contents_num * sizeof (WharfButtonContent)); wb->contents[c] = wbc; } }
/** * Program entrypoint. */ int main(int argc, char **argv) { int char_count; int string_count; int encoded_size; unsigned char charmap[256]; int frequencies[256]; huffman_node_t *leaf_nodes[256]; huffman_node_t *code_nodes[256]; huffman_node_t *root; int symbol_count; string_list_t *strings; FILE *input; FILE *table_output; FILE *data_output; int append_byte = -1; int ignore_case = 0; const char *input_filename = 0; const char *charmap_filename = 0; const char *table_output_filename = 0; const char *data_output_filename = 0; const char *table_label = ""; const char *node_label_prefix = ""; const char *string_table_label = ""; const char *string_label_prefix = ""; int generate_string_table = 0; int verbose = 0; /* Process arguments. */ { char *p; while ((p = *(++argv))) { if (!strncmp("--", p, 2)) { const char *opt = &p[2]; if (!strncmp("character-map=", opt, 14)) { charmap_filename = &opt[14]; } else if (!strncmp("table-output=", opt, 13)) { table_output_filename = &opt[13]; } else if (!strncmp("data-output=", opt, 12)) { data_output_filename = &opt[12]; } else if (!strncmp("table-label=", opt, 12)) { table_label = &opt[12]; } else if (!strncmp("node-label-prefix=", opt, 18)) { node_label_prefix = &opt[18]; } else if (!strncmp("string-label-prefix=", opt, 20)) { string_label_prefix = &opt[20]; generate_string_table = 1; } else if (!strcmp("generate-string-table", opt)) { generate_string_table = 1; } else if (!strncmp("string-table-label=", opt, 19)) { string_table_label = &opt[19]; } else if (!strncmp("append-byte=", opt, 12)) { append_byte = strtol(&opt[12], 0, 0); if ((append_byte < 0) || (append_byte >= 256)) { fprintf(stderr, "huffpuff: --append-byte: value must be in range 0..255\n"); return(-1); } } else if (!strcmp("ignore-case", opt)) { ignore_case = 1; } else if (!strcmp("verbose", opt)) { verbose = 1; } else if (!strcmp("help", opt)) { help(); } else if (!strcmp("usage", opt)) { usage(); } else if (!strcmp("version", opt)) { version(); } else { fprintf(stderr, "huffpuff: unrecognized option `%s'\n" "Try `huffpuff --help' or `huffpuff --usage' for more information.\n", p); return(-1); } } else { input_filename = p; } } } /* Set default character mapping f(c)=c */ { int i; for (i=0; i<256; i++) charmap[i] = (unsigned char)i; } if (charmap_filename) { if (verbose) fprintf(stdout, "reading character map\n"); if (!charmap_parse(charmap_filename, charmap)) { fprintf(stderr, "error: failed to parse character map `%s'\n", charmap_filename); return(-1); } } if (input_filename) { input = fopen(input_filename, "rt"); if (!input) { fprintf(stderr, "error: failed to open `%s' for reading\n", input_filename); return(-1); } } else { input = stdin; } /* Read strings to encode. */ if (verbose) fprintf(stdout, "reading strings\n"); strings = read_strings(input, ignore_case, frequencies, &char_count, &string_count); fclose(input); /* Create Huffman leaf nodes. */ if (verbose) fprintf(stdout, "creating Huffman leaf nodes\n"); symbol_count = 0; { int i; if (append_byte != -1) frequencies[append_byte] += string_count; for (i=0; i<256; i++) { if (frequencies[i] > 0) { huffman_node_t *node; node = huffman_create_node( /*symbol=*/i, /*weight=*/frequencies[i], /*left=*/NULL, /*right=*/NULL); leaf_nodes[symbol_count++] = node; code_nodes[i] = node; } else { code_nodes[i] = 0; } } } if (verbose) fprintf(stdout, " number of symbols: %d\n", symbol_count); /* Build the Huffman tree. */ if (verbose) fprintf(stdout, "Building the Huffman tree\n"); root = huffman_build_tree(leaf_nodes, symbol_count); /* Huffman-encode strings. */ if (verbose) fprintf(stdout, "encoding strings\n"); encoded_size = encode_strings(strings, code_nodes, append_byte); /* Sanity check */ if (verbose) fprintf(stdout, "verifying output integrity\n"); if (!verify_data_integrity(strings, root)) { assert(0); /* Cleanup */ huffman_delete_node(root); destroy_string_list(strings); return(-1); } /* Prepare output */ if (!table_output_filename) { table_output_filename = "huffpuff.tab.asm"; } table_output = fopen(table_output_filename, "wt"); if (!table_output) { fprintf(stderr, "error: failed to open `%s' for writing\n", table_output_filename); /* Cleanup */ huffman_delete_node(root); destroy_string_list(strings); return(-1); } if (!data_output_filename) { data_output_filename = "huffpuff.dat.asm"; } data_output = fopen(data_output_filename, "wt"); if (!data_output) { fprintf(stderr, "error: failed to open `%s' for writing\n", data_output_filename); /* Cleanup */ huffman_delete_node(root); destroy_string_list(strings); return(-1); } fprintf(data_output, "; Huffman-encoded string data automatically generated by huffpuff.\n"); /* Print the Huffman codes in code length order. */ if (verbose) fprintf(stdout, "writing Huffman decoder table\n"); fprintf(table_output, "; Huffman decoder table automatically generated by huffpuff.\n"); if (table_label && strlen(table_label)) fprintf(table_output, "%s:\n", table_label); write_huffman_codes(table_output, root, charmap, node_label_prefix); fclose(table_output); if (generate_string_table) { /* Print string pointer table */ int i; string_list_t *lst; if (verbose) fprintf(stdout, "writing string pointer table\n"); if (string_table_label && strlen(string_table_label)) fprintf(data_output, "%s:\n", string_table_label); for (i = 0, lst = strings; lst != 0; lst = lst->next, ++i) { fprintf(data_output, ".dw %sString%d\n", string_label_prefix, i); } } /* Write the Huffman-encoded strings. */ if (verbose) fprintf(stdout, "writing encoded string data\n"); write_huffman_strings(data_output, strings, string_label_prefix); fclose(data_output); if (verbose) fprintf(stdout, "compressed size: %d%%\n", (encoded_size*100) / char_count); /* Cleanup */ huffman_delete_node(root); destroy_string_list(strings); return 0; }
void MergeWinListOptions ( ASModuleConfig *asm_to, ASModuleConfig *asm_from) { int i ; START_TIME(option_time); WinListConfig *to = AS_WINLIST_CONFIG(asm_to); WinListConfig *from = AS_WINLIST_CONFIG(asm_from); if( to && from ) { /* Need to merge new config with what we have already :*/ /* now lets check the config sanity : */ /* mixing set and default flags : */ ASCF_MERGE_FLAGS(to,from); ASCF_MERGE_GEOMETRY_KEYWORD(WINLIST, to, from, Geometry); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MinSize); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MaxSize); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MaxRows); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MaxColumns); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MaxColWidth); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, MinColWidth); ASCF_MERGE_STRING_KEYWORD(WINLIST, to, from, FocusedStyle); ASCF_MERGE_STRING_KEYWORD(WINLIST, to, from, UnfocusedStyle); ASCF_MERGE_STRING_KEYWORD(WINLIST, to, from, StickyStyle); ASCF_MERGE_STRING_KEYWORD(WINLIST, to, from, UrgentStyle); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, UseName); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, Align); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, FBevel); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, UBevel); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, SBevel); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, FCompositionMethod); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, UCompositionMethod); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, SCompositionMethod); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, HSpacing); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, VSpacing); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, IconAlign); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, IconLocation); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, IconSize); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, NoCollidesSpacing); ASCF_MERGE_SCALAR_KEYWORD(WINLIST, to, from, ShowHints); for( i = 0 ; i < MAX_MOUSE_BUTTONS ; ++i ) if( from->Action[i] ) { destroy_string_list( to->Action[i], 0 ); to->Action[i] = from->Action[i]; from->Action[i] = NULL ; } #define MERGE_COLLIDES_ITEM(type) \ do{ to->type##Collides = saferealloc( to->type##Collides, (from->type##Collides_nitems+to->type##Collides_nitems)*sizeof(char*)); \ memcpy(&(to->type##Collides[to->type##Collides_nitems]), from->type##Collides, from->type##Collides_nitems*sizeof(char*) ) ; \ to->type##Collides_nitems += from->type##Collides_nitems; \ from->type##Collides_nitems = 0 ; free( from->type##Collides ); from->type##Collides = NULL ; }while(0) if( from->NoCollides_nitems > 0 ) MERGE_COLLIDES_ITEM(No); if( from->AllowCollides_nitems > 0 ) MERGE_COLLIDES_ITEM(Allow); } SHOW_TIME("to parsing",option_time); }
void WinList_fs2config( ASModuleConfig *asmodule_config, FreeStorageElem *Storage ) { FreeStorageElem *pCurr; ConfigItem item; WinListConfig *config = AS_WINLIST_CONFIG(asmodule_config) ; if( config == NULL ) return ; item.memory = NULL; for (pCurr = Storage; pCurr; pCurr = pCurr->next) { if (pCurr->term == NULL) continue; if (pCurr->term->type == TT_FLAG) { if( pCurr->term->id == WINLIST_Bevel_ID ) { set_scalar_value(&(config->FBevel),ParseBevelOptions( pCurr->sub ), &(config->set_flags), WINLIST_Bevel); config->UBevel = config->SBevel = config->FBevel; } }else { if (!ReadConfigItem (&item, pCurr)) continue; switch (pCurr->term->id) { case WINLIST_Spacing_ID : set_flags( config->set_flags, WINLIST_Spacing ); config->HSpacing = config->VSpacing = item.data.integer; break ; case WINLIST_CompositionMethod_ID : set_flags( config->set_flags, WINLIST_CompositionMethod ); config->FCompositionMethod = config->UCompositionMethod = config->SCompositionMethod = item.data.integer; break ; case WINLIST_MaxWidth_ID: set_flags (config->set_flags, WINLIST_MinSize|WINLIST_MaxSize); config->MaxSize.width = config->MinSize.width = item.data.integer; break; case WINLIST_Action_ID: { char *ptr = item.data.string; int action_no = 0, i; if (mystrncasecmp (ptr, "Click", 5) == 0) ptr += 5; if (isdigit (ptr[0])) { action_no = atoi (ptr); if (action_no <= 0) action_no = 1; --action_no; action_no %= MAX_MOUSE_BUTTONS; i = 0; while (!isspace (ptr[i]) && ptr[i]) ++i; while (isspace (ptr[i]) && ptr[i]) ++i; ptr += i; } if (*ptr) { destroy_string_list( config->Action[action_no], 0 ); config->Action[action_no] = comma_string2list( ptr ); } item.ok_to_free = 1; } break; #define HANDLE_COLLIDES_ITEM(type) \ if( item.data.string != NULL ) { \ config->type##Collides = saferealloc( config->type##Collides, (config->type##Collides_nitems+1)*sizeof(char*)); \ config->type##Collides[config->type##Collides_nitems] = item.data.string ; \ ++config->type##Collides_nitems ; } break case WINLIST_NoCollides_ID: HANDLE_COLLIDES_ITEM(No); case WINLIST_AllowCollides_ID: HANDLE_COLLIDES_ITEM(Allow); default: item.ok_to_free = 1; } } } ReadConfigItem (&item, NULL); }