home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- organization: Emtronix Data Services, Randallstown, Maryland
- keywords: simple editor for ELM mailer
- subject: v13i062: Elmedit
- From: smarc@uunet.uu.net@mas.UUCP
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 13, Issue 62
- Submitted-by: smarc@uunet.uu.net@mas.UUCP
- Archive-name: elmedit/part01
-
- This is the source for a simple editor we wrote for our users.
- Teaching them how to use VI was not a promising prospect. While it's
- not very fancy, it gets the job done. You may use this freely, but
- you can't sell or otherwise profit from it. 8-)
-
- This runs very slowly on older NCR's, and SCO Xenix. It's probably
- due to the curses package on those machines.
-
-
- #! /bin/sh
- # This file was wrapped with "dummyshar". "sh" this file to extract.
- # Contents: elmedit.c
- echo extracting 'elmedit.c'
- if test -f 'elmedit.c' -a -z "$1"; then echo Not overwriting 'elmedit.c'; else
- sed 's/^X//' << \EOF > 'elmedit.c'
- X /*
- X * elmedit.c
- X * Mark Winsor & Marc Siegel
- X * This is intended as a VERY simple ASCII editor for the ELM mailer.
- X * It allows naive users to use ELM without learning how to use an editor.
- X * It only handles 23 lines * 80 columns. There are no editing capabilities
- X * other than cursor movement.
- X *
- X * WARNING: If you invoke editor on a file with more than 23 lines, the
- X * file will be truncated when you write it out.
- X * In other words, one screenfull of text only!
- X *
- X * You are free to use this code, provided that you do not
- X * sell or otherwise profit from it. These comments must remain intact!
- X *
- X * Please send comments to:
- X * Marc Siegel {uunet}!wb3ffv!mas!smarc || smarc@mas.wb3ffv.AMPR.ORG
- X * or
- X * Mark Winsor {uunet}!wb3ffv!mas!wmark
- X */
- X
- X#include <curses.h>
- X#include <signal.h>
- X
- X#define BUFSIZE 1840
- X#define LINESIZE 80
- X#define CTRLJ '\012'
- X#define CTRLL '\014'
- X#define ESC '\033'
- X
- Xint lastindex;
- X
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X if (argc != 2) {
- X (void) usage(argv[0]);
- X (void) exit(1);
- X }
- X (void) startedit(argv[0],argv[1]);
- X (void) bye();
- X}
- X
- Xstartedit(progname,filename)
- Xchar *progname;
- Xchar *filename;
- X{
- X FILE *output;
- X char *editbuf;
- X int i;
- X
- X if ((editbuf = (char *)malloc(BUFSIZE)) == NULL) {
- X (void) fprintf(stderr,"\n%s: Cannot allocate %d bytes\n",
- X progname,BUFSIZE);
- X (void) exit(3);
- X }
- X for (i = 0; i < BUFSIZE; i++) {
- X *(editbuf + i) = ' ';
- X }
- X
- X lastindex = 0;
- X if ((output = fopen(filename,"r")) != NULL) {
- X (void) loadbuf(output,editbuf);
- X (void) fclose(output);
- X }
- X
- X (void) edit(progname,output,editbuf);
- X if (lastindex > 0) {
- X if ((output = fopen(filename,"w")) == NULL) {
- X (void) move(23,0);
- X (void) clrtoeol();
- X (void) mvprintw(23,0,"%s: Cannot open \"%s\"",progname,filename);
- X (void) refresh();
- X (void) bye();
- X }
- X (void) writebuf(output,editbuf);
- X }
- X (void) fclose(output);
- X return(0);
- X}
- X
- Xedit(progname,output,editbuf)
- Xchar *progname;
- XFILE *output;
- Xchar *editbuf;
- X{
- X int row;
- X int col;
- X int ch;
- X int index;
- X int bye();
- X
- X (void) initscr();
- X (void) signal(SIGINT,bye);
- X (void) signal(SIGQUIT,bye);
- X (void) signal(SIGTERM,bye);
- X (void) nonl();
- X (void) noecho();
- X (void) keypad(stdscr,TRUE);
- X
- X index = row = col = 0;
- X (void) dispbuf(editbuf);
- X
- X for (;;) {
- X row = index / LINESIZE;
- X col = index % LINESIZE;
- X (void) mvprintw(23,10,
- X "ESC to end, DEL to abort Row: %2d Col: %2d",
- X row + 1,col + 1);
- X (void) move(row,col);
- X (void) refresh();
- X ch = getch();
- X switch(ch) {
- X case(KEY_DOWN):
- X case(CTRLJ):
- X index += LINESIZE;
- X if (index > (BUFSIZE - 1)) {
- X index -= BUFSIZE;
- X }
- X break;
- X
- X case(KEY_UP):
- X index -= LINESIZE;
- X if (index < 0) {
- X index += BUFSIZE;
- X }
- X break;
- X
- X case(KEY_RIGHT):
- X ++index;
- X if (index > (BUFSIZE - 1)) {
- X index = 0;
- X }
- X break;
- X
- X case(KEY_LEFT):
- X case('\b'):
- X --index;
- X if (index < 0) {
- X index = BUFSIZE - 1;
- X }
- X break;
- X
- X case('\r'):
- X index = index + (80 - col);
- X if (index > (BUFSIZE - 1)) {
- X index = 0;
- X }
- X break;
- X
- X case(CTRLL):
- X (void) clearok(stdscr);
- X break;
- X
- X case(ESC):
- X return(0);
- X
- X default:
- X if (ch < ' ' || ch > '~') {
- X (void) beep();
- X }
- X else {
- X editbuf[index] = ch;
- X (void) mvprintw(row,col,"%c",ch);
- X (void) refresh();
- X if (index > lastindex) {
- X lastindex = index;
- X }
- X ++index;
- X if (index >= BUFSIZE) {
- X index = 0;
- X }
- X }
- X }
- X }
- X}
- X
- Xwritebuf(output,editbuf)
- XFILE *output;
- Xchar *editbuf;
- X{
- X int index;
- X int count;
- X char linebuf[LINESIZE + 1];
- X
- X index = 0;
- X for (;;) {
- X (void) strncpy(linebuf,(editbuf+index),LINESIZE);
- X linebuf[LINESIZE] = '\0';
- X for (count = (LINESIZE-1); linebuf[count] == ' ' && count > 0; count--)
- X ;
- X linebuf[(count + 1)] = '\0';
- X fprintf(output,"%s\n",linebuf);
- X index += LINESIZE;
- X if (index > lastindex) {
- X return(0);
- X }
- X }
- X}
- X
- Xloadbuf(output,editbuf)
- XFILE *output;
- Xchar *editbuf;
- X{
- X char line[LINESIZE + 2];
- X int index;
- X int len;
- X int row;
- X int col;
- X int i;
- X
- X index = 0;
- X while ((fgets(line,LINESIZE+2,output)) != NULL) {
- X len = strlen(line) - 1;
- X line[len] = '\0';
- X for (i = 0; i < len; i++) {
- X *(editbuf + index + i) = line[i];
- X }
- X index += LINESIZE;
- X if (index > (BUFSIZE - 1)) {
- X index -= LINESIZE;
- X break;
- X }
- X lastindex = index + i;
- X }
- X}
- X
- Xdispbuf(editbuf)
- Xchar *editbuf;
- X{
- X char line[LINESIZE + 1];
- X int index;
- X int row;
- X
- X index = 0;
- X while (index < BUFSIZE) {
- X (void) memcpy(line,(editbuf + index),LINESIZE);
- X line[LINESIZE] = '\0';
- X row = index / LINESIZE;
- X (void) mvprintw(row,0,"%s",line);
- X index += LINESIZE;
- X }
- X (void) refresh();
- X}
- X
- Xusage(progname)
- Xchar *progname;
- X{
- X (void) fprintf(stderr,"\n%s: Bad argument count\n",progname);
- X}
- X
- Xbye()
- X{
- X (void) move(23,0);
- X (void) clrtoeol();
- X (void) refresh();
- X (void) endwin();
- X (void) exit(0);
- X}
- X
- X/******* END OF ELMEDIT.C ************/
- EOF
- chars=`wc -c < 'elmedit.c'`
- if test $chars != 6554; then echo 'elmedit.c' is $chars characters, should be 6554 characters!; fi
- fi
- exit 0
-
- _ | Marc Siegel
- ' )--,--, | Randallstown, Maryland
- / / / __. __ _ | {uunet}!wb3ffv!mas!smarc
- / / (_(_/|_/ (_(_' | smarc@mas.wb3ffv.AMPR.ORG
- ===============================================================================
-
-
-