📄 part02
字号:
Xeoe: put_string (Exit_mode, 0);X RETURN (p-s);X }SHAR_EOFif test 6631 -ne "`wc -c < 'field.c'`"then echo shar: error transmitting "'field.c'" '(should have been 6631 characters)'fifi # end of overwriting checkecho shar: extracting "'selection.c'" '(5773 characters)'if test -f 'selection.c'then echo shar: will not over-write existing file "'selection.c'"elsesed 's/^X//' << \SHAR_EOF > 'selection.c'X/* Last update: 01/27/88 00:04 AM (Edition: 45) */X#include <stdio.h>X#include <sys/ioctl.h>X#include <ctype.h>X#include <strings.h>X#include "term.h"X#include "form.h"X#include "field.h"X#include "basic.h"XXint Help_display = NO; /* if YES, display help */XXextern struct field Field[];Xextern char Enter_mode[];Xextern char Exit_mode[];Xextern int Form_msg;Xextern char Exitc;Xextern char *malloc();Xextern char *calloc();X/*X Selection buffer looks like:XX <delchr> string1 <delchr> string2 <delchr> ... stringn <delchr>XX The first character in the buffer will be used as the delimiter toX separate selection strings. The last delimiter character is optional,X i.e., EOS will also terminate the last selection string.X*/XX/*-------------------------------------------------------------08/01/87-+X| |X| build_selection : take selection definition and create a list |X| |X+----------------------------------------------------------------------*/Xbuild_selection (fldp, buf, len)Xstruct field *fldp; /* ptr to field structure */Xchar *buf; /* selection strings */Xunsigned len; /* length of string */X {X register char *p = (char *)malloc(len+1);X register char **tp;X register int i;X char delimiter = buf[0]; /* selection delimiter */X char c;X unsigned cnt = 0; /* # of selections */X char *tmp[50]; /* temp array */XX ENTER(build_selection);X if (len == 0) len = strlen (buf);X while (len-- != 0) {X if ((c = *buf++) == delimiter) {X *p++ = EOS;X if (cnt >= 50) {X /* silent ignored extra for now */X }X else tmp[cnt++] = p;X }X else *p++ = c;X }X fldp->f_sel = tp = (char **) malloc (sizeof (char *) * (cnt + 1));X for (i=0; i<cnt; i++) *tp++ = tmp[i];X *tp = NULL;X fldp->f_attr |= FA_SELECTION;X RETURN (0);X }XX/*-------------------------------------------------------------08/01/87-+X| |X| sel_num : return the number of selections in a given field |X| |X+----------------------------------------------------------------------*/Xsel_num (fldp)Xstruct field *fldp;X {X register int i = 0;X register char **pp = fldp-> f_sel;XX ENTER(sel_num);X while (*pp++ != NULL) i++;X RETURN (i);X }XX/*-------------------------------------------------------------08/01/87-+X| |X| sel_field : allow user to select a selection from the list |X| |X+----------------------------------------------------------------------*/Xsel_field (idx)Xunsigned idx; /* index to Field array */X {X struct field *fldp = &Field[idx];X int n = fldp-> f_sno; /* selection number */X int selno; /* # of possible selections */X int i = -1;X char c;XX ENTER(sel_field);X selno = sel_num (fldp);X poscur (fldp-> f_line, fldp-> f_col, Enter_mode);X upd_field (idx, UF_STRING, fldp-> f_sel[n]);X while (1) {X int might_tab;X if (Help_display) display_help (fldp, n);X c = getkey ();X might_tab = 0;X if (Form_msg) {X form_msg ((char *)NULL, fldp->f_line, fldp->f_col);X put_string (Enter_mode, 0);X }X if ((c & 0x80) == 0x80) {X switch (c & 0x7f) {X case KL: goto prev_sel;X case KR: goto next_sel;X }X }X switch (c) {X case ' ':X case CTRL('F'):Xnext_sel: if (++n >= selno) n = 0; break;X case CTRL('H'):Xprev_sel: if (--n < 0) n = selno-1; break;X case '?':X if (!Help_display) {X display_help (fldp, n);X break;X }X default:if (c < LOW_GCHAR || c > HIGH_GCHAR) {X Exitc = c;X goto eoe;X }X i = cmp1st (c, fldp->f_sel, i+1);X if (i < 0) continue;X might_tab = 1;X n = i;X }X upd_field (idx, UF_STRING, fldp-> f_sel[n]);X if (might_tab && (fldp->f_attr & FA_AUTOTAB) != 0) {X Exitc = TAB;X break;X }X }Xeoe: put_string (Exit_mode, 0);X fldp-> f_sno = n; /* save selection number */X EXIT;X } XX/*-------------------------------------------------------------08/03/87-+X| |X| cmp1st : compare 1st character in a keyword list |X| |X+----------------------------------------------------------------------*/Xcmp1st (c, list, start)Xchar c; /* char to compare */Xchar **list; /* keyword list */Xint start; /* start entry index */X {X register int i, j;X register int n;XX ENTER(cmp1st);X if (list == NULL || list[0] == NULL) RETURN (-1);X for (n=0; list[n] != NULL; n++);X for (i=start, j=0; j<n; i++, j++) {X if (i >= n) i = 0;X if ((c | 0x20) == (list[i][0] | 0x20)) RETURN (i);X }X RETURN (-1); /* no match */X }XX/*-------------------------------------------------------------08/04/87-+X| |X| build_help_msg : build help message list |X| |X+----------------------------------------------------------------------*/Xbuild_help_msg (fldp, buf)Xstruct field *fldp; /* field where the msg belongs */Xchar *buf; /* message stores here */X {X unsigned len = strlen (buf);X unsigned n;X register int i;X register char *p;XX ENTER(build_help_msg);X n = sel_num (fldp);X if (fldp-> f_help == NULL) { /* first time call */X fldp-> f_help = (char **) calloc(n+1, sizeof(char *));X }X for (i=0; i<n; i++) {X if (fldp-> f_help[i] == NULL) break;X }X if (i < n) {X fldp-> f_help[i] = p = (char *) malloc (len + 1);X strcpy (p, buf);X }X EXIT;X }XX/*-------------------------------------------------------------08/04/87-+X| |X| display_help : display help message on message line |X| |X+----------------------------------------------------------------------*/Xdisplay_help (fldp, i)Xstruct field *fldp; /* field pointer */Xint i; /* index to help message */X {X char *p;X int numchar; /* # of pending input chars */XX ENTER(display_help);X if (fldp-> f_help == NULL) EXIT;X p = fldp-> f_help[i];X if (p != NULL) {X ioctl (0, FIONREAD, &numchar);X if (numchar == 0) form_msg (p, fldp->f_line, fldp->f_col);X }X EXIT;X }SHAR_EOFif test 5773 -ne "`wc -c < 'selection.c'`"then echo shar: error transmitting "'selection.c'" '(should have been 5773 characters)'fifi # end of overwriting checkecho shar: extracting "'keyword.c'" '(1253 characters)'if test -f 'keyword.c'then echo shar: will not over-write existing file "'keyword.c'"elsesed 's/^X//' << \SHAR_EOF > 'keyword.c'X/* Last update: 01/13/88 10:43 AM (Edition: 5) */X#include <stdio.h>X#include "basic.h"X/*----------------------------------------------------------------------+X| |X| fill_keyword : fill the field with possible matched keyword |X| |X+----------------------------------------------------------------------*/Xfill_keyword (buf, len, list)Xchar *buf;Xunsigned len; /* size of input field */Xchar **list;X {X int i, j;X unsigned flen; /* field length */X unsigned char match[80];X X ENTER (fill_keyword);X flen = fldlen (buf, len);X X for (i=j=0; list[i] != NULL; i++) {X if (kwcmp (buf, list[i], flen) == 0) {X /* find a match */X match[j++] = i;X }X }X if (j == 1) bcopy (buf, list[match[0]], len);X else if (j > 1) bcopy (buf, list[match[0]], flen);X X RETURN (j);X }X X/*----------------------------------------------------------------------+X| |X| kwcmp : compare a word with keyword (case insensitive) |X| |X+----------------------------------------------------------------------*/Xkwcmp (src, dest, len)Xchar *src;Xchar *dest;Xunsigned len;X {X ENTER (kwcmp);X while (len-- != 0) {X if ((*src++ | 0x20) != (*dest++ | 0x20))X RETURN (1); /* no match */X }X RETURN (0); /* match found */X }SHAR_EOFif test 1253 -ne "`wc -c < 'keyword.c'`"then echo shar: error transmitting "'keyword.c'" '(should have been 1253 characters)'fifi # end of overwriting checkecho shar: extracting "'option.c'" '(1317 characters)'if test -f 'option.c'then echo shar: will not over-write existing file "'option.c'"elsesed 's/^X//' << \SHAR_EOF > 'option.c'X/* Last update: 01/13/88 11:17 AM (Edition: 5) */X#include <stdio.h>X#include <strings.h>X#include "form.h"X#include "basic.h"XXunsigned char Rvideo; /* reverse video */Xunsigned char Undline; /* under line */Xunsigned char Hilite; /* high light */Xunsigned char Shell = CSH; /* output script type */XXextern char Varfile[];Xextern char Enter_mode[];Xextern char Exit_mode[];X X/*-------------------------------------------------------------05/08/86-+X| |X| set_options : set form editor options |X| |X+----------------------------------------------------------------------*/Xset_options (hilite, rvideo, undline, fname)Xint hilite; /* highlight attribute */Xint rvideo; /* reverse video attribute */Xint undline; /* underline attribute */Xchar *fname; /* output variable file name */X {X char sbuf [80]; /* set mode */X char ebuf [80]; /* exit mode */XX ENTER(set_options);XX sbuf[0] = ebuf[0] = EOS;X if (hilite) {X get_hilite (sbuf, ebuf);X strcat (Enter_mode, sbuf);X strcat (Exit_mode, ebuf);X }X if (undline) {X get_undline (sbuf, ebuf);X strcat (Enter_mode, sbuf);X strcat (Exit_mode, ebuf);X }X if (rvideo) {X get_rvideo (sbuf, ebuf);X strcat (Enter_mode, sbuf);X strcat (Exit_mode, ebuf);X }X if (fname) strncpy (Varfile, fname, MAXFNAME);X EXIT;X }SHAR_EOFif test 1317 -ne "`wc -c < 'option.c'`"then echo shar: error transmitting "'option.c'" '(should have been 1317 characters)'fifi # end of overwriting checkecho shar: extracting "'msg.c'" '(2999 characters)'if test -f 'msg.c'then echo shar: will not over-write existing file "'msg.c'"elsesed 's/^X//' << \SHAR_EOF > 'msg.c'X/* Last update: 01/13/88 10:59 AM (Edition: 11) */X#include <stdio.h>X#include <strings.h>X#include "basic.h"X#include "form.h"X/*X Two flavors to display message:XX form_msg display message then position cursor at givenX position, this allows form filling on terminalX without cursor save restore capability.XX formmsg display message and return to the caller'sX position using terminal's save/restore cursorX ability. This is designed to be used by fieldX checking routine where user don't know whereX the field is.X*/XX#define MAXSMSG 5X#define MSGSIZE 132XXint Form_msg = 0; /* form message on screen flag */XXstatic char Savemsg [MAXSMSG][MSGSIZE];Xstatic int Sdx = 0; /* number of next entry to use */Xstatic int Smcount = 0; /* number of messages saved */X/*----------------------------------------------------------------------+X| |X| form_msg : display message on the message line |X| |X+----------------------------------------------------------------------*/Xform_msg (s, line, col)Xchar *s; /* message to display, if NULL, clear message */Xunsigned char line; /* line to go at end */Xunsigned char col; /* column to go at end */X {X ENTER (form_msg);X poscur ((unsigned char)24, (unsigned char)1, (char *)NULL);X screen (SCR_REVERSE);X screen (SCR_EEOL);X if (s) {X Form_msg = 1;X put_string (s, 0);X save_msg (s);X }X else Form_msg = 0;X poscur (line, col, (char *)NULL);X EXIT;X }X X/*----------------------------------------------------------------------+X| |X| formmsg : form_msg () use terminal SC, RC feature |X| |X+----------------------------------------------------------------------*/Xformmsg (s)Xchar *s; /* message to display, if NULL, clear message */X {X ENTER (formmsg);X screen (SCR_SAVE);X poscur ((unsigned char)24, (unsigned char)1, (char *)NULL);X screen (SCR_REVERSE);X screen (SCR_EEOL);X if (s) {X Form_msg = 1;X put_string (s, 0);X save_msg (s);X }X else Form_msg = 0;X screen (SCR_RESTORE);X EXIT;X }X X/*----------------------------------------------------------------------+X| |X| save_msg : save a message on the message buffer |X| |X+----------------------------------------------------------------------*/Xsave_msg (s)Xchar *s;X {X ENTER (save_msg);X strncpy (Savemsg[Sdx], s, MSGSIZE);X if (++Sdx >= MAXSMSG) Sdx = 0;X if (Smcount < MAXSMSG) Smcount++;X EXIT;X }X X/*----------------------------------------------------------------------+X| |X| prev_msg : display previously displayed message |X| |X+----------------------------------------------------------------------*/Xprev_msg ()X {X ENTER (prev_msg);X if (!Smcount) return (0);X /* This routine actually pop the message stored */X if (--Sdx < 0) Sdx = MAXSMSG-1;X screen (SCR_SAVE);X poscur ((unsigned char)24, (unsigned char)1, (char *)NULL);X screen (SCR_REVERSE);X screen (SCR_EEOL);X put_string (Savemsg[Sdx], 0);X Form_msg = 1;X screen (SCR_RESTORE);X RETURN (1);X }SHAR_EOFif test 2999 -ne "`wc -c < 'msg.c'`"then echo shar: error transmitting "'msg.c'" '(should have been 2999 characters)'fifi # end of overwriting checkecho shar: extracting "'term.c'" '(6575 characters)'if test -f 'term.c'then echo shar: will not over-write existing file "'term.c'"elsesed 's/^X//' << \SHAR_EOF > 'term.c'X/* Last update: 01/13/88 11:16 AM (Edition: 9) */X#include <stdio.h>X#include <ctype.h>X#include <strings.h>X#include "form.h"XX#define YES (1)X#define NO (0)X#define EOS '\0'X#define when break; caseX#define otherwise break;defaultX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -