home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.lzh / EditLibr / ListStuff.cc < prev    next >
Text File  |  1994-04-23  |  8KB  |  296 lines

  1. /* -*- Mode: C -*- */
  2. /* ListStuff.cc - List stuff
  3.  * Created by Robert Heller on Mon Jan 20 00:19:54 1992
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Edit a Librarian Card Catalog file
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19.  
  20. #include <stream.h>
  21. #include <vBTree.h>
  22. #include <ctype.h>
  23. #ifdef MESSYDOS
  24. #include <CardRec.h>
  25. #include <ListRec.h>
  26. #else
  27. #include <CardRecord.h>
  28. #include <ListRecord.h>
  29. #endif
  30. #include <Terminal.h>
  31. #ifdef MESSYDOS
  32. #include <CmdScren.h>
  33. #include <LLScrPmt.h>
  34. #else
  35. #include <CommandScreen.h>
  36. #include <LLScrollPrompt.h>
  37. #endif
  38. #include "EditDefs.h"
  39. #include "EditGlob.h"
  40.  
  41. const Margin = 256;
  42.  
  43. extern int EditCard1(Key inkey);
  44.  
  45. int ListCards()
  46. {
  47.     CoreItem item;
  48.     Key searchkey;
  49.     static char title[80], line[LineLength];
  50.     Term->PromptLine(18,0,"Search prefix: ",searchkey,KeySize);
  51.     sprintf(title,"Ids matching %s",searchkey);
  52.     LLScrollPrompt IdList(title,3,0,80,15,20);
  53.     LineList* llist = (LineList*) 0;
  54.     LineList** ptr = &llist;
  55.     LineList* prev = (LineList*) 0;
  56.     if (Tree->SearchId(searchkey,&item)) {
  57.         do {
  58.             int fill;
  59.             char* p = line;
  60.             strcpy(p,item.key);
  61.             fill = KeySize - strlen(item.key);
  62.             p += strlen(item.key);
  63.             while (fill-- > 0) *p++ = ' ';
  64.             *p++ = ' ';
  65.             {
  66.                 CardRecord crec(&item.data);
  67.                 strcpy(p,crec->title);
  68.                 p += strlen(crec->title);
  69.             }
  70.             *p++ = 0;
  71.             LineList* newline = new LineList(line,0,prev);
  72.             *ptr = newline;
  73.             prev = newline;
  74.             ptr = &newline->nextline;
  75.             //cerr << "*** line = '" << line << "'\n";
  76.         } while (Tree->SearchIdAgain(&item));
  77.         if (llist != (LineList*) 0) {
  78.             if (IdList.Scroll(llist,"Card to edit (RETURN for more, q to exit):",title,KeySize) > 0) 
  79.                 EditCard1(title);
  80.             FreeLineList(llist);
  81.         }
  82.         return(-1);
  83.     } else {
  84.         Term->Message("No ids found");
  85.         return(1);
  86.     }
  87. }
  88.  
  89. int ListCardsFromList(char* title,ListRecord& list)
  90. {
  91.     CoreItem item;
  92.     static Key newkey;
  93.     static char line[LineLength];
  94.     LLScrollPrompt IdList(title,3,0,80,15,20);
  95.     LineList* llist = (LineList*) 0;
  96.     LineList** ptr = &llist;
  97.     LineList* prev = (LineList*) 0;
  98.     int numids = list.ElementCount();
  99.     for (int i = 0; i < numids; i++) {
  100.         if (Tree->SearchId(list[i],&item) && strlen(list[i]) == strlen(item.key)) {
  101.             int fill;
  102.             char* p = line;
  103.             strcpy(p,item.key);
  104.             fill = KeySize - strlen(item.key);
  105.             p += strlen(item.key);
  106.             while (fill-- > 0) *p++ = ' ';
  107.             *p++ = ' ';
  108.             {
  109.                 CardRecord crec(&item.data);
  110.                 strcpy(p,crec->title);
  111.                 p += strlen(crec->title);
  112.             }
  113.             *p++ = 0;
  114.             LineList* newline = new LineList(line,0,prev);
  115.             *ptr = newline;
  116.             prev = newline;
  117.             ptr = &newline->nextline;
  118.         }
  119.     }
  120.     if (llist != (LineList*) 0) {
  121.         if (IdList.Scroll(llist,"Card to edit (RETURN for more, q to exit):",title,KeySize) > 0) 
  122.             EditCard1(title);
  123.         FreeLineList(llist);
  124.     }
  125.     return(-1);
  126. }
  127.  
  128. int ListTitles()
  129. {
  130.     CoreItem item;
  131.     Key searchkey;
  132.     static char title[80],header[80],line[LineLength];
  133.     Term->PromptLine(18,0,"Search prefix: ",searchkey,KeySize);
  134.     sprintf(title,"Titles matching %s",searchkey);
  135.     LLScrollPrompt TitleList(title,3,0,80,15,20);
  136.     LineList* llist = (LineList*) 0;
  137.     LineList** ptr = &llist;
  138.     LineList* prev = (LineList*) 0;
  139.     int i;
  140.     int refnum = 0;
  141.     if (Tree->SearchTitle(searchkey,&item)) {
  142.         do {
  143.             refnum++;
  144.             sprintf(line,"%3d: %s",refnum,item.key);
  145.             LineList* newline = new LineList(line,0,prev);
  146.             *ptr = newline;
  147.             prev = newline;
  148.             ptr = &newline->nextline;
  149.         } while (Tree->SearchTitleAgain(&item));
  150.         if (llist != (LineList*) 0) {
  151.             if (refnum == 1) {
  152.                 if (Tree->SearchTitle(llist->thisline+5,&item)) {
  153.                     sprintf(header,"Ids for title %s",item.key);
  154.                     ListRecord rec(&item.data);
  155.                     if (rec.ElementCount() == 1) EditCard1(rec[0]);
  156.                     else if (rec.ElementCount() > 1)
  157.                         ListCardsFromList(header,rec);
  158.                 }
  159.             } else if (TitleList.Scroll(llist,"Ref#, RETURN for more, q to exit:",title,KeySize) > 0) {
  160.                 refnum = atoi(title);
  161.                 for (i = 1,prev = llist;
  162.                      prev != (LineList*)0 && i < refnum;
  163.                      prev = prev->nextline,i++) ;
  164.                 if (i == refnum) {
  165.                     if (Tree->SearchTitle(prev->thisline+5,&item)) {
  166.                         sprintf(header,"Ids for title %s",item.key);
  167.                         ListRecord rec(&item.data);
  168.                         if (rec.ElementCount() == 1) EditCard1(rec[0]);
  169.                         else if (rec.ElementCount() > 1)
  170.                             ListCardsFromList(header,rec);
  171.                     }
  172.                 } else Term->Message("Bad reference number");
  173.             }
  174.             FreeLineList(llist);
  175.         }
  176.         return(-1);
  177.     } else {
  178.         Term->Message("No titles found");
  179.         return(1);
  180.     }
  181. }
  182.  
  183. int ListAuthors()
  184. {
  185.     CoreItem item;
  186.     Key searchkey;
  187.     static char title[80],header[80],line[LineLength];
  188.     Term->PromptLine(18,0,"Search prefix: ",searchkey,KeySize);
  189.     sprintf(title,"Authors matching %s",searchkey);
  190.     LLScrollPrompt AuthorList(title,3,0,80,15,20);
  191.     LineList* llist = (LineList*) 0;
  192.     LineList** ptr = &llist;
  193.     LineList* prev = (LineList*) 0;
  194.     int refnum = 0;
  195.     int i;
  196.     if (Tree->SearchAuthor(searchkey,&item)) {
  197.         do {
  198.             refnum++;
  199.             sprintf(line,"%3d: %s",refnum,item.key);
  200.             LineList* newline = new LineList(line,0,prev);
  201.             *ptr = newline;
  202.             prev = newline;
  203.             ptr = &newline->nextline;
  204.         } while (Tree->SearchAuthorAgain(&item));
  205.         if (llist != (LineList*) 0) {
  206.             if (refnum == 1) {
  207.                 if (Tree->SearchAuthor(llist->thisline+5,&item)) {
  208.                     sprintf(header,"Ids for author %s",item.key);
  209.                     ListRecord rec(&item.data);
  210.                     if (rec.ElementCount() == 1) EditCard1(rec[0]);
  211.                     else if (rec.ElementCount() > 1)
  212.                         ListCardsFromList(header,rec);
  213.                 }
  214.             } else if (AuthorList.Scroll(llist,"Ref#, RETURN for more, q to exit:",title,KeySize) > 0) {
  215.                 refnum = atoi(title);
  216.                 for (i = 1,prev = llist;
  217.                      prev != (LineList*)0 && i < refnum;
  218.                      prev = prev->nextline,i++) ;
  219.                 if (i == refnum) {
  220.                     if (Tree->SearchAuthor(prev->thisline+5,&item)) {
  221.                         sprintf(header,"Ids for author %s",item.key);
  222.                         ListRecord rec(&item.data);
  223.                         if (rec.ElementCount() == 1) EditCard1(rec[0]);
  224.                         else if (rec.ElementCount() > 1)
  225.                             ListCardsFromList(header,rec);
  226.                     }
  227.                 } else Term->Message("Bad reference number");
  228.             }
  229.             FreeLineList(llist);
  230.         }
  231.         return(-1);
  232.     } else {
  233.         Term->Message("No authors found");
  234.         return(1);
  235.     }
  236. }
  237.  
  238. int ListSubjects()
  239. {
  240.     CoreItem item;
  241.     Key searchkey;
  242.     static char title[80],header[80],line[LineLength];
  243.     Term->PromptLine(18,0,"Search prefix: ",searchkey,KeySize);
  244.     sprintf(title,"Subjects matching %s",searchkey);
  245.     LLScrollPrompt SubjectList(title,3,0,80,15,20);
  246.     LineList* llist = (LineList*) 0;
  247.     LineList** ptr = &llist;
  248.     LineList* prev = (LineList*) 0;
  249.     int refnum = 0;
  250.     int i;
  251.     if (Tree->SearchSubj(searchkey,&item)) {
  252.         do {
  253.             refnum++;
  254.             sprintf(line,"%3d: %s",refnum,item.key);
  255.             LineList* newline = new LineList(line,0,prev);
  256.             *ptr = newline;
  257.             prev = newline;
  258.             ptr = &newline->nextline;
  259.         } while (Tree->SearchSubjAgain(&item));
  260.         if (llist != (LineList*) 0) {
  261.             if (refnum == 1) {
  262.                 if (Tree->SearchSubj(llist->thisline+5,&item)) {
  263.                     sprintf(header,"Ids for subject %s",item.key);
  264.                     ListRecord rec(&item.data);
  265.                     if (rec.ElementCount() == 1) EditCard1(rec[0]);
  266.                     else if (rec.ElementCount() > 1)
  267.                         ListCardsFromList(header,rec);
  268.                 }
  269.             } else if (SubjectList.Scroll(llist,"Ref#, RETURN for more, q to exit:",title,KeySize) > 0) {
  270.                 refnum = atoi(title);
  271.                 for (i = 1,prev = llist;
  272.                      prev != (LineList*)0 && i < refnum;
  273.                      prev = prev->nextline,i++) ;
  274.                 if (i == refnum) {
  275.                     if (Tree->SearchSubj(prev->thisline+5,&item)) {
  276.                         sprintf(header,"Ids for subject %s",item.key);
  277.                         ListRecord rec(&item.data);
  278.                         if (rec.ElementCount() == 1) EditCard1(rec[0]);
  279.                         else if (rec.ElementCount() > 1)
  280.                             ListCardsFromList(header,rec);
  281.                     }
  282.                 } else Term->Message("Bad reference number");
  283.             }
  284.             FreeLineList(llist);
  285.         }
  286.         return(-1);
  287.     } else {
  288.         Term->Message("No subjects found");
  289.         return(1);
  290.     }
  291. }
  292.  
  293.  
  294.  
  295.  
  296.