home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / pico / pilot.c < prev    next >
C/C++ Source or Header  |  1998-08-24  |  8KB  |  336 lines

  1. #if    !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: pilot.c,v 4.20 1998/08/24 17:37:26 hubert Exp $";
  3. #endif
  4. /*
  5.  * Program:    Main stand-alone Pine File Browser routines
  6.  *
  7.  * Author:    Michael Seibel
  8.  *        Networks and Distributed Computing
  9.  *        Computing & Communications
  10.  *        University of Washington
  11.  *        Administration Building, AG-44
  12.  *        Seattle, WA  98195
  13.  *        Internet: mikes@cac.washington.edu
  14.  *
  15.  *
  16.  * Pine and Pico are registered trademarks of the University of Washington.
  17.  * No commercial use of these trademarks may be made without prior written
  18.  * permission of the University of Washington.
  19.  * 
  20.  * Pine, Pico, and Pilot software and its included text are Copyright
  21.  * 1989-1998 by the University of Washington.
  22.  * 
  23.  * The full text of our legal notices is contained in the file called
  24.  * CPYRIGHT, included with this distribution.
  25.  *
  26.  *
  27.  * BROWSER NOTES:
  28.  *
  29.  * 30 Sep 92 - Stand alone PIne's "Lister of Things" came into being.
  30.  *           It's built against libpico.a from a command line like:
  31.  *
  32.  *               cc pilot.c libpico.a -ltermcap -lc -o pilot
  33.  *
  34.  *           should it become a fleshed out tool, we'll move it into
  35.  *           the normal build process.
  36.  */
  37.  
  38. #include    "headers.h"
  39.  
  40.  
  41. #define        PILOT_VERSION    "UW PILOT 2.0"
  42.  
  43.  
  44. extern char *gethomedir();
  45.  
  46. char *pilot_args PROTO((int, char **));
  47. void  pilot_args_help PROTO((void));
  48. void  pilot_display_args_err PROTO((char *, char **, int));
  49.  
  50. char  args_pilot_missing_flag[]  = "unknown flag \"%c\"";
  51. char  args_pilot_missing_arg[]   = "missing or empty argument to \"%c\" flag";
  52. char  args_pilot_missing_num[]   = "non numeric argument for \"%c\" flag";
  53. char  args_pilot_missing_color[] = "missing color for \"%s\" flag";
  54.  
  55. char *args_pilot_args[] = {
  56. "Possible Starting Arguments for Pilot file browser:",
  57. "",
  58. "\tArgument\t\tMeaning",
  59. "\t -a \t\tShowDot - show dot files in file browser",
  60. "\t -j \t\tGoto - allow 'Goto' command in file browser",
  61. "\t -g \t\tShow - show cursor in file browser",
  62. "\t -m \t\tMouse - turn on mouse support",
  63. "\t -v \t\tOneColumn - use single column display",
  64. "\t -x \t\tNoKeyhelp - suppress keyhelp",
  65. "\t -q \t\tTermdefWins - termcap or terminfo takes precedence over defaults",
  66. "\t -f \t\tKeys - force use of function keys",
  67. "\t -h \t\tHelp - give this list of options",
  68. "\t -n[#s] \tMail - notify about new mail every #s seconds, default=180",
  69. "\t -t \t\tShutdown - enable special shutdown mode",
  70. "\t -o <dir>\tOperation - specify the operating directory",
  71. "\t -z \t\tSuspend - allow use of ^Z suspension",
  72. #if     defined(DOS) || defined(OS2)
  73. "\t -cnf color \tforeground color",
  74. "\t -cnb color \tbackground color",
  75. "\t -crf color \treverse foreground color",
  76. "\t -crb color \treverse background color",
  77. #endif
  78. "", 
  79. "\t All arguments may be followed by a directory name to start in.",
  80. "",
  81. NULL
  82. };
  83.  
  84.  
  85. /*
  86.  * main standalone browser routine
  87.  */
  88. main(argc, argv)
  89. char    *argv[];
  90. {
  91.     char  bname[NBUFN];        /* buffer name of file to read    */
  92.     char  filename[NSTRING];
  93.     char  filedir[NSTRING];
  94.     char *dir;
  95.  
  96.     timeo = 0;
  97.     Pmaster = NULL;            /* turn OFF composer functionality */
  98.     km_popped = 0;
  99.     opertree[0] = '\0'; opertree[NLINE] = '\0';
  100.     filename[0] ='\0';
  101.     gmode |= MDBRONLY;            /* turn on exclusive browser mode */
  102.     set_collation();
  103.  
  104.     /*
  105.      * Read command line flags before initializing, otherwise, we never
  106.      * know to init for f_keys...
  107.      */
  108.     if(dir = pilot_args(argc, argv)){
  109.     strcpy(filedir, dir);
  110.     fixpath(filedir, NSTRING);
  111.     }
  112.     else
  113.       strcpy(filedir, gethomedir(NULL));
  114.  
  115.     if(!vtinit())            /* Displays.            */
  116.       exit(1);
  117.  
  118.     strcpy(bname, "main");        /* default buffer name */
  119.     edinit(bname);            /* Buffers, windows.   */
  120. #if    defined(USE_TERMCAP) || defined(USE_TERMINFO) || defined(VMS)
  121.     if(kbesc == NULL){            /* will arrow keys work ? */
  122.     (*term.t_putchar)('\007');
  123.     emlwrite("Warning: keypad keys may be non-functional", NULL);
  124.     }
  125. #endif    /* USE_TERMCAP/USE_TERMINFO/VMS */
  126.  
  127.     curbp->b_mode |= gmode;        /* and set default modes*/
  128.     if(timeo)
  129.       emlwrite("Checking for new mail every %D seconds", (void *) timeo);
  130.  
  131.     set_browser_title(PILOT_VERSION);
  132.     FileBrowse(filedir, NSTRING, filename, NSTRING, NULL, 0);
  133.     wquit(1, 0);
  134. }
  135.  
  136.  
  137. /*
  138.  *  Parse the command line args.
  139.  *
  140.  * Args      ac
  141.  *           av
  142.  *
  143.  * Result: command arguments parsed
  144.  *       possible printing of help for command line
  145.  *       various global flags set
  146.  *       returns the name of directory to start in if specified, else NULL
  147.  */
  148. char *
  149. pilot_args(ac, av)
  150.     int    ac;
  151.     char **av;
  152. {
  153.     int   c, usage = 0;
  154.     char *str;
  155.     char  tmp_1k_buf[1000];     /* tmp buf to contain err msgs  */ 
  156.  
  157. Loop:
  158.     /* while more arguments with leading - */
  159.     while(--ac > 0 && **++av == '-'){
  160.       /* while more chars in this argument */
  161.       while(*++*av){
  162.  
  163. #if    defined(DOS) || defined(OS2)
  164.     if(strcmp(*av, "cnf") == 0
  165.        || strcmp(*av, "cnb") == 0
  166.        || strcmp(*av, "crf") == 0
  167.        || strcmp(*av, "crb") == 0){
  168.  
  169.         char *cmd = *av; /* save it to use below */
  170.  
  171.         if(--ac){
  172.         str = *++av;
  173.         if(cmd[1] == 'n'){
  174.             if(cmd[2] == 'f')
  175.               pico_nfcolor(str);
  176.             else if(cmd[2] == 'b')
  177.               pico_nbcolor(str);
  178.         }
  179.         else if(cmd[1] == 'r'){
  180.             if(cmd[2] == 'f')
  181.               pico_rfcolor(str);
  182.             else if(cmd[2] == 'b')
  183.               pico_rbcolor(str);
  184.         }
  185.         }
  186.         else{
  187.         sprintf(tmp_1k_buf, args_pilot_missing_color, cmd);
  188.         pilot_display_args_err(tmp_1k_buf, NULL, 1);
  189.             usage++;
  190.         }
  191.  
  192.         goto Loop;
  193.     }
  194. #endif
  195.  
  196.     /*
  197.      * Single char options.
  198.      */
  199.     switch(c = **av){
  200.       /*
  201.        * These don't take arguments.
  202.        */
  203.       case 'a':
  204.         gmode ^= MDDOTSOK;        /* show dot files */
  205.         break;
  206.       case 'f':            /* -f for function key use */
  207.         gmode ^= MDFKEY;
  208.         break;
  209.       case 'j':            /* allow "Goto" in file browser */
  210.         gmode ^= MDGOTO;
  211.         break;
  212.       case 'g':            /* show-cursor in file browser */
  213.         gmode ^= MDSHOCUR;
  214.         break;
  215.       case 'm':            /* turn on mouse support */
  216.         gmode ^= MDMOUSE;
  217.         break;
  218.       case 'v':            /* single column display */
  219.         gmode ^= MDONECOL;
  220.         break;            /* break back to inner-while */
  221.       case 'x':            /* suppress keyhelp */
  222.         sup_keyhelp = !sup_keyhelp;
  223.         break;
  224.       case 'q':            /* -q for termcap takes precedence */
  225.         gmode ^= MDTCAPWINS;
  226.         break;
  227.       case 'z':            /* -z to suspend */
  228.         gmode ^= MDSSPD;
  229.         break;
  230.       case 'h':
  231.         usage++;
  232.         break;
  233.  
  234.       /*
  235.        * These do take arguments.
  236.        */
  237.       case 'n':            /* -n for new mail notification */
  238.       case 'o' :            /* operating tree */
  239.         if(*++*av)
  240.           str = *av;
  241.         else if(--ac)
  242.           str = *++av;
  243.         else{
  244.           sprintf(tmp_1k_buf, args_pilot_missing_arg, c);
  245.           pilot_display_args_err(tmp_1k_buf, NULL, 1);
  246.           usage++;
  247.           goto Loop;
  248.         }
  249.  
  250.         switch(c){
  251.           case 'o':
  252.         strncpy(opertree, str, NLINE);
  253.         gmode ^= MDTREE;
  254.         break;
  255.  
  256.     /* numeric args */
  257.           case 'n':
  258.         if(!isdigit((unsigned char)str[0])){
  259.           sprintf(tmp_1k_buf, args_pilot_missing_num, c);
  260.           pilot_display_args_err(tmp_1k_buf, NULL, 1);
  261.           usage++;
  262.         }
  263.  
  264.         timeo = 180;
  265.         if((timeo = atoi(str)) < 30)
  266.           timeo = 180;
  267.         
  268.         break;
  269.         }
  270.  
  271.         goto Loop;
  272.  
  273.       default:            /* huh? */
  274.         sprintf(tmp_1k_buf, args_pilot_missing_flag, c);
  275.         pilot_display_args_err(tmp_1k_buf, NULL, 1);
  276.         usage++;
  277.         break;
  278.     }
  279.       }
  280.     }
  281.  
  282.     if(usage)
  283.       pilot_args_help();
  284.  
  285.     /* return the directory */
  286.     if(ac > 0)
  287.       return(*av);
  288.     else
  289.       return(NULL);
  290. }
  291.  
  292.  
  293. /*----------------------------------------------------------------------
  294.     print a few lines of help for command line arguments
  295.  
  296.   Args:  none
  297.  
  298.  Result: prints help messages
  299.   ----------------------------------------------------------------------*/
  300. void
  301. pilot_args_help()
  302. {
  303.     /**  print out possible starting arguments... **/
  304.     pilot_display_args_err(NULL, args_pilot_args, 0);
  305.     exit(1);
  306. }
  307.  
  308.  
  309. /*----------------------------------------------------------------------
  310.    write argument error to the display...
  311.  
  312.   Args:  none
  313.  
  314.  Result: prints help messages
  315.   ----------------------------------------------------------------------*/
  316. void
  317. pilot_display_args_err(s, a, err)
  318.     char  *s;
  319.     char **a;
  320.     int    err;
  321. {
  322.     char  errstr[256], *errp;
  323.     FILE *fp = err ? stderr : stdout;
  324.  
  325.     if(err && s)
  326.       sprintf(errp = errstr, "Argument Error: %.200s", s);
  327.     else
  328.       errp = s;
  329.  
  330.     if(errp)
  331.       fprintf(fp, "%s\n", errp);
  332.  
  333.     while(a && *a)
  334.       fprintf(fp, "%s\n", *a++);
  335. }
  336.