home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1558 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  2.3 KB  |  101 lines

  1.  
  2. /*
  3.  * Copyright (C) 1990 by Jay Konigsberg. mail: jak@sactoh0
  4.  *
  5.  * Permission to use, copy, modify, and distribute this  software  and  its
  6.  * documentation is hereby  granted,  provided  that  the  above  copyright
  7.  * notice appear in all copies  and that  both  the  copyright  notice  and
  8.  * this permission notice appear in supporting documentation. This software
  9.  * is provided "as is" without express or implied  warranty.  However,  the
  10.  * author retains all Copyright priviliges and rights  to  renumeration  if
  11.  * this software is sold.
  12.  */
  13.  
  14. /*
  15.  * main - general setup and signal functions. Its life's work is to make
  16.  * the bed for commands().
  17.  */
  18.  
  19. #include "simped.h"
  20.  
  21. /*
  22. Global for interrupt routine: cleanup()
  23. */
  24. struct        termio    ttyset;        /* terminal settings */
  25. unsigned    short    c_lflag_hold;    /* hold original values for reset */
  26. unsigned    char    VEOF_hold;    /* hold original value for reset */
  27.  
  28. /* global to replace \b in input */
  29. unsigned char bs_char;
  30.  
  31. void main(argc, argv)
  32. int    argc;
  33. char    **argv;
  34. {
  35. int    fprintf(),
  36.     ioctl();
  37.  
  38. void    commands(),
  39.     exit();
  40.  
  41. extern    int    cleanup();
  42.  
  43. char    *options();        /* command line options - returns filename */
  44.  
  45. char    *editfile=NULL;        /* The file being edited */
  46.  
  47. int    newfile=FALSE,        /* new or existing file */
  48.     postnews=FALSE,        /* flag for postnews compatability */
  49.     append=FALSE;        /* flag to always come up in append mode */
  50.  
  51. FILE    *fopen(),
  52.     *fd=stdin;        /* file descriptor for command line */
  53.  
  54. /*
  55.  * was a filename was entered on the command line?
  56.  */
  57.  
  58. editfile = options(argc, argv, &postnews, &append, editfile);
  59. if (editfile)
  60.     {
  61.     if ((fd = fopen(editfile, "r+")) == NULL)
  62.     {
  63.     newfile = TRUE;
  64.     if ((fd = fopen(editfile, "a")) == NULL)
  65.         {
  66.         fprintf(stderr,"fopen failed: error=%d\n", errno);
  67.         exit(2);
  68.         }
  69.     }
  70.     }
  71. else
  72.     {
  73.     newfile = TRUE;
  74.     editfile = NULL;
  75.     fd = stdin;
  76.     }
  77.  
  78. /*
  79. enter raw mode
  80. */
  81. if ( ioctl(0, TCGETA, &ttyset) == -1 )
  82.     {
  83.     fprintf(stderr, "ioctl: error=%d\n", errno);
  84.     exit(2);
  85.     }
  86. c_lflag_hold=ttyset.c_lflag;
  87. VEOF_hold = ttyset.c_cc[4];
  88. bs_char = ttyset.c_cc[2];
  89. ttyset.c_cc[4] = (unsigned char)1;
  90. ttyset.c_lflag &= ~(ICANON | ECHO);
  91.  
  92. if ( ioctl(0, TCSETAW, &ttyset) == -1 )
  93.     {
  94.     fprintf(stderr, "ioctl: error=%d\n",errno);
  95.     }
  96. signal(SIGINT, cleanup);
  97.  
  98. commands(editfile, &newfile, fd, postnews, append);
  99. /*NOTREACHED*/
  100. }
  101.