Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!lll-winken!ncis.tis.llnl.gov!blackbird!lonex.radc.af.mil!wlbr!roger.imsd.contel.com!mh From: mh@roger.imsd.contel.com (Mike H.) Newsgroups: comp.windows.news Subject: NeWS version of elvis (the vi clone) part 6 of 9 Message-ID: <1991Jan11.020901.27485@wlbr.imsd.contel.com> Date: 11 Jan 91 02:09:01 GMT References: Sender: news@wlbr.imsd.contel.com (news) Distribution: comp Organization: Contel FSD, Westlake Village, CA Lines: 1884 Nntp-Posting-Host: roger.imsd.contel.com #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # opts.c # osk.c # ow.c # ow_tcap.c # This archive created: Thu Jan 10 17:21:09 1991 export PATH; PATH=/bin:$PATH if test -f 'opts.c' then echo shar: will not over-write existing file "'opts.c'" else cat << \SHAR_EOF > 'opts.c' /* opts.c */ /* Author: * Steve Kirkendall * 14407 SW Teal Blvd. #C * Beaverton, OR 97005 * kirkenda@cs.pdx.edu */ /* This file contains the code that manages the run-time options -- The * values that can be modified via the "set" command. */ #include "config.h" #include "vi.h" #ifndef NULL #define NULL (char *)0 #endif extern char *getenv(); /* maximum width to permit for strings, including ="" */ #define MAXWIDTH 20 /* These are the default values of all options */ char o_autoindent[1] = {FALSE}; char o_autoprint[1] = {TRUE}; char o_autowrite[1] = {FALSE}; #ifndef NO_ERRLIST char o_cc[30] = {CC_COMMAND}; #endif #ifndef NO_CHARATTR char o_charattr[1] = {FALSE}; #endif char o_columns[3] = {80, 32, 255}; #ifndef NO_DIGRAPH char o_digraph[1] = {FALSE}; #endif char o_directory[30] = TMPDIR; char o_edcompatible[1] = {FALSE}; char o_errorbells[1] = {TRUE}; char o_exrefresh[1] = {TRUE}; #ifndef NO_DIGRAPH char o_flipcase[80] # if CS_IBMPC = {"\207\200\201\232\202\220\204\216\206\217\221\222\224\231\244\245"} # endif # if CS_LATIN1 /* initialized by initopts() */ # endif ; #endif #ifndef NO_SENTENCE char o_hideformat[1] = {FALSE}; #endif char o_ignorecase[1] = {FALSE}; #ifndef NO_EXTENSIONS char o_inputmode[1] = {FALSE}; #endif char o_keytime[3] = {2, 0, 5}; char o_keywordprg[80] = {KEYWORDPRG}; char o_lines[3] = {25, 2, 50}; /* More lines? Enlarge kbuf */ char o_list[1] = {FALSE}; #ifndef NO_MAGIC char o_magic[1] = {TRUE}; #endif #ifndef NO_ERRLIST char o_make[30] = {MAKE_COMMAND}; #endif #ifndef NO_MODELINE char o_modeline[1] = {FALSE}; #endif #ifndef NO_SENTENCE char o_paragraphs[30] = "PPppIPLPQP"; #endif #if MSDOS char o_pcbios[1] = {TRUE}; #endif char o_readonly[1] = {FALSE}; char o_report[3] = {5, 1, 127}; char o_scroll[3] = {12, 1, 127}; #ifndef NO_SENTENCE char o_sections[30] = "NHSHSSSEse"; #endif char o_shell[60] = SHELL; char o_shiftwidth[3] = {8, 1, 255}; #ifndef NO_SHOWMATCH char o_showmatch[1] = {FALSE}; #endif #ifndef NO_SHOWMODE char o_smd[1] = {FALSE}; #endif char o_sidescroll[3] = {8, 1, 40}; char o_sync[1] = {NEEDSYNC}; char o_tabstop[3] = {8, 1, 40}; char o_term[30] = "?"; char o_vbell[1] = {TRUE}; char o_warn[1] = {TRUE}; char o_wrapmargin[3] = {0, 0, 255}; char o_wrapscan[1] = {TRUE}; /* The following describes the names & types of all options */ #define BOOL 0 #define NUM 1 #define STR 2 #define SET 0x01 /* this option has had its value altered */ #define CANSET 0x02 /* this option can be set at any time */ #define RCSET 0x06 /* this option can be set in a .exrc file only */ #define MR 0x40 /* does this option affect the way text is displayed? */ struct { char *name; /* name of an option */ char *nm; /* short name of an option */ char type; /* type of an option */ char flags; /* boolean: has this option been set? */ char *value; /* value */ } opts[] = { /* name type flags redraw value */ { "autoindent", "ai", BOOL, CANSET , o_autoindent }, { "autoprint", "ap", BOOL, CANSET , o_autoprint }, { "autowrite", "aw", BOOL, CANSET , o_autowrite }, #ifndef NO_ERRLIST { "cc", "cc", STR, CANSET , o_cc }, #endif #ifndef NO_CHARATTR { "charattr", "ca", BOOL, CANSET | MR, o_charattr }, #endif { "columns", "co", NUM, SET , o_columns }, #ifndef NO_DIGRAPH { "digraph", "dig", BOOL, CANSET , o_digraph }, #endif { "directory", "dir", STR, RCSET , o_directory }, { "edcompatible","ed", BOOL, CANSET , o_edcompatible }, { "errorbells", "eb", BOOL, CANSET , o_errorbells }, { "exrefresh", "er", BOOL, CANSET , o_exrefresh }, #ifndef NO_DIGRAPH { "flipcase", "fc", STR, CANSET , o_flipcase }, #endif #ifndef NO_SENTENCE { "hideformat", "hf", BOOL, CANSET | MR, o_hideformat }, #endif { "ignorecase", "ic", BOOL, CANSET , o_ignorecase }, #ifndef NO_EXTENSIONS { "inputmode", "im", BOOL, CANSET , o_inputmode }, #endif { "keytime", "kt", NUM, CANSET , o_keytime }, { "keywordprg", "kp", STR, CANSET , o_keywordprg }, { "lines", "ls", NUM, SET , o_lines }, { "list", "li", BOOL, CANSET | MR, o_list }, #ifndef NO_MAGIC { "magic", "ma", BOOL, CANSET , o_magic }, #endif #ifndef NO_ERRLIST { "make", "mk", STR, CANSET , o_make }, #endif #ifndef NO_MODELINE { "modeline", "ml", BOOL, CANSET , o_modeline }, #endif #ifndef NO_SENTENCE { "paragraphs", "pa", STR, CANSET , o_paragraphs }, #endif #if MSDOS { "pcbios", "pc", BOOL, SET , o_pcbios }, #endif { "readonly", "ro", BOOL, CANSET , o_readonly }, { "report", "re", NUM, CANSET , o_report }, { "scroll", "sc", NUM, CANSET , o_scroll }, #ifndef NO_SENTENCE { "sections", "se", STR, CANSET , o_sections }, #endif { "shell", "sh", STR, CANSET , o_shell }, #ifndef NO_SHOWMATCH { "showmatch", "sm", BOOL, CANSET , o_showmatch }, #endif #ifndef NO_SHOWMODE { "showmode", "smd", BOOL, CANSET , o_smd }, #endif { "shiftwidth", "sw", NUM, CANSET , o_shiftwidth }, { "sidescroll", "ss", NUM, CANSET , o_sidescroll }, { "sync", "sy", BOOL, CANSET , o_sync }, { "tabstop", "ts", NUM, CANSET | MR, o_tabstop }, { "term", "te", STR, SET , o_term }, { "vbell", "vb", BOOL, CANSET , o_vbell }, { "warn", "wa", BOOL, CANSET , o_warn }, { "wrapmargin", "wm", NUM, CANSET , o_wrapmargin }, { "wrapscan", "ws", BOOL, CANSET , o_wrapscan }, { NULL, NULL, 0, CANSET, NULL } }; /* This function initializes certain options from environment variables, etc. */ void initopts() { char *val; int i; /* set some stuff from environment variables */ #if MSDOS if (val = getenv("COMSPEC")) /* yes, ASSIGNMENT! */ #else if (val = getenv("SHELL")) /* yes, ASSIGNMENT! */ #endif { strcpy(o_shell, val); } #if ANY_UNIX if (val = getenv("TERM")) /* yes, ASSIGNMENT! */ { strcpy(o_term, val); } #endif #if TOS val = "vt52"; strcpy(o_term, val); #endif #if MSDOS if ((val = getenv("TERM")) /* yes, ASSIGNMENT! */ && strcmp(val, "pcbios")) { strcpy(o_term, val); o_pcbios[0] = 0; } else { strcpy(o_term, "pcbios"); o_pcbios[0] = 1; } #endif #if MSDOS || TOS if ((val = getenv("TMP")) /* yes, ASSIGNMENT! */ || (val = getenv("TEMP"))) strcpy(o_directory, val); #endif *o_scroll = LINES / 2 - 1; /* disable the vbell option if we don't know how to do a vbell */ if (!has_VB) { for (i = 0; opts[i].value != o_vbell; i++) { } opts[i].flags &= ~CANSET; *o_vbell = FALSE; } #ifndef NO_DIGRAPH # ifdef CS_LATIN1 for (i = 0, val = o_flipcase; i < 32; i++) { /* leave out the multiply/divide symbols */ if (i == 23) continue; /* add upper/lowercase pair */ *val++ = i + 0xc0; *val++ = i + 0xe0; } *val = '\0'; # endif /* CS_LATIN1 */ #endif /* not NO_DIGRAPH */ } /* This function lists the current values of all options */ void dumpopts(all) int all; /* boolean: dump all options, or just set ones? */ { #ifndef NO_OPTCOLS int i, j, k; char nbuf[4]; /* used for converting numbers to ASCII */ int widths[5]; /* width of each column, including gap */ int ncols; /* number of columns */ int nrows; /* number of options per column */ int nset; /* number of options to be output */ int width; /* width of a particular option */ int todump[50]; /* indicies of options to be dumped */ /* step 1: count the number of set options */ for (nset = i = 0; opts[i].name; i++) { if (all || (opts[i].flags & SET)) { todump[nset++] = i; } } /* step two: try to use as many columns as possible */ for (ncols = (nset > 5 ? 5 : nset); ncols > 1; ncols--) { /* how many would go in this column? */ nrows = (nset + ncols - 1) / ncols; /* figure out the width of each column */ for (i = 0; i < ncols; i++) { widths[i] = 0; for (j = 0, k = nrows * i; j < nrows && k < nset; j++, k++) { /* figure out the width of a particular option */ switch (opts[todump[k]].type) { case BOOL: if (!*opts[todump[k]].value) width = 2; else width = 0; break; case STR: width = 3 + strlen(opts[todump[k]].value); if (width > MAXWIDTH) width = MAXWIDTH; break; case NUM: width = 4; break; } width += strlen(opts[todump[k]].name); /* if this is the widest so far, widen col */ if (width > widths[i]) { widths[i] = width; } } } /* if the total width is narrow enough, then use it */ for (width = -2, i = 0; i < ncols; i++) { width += widths[i] + 2; } if (width < COLS - 1) { break; } } /* step 3: output the columns */ nrows = (nset + ncols - 1) / ncols; for (i = 0; i < nrows; i++) { for (j = 0; j < ncols; j++) { /* if we hit the end of the options, quit */ k = i + j * nrows; if (k >= nset) { break; } /* output this option's value */ width = 0; switch (opts[todump[k]].type) { case BOOL: if (!*opts[todump[k]].value) { qaddch('n'); qaddch('o'); width = 2; } qaddstr(opts[todump[k]].name); width += strlen(opts[todump[k]].name); break; case NUM: sprintf(nbuf, "%-3d", UCHAR(*opts[todump[k]].value)); qaddstr(opts[todump[k]].name); qaddch('='); qaddstr(nbuf); width = 4 + strlen(opts[todump[k]].name); break; case STR: qaddstr(opts[todump[k]].name); qaddch('='); qaddch('"'); strcpy(tmpblk.c, opts[todump[k]].value); width = 3 + strlen(tmpblk.c); if (width > MAXWIDTH) { width = MAXWIDTH; strcpy(tmpblk.c + MAXWIDTH - 6, "..."); } qaddstr(tmpblk.c); qaddch('"'); width += strlen(opts[todump[k]].name); break; } /* pad the field to the correct size */ if (k + nrows <= nset) { while (width < widths[j] + 2) { qaddch(' '); width++; } } } addch('\n'); exrefresh(); } #else int i; int col; char nbuf[4]; for (i = col = 0; opts[i].name; i++) { /* if not set and not all, ignore this option */ if (!all && !(opts[i].flags & SET)) { continue; } /* align this option in one of the columns */ if (col > 52) { addch('\n'); col = 0; } else if (col > 26) { while (col < 52) { qaddch(' '); col++; } } else if (col > 0) { while (col < 26) { qaddch(' '); col++; } } switch (opts[i].type) { case BOOL: if (!*opts[i].value) { qaddch('n'); qaddch('o'); col += 2; } qaddstr(opts[i].name); col += strlen(opts[i].name); break; case NUM: sprintf(nbuf, "%-3d", UCHAR(*opts[i].value)); qaddstr(opts[i].name); qaddch('='); qaddstr(nbuf); col += 4 + strlen(opts[i].name); break; case STR: qaddstr(opts[i].name); qaddch('='); qaddch('"'); qaddstr(opts[i].value); qaddch('"'); col += 3 + strlen(opts[i].name) + strlen(opts[i].value); break; } exrefresh(); } if (col > 0) { addch('\n'); exrefresh(); } #endif } #ifndef NO_MKEXRC /* This function saves the current configuarion of options to a file */ void saveopts(fd) int fd; /* file descriptor to write to */ { int i; char buf[256], *pos; /* write each set options */ for (i = 0; opts[i].name; i++) { /* if unset or unsettable, ignore this option */ if (!(opts[i].flags & SET) || !(opts[i].flags & CANSET)) { continue; } strcpy(buf, "set "); pos = &buf[4]; switch (opts[i].type) { case BOOL: if (!*opts[i].value) { *pos++='n'; *pos++='o'; } strcpy(pos, opts[i].name); strcat(pos, "\n"); break; case NUM: sprintf(pos, "%s=%-3d\n", opts[i].name, *opts[i].value & 0xff); break; case STR: sprintf(pos, "%s=\"%s\"\n", opts[i].name, opts[i].value); break; } twrite(fd, buf, strlen(buf)); } } #endif /* This function changes the values of one or more options. */ void setopts(assignments) char *assignments; /* a string containing option assignments */ { char *name; /* name of variable in assignments */ char *value; /* value of the variable */ char *scan; /* used for moving through strings */ int i, j; /* for each assignment... */ for (name = assignments; *name; ) { /* skip whitespace */ if (*name == ' ' || *name == '\t') { name++; continue; } /* find the value, if any */ for (scan = name; *scan >= 'a' && *scan <= 'z'; scan++) { } if (*scan == '=') { *scan++ = '\0'; if (*scan == '"') { value = ++scan; while (*scan && *scan != '"') { scan++; } if (*scan) { *scan++ = '\0'; } } else { value = scan; while (*scan && *scan != ' ' && *scan != '\t') { scan++; } if (*scan) { *scan++ = '\0'; } } } else { if (*scan) { *scan++ = '\0'; } value = NULL; if (name[0] == 'n' && name[1] == 'o') { name += 2; } } /* find the variable */ for (i = 0; opts[i].name && strcmp(opts[i].name, name) && strcmp(opts[i].nm, name); i++) { } /* change the variable */ if (!opts[i].name) { msg("invalid option name \"%s\"", name); } else if ((opts[i].flags & CANSET) != CANSET) { msg("option \"%s\" can't be altered", name); } else if ((opts[i].flags & RCSET) != CANSET && nlines >= 1L) { msg("option \"%s\" can only be set in a %s file", name, EXRC); } else if (value) { switch (opts[i].type) { case BOOL: msg("option \"[no]%s\" is boolean", name); break; case NUM: j = atoi(value); if (j == 0 && *value != '0') { msg("option \"%s\" must have a numeric value", name); } else if (j < opts[i].value[1] || j > (opts[i].value[2] & 0xff)) { msg("option \"%s\" must have a value between %d and %d", name, opts[i].value[1], opts[i].value[2] & 0xff); } else { *opts[i].value = atoi(value); opts[i].flags |= SET; } break; case STR: strcpy(opts[i].value, value); opts[i].flags |= SET; break; } if (opts[i].flags & MR) { mustredraw = TRUE; } } else /* valid option, no value */ { if (opts[i].type == BOOL) { *opts[i].value = (name[-1] != 'o'); opts[i].flags |= SET; if (opts[i].flags & MR) { mustredraw = TRUE; } } else { msg("option \"%s\" must be given a value", name); } } /* move on to the next option */ name = scan; } /* special processing ... */ /* if "readonly" then set the READONLY flag for this file */ if (*o_readonly) { setflag(file, READONLY); } } SHAR_EOF fi # end of overwriting check if test -f 'osk.c' then echo shar: will not over-write existing file "'osk.c'" else cat << \SHAR_EOF > 'osk.c' /* osk.c */ /* ------------------------------------------------------------------- * | | OS9Lib: stat(), fstat() | | | Copyright (c) 1988 by Wolfgang Ocker, Puchheim, | Ulli Dessauer, Germering and | Reimer Mellin, Muenchen | (W-Germany) | | This programm can be copied and distributed freely for any | non-commercial purposes. It can only be incorporated into | commercial software with the written permission of the authors. | | If you should modify this program, the authors would appreciate | a notice about the changes. Please send a (context) diff or the | complete source to: | | address: Wolfgang Ocker | Lochhauserstrasse 35a | D-8039 Puchheim | West Germany | | e-mail: weo@altger.UUCP, ud@altger.UUCP, ram@altger.UUCP | pyramid!tmpmbx!recco!weo | pyramid!tmpmbx!nitmar!ud | pyramid!tmpmbx!ramsys!ram | * ----------------------------------------------------------------- */ #ifdef OSK #define PATCHLEVEL 1 #ifndef VIREC #include #include "osk.h" #include #include #endif #include #include #include #include /* * f s t a t */ int fstat(fd, buff) int fd; struct stat *buff; { struct fildes ftmp; struct tm ttmp; struct _sgr fopt; if (_gs_gfd(fd, &ftmp, 16) < 0) /* 16 insteat of sizeof(struct fildes) */ return(-1); /* used due to a bug in stupid os9net */ if (_gs_opt(fd, &fopt) < 0) return(-1); ttmp.tm_year = (int) ftmp.fd_date[0]; ttmp.tm_mon = (int) ftmp.fd_date[1] - 1; ttmp.tm_mday = (int) ftmp.fd_date[2]; ttmp.tm_hour = (int) ftmp.fd_date[3]; ttmp.tm_min = (int) ftmp.fd_date[4]; ttmp.tm_sec = 0; ttmp.tm_isdst = -1; buff->st_atime = buff->st_mtime = mktime(&ttmp); ttmp.tm_year = (int) ftmp.fd_dcr[0]; ttmp.tm_mon = (int) ftmp.fd_dcr[1] - 1; ttmp.tm_mday = (int) ftmp.fd_dcr[2]; ttmp.tm_hour = ttmp.tm_min = ttmp.tm_sec = 0; ttmp.tm_isdst = -1; buff->st_ctime = mktime(&ttmp); memcpy(&(buff->st_size), ftmp.fd_fsize, sizeof(long)); /* misalignment! */ buff->st_uid = ftmp.fd_own[1]; buff->st_gid = ftmp.fd_own[0]; buff->st_mode = ftmp.fd_att; buff->st_nlink = ftmp.fd_link; buff->st_ino = fopt._sgr_fdpsn; buff->st_dev = fopt._sgr_dvt; return(0); } /* * s t a t */ int stat(filename, buff) char *filename; struct stat *buff; { register int i, ret; if ((i = open(filename, S_IREAD)) < 0) if ((i = open(filename, S_IFDIR | S_IREAD)) < 0) return(-1); ret = fstat(i, buff); close(i); return(ret); } /* unix library functions mist in OSK Author: Peter Reinig */ /* NOTE: this version of link() is only capable of renaming files, not true * UNIX-style linking. That's okay, though, because elvis only uses it for * renaming. */ link(from,to) char *from,*to; { char *buffer; int status; char *malloc(); if ((buffer = malloc(strlen(from) + strlen(to) + 12)) == NULL) return -1; sprintf(buffer,"rename %s %s\n",from,to); status = system(buffer); free(buffer); return status; } typedef (*procref)(); #define MAX_SIGNAL 10 extern exit(); static int (*sig_table[MAX_SIGNAL])(); static int _sig_install = 0; sig_handler(sig) int sig; { if ((int) sig_table[sig] > MAX_SIGNAL) sig_table[sig](sig); } procref signal(sig,func) int sig; int (*func)(); { int i, (*sav)(); if (!_sig_install) { for (i=0; i < MAX_SIGNAL; i++) sig_table[i] = exit; _sig_install = 1; intercept(sig_handler); } sav = sig_table[sig]; switch ((int) func) { case SIG_DFL : sig_table[sig] = exit; break; case SIG_IGN : sig_table[sig] = 0; break; default : sig_table[sig] = func; break; } return sav; } perror(str) char *str; { static int path = 0; if (!path && (path = open("/dd/sys/Errmsg", S_IREAD)) == -1) { fprintf(stderr,"Can\'t open error message file\n"); path = 0; } if (str && *str) { fprintf(stderr,"%s: ",str); fflush(stderr); } prerr(path,(short) errno); } isatty(fd) int fd; { struct sgbuf buffer; char type; _gs_opt(fd,&buffer); type = buffer.sg_class; if (type == DT_SCF) return 1; else return 0; } #endif /* OSK */ SHAR_EOF fi # end of overwriting check if test -f 'ow.c' then echo shar: will not over-write existing file "'ow.c'" else cat << \SHAR_EOF > 'ow.c' #if OPENWINDOWS #include #include #include #include #include "config.h" #include "vi.h" #include "curses.h" #include "elvis_cps.h" #define PS_ESC '\200' #define TTY 1 /* conditional for compiling in dumb tty support */ #ifndef RUNFILE #define RUNFILE "/usr/local/lib/elvis.ps" /* server side PostScript code */ #endif /* openwindows related elvis stuff */ /* author: mike hoegeman , mh@wlv.imsd.contel.com*/ struct ow_data Ow; int ElvisDestroyTag; extern void destroyProc(); int ElvisKeyTag; extern void keyProc(); int ElvisMiscTag; extern void miscProc(); int ElvisResizeTag; extern void resizeProc(); int ElvisDamageTag; extern void damageProc(); int *NewsTags[] = { &ElvisDestroyTag, &ElvisKeyTag, &ElvisMiscTag, &ElvisResizeTag, &ElvisDamageTag, (int *) 0 }; void destroyProc(tag, data) int tag; caddr_t *data; { ow_beep(); wire_ReadTag(); return; } void damageProc(tag, data) int tag; caddr_t *data; { int i; if (tag >= 0) i = wire_ReadTag(); redraw(MARK_UNSET, FALSE); redraw(cursor, 1); refresh(); return; } void resizeProc(tag, data) int tag; caddr_t *data; { int i; i = wire_ReadTag(); LINES = Ow.wLINES = wire_ReadInt(); COLS = Ow.wCOLS = wire_ReadInt(); return; } void keyProc(tag, data) int tag; caddr_t *data; { int t; t = wire_ReadTag(); Ow.keyFromNews = wire_ReadInt(); wire_ExitNotifier(); return; } int ow_tmpstart(fname) char *fname; { int x; x = tmpstart(fname); if (!Ow.tty) { ps_set_title(*fname == '\0' ? "Elvis" : fname); ps_flush_PostScript(); } return x; } int ow_beep() { #ifdef TTY if (Ow.tty) { beep(); return 0; } # endif ps_beep(); return 0; } int ow_rendermsg(msgtxt) char *msgtxt; { #ifdef TTY if (Ow.tty) return(rendermsg(msgtxt)); #endif ps_rendermsg(msgtxt); return 0; } int ow_appendmsg(old, new) char *old, *new; { /* we could get 'old' from the window but since it's handy here on the c side we might as well use it */ #ifdef TTY if (Ow.tty) return(appendmsg(old, new)); #endif ps_appendmsg(old, new); return 0; } #define DBG #ifdef DBG static int SHOW_OUTPUT = -1; sh(o, s, l, c) int o; char *s; int l, c; { putchar(o); while (l > 0) { putchar(*s++); l--; } putchar(c); return (0); } #define Print if (SHOW_OUTPUT) printf #define SH if (SHOW_OUTPUT) sh #else #define Print #define SH #endif int ttywrite(buf, len) register char *buf; register int len; { #define binc() buf++,len-- #define flushstr() {\ if (string) {\ SH('(', string, buf-string, ')');\ ps_ST(string, buf-string);\ string = (char *)0;\ }\ } #ifdef DBG if (SHOW_OUTPUT < 0) { extern char *getenv(); SHOW_OUTPUT = (getenv("SHOW_OUTPUT") == (char *) 0) ? 0 : 1; } #endif /* this is where we bury all the smarts for display */ if (!Ow.tty) { #define Return(x) {\ if (cursor_disabled)\ {\ ps_enable_cursor();\ Print("{{true /EC C S }}\n");\ }\ ps_flush_PostScript();\ Print("------------------------------------------\n");\ return(x);\ } #define ErrReturn(x) {\ msg("Garbled output, is this a binary file?");\ Print("Garbled output, is this a binary file?");\ Return(x);\ } char *string = (char *) 0; int rval = len; int cursor_disabled = 0; wire_SetCurrent(Ow.mainWire); /* if we have a fair chunk of stuff in our buffer, then just turn off the cursor completely till we are all done then turn it back on at the end. The turning on is done in 'Return' */ if (len > 30) { cursor_disabled++; Print("{{false /EC C S }}\n"); ps_disable_cursor(); } while (len > 0) { switch (*buf) { case PS_ESC: flushstr(); { register char *p; binc(); p = buf; while (*buf != PS_ESC) { if (!*buf) ErrReturn(rval); binc(); } ps_pswrite(p, buf - p); Print("\n"); SH('{', p, buf - p, '}'); Print("\n"); } binc(); break; default: switch (*buf) { case '\r': flushstr(); if (*(buf + 1) == '\n') { Print("\n"); ps_CrNl(); binc(); } else { Print(""); ps_Cr(); } break; case '\n': flushstr(); if (*(buf + 1) == '\r') { Print("\n"); ps_CrNl(); binc(); } else { Print("\n"); ps_Nl(); } break; /* move up one line */ case '\0': /* some binary file ?? , punt */ ErrReturn(rval); default: if (!string) string = buf; break; } binc(); break; } } flushstr(); Return(rval); #undef Return #undef ErrReturn } #ifdef TTY return (write(1, buf, len)); #else return -1; #endif } int ttyread(buf, len) char *buf; int len; { int rlen = 0; #ifdef TTY if (Ow.tty) return read(0, buf, len); #endif Ow.keyFromNews = -1; wire_EnterNotifier(); if (Ow.keyFromNews < 0) return -1; else { *buf++ = Ow.keyFromNews; rlen++; } return rlen; } void miscProc(tag, data) int tag; caddr_t *data; { return; } ow_vi() { extern char *getenv(); if (Ow.tty) { vi(); return 0; } if (getenv("ELVIS_DEBUG") == (char *) 0 && Ow.background) background(); vi(); return; } ow_ex() { ex(); return 0; } int ow_suspend_curses() { #ifdef TTY if (Ow.tty) { suspend_curses(); return 0; } #endif #ifndef NO_CURSORSHAPE if (has_CQ) { do_CQ(); } #endif return 0; } int ow_resume_curses(quietly) int quietly; { /* If we're supposed to quit quietly, then we're done */ void (*proc) (); # ifdef TTY if (Ow.tty) { resume_curses(quietly); return 0; } # endif if (quietly) return; proc = signal(SIGINT, SIG_IGN); { move(LINES - 1, 0); do_SO(); qaddstr("[Press to continue]"); do_SE(); refresh(); ttyread(kbuf, 20); /* in RAW mode, so <20 is very likely */ if (kbuf[0] == ':') { mode = MODE_COLON; addch('\n'); refresh(); } else { mode = MODE_VI; redraw(MARK_UNSET, FALSE); } exwrote = FALSE; } signal(SIGINT, proc); return 0; } #define register_tag(tag_name, tag_value, tag_proc, proc_data)\ wire_RegisterTag(tag_value, tag_proc, proc_data);\ ps_RegisterTag(tag_name, tag_value); int ow_initscr() { extern char *getenv(); extern void starttcap(); char *server; #ifdef TTY if (Ow.tty) { initscr(); return 0; } #endif if (!(server = getenv("NEWSSERVER"))) { server = getenv("DISPLAY"); if (!server || !strncmp(server, "unix", strlen("unix")) || !strncmp(server, "unix", strlen("UNIX"))) server = "localhost"; } Ow.mainWire = wire_Open(server); if (Ow.mainWire == wire_INVALID_WIRE) { /* wire_Perror("elvis"); */ Ow.tty = 1; initscr(); return 0; } else { static int firstime = 1; if (firstime) { wire_ReserveTags(100); wire_AllocateNamedTags(NewsTags); register_tag("ElvisDestroyTag", ElvisDestroyTag, destroyProc, NULL); register_tag("ElvisKeyTag", ElvisKeyTag, keyProc, NULL); register_tag("ElvisMiscTag", ElvisMiscTag, miscProc, NULL); register_tag("ElvisResizeTag", ElvisResizeTag, resizeProc, NULL); register_tag("ElvisDamageTag", ElvisDamageTag, damageProc, NULL); wire_SetCurrent(Ow.mainWire); ps_RunFile(RUNFILE); ps_flush_PostScript(); } else firstime = !firstime; stdscr = kbuf; starttcap(); return 0; } } int ow_getsize(sig) int sig; { extern char o_columns[], o_lines[]; #ifdef TTY if (Ow.tty) return getsize(sig); #endif /* copy the new values into Elvis' options */ *o_columns = COLS = Ow.wCOLS; *o_lines = LINES = Ow.wLINES; return 0; } /* termcap */ /*ARGSUSED*/ int ow_tgetent(bp, name) char *bp; /* buffer for entry */ char *name; /* name of the entry */ { #ifdef TTY if (Ow.tty) return(tgetent(bp,name)); #endif *bp = '\0'; return 1; } #define CAP(str) CAP2((str)[0], (str)[1]) #define CAP2(a,b) (((a) << 8) + ((b) & 0xff)) int ow_tgetnum(id) char *id; { #ifdef TTY if (Ow.tty) return(tgetnum(id)); #endif switch (CAP(id)) { /* # lines of lines on screen or page */ case CAP2('l', 'i'): return 44; /* # of columns in a line */ case CAP2('c', 'o'): return 80; /* # of garbage chars left by so or se */ case CAP2('s', 'g'): return 0; /* # of garbage chars left by us or ue */ case CAP2('u', 'g'): return 0; default: return -1; } } int ow_tgetflag(id) char *id; { #ifdef TTY if (Ow.tty) return(tgetflag(id)); #endif switch (CAP(id)) { /* terminal has **no** automatic margins */ case CAP2('a', 'm'): return 0; /* terminal has backspace capability */ case CAP2('b', 's'): return 1; /* safe to move while in insert mode */ case CAP2('m', 'i'): return 1; default: return 0; } } #define VAL2(v,a) (a) #define VAL3(a,b,c) (a) char * ow_tgetstr(id, bp) char *id; char **bp; /* pointer to pointer to buffer - ignored */ { #ifdef TTY extern char *tgetstr(); if (Ow.tty) return(tgetstr(id,bp)); #endif /* send method id to 'C', 'S' is a shorthand for 'send' */ #define RETURN(FIRSTLETTER,SECONDLETTER) {\ static char tp[] = {\ PS_ESC,\ '/', FIRSTLETTER, SECONDLETTER, ' ',\ 'C',' ','S',' ',\ PS_ESC\ };\ return tp;\ } switch (CAP(id)) { /* clear to end of line */ case CAP2('c', 'e'): RETURN('c', 'e'); /* clear to end of screen and home cursor */ case CAP2('c', 'l'): RETURN('c', 'l'); /* scroll text down */ case CAP2('s', 'r'): RETURN('s', 'r'); /* cursor invisible */ case CAP2('v', 'i'): RETURN('v', 'i'); /* cursor visible */ case CAP2('v', 'e'): RETURN('v', 'e'); /*- case CAP2('a', 'l'): RETURN('a', 'l'); case CAP2('d', 'l'): RETURN('d', 'l'); */ /* start bold */ case CAP2('s', 'o'): RETURN('s', 'o'); /* end bold */ case CAP2('s', 'e'): RETURN('s', 'e'); /* start underline */ case CAP2('u', 's'): RETURN('u', 's'); /* end underline */ case CAP2('u', 'e'): RETURN('u', 'e'); /* ------ cursor style change commands --------*/ /* change to normal cursor */ case CAP2('c', 'Q'): RETURN('c', 'Q'); /* change to ex command entry cursor */ case CAP2('c', 'X'): RETURN('c', 'X'); /* change to vi command mode cursor */ case CAP2('c', 'V'): RETURN('c', 'V'); /* change to vi input mode cursor */ case CAP2('c', 'I'): RETURN('c', 'I'); /* change to vi replace mode cursor */ case CAP2('c', 'R'): RETURN('c', 'R'); #if 0 case CAP2('V', 'B'): RETURN('V', 'B'); case CAP2('V', 'b'): RETURN('V', 'b'); case CAP2('d', 'o'): RETURN('d', 'o'); case CAP2('n', 'd'): RETURN('n', 'd'); case CAP2('t', 'i'): RETURN('t', 'i'); case CAP2('t', 'e'): return ""; case CAP2('k', 'u'): return "#H"; case CAP2('k', 'd'): return "#P"; case CAP2('k', 'l'): return "#K"; case CAP2('k', 'r'): return "#M"; case CAP2('H', 'M'): return "#G"; case CAP2('E', 'N'): return "#O"; case CAP2('P', 'U'): return "#I"; case CAP2('P', 'D'): #endif /* move up one line */ case CAP2('u', 'p'): RETURN('u', 'p'); /* backspace */ case CAP2('b', 'c'): RETURN('b', 'c'); /* cursor motion */ case CAP2('c', 'm'): { static char *tp = "\200%d %d /cm C S \200"; return tp; } default: return (char *) 0; } } /*ARGSUSED*/ char * ow_tgoto(cm, destcol, destrow) char *cm; /* cursor movement string -- ignored */ int destcol; /* destination column, 0 - 79 */ int destrow; /* destination row, 0 - 24 */ { static char buf[30]; #ifdef TTY extern char *tgoto(); if (Ow.tty) return (tgoto(cm, destcol, destrow)); #endif sprintf(buf, "\200%d %d /cm C S \200", destcol, destrow); return buf; } /* declaring cp a register makes gcc blow up ?? ! ?? */ void ow_tputs(cp, affcnt, outfn) char *cp; int affcnt; /* number of affected lines -- ignored */ int (*outfn) (); /* the output function */ { #ifdef TTY if (Ow.tty) { tputs(cp,affcnt,outfn); return; }; #endif while (*cp != '\0') { (*outfn)(*cp); cp++; } return; } int ow_scrolldown(l, y, x) long l; int y, x; { extern void drawtext(); REG char *text; char buf[80]; #ifdef TTY if (Ow.tty) return(scrolldown(l, y, x)); #endif /*- do ... - a move(y, x) - topline-l do_SR()'s - a move(topline-l-1, 0); */ sprintf( buf, "\200 %d %d /cm C S %d /SR C S %d %d /cm C S \200", y, x, (topline-l), (topline-1)-1, 0 ); qaddstr(buf); move((topline - l) - 1, 0); while (l < topline) { topline--; text = fetchline(topline); drawtext(text, FALSE); do_UP(); do_UP(); } move(LINES - 1, 0); clrtoeol(); return 0; } int ow_scrollup(l, y, x) long l; int y,x; { REG char *text; char buf[80]; #ifdef TTY if (Ow.tty) return(scrollup(l, y, x)); #endif move(y,x); clrtoeol(); sprintf(buf, "\200 %d /RSR C S \200", l-(botline)); qaddstr(buf); move(y - (l-botline), 0); while (l > botline) { topline++; /* <-- also adjusts botline */ text = fetchline(botline); drawtext(text, FALSE); } return 0; } /*+ X11/NeWS specific flags: -tty Force elvis to use the plain termcap interface and not the window interface. elvis will revert to the termcap interface automatically if it cannot connect to the X11/NeWS server. -bkg Have elvis run in the background, disassociated from the parent process. If "elvis" is the name of this program this is the default. +bkg Force elvis to run in the forground process. If the name of the program is not elvis ("vi" for example). then this is the default. -*/ int ow_customflags(argv, argc_p) char *argv[]; int *argc_p; { int x, e; # if MALLOC_DEBUG malloc_debug(MALLOC_DEBUG); # endif # define eq(a,b) (!strcmp(a,b)) # define skip() x++ # define shift() \ {\ int i;\ for (e = *argc_p, i=x; i #include int background() { int fd, p; p = fork(); switch (p) { case -1: perror("fork"); exit(1); default: exit(0); case 0: break; } (void) setpgrp(0, getpid()); if ((fd = open("/dev/tty", O_RDWR)) >= 0) { ioctl(fd, TIOCNOTTY, 0); close(fd); } return 0; } #endif SHAR_EOF fi # end of overwriting check if test -f 'ow_tcap.c' then echo shar: will not over-write existing file "'ow_tcap.c'" else cat << \SHAR_EOF > 'ow_tcap.c' #include #include "curses.h" /* implemenatation of the wprintw curses function */ void ow_printw(va_alist) va_dcl { char *fmt; WINDOW *win; va_list args; char tmpbuf[512]; va_start(args); win = va_arg(args, char *); fmt = va_arg(args, char *); vsprintf(tmpbuf, fmt, args); va_end(args); waddstr(win, tmpbuf); return; } SHAR_EOF fi # end of overwriting check # End of shell archive exit 0