help command
Bob Ware
bware at udenva.UUCP
Sat Nov 10 08:55:31 AEST 1984
The following source is a 'help' command intended primarily for new
Unix users. It provides an alternate way to locate a command manual
when the user does not know the needed command name.
Installation instructions are in whatcomm.c
Bob Ware
University of Denver (soon to be at Colorado School of Mines)
2020 S. Race St
Denver, Co 80208
303-871-2081
{seismo!hao, ucbvax!nbires, denelcor)!udenva!bware
---------------------cut here-----------------------------------------
: to unbundle, "sh" this file -- DO NOT use csh
: SHAR archive format. Archive created Fri Nov 9 15:32:12 MST 1984
echo x - sharfile
sed 's/^X//' > sharfile <<'+FUNKY+STUFF+'
X: to unbundle, "sh" this file -- DO NOT use csh
X: SHAR archive format. Archive created Fri Nov 9 15:32:12 MST 1984
Xecho x - sharfile
Xsed 's/^X//' > sharfile <<'+FUNKY+STUFF+'
+FUNKY+STUFF+
echo '-rw-r--r-- 1 bware 372 Nov 9 15:32 sharfile (as sent)'
chmod u=rw,g=r,o=r sharfile
ls -l sharfile
echo x - whatcomm.c
sed 's/^X//' > whatcomm.c <<'+FUNKY+STUFF+'
X/* whatcomm (help) command, written by Robert K Ware, University of Denver
X *
X * This command is intended for new unix users who are having trouble
X * finding the name of a command. Typically they will know what they wish
X * to do, but have not found the command using man or man -k.
X *
X * The command uses a file (FILENAME below) that has the command lines in an
X * outline form. Format:
X * There may not be any empty or blank lines.
X * The level in the outline is denoted by the number of leading blanks
X * divided by 2. The deepest level is the command name followed by
X * a short (one line) description (typically obtained with man -k <command>
X *
X * Format example:
X
XAccess control (login control, etc)
X chfn change full name of user
X chsh change default login shell
X mesg permit or deny messages
X passwd change login password
X su substitute user id temporarily
XCommunication (i/o)
X Graphics
X graph draw a graph
X plot graphics filters
X spline interpolate smooth curve
X vpr raster printer/plotter spooler
X Machine to machine
X ftp file transfer program
X gets get a string from standard input
X lpq spool queue examination program
X lpr line printer spooler
X
X *
X * To install:
X *
X * 1. Create the data file described above or use the example supplied with
X * the source package.
X *
X * 2. Define FILENAME to match the path to the above data file.
X *
X * 3. Compile and install.
X *
X * 4. Install the manual.
X *
X * NOTE: The data base supplied is for 4.2 BSD. I am sure others can come up
X * with better headings and organization. If you do, you might wish to share
X * it with the rest of us.
X *
X *
X * Bob Ware 11/9/84
X */
X#include <stdio.h>
X
X#define FILENAME "/usr/local/lib/whatlist" /* file name for data list */
X#define MAXSTR 80 /* max string length of item in data file */
X#define CKSIZE (3 * sizeof(char *) + MAXSTR + 1)
X /* size of needed structure */
X#define PADSIZE ( (CKSIZE / 64 + 1) * 64 )
X /* size of structure padded to even long */
X#define PAD (PADSIZE - CKSIZE) /* size of needed pad */
X#define SIZE (unsigned)sizeof(struct list)/* size of list structure */
X#define MAXCT 128 /* list size to make room for each time */
X#define NULLPTR (struct list *) NULL
X#define QUIT -1 /* 'q' response from user mapped to QUIT */
X#define BAD -2 /* invalid response from user mapped to BAD */
X
Xstruct list
X{
X struct list *next; /* the next item at same level */
X struct list *down; /* the first item at next lower level */
X struct list *up; /* the parent item at higher level */
X char str[MAXSTR+1]; /* one line from command list file */
X char pad[PAD]; /* pad structure to even long */
X};
Xchar *argv0; /* pointer to command name */
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X/*....................VARIABLES...............................................*/
X struct list *loadlist(); /* pointer to start of list */
X struct list *item_ptr; /* pointer to current item of list */
X struct list *send_man(); /* send manual and reset item pointer */
X int item_count; /* max item number for a list segment */
X int item, get_item(); /* response code from user *
X * invalid response = BAD *
X * 'q' = QUIT *
X * 0 = backup to previous level *
X * 1 to item_count = valid list no. */
X
X/*...................INIALIZE.................................................*/
X argv0 = argv[0]; /* innialize command name */
X item_ptr = loadlist(); /* load data list from FILENAME */
X
X/*...................MAIN LOOP................................................*/
X for(item = 0; item != QUIT;) /* keep going until QUIT response */
X {
X if (item == 0) /* for response = 'up' */
X {
X if(item_ptr->up != NULLPTR)
X item_ptr = item_ptr->up;
X item_count = send_list(item_ptr->down);
X }
X else if(item == BAD) /* send a prompt for input */
X {
X bad_prompt(item_count);
X if(item_ptr->down == NULLPTR)
X item_ptr = item_ptr->up;
X item_count = send_list(item_ptr->down);
X }
X else /* for valid response */
X {
X /* set new pointer */
X item_ptr = item_ptr->down;
X while(item-- > 1)
X item_ptr = item_ptr->next;
X
X /* send to stdio */
X if (item_ptr->down == NULLPTR) /* must be manual */
X item_ptr = send_man(item_ptr);
X else /* else must be list */
X item_count = send_list(item_ptr->down);
X
X }
X prompt(item_count);
X
X item = get_item(item_count); /* get input code from tty */
X }
X
X/*.....................EXIT................................................*/
X printf("\nDid not find the command you wanted?\n");
X printf("\tThen try: apropos <keyword>\n");
X}
Xstruct list *loadlist()
X{
X /********************************************************
X * 1. Opens the data file (FILENAME) *
X * 2. Interprets and loads a linked list of structures *
X * from the date *
X * 3. Makes memory available as needed for the list *
X * 4. Returns a pointer to the first start of the list *
X ********************************************************/
X
X/*.........................VARIABLES....................................*/
X extern char *calloc();
X
X FILE *file_ptr; /* file pointer */
X register int i; /* all purpose counter */
X register int chr_ct; /* position counter for string */
X register int this_level = -1; /* level number (-1 = top) */
X register int list_count ; /* item counter for the list */
X register int last_level; /* previous level number */
X char string[MAXSTR + 2]; /* i/o buffer for data */
X struct list *this_ptr; /* current list pointer */
X struct list *last_ptr; /* last list pointer */
X struct list *start_ptr; /* point to start of list */
X
X/*.........................open data file....................................*/
X if((file_ptr = fopen(FILENAME, "r")) == NULL)
X {
X fprintf(stderr,"Attempting open: %s\n",FILENAME);
X bomb("Unable to open above data file");
X }
X/*.........................allocate first chunk of memory....................*/
X if((start_ptr = (struct list *)calloc(MAXCT,SIZE)) == 0)
X bomb("out of memory");
X list_count = MAXCT;
X
X/*........................set up initial pointers............................*/
X this_ptr = start_ptr;
X this_ptr++;
X this_ptr->up = start_ptr;
X start_ptr->up = NULLPTR;
X start_ptr->down = this_ptr;
X start_ptr->next = NULLPTR;
X last_ptr = start_ptr;
X
X/*.........................main loop.........................................*
X * Ok, we now have opened the data file, allocated a chunk of memory *
X * and set up initial pointer values. *
X * *
X * We now need to: *
X * Read one line from file and copy to structure. If line was longer *
X * than MAXSTR (+ \0) then complain and quit. And interpret the level *
X * and load rest of structure. *
X * Repeat until end of file is reached. *
X *...........................................................................*/
X
X while((fgets(string,MAXSTR+2,file_ptr)) != NULL)
X {
X /* what level is this item? */
X last_level = this_level;
X for(chr_ct = 0; string[chr_ct] == ' '; chr_ct++);
X this_level = chr_ct/2;
X
X /* load string in structure */
X for(i=0; chr_ct <= MAXSTR+1;)
X {
X if( (string[chr_ct]=='\0') || (string[chr_ct]=='\n') )
X break;
X this_ptr->str[i++] = string[chr_ct++];
X }
X if(chr_ct > MAXSTR)
X bomb("Data file has a line that is too long.");
X this_ptr->str[i] = '\0';
X
X /* load rest of structure */
X if(this_level > last_level)
X {
X last_ptr->next = NULLPTR;
X last_ptr->down = this_ptr;
X this_ptr->up = last_ptr;
X }
X if(this_level == last_level)
X {
X last_ptr->next = this_ptr;
X last_ptr->down = NULLPTR;
X this_ptr->up = last_ptr->up;
X }
X if(this_level < last_level)
X {
X last_ptr->next = NULLPTR;
X last_ptr->down = NULLPTR;
X while(last_level-- > this_level)
X last_ptr = last_ptr->up;
X last_ptr->next = this_ptr;
X this_ptr->up = last_ptr->up;
X }
X
X /* reset this_ptr to next item */
X last_ptr = this_ptr; /* save it */
X if(list_count-- <= 1) /* out of memory? */
X {
X if((this_ptr = (struct list *)calloc(MAXCT,SIZE)) == 0)
X bomb("out of memory");
X list_count = MAXCT;
X }
X else
X this_ptr++; /* no, then next item */
X }
X
X/*......................finish up......................................*/
X last_ptr->next = NULLPTR;
X last_ptr->down = NULLPTR;
X
X return(start_ptr);
X}
Xbad_prompt(item_count)
Xint item_count;
X{
X printf("\n........................................\n");
X printf(". Input must be a number from 1 to %2d .\n",item_count);
X printf(". OR .\n");
X printf(". '0' to go back one step .\n");
X printf(". 'q' to quit .\n");
X printf("........................................\n\n");
X}
Xprompt(item_count)
Xint item_count;
X{
X printf("Enter # (0-%d) or q (quit): ",item_count);
X}
Xget_item(item_count)
Xint item_count;
X{
X char str[MAXSTR]; /* input string buffer */
X int item; /* item number (converted from input) */
X
X gets(str);
X
X /* interpret the response */
X
X item = atoi(str);
X
X if ( (*str == 'q') || (*str == 'Q') ) /* quit? */
X item = QUIT;
X else if( (item < 0) || (item > item_count) ) /* outside range? */
X item = BAD;
X else if ( (*str < '0') || (*str > '9') ) /* not a number? */
X item = BAD;
X
X return(item);
X}
Xsend_list(item_ptr)
Xstruct list *item_ptr;
X{
X /************************************************
X * 1. sends a list of the next items to stdio. *
X * (starting at item_ptr) *
X * 2. Counts the number of items in the list. *
X * 3. Returns the count. *
X ************************************************/
X
X int item_count = 0;
X
X while(item_ptr != NULLPTR)
X {
X item_count++;
X printf("%2d %s\n", item_count, item_ptr->str);
X item_ptr = item_ptr->next;
X }
X return(item_count);
X}
Xstruct list *send_man(item_ptr)
Xstruct list *item_ptr;
X{
X
X char *command; /* pointer to item string */
X char s[MAXSTR+1]; /* command name */
X int i; /* scratch pad */
X int pid,sts;
X
X command = item_ptr->str;
X
X /* strip white space and trailing info and load command name */
X
X for(i=0;(i<MAXSTR)&&(*command!=' ')&&(*command!='\t');i++,command++)
X s[i] = *command;
X s[i] = '\0';
X
X /* attempt to create a process */
X
X if ((pid = vfork()) == -1)
X bomb("no processes left - fork failed\n");
X
X if (pid)
X { while (wait(&sts) != pid)
X { if (wait(&sts) == -1)
X return(item_ptr);
X }
X return(item_ptr);
X }
X
X /* do it */
X
X execlp("man","man",s,0);
X
X return(item_ptr->up);
X}
Xbomb(error_msg)
Xchar *error_msg;
X{
X fprintf(stderr,"\n%s: %s\n", argv0, error_msg);
X exit(1);
X}
+FUNKY+STUFF+
echo '-rw-r--r-- 1 bware 10731 Nov 9 15:12 whatcomm.c (as sent)'
chmod u=rw,g=r,o=r whatcomm.c
ls -l whatcomm.c
echo x - whatcomm.nr
sed 's/^X//' > whatcomm.nr <<'+FUNKY+STUFF+'
X.TH WHATCOMM l dulocal
X.UC 4
X.SH NAME
Xwhatcomm \- locate a command -dulocal
X.SH SYNOPSIS
X.B whatcomm
X.br
X.SH DESCRIPTION
XWhatcomm provides an alternate way to find the name of a command.
X.PP
XA classification 'tree' of command names is used to locate commands which
Xhave the desired function. A user may move down the tree via a menu.
XAt the last level, the user may print the manual for a command on the
Xterminal.
X.PP
X.br
X.SH "EXAMPLE"
X
X% whatcomm
X
X 1 Access control
X 2 Communication
X 3 Documentation
X 4 File management
X 5 Miscellaneous
X 6 Program development
X 7 Running programs
X 8 Status information
X 9 Text processing
X
XEnter # (0-9) or q (quit): 4 <CR>
X
X 1 Analyse file(s)
X 2 Location of file/directory
X 3 Modify file/directory
X 4 Read/print a file
X 5 Tape format
X
X To go back to the previous list, enter: 0
X
XEnter # (0-5) or q (quit): 0 <CR>
X
X 1 Access control
X 2 Communication
X 3 Documentation
X 4 File management
X 5 Miscellaneous
X 6 Program development
X 7 Running programs
X 8 Status information
X 9 Text processing
X
XEnter # (0-9) or q (quit): 8 <CR>
X
X 1 Files
X 2 System
X 3 Terminal
X 4 Users
X
X To go back to the previous list, enter: 0
X
XEnter # (0-4) or q (quit): 1 <CR>
X
X 1 du summarize disk usage
X 2 file determine file type
X 3 ls -l print long listing of file names, with status info
X 4 size size of an object file
X
X To go back to the previous list, enter: 0
X
XEnter # (0-4) or q (quit): 2 <CR>
X.br
X .
X.br
X .
X.br
X prints manual for file to your terminal
X.br
X .
X.br
X .
X.PP
XEnter # (0-4) or q (quit): q <CR>
X
XDid not find the command you want?
X Then try: apropos <keyword>
X
X.SH "AUTHOR"
XThis program was written by
XRobert K. Ware, Computing Services,
XUniversity of Denver.
X.SH "FILES"
X/usr/local/lib/whatlist
X.PP
X.SH "SEE ALSO"
Xappropos (1), man (1)
+FUNKY+STUFF+
echo '-rw-r--r-- 1 bware 1821 Nov 9 14:34 whatcomm.nr (as sent)'
chmod u=rw,g=r,o=r whatcomm.nr
ls -l whatcomm.nr
echo x - whatlist
sed 's/^X//' > whatlist <<'+FUNKY+STUFF+'
XAccess control (login control, etc)
X chfn change full name of user
X chmod change mode (protection) of a file
X chsh change default login shell
X finger user information lookup program
X groups show group memberships
X login sign on
X mesg permit or deny messages
X passwd change login password
X su substitute user id temporarily
XCommunication (i/o)
X Graphics
X graph draw a graph
X plot graphics filters
X spline interpolate smooth curve
X vpr raster printer/plotter spooler
X Machine to machine
X clear clear terminal screen
X ftp file transfer program
X gets get a string from standard input
X lpq spool queue examination program
X lpr line printer spooler
X lprm remove jobs from the line printer spooling queue
X rcp remote file copy
X rlogin remote login
X rpr remote printer spooler -dulocal
X rsh remote shell
X tip connect to a remote system
X uucp unix to unix copy
X uuencode encode/decode a binary file for transmission via mail
X uusend send a file to a remote host
X uux unix to unix command execution
X People to people -local
X biff be notified if mail arrives and who it is from
X binmail send or receive mail among users
X from who is my mail from?
X mail send and receive mail
X newaliases rebuild the data base for the mail aliases file
X prmail print out mail in the post office
X rmail handle remote mail received via uucp
X talk talk to another user
X wall write to all users
X uuencode encode/decode a binary file for transmission via mail
X write write to another user
X xsend secret mail
X People to people -network
X checknews check to see if user has news
X inews submit news articles
X netstat show network status
X postnews submit news articles
X readnews read news articles
X telnet user interface to the TELNET protocol
X Tape
X dd convert and copy a file
X mt Magnetic tape manipulating program
X od octal dump
X tar tape archiver
X tp manipulate tape archive
XDocumentation (what's on the system)
X apropos locate commands by keyword lookup
X intro introduction to commands
X learn computer aided instruction about UNIX
X man find manual information by keywords; print out the manual
X trman translate version 6 manual macros to version 7 macros
X whatis describe what a command is
XFile management (doing things with/to files and directories)
X Analyse file(s)
X cmp compare two files
X comm select or reject lines common to two sorted files
X diff differential file and directory comparator
X diff3 3-way differential file comparison
X ls list contents of directory
X nm print name list
X pr print file
X sum sum and count blocks in a file
X test condition command
X what what versions of object modules were used to construct a file
X Location of file/directory
X cd change working directory
X cp copy
X find find files
X install install binaries
X ln make links
X ls list contents of directory
X mkdir make a directory
X mv move or rename files
X rcp remote file copy
X whereis locate source, binary, and or manual for program
X which locate program file including aliases and paths (\fIcsh\fR only)
X Modify file/directory
X chgrp change group
X chmod change mode (protection) of a file
X compact compress and uncompress files, and cat them
X install install binaries
X mkdir make a directory
X mv move or rename files
X ranlib convert archives to random libraries
X rm remove (unlink) files
X split split a file into pieces
X strip remove symbols and relocation bits
X touch update date last modified of a file
X Read/print a file
X cat catenate and print
X head give first few lines
X more file perusal filter for crt viewing
X see see what a file has in it
X strings find the printable strings in a object, or other binary, file
X tail deliver the last part of a file
X Revision control system
X ci check in RCS revisions
X co check out RCS revisions
X ident identify files
X merge three-way file merge
X rcs change RCS file attributes
X rcsdiff compare RCS revisions
X rcsintro introduction to RCS commands
X rcsmerge merge RCS revisions
X rlog print log messages and other information about RCS files
X Tape format
X ar archive and library maintainer
X dd convert and copy a file
X mt Magnetic tape manipulating program
X od octal dump
X tar tape archiver
X tp manipulate tape archive
XMiscellaneous (special purpose programs)
X bc arbitrary-precision arithmetic language
X dc desk calculator
X echo echo arguments
X false provide truth values
X play play and control games -dulocal
X script make typescript of terminal session
X true provide truth values
X units conversion program
X yes be repetitively affirmative
XProgram development (compilers - debuggers, etc)
X C
X cb C program beautifier
X cc C compiler
X ctags create a tags file
X indent indent and format C program source
X lint a C program verifier
X mkstr create an error message file by massaging C source
X xstr extract strings from C programs to implement shared strings
X vgrind grind nice listings of programs
X Compile/load/debug
X adb debugger
X cc C compiler
X dbx debugger
X error analyze and disperse compiler error messages
X gcore get core images of running processes
X gprof display call graph profile data
X ld link editor
X lorder find ordering relation for an object library
X make maintain program groups
X pc Pascal compiler
X pdx pascal debugger
X Fortran
X ctags create a tags file
X efl Extended Fortran Language
X f77 Fortran 77 compiler
X fsplit split a multi-routine Fortran file into individual files
X ratfor rational Fortran dialect
X fpr print Fortran file
X struct structure Fortran programs
X Other languages
X as assembler
X awk pattern scanning and processing language
X csh a shell (command interpreter) with C-like syntax
X eyacc modified yacc allowing much improved error recovery
X fp Functional Programming language compiler/interpreter
X lex generator of lexical analysis programs
X lisp lisp interpreter
X liszt compile a Franz Lisp program
X lxref lisp cross reference program
X sh command language
X vlp Format Lisp programs to be printed with nroff, vtroff, or troff
X yacc yet another compiler-compiler
X Pascal
X ctags create a tags file
X pc Pascal compiler
X pdx pascal debugger
X pi Pascal interpreter code translator
X pix Pascal interpreter and executor
X pmerge pascal file merger
X px Pascal interpreter
X pxp Pascal execution profiler
X pxref Pascal cross-reference program
X vgrind grind nice listings of programs
XRunning programs (executing object/script files)
X apply apply a command to a set of arguments
X at execute commands at a later time
X csh a shell (command interpreter) with C-like syntax
X gprof display call graph profile data
X kill terminate a process with extreme prejudice
X nice run a command at low priority (\fIsh\fR only)
X sh command language
X script make typescript of terminal session
X sleep suspend execution for an interval
X tee pipe fitting (split output of a command)
X time time a command
X wait await completion of process
XStatus information (what's happening? How are things set?)
X Files
X du summarize disk usage
X file determine file type
X ls -l print long listing of file names, with status info
X quota display disc usage and limits
X size size of an object file
X System
X date print and set the date
X df disk free
X du summarize disk usage
X hostid set or print identifier of current host system
X hostname set or print name of current host system
X iostat report I/O statistics
X printenv print out the environment
X pagesize print system page size
X prof display profile data
X ps process status
X ruptime show host status of local machines
X sysline display system status on status line of a terminal
X uptime show how long system has been up
X users compact list of users who are on the system
X vmstat report virtual memory statistics
X w who is on and what they are doing
X who who is on the system
X Terminal
X reset reset the teletype bits to a sensible state
X stty set terminal options
X tabs set terminal tabs
X tset set terminal modes
X tty get terminal name
X Users
X cal print calendar
X calendar reminder service
X last indicate last logins of users and teletypes
X lastcomm show last commands executed in reverse order
X leave remind you when you have to leave
X news access general news items about the system
X ps process status
X pwd working directory name
X quota display disc usage and limits
X rwho who's logged in on local machines
X users compact list of users who are on the system
X w who is on and what they are doing
X who who is on the system
X whoami print effective current user id
XText processing (Doing things in english)
X Analyse text files
X awk pattern scanning and processing language
X checknr check nroff/troff files
X grep search a file for a pattern
X uniq report repeated lines in a file
X vfontinfo inspect and print out information about unix fonts
X wc word count
X Composition/style
X diction print wordy sentences; thesaurus for diction
X explain print wordy sentences; thesaurus for diction
X look find lines in a sorted list
X spell find spelling errors
X style analyze surface characteristics of a document
X Edit file
X addbib create or extend bibliographic database
X colrm remove columns from a file
X deroff remove nroff, troff, tbl and eqn constructs
X ed text editor
X eqn typeset mathematics
X ex text editor
X indxbib build inverted index for a bibliography, find references
X join relational database operator
X refer find and insert literature references in documents
X roffbib run off bibliographic database
X sed stream editor
X sortbib sort bibliographic database
X vi screen oriented (visual) display editor based on ex
X Format a file
X colcrt filter nroff output for CRT previewing
X col filter reverse line feeds
X fmt simple text formatter
X fold fold long lines for finite width output device
X fpr print Fortran file
X nroff text formatting
X pti phototypesetter interpreter
X ptx permuted index
X soelim eliminate \&.so's from nroff input
X tbl format tables for nroff or troff
X tc photypesetter simulator
X tk paginator for the Tektronix 4014
X troff text formatting and typesetting
X vgrind grind nice listings of programs
X vlp Format Lisp programs to be printed with nroff, vtroff, or troff
X vtroff troff to a raster plotter
X vwidth make troff width table for a font
X Modify text
X basename strip filename affixes
X crypt encode/decode
X expand expand tabs to spaces, and vice versa
X expr evaluate arguments as an expression
X lex generator of lexical analysis programs
X m4 macro processor
X sed stream editor
X tr translate characters
X ul do underlining
X Sort
X rev reverse lines of a file
X sort sort or merge files
X symorder rearrange name list
X sortbib sort bibliographic database
X tsort topological sort
+FUNKY+STUFF+
echo '-rw-r--r-- 1 bware 13149 Nov 9 14:35 whatlist (as sent)'
chmod u=rw,g=r,o=r whatlist
ls -l whatlist
exit 0
More information about the Comp.sources.unix
mailing list