IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11007


Ignore:
Timestamp:
Jan 10, 2007, 7:43:40 AM (19 years ago)
Author:
eugene
Message:

fixed macro function error, added restrictions to book selections

Location:
trunk/Ohana/src/opihi
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/macro.c

    r10996 r11007  
    11# 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 };
    112
    123int macro (int argc, char **argv) {
     
    2718  }
    2819
    29   N = sizeof (macro_command) / sizeof (Command);
     20  CommandF *cmd;
    3021
    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);
    3828  }
    3929
    40   /* sub-command was not found, pass argv[1..N] to macro_create */
    41   status = macro_create (argc, argv);
    4230  return (status);
    4331}
  • trunk/Ohana/src/opihi/cmd.data/book_commands.c

    r10997 r11007  
    220220
    221221  int where, N;
    222   char *varName;
     222  char *varName, *keyName, *keyValue;
    223223  Book *book;
    224224  Page *page;
     
    231231  }
    232232
     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
    233242  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");
    235244    return FALSE;
    236245  }
     
    244253  }
    245254
    246   page = GetPage (book, where);
     255  if (keyName == NULL) {
     256    page = GetPage (book, where);
     257  } else {
     258    page = GetPageRestricted (book, where, keyName, keyValue);
     259  }
    247260  if (page == NULL) {
    248261    gprint (GP_ERR, "page %s in book %s not found\n", argv[2], argv[1]);
  • trunk/Ohana/src/opihi/include/data.h

    r10997 r11007  
    5050Page *FindPage (Book *book, char *name);
    5151Page *GetPage (Book *book, int where);
     52Page *GetPageRestricted (Book *book, int where, char *keyName, char *keyValue);
    5253Page *CreatePage (Book *book, char *name);
    5354int DeletePage (Book *book, Page *page);
  • trunk/Ohana/src/opihi/lib.data/page.c

    r10997 r11007  
    2424}
    2525
    26 /* return the given book */
     26/* return the given page */
    2727Page *GetPage (Book *book, int where) {
    2828
     
    3333  if (where >= book[0].Npages) return NULL;
    3434  return (book[0].pages[where]);
     35}
     36
     37/* return the given page with key restrictions */
     38Page *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]);
    3577}
    3678
  • trunk/Ohana/src/opihi/lib.shell/ListOps.c

    r10846 r11007  
    111111  char *comm;
    112112  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);
    116117
    117118  status = !strcmp (comm, "macro");
     
    120121 
    121122  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);
    136126  free (this_macro);
     127
     128  if (cmd == NULL) {
     129    return (FALSE);
     130  }
     131
    137132  return (TRUE);
    138 
    139133}
    140134
  • trunk/Ohana/src/opihi/lib.shell/Makefile

    r10342 r11007  
    2222$(SDIR)/macro_delete.$(ARCH).o          \
    2323$(SDIR)/macro_edit.$(ARCH).o            \
     24$(SDIR)/macro_funcs.$(ARCH).o           \
    2425$(SDIR)/macro_exec.$(ARCH).o            \
    2526$(SDIR)/macro_list.$(ARCH).o            \
Note: See TracChangeset for help on using the changeset viewer.