Software testing Excercises, due within 12 hrs maximum

profileSinghNeedsHe
DatapackagefromDecember2nd..zip

corp4.zip

Corp4.c

static struct _mcinsts { /* MCC_INST */ char *szFile; /* MCC_INST */ long iModuleBase; /* MCC_INST */ } _mcinsti = {(char*) "U:\\McCabe\\Windows_Exercises\\McCabe\\Exercises\\c\\corp4\\Corp4.c", -1}; /* MCC_INST */ int _mcterm5corp4(); /* MCC_INST */ int _mcdisable5corp4(); /* MCC_INST */ int _mcenable5corp4(); /* MCC_INST */ int _mcrepcacorp45(); /* MCC_INST */ int _mcrepcocorp45(); /* MCC_INST */ int _mcnewrec5corp4(); /* MCC_INST */ void marketing(); void development(); void support(); void maintenance(); void revenue(); int query(); int main() { long _mcvec[1]; int _mcdummy = _mcrepcacorp45(&_mcinsti,0,_mcvec,0); _mcdummy = _mcdummy; marketing(); return(0); } void marketing() { long _mcvec[3]; int _mcdummy = _mcrepcacorp45(&_mcinsti,1,_mcvec,0); int purchase; _mcdummy = _mcdummy; purchase = query("Is this a purchase"); if ( (_mcrepcocorp45(&_mcinsti,1,_mcvec,1,2, ( purchase == 1 ) != 0)) ) development(); else support(); } void development() { long _mcvec[9]; int _mcdummy = _mcrepcacorp45(&_mcinsti,2,_mcvec,0); int new_features; int research_results; int standard_product; _mcdummy = _mcdummy; new_features = query("Do you need new features?"); if ( (_mcrepcocorp45(&_mcinsti,2,_mcvec,1,2, ( new_features == 1 ) != 0)) ) { research_results = query("Do you have research results?"); if ( (_mcrepcocorp45(&_mcinsti,2,_mcvec,3,4, ( research_results == 1 ) != 0)) ) { } else { research_results = query("Was initial research successful?"); while ( (_mcrepcocorp45(&_mcinsti,2,_mcvec,5,6, ( research_results == 0 ) != 0)) ) { research_results = query("Was further research successful?"); } } } else { standard_product = query("Is this a standard product?"); if ( (_mcrepcocorp45(&_mcinsti,2,_mcvec,7,8, ( standard_product == 1 ) != 0)) ) revenue(); else maintenance(); } } void support() { long _mcvec[3]; int _mcdummy = _mcrepcacorp45(&_mcinsti,3,_mcvec,0); int bug; _mcdummy = _mcdummy; bug = query("Is there a bug?"); if ( (_mcrepcocorp45(&_mcinsti,3,_mcvec,1,2, ( bug == 1 ) != 0)) ) maintenance(); } void maintenance() { long _mcvec[1]; int _mcdummy = _mcrepcacorp45(&_mcinsti,4,_mcvec,0); _mcdummy = _mcdummy; } void revenue() { long _mcvec[1]; int _mcdummy = _mcrepcacorp45(&_mcinsti,5,_mcvec,0); _mcdummy = _mcdummy; } int query(question) char *question; { long _mcvec[1]; int _mcdummy = _mcrepcacorp45(&_mcinsti,6,_mcvec,0); char response[10], *a; _mcdummy = _mcdummy; (void)printf("\n%s\n", question); a = gets(response); return(*a == 'Y' | *a == 'y'); }

corp4.exe

corp4v2.zip

Corp4v2.c

void marketing(); void development(); void support(); void maintenance(); void revenue(); int query(); int TRUE=1; int FALSE=0; int main() { marketing(); return(0); } void marketing() { int purchase; purchase = query("Is this a purchase"); if (purchase == 1) development(); else support(); } void development() { int new_features; int research_results; int standard_product; new_features = query("Do you need new features?"); if (new_features == 1) { research_results = query("Do you have research results?"); if ( research_results == 1 ) { } else { research_results = query("Was initial research successful?"); while ( research_results == 0 ) { research_results = query("Was further research successful?"); } } } else { standard_product = query("Is this a standard product?"); if ( standard_product == 1 ) revenue(); else maintenance(); } } void support() { int bug; bug = query("Is there a bug?"); if ( bug == 1 ) maintenance(); } void maintenance() { } void revenue() { if (TRUE==TRUE) { } } int query(question) char *question; { char response[10], *a; (void)printf("\n%s\n", question); a = gets(response); return(*a == 'Y' | *a == 'y'); }

corp4v2.exe

LessCode.zip

ch.i

#line 1 "ch.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 3 "ch.c" /* * Low level character input from the input file. * We use these special purpose routines which optimize moving * both forward and backward from the current read pointer. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 10 "ch.c" int file = -1; /* File descriptor of the input file */ /* * Pool of buffers holding the most recently used blocks of the input file. */ static struct buf { struct buf *next, *prev; long block; char data[1024]; }; static struct buf *bufs = (0); int nbufs; /* * The buffer pool is kept as a doubly-linked circular list, * in order from most- to least-recently used. * The circular list is anchored by buf_anchor. */ static struct { struct buf *next, *prev; } buf_anchor; /* * If we fail to allocate enough memory for buffers, we try to limp * along with a minimum number of buffers. */ extern int clean_data; extern int ispipe; /* * Current position in file. * Stored as a block number and an offset into the block. */ static long ch_block; static int ch_offset; /* * Length of file, needed if input is a pipe. */ static POSITION ch_fsize; /* * Largest block number read if input is standard input (a pipe). */ static long last_piped_block; /* * Get the character pointed to by the read pointer. * ch_get() is a macro which is more efficient to call * than fch_get (the function), in the usual case * that the block desired is at the head of the chain. */ static int fch_get() { register struct buf *bp; register int n; register int end; POSITION pos; /* * Look for a buffer holding the desired block. */ for (bp = buf_anchor.next; bp != ((struct buf *)&buf_anchor); bp = bp->next) if (bp->block == ch_block) goto found; /* * Block is not in a buffer. * Take the least recently used buffer * and read the desired block into it. */ bp = buf_anchor.prev; bp->block = ch_block; pos = ch_block * 1024; if (ispipe) { /* * The block requested should be one more than * the last block read. */ if (ch_block != ++last_piped_block) { /* This "should not happen". */ char message[80]; sprintf(message, "Pipe error: last %ld, want %ld\n", last_piped_block-1, ch_block); error(message); /* Call error routine */ quit(); } } else lseek(file, pos, 0); /* * Read the block. This may take several reads if the input * is coming from standard input, due to the nature of pipes. */ end = 0; while ((n = read(file, &bp->data[end], 1024-end)) > 0) if ((end += n) >= 1024) break; if (n < 0) { error("read error"); quit(); } /* * Set an EOF marker in the buffered data itself. * Then ensure the data is "clean": there are no * extra EOF chars in the data and that the "meta" * bit (the 0200 bit) is reset in each char. */ if (end < 1024) { ch_fsize = pos + end; bp->data[end] = (0); } if (!clean_data) while (--end >= 0) { bp->data[end] &= 0177; if (bp->data[end] == (0)) bp->data[end] = '@'; } found: /* if (buf_head != bp) {this is guaranteed by the ch_get macro} */ { /* * Move the buffer to the head of the buffer chain. * This orders the buffer chain, most- to least-recently used. */ bp->next->prev = bp->prev; bp->prev->next = bp->next; bp->next = buf_anchor.next; bp->prev = ((struct buf *)&buf_anchor); buf_anchor.next->prev = bp; buf_anchor.next = bp; } return (bp->data[ch_offset]); } /* * Determine if a specific block is currently in one of the buffers. */ static int buffered(block) long block; { register struct buf *bp; for (bp = buf_anchor.next; bp != ((struct buf *)&buf_anchor); bp = bp->next) if (bp->block == block) return (1); return (0); } /* * Seek to a specified position in the file. * Return 0 if successful, non-zero if can't seek there. */ int ch_seek(pos) register POSITION pos; { long new_block; new_block = pos / 1024; if (!ispipe || new_block == last_piped_block + 1 || buffered(new_block) ) { /* * Set read pointer. */ ch_block = new_block; ch_offset = pos % 1024; return (0); } return (1); } /* * Seek to the end of the file. */ int ch_end_seek() { if (ispipe) { /* * Do it the slow way: read till end of data. */ while (ch_forw_get() != (0)) ; } else { (void) ch_seek((POSITION)(lseek(file, (long)0, 2))); } return (0); } /* * Return the length of the file, if known. */ POSITION ch_length() { if (ispipe) return (ch_fsize); return ((POSITION)(lseek(file, (long)0, 2))); } /* * Return the current position in the file. */ POSITION ch_tell() { return (ch_block * 1024 + ch_offset); } /* * Get the current char and post-increment the read pointer. */ int ch_forw_get() { register int c; c = ((buf_anchor.next->block == ch_block) ? buf_anchor.next->data[ch_offset] : fch_get()); if (c != (0) && ++ch_offset >= 1024) { ch_offset = 0; ch_block ++; } return (c); } /* * Pre-decrement the read pointer and get the new current char. */ int ch_back_get() { register int c; if (--ch_offset < 0) { if (ch_block <= 0 || (ispipe && !buffered(ch_block-1))) { ch_offset = 0; return ((0)); } ch_offset = 1024 - 1; ch_block--; } c = ((buf_anchor.next->block == ch_block) ? buf_anchor.next->data[ch_offset] : fch_get()); return (c); } /* * Initialize the buffer pool to all empty. * Caller suggests that we use want_nbufs buffers. */ void ch_init(want_nbufs) int want_nbufs; { register struct buf *bp; char *calloc(); if (nbufs < want_nbufs) { /* * We don't have enough buffers. * Free what we have (if any) and allocate some new ones. */ if (bufs != (0)) free((char *)bufs); bufs = (struct buf *) calloc(want_nbufs, sizeof(struct buf)); nbufs = want_nbufs; if (bufs == (0)) { /* * Couldn't get that many. * Try for a small default number of buffers. */ char message[80]; sprintf(message, "Cannot allocate %d buffers. Using %d buffers.", nbufs, 2); error(message); bufs = (struct buf *) calloc(2, sizeof(struct buf)); nbufs = 2; if (bufs == (0)) { /* * Couldn't even get the smaller number of bufs . * Something is wrong here, don't continue. */ sprintf(message, "Cannot even allocate %d buffers! Quitting.\n" , 2); error(message); quit(); /*NOTREACHED*/ } } } /* * Initialize the buffers to empty. * Set up the circular list. */ for (bp = &bufs[0]; bp < &bufs[nbufs]; bp++) { bp->next = bp + 1; bp->prev = bp - 1; bp->block = (long)(-1); } bufs[0].prev = bufs[nbufs-1].next = ((struct buf *)&buf_anchor); buf_anchor.next = &bufs[0]; buf_anchor.prev = &bufs[nbufs-1]; last_piped_block = -1; ch_fsize = ((POSITION)(-1)); (void) ch_seek((POSITION)0); }

command.i

#line 1 "command.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "command.c" /* * User-level command processor. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 7 "command.c" #line 1 "position.h" /* * Include file for interfacing to position.c modules. */ #line 8 "command.c" #line 1 ".\\setjmp.h" #line 9 "command.c" extern int erase_char, kill_char; extern int pr_type; extern int sigs; extern int ispipe; extern int quit_at_eof; extern int hit_eof; extern int sc_width, sc_height; extern char *first_cmd; extern char version[]; extern char current_file[]; extern char *editor; static char cmdbuf[90]; /* Buffer for holding a multi-char command */ static char *cp; /* Pointer into cmdbuf */ static int cmd_col; /* Current column of the multi-char command */ static char mcc; /* The multi-char command letter (e.g. '/') */ static char last_mcc; /* The previous mcc */ /* * Reset command buffer (to empty). */ cmd_reset() { cp = cmdbuf; } /* * Backspace in command buffer. */ static int cmd_erase() { if (cp == cmdbuf) /* * Backspace past beginning of the string: * this usually means abort the command. */ return (1); if (control_char(*--cp)) { /* * Erase an extra character, for the carat. */ backspace(); cmd_col--; } backspace(); cmd_col--; return (0); } /* * Set up the display to start a new multi-character command. */ start_mcc() { lower_left(); clear_eol(); putc(mcc); cmd_col = 1; } /* * Process a single character of a multi-character command, such as * a number, or the pattern of a search command. */ static int cmd_char(c) int c; { if (simon) { } if (c == erase_char) { if (cmd_erase()) return (1); } else if (c == kill_char) { /* {{ Could do this faster, but who cares? }} */ while (cmd_erase() == 0) ; } else { /* * Append the character to the string, * if there is room in the buffer and on the screen. */ if (cp < &cmdbuf[sizeof(cmdbuf)-1] && cmd_col < sc_width-3) { *cp++ = c; if (control_char(c)) { putc('^'); cmd_col++; c = carat_char(c); } putc(c); cmd_col++; } else bell(); } return (0); } /* * Return the number currently in the command buffer. */ static int cmd_int() { *cp = '\0'; cp = cmdbuf; return (atoi(cmdbuf)); } /* * Move the cursor to lower left before executing a command. * This looks nicer if the command takes a long time before * updating the screen. */ static void cmd_exec() { lower_left(); flush(); } /* * Display the appropriate prompt. */ static void prompt() { register char *p; if (simon==0) { } if (simon==0) printf("heeloo"); if (first_cmd != (0) && *first_cmd != '\0') /* * No prompt necessary if commands are from first_cmd * rather than from the user. */ return; /* * Select the proper prompt and display it. */ p = pr_string(); if (p == (0)) putc(':'); else { so_enter(); puts(p); so_exit(); } } /* * Get command character. * The character normally comes from the keyboard, * but may come from the "first_cmd" string. */ static int getcc() { if (first_cmd == (0)) return (getc()); if (*first_cmd == '\0') { /* * Reached end of first_cmd input. */ first_cmd = (0); if (cp > cmdbuf && position(0) == ((POSITION)(-1))) { /* * Command is incomplete, so try to complete it. * There are only two cases: * 1. We have "/string" but no newline. Add the \n. * 2. We have a number but no command. Treat as #g. * (This is all pretty hokey.) */ if (mcc != ':') return ('\n'); else return ('g'); } return (getc()); } return (*first_cmd++); } /* * Main command processor. * Accept and execute commands until a quit command, then return. */ void commands() { register int c; register int n; register int scroll = 10; mcc = last_mcc = 0; setjmp(main_loop); for (;;) { /* * Display prompt and accept a character. */ psignals(); /* See if any signals need processing */ if (quit_at_eof && hit_eof > 1) /* * After hitting end-of-file for the second time, * automatically advance to the next file. * If there are no more files, quit. */ next_file(1); cmd_reset(); lower_left(); clear_eol(); prompt(); c = getcc(); again: if (sigs) continue; if (mcc) { /* * We are in a multi-character command. * All chars until newline go into the command buffer. * (Note that mcc == ':' is a special case that * means a number is being entered.) */ if (mcc != ':' && (c == '\n' || c == '\r')) { /* * Execute the command. */ *cp = '\0'; cmd_exec(); if (mcc == 'E') { char *p; /* * Ignore leading spaces * in the filename. */ for (p = cmdbuf; *p == ' '; p++) ; edit(p); } else if (mcc == '!') { lsystem(cmdbuf); error("!done"); first_cmd = "r"; /* Repaint */ } else search(mcc, cmdbuf, n); mcc = 0; } else { if (mcc == ':' && (c < '0' || c > '9') && c != erase_char && c != kill_char) { /* * This is not part of the number * we were entering. Process * it as a regular character. */ mcc = 0; goto again; } /* * Append the char to the command buffer. */ if (cmd_char(c)) { /* Abort the multi-char command. */ mcc = 0; continue; } c = getcc(); goto again; } } else switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* * First digit of a number. */ mcc = ':'; start_mcc(); goto again; case 'f': case ' ': case (('F')&037): /* * Forward one screen. */ n = cmd_int(); if (n <= 0) n = sc_height - 1; forward(n, 1); break; case 'b': case (('B')&037): /* * Backward one screen. */ n = cmd_int(); if (n <= 0) n = sc_height - 1; backward(n, 1); break; case 'e': case 'j': case '\r': case '\n': case (('E')&037): /* * Forward N (default 1) line. */ n = cmd_int(); if (n <= 0) n = 1; forward(n, 0); break; case 'y': case 'k': case (('K')&037): case (('Y')&037): /* * Backward N (default 1) line. */ n = cmd_int(); if (n <= 0) n = 1; backward(n, 0); break; case 'd': case (('D')&037): /* * Forward N lines * (default same as last 'd' or 'u' command). */ n = cmd_int(); if (n > 0) scroll = n; forward(scroll, 0); break; case 'u': case (('U')&037): /* * Forward N lines * (default same as last 'd' or 'u' command). */ n = cmd_int(); if (n > 0) scroll = n; backward(scroll, 0); break; case 'R': /* * Flush buffers, then repaint screen. */ ch_init(0); /* Fall thru */ case 'r': case (('R')&037): case (('L')&037): /* * Repaint screen. */ repaint(); break; case 'g': /* * Go to line N, default beginning of file. */ n = cmd_int(); if (n <= 0) n = 1; cmd_exec(); jump_back(n); break; case 'p': case '%': /* * Go to a specified percentage into the file. */ n = cmd_int(); if (n < 0) n = 0; if (n > 100) n = 100; cmd_exec(); jump_percent(n); break; case 'G': /* * Go to line N, default end of file. */ n = cmd_int(); cmd_exec(); if (n <= 0) jump_forw(); else jump_back(n); break; case '=': case (('G')&037): /* * Print file name, etc. */ error(eq_message()); break; case 'V': /* * Print version number, without the "@(#)". */ error(version+4); break; case 'q': /* * Exit. */ return; case '/': case '?': /* * Search for a pattern. * Accept chars of the pattern until \n. */ n = cmd_int(); if (n <= 0) n = 1; mcc = last_mcc = c; start_mcc(); c = getcc(); goto again; case 'n': /* * Repeat previous search. */ n = cmd_int(); if (n <= 0) n = 1; mcc = last_mcc; start_mcc(); cmd_exec(); search(mcc, (char *)(0), n); mcc = 0; break; case 'h': /* * Help. */ help(); repaint(); break; case 'E': /* * Edit a new file. Get the filename. */ cmd_reset(); mcc = 'E'; start_mcc(); puts("dit: "); /* This looks nicer */ cmd_col += 5; c = getcc(); goto again; case '!': /* * Shell escape. */ cmd_reset(); mcc = '!'; start_mcc(); c = getcc(); goto again; case 'v': if (ispipe) { error("Cannot edit standard input"); break; } sprintf(cmdbuf, "%s %s", editor, current_file); lsystem(cmdbuf); first_cmd = "R"; break; case 'N': /* * Examine next file. */ n = cmd_int(); if (n <= 0) n = 1; next_file(n); break; case 'P': /* * Examine previous file. */ n = cmd_int(); if (n <= 0) n = 1; prev_file(n); break; case '-': /* * Toggle a flag setting. */ mcc = '-'; start_mcc(); c = getcc(); mcc = 0; if (c == erase_char || c == kill_char) break; toggle_option(c); break; case 'm': /* * Set a mark. */ lower_left(); clear_eol(); puts("mark: "); c = getcc(); if (c == erase_char || c == kill_char) break; setmark(c); break; case '\'': /* * Go to a mark. */ lower_left(); clear_eol(); puts("goto mark: "); c = getcc(); if (c == erase_char || c == kill_char) break; gomark(c); break; default: bell(); break; } } }

help.i

#line 1 "help.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "help.c" #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 3 "help.c" /* * Display some help. * Help is in two pages. */ static void help0() { puts("f, SPACE Forward one screen.\n"); puts("b Backward one screen.\n"); puts("e, j, CR * Forward N lines, default 1.\n"); puts("y, k * Backward N lines, default 1.\n"); puts("d * Forward N lines, default 10 or last N to d or u command.\n"); puts("u * Backward N lines, default 10 or last N to d or u command.\n"); puts("r Repaint screen.\n"); puts("g * Go to line N, default 1.\n"); puts("G * Like g, but default is last line in file.\n"); puts("= Print current file name\n"); puts("/pattern * Search forward for N-th occurence of pattern.\n"); puts("?pattern * Search backward for N-th occurence of pattern.\n") ; puts("n * Repeat previous search (for N-th occurence).\n"); puts("q Exit.\n"); error("More help..."); } static void help1() { char message[100]; extern char all_options[]; puts("R Repaint screen, discarding buffered input.\n"); puts("p, % * Position to N percent into the file.\n"); puts("m<letter> Mark the current position with <letter>.\n"); puts("'<letter> Return to a previously marked position.\n"); sprintf(message, "-X Toggle a flag (X may be one of \"%s\").\n", all_options); puts(message); puts("E [file] Examine a new file.\n"); puts("N Examine the next file (from the command line).\n") ; puts("P Examine the previous file (from the command line). \n"); puts("V Print version number.\n"); puts("!command Passes the command to a shell to be executed.\n"); #line 49 "help.c" sprintf(message, "v Edit the current file with $EDITOR (default %s).\n", "/usr/bin/vi"); puts(message); #line 55 "help.c" error(""); } void help() { register int i; for (i = 0; i < 2; i++) { clear(); puts("Commands marked with * may be preceeded by a number, N.\n\n"); switch (i) { case 0: help0(); break; case 1: help1(); break; } } }

input.i

#line 1 "input.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "input.c" /* * High level routines dealing with getting lines of input * from the file being viewed. * * When we speak of "lines" here, we mean PRINTABLE lines; * lines processed with respect to the screen width. * We use the term "raw line" to refer to lines simply * delimited by newlines; not processed with respect to screen width. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 13 "input.c" extern int do_bs; extern int squeeze; extern char *line; /* * Get the next line. * A "current" position is passed and a "new" position is returned. * The current position is the position of the first character of * a line. The new position is the position of the first character * of the NEXT line. The line obtained is the line starting at curr_pos. */ POSITION forw_line(curr_pos) POSITION curr_pos; { POSITION new_pos; register int c; if (curr_pos == ((POSITION)(-1)) || ch_seek(curr_pos)) return (((POSITION)(-1))); c = ch_forw_get(); if (c == (0)) return (((POSITION)(-1))); prewind(); for (;;) { if (c == '\n' || c == (0)) { /* * End of the line. */ new_pos = ch_tell(); break; } /* * Append the char to the line and get the next char. */ if (pappend(c)) { /* * The char won't fit in the line; the line * is too long to print in the screen width. * End the line here. */ new_pos = ch_tell() - 1; break; } c = ch_forw_get(); } (void) pappend('\0'); if (squeeze && *line == '\0') { /* * This line is blank. * Skip down to the last contiguous blank line * and pretend it is the one which we are returning. */ while ((c = ch_forw_get()) == '\n') ; if (c != (0)) (void) ch_back_get(); new_pos = ch_tell(); } return (new_pos); } /* * Get the previous line. * A "current" position is passed and a "new" position is returned. * The current position is the position of the first character of * a line. The new position is the position of the first character * of the PREVIOUS line. The line obtained is the one starting at new_pos. */ POSITION back_line(curr_pos) POSITION curr_pos; { POSITION new_pos, begin_new_pos; int c; if (curr_pos == ((POSITION)(-1)) || curr_pos <= (POSITION)0 || ch_seek(curr_pos-1)) return (((POSITION)(-1))); if (squeeze) { /* * Find out if the "current" line was blank. */ (void) ch_forw_get(); /* Skip the newline */ c = ch_forw_get(); /* First char of "current" line */ (void) ch_back_get(); /* Restore our position */ (void) ch_back_get(); if (c == '\n') { /* * The "current" line was blank. * Skip over any preceeding blank lines, * since we skipped them in forw_line(). */ while ((c = ch_back_get()) == '\n') ; if (c == (0)) return (((POSITION)(-1))); (void) ch_forw_get(); } } /* * Scan backwards until we hit the beginning of the line. */ for (;;) { c = ch_back_get(); if (c == '\n') { /* * This is the newline ending the previous line. * We have hit the beginning of the line. */ new_pos = ch_tell() + 1; break; } if (c == (0)) { /* * We have hit the beginning of the file. * This must be the first line in the file. * This must, of course, be the beginning of the line. */ new_pos = (POSITION)0; break; } } /* * Now scan forwards from the beginning of this line. * We keep discarding "printable lines" (based on screen width) * until we reach the curr_pos. * * {{ This algorithm is pretty inefficient if the lines * are much longer than the screen width, * but I don't know of any better way. }} */ if (ch_seek(new_pos)) return (((POSITION)(-1))); loop: begin_new_pos = new_pos; prewind(); do { c = ch_forw_get(); new_pos++; if (c == '\n') break; if (pappend(c)) { /* * Got a full printable line, but we haven't * reached our curr_pos yet. Discard the line * and start a new one. */ (void) pappend('\0'); (void) ch_back_get(); new_pos--; goto loop; } } while (new_pos < curr_pos); (void) pappend('\0'); return (begin_new_pos); }

line.i

#line 1 "line.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "line.c" /* * Routines to manipulate the "line buffer". * The line buffer holds a line of output as it is being built * in preparation for output to the screen. * We keep track of the PRINTABLE length of the line as it is being built. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 10 "line.c" static char linebuf[1024]; /* Buffer holds the current output line */ static char *curr; /* Pointer into linebuf */ static int column; /* Printable length, accounting for backspaces, etc. */ /* * A ridiculously complex state machine takes care of backspaces * when in BS_UNDERLINE mode. The complexity arises from the attempt * to deal with all cases, especially involving long lines with underlining. * There are still some cases which will break it. * * There are four states: * UL_NORMAL is the normal state (not in underline mode). * UL_YES means we are in underline mode. We expect to get * either a sequence like "_\bX" or "X\b_" to continue * underline mode, or just some ordinary characters * (no backspaces) to end underline mode. * UL_X means we are one character after UL_YES * (we have gotten the '_' in "_\bX" or the 'X' in "X\b_"). * UL_XB means we are one character after UL_X * (we have gotten the backspace in "_\bX" or "X\b_"; * we expect one more ordinary character, * which will put us back in state UL_YES). */ static int ul_state; /* Currently in underline mode? */ char *line; /* Pointer to the current line. Usually points to linebuf. */ extern int bs_mode; extern int tabstop; extern int ul_width, ue_width; extern int sc_width, sc_height; /* * Rewind the line buffer. */ void prewind() { line = curr = linebuf; ul_state = 0; column = 0; } /* * Append a character to the line buffer. * Expand tabs into spaces, handle underlining. * Returns 0 if ok, 1 if couldn't fit in buffer. */ int pappend(c) int c; { if (c == '\0') { /* * Terminate underline mode, if necessary. * Append a '\0' to the end of the line. */ switch (ul_state) { case 2: curr[0] = curr[-1]; curr[-1] = '\202'; curr++; break; case 3: case 1: *curr++ = '\202'; break; } ul_state = 0; *curr = '\0'; return (0); } if (curr > linebuf + sizeof(linebuf) - 12) /* * Almost out of room in the line buffer. * Don't take any chances. * {{ Linebuf is supposed to be big enough that this * will never happen, but may need to be made * bigger for wide screens or lots of backspaces. }} */ return (1); if (bs_mode == 0) { /* * Advance the state machine. */ switch (ul_state) { case 0: if (curr <= linebuf + 1 || curr[-1] != '\b') break; if (c != '_' && curr[-2] != '_') { curr -= 2; break; } /* * We have either "_\bX" or "X\b_" (including * the current char). Switch into underline mode. */ if (column + ul_width + ue_width + 1 >= sc_width) /* * Not enough room left on the screen to * enter and exit underline mode. */ return (1); if (ul_width > 0 && curr > linebuf + 2 && curr[-3] == ' ') { /* * Special case for magic cookie terminals: * if the previous char was a space, replace * it with the "enter underline" sequence. */ curr[-3] = '\201'; column += ul_width-1; } else { curr[-1] = curr[-2]; curr[-2] = '\201'; column += ul_width; curr++; } /* Fall thru */ case 3: /* * Termination of a sequnce "_\bX" or "X\b_". */ if (c == '_') c = curr[-2]; curr -= 2; ul_state = 1; break; case 1: if (column + ue_width + 1 >= sc_width) /* * We have just barely enough room to * exit underline mode. */ return (1); ul_state = 2; break; case 2: if (c == '\b') ul_state = 3; else { /* * Exit underline mode. * We have to shuffle the chars a bit * to make this work. */ curr[0] = curr[-1]; curr[-1] = '\202'; column += ue_width; if (ul_width > 0 && curr[0] == ' ') /* * Another special case for magic * cookie terminals: if the next * char is a space, replace it * with the "exit underline" sequence. */ column--; else curr++; ul_state = 0; } break; } } if (c == ' ') { /* * Expand a tab into spaces. */ do { if ((column+1) + ((ul_state)?ue_width:0) > sc_width) return (1); else column = (column+1); } while ((column % tabstop) != 0); *curr++ = ' '; return (0); } if (c == '\b') { if (bs_mode == 2) { /* * Treat backspace as a control char: output "^H". */ if ((column+2) + ((ul_state)?ue_width:0) > sc_width) return (1); else column = (column+2); *curr++ = ('H' | 0200); } else { /* * Output a real backspace. */ column--; *curr++ = '\b'; } return (0); } if (control_char(c)) { /* * Put a "^X" into the buffer. * The 0200 bit is used to tell put_line() to prefix * the char with a ^. We don't actually put the ^ * in the buffer because we sometimes need to move * chars around, and such movement might separate * the ^ from its following character. */ if ((column+2) + ((ul_state)?ue_width:0) > sc_width) return (1); else column = (column+2); *curr++ = (carat_char(c) | 0200); return (0); } /* * Ordinary character. Just put it in the buffer. */ if ((column+1) + ((ul_state)?ue_width:0) > sc_width) return (1); else column = (column+1); *curr++ = c; return (0); } /* * Analogous to forw_line(), but deals with "raw lines": * lines which are not split for screen width. * {{ This is supposed to be more efficient than forw_line(). }} */ POSITION forw_raw_line(curr_pos) POSITION curr_pos; { register char *p; register int c; POSITION new_pos; if (curr_pos == ((POSITION)(-1)) || ch_seek(curr_pos) || (c = ch_forw_get()) == (0)) return (((POSITION)(-1))); p = linebuf; for (;;) { if (c == '\n' || c == (0)) { new_pos = ch_tell(); break; } if (p >= &linebuf[sizeof(linebuf)-1]) { /* * Overflowed the input buffer. * Pretend the line ended here. * {{ The line buffer is supposed to be big * enough that this never happens. }} */ new_pos = ch_tell() - 1; break; } *p++ = c; c = ch_forw_get(); } *p = '\0'; line = linebuf; return (new_pos); } /* * Analogous to back_line(), but deals with "raw lines". * {{ This is supposed to be more efficient than back_line(). }} */ POSITION back_raw_line(curr_pos) POSITION curr_pos; { register char *p; register int c; POSITION new_pos; if (curr_pos == ((POSITION)(-1)) || curr_pos <= (POSITION)0 || ch_seek(curr_pos-1)) return (((POSITION)(-1))); p = &linebuf[sizeof(linebuf)]; *--p = '\0'; for (;;) { c = ch_back_get(); if (c == '\n') { /* * This is the newline ending the previous line. * We have hit the beginning of the line. */ new_pos = ch_tell() + 1; break; } if (c == (0)) { /* * We have hit the beginning of the file. * This must be the first line in the file. * This must, of course, be the beginning of the line. */ new_pos = (POSITION)0; break; } if (p <= linebuf) { /* * Overflowed the input buffer. * Pretend the line ended here. */ new_pos = ch_tell() + 1; break; } *--p = c; } line = p; return (new_pos); }

main.i

#line 1 "main.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "main.c" /* * Entry point, initialization, miscellaneous routines. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 7 "main.c" #line 1 "position.h" /* * Include file for interfacing to position.c modules. */ #line 8 "main.c" #line 1 ".\\setjmp.h" #line 9 "main.c" int ispipe; char * first_cmd; char * every_first_cmd; int new_file; int is_tty; char current_file[128]; int ac; char **av; int curr_ac; char * editor; #line 22 "main.c" extern int file; extern int nbufs; extern int sigs; extern int quit_at_eof; extern int p_nbufs, f_nbufs; extern int back_scroll; extern int top_scroll; extern int sc_height; /* * Edit a new file. * Filename "-" means standard input. * No filename means the "current" file, from the command line. */ void edit(filename) char *filename; { register int f; char message[100]; static int any_edited = 0; static int hold_scroll = 0; int fFirst; int fFile; int fReturn = 0; fFile = fFilename != (0) && *filename != '\0'; if (!fFile) { if (curr_ac >= ac) { error("No current file"); fReturn = 1; } filename = av[curr_ac]; } if (!fReturn) { if (strcmp(filename, "-") == 0) f = 0; /* Standard input */ else if ((f = open(filename, 0)) < 0) { sprintf(message, "Cannot open %.*s", error_width()-13, filename); if (any_edited) error(message); else { puts(message); hold_scroll = 1; } fReturn = 1; } if (!fReturn) { if (isatty(f)) { /* * Not really necessary to call this an error, * but if the control terminal (for commands) * and the input file (for data) are the same, * we get weird results at best. */ error("Can't take input from a terminal"); if (f > 0) close(f); } else { /* * Close the current input file and set up to use the new one. */ if (file > 0) close(file); new_file = 1; strcpy(current_file, filename); ispipe = (f == 0); file = f; ch_init( (ispipe) ? p_nbufs : f_nbufs ); init_mark(); if (every_first_cmd != (0)) first_cmd = every_first_cmd; if (is_tty) { any_edited = 1; if (hold_scroll) { /* * Before erasing the screen contents, * display the file name and ask for a keystroke. */ error(filename); hold_scroll = 0; } fFirst = first_cmd != (0) && *first_cmd != '\0'; if (!fFirst) { /* * Display the first screen. */ jump_back(1); } else { /* * The first_cmd will hopefully redisplay the * screen, so we need not display anything yet. * Indicate there is nothing yet on the screen. */ pos_clear(); } } } } } } /* * Edit the next file in the command line list. */ void next_file(n) int n; { if (curr_ac + n >= ac) { if (quit_at_eof) quit(); error("No (N-th) next file"); } else edit(av[curr_ac += n]); } /* * Edit the previous file in the command line list. */ void prev_file(n) int n; { if (curr_ac - n < 0) error("No (N-th) previous file"); else edit(av[curr_ac -= n]); } /* * Copy a file directly to standard output. * Used if standard output is not a tty. */ static void cat_file() { register int c; while ((c = ch_forw_get()) != (0)) putc(c); flush(); } /* * Entry point. */ main(argc, argv) int argc; char *argv[]; { char *getenv(); /* * Process command line arguments and LESS environment arguments. * Command line arguments override environment arguments. */ init_option(); scan_option(getenv("LESS")); argv++; while ( (--argc > 0) && (argv[0][0] == '-' || argv[0][0] == '+') && argv[0][1] != '\0') scan_option(*argv++); editor = getenv("EDITOR"); if (editor == (0) || *editor == '\0') editor = "/usr/bin/vi"; #line 209 "main.c" /* * Set up list of files to be examined. */ ac = argc; av = argv; curr_ac = 0; /* * Set up terminal, etc. */ is_tty = isatty(1); if (!is_tty) { /* * Output is not a tty. * Just copy the input file(s) to output. */ if (ac < 1) { edit("-"); cat_file(); } else { do { edit((char *)(0)); if (file >= 0) cat_file(); } while (++curr_ac < ac); } exit(0); } raw_mode(1); get_term(); open_getc(); init(); if (back_scroll < 0) { /* {{ KLUDGE }} */ back_scroll = sc_height-1; if (top_scroll) back_scroll--; } if (setjmp(main_loop)) quit(); init_signals(); /* * Select the first file to examine. */ if (ac < 1) edit("-"); /* Standard input */ else { /* * Try all the files named as command arguments. * We are simply looking for one which can be * opened without error. */ do { edit((char *)(0)); if (file >= 0) /* We can open this file. */ break; putc('\n'); flush(); } while (++curr_ac < ac); } if (file >= 0) commands(); quit(); } /* * Exit the program. */ void quit() { /* * Put cursor at bottom left corner, clear the line, * reset the terminal modes, and exit. */ lower_left(); clear_eol(); deinit(); flush(); raw_mode(0); exit(0); }

option.i

#line 1 "option.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "option.c" /* * Process command line options. * Each option is a single letter which controls a program variable. * The options have defaults which may be changed via * the command line option, or toggled via the "-" command. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 10 "option.c" /* * Types of options. */ /* * Variables controlled by command line options. */ int p_nbufs, f_nbufs; /* Number of buffers. There are two values, one used for input from a pipe and the other for input from a file. */ int clean_data; /* Can we assume the data is "clean"? (That is, free of nulls, etc) */ int quiet; /* Should we suppress the audible bell? */ int top_search; /* Should forward searches start at the top of the screen? (alternative is bottom) */ int top_scroll; /* Repaint screen from top? (alternative is scroll from bottom) */ int pr_type; /* Type of prompt (short, medium, long) */ int bs_mode; /* How to process backspaces */ int know_dumb; /* Don't complain about dumb terminals */ int quit_at_eof; /* Quit after hitting end of file twice */ int squeeze; /* Squeeze multiple blank lines into one */ int tabstop; /* Tab settings */ int back_scroll; /* Repaint screen on backwards movement */ int twiddle; /* Display "~" for lines after EOF */ extern int nbufs; extern char *first_cmd; extern char *every_first_cmd; static struct option { char oletter; /* The controlling letter (a-z) */ char otype; /* Type of the option */ int odefault; /* Default value */ int *ovar; /* Pointer to the associated variable */ char *odesc[3]; /* Description of each value */ } option[] = { { 'c', 01, 0, &clean_data, { "Don't assume data is clean", "Assume data is clean", (0) } }, { 'd', 01|0100, 0, &know_dumb, { (0), (0), (0)} }, { 'e', 01, 0, &quit_at_eof, { "Don't quit at end-of-file", "Quit at end-of-file", (0) } }, { 'h', 04, -1, &back_scroll, { "Backwards scroll limit is %d lines", (0), (0) } }, { 'p', 01, 0, &top_scroll, { "Repaint by scrolling from bottom of screen", "Repaint by painting from top of screen", (0) } }, { 'x', 04, 8, &tabstop, { "Tab stops every %d spaces", (0), (0) } }, { 's', 01, 0, &squeeze, { "Don't squeeze multiple blank lines", "Squeeze multiple blank lines", (0) } }, { 't', 01, 1, &top_search, { "Forward search starts from bottom of screen", "Forward search starts from top of screen", (0) } }, { 'w', 01, 1, &twiddle, { "Display nothing for lines after end-of-file", "Display ~ for lines after end-of-file", (0) } }, { 'm', 02, 0, &pr_type, { "Prompt with a colon", "Prompt with a message", "Prompt with a verbose message" } }, { 'q', 02, 2, &quiet, { "Ring the bell for errors AND at eof/bof", "Ring the bell for errors but not at eof/bof", "Never ring the bell" } }, { 'u', 02, 0, &bs_mode, { "Underlined text displayed in underline mode", "All backspaces cause overstrike", "Backspaces print as ^H" } }, { '\0' } }; char all_options[64]; /* List of all valid options */ /* * Initialize each option to its default value. */ void init_option() { register struct option *o; register char *p; /* * First do special cases, not in option table. */ first_cmd = every_first_cmd = (0); f_nbufs = 5; /* -bf */ p_nbufs = 12; /* -bp */ p = all_options; *p++ = 'b'; for (o = option; o->oletter != '\0'; o++) { /* * Set each variable to its default. * Also make a list of all options, in "all_options". */ *(o->ovar) = o->odefault; *p++ = o->oletter; if (o->otype & 02) *p++ = ((o->oletter)-'a'+'A'); } *p = '\0'; } /* * Toggle command line flags from within the program. * Used by the "-" command. */ void toggle_option(c) int c; { register struct option *o; char message[100]; char buf[5]; /* * First check for special cases not handled by the option table. */ switch (c) { case 'b': sprintf(message, "%d buffers", nbufs); error(message); interupt(); return; } for (o = option; o->oletter != '\0'; o++) { if ((o->otype & 01) && (o->oletter == c) && (o->otype & 0100) == 0) { /* * Boolean option: * just toggle it. */ *(o->ovar) = ! *(o->ovar); error(o->odesc[*(o->ovar)]); return; } else if ((o->otype & 02) && (o->oletter == c) && (o->otype & 0100) == 0) { /* * Triple-valued option with lower case letter: * make it 1 unless already 1, then make it 0. */ *(o->ovar) = (*(o->ovar) == 1) ? 0 : 1; error(o->odesc[*(o->ovar)]); return; } else if ((o->otype & 02) && (((o->oletter)-'a'+'A') == c) && (o->otype & 0100) == 0) { /* * Triple-valued option with upper case letter: * make it 2 unless already 2, then make it 0. */ *(o->ovar) = (*(o->ovar) == 2) ? 0 : 2; error(o->odesc[*(o->ovar)]); return; } else if ((o->otype & 04) && (o->oletter == c) && (o->otype & 0100) == 0) { sprintf(message, o->odesc[0], *(o->ovar)); error(message); return; } } if (control_char(c)) sprintf(buf, "^%c", carat_char(c)); else sprintf(buf, "%c", c); sprintf(message, "\"-%s\": no such flag. Use one of \"%s\"", buf, all_options); error(message); } /* * Scan an argument (either from command line or from LESS environment * variable) and process it. */ void scan_option(s) char *s; { register struct option *o; register int c; if (s == (0)) return; next: if (*s == '\0') return; switch (c = *s++) { case '-': case ' ': case ' ': goto next; case '+': if (*s == '+') every_first_cmd = ++s; first_cmd = s; return; case 'b': switch (*s) { case 'f': s++; f_nbufs = getnum(&s, 'b'); break; case 'p': s++; p_nbufs = getnum(&s, 'b'); break; default: f_nbufs = p_nbufs = getnum(&s, 'b'); break; } goto next; } for (o = option; o->oletter != '\0'; o++) { if ((o->otype & 01) && (o->oletter == c)) { *(o->ovar) = ! o->odefault; goto next; } else if ((o->otype & 02) && (o->oletter == c)) { *(o->ovar) = (o->odefault == 1) ? 0 : 1; goto next; } else if ((o->otype & 02) && (((o->oletter)-'a'+'A') == c)) { *(o->ovar) = (o->odefault == 2) ? 0 : 2; goto next; } else if ((o->otype & 04) && (o->oletter == c)) { *(o->ovar) = getnum(&s, c); goto next; } } printf("\"-%c\": invalid flag\n", c); exit(1); } /* * Translate a string into a number. * Like atoi(), but takes a pointer to a char *, and updates * the char * to point after the translated number. */ static int getnum(sp, c) char **sp; int c; { register char *s; register int n; s = *sp; if (*s < '0' || *s > '9') { printf("number is required after -%c\n", c); exit(1); } n = 0; while (*s >= '0' && *s <= '9') n = 10 * n + *s++ - '0'; *sp = s; return (n); }

output.i

#line 1 "output.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "output.c" /* * High level routines dealing with the output to the screen. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 7 "output.c" extern int sigs; extern int sc_width, sc_height; extern int ul_width, ue_width; extern int so_width, se_width; extern int tabstop; extern int twiddle; extern char *line; extern char *first_cmd; /* * Display the line which is in the line buffer. */ void put_line() { register char *p; register int c; register int column; extern int auto_wrap, ignaw; if (sigs) /* * Don't output if a signal is pending. */ return; if (line == (0)) line = (twiddle) ? "~" : ""; column = 0; for (p = line; *p != '\0'; p++) { switch (c = *p) { case '\201': ul_enter(); column += ul_width; break; case '\202': ul_exit(); column += ue_width; break; case ' ': do { putc(' '); column++; } while ((column % tabstop) != 0); break; case '\b': putbs(); column--; break; default: if (c & 0200) { putc('^'); putc(c & 0177); column += 2; } else { putc(c); column++; } } } if (column < sc_width || !auto_wrap || ignaw) putc('\n'); } /* * Is a given character a "control" character? * {{ ASCII DEPENDENT }} */ int control_char(c) int c; { return (c < ' ' || c == '\177'); } /* * Return the printable character used to identify a control character * (printed after a carat; e.g. '\3' => "^C"). * {{ ASCII DEPENDENT }} */ int carat_char(c) int c; { return ((c == '\177') ? '?' : (c | 0100)); } static char obuf[1024]; static char *ob = obuf; /* * Flush buffered output. */ void flush() { write(1, obuf, ob-obuf); ob = obuf; } /* * Discard buffered output. */ void dropout() { ob = obuf; } /* * Output a character. */ void putc(c) int c; { if (ob >= &obuf[sizeof(obuf)]) flush(); *ob++ = c; } /* * Output a string. */ void puts(s) register char *s; { while (*s != '\0') putc(*s++); } /* * Output a message in the lower left corner of the screen * and wait for carriage return. */ static char return_to_continue[] = " (press RETURN)"; void error(s) char *s; { register int c; static char buf[2]; lower_left(); clear_eol(); so_enter(); puts(s); puts(return_to_continue); so_exit(); #line 172 "output.c" c = getc(); if (c != '\n' && c != '\r' && c != ' ') { buf[0] = c; first_cmd = buf; } #line 179 "output.c" if (strlen(s) > sc_width) repaint(); } int error_width() { /* * Don't use the last position, because some terminals * will scroll if you write in the last char of the last line. */ return (sc_width - (sizeof(return_to_continue) + so_width + se_width + 1)); }

position.i

#line 1 "position.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "position.c" /* * Routines dealing with the "position" table. * This is a table which tells the position (in the input file) of the * first char on each currently displayed line. * * {{ The position table is scrolled by moving all the entries. * Would be better to have a circular table * and just change a couple of pointers. }} */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 13 "position.c" #line 1 "position.h" /* * Include file for interfacing to position.c modules. */ #line 14 "position.c" static POSITION table[100]; /* The position table */ extern int sc_width, sc_height; /* * Return the position of one of: * the top (first) line on the screen * the second line on the screen * the bottom line on the screen * the line after the bottom line on the screen */ POSITION position(where) int where; { switch (where) { case -1: where = sc_height - 2; break; case -2: where = sc_height - 1; break; } return (table[where]); } /* * Add a new file position to the bottom of the position table. */ void add_forw_pos(pos) POSITION pos; { register int i; /* * Scroll the position table up. */ for (i = 1; i < sc_height; i++) table[i-1] = table[i]; table[sc_height - 1] = pos; } /* * Add a new file position to the top of the position table. */ void add_back_pos(pos) POSITION pos; { register int i; /* * Scroll the position table down. */ for (i = sc_height - 1; i > 0; i--) table[i] = table[i-1]; table[0] = pos; } /* * Initialize the position table, done whenever we clear the screen. */ void pos_clear() { register int i; for (i = 0; i < sc_height; i++) table[i] = ((POSITION)(-1)); } /* * See if the byte at a specified position is currently on the screen. * Check the position table to see if the position falls within its range. * Return the position table entry if found, -1 if not. */ int onscreen(pos) POSITION pos; { register int i; if (pos < table[0]) return (-1); for (i = 1; i < sc_height; i++) if (pos < table[i]) return (i-1); return (-1); }

prim.i

#line 1 "prim.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "prim.c" /* * Primitives for displaying the file on the screen. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 7 "prim.c" #line 1 "position.h" /* * Include file for interfacing to position.c modules. */ #line 8 "prim.c" int hit_eof; /* Keeps track of how many times we hit end of file */ extern int quiet; extern int top_search; extern int top_scroll; extern int back_scroll; extern int sc_width, sc_height; extern int sigs; extern char *line; extern char *first_cmd; /* * Sound the bell to indicate he is trying to move past end of file. */ static void eof_bell() { if (quiet == 0) bell(); else vbell(); } /* * Check to see if the end of file is currently "displayed". */ static void eof_check() { POSITION pos; /* * If the bottom line is empty, we are at EOF. * If the bottom line ends at the file length, * we must be just at EOF. */ pos = position(-2); if (pos == ((POSITION)(-1)) || pos == ch_length()) hit_eof++; } /* * Display n lines, scrolling forward, * starting at position pos in the input file. * "force" means display the n lines even if we hit end of file. * "only_last" means display only the last screenful if n > screen size. */ static void forw(n, pos, force, only_last) register int n; POSITION pos; int force; int only_last; { int eof = 0; int nlines = 0; int repaint_flag; /* * repaint_flag tells us not to display anything till the end, * then just repaint the entire screen. */ if (a) { null(); } repaint_flag = (only_last && n > sc_height-1); if (!repaint_flag) { if (top_scroll && n >= sc_height - 1) { /* * Start a new screen. * {{ This is not really desirable if we happen * to hit eof in the middle of this screen, * but we don't know if that will happen now. }} */ clear(); home(); force = 1; } else { lower_left(); clear_eol(); } if (pos != position(-2)) { /* * This is not contiguous with what is * currently displayed. Clear the screen image * (position table) and start a new screen. */ pos_clear(); add_forw_pos(pos); force = 1; if (top_scroll) { clear(); home(); } else { puts("...skipping...\n"); } } } while (--n >= 0) { /* * Read the next line of input. */ pos = forw_line(pos); if (pos == ((POSITION)(-1))) { /* * End of file: stop here unless the top line * is still empty, or "force" is true. */ eof = 1; if (!force && position(0) != ((POSITION)(-1))) break; line = (0); } /* * Add the position of the next line to the position table. * Display the current line on the screen. */ add_forw_pos(pos); nlines++; if (!repaint_flag) put_line(); } if (eof) hit_eof++; else eof_check(); if (nlines == 0) eof_bell(); else if (repaint_flag) repaint(); } /* * Display n lines, scrolling backward. */ static void back(n, pos, force, only_last) register int n; POSITION pos; int force; int only_last; { int nlines = 0; int repaint_flag; int fBreak; int fLoop; repaint_flag = (n > back_scroll) | ( (only_last != 0) & (n > sc_height-1)); /* repaint_flag = (n > back_scroll || (only_last && n > sc_height-1)); */ hit_eof = 0; fBreak = 0; fLoop = (--n >= 0); while (fLoop) { /* * Get the previous line of input. */ pos = back_line(pos); if (pos == ((POSITION)(-1))) { /* * Beginning of file: stop here unless "force" is true. */ if (!force) fBreak = 1; else line = (0); } /* * Add the position of the previous line to the position table. * Display the line on the screen. */ if (!fBreak) { add_back_pos(pos); nlines++; if (!repaint_flag) { home(); add_line(); put_line(); } } fLoop = !fBreak && (--n >= 0); } eof_check(); if (nlines == 0) eof_bell(); else if (repaint_flag) repaint(); } /* * Display n more lines, forward. * Start just after the line currently displayed at the bottom of the screen. */ void forward(n, only_last) int n; int only_last; { POSITION pos; pos = position(-2); if (pos == ((POSITION)(-1))) { eof_bell(); hit_eof++; return; } forw(n, pos, 0, only_last); } /* * Display n more lines, backward. * Start just before the line currently displayed at the top of the screen. */ void backward(n, only_last) int n; int only_last; { POSITION pos; pos = position(0); if (pos == ((POSITION)(-1))) { /* * This will almost never happen, * because the top line is almost never empty. */ eof_bell(); return; } back(n, pos, 0, only_last); } /* * Repaint the screen, starting from a specified position. */ static void prepaint(pos) POSITION pos; { hit_eof = 0; forw(sc_height-1, pos, 0, 0); } /* * Repaint the screen. */ void repaint() { /* * Start at the line currently at the top of the screen * and redisplay the screen. */ prepaint(position(0)); } /* * Jump to the end of the file. * It is more convenient to paint the screen backward, * from the end of the file toward the beginning. */ void jump_forw() { POSITION pos; if (ch_end_seek()) { error("Cannot seek to end of file"); return; } pos = ch_tell(); clear(); pos_clear(); add_back_pos(pos); back(sc_height - 1, pos, 0, 0); } /* * Jump to line n in the file. */ void jump_back(n) register int n; { register int c; /* * This is done the slow way, by starting at the beginning * of the file and counting newlines. */ if (ch_seek((POSITION)0)) { /* * Probably a pipe with beginning of file no longer buffered. */ error("Cannot get to beginning of file"); return; } /* * Start counting lines. */ while (--n > 0) { while ((c = ch_forw_get()) != '\n') if (c == (0)) { error("File is not that long"); /* {{ Maybe tell him how long it is? }} */ return; } } /* * Finally found the place to start. * Clear and redisplay the screen from there. * * {{ We *could* figure out if the new position is * close enough to just scroll there without clearing * the screen, but it's not worth it. }} */ prepaint(ch_tell()); } /* * Jump to a specified percentage into the file. * This is a poor compensation for not being able to * quickly jump to a specific line number. */ void jump_percent(percent) int percent; { POSITION pos, len; /* * Determine the position in the file * (the specified percentage of the file's length). */ if ((len = ch_length()) == ((POSITION)(-1))) { error("Don't know length of file"); return; } pos = (percent * len) / 100; jump_loc(pos); } void jump_loc(pos) POSITION pos; { register int c; register int nline; POSITION tpos; /* * See if the desired line is BEFORE the currently * displayed screen. If so, see if it is close enough * to scroll backwards to it. */ tpos = position(0); if (pos < tpos) { for (nline = 1; nline <= back_scroll; nline++) { tpos = back_line(tpos); if (tpos == ((POSITION)(-1)) || tpos <= pos) { back(nline, position(0), 1, 0); return; } } } else if ((nline = onscreen(pos)) >= 0) { /* * The line is currently displayed. * Just scroll there. */ forw(nline, position(-2), 1, 0); return; } /* * Line is not on screen. * Back up to the beginning of the current line. */ if (ch_seek(pos)) { error("Cannot seek to that position"); return; } while ((c = ch_back_get()) != '\n' && c != (0)) ; if (c == '\n') (void) ch_forw_get(); /* * Clear and paint the screen. */ prepaint(ch_tell()); } /* * The table of marks. * A mark is simply a position in the file. */ static POSITION marks[26]; /* * Initialize the mark table to show no marks are set. */ void init_mark() { int i; for (i = 0; i < 26; i++) marks[i] = ((POSITION)(-1)); } /* * See if a mark letter is valid (between a and z). */ static int badmark(c) int c; { if (c < 'a' || c > 'z') { error("Choose a letter between 'a' and 'z'"); return (1); } return (0); } /* * Set a mark. */ void setmark(c) int c; { if (badmark(c)) return; marks[c-'a'] = position(0); } /* * Go to a previously set mark. */ void gomark(c) int c; { POSITION pos; if (badmark(c)) return; if ((pos = marks[c-'a']) == ((POSITION)(-1))) error("mark not set"); else jump_loc(pos); stop(); } /* * Search for the n-th occurence of a specified pattern, * either forward (direction == '/'), or backwards (direction == '?'). */ void search(direction, pattern, n) int direction; char *pattern; register int n; { register int search_forward = (direction == '/'); POSITION pos, linepos; char *re_comp(); char *errmsg; /* * (re_comp handles a null pattern internally, * so there is no need to check for a null pattern here.) */ if ((errmsg = re_comp(pattern)) != (0)) { error(errmsg); return; } #line 578 "prim.c" /* * Figure out where to start the search. */ if (position(0) == ((POSITION)(-1))) { /* * Nothing is currently displayed. * Start at the beginning of the file. * (This case is mainly for first_cmd searches, * for example, "+/xyz" on the command line.) */ pos = (POSITION)0; } else if (!search_forward) { /* * Backward search: start just before the top line * displayed on the screen. */ pos = position(0); } else if (top_search) { /* * Forward search and "start from top". * Start at the second line displayed on the screen. */ pos = position(1); } else { /* * Forward search but don't "start from top". * Start just after the bottom line displayed on the screen. */ pos = position(-2); } if (pos == ((POSITION)(-1))) { /* * Can't find anyplace to start searching from. */ error("Nothing to search"); return; } for (;;) { /* * Get lines until we find a matching one or * until we hit end-of-file (or beginning-of-file * if we're going backwards). */ if (sigs) /* * A signal aborts the search. */ return; if (search_forward) { /* * Read the next line, and save the * starting position of that line in linepos. */ linepos = pos; pos = forw_raw_line(pos); } else { /* * Read the previous line and save the * starting position of that line in linepos. */ pos = back_raw_line(pos); linepos = pos; } if (pos == ((POSITION)(-1))) { /* * We hit EOF/BOF without a match. */ error("Pattern not found"); return; } /* * Test the next line to see if we have a match. * This is done in a variety of ways, depending * on what pattern matching functions are available. */ #line 672 "prim.c" if ( (re_exec(line) == 1) #line 677 "prim.c" #line 678 "prim.c" && (--n <= 0) ) /* * Found the matching line. */ break; } jump_loc(linepos); } #line 710 "prim.c"

prompt.i

#line 1 "prompt.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "prompt.c" /* * Prompting and other messages. * There are three flavors of prompts, SHORT, MEDIUM and LONG, * selected by the -m/-M options. * A prompt is either a colon or a message composed of various * pieces, such as the name of the file being viewed, the percentage * into the file, etc. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 12 "prompt.c" #line 1 "position.h" /* * Include file for interfacing to position.c modules. */ #line 13 "prompt.c" extern int pr_type; extern int ispipe; extern int hit_eof; extern int new_file; extern int sc_width; extern char current_file[]; extern int ac; extern char **av; extern int curr_ac; static char message[500]; /* * Append the name of the current file (to the message buffer). */ static void ap_filename() { if (!ispipe) sprintf(message + strlen(message), "%s", current_file); } /* * Append the "file N of M" message. */ static void ap_of() { if (ac > 1) sprintf(message + strlen(message), " (file %d of %d)", curr_ac+1, ac); } /* * Append the byte offset into the current file. */ static void ap_byte() { POSITION pos, len; pos = position(-2); if (pos != ((POSITION)(-1))) { sprintf(message + strlen(message), " byte %ld", pos); len = ch_length(); if (len > 0) sprintf(message + strlen(message), "/%ld", len); } } /* * Append the percentage into the current file. * If we cannot find the percentage and must_print is true, * the use the byte offset. */ static void ap_percent(must_print) { POSITION pos,len; pos = position(-2); len = ch_length(); if (len > 0 && pos != ((POSITION)(-1))) sprintf(message + strlen(message), " (%ld%%)", (100 * pos) / len); else if (must_print) ap_byte(); } /* * Append the end-of-file message. */ static void ap_eof() { strcat(message, " END"); if (curr_ac + 1 < ac) sprintf(message + strlen(message), " - Next: %s", av[curr_ac+1]); } /* * Return a message suitable for printing by the "=" command. */ char * eq_message() { message[0] = '\0'; ap_filename(); ap_of(); ap_byte(); ap_percent(0); /* * Truncate to the screen width. * {{ This isn't very nice. }} */ message[error_width()] = '\0'; return (message); } /* * Return a prompt. * This depends on the prompt type (SHORT, MEDIUM, LONG), etc. * If we can't come up with an appropriate prompt, return NULL * and the caller will prompt with a colon. */ char * pr_string() { message[0] = '\0'; switch (pr_type) { case 0: if (new_file) { ap_filename(); ap_of(); } if (hit_eof) ap_eof(); break; case 1: if (new_file) { ap_filename(); ap_of(); } if (hit_eof) ap_eof(); else ap_percent(1); break; case 2: ap_filename(); if (new_file) ap_of(); ap_byte(); if (hit_eof) ap_eof(); else ap_percent(0); break; } new_file = 0; if (message[0] == '\0') return ((0)); /* * Truncate to the screen width. * {{ This isn't very nice. }} */ message[sc_width-2] = '\0'; return (message); }

screen.i

#line 1 "screen.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "screen.c" /* * Routines which deal with the characteristics of the terminal. * Uses termcap to be as terminal-independent as possible. * * {{ Someday this should be rewritten to use curses. }} */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 10 "screen.c" #line 13 "screen.c" #line 1 "sgtty.h" /* @(#)sgtty.h 1.7 88/08/19 SMI; from UCB 4.2 85/01/03 */ #line 9 "sgtty.h" #line 11 "sgtty.h" #line 14 "screen.c" #line 15 "screen.c" /* * Strings passed to tputs() to do various terminal functions. */ static char *sc_pad, /* Pad string */ *sc_home, /* Cursor home */ *sc_addline, /* Add line, scroll down following lines */ *sc_lower_left, /* Cursor to last line, first column */ *sc_move, /* General cursor positioning */ *sc_clear, /* Clear screen */ *sc_eol_clear, /* Clear to end of line */ *sc_s_in, /* Enter standout (highlighted) mode */ *sc_s_out, /* Exit standout mode */ *sc_u_in, /* Enter underline mode */ *sc_u_out, /* Exit underline mode */ *sc_visual_bell, /* Visual bell (flash screen) sequence */ *sc_backspace, /* Backspace cursor */ *sc_init, /* Startup terminal initialization */ *sc_deinit; /* Exit terminal de-intialization */ static int dumb; static int hard; int auto_wrap; /* Terminal does \r\n when write past margin */ int ignaw; /* Terminal ignores \n ily after wrap */ int erase_char, kill_char; /* The user's erase and line-kill chars */ int sc_width, sc_height; /* Height & width of screen */ int ul_width, ue_width; /* Printing width of underline sequences */ int so_width, se_width; /* Printing width of standout sequences */ /* * These two variables are sometimes defined in, * and needed by, the termcap library. * It may be necessary on some systems to declare them extern here. */ /*extern*/ short ospeed; /* Terminal output baud rate */ /*extern*/ char PC; /* Pad character */ extern int quiet; /* If VERY_QUIET, use visual bell for bell */ extern int know_dumb; /* Don't complain about a dumb terminal */ extern int back_scroll; char *tgetstr(); char *tgoto(); /* * Change terminal to "raw mode", or restore to "normal" mode. * "Raw mode" means * 1. An outstanding read will complete on receipt of a single keystroke. * 2. Input is not echoed. * 3. On output, \n is mapped to \r\n. * 4. is NOT be expanded into spaces. * 5. Signal-causing characters such as ctrl-C (interrupt), * etc. are NOT disabled. * It doesn't matter whether an input \n is mapped to \r, or vice versa. */ void raw_mode(on) int on; { struct termio s; static struct termio save_term; if (on) { /* * Get terminal modes. */ ioctl(2, TCGETA, &s); /* * Save modes and set certain variables dependent on modes. */ save_term = s; ospeed = s.c_cflag & CBAUD; erase_char = s.c_cc[VERASE]; kill_char = s.c_cc[VKILL]; /* * Set the modes to the way we want them. */ s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); s.c_oflag |= (OPOST|ONLCR|TAB3); s.c_oflag &= ~(OCRNL|ONOCR|ONLRET); s.c_cc[VMIN] = 1; s.c_cc[VTIME] = 0; } else { /* * Restore saved modes. */ s = save_term; } if (on) { /* * Get terminal modes. */ ioctl(2, TIOCGETP, &s); /* * Save modes and set certain variables dependent on modes. */ save_term = s; ospeed = s.sg_ospeed; erase_char = s.sg_erase; kill_char = s.sg_kill; /* * Set the modes to the way we want them. */ s.sg_flags |= CBREAK; s.sg_flags &= ~(ECHO|XTABS); } else { /* * Restore saved modes. */ s = save_term; } ioctl(2, TIOCSETN, &s); } static int couldnt = 0; static void cannot(s) char *s; { if (know_dumb) /* * He knows he has a dumb terminal, so don't tell him. */ return; printf("WARNING: terminal cannot \"%s\"\n", s); couldnt = 1; } /* * Get terminal capabilities via termcap. */ void get_term() { char termbuf[1024]; char *sp; static char sbuf[150]; char *getenv(); /* * Find out what kind of terminal this is. */ if (tgetent(termbuf, getenv("TERM")) <= 0) dumb = 1; /* * Get size of the screen. */ if (dumb || (sc_height = tgetnum("li")) < 0 || tgetflag("hc")) { /* Oh no, this is a hardcopy terminal. */ hard = 1; sc_height = 24; } if (dumb || (sc_width = tgetnum("co")) < 0) sc_width = 80; auto_wrap = tgetflag("am"); ignaw = tgetflag("xn"); /* * Assumes termcap variable "sg" is the printing width of * the standout sequence, the end standout sequence, * the underline sequence, and the end underline sequence. */ if ((ul_width = tgetnum("sg")) < 0) ul_width = 0; so_width = se_width = ue_width = ul_width; /* * Get various string-valued capabilities. */ sp = sbuf; sc_pad = (dumb) ? (0) : tgetstr("pc", &sp); if (sc_pad != (0)) PC = *sc_pad; sc_init = (dumb) ? (0) : tgetstr("ti", &sp); if (sc_init == (0)) sc_init = ""; sc_deinit= (dumb) ? (0) : tgetstr("te", &sp); if (sc_deinit == (0)) sc_deinit = ""; sc_eol_clear = (dumb) ? (0) : tgetstr("ce", &sp); if (hard || sc_eol_clear == (0) || *sc_eol_clear == '\0') { cannot("clear to end of line"); sc_eol_clear = ""; } sc_clear = (dumb) ? (0) : tgetstr("cl", &sp); if (hard || sc_clear == (0) || *sc_clear == '\0') { cannot("clear screen"); sc_clear = "\n\n"; } sc_move = (dumb) ? (0) : tgetstr("cm", &sp); if (hard || sc_move == (0) || *sc_move == '\0') { /* * This is not an error here, because we don't * always need sc_move. * We need it only if we don't have home or lower-left. */ sc_move = ""; } sc_s_in = (dumb) ? (0) : tgetstr("so", &sp); if (hard || sc_s_in == (0)) sc_s_in = ""; sc_s_out = (dumb) ? (0) : tgetstr("se", &sp); if (hard || sc_s_out == (0)) sc_s_out = ""; sc_u_in = (dumb) ? (0) : tgetstr("us", &sp); if (hard || sc_u_in == (0)) sc_u_in = sc_s_in; sc_u_out = (dumb) ? (0) : tgetstr("ue", &sp); if (hard || sc_u_out == (0)) sc_u_out = sc_s_out; sc_visual_bell = (dumb) ? (0) : tgetstr("vb", &sp); if (hard || sc_visual_bell == (0)) sc_visual_bell = ""; sc_home = (dumb) ? (0) : tgetstr("ho", &sp); if (hard || sc_home == (0) || *sc_home == '\0') { if (*sc_move == '\0') { cannot("home cursor"); /* * This last resort for sc_home is supposed to * be an up-arrow suggesting moving to the * top of the "virtual screen". (The one in * your imagination as you try to use this on * a hard copy terminal.) */ sc_home = "|\b^"; } else { /* * No "home" string, * but we can use "move(0,0)". */ strcpy(sp, tgoto(sc_move, 0, 0)); sc_home = sp; sp += strlen(sp) + 1; } } sc_lower_left = (dumb) ? (0) : tgetstr("ll", &sp); if (hard || sc_lower_left == (0) || *sc_lower_left == '\0') { if (*sc_move == '\0') { cannot("move cursor to lower left of screen"); sc_lower_left = "\r"; } else { /* * No "lower-left" string, * but we can use "move(0,last-line)". */ strcpy(sp, tgoto(sc_move, 0, sc_height-1)); sc_lower_left = sp; sp += strlen(sp) + 1; } } /* * To add a line at top of screen and scroll the display down, * we use "al" (add line) or "sr" (scroll reverse). */ if (dumb) sc_addline = (0); else if ((sc_addline = tgetstr("al", &sp)) == (0) || *sc_addline == '\0') sc_addline = tgetstr("sr", &sp); if (hard || sc_addline == (0) || *sc_addline == '\0') { cannot("scroll backwards"); sc_addline = ""; /* Force repaint on any backward movement */ back_scroll = 0; } if (dumb || tgetflag("bs")) sc_backspace = "\b"; else { sc_backspace = tgetstr("bc", &sp); if (sc_backspace == (0) || *sc_backspace == '\0') sc_backspace = "\b"; } if (couldnt) /* Give him time to read all the "cannot" messages. */ error(""); } /* * Below are the functions which perform all the * terminal-specific screen manipulation. */ /* * Initialize terminal */ void init() { tputs(sc_init, sc_height, putc); } /* * Deinitialize terminal */ void deinit() { tputs(sc_deinit, sc_height, putc); } /* * Home cursor (move to upper left corner of screen). */ void home() { tputs(sc_home, 1, putc); } /* * Add a blank line (called with cursor at home). * Should scroll the display down. */ void add_line() { tputs(sc_addline, sc_height, putc); } /* * Move cursor to lower left corner of screen. */ void lower_left() { tputs(sc_lower_left, 1, putc); } /* * Ring the terminal bell. */ void bell() { if (quiet == 2) vbell(); else putc('\7'); } /* * Output the "visual bell", if there is one. */ void vbell() { if (*sc_visual_bell == '\0') return; tputs(sc_visual_bell, sc_height, putc); } /* * Clear the screen. */ void clear() { tputs(sc_clear, sc_height, putc); } /* * Clear from the cursor to the end of the cursor's line. * {{ This must not move the cursor. }} */ void clear_eol() { tputs(sc_eol_clear, 1, putc); } /* * Begin "standout" (bold, underline, or whatever). */ void so_enter() { tputs(sc_s_in, 1, putc); } /* * End "standout". */ void so_exit() { tputs(sc_s_out, 1, putc); } /* * Begin "underline" (hopefully real underlining, * otherwise whatever the terminal provides). */ void ul_enter() { tputs(sc_u_in, 1, putc); } /* * End "underline". */ void ul_exit() { tputs(sc_u_out, 1, putc); } /* * Erase the character to the left of the cursor * and move the cursor left. */ void backspace() { /* * Try to erase the previous character by overstriking with a space. */ tputs(sc_backspace, 1, putc); putc(' '); tputs(sc_backspace, 1, putc); } /* * Output a plain backspace, without erasing the previous char. */ void putbs() { tputs(sc_backspace, 1, putc); }

signal.i

#line 1 "signal.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "signal.c" /* * Routines dealing with signals. * * A signal usually merely causes a bit to be set in the "signals" word. * At some convenient time, the mainline code checks to see if any * signals need processing by calling psignal(). * An exception is made if we are reading from the keyboard when the * signal is received. Some operating systems will simply call the * signal handler and NOT return from the read (with EINTR). * To handle this case, we service the interrupt directly from * the handler if we are reading from the keyboard. */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 16 "signal.c" #line 1 "c:\\msdev\\include\\signal.h" /*** *signal.h - defines signal values and routines * * Copyright (c) 1985-1995, Microsoft Corporation. All rights reserved. * *Purpose: * This file defines the signal values and declares the signal functions. * [ANSI/System V] * * [Public] * ****/ #pragma once #line 17 "c:\\msdev\\include\\signal.h" #line 24 "c:\\msdev\\include\\signal.h" /* Define _CRTAPI1 (for compatibility with the NT SDK) */ #line 39 "c:\\msdev\\include\\signal.h" #line 40 "c:\\msdev\\include\\signal.h" /* Define _CRTAPI2 (for compatibility with the NT SDK) */ #line 50 "c:\\msdev\\include\\signal.h" #line 51 "c:\\msdev\\include\\signal.h" /* Define _CRTIMP */ /* current definition */ #line 66 "c:\\msdev\\include\\signal.h" #line 67 "c:\\msdev\\include\\signal.h" #line 68 "c:\\msdev\\include\\signal.h" /* Define __cdecl for non-Microsoft compilers */ #line 75 "c:\\msdev\\include\\signal.h" typedef int sig_atomic_t; #line 81 "c:\\msdev\\include\\signal.h" /* Signal types */ /* signal action codes */ /* signal error value (returned by signal call on error) */ /* pointer to exception information pointers structure */ #line 116 "c:\\msdev\\include\\signal.h" extern void * _pxcptinfoptrs; #line 118 "c:\\msdev\\include\\signal.h" /* Function prototypes */ void (__cdecl * __cdecl signal(int, void (__cdecl *)(int)))(int); int __cdecl raise(int); #line 131 "c:\\msdev\\include\\signal.h" #line 17 "signal.c" #line 1 ".\\setjmp.h" #line 18 "signal.c" /* * The type of signal handler functions. * Usually int, although it should be void. */ typedef int HANDLER; /* * "sigs" contains bits indicating signals which need to be processed. */ int sigs; extern int reading; extern char *first_cmd; /* * Interrupt signal handler. */ static HANDLER interupt() { signal(2,interupt); sigs |= 01; if (reading) psignals(); } /* * "Stop" (^Z) signal handler. */ static HANDLER stop() { signal(SIGTSTP,stop); sigs |= S_STOP; if (reading) psignals(); } /* * Set up the signal handlers. */ void init_signals() { (void) signal(2,interupt); (void) signal(SIGTSTP,stop); } /* * Process any signals we have recieved. * A received signal cause a bit to be set in "sigs". */ void psignals() { register int tsignals; tsignals = sigs; sigs = 0; if (tsignals == 0) return; dropout(); /* Discard any buffered output */ if (tsignals & S_STOP) { /* * Clean up the terminal. */ signal(SIGTTOU,(void (__cdecl *)(int))1); lower_left(); clear_eol(); flush(); raw_mode(0); signal(SIGTTOU,(void (__cdecl *)(int))0); signal(SIGTSTP,(void (__cdecl *)(int))0); /* * This system will not allow us to send a * stop signal (SIGTSTP) to ourself * while we are in the signal handler, like maybe now. * (This can be the case if we are reading; see comment above.) * So we ask the silly system for permission to do so. */ sigsetmask(0); kill(getpid(), SIGTSTP); /* * ... Bye bye. ... * Hopefully we'll be back later and resume here... * Reset the terminal and arrange to repaint the * screen when we get back to the main command loop. */ signal(SIGTSTP,stop); raw_mode(1); first_cmd = "r"; longjmp(main_loop, 1); } if (tsignals & 01) { bell(); /* * {{ You may wish to replace the bell() with * error("Interrupt"); }} */ } longjmp(main_loop, 1); } /* * Pass the specified command to a shell to be executed. * Like plain "system()", but handles resetting terminal modes, etc. */ void lsystem(cmd) char *cmd; { int inp; /* * Print the command which is to be executed. */ lower_left(); clear_eol(); puts("!"); puts(cmd); puts("\n"); /* * De-initialize the terminal and take out of raw mode. */ deinit(); flush(); raw_mode(0); /* * Restore signals to their defaults. */ signal(2,(void (__cdecl *)(int))0); signal(SIGTSTP,(void (__cdecl *)(int))0); /* * Pass the command to the system to be executed. */ inp = dup(0); close(0); open("/dev/tty", 0); system(cmd); close(0); dup(inp); close(inp); /* * Reset signals, raw mode, etc. */ init_signals(); raw_mode(1); init(); /* * if (c == '\0') * { * switch (ul_state) * { * case UL_X: * curr[0] = curr[-1]; * curr[-1] = UE_CHAR; * curr++; * break; * case UL_XB: * case UL_YES: * *curr++ = UE_CHAR; * break; * } * ul_state = UL_NORMAL; * *curr = '\0'; * return (0); * } * * if (curr > linebuf + sizeof(linebuf) - 12) * return(1); * * if (bs_mode == BS_UNDERLINE) * { * switch (ul_state) * { * case UL_NORMAL: * if (curr <= linebuf + 1 || curr[-1] != '\b') * break; * if (c != '_' && curr[-2] != '_') * { * curr -= 2; * break; * } * * if (column + ul_width + ue_width + 1 >= sc_width) * return (1); * * if (ul_width > 0 && * curr > linebuf + 2 && curr[-3] == ' ') * { * curr[-3] = UL_CHAR; * column += ul_width-1; * } else * { * curr[-1] = curr[-2]; * curr[-2] = UL_CHAR; * column += ul_width; * curr++; * } * case UL_XB: * if (c == '_') * c = curr[-2]; * curr -= 2; * ul_state = UL_YES; * break; * case UL_YES: * if (column + ue_width + 1 >= sc_width) * return (1); * ul_state = UL_X; * break; * case UL_X: * if (c == '\b') * ul_state = UL_XB; * else * { * curr[0] = curr[-1]; * curr[-1] = UE_CHAR; * column += ue_width; * if (ul_width > 0 && curr[0] == ' ') * column--; * else * curr++; * ul_state = UL_NORMAL; * } * break; * } * } * * if (c == ' ') * { * do * { * NEW_COLUMN(column+1); * } while ((column % tabstop) != 0); * *curr++ = ' '; * return (0); * } * * if (c == '\b') * { * if (bs_mode == BS_CONTROL) * { * NEW_COLUMN(column+2); * *curr++ = ('H' | 0200); * } else * { * column--; * *curr++ = '\b'; * } * return (0); * } * * if (control_char(c)) * { * NEW_COLUMN(column+2); * *curr++ = (carat_char(c) | 0200); * return (0); * } * * NEW_COLUMN(column+1); * *curr++ = c; * return (0); */ }

ttyin.i

#line 1 "ttyin.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "ttyin.c" /* * Routines dealing with getting input from the keyboard (i.e. from the user). */ #line 1 "less.h" /* * Standard include file for "less". */ /* * Language details. */ #line 11 "less.h" /* * Special types and constants. */ typedef long POSITION; /* * {{ Warning: if POSITION is changed to other than "long", * you may have to change some of the printfs which use "%ld" * to print a variable of type POSITION. }} */ /* How quiet should we be? */ /* How should we prompt? */ /* How should we handle backspaces? */ /* Flag to eq_message() telling what to put in the message */ /* Special chars used to tell put_line() to do something special */ long lseek(); #line 1 "funcs.h" void edit (); void next_file (); void prev_file (); void quit (); void init_option (); void toggle_option (); void scan_option (); void forward (); void backward (); void repaint (); void jump_forw (); void jump_back (); void jump_percent (); void jump_loc (); void init_mark (); void setmark (); void gomark (); void search (); int ch_seek (); int ch_end_seek (); POSITION ch_length (); POSITION ch_tell (); int ch_forw_get (); int ch_back_get (); void ch_init (); POSITION position (); void add_forw_pos (); void add_back_pos (); void pos_clear (); int onscreen (); POSITION forw_line (); POSITION back_line (); void put_line (); int control_char (); int carat_char (); void flush (); void dropout (); void putc (); void puts (); void error (); int error_width (); void raw_mode (); void get_term (); void init (); void deinit (); void home (); void add_line (); void lower_left (); void bell (); void vbell (); void clear (); void clear_eol (); void so_enter (); void so_exit (); void ul_enter (); void ul_exit (); void backspace (); void putbs (); char * eq_message (); char * pr_string (); void prewind (); int pappend (); POSITION forw_raw_line (); POSITION back_raw_line (); void init_signals (); void psignals (); void lsystem (); void help (); void open_getc (); int getc (); void commands (); #line 60 "less.h" #line 7 "ttyin.c" /* * The boolean "reading" is set true or false according to whether * we are currently reading from the keyboard. * This information is used by the signal handling stuff in signal.c. * {{ There are probably some race conditions here * involving the variable "reading". }} */ int reading; static int tty; /* * Open keyboard for input. * (Just use file descriptor 2.) */ void open_getc() { tty = 2; } /* * Get a character from the keyboard. */ int getc() { char c; int result; reading = 1; do { flush(); result = read(tty, &c, 1); } while (result != 1); reading = 0; return (c & 0177); }

version.i

#line 1 "version.c" #line 1 "defs.h" /* *********************** ** THIS STUFF WAS IN THE MAKEFILE ** IT BROKE THE XENIX C COMPILER SO I MOVED THE DEFINITIONS HERE *********************** ########################################################################## # System-specific parameters ########################################################################## # Define XENIX if running under XENIX 3.0 # or SCO XENIX System V XENIX = 0 # VOID is 1 if your C compiler supports the "void" type, # 0 if it does not. VOID = 1 # off_t is the type which lseek() returns. # It is also the type of lseek()'s second argument. off_t = long # TERMIO is 1 if your system has /usr/include/termio.h. # This is normally the case for System 5. # If TERMIO is 0 your system must have /usr/include/sgtty.h. # This is normally the case for BSD. TERMIO = 1 # SIGSETMASK is 1 if your system has the sigsetmask() call. # This is normally the case only for BSD 4.2, # not for BSD 4.1 or System 5. SIGSETMASK = 0 ########################################################################## # Optional and semi-optional features ########################################################################## # REGCMP is 1 if your system has the regcmp() function. # This is normally the case for System 5. # RECOMP is 1 if your system has the re_comp() function. # This is normally the case for BSD. # If neither is 1, pattern matching is supported, but without metacharacters. REGCMP = 0 RECOMP = 0 # SHELL_ESCAPE is 1 if you wish to allow shell escapes. # (This is possible only if your system supplies the system() function.) SHELL_ESCAPE = 1 # EDITOR is 1 if you wish to allow editor invocation (the "v" command). # (This is possible only if your system supplies the system() function.) # EDIT_PGM is the name of the (default) editor to be invoked. EDITOR = 1 EDIT_PGM = /bin/vi # ONLY_RETURN is 1 if you want RETURN to be the only input which # will continue past an error message. # Otherwise, any key will continue past an error message. ONLY_RETURN = 0 */ #line 2 "version.c" /* * less * Copyright (c) 1984,1985 Mark Nudelman * * This program may be freely used and/or modified, * with the following provisions: * 1. This notice and the above copyright notice must remain intact. * 2. Neither this program, nor any modification of it, * may not be sold for profit without written consent of the author. * * ----------------------------------------------------------------- * * This program is a paginator similar to "more", * but allows you to move both forward and backward in the file. * Commands are based on "more" and "vi". * * ----------------------- CHANGES --------------------------------- * * Allowed use on standard input 1/29/84 markn * Added E, N, P commands 2/1/84 markn * Added '=' command, 'stop' signal handling 4/17/84 markn * Added line folding 4/20/84 markn * v2: Fixed '=' command to use BOTTOM_PLUS_ONE, * instead of TOP, added 'p' & 'v' commands 4/27/84 markn * v3: Added -m and -t options, '-' command 5/3/84 markn * v4: Added LESS environment variable 5/3/84 markn * v5: New comments, fixed '-' command slightly 5/3/84 markn * v6: Added -Q, visual bell 5/15/84 markn * v7: Fixed jump_back(n) bug: n should count real * lines, not folded lines. Also allow number * on G command. 5/24/84 markn * v8: Re-do -q and -Q commands 5/30/84 markn * v9: Added "+<cmd>" argument 9/25/84 markn * v10: Fixed bug in -b<n> argument processing 10/10/84 markn * v11: Made error() ring bell if \n not entered. 10/18/84 markn * ----------------------------------------------------------------- * v12: Reorganized signal handling and made * portable to 4.2bsd. 2/13/85 mark * v13: Reword error message for '-' command. 2/16/85 mark * v14: Added -bf and -bp variants of -b. 2/22/85 mark * v15: Miscellaneous changes. 2/25/85 mark * v16: Added -u flag for backspace processing. 3/13/85 mark * v17: Added j and k commands, * changed -t default. 4/13/85 mark * v18: Rewrote signal handling code. 4/20/85 mark * v19: Got rid of "verbose" eq_message(). 5/2/85 mark * Made search() scroll in some cases. * v20: Fixed screen.c ioctls for System V. 5/21/85 mark * v21: Fixed some first_cmd bugs. 5/23/85 mark * v22: Added support for no RECOMP nor REGCMP. 5/24/85 mark * v23: Miscellanous changes and prettying up. 5/25/85 mark * v24: Added ti,te terminal init & de-init 6/3/85 Mike Kersenbrock * v25: Added -U flag, standout mode underlining. 6/8/85 mark * v26: Added -M flag. 6/9/85 mark * Use underline termcap (us) if it exists. * v27: Renamed some variables to make unique in 6/15/85 mark * 6 chars. Minor fix to -m. * v28: Fixed right margin bug. 6/28/85 mark * v29: Incorporated M.Rose's changes to signal.c 6/28/85 mark * v30: Fixed stupid bug in argument processing. 6/29/85 mark * v31: Added -p flag, changed repaint algorithm. 7/15/85 mark * Added kludge for magic cookie terminals. * v32: Added cat_file if output not a tty. 7/16/85 mark * v33: Added -e flag and EDITOR. 7/23/85 mark * v34: Added -s flag. 7/26/85 mark * v35: Rewrote option handling; added option.c. 7/27/85 mark * v36: Fixed -e flag to work if not last file. 7/29/85 mark * v37: Added -x flag. 8/10/85 mark * v38: Changed prompting; created prompt.c. 8/19/85 mark * v39: (Not -p) does not initially clear screen. 8/24/85 mark * v40: Added "skipping" indicator in forw(). 8/26/85 mark * v41: ONLY_RETURN, control char commands, 9/17/85 mark * faster search, other minor fixes. * v42: Added ++ command line syntax; 9/25/85 mark * ch_fsize for pipes. * v43: Added -h flag, changed prim.c algorithms. 10/15/85 mark * v44: Made END print in all cases of eof; 10/16/85 mark * ignore SIGTTOU after receiving SIGTSTP. * v45: Never print backspaces unless -u. 10/16/85 mark * v46: Backwards scroll in jump_loc. 10/24/85 mark * v47: Fixed bug in edit(): *first_cmd==0 10/30/85 mark * v48: Use TIOCSETN instead of TIOCSETP. 11/16/85 mark * Added marks (m and ' commands). * ----------------------------------------------------------------- */ char version[] = "@(#) less version 48";