#!/bin/sh # This is `vwcurses.07' (part 7 of a multipart archive). # Do not concatenate these parts, unpack them in order with `/bin/sh'. # File `vw_curses/termlib/termcap' is being continued... # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 7; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping vw_curses/termlib/termcap' else echo 'x - continuing file vw_curses/termlib/termcap' sed 's/^X//' << 'SHAR_EOF' >> '_sharuue.tmp' && M/5Q%43IH;SU<14@Z7`H).FEM/5Q%4#II<#TV.FQI(S(T.FYD/5Q%0SIP=#IS M;SU<14\Q.G-E/5Q%3S`Z=7`]7$5!.@I$-'PS,#0U?&1M,S`T-7QD871A;65D M:6$@,S`T-6$Z7`H).FES/5Q%55Q%5CID;SU>2CI<"@DZ86TZ;&4]7D@Z8G,Z M8V0],EQ%2CIC93U<14LZ8VP],EQ%33IC;3U<15DE63IT83TX7'0Z=7`]7EPZ:&\],5Y(.G!C M/5Y`.@I).7QI8FU\:6)M,S$P,7PS,3`Q?&DS,3`Q?$E"32`S,3`Q+3$P.EP* M"3ID;SU>2CIC=#U<14@Z5CIC;#TT,%Y8 M.F-M/5Y0)2L@)2L@.F-O(S@P.EP*"3IH;STT,%Y9.FMD/5Y*.FML/5Y(.FMR M/5Y5.FMU/5Y:.FQI(S(T.FUA/5Y:7E!>52`Z;F0]7E4Z=7`]7EHZ"DTY?'9C M-#`T+7-\=F]L:V5R+6-R86EG(#0P-"!W+W-T86YD;W5T(&UO9&4Z7`H).F1O M/5Y*.G-E/5Y/.G-O/5Y..G1C/79C-#`T.@HC($9R;VT@8V)O2#IB3#IU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I<"@DZ86TZ8G,Z8VT]7$4])2L@)2L@.F-L M/3%>6CIC;R,X,#IH;SU>7CIL:2,R-#IM83U>2UY0.FYD/5Y,.G5P/5Y+.EP* M"3IKG-\>F5N-3!\>C4P?'IE<&AY2#IK3#IK=3U>2SIK M9#U>2CIK:#U<,#,V.G5P/5Y+.EP*"3I"4SU>53I#3#U>5CI#4CU>0CI22SU> M3#I52SU>2SI,2SU>2#I$2SU>2CI(33U<,#,V.@IZ=7QG;S$T,'QG6)O87)D(&5X8V5P="!F=6YC=&EO;B!K97ES(&%R92!986QE("AE+F2`X,"!T86(@8V]L=6UN71E2SIC93U>73IC;#U>3#IC;3U>7B5R M)2L@)2L@.F-O(S@P.D50.FAO/5Y9.FQI(S(T.FYD/5Y<.G!T.EP*"3IR8SU< M13@Z2SIK9#U>2CIK;#U>2#IK3#IK:#U>7CIM83T( M:%PP,3)J"VL,;!Y(.EP*"3IK,#U<13`Z:S$]7$4Q.FLR/5Q%,CIK,SU<13,Z M:S0]7$4T.FLU/5Q%-3IK-CU<138Z:S<]7$4W.FLX/5Q%.#IK.3U<13DZ7`H) M.G9S/5Y/7$5;-VE<15MM7$5;/S=H7$5;/S-G7')<14A9,"`@("`@(%Q%2"`@ M("`@("`@7$5(("`@("`@("!<14@@("`@("`@(%Q%2"`@("`@("`@7$5(("`@ M("`@("!<14@@("`@("`@(%Q%2"`@("`@("`@7$5(("`@("`@("!<14A<71E71E2#I<"@DZ86P]7$5;3#ID;#U<15M-.FQE/5Y(.F-M/5Q% M6R5I)60[)61(.FYD/5Q%6T,Z=7`]7$5;03I<"@DZ8V4]7$5;2SIH;SU<15M( M.F1C/5Q%6U`Z:6,]7$5;0#I<"@DZ _sharnew.tmp echo 'x - extracting vw_curses/test/Makefile (text)' sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/test/Makefile' && EXECS= twinkle X CFLAGS= -O2 CPPFLAGS= -DVxWorks -I$(VWDIR)/h -I../h LDFLAGS= -L../lib X CC= gcc68k AS= gas LD= ld68k INSTALL= cp -p X # Root directory for VxWorks VWDIR=/vx X X COMPILE.c= $(CC) $(CFLAGS) $(CPPFLAGS) -c LINK.c= $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) COMPILE.cc= $(C++) $(CFLAGS) $(CPPFLAGS) -c LINK.cc= $(C++) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) LINK= $(LD) $(LDFLAGS) X X.c.o: X $(COMPILE.c) $*.c X X.s.o: X X X all: $(EXECS) X twinkle: twinkle.o random.o X $(LINK) -r -o $@ twinkle.o random.o -lcurses -ltermlib X X clean: force X rm -f twinkle.o random.o $(EXECS) X # dummy target to force execution of a rule force: X SHAR_EOF $shar_touch -am 0627110495 'vw_curses/test/Makefile' && chmod 0644 'vw_curses/test/Makefile' || echo 'restore of vw_curses/test/Makefile failed' shar_count="`wc -c < 'vw_curses/test/Makefile'`" test 617 -eq "$shar_count" || echo "vw_curses/test/Makefile: original size 617, current size $shar_count" rm -f _sharnew.tmp fi # ============= vw_curses/test/README ============== if test -f 'vw_curses/test/README' && test X"$1" != X"-c"; then echo 'x - skipping vw_curses/test/README (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vw_curses/test/README (text)' sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/test/README' && The twinkle program is for testing curses and termlib. X First 'make install' in the curses and termlib directories to build those libraries as appropriate. Then edit the TERMINAL type in twinkle.c and 'make' in this directory. X Use 'ld _sharnew.tmp echo 'x - extracting vw_curses/test/twinkle.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/test/twinkle.c' && #include #include #include X /* X * Curses demo program 'twinkle', from Sun Programmer's Guide vol. 2. X * Before compiling, set TERMINAL definition below as appropriate. X * X * Notes: X * This version does not use signals. X * VxWorks version of curses always uses Def_term (there's no getenv()). X * initscr() seems to require about 41000 bytes from malloc(), so X * at least 45000 should be made available. X * Remember: The OK macro is set by curses.h, so it can't be used for X * VxWorks calls anymore! Use VX_OK instead (defined in ../h/stdio.h). X */ X #define TERMINAL "vt100" X #define NCOLS 80 #define NLINES 24 #define MAXPATTERNS 4 X struct locs { X char y,x; }; X typedef struct locs LOCS; X LOCS Layout [NCOLS * NLINES]; /* current board layout */ X int Pattern, /* current pattern number */ X Numstars; /* number of stars in pattern */ X void makeboard(); bool ison(reg int y, reg int x); void puton(reg char ch); X int twinkle() { X int i; X X srandom(1); X X /* Initialize curses: set default terminal type (always used on X * VxWorks) and call initscr(), checking to be sure there's enough X * malloc() free store. Then set various parameters. X */ X strcpy(Def_term,TERMINAL); X if (initscr()==ERR) { X fprintf(stderr,"twinkle: Error from initscr (not enough free store)\n"); X exit(1); X } X noecho(); X leaveok(stdscr, TRUE); X scrollok(stdscr, FALSE); X X /* main loop */ X for (i=1; i<=10; i++) { X makeboard(); /* make the board setup */ X puton('*'); /* put on '*'s */ X puton(' '); /* cover up with ' 's */ X } X X /* Shut down curses: move the cursor to the lower-left corner X * by direct addressing, since current location is not guaranteed. X * We lie and say we used to be at upper right corner to ensure X * absolute addressing. X */ X mvcur(0,COLS-1, LINES-1,0); X fflush(stdout); /* always flush after mvcur() */ X endwin(); X X exit(0); } X X /* X * Make the current board setup. It picks a random pattern and calls X * ison() to determine if the character is on that pattern or not. X */ void makeboard() { X reg int y,x; X reg LOCS *lp; X X Pattern = random() % MAXPATTERNS; X lp=Layout; X for (y=0; yy=y; X lp++->x=x; X } X Numstars=lp-Layout; } X /* X * Return TRUE if (y,x) is on the current pattern. X */ bool ison(reg int y, reg int x) { X switch (Pattern) { X case 0: /* alternating lines */ X return !(y & 01); X case 1: /* box */ X if (x>=LINES && y>=NCOLS) X return FALSE; X if (y<3 || y>=NLINES-3) X return TRUE; X return(x<3 || x>=NCOLS-3); X case 2: /* holy pattern! */ X return((x+y) & 01); X case 3: /* bar across center */ X return(y>=9 && y<=15); X default: X exit(2); X } X /* NOTREACHED */ } X void puton(reg char ch) { X reg LOCS *lp; X reg int r; X reg LOCS *end; X LOCS temp; X X end=&Layout[Numstars]; X for (lp=Layout; lpy, lp->x, ch); X refresh(); X } } SHAR_EOF $shar_touch -am 0627091195 'vw_curses/test/twinkle.c' && chmod 0644 'vw_curses/test/twinkle.c' || echo 'restore of vw_curses/test/twinkle.c failed' shar_count="`wc -c < 'vw_curses/test/twinkle.c'`" test 3350 -eq "$shar_count" || echo "vw_curses/test/twinkle.c: original size 3350, current size $shar_count" rm -f _sharnew.tmp fi # ============= vw_curses/test/random.c ============== if test -f 'vw_curses/test/random.c' && test X"$1" != X"-c"; then echo 'x - skipping vw_curses/test/random.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vw_curses/test/random.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/test/random.c' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88"; #endif /* LIBC_SCCS and not lint */ X #include X /* X * random.c: X * An improved random number generation package. In addition to the standard X * rand()/srand() like interface, this package also has a special state info X * interface. The initstate() routine is called with a seed, an array of X * bytes, and a count of how many bytes are being passed in; this array is then X * initialized to contain information for random number generation with that X * much state information. Good sizes for the amount of state information are X * 32, 64, 128, and 256 bytes. The state can be switched by calling the X * setstate() routine with the same array as was initiallized with initstate(). X * By default, the package runs with 128 bytes of state information and X * generates far better random numbers than a linear congruential generator. X * If the amount of state information is less than 32 bytes, a simple linear X * congruential R.N.G. is used. X * Internally, the state information is treated as an array of longs; the X * zeroeth element of the array is the type of R.N.G. being used (small X * integer); the remainder of the array is the state information for the X * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of X * state information, which will allow a degree seven polynomial. (Note: the X * zeroeth word of state information also has some other information stored X * in it -- see setstate() for details). X * The random number generation technique is a linear feedback shift register X * approach, employing trinomials (since there are fewer terms to sum up that X * way). In this approach, the least significant bit of all the numbers in X * the state table will act as a linear feedback shift register, and will have X * period 2^deg - 1 (where deg is the degree of the polynomial being used, X * assuming that the polynomial is irreducible and primitive). The higher X * order bits will have longer periods, since their values are also influenced X * by pseudo-random carries out of the lower bits. The total period of the X * generator is approximately deg*(2**deg - 1); thus doubling the amount of X * state information has a vast influence on the period of the generator. X * Note: the deg*(2**deg - 1) is an approximation only good for large deg, X * when the period of the shift register is the dominant factor. With deg X * equal to seven, the period is actually much longer than the 7*(2**7 - 1) X * predicted by this formula. X */ X X X /* X * For each of the currently supported random number generators, we have a X * break value on the amount of state information (you need at least this X * many bytes of state info to support this random number generator), a degree X * for the polynomial (actually a trinomial) that the R.N.G. is based on, and X * the separation between the two lower order coefficients of the trinomial. X */ X #define TYPE_0 0 /* linear congruential */ #define BREAK_0 8 #define DEG_0 0 #define SEP_0 0 X #define TYPE_1 1 /* x**7 + x**3 + 1 */ #define BREAK_1 32 #define DEG_1 7 #define SEP_1 3 X #define TYPE_2 2 /* x**15 + x + 1 */ #define BREAK_2 64 #define DEG_2 15 #define SEP_2 1 X #define TYPE_3 3 /* x**31 + x**3 + 1 */ #define BREAK_3 128 #define DEG_3 31 #define SEP_3 3 X #define TYPE_4 4 /* x**63 + x + 1 */ #define BREAK_4 256 #define DEG_4 63 #define SEP_4 1 X X /* X * Array versions of the above information to make code run faster -- relies X * on fact that TYPE_i == i. X */ X #define MAX_TYPES 5 /* max number of types above */ X static int degrees[ MAX_TYPES ] = { DEG_0, DEG_1, DEG_2, X DEG_3, DEG_4 }; X static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2, X SEP_3, SEP_4 }; X X X /* X * Initially, everything is set up as if from : X * initstate( 1, &randtbl, 128 ); X * Note that this initialization takes advantage of the fact that srandom() X * advances the front and rear pointers 10*rand_deg times, and hence the X * rear pointer which starts at 0 will also end up at zero; thus the zeroeth X * element of the state information, which contains info about the current X * position of the rear pointer is just X * MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3. X */ X static long randtbl[ DEG_3 + 1 ] = { TYPE_3, X 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, X 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, X 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, X 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, X 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, X 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, X 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, X 0xf5ad9d0e, 0x8999220b, 0x27fb47b9 }; X /* X * fptr and rptr are two pointers into the state info, a front and a rear X * pointer. These two pointers are always rand_sep places aparts, as they cycle X * cyclically through the state information. (Yes, this does mean we could get X * away with just one pointer, but the code for random() is more efficient this X * way). The pointers are left positioned as they would be from the call X * initstate( 1, randtbl, 128 ) X * (The position of the rear pointer, rptr, is really 0 (as explained above X * in the initialization of randtbl) because the state table pointer is set X * to point to randtbl[1] (as explained below). X */ X static long *fptr = &randtbl[ SEP_3 + 1 ]; static long *rptr = &randtbl[ 1 ]; X X X /* X * The following things are the pointer to the state information table, X * the type of the current generator, the degree of the current polynomial X * being used, and the separation between the two pointers. X * Note that for efficiency of random(), we remember the first location of X * the state information, not the zeroeth. Hence it is valid to access X * state[-1], which is used to store the type of the R.N.G. X * Also, we remember the last location, since this is more efficient than X * indexing every time to find the address of the last element to see if X * the front and rear pointers have wrapped. X */ X static long *state = &randtbl[ 1 ]; X static int rand_type = TYPE_3; static int rand_deg = DEG_3; static int rand_sep = SEP_3; X static long *end_ptr = &randtbl[ DEG_3 + 1 ]; X X X /* X * srandom: X * Initialize the random number generator based on the given seed. If the X * type is the trivial no-state-information type, just remember the seed. X * Otherwise, initializes state[] based on the given "seed" via a linear X * congruential generator. Then, the pointers are set to known locations X * that are exactly rand_sep places apart. Lastly, it cycles the state X * information a given number of times to get rid of any initial dependencies X * introduced by the L.C.R.N.G. X * Note that the initialization of randtbl[] for default usage relies on X * values produced by this routine. X */ X void srandom( x ) X X unsigned x; { X register int i, j; X long random(); X X if( rand_type == TYPE_0 ) { X state[ 0 ] = x; X } X else { X j = 1; X state[ 0 ] = x; X for( i = 1; i < rand_deg; i++ ) { X state[i] = 1103515245*state[i - 1] + 12345; X } X fptr = &state[ rand_sep ]; X rptr = &state[ 0 ]; X for( i = 0; i < 10*rand_deg; i++ ) random(); X } } X X X /* X * initstate: X * Initialize the state information in the given array of n bytes for X * future random number generation. Based on the number of bytes we X * are given, and the break values for the different R.N.G.'s, we choose X * the best (largest) one we can and set things up for it. srandom() is X * then called to initialize the state information. X * Note that on return from srandom(), we set state[-1] to be the type X * multiplexed with the current value of the rear pointer; this is so X * successive calls to initstate() won't lose this information and will X * be able to restart with setstate(). X * Note: the first thing we do is save the current state, if any, just like X * setstate() so that it doesn't matter when initstate is called. X * Returns a pointer to the old state. X */ X char * initstate( seed, arg_state, n ) X X unsigned seed; /* seed for R. N. G. */ X char *arg_state; /* pointer to state array */ X int n; /* # bytes of state info */ { X register char *ostate = (char *)( &state[ -1 ] ); X X if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; X else state[ -1 ] = MAX_TYPES*(rptr - state) + rand_type; X if( n < BREAK_1 ) { X if( n < BREAK_0 ) { X fprintf( stderr, "initstate: not enough state (%d bytes) with which to do jack; ignored.\n", n ); X return(NULL); X } X rand_type = TYPE_0; X rand_deg = DEG_0; X rand_sep = SEP_0; X } X else { X if( n < BREAK_2 ) { X rand_type = TYPE_1; X rand_deg = DEG_1; X rand_sep = SEP_1; X } X else { X if( n < BREAK_3 ) { X rand_type = TYPE_2; X rand_deg = DEG_2; X rand_sep = SEP_2; X } X else { X if( n < BREAK_4 ) { X rand_type = TYPE_3; X rand_deg = DEG_3; X rand_sep = SEP_3; X } X else { X rand_type = TYPE_4; X rand_deg = DEG_4; X rand_sep = SEP_4; X } X } X } X } X state = &( ( (long *)arg_state )[1] ); /* first location */ X end_ptr = &state[ rand_deg ]; /* must set end_ptr before srandom */ X srandom( seed ); X if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; X else state[ -1 ] = MAX_TYPES*(rptr - state) + rand_type; X return( ostate ); } X X X /* X * setstate: X * Restore the state from the given state array. X * Note: it is important that we also remember the locations of the pointers X * in the current state information, and restore the locations of the pointers X * from the old state information. This is done by multiplexing the pointer X * location into the zeroeth word of the state information. X * Note that due to the order in which things are done, it is OK to call X * setstate() with the same state as the current state. X * Returns a pointer to the old state information. X */ X char * setstate( arg_state ) X X char *arg_state; { X register long *new_state = (long *)arg_state; X register int type = new_state[0]%MAX_TYPES; X register int rear = new_state[0]/MAX_TYPES; X char *ostate = (char *)( &state[ -1 ] ); X X if( rand_type == TYPE_0 ) state[ -1 ] = rand_type; X else state[ -1 ] = MAX_TYPES*(rptr - state) + rand_type; X switch( type ) { X case TYPE_0: X case TYPE_1: X case TYPE_2: X case TYPE_3: X case TYPE_4: X rand_type = type; X rand_deg = degrees[ type ]; X rand_sep = seps[ type ]; X break; X X default: X fprintf( stderr, "setstate: state info has been munged; not changed.\n" ); X } X state = &new_state[ 1 ]; X if( rand_type != TYPE_0 ) { X rptr = &state[ rear ]; X fptr = &state[ (rear + rand_sep)%rand_deg ]; X } X end_ptr = &state[ rand_deg ]; /* set end_ptr too */ X return( ostate ); } X X X /* X * random: X * If we are using the trivial TYPE_0 R.N.G., just do the old linear X * congruential bit. Otherwise, we do our fancy trinomial stuff, which is the X * same in all ther other cases due to all the global variables that have been X * set up. The basic operation is to add the number at the rear pointer into X * the one at the front pointer. Then both pointers are advanced to the next X * location cyclically in the table. The value returned is the sum generated, X * reduced to 31 bits by throwing away the "least random" low bit. X * Note: the code takes advantage of the fact that both the front and X * rear pointers can't wrap on the same call by not testing the rear X * pointer if the front one has wrapped. X * Returns a 31-bit random number. X */ X long random() { X long i; X X if( rand_type == TYPE_0 ) { X i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff; X } X else { X *fptr += *rptr; X i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */ X if( ++fptr >= end_ptr ) { X fptr = state; X ++rptr; X } X else { X if( ++rptr >= end_ptr ) rptr = state; X } X } X return( i ); } X SHAR_EOF $shar_touch -am 0627091295 'vw_curses/test/random.c' && chmod 0644 'vw_curses/test/random.c' || echo 'restore of vw_curses/test/random.c failed' shar_count="`wc -c < 'vw_curses/test/random.c'`" test 12804 -eq "$shar_count" || echo "vw_curses/test/random.c: original size 12804, current size $shar_count" rm -f _sharnew.tmp fi # ============= vw_curses/README ============== if test -f 'vw_curses/README' && test X"$1" != X"-c"; then echo 'x - skipping vw_curses/README (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vw_curses/README (text)' sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/README' && This is curses and termlib for VxWorks 4.0.2. (OS dependence is minimal, so it should work, or just about, with 5.0 too). X Curses allows you to manage text windows nicely, including scrolling of arbitrary rectangular text regions, overlapping windows, etc. Termlib is used by curses to allow it to work with almost any cursor-addressible terminal or terminal emulator. The version of curses that I started with (4.3 Tahoe) was full of nasty bugs, most of which should be fixed by now, but you may still be able to find some. X For the VxWorks version, I added semaphore locking to curses so that multiple processes can use it. The termlib routines have no locking, but you should be OK because they are called by curses, which is locked. Both curses and termlib use static variables (e.g. 'Def_term' variable and 'genbuf' buffer for the current termcap entry in curses, 'tbuf' pointer in termlib), which you have to be careful about. This should not cause a problem unless you want to have two totally independent displays or other fanciness. The bottom line is: this works very well for me. However, it is useful to understand the historical kludge perpetrated by termlib to access the terminal capability currently in use by the application (e.g. for operations such as tgetstr()): The termcap entry is initialized by curses during the initscr() call, which uses tgetent() to get the termcap from termlib. The entry is held by curses in a static character buffer ('genbuf'). The termlib routines keep their own static character pointer, 'tbuf', which points at 'genbuf'. If you call tgetstr(), then termlib uses 'tbuf' to look through the termcap entry being used by curses. As you can well imagine, this means there can be only one "current" termcap. To stay out of trouble, call initscr() only once and from only one task, and avoid calling the tgetent() routine yourself. X X Usual disclaimer: This software is provided ``as is'' and without any express or implied warranties. My employer (ISTS) is in no way responsible for its contents. Any bugs you encounter you will have to fix yourself. X Caution: The curses.h include file defines the preprocessor macros OK and ERR. Unfortunately, VxWorks also defines OK, and does so differently. My solution has been to use VX_OK for VxWorks instead (see h/stdio.h), and let curses have OK. You may want to do things the other way around, so I also define CURSES_OK. Your code must then fix the OK macro after #including curses.h. X Good luck. If you have any questions, improvements, bug fixes, etc. send them to georg@sgl.ists.ca. X Georg Feil Space Geodynamics Laboratory ISTS, 2700 Steeles Ave West Concord, Ontario (416) 665-5458 -------------------------------------------------------------------- X To install, X 1) Cd to the termlib directory, and edit the Makefile there. Set VWDIR to X your local VxWorks root directory. Set other things such as the tools to X use (default is the GNU tools gcc, gld etc.) X 2) If your VxWorks target system has a file system, copy the termcap file X over to it, and set the appropriate pathname in termcap.c (DEF_FILE). X If there is no file system, add any necessary capability entries to X the termcaps[] array in termcap.c, combining multiple lines into one X as has been done with the existing entries. You may need to look in your X own system's termcap file (usually /etc/termcap) to find entries. X 3) Type 'make install' to build the termlib library, libtermlib.a. It will X be placed in the lib directory. X 4) Cd to the curses directory, and edit the Makefile as in step (1). X 5) Type 'make install' to build the curses library, libcurses.a. It will X be placed in the lib directory. X 6) Cd to the test directory and edit the Makefile. Set the TERMINAL type X as desired by editing twinkle.c, then type 'make' to build the X test program twinkle. X 7) Use 'ld _sharnew.tmp echo 'x - extracting vw_curses/README.2nd (binary)' sed 's/^X//' << 'SHAR_EOF' > _sharuue.tmp && begin 600 vw_curses/README.2nd SHAR_EOF : || echo 'restore of vw_curses/README.2nd failed' fi echo 'End of archive part 7' echo 'File vw_curses/README.2nd is continued in part 8' echo 8 > _sharseq.tmp exit 0