Changeset ce68f23
- Timestamp:
- Jun 25, 2011, 3:26:16 AM (13 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- c266281
- Parents:
- 3cdd6d2
- git-author:
- David Benjamin <davidben@mit.edu> (06/11/11 20:06:46)
- git-committer:
- David Benjamin <davidben@mit.edu> (06/25/11 03:26:16)
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
cmd.c
r6829afc rce68f23 28 28 } 29 29 30 void owl_cmddict_get_names(const owl_cmddict *d, owl_list *l) {31 owl_dict_get_keys(d, l);30 GPtrArray *owl_cmddict_get_names(const owl_cmddict *d) { 31 return owl_dict_get_keys(d); 32 32 } 33 33 -
dict.c
r6829afc rce68f23 56 56 } 57 57 58 /* Appends dictionary keys to a list. Duplicates the keys, 59 * so they will need to be freed by the caller. */ 60 void owl_dict_get_keys(const owl_dict *d, owl_list *l) { 58 /* Returns a GPtrArray of dictionary keys. Duplicates the keys, so 59 * they will need to be freed by the caller with g_free. */ 60 CALLER_OWN GPtrArray *owl_dict_get_keys(const owl_dict *d) { 61 GPtrArray *keys = g_ptr_array_sized_new(d->size); 61 62 int i; 62 for (i =0; i<d->size; i++) {63 owl_list_append_element(l, g_strdup(d->els[i].k));63 for (i = 0; i < d->size; i++) { 64 g_ptr_array_add(keys, g_strdup(d->els[i].k)); 64 65 } 66 return keys; 65 67 } 66 68 -
fmtext.c
r6829afc rce68f23 755 755 * If format_fn is specified, passes it the list element value 756 756 * and it will return a string which this needs to free. */ 757 void owl_fmtext_append_list(owl_fmtext *f, const owl_list*l, const char *join_with, char *(format_fn)(const char *))758 { 759 int i , size;757 void owl_fmtext_append_list(owl_fmtext *f, const GPtrArray *l, const char *join_with, char *(format_fn)(const char *)) 758 { 759 int i; 760 760 const char *elem; 761 761 char *text; 762 762 763 size = owl_list_get_size(l); 764 for (i=0; i<size; i++) { 765 elem = owl_list_get_element(l,i); 763 for (i = 0; i < l->len; i++) { 764 elem = l->pdata[i]; 766 765 if (elem && format_fn) { 767 766 text = format_fn(elem); … … 773 772 owl_fmtext_append_normal(f, elem); 774 773 } 775 if ((i < size-1) && join_with) {774 if ((i < l->len - 1) && join_with) { 776 775 owl_fmtext_append_normal(f, join_with); 777 776 } -
functions.c
r3cdd6d2 rce68f23 47 47 void owl_function_show_commands(void) 48 48 { 49 owl_listl;49 GPtrArray *l; 50 50 owl_fmtext fm; 51 51 … … 53 53 owl_fmtext_append_bold(&fm, "Commands: "); 54 54 owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n"); 55 owl_list_create(&l); 56 owl_cmddict_get_names(owl_global_get_cmddict(&g), &l); 57 owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe); 55 l = owl_cmddict_get_names(owl_global_get_cmddict(&g)); 56 owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe); 58 57 owl_fmtext_append_normal(&fm, "\n"); 59 58 owl_function_popless_fmtext(&fm); 60 owl_ list_cleanup(&l, g_free);59 owl_ptr_array_free(l, g_free); 61 60 owl_fmtext_cleanup(&fm); 62 61 } … … 81 80 82 81 void owl_function_show_styles(void) { 83 owl_listl;82 GPtrArray *l; 84 83 owl_fmtext fm; 85 84 86 85 owl_fmtext_init_null(&fm); 87 86 owl_fmtext_append_bold(&fm, "Styles:\n"); 88 owl_list_create(&l); 89 owl_global_get_style_names(&g, &l); 90 owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe); 87 l = owl_global_get_style_names(&g); 88 owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe); 91 89 owl_fmtext_append_normal(&fm, "\n"); 92 90 owl_function_popless_fmtext(&fm); 93 owl_ list_cleanup(&l, g_free);91 owl_ptr_array_free(l, g_free); 94 92 owl_fmtext_cleanup(&fm); 95 93 } … … 1576 1574 const char *name; 1577 1575 char *var; 1578 owl_listvarnames;1579 int i , numvarnames;1576 GPtrArray *varnames; 1577 int i; 1580 1578 GString *str = g_string_new(""); 1581 1579 1582 1580 g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); 1583 1581 g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); 1584 owl_list_create(&varnames); 1585 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1586 numvarnames = owl_list_get_size(&varnames); 1587 for (i=0; i<numvarnames; i++) { 1588 name = owl_list_get_element(&varnames, i); 1582 varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); 1583 for (i = 0; i < varnames->len; i++) { 1584 name = varnames->pdata[i]; 1589 1585 if (name && name[0]!='_') { 1590 1586 g_string_append_printf(str, "\n%-20s = ", name); … … 1597 1593 } 1598 1594 g_string_append(str, "\n"); 1599 owl_ list_cleanup(&varnames, g_free);1595 owl_ptr_array_free(varnames, g_free); 1600 1596 1601 1597 owl_function_popless_text(str->str); … … 1605 1601 void owl_function_show_variables(void) 1606 1602 { 1607 owl_listvarnames;1603 GPtrArray *varnames; 1608 1604 owl_fmtext fm; 1609 int i , numvarnames;1605 int i; 1610 1606 const char *varname; 1611 1607 … … 1613 1609 owl_fmtext_append_bold(&fm, 1614 1610 "Variables: (use 'show variable <name>' for details)\n"); 1615 owl_list_create(&varnames); 1616 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1617 numvarnames = owl_list_get_size(&varnames); 1618 for (i=0; i<numvarnames; i++) { 1619 varname = owl_list_get_element(&varnames, i); 1611 varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); 1612 for (i = 0; i < varnames->len; i++) { 1613 varname = varnames->pdata[i]; 1620 1614 if (varname && varname[0]!='_') { 1621 1615 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 1622 1616 } 1623 1617 } 1624 owl_ list_cleanup(&varnames, g_free);1618 owl_ptr_array_free(varnames, g_free); 1625 1619 owl_function_popless_fmtext(&fm); 1626 1620 owl_fmtext_cleanup(&fm); … … 2826 2820 void owl_function_show_keymaps(void) 2827 2821 { 2828 owl_listl;2822 GPtrArray *l; 2829 2823 owl_fmtext fm; 2830 2824 const owl_keymap *km; 2831 2825 const owl_keyhandler *kh; 2832 int i , numkm;2826 int i; 2833 2827 const char *kmname; 2834 2828 … … 2837 2831 owl_fmtext_append_bold(&fm, "Keymaps: "); 2838 2832 owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); 2839 owl_list_create(&l); 2840 owl_keyhandler_get_keymap_names(kh, &l); 2841 owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); 2833 l = owl_keyhandler_get_keymap_names(kh); 2834 owl_fmtext_append_list(&fm, l, "\n", owl_function_keymap_summary); 2842 2835 owl_fmtext_append_normal(&fm, "\n"); 2843 2836 2844 numkm = owl_list_get_size(&l); 2845 for (i=0; i<numkm; i++) { 2846 kmname = owl_list_get_element(&l, i); 2837 for (i = 0; i < l->len; i++) { 2838 kmname = l->pdata[i]; 2847 2839 km = owl_keyhandler_get_keymap(kh, kmname); 2848 2840 owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); … … 2852 2844 2853 2845 owl_function_popless_fmtext(&fm); 2854 owl_ list_cleanup(&l, g_free);2846 owl_ptr_array_free(l, g_free); 2855 2847 owl_fmtext_cleanup(&fm); 2856 2848 } -
global.c
re6d7e4e rce68f23 753 753 } 754 754 755 void owl_global_get_style_names(const owl_global *g, owl_list *l) { 756 owl_dict_get_keys(&(g->styledict), l); 755 CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g) 756 { 757 return owl_dict_get_keys(&g->styledict); 757 758 } 758 759 -
help.c
rf25df21 rce68f23 6 6 owl_fmtext fm; 7 7 const char *varname; 8 owl_listvarnames;9 int i , numvarnames;8 GPtrArray *varnames; 9 int i; 10 10 11 11 owl_fmtext_init_null(&fm); … … 129 129 owl_fmtext_append_bold(&fm, 130 130 "Variables:\n"); 131 owl_list_create(&varnames); 132 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 133 numvarnames = owl_list_get_size(&varnames); 134 for (i=0; i<numvarnames; i++) { 135 varname = owl_list_get_element(&varnames, i); 131 varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); 132 for (i = 0; i < varnames->len; i++) { 133 varname = varnames->pdata[i]; 136 134 if (varname && varname[0]!='_') { 137 135 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 138 136 } 139 137 } 140 owl_ list_cleanup(&varnames, g_free);138 owl_ptr_array_free(varnames, g_free); 141 139 142 140 owl_fmtext_append_normal(&fm, "\n"); -
keymap.c
r3cdd6d2 rce68f23 209 209 } 210 210 211 void owl_keyhandler_get_keymap_names(const owl_keyhandler *kh, owl_list *l)212 { 213 owl_dict_get_keys(&kh->keymaps, l);211 CALLER_OWN GPtrArray *owl_keyhandler_get_keymap_names(const owl_keyhandler *kh) 212 { 213 return owl_dict_get_keys(&kh->keymaps); 214 214 } 215 215 -
perlconfig.c
rf9df2f0 rce68f23 36 36 } 37 37 38 CALLER_OWN AV *owl_new_av(const owl_list*l, SV *(*to_sv)(const void *))38 CALLER_OWN AV *owl_new_av(const GPtrArray *l, SV *(*to_sv)(const void *)) 39 39 { 40 40 AV *ret; … … 44 44 ret = newAV(); 45 45 46 for (i = 0; i < owl_list_get_size(l); i++) {47 element = owl_list_get_element(l, i);46 for (i = 0; i < l->len; i++) { 47 element = l->pdata[i]; 48 48 av_push(ret, to_sv(element)); 49 49 } … … 55 55 { 56 56 HV *ret; 57 owl_list l;57 GPtrArray *keys; 58 58 const char *key; 59 59 void *element; … … 63 63 64 64 /* TODO: add an iterator-like interface to owl_dict */ 65 owl_list_create(&l); 66 owl_dict_get_keys(d, &l); 67 for (i = 0; i < owl_list_get_size(&l); i++) { 68 key = owl_list_get_element(&l, i); 65 keys = owl_dict_get_keys(d); 66 for (i = 0; i < keys->len; i++) { 67 key = keys->pdata[i]; 69 68 element = owl_dict_find_element(d, key); 70 69 (void)hv_store(ret, key, strlen(key), to_sv(element), 0); 71 70 } 72 owl_ list_cleanup(&l, g_free);71 owl_ptr_array_free(keys, g_free); 73 72 74 73 return ret; -
perlglue.xs
rbcde7926 rce68f23 329 329 all_filters() 330 330 PREINIT: 331 owl_list fl; 332 CODE: 333 { 334 owl_list_create(&fl); 335 owl_dict_get_keys(&g.filters, &fl); 336 RETVAL = owl_new_av(&fl, (SV*(*)(const void*))owl_new_sv); 331 GPtrArray *fl; 332 CODE: 333 { 334 fl = owl_dict_get_keys(&g.filters); 335 RETVAL = owl_new_av(fl, (SV*(*)(const void*))owl_new_sv); 337 336 sv_2mortal((SV*)RETVAL); 338 owl_ list_cleanup(&fl, g_free);337 owl_ptr_array_free(fl, g_free); 339 338 } 340 339 OUTPUT: … … 344 343 all_styles() 345 344 PREINIT: 346 owl_list l; 347 CODE: 348 { 349 owl_list_create(&l); 350 owl_global_get_style_names(&g, &l); 351 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv); 345 GPtrArray *l; 346 CODE: 347 { 348 l = owl_global_get_style_names(&g); 349 RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); 352 350 sv_2mortal((SV*)RETVAL); 353 351 } … … 355 353 RETVAL 356 354 CLEANUP: 357 owl_ list_cleanup(&l, g_free);355 owl_ptr_array_free(l, g_free); 358 356 359 357 … … 361 359 all_variables() 362 360 PREINIT: 363 owl_list l; 364 CODE: 365 { 366 owl_list_create(&l); 367 owl_dict_get_keys(owl_global_get_vardict(&g), &l); 368 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv); 361 GPtrArray *l; 362 CODE: 363 { 364 l = owl_dict_get_keys(owl_global_get_vardict(&g)); 365 RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); 369 366 sv_2mortal((SV*)RETVAL); 370 367 } … … 372 369 RETVAL 373 370 CLEANUP: 374 owl_ list_cleanup(&l, g_free);371 owl_ptr_array_free(l, g_free); 375 372 376 373 … … 378 375 all_keymaps() 379 376 PREINIT: 380 owl_listl;377 GPtrArray *l; 381 378 const owl_keyhandler *kh; 382 379 CODE: 383 380 { 384 381 kh = owl_global_get_keyhandler(&g); 385 owl_list_create(&l); 386 owl_keyhandler_get_keymap_names(kh, &l); 387 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv); 382 l = owl_keyhandler_get_keymap_names(kh); 383 RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv); 388 384 sv_2mortal((SV*)RETVAL); 389 385 } … … 391 387 RETVAL 392 388 CLEANUP: 393 owl_ list_cleanup(&l, g_free);389 owl_ptr_array_free(l, g_free); 394 390 395 391 void -
tester.c
r4e37d56 rce68f23 230 230 int owl_dict_regtest(void) { 231 231 owl_dict d; 232 owl_listl;232 GPtrArray *l; 233 233 int numfailed=0; 234 234 char *av = g_strdup("aval"), *bv = g_strdup("bval"), *cv = g_strdup("cval"), … … 251 251 252 252 FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d)); 253 owl_list_create(&l); 254 owl_dict_get_keys(&d, &l); 255 FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l)); 253 l = owl_dict_get_keys(&d); 254 FAIL_UNLESS("get_keys result size", 3 == l->len); 256 255 257 256 /* these assume the returned keys are sorted */ 258 FAIL_UNLESS("get_keys result val", 0==strcmp("a",owl_list_get_element(&l,0)));259 FAIL_UNLESS("get_keys result val", 0==strcmp("b",owl_list_get_element(&l,1)));260 FAIL_UNLESS("get_keys result val", 0==strcmp("c",owl_list_get_element(&l,2)));261 262 owl_ list_cleanup(&l, g_free);257 FAIL_UNLESS("get_keys result val", 0 == strcmp("a", l->pdata[0])); 258 FAIL_UNLESS("get_keys result val", 0 == strcmp("b", l->pdata[1])); 259 FAIL_UNLESS("get_keys result val", 0 == strcmp("c", l->pdata[2])); 260 261 owl_ptr_array_free(l, g_free); 263 262 owl_dict_cleanup(&d, NULL); 264 263 -
variable.c
r6829afc rce68f23 729 729 } 730 730 731 void owl_variable_dict_get_names(const owl_vardict *d, owl_list *l) {732 owl_dict_get_keys(d, l);731 CALLER_OWN GPtrArray *owl_variable_dict_get_names(const owl_vardict *d) { 732 return owl_dict_get_keys(d); 733 733 } 734 734
Note: See TracChangeset
for help on using the changeset viewer.