/**********************************************************************\ * Man V1.2 * * Copyright (C) 1989 by G. Glendown * * * * This program and all documentation is placed in the public domain. * *No fee may be charged except for media and copying. ArcPrep may be * * included on Fred Fish's distribution disk. Any other PD-collector * * will have to get my permission prior to putting Man on his disks. * * Any net service may distribute Man, as long as no fee for * *downloading is charged (execpt normal line costs). You may make any* * changes to Man, but I would appreciate it if you could send me the * * new sources (except conversions to Lattice-C or Modula-II) or at * * least a short note about what you did... * * * * German PD dealers: * * Please read the file 'GermanDistribution' * \**********************************************************************/ /* ts=4 */ /* * Man V1.2 * * Unix-style manual command controlled completely by * the file "man:manuals" * * USAGE: * * man [-vTextViewer] [-pPath] [-f] * */ #include #define LINE 512 #define MAXCOM 16 /* Maximum size of command name */ #define EMPTY " " #define FNPOS 20 /* start position of command line/filename */ #define MANFILE "man:manuals" /* Uncomment this if you don't have my library with a new PrintF... */ /*#define PrintF printf*/ int cnt,fc; FILE *fh,*fopen(); char *fgets(); char line[LINE],w[MAXCOM<<1]; char path[11][128]; char cmmnd[128]={"run less "}; int Status=0; #define CUSTOMVIEW (1<<0) #define FIRSTONLY (1<<1) #define DISPLAYPATHS (1<<2) int pt; char *name; /**********************************************************************\ * main * * * * Does all scanning of the CLI parameters, prints the paths defined * * and checks the 'manuals'-file. * \**********************************************************************/ main(argc,argv) int argc; char *argv[]; { char *c; int t; if (argc<=1) PrintF("Use '%s man' to see usage of %s\n",argv[0],argv[0]),exit(0L); cnt=0; name=(char *)NULL; for (t=1;t1< if file is found * * >0< file not found * \**********************************************************************/ int Found(p,n) int *p,*n; { char f[256]; struct FileLock *l,*Lock(); strcpy(f,p); strcat(f,n); l=Lock(f,ACCESS_READ); if (l) UnLock(l),fc++; if (l) return(1); else return(0); } /**********************************************************************\ * DisplayFile * * This routine will call either the file viewer, or it will execute * * the command supplied. * ********************************************************************** * Parameters: * * - line includes either the filename or the line to be executed * \**********************************************************************/ DisplayFile(f) char *f; { int t; char exec[256]; t=0; if (*f=='!') Execute(&f[1],0L,0L); else { do { t++; } while ((f[t]!=' ')&&(f[t]!='\n')); strcpy(exec,cmmnd); strncat(exec,f,t); PrintF("%s - ",f); Execute(exec,0L,0L); } } /**********************************************************************\ * SearchStart * *This routine scans the 'manuals'-file for the PATH and VIEW commands* * and tries to find the 'START_MAN'-command. * ********************************************************************** * Parameters: * * - filepointer to the 'manuals'-file. * \**********************************************************************/ SearchStart(fh) struct FileHandle *fh; { char line[LINE],*c; for (;;) { if (c=fgets(line,LINE,fh)) { if (strncmp(line,"START_MAN",9)==0) return; if (strncmp(line,"VIEW:",5)==0) { if ((Status&CUSTOMVIEW)==0) { strcpy(cmmnd,&line[5]); cmmnd[strlen(cmmnd)-1]=' '; } } if (strncmp(line,"PATH ",5)==0) { if (pt<10) { strcpy(path[pt],&line[5]); path[pt][strlen(path[pt])-1]='\0'; pt++; } else PrintF("Too many paths in 'man:manuals' - file!\n"); } } } }