|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 4222 (0x107e)
Types: TextFile
Names: »c_help.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
└─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z«
└─⟦946c717da⟧
└─⟦this⟧ »c_help.c«
/*
* Copyright (c) 1988 Michael A. Cooper, University of Southern California.
* This program may be used, copied, modified, and redistributed freely
* for noncommercial purposes, so long as this notice remains intact.
*/
#ifndef lint
static char *RCSid = "$Header: c_help.c,v 4.2 88/07/05 15:58:29 mcooper Exp $";
#endif
/*
*------------------------------------------------------------------
*
* $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/c_help.c,v $
* $Revision: 4.2 $
* $Date: 88/07/05 15:58:29 $
* $State: Exp $
*
*------------------------------------------------------------------
*
* Michael A. Cooper
* Research and Development Group
* University Computing Services
* University of Southern California
* (mcooper@oberon.USC.EDU)
*
*------------------------------------------------------------------
*
* $Log: c_help.c,v $
* Revision 4.2 88/07/05 15:58:29 mcooper
* Added copyright notice.
*
* Revision 4.1 88/04/20 16:54:22 mcooper
* Use a pager to display help info.
*
* Revision 4.0 88/04/20 15:41:26 mcooper
* Version 4.
*
* Revision 3.2 88/03/02 16:09:23 mcooper
* Cleanup time.
*
* Revision 3.1 88/03/01 15:48:35 mcooper
* Cleaned up header files.
*
* Revision 3.0 87/07/24 14:13:52 mcooper
* Version 3.
*
*------------------------------------------------------------------
*/
#include "defs.h"
#include "parse.h"
static keywrd helpkeys[MAXHELP];
static int numhelpkeys = 0;
static keytab helptab = { 0, helpkeys };
static char cmddef[] = "help";
static fdb helpfdb = { _CMKEY, 0, NULL, (pdat) &helptab, "Command, ",
cmddef, NULL };
static pval val;
static fdb *used;
static FILE *helpfd = NULL;
/*
* c_help - Ccmd interface to help.
*/
c_help()
{
if (numhelpkeys < 1) {
if (mkhelpkeys() < 0)
return(-1);
helptab._ktcnt = numhelpkeys;
}
noise("command");
helpfdb._cmfnc = _CMKEY;
parse(&helpfdb, &val, &used);
strcpy(cmddef, atmbuf);
confirm();
return(prhelp(atmbuf));
}
/*
* mkhelpkeys - Makes a keywrd structure containing all help keywords.
*/
mkhelpkeys()
{
char buf[BUFSIZ], last[BUFSIZ], subject[BUFSIZ];
int x = 0;
if (helpfd == NULL) {
if ((helpfd = fopen(helpfile, "r")) == NULL) {
perror(helpfile);
return(-1);
}
}
rewind(helpfd);
strcpy(buf, "");
strcpy(last, "");
numhelpkeys = 0;
while (fgets(buf, sizeof(buf), helpfd)) {
if (buf[0] == ' ' || buf[0] == '\t')
continue;
strcpy(subject, "");
sscanf(buf, "%s", subject);
if (strlen(subject) <= 0)
continue;
if (strlen(last) > 0 && strncmp(subject, last, strlen(last)) == 0)
continue;
if (numhelpkeys > 0) {
for (x = 0; x <= numhelpkeys; x++) {
if (x > MAXHELP) {
printf("?Exceeded MAXHELP (%d).\n", MAXHELP);
return(-1);
}
if (helpkeys[x]._kwkwd != NULL &&
strncmp(subject, helpkeys[x]._kwkwd, strlen(subject)) == 0) {
continue;
}
}
}
helpkeys[numhelpkeys]._kwkwd = (char *) xmalloc(strlen(subject)+1);
strcpy(helpkeys[numhelpkeys]._kwkwd, subject);
helpkeys[numhelpkeys]._kwval = 0;
strcpy(last, subject);
++numhelpkeys;
helpkeys[numhelpkeys]._kwkwd = NULL;
}
return(0);
}
/*
* prhelp - Print out help for "str".
*/
prhelp(str)
char *str;
{
FILE *tmpfd;
int found = FALSE;
char buf[BUFSIZ];
char *p, *pager;
char *tmpfile = "/tmp/dt.help.XXXXXX";
mktemp(tmpfile);
if ((tmpfd = fopen(tmpfile, "w")) == NULL) {
perror(tmpfile);
return(-1);
}
if (helpfd == NULL) {
if ((helpfd = fopen(helpfile, "r")) == NULL) {
perror(helpfile);
return(-1);
}
}
rewind(helpfd);
while (fgets(buf, sizeof(buf), helpfd)) {
if (strncmp(buf, str, strlen(str)) == 0) {
p = index(buf, '\t');
if (p == NULL)
fprintf(tmpfd, "\n");
else if (++p != NULL)
fprintf(tmpfd, p);
found = TRUE;
}
}
fclose(tmpfd);
if (found) {
pager = (char *) getenv("PAGER");
if (pager == NULL) {
pager = PAGER;
}
sprintf(buf, "%s %s", pager, tmpfile);
system(buf);
} else {
fprintf(stderr, "No help available for \"%s\".\n", str);
return(-1);
}
unlink(tmpfile);
return(0);
}