home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / rolodex / part2 / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  6.6 KB  |  285 lines

  1. #include <sys/file.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <sgtty.h>
  5. #include <sys/time.h>
  6. #include <signal.h>
  7.  
  8. #include "sys5.h"
  9.  
  10. #ifdef TMC
  11. #include <ctools.h>
  12. #else
  13. #include "ctools.h"
  14. #endif
  15. #include "args.h"
  16. #include "menu.h"
  17. #include "mem.h"
  18.  
  19. #include "rolofiles.h"
  20. #include "rolodefs.h"
  21. #include "datadef.h"
  22. #include "choices.h"
  23.  
  24.  
  25. print_short ()
  26.  
  27. /* print the names and phone numbers of everyone in the rolodex. */
  28.  
  29.  
  30.   Ptr_Rolo_List rptr;
  31.   Ptr_Rolo_Entry entry;
  32.         
  33.   rptr = Begin_Rlist;
  34.   if (rptr == 0) {
  35.      fprintf(stderr,"No entries to print out...\n");
  36.      return;
  37.   }
  38.    
  39.   fprintf (
  40.      stdout,
  41.      "\nNAME                      WORK PHONE                HOME PHONE"
  42.    );
  43.   fprintf (
  44.      stdout,
  45.      "\n----                      ----------                ----------\n\n\n"
  46.    );
  47.  
  48.    while (rptr != 0) {
  49.         entry = get_entry(rptr);
  50.         fprintf (
  51.             stdout,
  52.             "%-25s %-25s %-25s\n",
  53.             get_basic_rolo_field((int) R_NAME,entry),
  54.             get_basic_rolo_field((int) R_WORK_PHONE,entry),
  55.             get_basic_rolo_field((int) R_HOME_PHONE,entry)
  56.          );   
  57.          rptr = get_next_link(rptr);
  58.    }       
  59.    
  60.  }  
  61.    
  62.  
  63. person_match (person,entry) char *person; Ptr_Rolo_Entry entry; 
  64.  
  65. /* Match against a rolodex entry's Name and Company fields. */
  66. /* Thus if I say 'rolo CCA' I will find people who work at CCA. */
  67. /* This is good because sometimes you will forget a name but remember */
  68. /* the company the person works for. */
  69.  
  70.   char *name, *company;        
  71.   int len;
  72.   len = strlen(person);
  73.   name = get_basic_rolo_field((int) R_NAME,entry);
  74.   company = get_basic_rolo_field((int) R_COMPANY,entry);
  75.   if (strncsearch(name,strlen(name),person,len)) return(1);
  76.   if (strncsearch(company,strlen(company),person,len)) return(1);
  77.   return(0);
  78. }
  79.  
  80.  
  81. int find_all_person_matches (person) char *person;
  82.  
  83. {
  84.   Ptr_Rolo_List rptr = Begin_Rlist;        
  85.   int count = 0;
  86.   while (rptr != 0) {
  87.     unset_matched(rptr);
  88.     if (person_match(person,get_entry(rptr))) {
  89.        set_matched(rptr);
  90.        count++;
  91.     }
  92.     rptr = get_next_link(rptr);
  93.   }
  94.   return(count);
  95. }
  96.  
  97.  
  98. look_for_person (person) char *person; 
  99.  
  100. /* search against Name and Company over the rolodex.  If a match is found */
  101. /* display the entry and give the user a choice of what to do next. */
  102.  
  103. {
  104.   Ptr_Rolo_List rptr;        
  105.   int found = 0,result,nmatches;
  106.   static displayed_menu = 0;
  107.   char *response;
  108.   
  109.   rptr = Begin_Rlist;        
  110.   while (rptr != 0) {        
  111.     if (person_match(person,get_entry(rptr))) {
  112.        clear_the_screen();
  113.        display_entry(get_entry(rptr));
  114.        if (!found) {
  115.           nmatches = find_all_person_matches(person);
  116.           if (nmatches > 1) {
  117.              printf (
  118.                 "There are %d other entries which match '%s'\n\n",
  119.                 nmatches - 1, person
  120.               );
  121.           }
  122.        }
  123.        found = 1;
  124.        try_again :
  125.        if (!displayed_menu) cathelpfile(libdir("poptionmenu"),0,0);
  126.        displayed_menu = 1;
  127.        menu_match (
  128.             &result,
  129.             &response,
  130.             "Select option (? for help): ",
  131.             0,1,1,1,6,
  132.             "Continue",P_CONTINUE,
  133.             "",P_CONTINUE,
  134.             "Next",P_NEXT_PERSON,
  135.             "\\",P_ABORT,
  136.             "Help",P_HELP,
  137.             "?",P_HELP
  138.          );
  139.        switch (result) {
  140.          case P_CONTINUE :
  141.            break;
  142.          case P_NEXT_PERSON :
  143.            return;
  144.            break;
  145.          case P_ABORT :
  146.            roloexit(0);
  147.            break;
  148.          case P_HELP :
  149.            cathelpfile(libdir("poptionshelp"),"person search options",1);
  150.            goto try_again;
  151.          default :
  152.            fprintf(stderr,"Impossible return from menu_match\n");
  153.            exit(-1);
  154.        }
  155.     }
  156.     rptr = get_next_link(rptr);
  157.   }
  158.   if (!found) {
  159.      fprintf(stderr,"\nNo entry found for '%s'\n\n",person);
  160.      sleep(2);
  161.   }
  162.   else {
  163.      printf("No further matches for '%s'\n",person);
  164.      sleep(2);
  165.   }   
  166. }
  167.  
  168.  
  169. print_people ()
  170.  
  171. {
  172.   int index;
  173.   char *person;
  174.   index = 1;
  175.   while (T) {
  176.      if (0 == (person = non_option_arg(index++))) break;
  177.      look_for_person(person);
  178.   }
  179. }
  180.  
  181.  
  182. interactive_rolo ()
  183.  
  184. /* Top level of the iteractive rolodex.  This code is just a big switch */
  185. /* which passes responsibility off to various routines in 'operations.c' */
  186. /* and 'update.c' */
  187.  
  188. {
  189.  
  190.   int result,rval,field_index;
  191.   char *response,*field_name,*search_string;
  192.  
  193.   fprintf(stdout,"\n\nTMC ROLODEX, Version %s\n\n\n",VERSION);        
  194.   
  195.   while (1) {        
  196.         
  197.     cathelpfile(libdir("mainmenu"),0,0);
  198.     rval = menu_match (
  199.          &result,
  200.          &response,
  201.          "Select option (? for help): ",
  202.          0,1,0,1,7,
  203.          "+",M_ADD,
  204.          "%",M_PERUSE,
  205.          "\\",M_EXIT,
  206.          "?",M_HELP,
  207.          "*",M_SAVE,
  208.          "$",M_SEARCH_BY_OTHER,
  209.          "!",M_PRINT_TO_LASER_PRINTER
  210.       );
  211.       
  212.     switch (rval) {
  213.         
  214.       case MENU_AMBIGUOUS :
  215.       case MENU_ERROR :
  216.         fprintf(stderr,"Impossible return 1 from main menu_match\n");
  217.         exit(-1);
  218.         break;
  219.         
  220.       case MENU_NO_MATCH :
  221.         response = copystr(response);
  222.         rolo_search_mode((int) R_NAME,Field_Names[(int) R_NAME],response);
  223.         break;
  224.         
  225.       case MENU_MATCH :
  226.         
  227.         switch (result) {
  228.           case M_ADD :
  229.             rolo_add();
  230.             break;
  231.           case M_SEARCH_BY_OTHER :
  232.             if ((-1 == select_field_to_search_by(&field_index,&field_name)) ||
  233.                 (0 == (search_string = select_search_string()))) {
  234.                break;
  235.             }
  236.             rolo_search_mode(field_index,field_name,search_string);
  237.             break;
  238.           case M_PRINT_TO_LASER_PRINTER :
  239.             fprintf(stderr,"Not implemented\n");
  240.             sleep(1);
  241.             break;
  242.           case M_PERUSE :
  243.             rolo_peruse_mode(Begin_Rlist);
  244.             break;
  245.           case M_EXIT :
  246.             save_and_exit(0);
  247.             break;
  248.           case M_SAVE :
  249.             if (changed) {
  250.                save_to_disk();
  251.                sleep(1);
  252.             }
  253.             else {
  254.                printf("No changes to be saved...\n");
  255.                sleep(2);
  256.             }
  257.             break;
  258.           case M_HELP :
  259.             cathelpfile(libdir("moptionhelp"),"top level menu",1);
  260.             any_char_to_continue();
  261.             break;
  262.           default :
  263.             fprintf(stderr,"Impossible result from menu_match...\n");
  264.             save_and_exit(-1);
  265.         }
  266.         break;
  267.             
  268.       case MENU_EOF :
  269.         user_eof();
  270.         break;
  271.         
  272.       default :
  273.         fprintf(stderr,"Impossible return 2 from menu_match\n");
  274.         save_and_exit(-1);
  275.         
  276.     }
  277.     
  278.     clear_the_screen();
  279.     
  280.   }
  281.  
  282. }
  283.