Changeset 10997
- Timestamp:
- Jan 9, 2007, 9:58:22 AM (19 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 5 added
- 9 edited
-
cmd.data/Makefile (modified) (2 diffs)
-
cmd.data/book.c (added)
-
cmd.data/book_commands.c (added)
-
cmd.data/init.c (modified) (4 diffs)
-
cmd.data/queueload.c (added)
-
include/data.h (modified) (1 diff)
-
include/macro.h (modified) (1 diff)
-
lib.data/Makefile (modified) (1 diff)
-
lib.data/book.c (modified) (5 diffs)
-
lib.data/page.c (added)
-
pantasks/Makefile (modified) (1 diff)
-
pantasks/init.c (modified) (2 diffs)
-
pantasks/init_server.c (modified) (2 diffs)
-
pantasks/ipptool2book.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/Makefile
r10342 r10997 14 14 $(SDIR)/applyfit.$(ARCH).o \ 15 15 $(SDIR)/box.$(ARCH).o \ 16 $(SDIR)/book.$(ARCH).o \ 17 $(SDIR)/book_commands.$(ARCH).o \ 16 18 $(SDIR)/center.$(ARCH).o \ 17 19 $(SDIR)/clear.$(ARCH).o \ … … 71 73 $(SDIR)/queuedrop.$(ARCH).o \ 72 74 $(SDIR)/queuelist.$(ARCH).o \ 75 $(SDIR)/queueload.$(ARCH).o \ 73 76 $(SDIR)/queuesize.$(ARCH).o \ 74 77 $(SDIR)/queuepush.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/init.c
r10307 r10997 5 5 int applyfit2d PROTO((int, char **)); 6 6 int box PROTO((int, char **)); 7 int book_command PROTO((int, char **)); 7 8 int center PROTO((int, char **)); 8 9 int circstats PROTO((int, char **)); … … 63 64 int ps PROTO((int, char **)); 64 65 int queuelist PROTO((int, char **)); 66 int queueload PROTO((int, char **)); 65 67 int queueinit PROTO((int, char **)); 66 68 int queuedelete PROTO((int, char **)); … … 117 119 {"applyfit2d", applyfit2d, "apply 2-d fit to new vector"}, 118 120 {"box", box, "draw a box on the plot"}, 121 {"book", book_command, "commands to manipulate book/page/word data"}, 119 122 {"center", center, "center image on coords"}, 120 123 {"circstats", circstats, "circular statistics"}, … … 183 186 {"queuedelete", queuedelete, "delete a queue"}, 184 187 {"queuelist", queuelist, "list defined queues"}, 188 {"queueload", queueload, "load queue from command"}, 185 189 {"queuesize", queuesize, "show queue size"}, 186 190 {"rd", rd, "load fits image"}, -
trunk/Ohana/src/opihi/include/data.h
r8190 r10997 16 16 } Queue; 17 17 18 typedef struct { 19 char *name; 20 int NWORDS; 21 int Nwords; 22 char **words; 23 char **value; 24 } Page; 25 26 typedef struct { 27 char *name; 28 int NPAGES; 29 int Npages; 30 Page **pages; 31 int *index; 32 char **pageIDs; 33 } Book; 34 18 35 void InitData (); 36 37 /* in book.c */ 38 void InitBooks (); 39 void InitBook (Book *book, char *name); 40 void FreeBook (Book *book); 41 Book *FindBook (char *name); 42 Book *GetBook (int where); 43 Book *CreateBook (char *name); 44 int DeleteBook (Book *book); 45 void ListBooks (); 46 47 /* in page.c */ 48 void InitPage (Page *page, char *name); 49 void FreePage (Page *page); 50 Page *FindPage (Book *book, char *name); 51 Page *GetPage (Book *book, int where); 52 Page *CreatePage (Book *book, char *name); 53 int DeletePage (Book *book, Page *page); 54 void ListPages (Book *book); 55 void ListWords (Page *page); 56 int BookSetWord (Page *page, char *word, char *value); 57 char *BookGetWord (Page *page, char *word); 19 58 20 59 /* 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 9 9 # general numerical functions (libdata) ##################### 10 10 srcs = \ 11 $(SDIR)/book.$(ARCH).o \ 12 $(SDIR)/page.$(ARCH).o \ 11 13 $(SDIR)/sort.$(ARCH).o \ 12 14 $(SDIR)/fft.$(ARCH).o \ -
trunk/Ohana/src/opihi/lib.data/book.c
r10847 r10997 1 1 # 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 list20 book create21 book newpage (book.page)22 book delpage (book.page)23 book newword (book.page.word) (value)24 */25 2 26 3 Book **books; /* book to store the list of all books */ 27 4 int Nbooks; /* number of currently defined books */ 28 5 int 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 }44 6 45 7 void InitBooks () { … … 49 11 } 50 12 51 /* list known books */ 52 void ListBooks () { 13 void 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 24 void 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 */ 39 Book *GetBook (int where) { 53 40 54 41 int i; 55 42 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]); 60 47 } 61 48 … … 67 54 for (i = 0; i < Nbooks; i++) { 68 55 if (!strcmp (books[i][0].name, name)) { 69 return ( &books[i][0]);56 return (books[i]); 70 57 } 71 58 } 72 59 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);87 60 } 88 61 … … 100 73 CHECK_REALLOCATE (books, Book *, NBOOKS, Nbooks, 16); 101 74 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); 106 76 books[N] = book; 107 77 return (book); … … 133 103 } 134 104 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); 141 106 return (TRUE); 142 107 } 143 108 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 */ 110 void ListBooks () { 406 111 407 112 int i; 408 113 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); 413 116 } 414 return (TRUE);117 return; 415 118 } 416 -
trunk/Ohana/src/opihi/pantasks/Makefile
r10694 r10997 57 57 $(SDIR)/task_command.$(ARCH).o \ 58 58 $(SDIR)/task_options.$(ARCH).o \ 59 $(SDIR)/version.$(ARCH).o 59 $(SDIR)/version.$(ARCH).o \ 60 $(SDIR)/ipptool2book.$(ARCH).o 60 61 61 62 client = \ -
trunk/Ohana/src/opihi/pantasks/init.c
r10694 r10997 21 21 int verbose PROTO((int, char **)); 22 22 int version PROTO((int, char **)); 23 int ipptool2book PROTO((int, char **)); 23 24 24 25 static Command cmds[] = { … … 44 45 {"version", version, "show version information"}, 45 46 {"verbose", verbose, "set/toggle verbose mode"}, 47 {"ipptool2book", ipptool2book, "convert queue with ipptool output to book"}, 46 48 }; 47 49 -
trunk/Ohana/src/opihi/pantasks/init_server.c
r8548 r10997 17 17 int version PROTO((int, char **)); 18 18 int server PROTO((int, char **)); 19 int ipptool2book PROTO((int, char **)); 19 20 20 21 static Command cmds[] = { … … 36 37 {"version", version, "show version information"}, 37 38 {"verbose", verbose, "set/toggle verbose mode"}, 39 {"ipptool2book", ipptool2book, "convert queue with ipptool output to book"}, 38 40 }; 39 41
Note:
See TracChangeset
for help on using the changeset viewer.
