Changeset d275eb2
- Timestamp:
- Jan 2, 2011, 3:31:58 PM (14 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- 2bc6ad35
- Parents:
- f640876
- git-author:
- David Benjamin <davidben@mit.edu> (12/15/10 13:18:34)
- git-committer:
- David Benjamin <davidben@mit.edu> (01/02/11 15:31:58)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
rb31f1c9 rd275eb2 1670 1670 char *lastrv = NULL, *newbuff; 1671 1671 char **commands; 1672 int ncommands,i;1672 int i; 1673 1673 if (argc < 2) { 1674 1674 owl_function_makemsg("Invalid arguments to 'multi' command."); … … 1688 1688 } 1689 1689 } 1690 commands = atokenize(newbuff, ";", &ncommands);1691 for (i =0; i<ncommands; i++) {1690 commands = g_strsplit_set(newbuff, ";", 0); 1691 for (i = 0; commands[i] != NULL; i++) { 1692 1692 if (lastrv) { 1693 1693 owl_free(lastrv); … … 1696 1696 } 1697 1697 owl_free(newbuff); 1698 atokenize_delete(commands, ncommands);1698 g_strfreev(commands); 1699 1699 return lastrv; 1700 1700 } -
keybinding.c
r8a921b5 rd275eb2 39 39 int nktokens, i; 40 40 41 ktokens = atokenize(keyseq, " ", &nktokens);42 if (!ktokens) return(-1);43 if (nktokens > OWL_KEYMAP_MAXSTACK) {44 atokenize_delete(ktokens, nktokens);41 ktokens = g_strsplit_set(keyseq, " ", 0); 42 nktokens = g_strv_length(ktokens); 43 if (nktokens < 1 || nktokens > OWL_KEYMAP_MAXSTACK) { 44 g_strfreev(ktokens); 45 45 return(-1); 46 46 } … … 48 48 for (i=0; i<nktokens; i++) { 49 49 kb->keys[i] = owl_keypress_fromstring(ktokens[i]); 50 if (kb->keys[i] == ERR) { 51 atokenize_delete(ktokens, nktokens);50 if (kb->keys[i] == ERR) { 51 g_strfreev(ktokens); 52 52 owl_free(kb->keys); 53 53 return(-1); … … 55 55 } 56 56 kb->len = nktokens; 57 atokenize_delete(ktokens, nktokens);57 g_strfreev(ktokens); 58 58 return(0); 59 59 } -
util.c
rfa90c34 rd275eb2 11 11 #include <glib/gstdio.h> 12 12 #include <glib-object.h> 13 14 char **atokenize(const char *buffer, const char *sep, int *i)15 {16 /* each element of return must be freed by user */17 char **args;18 char *workbuff, *foo;19 int done=0, first=1, count=0;20 21 workbuff = owl_strdup(buffer);22 23 args=NULL;24 while (!done) {25 if (first) {26 first=0;27 foo=strtok(workbuff, sep);28 } else {29 foo=strtok(NULL, sep);30 }31 if (foo==NULL) {32 done=1;33 } else {34 args=owl_realloc(args, sizeof(char *) * (count+1));35 args[count] = owl_strdup(foo);36 count++;37 }38 }39 *i=count;40 owl_free(workbuff);41 return(args);42 }43 13 44 14 const char *skiptokens(const char *buff, int n) { … … 127 97 } 128 98 129 void atokenize_delete(char **tok, int nels)130 {131 int i;132 for (i=0; i<nels; i++) {133 owl_free(tok[i]);134 }135 owl_free(tok);136 }137 138 139 99 void owl_parse_delete(char **argv, int argc) 140 100 { -
variable.c
rbc14adc rd275eb2 952 952 int nenums, val; 953 953 if (newval == NULL) return(0); 954 enums = atokenize(v->validsettings, ",", &nenums);955 if (enums == NULL) return(0);956 atokenize_delete(enums, nenums);954 enums = g_strsplit_set(v->validsettings, ",", 0); 955 nenums = g_strv_length(enums); 956 g_strfreev(enums); 957 957 val = *(const int*)newval; 958 958 if (val < 0 || val >= nenums) { … … 964 964 int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval) { 965 965 char **enums; 966 int nenums,i, val=-1;966 int i, val=-1; 967 967 if (newval == NULL) return(-1); 968 enums = atokenize(v->validsettings, ",", &nenums); 969 if (enums == NULL) return(-1); 970 for (i=0; i<nenums; i++) { 968 enums = g_strsplit_set(v->validsettings, ",", 0); 969 for (i = 0; enums[i] != NULL; i++) { 971 970 if (0==strcmp(newval, enums[i])) { 972 971 val = i; 973 972 } 974 973 } 975 atokenize_delete(enums, nenums);974 g_strfreev(enums); 976 975 if (val == -1) return(-1); 977 976 return (v->set_fn(v, &val)); … … 986 985 return -1; 987 986 } 988 enums = atokenize(v->validsettings, ",", &nenums); 987 enums = g_strsplit_set(v->validsettings, ",", 0); 988 nenums = g_strv_length(enums); 989 989 i = *(const int*)val; 990 990 if (i<0 || i>=nenums) { 991 991 snprintf(buf, bufsize, "<invalid:%d>",i); 992 atokenize_delete(enums, nenums);992 g_strfreev(enums); 993 993 return(-1); 994 994 } 995 995 snprintf(buf, bufsize, "%s", enums[i]); 996 atokenize_delete(enums, nenums);996 g_strfreev(enums); 997 997 return 0; 998 998 }
Note: See TracChangeset
for help on using the changeset viewer.