IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10997


Ignore:
Timestamp:
Jan 9, 2007, 9:58:22 AM (19 years ago)
Author:
eugene
Message:

added book / page commands

Location:
trunk/Ohana/src/opihi
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r10342 r10997  
    1414$(SDIR)/applyfit.$(ARCH).o      \
    1515$(SDIR)/box.$(ARCH).o           \
     16$(SDIR)/book.$(ARCH).o          \
     17$(SDIR)/book_commands.$(ARCH).o \
    1618$(SDIR)/center.$(ARCH).o        \
    1719$(SDIR)/clear.$(ARCH).o         \
     
    7173$(SDIR)/queuedrop.$(ARCH).o     \
    7274$(SDIR)/queuelist.$(ARCH).o     \
     75$(SDIR)/queueload.$(ARCH).o     \
    7376$(SDIR)/queuesize.$(ARCH).o     \
    7477$(SDIR)/queuepush.$(ARCH).o     \
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r10307 r10997  
    55int applyfit2d       PROTO((int, char **));
    66int box              PROTO((int, char **));
     7int book_command     PROTO((int, char **));
    78int center           PROTO((int, char **));
    89int circstats        PROTO((int, char **));
     
    6364int ps               PROTO((int, char **));
    6465int queuelist        PROTO((int, char **));
     66int queueload        PROTO((int, char **));
    6567int queueinit        PROTO((int, char **));
    6668int queuedelete      PROTO((int, char **));
     
    117119  {"applyfit2d",   applyfit2d,       "apply 2-d fit to new vector"},
    118120  {"box",          box,              "draw a box on the plot"},
     121  {"book",         book_command,     "commands to manipulate book/page/word data"},
    119122  {"center",       center,           "center image on coords"},
    120123  {"circstats",    circstats,        "circular statistics"},
     
    183186  {"queuedelete",  queuedelete,      "delete a queue"},
    184187  {"queuelist",    queuelist,        "list defined queues"},
     188  {"queueload",    queueload,        "load queue from command"},
    185189  {"queuesize",    queuesize,        "show queue size"},
    186190  {"rd",           rd,               "load fits image"},
  • trunk/Ohana/src/opihi/include/data.h

    r8190 r10997  
    1616} Queue;
    1717
     18typedef struct {
     19  char *name;
     20  int NWORDS;
     21  int Nwords;
     22  char **words;
     23  char **value;
     24} Page;
     25
     26typedef struct {
     27  char *name;
     28  int NPAGES;
     29  int Npages;
     30  Page **pages;
     31  int *index;
     32  char **pageIDs;
     33} Book;
     34
    1835void InitData ();
     36
     37/* in book.c */
     38void InitBooks ();
     39void InitBook (Book *book, char *name);
     40void FreeBook (Book *book);
     41Book *FindBook (char *name);
     42Book *GetBook (int where);
     43Book *CreateBook (char *name);
     44int DeleteBook (Book *book);
     45void ListBooks ();
     46
     47/* in page.c */
     48void InitPage (Page *page, char *name);
     49void FreePage (Page *page);
     50Page *FindPage (Book *book, char *name);
     51Page *GetPage (Book *book, int where);
     52Page *CreatePage (Book *book, char *name);
     53int DeletePage (Book *book, Page *page);
     54void ListPages (Book *book);
     55void ListWords (Page *page);
     56int BookSetWord (Page *page, char *word, char *value);
     57char *BookGetWord (Page *page, char *word);
    1958
    2059/* in queues.c */
  • trunk/Ohana/src/opihi/include/macro.h

    r2598 r10997  
    1 static Command in_macro[] = {
    2   {"create", macro_create, "create a macro *"},
    3   {"delete", macro_delete, "delete a macro *"},
    4   {"list",   macro_list_f, "list a macro *"},
    5   {"edit",   macro_edit,   "edit a macro <not working yet!> *"},
    6   {"read",   macro_read,   "read a macro from a file <not working yet!> *"},
    7   {"write",  macro_write,  "write a macro to a file <not working yet!> *"}
    8 };
    9 
    10 /*** need to encapsulate the macro command lookup ***/
  • trunk/Ohana/src/opihi/lib.data/Makefile

    r10342 r10997  
    99# general numerical functions (libdata) #####################
    1010srcs = \
     11$(SDIR)/book.$(ARCH).o                  \
     12$(SDIR)/page.$(ARCH).o                  \
    1113$(SDIR)/sort.$(ARCH).o                  \
    1214$(SDIR)/fft.$(ARCH).o                   \
  • trunk/Ohana/src/opihi/lib.data/book.c

    r10847 r10997  
    11# include "data.h"
    2 
    3 typedef struct {
    4   int Nvalues;
    5   char *id;
    6   char **word;
    7   char **value;
    8 } Page;
    9 
    10 typedef struct {
    11   int Npages;
    12   char *name;
    13   int *index;
    14   char **sorted;
    15   Page *pages;
    16 } Book;
    17 
    18 /* commands:
    19    book list
    20    book create
    21    book newpage (book.page)
    22    book delpage (book.page)
    23    book newword (book.page.word) (value)
    24 */
    252
    263Book **books;   /* book to store the list of all books */
    274int    Nbooks;   /* number of currently defined books */
    285int    NBOOKS;   /* number of currently allocated books */
    29 
    30 int CreatePage (Book *book, char *id) {
    31   int N;
    32 
    33   N = book[0].Npages;
    34   book[0].page[N].id = strcreate (name);
    35   book[0].page[N].Nvalues = 0;
    36   book[0].Npages ++;
    37 
    38   if (book[0].Npages == book[0].NPAGES - 1) {
    39     REALLOC ();
    40   }
    41 
    42 
    43 }
    446
    457void InitBooks () {
     
    4911}
    5012
    51 /* list known books */
    52 void ListBooks () {
     13void InitBook (Book *book, char *name) {
     14
     15    book[0].name = strcreate (name);
     16
     17    book[0].Npages = 0;
     18    book[0].NPAGES = 16;
     19    ALLOCATE (book[0].pages, Page *, book[0].NPAGES);
     20    ALLOCATE (book[0].pageIDs, char *, book[0].NPAGES);
     21    ALLOCATE (book[0].index, int, book[0].NPAGES);
     22}
     23
     24void FreeBook (Book *book) {
     25
     26    int i;
     27
     28    free (book[0].name);
     29    for (i = 0; i < book[0].Npages; i++) {
     30        FreePage (book[0].pages[i]);
     31        free (book[0].pageIDs[i]);
     32    }
     33    free (book[0].pages);
     34    free (book[0].pageIDs);
     35    free (book[0].index);
     36}
     37
     38/* return the given book */
     39Book *GetBook (int where) {
    5340
    5441  int i;
    5542
    56   for (i = 0; i < Nbooks; i++) {
    57     gprint (GP_ERR, "%-15s %3d\n", books[i][0].name, books[i][0].Nlines);
    58   }
    59   return;
     43  if (where < 0) where += Nbooks;
     44  if (where < 0) return NULL;
     45  if (where >= Nbooks) return NULL;
     46  return (books[where]);
    6047}
    6148
     
    6754  for (i = 0; i < Nbooks; i++) {
    6855    if (!strcmp (books[i][0].name, name)) {
    69       return (&books[i][0]);
     56      return (books[i]);
    7057    }
    7158  }
    7259  return (NULL);
    73 }
    74 
    75 /* make a new named book */
    76 int InitBook (Book *book) {
    77 
    78   int i;
    79 
    80   for (i = 0; i < book[0].Nlines; i++) {
    81     free (book[0].lines[i]);
    82   }
    83   book[0].Nlines = 0;
    84   book[0].NLINES = 16;
    85   REALLOCATE (book[0].lines, char *, book[0].NLINES);
    86   return (TRUE);
    8760}
    8861
     
    10073  CHECK_REALLOCATE (books, Book *, NBOOKS, Nbooks, 16);
    10174  ALLOCATE (book, Book, 1);
    102   book[0].Nlines = 0;
    103   book[0].NLINES = 16;
    104   book[0].name = strcreate (name);
    105   ALLOCATE (book[0].lines, char *, book[0].NLINES);
     75  InitBook (book, name);
    10676  books[N] = book;
    10777  return (book);
     
    133103  }
    134104
    135   free (book[0].name);
    136   for (i = 0; i < book[0].Nlines; i++) {
    137     free (book[0].lines[i]);
    138   }
    139   free (book[0].lines);
    140   free (book);
     105  FreeBook (book);
    141106  return (TRUE);
    142107}
    143108
    144 void PushNamedBook (char *name, char *line) {
    145 
    146   Book *book;
    147  
    148   book = FindBook (name);
    149   if (book == NULL) {
    150     book = CreateBook (name);
    151   }
    152   PushBook (book, line);
    153   return;
    154 }
    155 
    156 /* push line onto book.  return chars create new lines */
    157 void PushBook (Book *book, char *line) {
    158 
    159   int N;
    160   char *p, *q;
    161 
    162   p = line;
    163   q = strchr (line, '\n');
    164   N = book[0].Nlines;
    165   while (q != NULL) {
    166     book[0].lines[N] = strncreate (p, q - p);
    167     N++;
    168     CHECK_REALLOCATE (book[0].lines, char *, book[0].NLINES, N, 16);
    169     p = q + 1;
    170     q = strchr (p, '\n');
    171   }   
    172   if (*p) {
    173     book[0].lines[N] = strcreate (p);
    174     N++;
    175     CHECK_REALLOCATE (book[0].lines, char *, book[0].NLINES, N, 16);
    176   }
    177   book[0].Nlines = N;
    178   return;
    179 }
    180 
    181 // return a newly allocated string containing the requested key value
    182 char *ChooseSingleKey (char *line, int Key) {
    183 
    184   int i;
    185   char *key, *p;
    186 
    187   if (Key == -1) {
    188     key = strcreate (line);
    189     return (key);
    190   }
    191 
    192   key = line;
    193   for (i = 0; (i < Key) && (key != NULL); i++) {
    194     p = nextword (key);
    195     key = p;
    196   }
    197   key = thisword (key);
    198   return (key);
    199 }
    200 
    201 /* construct merged key given keylist of the form K:N:M */
    202 char *ChooseKey (char *line, char *keylist) {
    203 
    204   char *output, *entry, *key, *p, *q;
    205   int first, keynum;
    206 
    207   if (line == NULL) return (NULL);
    208   if (keylist == NULL) return (line);
    209 
    210   ALLOCATE (output, char, strlen(line) + 1);
    211   memset (output, 0, strlen(line) + 1);
    212 
    213   first = TRUE;
    214   p = q = keylist;
    215   while (q != NULL) {
    216     q = strchr (p, ':');
    217     if (q == NULL) {
    218       entry = strcreate (p);
    219     } else {
    220       entry = strncreate (p, q - p);
    221     }
    222     keynum = atoi (entry);
    223     free (entry);
    224 
    225     key = ChooseSingleKey (line, keynum);
    226 
    227     if (!first) strcat (output, ":");
    228     if (key) {
    229         strcat (output, key);
    230         free (key);
    231     }
    232 
    233     if (q != NULL) p = q + 1;
    234     first = FALSE;
    235   }
    236   return (output);
    237 }
    238 
    239 /* push line onto book, skipping existing matches (optionally by key) */
    240 void PushBookUnique (Book *book, char *line, char *Key) {
    241 
    242   int i, j, N, found;
    243   char *p, *q, *key1, *key2;
    244   Book tmp;
    245 
    246   /* init tmp book */
    247   tmp.Nlines = 0;
    248   tmp.NLINES = 16;
    249   ALLOCATE (tmp.lines, char *, tmp.NLINES);
    250 
    251   /* push entries on tmp book */
    252   p = line;
    253   q = strchr (line, '\n');
    254   N = tmp.Nlines;
    255   while (q != NULL) {
    256     tmp.lines[N] = strncreate (p, q - p);
    257     N++;
    258     CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
    259     p = q + 1;
    260     q = strchr (p, '\n');
    261   }   
    262   if (*p) {
    263     tmp.lines[N] = strcreate (p);
    264     N++;
    265     CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
    266   }
    267   tmp.Nlines = N;
    268 
    269   /* add unique entries in tmp to book */
    270   for (i = 0; i < tmp.Nlines; i++) {
    271     key1 = ChooseKey (tmp.lines[i], Key);
    272     if (key1 == NULL) continue;
    273     found = FALSE;
    274     for (j = 0; !found && (j < book[0].Nlines); j++) {
    275       key2 = ChooseKey (book[0].lines[j], Key);
    276       if (key2 == NULL) continue;
    277       found = !strcmp (key1, key2);
    278       free (key2);
    279     }     
    280     if (!found) PushBook (book, tmp.lines[i]);
    281     free (key1);
    282   }
    283   for (i = 0; i < tmp.Nlines; i++) {
    284     free (tmp.lines[i]);
    285   }
    286   free (tmp.lines);
    287   return;
    288 }
    289 
    290 /* push line onto book, replacing matches (optionally by Key) */
    291 void PushBookReplace (Book *book, char *line, char *Key) {
    292 
    293   int i, j, N, found;
    294   char *p, *q, *key1, *key2;
    295   Book tmp;
    296 
    297   /* init tmp book */
    298   tmp.Nlines = 0;
    299   tmp.NLINES = 16;
    300   ALLOCATE (tmp.lines, char *, tmp.NLINES);
    301 
    302   /* push entries on tmp book */
    303   p = line;
    304   q = strchr (line, '\n');
    305   N = tmp.Nlines;
    306   while (q != NULL) {
    307     tmp.lines[N] = strncreate (p, q - p);
    308     N++;
    309     CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
    310     p = q + 1;
    311     q = strchr (p, '\n');
    312   }   
    313   if (*p) {
    314     tmp.lines[N] = strcreate (p);
    315     N++;
    316     CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
    317   }
    318   tmp.Nlines = N;
    319 
    320   /* add unique entries in tmp to book */
    321   for (i = 0; i < tmp.Nlines; i++) {
    322     key1 = ChooseKey (tmp.lines[i], Key);
    323     if (key1 == NULL) continue;
    324     found = FALSE;
    325     for (j = 0; !found && (j < book[0].Nlines); j++) {
    326       key2 = ChooseKey (book[0].lines[j], Key);
    327       if (key2 == NULL) continue;
    328       found = !strcmp (key1, key2);
    329       if (found) {
    330         // XXX do I need to free book[0].lines[j]??
    331         book[0].lines[j] = strcreate (tmp.lines[i]);
    332       }
    333       free (key2);
    334     }     
    335     if (!found) PushBook (book, tmp.lines[i]);
    336     free (key1);
    337   }
    338   for (i = 0; i < tmp.Nlines; i++) {
    339     free (tmp.lines[i]);
    340   }
    341   free (tmp.lines);
    342   return;
    343 }
    344 
    345 char *PopBook (Book *book) {
    346 
    347   int i, NLINES_2;
    348   char *line;
    349 
    350   if (book[0].Nlines == 0) return (NULL);
    351   line = book[0].lines[0];
    352 
    353   for (i = 0; i < book[0].Nlines - 1; i++) {
    354     book[0].lines[i] = book[0].lines[i+1];
    355   }
    356   book[0].Nlines --;
    357 
    358   /* shrink book allocation if small enough */
    359   NLINES_2 = MAX (16, book[0].NLINES / 2);
    360   if (book[0].Nlines < NLINES_2) {
    361     book[0].NLINES = NLINES_2;
    362     REALLOCATE (book[0].lines, char *, book[0].NLINES);
    363   }   
    364   return (line);
    365 }
    366 
    367 /* pop the first entry which for which the key matches */
    368 char *PopBookMatch (Book *book, char *Key, char *value) {
    369 
    370   int i, choice, NLINES_2;
    371   char *line, *test;
    372 
    373   if (book[0].Nlines == 0) return (NULL);
    374 
    375   /* find the matching key */
    376   choice = -1;
    377   for (i = 0; (i < book[0].Nlines) && (choice == -1); i++) {
    378       test = ChooseKey (book[0].lines[i], Key);
    379       if (test == NULL) continue;
    380       if (strcmp (value, test)) {
    381         free (test);
    382         continue;
    383       }
    384       free (test);
    385       choice = i;
    386   }
    387   if (choice == -1) return NULL;
    388 
    389   line = book[0].lines[choice];
    390 
    391   for (i = choice; i < book[0].Nlines - 1; i++) {
    392     book[0].lines[i] = book[0].lines[i+1];
    393   }
    394   book[0].Nlines --;
    395 
    396   /* shrink book allocation if small enough */
    397   NLINES_2 = MAX (16, book[0].NLINES / 2);
    398   if (book[0].Nlines < NLINES_2) {
    399     book[0].NLINES = NLINES_2;
    400     REALLOCATE (book[0].lines, char *, book[0].NLINES);
    401   }   
    402   return (line);
    403 }
    404 
    405 int PrintBook (Book *book) {
     109/* list known books */
     110void ListBooks () {
    406111
    407112  int i;
    408113
    409   if (book[0].Nlines == 0) return (TRUE);
    410 
    411   for (i = 0; i < book[0].Nlines; i++) {
    412     gprint (GP_LOG, "%s\n", book[0].lines[i]);
     114  for (i = 0; i < Nbooks; i++) {
     115    gprint (GP_ERR, "%-15s %3d\n", books[i][0].name, books[i][0].Npages);
    413116  }
    414   return (TRUE);
     117  return;
    415118}
    416 
  • trunk/Ohana/src/opihi/pantasks/Makefile

    r10694 r10997  
    5757$(SDIR)/task_command.$(ARCH).o \
    5858$(SDIR)/task_options.$(ARCH).o \
    59 $(SDIR)/version.$(ARCH).o
     59$(SDIR)/version.$(ARCH).o \
     60$(SDIR)/ipptool2book.$(ARCH).o
    6061
    6162client = \
  • trunk/Ohana/src/opihi/pantasks/init.c

    r10694 r10997  
    2121int verbose         PROTO((int, char **));
    2222int version         PROTO((int, char **));
     23int ipptool2book    PROTO((int, char **));
    2324
    2425static Command cmds[] = { 
     
    4445  {"version",    version,      "show version information"},
    4546  {"verbose",    verbose,      "set/toggle verbose mode"},
     47  {"ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    4648};
    4749
  • trunk/Ohana/src/opihi/pantasks/init_server.c

    r8548 r10997  
    1717int version         PROTO((int, char **));
    1818int server          PROTO((int, char **));
     19int ipptool2book    PROTO((int, char **));
    1920
    2021static Command cmds[] = { 
     
    3637  {"version",    version,       "show version information"},
    3738  {"verbose",    verbose,       "set/toggle verbose mode"},
     39  {"ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    3840};
    3941
Note: See TracChangeset for help on using the changeset viewer.