Monitor source Part 2 of 9
jct
jct at jct.UUCP
Tue Jul 11 13:55:50 AEST 1989
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 9)."
# Contents: help/scrio.hlp hindex.c include/km/monitor.h
# include/km/scrops.h lib/docmd.c lib/scrout3.c lib/scrout6.c
# lib/scrout9.c lib/string1.c lib/string2.c lib/tgoto.c
# Wrapped by jct@ on Mon Jul 10 22:48:04 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'help/scrio.hlp' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'help/scrio.hlp'\"
else
echo shar: Extracting \"'help/scrio.hlp'\" \(5873 characters\)
sed "s/^X//" >'help/scrio.hlp' <<'END_OF_FILE'
X.XXIstandard 2067 2070
X.XXIstdio_structs 2611 2056
X.XXIdefine 3354 2056
X.XXIdefine 3381 2056
X.XXIdefine 3407 2056
X.XXIdefine 3433 2056
X.XXIdefine 3459 2056
X.XXIdefine 3484 2056
X.XXIdefine 3510 2056
X.XXIdefine 3537 2056
X.XXIdefine 3562 2056
X.XXIdefine 3585 2056
X.XXIdefine 3605 2056
X.XXIdefine 3627 2056
X.XXIdefine 3650 2056
X.XXIdefine 3671 2056
X.XXIdefine 3695 2056
X.XXIdefine 3717 2056
X.XXIdefine 3739 2056
X.XXIdefine 3763 2056
X.XXIdefine 3787 2056
X.XXIdefine 3811 2056
X.XXIdefine 3835 2056
X.XXIdefine 3859 2056
X.XXIdefine 3883 2056
X.XXIdefine 3907 2056
X.XXIdefine 3931 2056
X.XXIdefine 3955 2056
X.XXIdefine 3979 2056
X.XXIdefine 4001 2056
X.XXIdefine 4022 2056
X.XXIdefine 4047 2056
X.XXIdefine 4071 2056
X.XXIdefine 4102 4105
X.XXIstdio_vars 4118 4483
X.XXIendwin 4492 4534
X.XXIinitscr 4544 4594
X.XXInewwin 4603 4676
X.XXIsetterm 4686 4736
X.XXIwrefresh 4747 4798
X.XXIkeypad 4807 4851
X.XXIkeypadend 4863 4913
X.XXItographic 4925 4987
X.XXIwaddgraphic 5001 2056
X.XXIdefine 5105 2056
X.XXIdefine 5122 2056
X.XXIdefine 5139 2056
X.XXIdefine 5157 2056
X.XXIdefine 5175 2056
X.XXIdefine 5193 2056
X.XXIdefine 5211 2056
X.XXIdefine 5229 2056
X.XXIdefine 5247 2056
X.XXIdefine 5265 2056
X.XXIdefine 5283 5286
X.XXIbg_bits 5296 5360
X.XXIfg_bits 5370 5434
X.XXIwsetcolor 5446 5581
X.XXIget_color 5593 5663
X.XXItgetchar 5674 5736
X.XXIprint_screen 5751 5872
X#standard
X))
X.XXT " Help With Window Oriented Screen I/O "
X.XXS "Data Structures" stdio_structs
X.XXS "Global Variables" stdio_vars
X.XXS "endwin()" endwin
X.XXS "initscr()" initscr
X.XXS "newwin()" newwin
X.XXS "setterm()" setterm
X.XXS "wrefresh()" wrefresh
X.XXS "keypad()" keypad
X.XXS "keypadend()" keypadend
X.XXS "tographic()" tographic
X.XXS "waddgraphic()" waddgraphic
X.XXS "bg_bits()" bg_bits
X.XXS "fg_bits()" fg_bits
X.XXS "wsetcolor()" wsetcolor
X.XXS "get_color()" get_color
X.XXS "tgetchar()" tgetchar
X.XXS "print_screen()" print_screen
X
X#stdio_structs
Data Structures in Scrio
typedef struct
X {
X char *str;
X int key;
X } KEY_TBL;
X
typedef struct
X {
X int ch;
X int insert;
X char *str;
X char *curr;
X char *end;
X } IN_STAT;
X
typedef struct
X {
X char ch;
X char color;
X char attrib;
X char ch_flags;
X } YX_ELEMENT;
X
typedef struct win_struct
X {
X short y_org, x_org;
X short y_max, x_max;
X short y_cur, x_cur;
X YX_ELEMENT *ch_cur;
X YX_ELEMENT *ch_first;
X YX_ELEMENT *ch_last;
X YX_ELEMENT *buf;
X short buf_len;
X short flags;
X short color;
X short attrib;
X short ch_flags;
X struct win_struct *prev, *next;
X } WINDOW;
X
X#define BOX_FLAG 0x0001
X#define SCROLL_FLAG 0x0002
X#define FLUSH_FLAG 0x0004
X#define CLEAR_FLAG 0x0008
X#define LEAVE_FLAG 0x0010
X#define NO_CHANGE 0x0020
X#define FULLWINDOW 0x0040
X#define TSTCLRTOEOL 0x0080
X#define SET_COLOR 0x0100
X
X#define BLACK 0x0000
X#define RED 0x0001
X#define GREEN 0x0002
X#define YELLOW 0x0003
X#define BLUE 0x0004
X#define MAGENTA 0x0005
X#define CYAN 0x0006
X#define WHITE 0x0007
X#define COLOR_8 0x0008
X#define COLOR_9 0x0009
X#define COLOR_10 0x000a
X#define COLOR_11 0x000b
X#define COLOR_12 0x000c
X#define COLOR_13 0x000d
X#define COLOR_14 0x000e
X#define COLOR_15 0x000f
X
X#define NORMAL 0x0000
X#define STANDOUT 0x0001
X#define BLINK 0x0002
X#define BOLD 0x0004
X#define UNDERLINE 0x0008
X#define GRAPHIC 0x0010
X
X#define REVERSED_COLOR 0x0001
X))
X
X#stdio_vars
Global Variables in Scrio
char *BC, PC, *UP;
char *Def_term, ttytype[30];
int My_term;
int LINES, COLS;
int have_standout, have_blink, have_bold, have_underline;
int have_color, have_graphic, rev_color;
int def_fg, def_bg;
short ospeed;
TERMIO _tty, _stty;
int _tty_ch;
WINDOW *stdscr, *curscr;
KEY_TBL key_tbl[];
int key_tbl_index;
X))
X
X#endwin
Help With Function endwin
int endwin()
X))
X
X#initscr
Help With Function initscr()
WINDOW *initscr()
X))
X
X#newwin
Help With Function newwin()
WINDOW *newwin(lines, cols, y_org, x_org)
X))
X
X#setterm
Help With Function setterm()
int setterm(name)
X))
X
X#wrefresh
Help With Function wrefresh()
int wrefresh(win)
X))
X
X#keypad
Help With Function keypad()
int keypad()
X))
X
X#keypadend
Help With Function keypadend()
int keypadend()
X))
X
X#tographic
Help With Function tographic()
int tographic(ch)
X int ch;
X))
X
X#waddgraphic
Help With Function waddgraphic()
int waddgraphic(win, ch)
X WINDOW *win;
X int ch;
X
X#define G_H 'A'
X#define G_V 'B'
X#define G_C 'C'
X#define G_UL 'D'
X#define G_DT 'E'
X#define G_UR 'F'
X#define G_LT 'G'
X#define G_LR 'H'
X#define G_UT 'I'
X#define G_LL 'J'
X#define G_RT 'K'
X))
X
X#bg_bits
Help With Function fg_bits()
int fg_bits(color)
X int color;
X))
X
X#fg_bits
Help With Function bg_bits()
int bg_bits(color)
X int color;
X))
X
X#wsetcolor
Help With Function wsetcolor()
int wsetcolor(win, foreground, background)
X WINDOW *win;
X int foreground;
X int background;
X))
X
X#get_color
Help With Function get_color()
int get_color(color)
X char *color;
X))
X
X#tgetchar
Help With Function tgetchar()
int tgetchar(id)
X char *id;
X))
X
X#print_screen
Help With Function print_screen()
int print_screen(parm_printer, parm_file)
X char *parm_printer;
X char *parm_file;
X
X))
X
END_OF_FILE
if test 5873 -ne `wc -c <'help/scrio.hlp'`; then
echo shar: \"'help/scrio.hlp'\" unpacked with wrong size!
fi
# end of 'help/scrio.hlp'
fi
if test -f 'hindex.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'hindex.c'\"
else
echo shar: Extracting \"'hindex.c'\" \(5624 characters\)
sed "s/^X//" >'hindex.c' <<'END_OF_FILE'
X/* program help index */
X
X/*
X "indexes" a text file for fseek()
X intended for screen help files
X format :
X .XXIsection position_start position_end
X where section is the help section name and position is a long
X position in the help file to seek to for that position. Position_start
X is the first char on the line after the section name, "#section_name".
X Position_end is the first char on the line after the end section mark, "))".
X All indexes are at the head of the file and begin with '.XXI'
X any line not beginning with '.XXI' says that the index is complete.
X*/
X
X/*
X created May 6, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X
X#include <km/defs.h>
X#include <km/string1.h>
X
X#ifdef DOS
X#include <io.h>
X#endif
X
X#define NUM_NODES 200
X#ifdef UNIX
X#define TEMP "temp.XXXXXX"
X#endif
X
typedef struct
X {
X char *name;
X long offset_start;
X long offset_end;
X } NODE;
X
extern char *malloc();
extern char *mktemp();
X
void error(message1, message2)
X char *message1;
X char *message2;
X{
X fprintf(stderr, "%s %s\n", message1, message2);
X exit(1);
X}
X
void hindex()
X{
X int i, c, in_section;
X int in_index = TRUE;
X char buf[NUM_NODES], *p;
X char ifn[20];
X long offset;
X FILE *ifd;
X NODE node[200], *np;
X
X#ifdef DOS
X strcpy(ifn, "temp.001");
X#else
X strcpy(ifn, TEMP);
X mktemp(ifn);
X#endif
X if ((ifd = fopen(ifn, "w")) == NULL) /* open intermediate file for write */
X error("can't open intermediate file for writing", ifn);
X i = 0; /* initialize variables */
X offset = 0;
X in_section = FALSE;
X while (fgets(buf, sizeof(buf), stdin) != NULL) /* read a line */
X {
X if (in_index)
X {
X if (substr(buf, ".XXI", FALSE)) /* have an index mark? */
X#ifdef DOS
X offset += (strlen(buf) + 1); /* count length of existing index */
X#else
X offset += strlen(buf); /* count length of existing index */
X#endif
X else
X in_index = FALSE; /* not in index any more */
X }
X if (*buf == '#') /* have a section start mark? */
X {
X if (in_section)
X {
X in_section = FALSE;
X node[i].offset_end = UNDETERMINED;
X i++;
X if (i >= NUM_NODES - 1)
X error("too many sections in help file to index on", "");
X }
X in_section = TRUE;
X p = buf + 1;
X while (*p) /* delimit section name */
X {
X if (isspace(*p))
X {
X c = *p; /* save delimited character */
X *p = '\0';
X break;
X }
X p++;
X }
X if ((node[i].name = malloc(strlen(buf + 1) + 1)) == NULL)
X error("no memory for section names", "");
X strcpy(node[i].name, buf + 1);
X *p = c; /* restore delimited character */
X node[i].offset_start = ftell(stdin) - offset;
X }
X else if (in_section && substr(buf, "))", FALSE)) /* have a section end mark? */
X {
X in_section = FALSE;
X node[i].offset_end = ftell(stdin) - offset;
X i++;
X if (i >= NUM_NODES - 1)
X error("too many sections in help file to index on", "");
X }
X if (!in_index) /* copy line to intermediate file */
X fputs(buf, ifd);
X }
X node[i].name = NULL; /* mark end of node list */
X fclose(ifd); /* close intermediate file */
X if ((ifd = fopen(ifn, "r")) == NULL) /* reopen for reading */
X error("can't open intermediate file for reading", ifn);
X
X/*
X count up the total extra offset due to the indexes in the output file
X each node has a 11 char field for offset_start, 11 for offset_end,
X strlen(name), and the 5 chars for ".XXI" which is 4 and the "\n" which
X makes 5. The 11 char fields for offsets allows a 10 digit offset to go
X to 2 billion, which is the max positive long value, and a delimiting space.
X*/
X
X offset = 0;
X np = node; /* go to first node */
X while (np->name)
X {
X#ifdef DOS
X offset += strlen(np->name) + 6 + 11 + 11;
X#else
X offset += strlen(np->name) + 5 + 11 + 11;
X#endif
X np++;
X }
X np = node; /* go to first node */
X while (np->name)
X {
X fprintf(stdout, ".XXI%s%11ld%11ld\n", np->name, (np->offset_start + offset), (np->offset_end + offset));
X free(np->name);
X np++;
X }
X while (fgets(buf, sizeof(buf), ifd) != NULL) /* copy rest of file */
X fputs(buf, stdout); /* to stdout */
X fclose(ifd);
X if (unlink(ifn) == ERROR) /* delete intermediate file */
X error("can't delete intermediate file", ifn);
X}
X
main(argc, argv)
X int argc;
X char *argv[];
X{
X int i;
X char ofn[20];
X
X if (argc < 2)
X hindex();
X else
X {
X for (i = 1; i < argc; i++)
X {
X#ifdef DOS
X strcpy(ofn, "temp.002");
X#else
X strcpy(ofn, TEMP);
X mktemp(ofn);
X#endif
X if (freopen(argv[i], "r", stdin) == NULL)
X error("can't open input file", argv[i]);
X if (freopen(ofn, "w", stdout) == NULL)
X error("can't open temporary file", ofn);
X hindex();
X fclose(stdin);
X fclose(stdout);
X if (unlink(argv[i]) == ERROR)
X error("can't delete old file", argv[i]);
X#ifdef DOS
X if (rename(ofn, argv[i]) == ERROR)
X error("can't rename temporary file", ofn);
X#else
X if (link(ofn, argv[i]) == ERROR)
X error("can't rename temporary file", ofn);
X if (unlink(ofn) == ERROR)
X error("can't delete temporary file", ofn);
X#endif
X }
X }
X exit(0);
X}
X
END_OF_FILE
if test 5624 -ne `wc -c <'hindex.c'`; then
echo shar: \"'hindex.c'\" unpacked with wrong size!
fi
# end of 'hindex.c'
fi
if test -f 'include/km/monitor.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'include/km/monitor.h'\"
else
echo shar: Extracting \"'include/km/monitor.h'\" \(4145 characters\)
sed "s/^X//" >'include/km/monitor.h' <<'END_OF_FILE'
X/* Include file for monitor program */
X
X/*
X Created April 14, 1988 by JCT
X*/
X
X#include <sys/sysmacros.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/param.h>
X#include <sys/times.h>
X#include <sys/dir.h>
X#include <sys/signal.h>
X#include <sys/sysinfo.h>
X#include <sys/proc.h>
X#include <sys/user.h>
X#include <sys/text.h>
X#include <sys/file.h>
X#include <sys/inode.h>
X#include <sys/var.h>
X#include <sys/map.h>
X#include <sys/utsname.h>
X
X#if SYSV /* must come after km/defs.h */
X#include <sys/gdisk.h>
X#undef winch
X#include <sys/elog.h>
X#endif
X
X#define COL_1 2
X#define COL_2 42
X#define LINE_1 2
X#define LINE_2 9
X#define LINE_3 16
X#define PROMPT " Press (Q)uit, (T)op or <SPACE> to backup "
X
X#define SPTR_TEXT 0
X#define SPTR_MAPENT 1
X#define SPTR_FILE 2
X#define SPTR_INODE 3
X#define SPTR_PROC 4
X
typedef struct
X {
X int what;
X union
X {
X char *ptr;
X struct text *text;
X struct mapent *mapent;
X struct file *file;
X struct inode *inode;
X struct proc *proc;
X } where;
X } SPTR;
X
typedef struct
X {
X long sysinfo;
X long swplo;
X long proc;
X long text;
X long file;
X long inode;
X long user;
X long v;
X long lbolt;
X long hz;
X long timezone;
X long dstflag;
X long utsname;
X#if XENIX
X long coremap;
X long mapent;
X long end;
X long mem;
X#endif
X#if SYSV
X long gdstat;
X#endif
X } OFFSETS;
X
extern int all_procs, sample_interval;
extern int kfd, sfd, mfd, ufd, mode, uid, gid, proc_size;
extern int file_size, text_size, inode_size;
X#if XENIX
extern int mapent_size;
X#endif
extern long lr_limit, lw_limit, si_limit, so_limit;
extern long rc_limit, wc_limit, rt_limit, wt_limit;
extern long ri_limit, wi_limit, ps_limit;
extern long ni_limit, db_limit, sc_limit, ig_limit;
extern long of_limit, tx_limit, pr_limit, in_limit;
extern long nfile, ntext, ninode, nproc;
X#if XENIX
extern long fm_limit;
extern long free_mem, free_max[];
extern int free_wait;
X#else
extern long sr_limit, sw_limit, sf_limit, se_limit;
extern long rq_limit, sq_limit, sm_limit, mg_limit;
extern long aq_limit, as_limit, aw_limit, bc_limit;
X#endif
X#if SYSV
extern long idle_usage;
X#endif
extern OFFSETS offsets;
extern long cpu_total;
extern long last_time, new_time, llast_time, time_interval;
extern long lbolt, boot_time, curr_time;
extern char name_buf[], *name_ptr, *proc_name, boot_when[];
extern int hz, tz, dstflag;
extern struct utsname utsname;
extern daddr_t swplo;
extern struct tms tbuf;
extern struct sysinfo si_last, si_new, si_llast;
extern struct var v_buf;
extern struct user user_last, user_new, user_llast;
X#if XENIX
extern struct map coremap;
X#endif
extern SPTR sptr;
extern struct proc *proc_buf;
extern struct file *file_buf;
X#if SYSV
extern int disk;
extern struct iotime io_last [DISKS], io_new [DISKS], io_llast [DISKS];
extern SCR disk_menu;
X#endif
extern SCR main_menu;
extern SCR mode_scr;
X
X/*
X Declare external user functions
X*/
X
extern void chart_top();
extern void plot_top();
extern void put_scale();
extern void put_chart();
extern void chart_absolute();
extern void chart_capacity();
extern void chart_percent();
extern void bar_plot();
extern void bar_percent();
extern int rescale();
extern void bar_persec();
extern void bar_absolute();
extern void plot_CPU();
extern void plot_disk();
extern void plot_IO();
extern void plot_misc();
extern void plot_capacity();
X#if SYSV
extern void plot_scall();
extern void plot_HD();
extern void plot_IPC();
X#endif
extern int plot_data();
extern void set_mode();
extern int mode_CPU();
extern int mode_disk();
extern int mode_IO();
extern int mode_misc();
extern int mode_capacity();
X#if SYSV
extern int mode_scall();
extern int do_disk();
extern int mode_HD();
extern int mode_IPC();
X#endif
extern int mode_proc();
extern int mode_top();
extern int mode_config();
extern int top_chk();
extern int get_interval();
X
END_OF_FILE
if test 4145 -ne `wc -c <'include/km/monitor.h'`; then
echo shar: \"'include/km/monitor.h'\" unpacked with wrong size!
fi
# end of 'include/km/monitor.h'
fi
if test -f 'include/km/scrops.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'include/km/scrops.h'\"
else
echo shar: Extracting \"'include/km/scrops.h'\" \(2846 characters\)
sed "s/^X//" >'include/km/scrops.h' <<'END_OF_FILE'
X/* scrops.h */
X
X/*
X Contains definitions used for library screen functions found
X in scrops.c
X*/
X
X/*
X Created February 11, 1986 by JCT
X*/
X
X/*
X The following are flag bits for screen flags, 16 bits available
X*/
X
X#define SCR_TYPE_AHEAD 0x0001
X#define SCR_MENU 0x0002
X#define SCR_NO_ERASE 0x0004
X#define SCR_NUMERIC 0x0008
X#define SCR_RAW 0x0010
X#define SCR_HELP_LOOP 0x0020
X#define SCR_NO_REFRESH 0x0040
X#define SCR_NO_INI 0x0100
X#define SCR_FORCE_COLOR 0x0200
X#define SCR_MRING 0x0800
X#define SCR_MPOPUP 0x1000
X#define SCR_MPULLDOWN 0x2000
X#define SCR_NO_HELP 0x4000
X#define SCR_NO_PROMPT 0x8000
X
X/*
X The following are flags for SCR_ENTRYs, 16 available
X*/
X
X#define SCR_PICK 0x0080
X#define SCR_NPARM 0x0100
X#define SCR_PPARM 0x0200
X#define SCR_PUT_ACTIVE 0x0400
X
X/*
X The following are flag bits for local processing
X The programmer normally doesn't worry about these
X 16 bits available.
X*/
X
X#define SCR_UP 0x0001
X#define SCR_HAVE_KEY 0x0002
X#define SCR_DISPLAY 0x0004
X#define SCR_SETKEYS 0x0008
X#define SCR_QUIT 0x0010
X
X/*
X Misc.
X*/
X
X#define INIT_LINE 3
X
typedef struct
X {
X short key;
X char *text;
X int (*func)();
X int number;
X char *pointer;
X char *help_section;
X short flags;
X short color;
X } SCR_ENTRY;
X
typedef struct
X {
X WINDOW *win;
X char *head;
X int (*func_entry)();
X int (*func_loop)();
X int (*func_chk)();
X char *prompt;
X SCR_ENTRY *entry;
X SCR_ENTRY *active_entry;
X SCR_ENTRY *last_active;
X short timeout;
X char *help_file;
X char *help_section;
X short flags;
X short lflags;
X short color;
X } SCR;
X
extern int scr_quit, scr_main, scr_backup, scr_repeat, menu_column;
extern int scr_key_curr, scr_level;
extern int msg_line, msg_column, help_fg, help_bg;
X
extern int setup();
extern int setdown();
extern int wcenter();
extern int wput_str();
extern int wput_fstr();
extern int wput_msg();
extern int wput_int();
extern int wput_time();
extern int wput_date();
extern int wput_when();
extern int wput_head();
extern int wput_prompt();
extern int put_entry();
extern int do_process();
extern int put_scr();
extern int check_key();
extern int do_scr();
extern int do_active_entry();
X
X#define center(s) wcenter(stdscr,s)
X#define put_str(l,c,msg,mode) wput_str(stdscr,l,c,msg,mode)
X#define putf_str(l,c,msg,mode) wputf_str(stdscr,l,c,msg,mode)
X#define put_msg(m) wput_msg(stdscr,m)
X#define put_int(l,c,n,p,h) wput_int(stdscr,l,c,n,p,h)
X#define put_time(l,c,w,f,h) wput_time(stdscr,l,c,w,f,h)
X#define put_date(l,c,w,f,h) wput_date(stdscr,l,c,w,f,h)
X#define put_when(l,c,w,f,h) wput_when(stdscr,l,c,w,f,h)
X#define put_head(h) wput_head(stdscr,h)
X#define put_prompt(m) wput_prompt(stdscr,m)
X#define do_help(f,s,g) wdo_help(stdscr,f,s,g)
END_OF_FILE
if test 2846 -ne `wc -c <'include/km/scrops.h'`; then
echo shar: \"'include/km/scrops.h'\" unpacked with wrong size!
fi
# end of 'include/km/scrops.h'
fi
if test -f 'lib/docmd.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/docmd.c'\"
else
echo shar: Extracting \"'lib/docmd.c'\" \(3903 characters\)
sed "s/^X//" >'lib/docmd.c' <<'END_OF_FILE'
X/* Module do command */
X
X/*
X executes the UNIX command passed to it
X returns TRUE if command started (fork succedded), FALSE otherwise
X if wait, waits for command (child process) to end
X stores result in int pointed to by result only if returns TRUE and
X result pointer is non-zero
X 0x0000 - no wait
X 0x01ss - child stopped (see ptrace(2)), ss is signal #
X 0x02ss - child exited normally, ss is exit status
X 0x04ss - child exited due to receiving signal, ss is signal #
X 0x0800 - wait failed
X if returns FALSE, *result unchanged
X*/
X
X/*
X Created January 16, 1985 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#define BUF_SIZE 100
X#define ARGV_SIZE 10
X
X#include <stdio.h>
X#include <ctype.h>
X
X#include <km/defs.h>
X
X#ifdef DOS
X#include <process.h>
X#else
X#include <signal.h>
X#endif
X
extern int (*signal())();
extern void exit();
extern char *strncpy();
X
int do_command(what, want_wait, result)
X char *what;
X int want_wait;
X int *result;
X{
X int pid, index = 0, status, res, stat, in_quote = FALSE;
X int (*del)(), (*quit)();
X char buf[BUF_SIZE];
X char *argv[ARGV_SIZE];
X
X what = strncpy(buf, what, BUF_SIZE);
X buf[BUF_SIZE - 1] = '\0';
X while ((*what) && (index < ARGV_SIZE)) /* process command arguments */
X {
X while (isspace(*what))
X what++;
X if (*what == '\'')
X {
X in_quote = TRUE;
X what++;
X }
X argv[index++] = what;
X while ((*what) && (in_quote || !isspace(*what)))
X {
X if (*what == '\'')
X {
X in_quote = FALSE;
X *what = ' ';
X }
X else
X what++;
X }
X if (*what)
X {
X *what = '\0';
X what++;
X }
X }
X argv[index] = (char*)0;
X#ifdef DOS
X if ((status = spawnvp(P_WAIT, argv[0], argv)) == ERROR)
X {
X stat = FALSE;
X res = 0x0800;
X }
X else
X {
X stat = TRUE;
X res = ((status & 0x00ff) | 0x0200);
X }
X#else
X del = signal(SIGINT,SIG_IGN); /* ignore signals so that parent */
X quit = signal(SIGQUIT,SIG_IGN); /* is not terminated by child */
X switch (pid = fork())
X {
X case 0 : signal(SIGINT, del); /* child process */
X signal(SIGQUIT, quit); /* reset child signals */
X execv(argv[0], argv); /* do the command */
X exit(0x0040); /* in case exec fails */
X stat = FALSE; /* just to be consistant */
X break;
X case -1 : stat = FALSE; /* fork failed */
X break;
X default : if (want_wait) /* parent process */
X {
X if (wait(&status) == pid)
X {
X status &= 0xffff;
X if ((status & 0x00ff) == 0x00ff) /* child stopped */
X res = ((status >> 8) | 0x0100); /* return signal # (high order 8 bits) */
X else if ((status & 0x00ff) == 0x0000) /* child exited */
X res = ((status >> 8) | 0x0200); /* return exit code (high order 8 bits) */
X else /* child terminated */
X res = ((status & 0x00ff) | 0x0400); /* return signal # (low order 8 bits) */
X }
X else
X res = 0x0800; /* wait failed */
X }
X else /* no wait */
X res = 0x0000;
X stat = TRUE;
X break;
X }
X signal(SIGINT,del); /* reset signals */
X signal(SIGQUIT,quit);
X#endif
X if (result != NULL)
X *result = res;
X return(stat);
X}
X
END_OF_FILE
if test 3903 -ne `wc -c <'lib/docmd.c'`; then
echo shar: \"'lib/docmd.c'\" unpacked with wrong size!
fi
# end of 'lib/docmd.c'
fi
if test -f 'lib/scrout3.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/scrout3.c'\"
else
echo shar: Extracting \"'lib/scrout3.c'\" \(4111 characters\)
sed "s/^X//" >'lib/scrout3.c' <<'END_OF_FILE'
X/* module screen output */
X
X/*
X provides UNIX "curses" type routines
X*/
X
X/*
X created May 5, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X
X#include <km/defs.h>
X#include <km/scrio.h>
X
char *longname(termbuf, name) /* longname from termbuf into name */
X char *termbuf;
X char *name;
X{
X char *temp;
X
X while (*termbuf)
X {
X if (*termbuf == ':')
X break;
X if (*termbuf == '|')
X break;
X termbuf++;
X }
X if (*termbuf == '|')
X {
X termbuf++;
X temp = termbuf;
X while (*temp)
X {
X if (*temp == ':')
X break;
X if (*temp == '|')
X break;
X temp++;
X }
X *temp = '\0';
X return(termbuf);
X }
X else
X return(name);
X}
X
int wmvcur(win, y_last, x_last, y_new, x_new) /* move cursor */
X WINDOW *win;
X int y_last;
X int x_last;
X int y_new;
X int x_new;
X{
X YX_ELEMENT *first, *last;
X
X if (win->flags & BOX_FLAG)
X {
X if ((x_new >= (win->x_max - 1)) || (y_new >= (win->y_max - 1)) ||
X (x_new < 1) || (y_new < 1) ||
X (x_last >= (win->x_max - 1)) || (y_last >= (win->y_max - 1)) ||
X (x_last < 1) || (y_last < 1))
X return(FALSE);
X }
X else
X {
X if ((x_new >= win->x_max) || (y_new >= win->y_max) ||
X (x_new < 0) || (y_new < 0) ||
X (x_last >= win->x_max) || (y_last >= win->y_max) ||
X (x_last < 0) || (y_last < 0))
X return(FALSE);
X }
X first = win->buf + ((y_last * win->x_max) + x_last);
X last = win->buf + ((y_new * win->x_max) + x_new);
X win->ch_cur = last;
X win->x_cur = x_new;
X win->y_cur = y_new;
X if (first < win->ch_first)
X win->ch_first = first;
X if (last > win->ch_last)
X win->ch_last = last;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
WINDOW *superwin(win, on_bottom_win)
X WINDOW *win;
X WINDOW *on_bottom_win;
X{
X if (win == stdscr)
X return(WIN_NULL);
X if (on_bottom_win == WIN_NULL)
X {
X for (on_bottom_win = stdscr; on_bottom_win->next != WIN_NULL;
X on_bottom_win = on_bottom_win->next)
X ;
X }
X if (win->next)
X win->next->prev = win->prev;
X if (win->prev)
X win->prev->next = win->next;
X if (on_bottom_win->next)
X on_bottom_win->next->prev = win;
X win->prev = on_bottom_win;
X win->next = on_bottom_win->next;
X on_bottom_win->next = win;
X return (win);
X}
X
WINDOW *subwin(win, on_top_win)
X WINDOW *win;
X WINDOW *on_top_win;
X{
X if (on_top_win == stdscr)
X return(WIN_NULL);
X if (on_top_win == WIN_NULL)
X {
X if ((on_top_win = stdscr->next) == WIN_NULL)
X return(WIN_NULL);
X }
X if (win->next)
X win->next->prev = win->prev;
X if (win->prev)
X win->prev->next = win->next;
X if (on_top_win->prev)
X on_top_win->prev->next = win;
X on_top_win->prev = win;
X win->prev = on_top_win->prev;
X win->next = on_top_win;
X return(win);
X}
X
int touchwin(win) /* make window look modified */
X REGISTER WINDOW *win;
X{
X win->ch_first = win->buf;
X win->ch_last = win->buf + win->buf_len - 1;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
int winch(win) /* get char at current x,y position */
X REGISTER WINDOW *win;
X{
X return(win->ch_cur->ch);
X}
X
int wmove(win, y_new, x_new) /* move to row, col position */
X REGISTER WINDOW *win;
X REGISTER int y_new;
X REGISTER int x_new;
X{
X if (y_new == UNDETERMINED)
X y_new = win->y_cur;
X if (x_new == UNDETERMINED)
X x_new = win->x_cur;
X if (win->flags & BOX_FLAG)
X {
X if ((x_new >= (win->x_max - 1)) || (y_new >= (win->y_max - 1)) ||
X (x_new < 1) || (y_new < 1))
X return(FALSE);
X }
X else
X {
X if ((x_new >= win->x_max) || (y_new >= win->y_max) ||
X (x_new < 0) || (y_new < 0))
X return(FALSE);
X }
X win->ch_cur = win->buf + ((y_new * win->x_max) + x_new);
X win->x_cur = x_new;
X win->y_cur = y_new;
X return(TRUE);
X}
X
END_OF_FILE
if test 4111 -ne `wc -c <'lib/scrout3.c'`; then
echo shar: \"'lib/scrout3.c'\" unpacked with wrong size!
fi
# end of 'lib/scrout3.c'
fi
if test -f 'lib/scrout6.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/scrout6.c'\"
else
echo shar: Extracting \"'lib/scrout6.c'\" \(5942 characters\)
sed "s/^X//" >'lib/scrout6.c' <<'END_OF_FILE'
X/* module screen output */
X
X/*
X provides UNIX "curses" type routines
X*/
X
X/*
X created May 5, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X
X#include <km/defs.h>
X#include <km/scrio.h>
X
int wclear(win) /* clear window */
X WINDOW *win;
X{
X return(werase(win));
X}
X
int wclrtobot(win) /* clear to bottom of window */
X WINDOW *win;
X{
X REGISTER int i;
X int x;
X YX_ELEMENT buf;
X REGISTER YX_ELEMENT *ptr;
X
X buf.ch = ' ';
X if (win->ch_flags & REVERSED_COLOR)
X buf.color = (((win->color >> 4) & 0x0f) || ((win->color << 4) & 0xf0));
X else
X buf.color = win->color;
X buf.attrib = 0;
X buf.ch_flags = 0;
X ptr = win->ch_cur;
X i = win->buf_len - (win->ch_cur - win->buf);
X x = win->x_max - win->x_cur;
X if (win->flags & BOX_FLAG)
X {
X i -= (win->x_max + 1);
X x--;
X for ( ; i; )
X {
X if (x)
X {
X x--;
X *ptr++ = buf;
X i--;
X }
X else
X {
X x = win->x_max - 2;
X ptr += 2;
X i -= 2;
X }
X }
X }
X else
X {
X for ( ; i; i--)
X *ptr++ = buf;
X }
X if (win->ch_cur < win->ch_first)
X win->ch_first = win->ch_cur;
X win->ch_last = win->buf + win->buf_len - 1;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
int wclrtoeol(win) /* clear to end of line of window */
X WINDOW *win;
X{
X REGISTER int i;
X YX_ELEMENT buf, *last;
X REGISTER YX_ELEMENT *ptr;
X
X buf.ch = ' ';
X if (win->ch_flags & REVERSED_COLOR)
X buf.color = (((win->color >> 4) & 0x0f) || ((win->color << 4) & 0xf0));
X else
X buf.color = win->color;
X buf.attrib = 0;
X buf.ch_flags = 0;
X ptr = win->ch_cur;
X i = win->x_max - win->x_cur;
X if (win->flags & BOX_FLAG)
X i--;
X last = win->ch_cur + i - 1;
X for ( ; i; i--)
X *ptr++ = buf;
X if (win->ch_cur < win->ch_first)
X win->ch_first = win->ch_cur;
X if (last > win->ch_last)
X win->ch_last = last;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
int wdelch(win) /* delete current char from window */
X WINDOW *win;
X{
X int i;
X YX_ELEMENT *last;
X REGISTER YX_ELEMENT *ptr1;
X REGISTER YX_ELEMENT *ptr2;
X
X ptr1 = win->ch_cur;
X ptr2 = ptr1 + 1;
X i = win->x_max - win->x_cur - 1;
X if (win->flags & BOX_FLAG)
X i--;
X last = win->ch_cur + i + 1;
X for ( ; i; i--)
X *ptr1++ = *ptr2++;
X ptr1->ch = ' ';
X if (win->ch_flags & REVERSED_COLOR)
X ptr1->color = (((win->color >> 4) & 0x0f) || ((win->color << 4) & 0xf0));
X else
X ptr1->color = win->color;
X ptr1->attrib = 0;
X ptr1->ch_flags = 0;
X if (win->ch_cur < win->ch_first)
X win->ch_first = win->ch_cur;
X if (last > win->ch_last)
X win->ch_last = last;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
int wdeleteln(win) /* delete one line from the window */
X WINDOW *win;
X{
X int i, j, x;
X YX_ELEMENT buf, *first;
X REGISTER YX_ELEMENT *ptr1;
X REGISTER YX_ELEMENT *ptr2;
X
X buf.ch = ' ';
X if (win->ch_flags & REVERSED_COLOR)
X buf.color = (((win->color >> 4) & 0x0f) || ((win->color << 4) & 0xf0));
X else
X buf.color = win->color;
X buf.attrib = 0;
X buf.ch_flags = 0;
X ptr1 = win->ch_cur - win->x_cur;
X ptr2 = ptr1 + win->x_max;
X first = ptr1;
X i = (win->buf + win->buf_len) - first;
X j = i - win->x_max;
X if (win->flags & BOX_FLAG)
X {
X ptr1++;
X ptr2++;
X i -= (win->x_max + 2);
X j -= (win->x_max + 2);
X x = win->x_max - 2;
X for ( ; j; )
X {
X if (x)
X {
X x--;
X *ptr1++ = *ptr2++;
X i--;
X j--;
X }
X else
X {
X x = win->x_max - 2;
X ptr1 += 2;
X ptr2 += 2;
X i -= 2;
X j -= 2;
X }
X }
X ptr1 += 2;
X i -= 2;
X }
X else
X {
X for ( ; j; i--, j--)
X *ptr1++ = *ptr2++;
X }
X for ( ; i; i--)
X *ptr1++ = buf;
X if (first < win->ch_first)
X win->ch_first = first;
X win->ch_last = win->buf + win->buf_len - 1;
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
int werase(win) /* erase window */
X WINDOW *win;
X{
X REGISTER int i;
X int x;
X YX_ELEMENT buf;
X REGISTER YX_ELEMENT *ptr;
X
X#ifndef MMAPPED
X if (win == curscr)
X {
X buf.ch = 0;
X buf.color = 0;
X win->color = 0;
X }
X else
X#endif
X {
X buf.ch = ' ';
X if (win->ch_flags & REVERSED_COLOR)
X buf.color = (((win->color >> 4) & 0x0f) || ((win->color << 4) & 0xf0));
X else
X buf.color = win->color;
X }
X buf.attrib = 0;
X buf.ch_flags = 0;
X ptr = win->buf;
X i = win->buf_len;
X if (win->flags & BOX_FLAG)
X {
X ptr += (win->x_max + 1);
X i -= (win->x_max << 1);
X x = win->x_max - 2;
X for ( ; i; )
X {
X if (x)
X {
X x--;
X *ptr++ = buf;
X i--;
X }
X else
X {
X x = win->x_max - 2;
X ptr += 2;
X i -= 2;
X }
X }
X }
X else
X {
X for ( ; i; i--)
X *ptr++ = buf;
X }
X#ifndef MMAPPED
X if (win == curscr)
X {
X win->y_cur = UNDETERMINED;
X win->x_cur = UNDETERMINED;
X win->ch_cur = win->buf;
X win->ch_first = win->buf;
X win->ch_last = win->buf + win->buf_len - 1;
X }
X else
X#endif
X {
X if (win->flags & BOX_FLAG)
X {
X win->y_cur = 1;
X win->x_cur = 1;
X win->ch_cur = win->buf + win->x_max + 1;
X win->ch_first = win->buf;
X win->ch_last = win->buf + win->buf_len - 1;
X }
X else
X {
X win->y_cur = 0;
X win->x_cur = 0;
X win->ch_cur = win->buf;
X win->ch_first = win->buf;
X win->ch_last = win->buf + win->buf_len - 1;
X }
X }
X win->flags &= ~NO_CHANGE;
X return(TRUE);
X}
X
END_OF_FILE
if test 5942 -ne `wc -c <'lib/scrout6.c'`; then
echo shar: \"'lib/scrout6.c'\" unpacked with wrong size!
fi
# end of 'lib/scrout6.c'
fi
if test -f 'lib/scrout9.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/scrout9.c'\"
else
echo shar: Extracting \"'lib/scrout9.c'\" \(4337 characters\)
sed "s/^X//" >'lib/scrout9.c' <<'END_OF_FILE'
X/* module screen output */
X
X/*
X provides UNIX "curses" type routines
X*/
X
X/*
X created May 5, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X
X#include <km/defs.h>
X#include <km/ascii.h>
X#include <km/scrio.h>
X
int wstandend(win) /* clear standout mode on a window */
X REGISTER WINDOW *win;
X{
X return(wclrattrib(win, STANDOUT));
X}
X
int wstandout(win) /* set standout mode on a window */
X REGISTER WINDOW *win;
X{
X return(waddattrib(win, STANDOUT));
X}
X
int winattrib(win)
X REGISTER WINDOW *win; /* get attributes of current char */
X{
X return(win->buf[(win->y_cur * win->x_max) + win->x_cur].attrib);
X}
X
int wincolor(win)
X REGISTER WINDOW *win; /* get color of current char */
X{
X return(win->buf[(win->y_cur * win->x_max) + win->x_cur].color);
X}
X
int wendattrib(win) /* clear all window attributes */
X REGISTER WINDOW *win;
X{
X if (win->attrib)
X {
X if (win->ch_flags & REVERSED_COLOR)
X {
X wsetcolor(win, win->color & 0x0f, (win->color >> 4) & 0x0f);
X win->ch_flags &= ~REVERSED_COLOR;
X }
X win->attrib = 0;
X return(TRUE);
X }
X else
X return(FALSE);
X}
X
int wclrattrib(win, attrib) /* clear specific attribute */
X REGISTER WINDOW *win;
X REGISTER int attrib;
X{
X if (win->attrib & attrib)
X {
X if ((attrib & STANDOUT) && (win->ch_flags & REVERSED_COLOR))
X {
X wsetcolor(win, win->color & 0x0f, (win->color >> 4) & 0x0f);
X win->ch_flags &= ~REVERSED_COLOR;
X }
X win->attrib &= ~attrib;
X return(TRUE);
X }
X return(FALSE);
X}
X
int wsetattrib(win, attrib) /* set window attribute */
X REGISTER WINDOW *win;
X REGISTER int attrib;
X{
X int new_attrib = 0, new_ch_flags = 0, stat = TRUE;
X
X if (attrib & STANDOUT)
X {
X if (have_standout)
X {
X if (rev_color && (win->color))
X new_ch_flags |= REVERSED_COLOR;
X new_attrib |= STANDOUT;
X }
X else
X stat = FALSE;
X }
X if (attrib & BLINK)
X {
X if (have_blink)
X new_attrib |= BLINK;
X else
X stat = FALSE;
X }
X if (attrib & BOLD)
X {
X if (have_bold)
X new_attrib |= BOLD;
X else
X stat = FALSE;
X }
X if (attrib & UNDERLINE)
X {
X if (have_underline)
X new_attrib |= UNDERLINE;
X else
X stat = FALSE;
X }
X if (attrib & GRAPHIC)
X {
X if (have_graphic)
X new_attrib |= GRAPHIC;
X else
X stat = FALSE;
X }
X if (stat)
X {
X if ((new_ch_flags & REVERSED_COLOR) && !(win->ch_flags & REVERSED_COLOR))
X wsetcolor(win, win->color & 0x0f, (win->color >> 4) & 0x0f);
X else if (!(new_attrib & STANDOUT) && (win->ch_flags & REVERSED_COLOR))
X {
X wsetcolor(win, win->color & 0x0f, (win->color >> 4) & 0x0f);
X win->ch_flags &= ~REVERSED_COLOR;
X }
X win->attrib = new_attrib;
X win->ch_flags |= new_ch_flags;
X }
X return(stat);
X}
X
int waddattrib(win, attrib) /* add window attribute */
X REGISTER WINDOW *win;
X REGISTER int attrib;
X{
X int new_attrib = 0, new_ch_flags = 0, stat = TRUE;
X
X if (attrib & STANDOUT)
X {
X if (have_standout)
X {
X if (rev_color && (win->color))
X new_ch_flags |= REVERSED_COLOR;
X new_attrib |= STANDOUT;
X }
X else
X stat = FALSE;
X }
X if (attrib & BLINK)
X {
X if (have_blink)
X new_attrib |= BLINK;
X else
X stat = FALSE;
X }
X if (attrib & BOLD)
X {
X if (have_bold)
X new_attrib |= BOLD;
X else
X stat = FALSE;
X }
X if (attrib & UNDERLINE)
X {
X if (have_underline)
X new_attrib |= UNDERLINE;
X else
X stat = FALSE;
X }
X if (attrib & GRAPHIC)
X {
X if (have_graphic)
X new_attrib |= GRAPHIC;
X else
X stat = FALSE;
X }
X if (stat)
X {
X if ((new_ch_flags & REVERSED_COLOR) && !(win->ch_flags & REVERSED_COLOR))
X wsetcolor(win, win->color & 0x0f, (win->color >> 4) & 0x0f);
X win->attrib |= new_attrib;
X win->ch_flags |= new_ch_flags;
X }
X return(stat);
X}
X
END_OF_FILE
if test 4337 -ne `wc -c <'lib/scrout9.c'`; then
echo shar: \"'lib/scrout9.c'\" unpacked with wrong size!
fi
# end of 'lib/scrout9.c'
fi
if test -f 'lib/string1.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/string1.c'\"
else
echo shar: Extracting \"'lib/string1.c'\" \(5136 characters\)
sed "s/^X//" >'lib/string1.c' <<'END_OF_FILE'
X/* Module string operations */
X
X/*
X Preforms functions to find the end of a string, test for string equality
X insert an integer into a string, preform upper or lower case string
X conversions, fill strings and reverse strings.
X*/
X
X/*
X Created January 31, 1986 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X
X#include <km/defs.h>
X
char *strend (string)
X REGISTER char *string;
X{
X while (*string++)
X ;
X return (--string);
X}
X
int streq (s1, s2, ignore_case)
X REGISTER char *s1;
X REGISTER char *s2;
X int ignore_case;
X{
X if (*s1 && *s2)
X {
X if (ignore_case)
X {
X while (*s1 && (tolower (*s1) == tolower (*s2)))
X {
X s1++;
X s2++;
X }
X }
X else
X {
X while (*s1 && (*s1 == *s2))
X {
X s1++;
X s2++;
X }
X }
X if ((*s1 == '\0') && (*s2 == '\0'))
X return (TRUE);
X }
X return (FALSE);
X}
X
int strneq (s1, s2, n, ignore_case)
X REGISTER char *s1;
X REGISTER char *s2;
X int n;
X int ignore_case;
X{
X if (n == 0)
X return (TRUE);
X if (*s1 && *s2)
X {
X if (ignore_case)
X {
X while (n && *s1 && (tolower (*s1) == tolower (*s2)))
X {
X s1++;
X s2++;
X n--;
X }
X }
X else
X {
X while (n && *s1 && (*s1 == *s2))
X {
X s1++;
X s2++;
X n--;
X }
X }
X if ((n == 0) || ((*s1 == '\0') && (*s2 == '\0')))
X return (TRUE);
X }
X return (FALSE);
X}
X
int substr (s1, s2, ignore_case)
X REGISTER char *s1;
X REGISTER char *s2;
X int ignore_case;
X{
X if (*s1 && *s2)
X {
X if (ignore_case)
X {
X while (*s1 && (tolower (*s1) == tolower (*s2)))
X {
X s1++;
X s2++;
X }
X }
X else
X {
X while (*s1 && (*s1 == *s2))
X {
X s1++;
X s2++;
X }
X }
X if (*s2 == '\0')
X return (TRUE);
X }
X return (FALSE);
X}
X
char *strpos (s1, s2, ignore_case)
X REGISTER char *s1;
X REGISTER char *s2;
X int ignore_case;
X{
X char *start, *save_s2;;
X
X if (!s1 || !s2)
X return(NULL);
X save_s2 = s2;
X if (ignore_case)
X {
X while (*s1)
X {
X while (*s1 && (tolower (*s1) != tolower (*s2)))
X s1++;
X start = s1;
X while (*s1 && (tolower (*s1) == tolower (*s2)))
X {
X s1++;
X s2++;
X }
X if (*s2 == '\0')
X return (start);
X s1 = start;
X s2 = save_s2;
X }
X }
X else
X {
X while (*s1)
X {
X while (*s1 && (*s1 != *s2))
X s1++;
X start = s1;
X while (*s1 && (*s1 == *s2))
X {
X s1++;
X s2++;
X }
X if (*s2 == '\0')
X return (start);
X s1 = start;
X s2 = save_s2;
X }
X }
X return (NULL);
X}
X
char *strint (dest, number, places, pad)
X char *dest;
X int number;
X int places;
X int pad;
X{
X char sdata[20], *save_ptr;
X int neg, index = 0;
X
X save_ptr = dest;
X if (neg = (number < 0))
X number = -number;
X do
X {
X sdata [index++] = number % 10 + '0';
X places--;
X }
X while ((number /= 10) > 0);
X if (neg)
X sdata [index++] = '-';
X if (pad > 0)
X {
X while (places-- > 0)
X sdata [index++] = (char) pad;
X }
X while (index > 0)
X *dest++ = sdata [--index];
X *dest = '\0';
X return (save_ptr);
X}
X
char *strupr (s)
X REGISTER char *s;
X{
X char *d;
X
X d = s;
X while (*s)
X {
X *s = toupper (*s);
X s++;
X }
X return (d);
X}
X
char *strlwr (s)
X REGISTER char *s;
X{
X char *d;
X
X d = s;
X while (*s)
X {
X *s = tolower (*s);
X s++;
X }
X return (d);
X}
X
char *strset (s, c)
X REGISTER char *s;
X REGISTER char c;
X{
X char *d;
X
X d = s;
X while (*s)
X *s++ = c;
X return (d);
X}
X
char *strnset(s, c, n)
X REGISTER char *s;
X REGISTER char c;
X int n;
X{
X char *d;
X
X d = s;
X while ((n-- > 0) && *s)
X *s++ = c;
X return (d);
X}
X
char *strrev (s)
X REGISTER char *s;
X{
X char *d, *r, c;
X
X d = s;
X r = s;
X while (*d)
X d++;
X d--;
X while (s < d)
X {
X c = *s;
X *s++ = *d;
X *d-- = c;
X }
X return (r);
X}
X
char *strleft (s)
X REGISTER char *s;
X{
X char *t, *d;
X
X t = s;
X d = s;
X while (isspace (*t))
X t++;
X while (*s = *t);
X return (d);
X}
X
char *strpad (s, c, n)
X REGISTER char *s;
X REGISTER char c;
X int n;
X{
X char *temp;
X
X while (n--)
X *s++ = c;
X return (temp);
X}
X
char *basename (s)
X REGISTER char *s;
X{
X REGISTER char *temp;
X
X temp = s;
X while (*s)
X {
X if (*s == '/')
X temp = s + 1;
X s++;
X }
X return (temp);
X}
X
END_OF_FILE
if test 5136 -ne `wc -c <'lib/string1.c'`; then
echo shar: \"'lib/string1.c'\" unpacked with wrong size!
fi
# end of 'lib/string1.c'
fi
if test -f 'lib/string2.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/string2.c'\"
else
echo shar: Extracting \"'lib/string2.c'\" \(2995 characters\)
sed "s/^X//" >'lib/string2.c' <<'END_OF_FILE'
X/* Module string date operation, UNIX specific */
X
X/*
X Provides UNIX specific functions to convert time and date into strings
X*/
X
X/*
X Created February 1, 1986 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <time.h>
X#include <string.h>
X
X#include <km/string1.h>
X#include <km/string2.h>
X
extern struct tm *localtime();
X
char *strdate(dest, when, format)
X char *dest;
X long when;
X int format;
X{
X int length;
X struct tm *atime;
X
X atime = localtime(&when);
X if (format & DATE_NUMERIC)
X {
X sprintf(dest, "%d/%d/", (atime->tm_mon + 1), atime->tm_mday);
X strint(strend(dest), atime->tm_year, 2, '0');
X }
X else
X {
X if (format & DATE_LONG)
X length = 99;
X else
X length = 3;
X switch (atime->tm_wday)
X {
X case 0 : strncpy(dest, "Sunday", length); break;
X case 1 : strncpy(dest, "Monday", length); break;
X case 2 : strncpy(dest, "Tuesday", length); break;
X case 3 : strncpy(dest, "Wednesday", length); break;
X case 4 : strncpy(dest, "Thursday", length); break;
X case 5 : strncpy(dest, "Friday", length); break;
X case 6 : strncpy(dest, "Saturday", length); break;
X }
X if (!(format & DATE_LONG))
X dest[3] = '\0';
X strcat(dest, ", ");
X switch (atime->tm_mon)
X {
X case 0 : strncat(dest, "January", length); break;
X case 1 : strncat(dest, "February", length); break;
X case 2 : strncat(dest, "March", length); break;
X case 3 : strncat(dest, "April", length); break;
X case 4 : strncat(dest, "May", length); break;
X case 5 : strncat(dest, "June", length); break;
X case 6 : strncat(dest, "July", length); break;
X case 7 : strncat(dest, "August", length); break;
X case 8 : strncat(dest, "September", length); break;
X case 9 : strncat(dest, "October", length); break;
X case 10 : strncat(dest, "November", length); break;
X case 11 : strncat(dest, "December", length); break;
X }
X if (!(format & DATE_LONG))
X dest[8] = '\0';
X strint(strend(dest), atime->tm_mday, 3, ' ');
X strcat(dest, ", 19");
X strint(strend(dest), atime->tm_year, 2, '0');
X }
X return(dest);
X}
X
char *strtime(dest, when, format)
X char *dest;
X long when;
X int format;
X{
X struct tm *atime;
X
X atime = localtime(&when);
X strint(dest, atime->tm_hour, 2, '0');
X strcat(dest, ":");
X strint(strend(dest), atime->tm_min, 2, '0');
X if (format & TIME_SECONDS)
X {
X strcat(dest, ":");
X strint(strend(dest), atime->tm_sec, 2, '0');
X }
X return(dest);
X}
X
END_OF_FILE
if test 2995 -ne `wc -c <'lib/string2.c'`; then
echo shar: \"'lib/string2.c'\" unpacked with wrong size!
fi
# end of 'lib/string2.c'
fi
if test -f 'lib/tgoto.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/tgoto.c'\"
else
echo shar: Extracting \"'lib/tgoto.c'\" \(2859 characters\)
sed "s/^X//" >'lib/tgoto.c' <<'END_OF_FILE'
X/* Module terminal go to */
X
X/*
X Provides interpretting of terminal cursor motion sequences
X*/
X
X/*
X Created October 21, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <km/defs.h>
X#include <km/ascii.h>
X
extern char *BC;
extern char *UP;
X
char *tgoto(cm, col, line)
X REGISTER char *cm;
X int col;
X int line;
X{
X REGISTER char *output;
X char *ptr;
X int reverse = FALSE, parm, temp;
X
X static char buf[20], extra[20];
X static char error[] = "OOPS";
X
X if (!cm)
X return(error);
X output = buf;
X extra[0] = '\0';
X parm = line; /* by default line is first parm */
X while (temp = *cm++)
X {
X if (temp != '%')
X *output++ = temp;
X else
X {
X switch (*cm++)
X {
X case '>' :
X if (parm > (temp = *cm++))
X parm += *cm++;
X else
X cm++;
X break;
X case '%' :
X *output++ = '%';
X break;
X case '+' :
X parm += *cm++; /* fall thru */
X case '.' :
X if ((parm == '\0') || (parm == CTRL_D) || (parm == HT) || (parm == '\n'))
X {
X if (!reverse && !UP)
X *output++ = parm;
X else
X {
X do
X {
X if (reverse)
X {
X if (BC)
X ptr = BC;
X else
X ptr = "\b";
X }
X else
X ptr = UP;
X strcat(extra, ptr);
X }
X while (++parm == '\n');
X }
X }
X else
X *output++ = parm;
X reverse = !reverse;
X if (reverse)
X parm = col;
X else
X parm = line;
X break;
X case 'd' :
X if (parm >= 100)
X *output++ = (parm / 100) + '0';
X if (parm >= 10)
X {
X parm = parm % 100;
X *output++ = (parm / 10) + '0';
X }
X *output++ = (parm % 10) + '0';
X reverse = !reverse;
X if (reverse)
X parm = col;
X else
X parm = line;
X break;
X case '3' :
X *output++ = (parm / 100) + '0'; /* fall thru */
X case '2' :
X parm = parm % 100;
X *output++ = (parm / 10) + '0';
X *output++ = (parm % 10) + '0';
X reverse = !reverse;
X if (reverse)
X parm = col;
X else
X parm = line;
X break;
X case 'B' :
X parm = (16 * (parm / 10) + (parm % 10));
X break;
X case 'D' :
X parm = (parm - (2 * (parm % 16)));
X break;
X case 'i' :
X col++;
X line++;
X parm++;
X break;
X case 'n' :
X col ^= 0140;
X line ^= 0140;
X parm ^= 0140;
X break;
X case 'r' :
X reverse = TRUE;
X if (reverse)
X parm = col;
X else
X parm = line;
X break;
X default :
X return(error);
X break;
X }
X }
X }
X strcpy(output, extra);
X return(buf);
X}
X
END_OF_FILE
if test 2859 -ne `wc -c <'lib/tgoto.c'`; then
echo shar: \"'lib/tgoto.c'\" unpacked with wrong size!
fi
# end of 'lib/tgoto.c'
fi
echo shar: End of archive 2 \(of 9\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 9 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
More information about the Comp.unix.xenix
mailing list