home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / pico / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  6.6 KB  |  254 lines

  1. #if    !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: main.c,v 4.4 1993/10/06 17:09:24 mikes Exp $";
  3. #endif
  4. /*
  5.  * Program:    Main stand-alone Pine Composer routines
  6.  *
  7.  *
  8.  * Michael Seibel
  9.  * Networks and Distributed Computing
  10.  * Computing and Communications
  11.  * University of Washington
  12.  * Administration Builiding, AG-44
  13.  * Seattle, Washington, 98195, USA
  14.  * Internet: mikes@cac.washington.edu
  15.  *
  16.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  17.  *
  18.  * Copyright 1991-1993  University of Washington
  19.  *
  20.  *  Permission to use, copy, modify, and distribute this software and its
  21.  * documentation for any purpose and without fee to the University of
  22.  * Washington is hereby granted, provided that the above copyright notice
  23.  * appears in all copies and that both the above copyright notice and this
  24.  * permission notice appear in supporting documentation, and that the name
  25.  * of the University of Washington not be used in advertising or publicity
  26.  * pertaining to distribution of the software without specific, written
  27.  * prior permission.  This software is made available "as is", and
  28.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  29.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  31.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  32.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  33.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  34.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  35.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  36.  *
  37.  * Pine and Pico are trademarks of the University of Washington.
  38.  * No commercial use of these trademarks may be made without prior
  39.  * written permission of the University of Washington.
  40.  *
  41.  *
  42.  * WEEMACS/PICO NOTES:
  43.  *
  44.  * 08 Jan 92 - removed PINE defines to simplify compiling
  45.  *
  46.  * 08 Apr 92 - removed PINE stub calls
  47.  *
  48.  */
  49.  
  50. #include        <stdio.h>
  51. #include    <setjmp.h>
  52. #include    "osdep.h"    /* operating system dependent includes */
  53. #include    "pico.h"    /* pine composer definitions */
  54. #include        "estruct.h"    /* global structures and defines */
  55. #include    "efunc.h"    /* function declarations and sans name table */
  56. #include    "edef.h"    /* global definitions */
  57. #ifdef HEBREW
  58. #include        "hebrew.h" 
  59. #endif
  60.  
  61.  
  62. /*
  63.  * this isn't defined in the library, because it's a pine global
  64.  * which we use for GetKey's timeout
  65.  */
  66. int    timeout = 0;            /* global timeout value        */
  67.  
  68. /*
  69.  * function key mappings
  70.  */
  71. static int fkm[12][2] = {
  72.     { F1,  (CTRL|'G')},
  73.     { F2,  (CTRL|'X')},
  74.     { F3,  (CTRL|'O')},
  75.     { F4,  (CTRL|'J')},
  76.     { F5,  (CTRL|'R')},
  77.     { F6,  (CTRL|'W')},
  78.     { F7,  (CTRL|'Y')},
  79.     { F8,  (CTRL|'V')},
  80.     { F9,  (CTRL|'K')},
  81.     { F10, (CTRL|'U')},
  82.     { F11, (CTRL|'C')},
  83. #ifdef    SPELLER
  84.     { F12, (CTRL|'T')}
  85. #else
  86.     { F12, (CTRL|'D')}
  87. #endif
  88. };
  89.  
  90.  
  91. /*
  92.  * main standalone pico routine
  93.  */
  94. main(argc, argv)
  95. char    *argv[];
  96. {
  97.     register int    c;
  98.     register int    f;
  99.     register int    n;
  100.     register BUFFER *bp;
  101.     register int    carg;        /* current arg to scan         */
  102.     int         viewflag = FALSE;        /* are we starting in view mode?*/
  103.     int         starton = 0;        /* where's dot to begin with?    */
  104.     char     bname[NBUFN];        /* buffer name of file to read    */
  105.     char    *clerr = NULL;        /* garbage on command line    */
  106.     
  107.     Pmaster = NULL;            /* turn OFF composer functionality */
  108.  
  109. #ifdef HEBREW
  110.     compose_heb=0;
  111.     control_mode=1;
  112. #endif
  113.  
  114.     /*
  115.      * Read command line flags before initializing, otherwise, we never
  116.      * know to init for f_keys...
  117.      */
  118.     carg = 1;
  119.     while(carg < argc){
  120.     if(argv[carg][0] == '-'){
  121.         switch(argv[carg][1]){
  122.           case 'v':            /* -v for View File */
  123.           case 'V':
  124.         viewflag = !viewflag;
  125.         break;
  126.           case 'f':            /* -f for function key use */
  127.         gmode ^= MDFKEY;
  128.         break;
  129.           case 'n':            /* -n for new mail notification */
  130.         timeout = 180;
  131.         if(argv[carg][2] != '\0')
  132.           if((timeout = atoi(&argv[carg][2])) < 30)
  133.             timeout = 180;
  134.         break;
  135.           case 't':            /* special shutdown mode */
  136.         gmode ^= MDTOOL;
  137.         rebindfunc(wquit, quickexit);
  138.         break;
  139.           case 'z':            /* -z to suspend */
  140.         gmode ^= MDSSPD;
  141.         break;
  142.           case 'w':            /* -w turn off word wrap */
  143.         gmode ^= MDWRAP;
  144.         break;
  145. #ifdef HEBREW
  146.           case 'e':
  147.           case 'E':
  148.         compose_heb=0;
  149.         break;
  150.           case 'h':
  151.           case 'H':
  152.         compose_heb=1;
  153.         break;
  154. #endif
  155.           default:            /* huh? */
  156.         clerr = argv[carg];
  157.         break;
  158.         }
  159.         carg++;
  160.     }
  161.     else if(argv[carg][0] == '+'){    /* leading '+' is special */
  162.         starton = atoi(&argv[carg][1]);
  163.         carg++;
  164.     }
  165.     else                /* pick up file name later... */
  166.       break;
  167.     }
  168.  
  169.     if(!vtinit())            /* Displays.            */
  170.     exit(1);
  171.  
  172.     strcpy(bname, "main");        /* default buffer name */
  173.     edinit(bname);            /* Buffers, windows.   */
  174.  
  175.     update();                /* let the user know we are here */
  176.  
  177. #if    TERMCAP
  178.     if(kpadseqs == NULL){        /* will arrow keys work ? */
  179.     (*term.t_putchar)('\007');
  180.     emlwrite("Warning: keypad keys may non-functional", NULL);
  181.     }
  182. #endif    /* TERMCAP */
  183.  
  184.     if(carg < argc){            /* Any file to edit? */
  185.  
  186.     makename(bname, argv[carg]);    /* set up a buffer for this file */
  187.  
  188.     bp = curbp;            /* read in first file */
  189.     makename(bname, argv[carg]);
  190.     strcpy(bp->b_bname, bname);
  191.     strcpy(bp->b_fname, argv[carg]);
  192.     if (readin(argv[carg], (viewflag==FALSE)) == ABORT) {
  193.         strcpy(bp->b_bname, "main");
  194.         strcpy(bp->b_fname, "");
  195.     }
  196.     bp->b_dotp = bp->b_linep;
  197.     bp->b_doto = 0;
  198.  
  199.     if (viewflag)            /* set the view mode */
  200.       bp->b_mode |= MDVIEW;
  201.     }
  202.  
  203.     /* setup to process commands */
  204.     lastflag = 0;            /* Fake last flags.     */
  205.     curbp->b_mode |= gmode;        /* and set default modes*/
  206.  
  207.     curwp->w_flag |= WFMODE;        /* and force an update    */
  208.  
  209.     if(timeout)
  210.       emlwrite("Checking for new mail every %D seconds", (void *)timeout);
  211.  
  212.     if(clerr){                /* post any errors on command line */
  213.     if(mpresf)            /* show earlier message though! */
  214.       sleep(2);
  215.     emlwrite("\007Unknown option: %s", clerr);
  216.     }
  217.  
  218.     forwline(0, starton - 1);        /* move dot to specified line */
  219. #ifdef HEBREW
  220.     init_hebdata();
  221. #endif
  222.  
  223.     while(1){
  224.  
  225.     update();            /* Fix up the screen    */
  226.  
  227. #if    defined(DOS) && defined(MOUSE)
  228.     register_mfunc(pico_mouse, 2, 0,term.t_nrow-3,term.t_ncol);
  229. #endif
  230.     c = GetKey();    
  231.  
  232.     if(timeout && (c == NODATA || time_to_check())){
  233.         if(pico_new_mail())
  234.           emlwrite("You may possibly have new mail.", NULL);
  235.     }
  236.  
  237.     if(c == NODATA)
  238.       continue;
  239.  
  240.     if(mpresf){            /* erase message line? */
  241.         if(mpresf++ > MESSDELAY)
  242.           mlerase();
  243.     }
  244.  
  245.     f = FALSE;
  246.     n = 1;
  247.  
  248. #if    defined(DOS) && defined(MOUSE)
  249.     clear_mfunc();
  250. #endif
  251.     execute(normal(c, fkm, 1), f, n);    /* Do it.               */
  252.     }
  253. }
  254.