home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * Copyright (C) 1990 Jay Konigsberg - see Makefile for details
- * This is Free Software, distrubited under the GNU Software Aggrement.
- */
-
- #include "simped.h"
-
- /*
- Global for interrupt routine: cleanup()
- */
- struct termio ttyset; /* terminal settings */
- unsigned short c_lflag_hold; /* hold original values for reset */
- unsigned char VEOF_hold; /* hold original value for reset */
-
- void main(argc, argv)
- int argc;
- char **argv;
- {
- int fprintf(),
- ioctl();
-
- void commands(),
- exit();
-
- extern int cleanup();
-
- char *editfile=NULL; /* The file being edited */
-
- int newfile=FALSE; /* new or existing file */
-
- FILE *fopen(),
- *fd=stdin; /* file descriptor for command line */
-
- /*
- was a filename was entered on the command line?
- */
- if (argc > 2)
- {
- fprintf(stderr, "%s: one file maximum on command line\n", argv[0]);
- exit(2);
- }
- else
- {
- if (argc == 2)
- {
- if ((fd = fopen(argv[1], "r+")) == NULL)
- {
- newfile = TRUE;
- if ((fd = fopen(argv[1], "a")) == NULL)
- {
- fprintf(stderr,"fopen failed: error=%d\n", errno);
- exit(2);
- }
- }
- editfile = argv[1];
- }
- else
- {
- newfile = TRUE;
- editfile = NULL;
- fd = stdin;
- }
- }
-
- /*
- enter raw mode
- */
- if ( ioctl(0, TCGETA, &ttyset) == -1 )
- {
- fprintf(stderr, "ioctl: error=%d\n", errno);
- exit(2);
- }
- c_lflag_hold=ttyset.c_lflag;
- VEOF_hold = ttyset.c_cc[4];
- ttyset.c_cc[4] = (unsigned char)1;
- ttyset.c_lflag &= ~(ICANON | ECHO);
-
- if ( ioctl(0, TCSETAW, &ttyset) == -1 )
- {
- fprintf(stderr, "ioctl: error=%d\n",errno);
- }
- signal(SIGINT, cleanup);
-
- commands(editfile, &newfile, fd);
- /*NOTREACHED*/
- }
-