Changeset 11007
- Timestamp:
- Jan 10, 2007, 7:43:40 AM (19 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 1 added
- 6 edited
-
cmd.basic/macro.c (modified) (2 diffs)
-
cmd.data/book_commands.c (modified) (3 diffs)
-
include/data.h (modified) (1 diff)
-
lib.data/page.c (modified) (2 diffs)
-
lib.shell/ListOps.c (modified) (2 diffs)
-
lib.shell/Makefile (modified) (1 diff)
-
lib.shell/macro_funcs.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/macro.c
r10996 r11007 1 1 # include "basic.h" 2 3 static Command macro_command[] = {4 {"create", macro_create, "create a macro *"},5 {"delete", macro_delete, "delete a macro *"},6 {"list", macro_list_f, "list a macro *"},7 {"edit", macro_edit, "edit a macro <not working yet!> *"},8 {"read", macro_read, "read a macro from a file <not working yet!> *"},9 {"write", macro_write, "write a macro to a file <not working yet!> *"}10 };11 2 12 3 int macro (int argc, char **argv) { … … 27 18 } 28 19 29 N = sizeof (macro_command) / sizeof (Command);20 CommandF *cmd; 30 21 31 /* find the macro sub-command which matches from the list. */ 32 /* if sub-command is not found, assume this is creating a new macro */ 33 for (i = 0; i < N; i++) { 34 if (!strcmp (macro_command[i].name, argv[1])) { 35 status = (*macro_command[i].func) (argc - 1, argv + 1); 36 return (status); 37 } 22 cmd = find_macro_command (argv[1]); 23 if (cmd != NULL) { 24 status = (*cmd) (argc - 1, argv + 1); 25 } else { 26 /* sub-command was not found, pass argv[1..N] to macro_create */ 27 status = macro_create (argc, argv); 38 28 } 39 29 40 /* sub-command was not found, pass argv[1..N] to macro_create */41 status = macro_create (argc, argv);42 30 return (status); 43 31 } -
trunk/Ohana/src/opihi/cmd.data/book_commands.c
r10997 r11007 220 220 221 221 int where, N; 222 char *varName ;222 char *varName, *keyName, *keyValue; 223 223 Book *book; 224 224 Page *page; … … 231 231 } 232 232 233 keyName = NULL; 234 if ((N = get_argument (argc, argv, "-key"))) { 235 remove_argument (N, &argc, argv); 236 keyName = strcreate (argv[N]); 237 remove_argument (N, &argc, argv); 238 keyValue = strcreate (argv[N]); 239 remove_argument (N, &argc, argv); 240 } 241 233 242 if (argc != 3) { 234 gprint (GP_ERR, "USAGE: book getpage (book) (where) [-var var] \n");243 gprint (GP_ERR, "USAGE: book getpage (book) (where) [-var var] [-key key value]\n"); 235 244 return FALSE; 236 245 } … … 244 253 } 245 254 246 page = GetPage (book, where); 255 if (keyName == NULL) { 256 page = GetPage (book, where); 257 } else { 258 page = GetPageRestricted (book, where, keyName, keyValue); 259 } 247 260 if (page == NULL) { 248 261 gprint (GP_ERR, "page %s in book %s not found\n", argv[2], argv[1]); -
trunk/Ohana/src/opihi/include/data.h
r10997 r11007 50 50 Page *FindPage (Book *book, char *name); 51 51 Page *GetPage (Book *book, int where); 52 Page *GetPageRestricted (Book *book, int where, char *keyName, char *keyValue); 52 53 Page *CreatePage (Book *book, char *name); 53 54 int DeletePage (Book *book, Page *page); -
trunk/Ohana/src/opihi/lib.data/page.c
r10997 r11007 24 24 } 25 25 26 /* return the given book*/26 /* return the given page */ 27 27 Page *GetPage (Book *book, int where) { 28 28 … … 33 33 if (where >= book[0].Npages) return NULL; 34 34 return (book[0].pages[where]); 35 } 36 37 /* return the given page with key restrictions */ 38 Page *GetPageRestricted (Book *book, int where, char *keyName, char *keyValue) { 39 40 int i; 41 int N, Nout; 42 char *value; 43 44 if (where < 0) where += book[0].Npages; 45 if (where < 0) return NULL; 46 if (where >= book[0].Npages) return NULL; 47 48 if (where >= 0) { 49 N = -1; 50 for (i = 0; (i < book[0].Npages) && (N < where); i++) { 51 value = BookGetWord (book[0].pages[i], keyName); 52 if ((value == NULL) && !strcmp (keyValue, "NULL")) { 53 N++; 54 Nout = i; 55 } 56 if ((value != NULL) && !strcmp (keyValue, value)) { 57 N++; 58 Nout = i; 59 } 60 } 61 } else { 62 N = 0; 63 for (i = book[0].Npages - 1; (i >= 0) && (N > where); i--) { 64 value = BookGetWord (book[0].pages[i], keyName); 65 if ((value == NULL) && !strcmp (keyValue, "NULL")) { 66 N--; 67 } 68 if ((value != NULL) && !strcmp (keyValue, value)) { 69 N--; 70 } 71 } 72 } 73 74 if (N != where) return NULL; 75 76 return (book[0].pages[Nout]); 35 77 } 36 78 -
trunk/Ohana/src/opihi/lib.shell/ListOps.c
r10846 r11007 111 111 char *comm; 112 112 char *this_macro; 113 114 comm = thisword (line); 115 if (comm == (char *) NULL) return (FALSE); 113 CommandF *cmd; 114 115 comm = thisword (line); 116 if (comm == NULL) return (FALSE); 116 117 117 118 status = !strcmp (comm, "macro"); … … 120 121 121 122 this_macro = thisword (nextword (line)); 122 123 if (this_macro == (char *)NULL) return (FALSE); 124 125 N = sizeof (in_macro) / sizeof (Command); 126 127 /* find the macro sub-command which matches from the list. */ 128 /* if sub-command is not found, assume this is creating a new macro */ 129 for (i = 0; i < N; i++) { 130 if (!strcmp (in_macro[i].name, this_macro)) { 131 free (this_macro); 132 return (FALSE); 133 } 134 } 135 123 if (this_macro == NULL) return (FALSE); 124 125 cmd = find_macro_command (this_macro); 136 126 free (this_macro); 127 128 if (cmd == NULL) { 129 return (FALSE); 130 } 131 137 132 return (TRUE); 138 139 133 } 140 134 -
trunk/Ohana/src/opihi/lib.shell/Makefile
r10342 r11007 22 22 $(SDIR)/macro_delete.$(ARCH).o \ 23 23 $(SDIR)/macro_edit.$(ARCH).o \ 24 $(SDIR)/macro_funcs.$(ARCH).o \ 24 25 $(SDIR)/macro_exec.$(ARCH).o \ 25 26 $(SDIR)/macro_list.$(ARCH).o \
Note:
See TracChangeset
for help on using the changeset viewer.
