allbery@ncoast.UUCP (Brandon S. Allbery) (01/31/88)
Comp.sources.misc: Volume 2, Issue 36 Submitted-By: The Moderator <allbery@ncoast.UUCP> Archive-Name: usc/Part4 I've received so many requests for my Unify(r) screen routines that I am posting them. The USC library is in four parts; unshar them and type "make". The curses used is System V; BSDers will want to tweak the usual stuff, such as beep() and cbreak(). I also have a simple screen program using this; if demand warrants, I will post it -- but in terms of features, you're probably better off with ENTER. #--------------------------------CUT HERE------------------------------------- #! /bin/sh # # This is a shell archive. Save this into a file, edit it # and delete all lines above this comment. Then give this # file to sh by executing the command "sh file". The files # will be extracted into the current directory owned by # you with default permissions. # # The files contained herein are: # # -r--r--r-- 1 allbery users 2258 Jan 30 18:01 utime.c # -r--r--r-- 1 allbery users 2712 Jan 30 18:01 xerror.c # -rw-r--r-- 1 allbery users 222 Jan 30 18:01 xrc.h # -r--r--r-- 1 allbery users 1363 Jan 30 18:01 xsfldesc.c # -rw-r--r-- 1 allbery users 540 Jan 30 18:01 xsfldesc.h # -r--r--r-- 1 allbery users 784 Jan 30 18:01 xsize.c # -r--r--r-- 1 allbery users 1444 Jan 30 18:01 yorn.c # -r--r--r-- 1 allbery users 8188 Jan 30 18:01 zoom.c # echo 'x - utime.c' if test -f utime.c; then echo 'shar: not overwriting utime.c'; else sed 's/^X//' << '________This_Is_The_END________' > utime.c X/* X * $Header: utime.c,v 1.5 87/06/09 11:53:19 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: utime.c,v $ X * Revision 1.5 87/06/09 11:53:19 brandon X * Right-justified buffer display; repositioned cursor after conversion errors. X * X * Revision 1.4 87/06/01 08:37:49 brandon X * Added ^V (view) capability for related records. X * X * Revision 1.3 87/05/27 14:43:30 brandon X * Made sure buffer was padded with spaces. X * X * Revision 1.2 87/05/26 14:29:40 brandon X * Well, utime() was the culprit (be nice if I could read!)-: X * X * Revision 1.1 87/05/26 13:34:36 brandon X * Initial revision X * X * Revision 1.4 87/05/12 13:26:31 brandon X * Dumb bug in : parsing. X * X * Revision 1.3 87/05/12 12:04:10 brandon X * Changed to pass FWD, BACK, GO without checking the data buffer X * X * Revision 1.2 87/04/29 11:30:53 brandon X * Added RCS header information X * X */ X X/*LINTLIBRARY*/ X X#include "usc.h" X X/* X * Get a time. H:M only. X */ X Xint updtime(buf) Xshort *buf; { X int cnt, rc, hr, min, y, x; X char ibuf[6]; X X setraw(); X (void) sprintf(ibuf, "%02d:%02d", *buf / 60, *buf % 60); X getyx(stdscr, y, x); X for (;;) { X (void) move(y, x); X if ((rc = inl(ibuf, 5, 0)) == BACK || rc == FWD || rc == GO || rc == LOOK) X return rc; X for (cnt = 0; cnt < 5 && ibuf[cnt] == ' '; cnt++) X ; X if (cnt == 5) { X prtmsg(1, 23, "Invalid time"); X continue; X } X if (!isdigit(cnt)) { X prtmsg(1, 23, "Invalid time"); X continue; X } X hr = 0; X min = 0; X while (cnt < 5 && isdigit(ibuf[cnt])) { X hr *= 10; X hr += ibuf[cnt++] - '0'; X } X if (cnt > 2 || ibuf[cnt++] != ':') { X prtmsg(1, 23, "Invalid time"); X continue; X } X if (!isdigit(ibuf[cnt])) { X prtmsg(1, 23, "Invalid time"); X continue; X } X min = 10 * (ibuf[cnt++] - '0'); X if (!isdigit(ibuf[cnt])) { X prtmsg(1, 23, "Invalid time"); X continue; X } X min += ibuf[cnt++] - '0'; X while (cnt < 5) X if (ibuf[cnt++] != ' ') { X prtmsg(1, 23, "Invalid time"); X continue; X } X if (hr < 23 && min < 59) X break; X prtmsg(1, 23, "Invalid time"); X } X return rc; X} ________This_Is_The_END________ if test `wc -l < utime.c` -ne 97; then echo 'shar: utime.c was damaged during transit (should have been 97 bytes)' fi fi ; : end of overwriting check echo 'x - xerror.c' if test -f xerror.c; then echo 'shar: not overwriting xerror.c'; else sed 's/^X//' << '________This_Is_The_END________' > xerror.c X/* X * $Header: xerror.c,v 1.9 87/05/29 10:53:45 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: xerror.c,v $ X * Revision 1.9 87/05/29 10:53:45 brandon X * Have to deal with an error before the screen is set up (was dumping core on X * endwin() with stdscr == NULL). X * X * Revision 1.8 87/05/12 10:57:56 brandon X * Tried a better way of resetting to standard terminal mode. X * X * Revision 1.7 87/05/11 17:03:57 brandon X * oops! "errprog" -> "errcall" X * X * Revision 1.6 87/05/11 16:57:44 brandon X * added an error hook (primary use is to dump core on error exit) X * X * Revision 1.5 87/05/11 14:12:33 brandon X * rearranged order of echo() kludge and other I/O routines to make sure it X * takes X * X * Revision 1.4 87/05/11 13:32:41 brandon X * echo() call conflicts with unify; changed to system("stty echo") [UGH!] X * X * Revision 1.3 87/05/01 16:15:06 brandon X * V_prgnm turned out to be defined in libx.a (unify). X * X * Revision 1.2 87/04/29 11:31:27 brandon X * Added RCS header information X * X */ X X/*LINTLIBRARY*/ X X#include "usc.h" X#include <varargs.h> X X/* X * Error log operations. We try to emulate UNIFY 3.2's error log stuff, but X * it's not absolutely essential that we succeed (thankfully). X * X * A side benefit of this for pre-3.2 users is that the error log is used X * regardless of the UNIFY version. (The error log should have been in the X * first version of UNIFY.) X */ X Xextern int errno; Xextern char *V_prgnm; X Xchar errcall[30] = "xerror"; Xvoid (*errhook)() = (void (*)()) 0; X X/*VARARGS*/ Xxerror(va_alist) Xva_dcl { X va_list args; X int ier; X char *fnm, *fmt; X FILE *errlog; X long now; X X if (stdscr != (WINDOW *) 0) X (void) endwin(); X va_start(args); X ier = va_arg(args, int); X fnm = va_arg(args, char *); X fmt = va_arg(args, char *); X if ((errlog = _dbfopen("errlog", "a")) == (FILE *) 0) { X errlog = stderr; X (void) fprintf(stderr, "\r\nInternal error %d/%d from %s: ", ier, errno, fnm); X } X else { X now = time((long *) 0); X (void) fprintf(errlog, "\n***\n\n%s\nProgram: %s\nCalling function: %s\nOffending function: %s\nStatus: %d\nErrno: %d\nNotes: ", X ctime(&now), V_prgnm, errcall, fnm, ier, errno); X (void) fprintf(stderr, "\r\nAn internal program error has occurred. Please see the error log for details.\r\n\r\n\r\n"); X } X (void) vfprintf(errlog, fmt, args); X va_end(args); X if (errlog == stderr) X (void) fprintf(stderr, "\r\n\r\n"); X else X (void) putc('\n', errlog); X if (errhook != (void (*)()) 0) X (*errhook)(ier, fnm, errcall); X exit(99); X} ________This_Is_The_END________ if test `wc -l < xerror.c` -ne 93; then echo 'shar: xerror.c was damaged during transit (should have been 93 bytes)' fi fi ; : end of overwriting check echo 'x - xrc.h' if test -f xrc.h; then echo 'shar: not overwriting xrc.h'; else sed 's/^X//' << '________This_Is_The_END________' > xrc.h Xextern int setxrc(); X X#define XRC_GO 1 /* allow new return code -5 (also -6 if XRC_XOK) */ X#define XRC_XOK 2 /* allow new return code -7 (also -6 if XRC_GO) */ X#define XRC_LOOK 4 /* allow new return code -8 (internal) */ ________This_Is_The_END________ if test `wc -l < xrc.h` -ne 5; then echo 'shar: xrc.h was damaged during transit (should have been 5 bytes)' fi fi ; : end of overwriting check echo 'x - xsfldesc.c' if test -f xsfldesc.c; then echo 'shar: not overwriting xsfldesc.c'; else sed 's/^X//' << '________This_Is_The_END________' > xsfldesc.c X/* X * $Header: xsfldesc.c,v 1.6 87/05/11 15:50:16 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: xsfldesc.c,v $ X * Revision 1.6 87/05/11 15:50:16 brandon X * removed debugging X * X * Revision 1.5 87/05/11 15:47:13 brandon X * another check added X * X * Revision 1.4 87/05/11 15:42:25 brandon X * wrong debug sring X * X * Revision 1.3 87/05/11 15:38:54 brandon X * bugchk X * X * Revision 1.2 87/04/29 11:31:28 brandon X * Added RCS header information X * X */ X X/*LINTLIBRARY*/ X X#include "usc.h" X X/* X * ENTRY POINT: xsfldesc() -- Return complete screen field description X * X * DIFFERENCE FROM UNIFY: This function is not provided in the UNIFY screen X * interface. Its purpose is to allow screen fields to be examined or set X * from a program. In particular, a program may load extended attributes X * (uppercase shifting only at present) for screen fields, which will then be X * used automatically by inbuf() and input(). X * X * This function returns a pointer to the internal screen field structure, X * which is delared in xsfdesc.h. X */ X Xstruct q *xsfldesc(sfld) { X if (sfld < 0 || sfld >= __nsf) X return (struct q *) 0; X return &__scf[sfld]; X} ________This_Is_The_END________ if test `wc -l < xsfldesc.c` -ne 49; then echo 'shar: xsfldesc.c was damaged during transit (should have been 49 bytes)' fi fi ; : end of overwriting check echo 'x - xsfldesc.h' if test -f xsfldesc.h; then echo 'shar: not overwriting xsfldesc.h'; else sed 's/^X//' << '________This_Is_The_END________' > xsfldesc.h X/* X * The internal screen field structure. xsfldesc() return a POINTER to the X * actual struct, so be careful!!! Only one update operation is defined: to X * OR the flag UPCASE (below) with it to tell USC to force input to be upper X * case on the field. X */ X Xstruct xsfldesc { X char xsf_nam[8]; X char xsf_dbfld[44]; X short xsf_fld; X short xsf_typ; X short xsf_len; X short xsf_col; X short xsf_lin; X char xsf_prmp[40]; X short xsf_pcol; X short xsf_plin; X}; X X#define XSFLDESC struct xsfldesc X#define UPCASE 0x80 X Xextern XSFLDESC *xsfldesc(); ________This_Is_The_END________ if test `wc -l < xsfldesc.h` -ne 24; then echo 'shar: xsfldesc.h was damaged during transit (should have been 24 bytes)' fi fi ; : end of overwriting check echo 'x - xsize.c' if test -f xsize.c; then echo 'shar: not overwriting xsize.c'; else sed 's/^X//' << '________This_Is_The_END________' > xsize.c X/* X * $Header: xsize.c,v 1.1 87/05/12 10:49:42 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: xsize.c,v $ X * Revision 1.1 87/05/12 10:49:42 brandon X * Initial revision X * X */ X X/*LINTLIBRARY*/ X X#include "usc.h" X X/* X * The "xsize" function returns the external size of a screen field. X */ X Xint xsize(typ, len) { X switch (typ) { X case INT: X case LONG: X case STRNG: X return len; X case DATE: X return 8; X case HR: X return 5; X case AMT: X case HAMT: X return len + 3; X case FLT: X return len / 10; X default: X xerror(typ, "xsize", "Unknown internal type"); X /*NOTREACHED*/ X } X} ________This_Is_The_END________ if test `wc -l < xsize.c` -ne 43; then echo 'shar: xsize.c was damaged during transit (should have been 43 bytes)' fi fi ; : end of overwriting check echo 'x - yorn.c' if test -f yorn.c; then echo 'shar: not overwriting yorn.c'; else sed 's/^X//' << '________This_Is_The_END________' > yorn.c X/* X * $Header: yorn.c,v 1.5 87/06/01 11:26:32 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: yorn.c,v $ X * Revision 1.5 87/06/01 11:26:32 brandon X * After adding code to save the upshift state, I forgot to assign the new X * state. (oops :-) X * X * Revision 1.4 87/06/01 11:15:46 brandon X * Smartened up response and cleared prompt before returning X * X * Revision 1.3 87/05/26 13:34:48 brandon X * Uses update mode with default = 'N'. X * X * Revision 1.2 87/04/29 11:31:30 brandon X * Added RCS header information X * X */ X X/*LINTLIBRARY*/ X X#include "usc.h" X X/* X * ENTRY POINT: yorn() -- Ask for confirmation of an operation X * X * DIFFERENCE FROM UNIFY: None. X */ X Xyorn(prompt) Xchar *prompt; { X char ib[1]; X int oucf, ier; X X setraw(); X (void) mvaddstr(22, 1, prompt); X for (;;) { X ib[0] = 'N'; X oucf = _sh_up; X _sh_up = 1; X ier = inl(ib, 1, 0); X _sh_up = oucf; X switch (ier) { X case FWD_OK: X break; X case BACK: X case BACK_OK: X case GO: X case GO_OK: X case FWD: X ib[0] = 'N'; X } X switch (ib[0]) { X case 'Y': X case 'y': X (void) move(22, 1); X (void) clrtoeol(); X return 1; X case 'N': X case 'n': X (void) move(22, 1); X (void) clrtoeol(); X return 0; X } X prtmsg(1, 23, "Please enter Y or N"); X } X} ________This_Is_The_END________ if test `wc -l < yorn.c` -ne 73; then echo 'shar: yorn.c was damaged during transit (should have been 73 bytes)' fi fi ; : end of overwriting check echo 'x - zoom.c' if test -f zoom.c; then echo 'shar: not overwriting zoom.c'; else sed 's/^X//' << '________This_Is_The_END________' > zoom.c X/* X * $Header: zoom.c,v 1.11 87/06/09 12:34:44 brandon Exp $ X * X * ``USC'' -- UNIFY(r) Screens using Curses X * UNIFY(r) is a registered trademark of Unify Corporation. X * X * THIS PROGRAM IS NOT BASED ON COPYRIGHTED CODE OF UNIFY CORPORATION, AND X * IS HEREBY PLACED IN THE PUBLIC DOMAIN. X * X * $Log: zoom.c,v $ X * Revision 1.11 87/06/09 12:34:44 brandon X * OOPS! Wanted wattroff(), *used* attroff().... sigh. X * X * Revision 1.10 87/06/09 12:31:57 brandon X * Added RV "cursor"; fixed clearing on last page. X * X * Revision 1.9 87/06/03 13:17:30 brandon X * Fixed final paging bugs; now full functional. X * X * Revision 1.8 87/06/03 11:10:01 brandon X * Added extra refresh() so the cursor will end up in the NEW window. I hope. X * X * Revision 1.7 87/06/02 12:51:55 brandon X * Linted. X * X * Revision 1.6 87/06/02 12:34:22 brandon X * Linted. X * X * Revision 1.5 87/06/02 12:16:40 brandon X * Changed error() to xerror(); also ifdefed for Unify 3.2 (it won't work under X * earlier versions, since it uses the new data dictionary access calls). X * X * Revision 1.4 87/06/01 16:43:29 brandon X * Now uses incs() (input character by status code) instead of getchar(). X * X * Revision 1.3 87/06/01 10:05:16 brandon X * Made sure current-record cursor stayed in place on FWD from last record. X * X * Revision 1.2 87/06/01 09:35:01 brandon X * Added touchwin() to fix curses bug with missing touchwin() in delwin(). X * (This bug is actually a holdover from the old curses.??!) X * X * Revision 1.1 87/06/01 08:31:27 brandon X * Initial revision X * X */ X X/*LINTLIBRARY*/ X X#ifndef UNIFY32 X#ifndef lint Xstatic char dummy = '\0'; /* dumb loaders (Sys III) need this, alas */ X#endif X#else X X#include "usc.h" X#ifdef TG X#include "tgraph.h" X#else X#ifndef ACS_HLINE X#define ACS_HLINE '-' X#define ACS_VLINE '|' X#define ACS_LLCORNER '`' X#define ACS_ULCORNER ',' X#define ACS_LRCORNER '\'' X#define ACS_URCORNER '.' X#define ACS_TTEE '+' X#define ACS_BTEE '+' X#endif X#endif X Xextern char *fldsyn(); Xextern long atol(); X X/* X * When XRC_LOOK is enabled and ^V is entered in a field with an explicit X * relationship, zoom() is invoked to display a browse window. The user may X * then move around within the window, select a record, and return, which X * causes that record's key to be entered as the value of the field. X * X * TAB move up one record X * RET move down one record X * ^F move forward one page X * ^B move back X * ^V exit without returning a value X * ESC exit and return key of current record X */ X Xzoom(x, y, fld, fdp, buf) XFLDESC *fdp; Xchar *buf; { X WINDOW *w; X int nfld, bfld, cnt, len, ier; X int *bwf; X long myloc, endloc, pageloc, lastrec; X FLDESC fd; X char xbuf[256]; X X nfld = 0; X for (bfld = numflds(); bfld > 0; bfld--) X if (fldesc(bfld, &fd) && fd.f_rec == fdp->f_rprec && fd.f_typ != COMB) X nfld++; X if ((bwf = (int *) malloc((unsigned) (nfld + 1) * sizeof *bwf)) == (int *) 0) X xerror("zoom", 0, "out of memory at field %d", fld); X bwf[nfld--] = 0; X for (bfld = numflds(); bfld > 0; bfld--) X if (fldesc(bfld, &fd) && fd.f_rec == fdp->f_rprec && fd.f_typ != COMB) X bwf[nfld--] = bfld; X len = 3; X for (nfld = 0; bwf[nfld] != 0; nfld++) { X (void) fldesc(bwf[nfld], &fd); X if ((bfld = strlen(fldsyn(bwf[nfld]))) > fd.f_len) X fd.f_len = bfld; X if ((len += fd.f_len + 1) >= COLS) X break; X } X if (bwf[nfld] != 0) { X len -= fd.f_len + 1; X bwf[nfld] = 0; X } X if (LINES - y < 5) X y = LINES - 5; X if ((x -= len - 2) < 0) X x = 0; X if ((w = newwin(LINES - y - 1, len, y, x)) == (WINDOW *) 0) X xerror("zoom", 0, "can't allocate window"); X /* now ready to display stuff in our pet window */ X#ifdef TG X graph(""); X#endif X (void) box(w, ACS_VLINE, ACS_HLINE); X (void) mvwaddch(w, 0, 0, ACS_ULCORNER); X (void) mvwaddch(w, LINES - y - 2, 0, ACS_LLCORNER); X (void) mvwaddch(w, LINES - y - 2, len - 1, ACS_LRCORNER); X (void) mvwaddch(w, 0, len - 1, ACS_URCORNER); X cnt = 2; X for (nfld = 0; bwf[nfld + 1] != 0; nfld++) { X (void) fldesc(bwf[nfld], &fd); X if ((bfld = strlen(fldsyn(bwf[nfld]))) > fd.f_len) X fd.f_len = bfld; X cnt += fd.f_len; X (void) mvwaddch(w, 0, cnt, ACS_TTEE); X (void) mvwaddch(w, LINES - y - 2, cnt, ACS_BTEE); X cnt++; X } X (void) wmove(w, 1, 2); X for (nfld = 0; bwf[nfld] != 0; nfld++) { X (void) fldesc(bwf[nfld], &fd); X if ((bfld = strlen(fldsyn(bwf[nfld]))) > fd.f_len) X fd.f_len = bfld; X (void) wattron(w, A_UNDERLINE); X (void) wprintw(w, "%-*.*s", fd.f_len, fd.f_len, fldsyn(bwf[nfld])); X (void) wattroff(w, A_UNDERLINE); X if (bwf[nfld + 1] != 0) X (void) waddch(w, ACS_VLINE); X } X myloc = 1; X pageloc = 1; X lastrec = sort(fdp->f_rprec); X for (;;) { X cnt = 2; X endloc = pageloc; X for (ier = sethere(fdp->f_rprec, pageloc); cnt < LINES - y - 2 && ier == 0; ier = sethere(fdp->f_rprec, ++endloc)) { X (void) mvwaddch(w, cnt, 1, ' '); X for (nfld = 0; bwf[nfld] != 0; nfld++) { X (void) fldesc(bwf[nfld], &fd); X (void) gprint(bwf[nfld], xbuf); X if ((bfld = strlen(fldsyn(bwf[nfld]))) > fd.f_len) X fd.f_len = bfld; X if (myloc == endloc) X (void) wattron(w, A_STANDOUT); X (void) wprintw(w, "%-*.*s", fd.f_len, fd.f_len, xbuf); X if (myloc == endloc) X (void) wattroff(w, A_STANDOUT); X if (bwf[nfld + 1] != 0) X (void) waddch(w, ACS_VLINE); X } X cnt++; X } X endloc--; X/* if (myloc < pageloc || myloc > endloc) X myloc = pageloc; */ X while (cnt < LINES - y - 2) { X (void) mvwaddch(w, cnt, 1, ' '); X for (nfld = 0; bwf[nfld] != 0; nfld++) { X (void) fldesc(bwf[nfld], &fd); X if ((bfld = strlen(fldsyn(bwf[nfld]))) > fd.f_len) X fd.f_len = bfld; X (void) wprintw(w, "%*s", fd.f_len, ""); X if (bwf[nfld + 1] != 0) X (void) waddch(w, ACS_VLINE); X } X cnt++; X } X cnt = myloc - pageloc; X (void) wattron(w, A_STANDOUT); X (void) mvwaddch(w, 2 + cnt, 1, '>'); X (void) wattroff(w, A_STANDOUT); X (void) wmove(w, 2 + cnt, 1); X (void) refresh(); /* so the next one places the cursor */ X (void) wrefresh(w); X ier = 0; X switch (incs(XRC_GO|XRC_LOOK|XRC_CFB|XRC_NOFLSH)) { X case GO: X if ((ier = sethere(fdp->f_rprec, myloc)) != 0) { X prtmsg(1, 23, "Record not available"); X continue; X } X (void) gfield(fdp->f_rpfld, buf); X ier = 1; X /*FALLTHROUGH*/ X case LOOK: X unsort(fdp->f_rprec); X (void) delwin(w); X (void) touchwin(stdscr); X free((char *) bwf); X return (ier? OK: FWD); X case FWD: X if (++myloc <= endloc) X break; X if (myloc > lastrec) X myloc = lastrec; X /*FALLTHROUGH*/ X case CFWD: X if ((pageloc += LINES - y - 4) > lastrec) { X prtmsg(1, 23, "There is no next page"); X pageloc -= LINES - y - 4; X } X break; X case BACK: X if (--myloc >= pageloc) X break; X if (myloc < 0) X myloc = 0; X /*FALLTHROUGH*/ X case CBACK: X if ((pageloc -= LINES - y - 4) < 1) { X prtmsg(1, 23, "There is no previous page"); X pageloc = 1; X } X break; X default: X (void) beep(); X } X } X} X X/*****************************************************************************/ X Xstatic FILE *_F_ = (FILE *) 0; Xstatic int _S_ = 0; X Xsort(r) { X int ier, key; X long nrec, here; X FLDESC fd; X char buf[1024], t[50]; X X if (_F_ != (FILE *) 0) X unsort(r); X (void) sprintf(t, "/tmp/,zt%05d", getpid()); X if ((_F_ = fopen(t, "w")) == (FILE *) 0) X xerror("zoomsort", 0, "cannot create tag file %s", t); X (void) fldesc(key = reckey(r), &fd); X nrec = 0L; X for (ier = seqacc(r, 1); ier == 0; ier = seqacc(r, 2)) { X nrec++; X (void) gprint(key, buf); X (void) loc(r, &here); X (void) sprintf(buf + fd.f_len, "%09ld\n", here); X (void) fputs(buf, _F_); X } X (void) fclose(_F_); X switch (fork()) { X case -1: X xerror("zoomsort", 0, "cannot fork"); X case 0: X (void) sprintf(buf, "-0.%d", fd.f_len); X (void) execlp("sort", "sort", "+0", buf, t, "-o", t, (char *) 0); X _exit(-1); X default: X (void) wait((int *) 0); X } X if ((_F_ = fopen(t, "r")) == (FILE *) 0) X xerror("zoomsort", -1, "cannot reopen tagfile %s", t); X (void) unlink(t); X _S_ = fd.f_len + 10; X return nrec; X} X Xunsort(r) { X (void) fclose(_F_); X _F_ = (FILE *) 0; X _S_ = 0; X} X Xsethere(r, pos) Xlong pos; { X char buf[1024]; X X (void) fseek(_F_, (pos - 1) * _S_, 0); X if (fgets(buf, sizeof buf, _F_) == (char *) 0) X return -1; X return setloc(r, atol(buf + _S_ - 10)); X} X X#endif ________This_Is_The_END________ if test `wc -l < zoom.c` -ne 307; then echo 'shar: zoom.c was damaged during transit (should have been 307 bytes)' fi fi ; : end of overwriting check exit 0