From: CSBVAX::MRGATE!montnaro@sprite@SMTP 20-MAR-1987 23:11 To: MODSRC Subj: kurses Received: by sprite.steinmetz (3.2/1.1x Steinmetz) id AA07113; Fri, 20 Mar 87 22:54:59 EST Date: Fri, 20 Mar 87 22:54:59 EST From: Skip Montanaro Posted-Date: Fri, 20 Mar 87 22:54:59 EST Message-Id: <8703210354.AA07113@sprite.steinmetz> To: modsrc@arisia.decnet Subject: kurses Path: seismo!ut-sally!husc6!mit-eddie!mirror!sources-request From: sources-request@mirror.TMC.COM Newsgroups: mod.sources Subject: v08i052: A program to call curses(3) functions Message-ID: <1649@mirror.TMC.COM> Date: 9 Feb 87 18:21:18 GMT Sender: rs@mirror.TMC.COM Lines: 812 Approved: mirror!rs Submitted by: sdcrdcf!trwrb!ries (Marc Ries) Mod.sources: Volume 8, Issue 52 Archive-name: kurses [ Interested parties may also want to see tput, in Volume 7. --r$ ] # Cut_Here-----Cut_Here-----Cut_Here---------Cut_Here #! /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: # README # att_kurses.mk # bsd_kurses.mk # kshtest # kurses.1 # kurses.c # shtest export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'README'" '(1007 characters)' if test -f 'README' then echo shar: "will not over-write existing file 'README'" else cat << \RiesES_PIECES > 'README' Kurses (aka, curse) was published to the net several years ago. With some changes, it has proved to be a powerful interpreter for manipulating VDT screens, and (especially combined with ksh functions) can be a "production" quality UNIX application development tool. The need arose to be able to drive "kurses" scripts under terminfo, and kurses has been (quickly) ported to SYSVR3. Compile it for pre-terminfo UNIX's via the 'bsd_kurses.mk" makefile or for terminfo UNIX via 'att_kurses.mk'. A man page is included (and note the origional author, Jonathan Bowen of Oxford, England). Your can "test" kurses on your VDT using 'shtest' for the Bourne shell or 'kshtest' for the Korn shell. Not *all* of the options have been thoroughly tested but the most useful ones should be OK. Please send bugs [features 8-{)] and fixes and improvements to me: Marc A. Ries sdcrdcf!---\ ihnp4!------\----- trwrb! --- ries ucbvax!-----/ RiesES_PIECES fi echo shar: "extracting 'att_kurses.mk'" '(547 characters)' if test -f 'att_kurses.mk' then echo shar: "will not over-write existing file 'att_kurses.mk'" else cat << \RiesES_PIECES > 'att_kurses.mk' # # Makefile: kurses # Created: Thursday, November 06, 1986 # By: Marc Ries (TRW Operations and Support Group) # CC = /bin/cc OPTS = -O -s # DEFS = -DBSD DEFS = -DSYSV CFLAGS = $(OPTS) $(DEFS) SRCS = kurses.c OBJS = kurses.o # Define LIB2 if target system is Berkeley Version # LIB2 = -ltermcap LIBS = -lcurses $(LIB2) all: kurses kurses: $(OBJS) $(CC) $(CFLAGS) -o kurses $(OBJS) $(LIBS) clean: rm -f $(OBJS) a.out core shar: shar -v kurses.[1clyh] Makefile > kurses.shr edit: vi $(SRCS) kurses.o: kurses.c RiesES_PIECES fi echo shar: "extracting 'bsd_kurses.mk'" '(545 characters)' if test -f 'bsd_kurses.mk' then echo shar: "will not over-write existing file 'bsd_kurses.mk'" else cat << \RiesES_PIECES > 'bsd_kurses.mk' # # Makefile: kurses # Created: Thursday, November 06, 1986 # By: Marc Ries (TRW Operations and Support Group) # CC = /bin/cc OPTS = -O -s DEFS = -DBSD # DEFS = -DSYSV CFLAGS = $(OPTS) $(DEFS) SRCS = kurses.c OBJS = kurses.o # Define LIB2 if target system is Berkeley Version LIB2 = -ltermcap LIBS = -lcurses $(LIB2) all: kurses kurses: $(OBJS) $(CC) $(CFLAGS) -o kurses $(OBJS) $(LIBS) clean: rm -f $(OBJS) a.out core shar: shar -v kurses.[1clyh] Makefile > kurses.shr edit: vi $(SRCS) kurses.o: kurses.c RiesES_PIECES fi echo shar: "extracting 'kshtest'" '(1779 characters)' if test -f 'kshtest' then echo shar: "will not over-write existing file 'kshtest'" else cat << \RiesES_PIECES > 'kshtest' #!/bin/ksh trap 'kurses -cl;exit' 1 2 3 15 function main_menu { kurses \ -cm 0 1 \ -ce \ '*********************************** M E N U ************************************' \ -cm 0 2 -ce \ -cm 0 3 \ -ce \ ' 1 Display Modules A thru P' \ -cm 0 4 \ -ce \ ' 2 Display Modules Q thru Z' \ -cm 0 5 \ -ce \ ' 3 Display Sub-Modules A thru Z' \ -cm 0 6 \ -ce \ ' 4 Display HELP information' \ -cm 0 7 \ -ce \ ' 5 Exit.' \ -cm 0 8 \ -ce \ -cm 0 9 \ -ce \ ' Enter Option: ' \ -cm 0 10 \ -ce \ -cm 0 22 \ '**************************** Default is Option 1 *****************************' \ -cm 27 9 ; } # function help_menu { kurses -cm 0 11 cat <<+ENDCAT ****************************** HELP INFORMATION ****************************** Option 1 - Help information for Option 1 Option 2 - Help information for Option 2 Option 3 - Help information for Option 3 Option 5 - Exit this program. +ENDCAT } # function clrlwin { kurses \ -cm 0 11 \ '*****************************************' \ '***************************************' \ -cm 0 12 -ce \ -cm 0 13 -ce \ -cm 0 14 -ce \ -cm 0 15 -ce \ -cm 0 16 -ce \ -cm 0 17 -ce \ -cm 0 18 -ce \ -cm 0 19 -ce \ -cm 0 20 -ce \ -cm 0 21 -ce \ -cm 0 22 \ '*************************************************************' ; } # kurses -cl status=loop while test $status = "loop" do main_menu read response case "$response" in 4) help_menu status=loop ;; 5) kurses -cl status=exit exit ;; *) clrlwin kurses \ -cm 13 9 -ce \ 'Enter Option: ' status=loop ;; esac done RiesES_PIECES chmod +x 'kshtest' fi echo shar: "extracting 'kurses.1'" '(2606 characters)' if test -f 'kurses.1' then echo shar: "will not over-write existing file 'kurses.1'" else cat << \RiesES_PIECES > 'kurses.1' ..TH CURSE 1 "14 November 1986" ..UC 4 ..SH NAME kurses \- screen functions ..SH SYNOPSIS ..B kurses [ options ] [ text ] ... ..SH DESCRIPTION This command gives the user a method of updating the screen from a shell. The options are two letter variable names from (the Berkeley version of) ..I curses.h as detailed in Appendix A of ..I "Screen Updating and Cursor Movement Optimization: A Library Package". All the ..I char* type variables are included. In addition, two numeric options (-li and -co) are recognized, so you can adapt your work to any screen shape size. Some commonly used options are: ..TP 6 ..B -cd Clear to end of Display. ..TP 6 ..B -ce Clear to End of line. ..TP 6 ..B -cl CLear screen. This is exactly like the ..I clear command. ..TP 6 ..B -cm Cursor Motion. This takes the next two numerical arguments on the command line to be the ..I x and ..I y coordinates of the desired position of the cursor from the ..I home position ..I (0,0) at the top lefthand corner of the screen. ..TP 6 ..B -ho HOme cursor. This moves the cursor to the top lefthand corner of the screen. This is equivalent to ..I -cm 0 0. ..TP 6 ..B -ll Last Line. This moves the cursor to the bottom lefthand corner of the screen. This is equivalent to ..I -cm 0 23 on a standard 24 line screen. ..TP 6 ..B -se Standout End (may leave space). ..TP 6 ..B -so Stand Out begin (may leave space). This normally produces reverse video but depends on the terminal\'s capabilities. ..TP 6 ..B -ue Underline Ending sequence. ..TP 6 ..B -us Underline Starting sequence. ..TP 6 ..B -xx Prints all allowable options. ..PP The options may be given in upper or lower case. Letters after the first two characters are ignored (e.g. ..B -clear may be used instead of ..B -cl ). Any arguments not starting with a `-' are treated as text and are printed at the current cursor position in the current style (e.g. standout mode). For example, to print a message in standout mode at the center of a standard 80 by 24 character screen and leave the cursor at the bottom of the screen, the following sequence could be used: ..PP ..ti+8n kurses -cl -cm 34 11 -so \'Long Live UNIX\' -se -ll ..SH SEE ALSO ..I "Screen Updating and Cursor Movement Optimization: A Library Package," Ken Arnold, ..br clear(1) or tput(1), curses(3x), termcap(5) or terminfo(5) ..SH AUTHORS Jonathan Bowen, PRG, Oxford, England ..br Marc Ries, TRW, California ..SH BUGS Some options will only work if the corresponding ..I termcap (if compiled for curses) or ..I terminfo (if compiled for terminfo) entry has been set for the terminal in use (e.g. standout mode). Cursor motion may not work on some terminals. RiesES_PIECES fi echo shar: "extracting 'kurses.c'" '(9141 characters)' if test -f 'kurses.c' then echo shar: "will not over-write existing file 'kurses.c'" else cat << \RiesES_PIECES > 'kurses.c' /* * File name: x %I% * By: Marc Ries * Latest change: Thursday, November 13, 1986 * Purpose of this file: * Screen manipulations via a shell * */ #include #ifndef BSD #include #endif BSD void exit(); char *tparm(); outc (c) int c; { (void) putchar(c); } main(argc, argv) int argc; char *argv[]; { char c1, c2, *s; char *i_xy; int x, y, errret; if (--argc <= 0) { (void) fprintf(stderr,"Usage: kurses -xx ...\n"); exit(1); } #ifndef BSD if ((setupterm(0,1,&errret)) == -1) { (void) fprintf(stderr, "Unknown terminfo terminal type!\n"); exit(1); } #else initscr(); #endif BSD while (--argc >= 0) { ++argv; if ((*argv)[0] == '-') { c1 = (*argv)[1]; if ((c1 >= 'A') && (c1 <= 'Z')) c1 = c1+'a'-'A'; c2 = (*argv)[2]; if ((c2 >= 'A') && (c2 <= 'Z')) c2 = c2+'a'-'A'; if ((c1 == 'x') && (c2 == 'x')) { (void) printf("Legal options are:\n"); (void) printf("al,bc,bt,cd,ce,cl,cm,dc,dl,dm,do,ed,ei,ho\n"); (void) printf("ic,im,ip,ll,ma,nd,pc,se,sf,so,sr,ta,te,ti\n"); (void) printf("uc,ue,ul,us,vb,ve,vs\n"); (void) printf("Numeric valued capabilities:\n"); (void) printf("li and co\n"); } else if ((c1 == 'a') && (c2 == 'l')) { #ifndef BSD tputs(key_il, 1, outc); #else tputs(AL, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 'b') && (c2 == 'c')) { (void) printf("%s",cursor_left); } else if ((c1 == 'b') && (c2 == 't')) { tputs(back_tab, 1, outc); } #else else if ((c1 == 'b') && (c2 == 'c')) (void) printf("%s",BC); else if ((c1 == 'b') && (c2 == 't')) (void) printf("%s",BT); #endif BSD else if ((c1 == 'c') && (c2 == 'd')) { #ifndef BSD tputs(clr_eos, 1, outc); #else tputs(CD, 1, outc); #endif BSD } else if ((c1 == 'c') && (c2 == 'e')) { #ifndef BSD putp(clr_eol); #else tputs(CE, 1, outc); #endif BSD } else if ((c1 == 'c') && (c2 == 'l')) { #ifndef BSD putp(clear_screen); #else tputs(CL, 1, outc); #endif BSD } else if ((c1 == 'c') && (c2 == 'm')) { if ((argc -= 2) < 0) { (void) fprintf(stderr,"Usage: kurses -cm X Y\n"); exit(1); } x = (char)atoi(*++argv); y = (char)atoi(*++argv); #ifndef BSD i_xy = (tparm(cursor_address,y,x)); tputs(i_xy,0,outc); #else movecursor(x,y); #endif BSD } #ifndef BSD else if ((c1 == 'c') && (c2 == 'o')) (void) printf("%d", columns); #else else if ((c1 == 'c') && (c2 == 'o')) (void) printf("%d", COLS); #endif BSD else if ((c1 == 'd') && (c2 == 'c')) { #ifndef BSD tputs(parm_dch, 1, outc); #else tputs(DC, 1, outc); #endif BSD } else if ((c1 == 'd') && (c2 == 'l')) { #ifndef BSD tputs(key_dl, 1, outc); #else tputs(DL, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 'd') && (c2 == 'm')) { (void) printf("%s",enter_delete_mode); #else else if ((c1 == 'd') && (c2 == 'm')) (void) printf("%s",DM); else if ((c1 == 'd') && (c2 == 'o')) (void) printf("%s",DO); else if ((c1 == 'e') && (c2 == 'd')) (void) printf("%s",ED); else if ((c1 == 'e') && (c2 == 'i')) (void) printf("%s",EI); else if ((c1 == 'h') && (c2 == 'o')) { if (*HO != '\0') (void) printf("%s",HO); else movecursor(0,0); #endif BSD } #ifndef BSD else if ((c1 == 'd') && (c2 == 'o')) { (void) printf("%s",cursor_down); } else if ((c1 == 'e') && (c2 == 'd')) { (void) printf("%s",exit_delete_mode); } else if ((c1 == 'e') && (c2 == 'i')) { (void) printf("%s",exit_insert_mode); } else if ((c1 == 'h') && (c2 == 'o')) { putp(cursor_home); } #endif BSD else if ((c1 == 'i') && (c2 == 'c')) { #ifndef BSD tputs(insert_character, 1, outc); #else tputs(IC, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 'i') && (c2 == 'm')) { (void) printf("%s",enter_insert_mode); } #else else if ((c1 == 'i') && (c2 == 'm')) (void) printf("%s",IM); #endif BSD else if ((c1 == 'i') && (c2 == 'p')) { #ifndef BSD tputs(insert_padding, 1, outc); #else tputs(IP, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 'l') && (c2 == 'l')) { if (*cursor_to_ll != '\0') { putp(cursor_to_ll); } i_xy = (tparm(cursor_address,lines-1,0)); tputs(i_xy,0,outc); #else else if ((c1 == 'l') && (c2 == 'l')) { if (*LL != '\0') (void) printf("%s",LL); else movecursor(0,LINES-1); #endif BSD } #ifndef BSD else if ((c1 == 'l') && (c2 == 'i')) { (void) printf("%d", lines); } else if ((c1 == 'n') && (c2 == 'd')) { (void) printf("%s",cursor_right); } else if ((c1 == 'p') && (c2 == 'c')) { (void) printf("%s",pad_char); } else if ((c1 == 's') && (c2 == 'e')) { tputs(exit_standout_mode, 1, outc); } #else else if ((c1 == 'l') && (c2 == 'i')) (void) printf("%d", LINES); else if ((c1 == 'm') && (c2 == 'a')) (void) printf("%s",MA); else if ((c1 == 'n') && (c2 == 'd')) (void) printf("%s",ND); else if ((c1 == 'p') && (c2 == 'c')) (void) printf("%s",PC); else if ((c1 == 's') && (c2 == 'e')) (void) printf("%s",SE); #endif BSD else if ((c1 == 's') && (c2 == 'f')) { #ifndef BSD tputs(scroll_forward, 1, outc); #else tputs(SF, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 's') && (c2 == 'o')) { tputs(enter_standout_mode, 1, outc); } else if ((c1 == 's') && (c2 == 'r')) { #else else if ((c1 == 's') && (c2 == 'o')) (void) printf("%s",SO); else if ((c1 == 's') && (c2 == 'r')) { #endif BSD #ifndef BSD *scroll_reverse = tputs(scroll_reverse, 1, outc); (void) printf("%s",scroll_reverse); #else *SR = tputs(SR, 1, outc); (void) printf("%s",SR); #endif BSD } else if ((c1 == 't') && (c2 == 'a')) { #ifndef BSD tputs(tab, 1, outc); #else tputs(TA, 1, outc); #endif BSD } #ifndef BSD else if ((c1 == 't') && (c2 == 'e')) { (void) printf("%s",exit_ca_mode); } else if ((c1 == 't') && (c2 == 'i')) { (void) printf("%s",enter_ca_mode); } else if ((c1 == 'u') && (c2 == 'c')) { tputs(underline_char, 1, outc); } else if ((c1 == 'u') && (c2 == 'e')) { tputs(exit_underline_mode, 1, outc); } else if ((c1 == 'u') && (c2 == 'l')) { (void) printf("%s",transparent_underline); } else if ((c1 == 'u') && (c2 == 's')) { tputs(enter_underline_mode, 1, outc); } else if ((c1 == 'v') && (c2 == 'b')) { tputs(flash_screen, 1, outc); } else if ((c1 == 'v') && (c2 == 'e')) { tputs(cursor_normal, 1, outc); } else if ((c1 == 'v') && (c2 == 's')) { tputs(cursor_visible, 1, outc); } #else else if ((c1 == 't') && (c2 == 'e')) (void) printf("%s",TE); else if ((c1 == 't') && (c2 == 'i')) (void) printf("%s",TI); else if ((c1 == 'u') && (c2 == 'c')) (void) printf("%s",UC); else if ((c1 == 'u') && (c2 == 'e')) (void) printf("%s",UE); else if ((c1 == 'u') && (c2 == 'l')) (void) printf("%s",UL); else if ((c1 == 'u') && (c2 == 's')) (void) printf("%s",US); else if ((c1 == 'v') && (c2 == 'b')) (void) printf("%s",VB); else if ((c1 == 'v') && (c2 == 'e')) (void) printf("%s",VE); else if ((c1 == 'v') && (c2 == 's')) (void) printf("%s",VS); #endif BSD else (void) fprintf(stderr,"kurses: unknown option %s\n",*argv); } else for (s = argv[0]; *s != '\0'; s++) (void) putchar(*s); } #ifndef BSD resetterm(); exit(0); #else endwin(); #endif BSD } #ifdef BSD movecursor(x,y) int x, y; { char n, *s; int i = 0, rev = 0; for (s = CM; *s != '\0'; s++) { while (*s >= '0' && *s <= '9') *s++; /* strip padding nums */ if (*s != '%') (void) putchar(*s); else { switch (i) { case 0: n = (rev?x:y); break; case 1: n = (rev?y:x); break; default: n = '\0'; } switch(*++s) { case 'd': (void) printf("%d",n); i++; break; case '2': (void) printf("%2d",n); i++; break; case '3': (void) printf("%3d",n); i++; break; case '+': n += (int)*++s; case '.': (void) printf("%c",(char)n); i++; break; case '>': if (n > (int)*++s) n+=(int)*++s; else *++s; break; case 'i': x++; y++; break; case 'n': x ^= 0140; y ^= 0140; break; case 'B': x = (16*(x/10))+(x%10); y = (16*(y/10))+(y%10); break; case 'D': x = (x-2*(x%16)); y = (y-2*(y%16)); case 'r': rev++; break; default: *--s; case '%': break; } } } } #endif BSD RiesES_PIECES fi echo shar: "extracting 'shtest'" '(1682 characters)' if test -f 'shtest' then echo shar: "will not over-write existing file 'shtest'" else cat << \RiesES_PIECES > 'shtest' #!/bin/sh trap 'kurses -cl; exit' 1 2 3 15 kurses -cl \ -cm 0 1 \ -ce \ '*********************************** MENU ***************************************' \ -cm 0 2 -ce \ -cm 0 3 \ -ce \ ' 1 Display Menu Subject 1.' \ -cm 0 4 \ -ce \ ' 2 Display Alternate Menu Items.' \ -cm 0 5 \ -ce \ ' 3 Display Page ID.' \ -cm 0 6 \ -ce \ ' 4 Display HELP information.' \ -cm 0 7 \ -ce \ ' 5 Exit.' \ -cm 0 8 \ -ce \ -cm 0 9 \ -ce \ ' Enter Option: ' \ -cm 0 10 \ -ce \ -cm 0 22 \ '**************************** Default is Option 1 *****************************' \ -cm 27 9 # status=loop while test $status = "loop" do read response case "$response" in 4) kurses -cm 0 11 cat <<+ENDCAT ****************************** HELP INFORMATION ****************************** Option 1 - Help information for Option 1 Option 2 - Help information for Option 2 Option 3 - Help information for Option 3 Option 5 - Exit this program. +ENDCAT kurses \ -cm 13 9 -ce \ 'Enter Option: ' status=loop ;; 5) kurses -cl status=exit exit ;; *) kurses \ -cm 0 11 \ '*****************************************' \ '***************************************' \ -cm 0 12 -ce \ -cm 0 13 -ce \ -cm 0 14 -ce \ -cm 0 15 -ce \ -cm 0 16 -ce \ -cm 0 17 -ce \ -cm 0 18 -ce \ -cm 0 19 -ce \ -cm 0 20 -ce \ -cm 0 21 -ce \ -cm 0 22 \ '*************************************************************' \ -cm 13 9 -ce \ 'Enter Option: ' status="loop" esac done RiesES_PIECES chmod +x 'shtest' fi exit 0 # End of shell archive