1996-01-28 00:41:22 +00:00
|
|
|
/*
|
1998-03-29 07:16:25 +00:00
|
|
|
* Copyright 1995-1998 by Devin Reade <gdr@trenco.gno.org>. For distribution
|
1996-01-28 00:41:22 +00:00
|
|
|
* information see the README file that is part of the manpack archive,
|
|
|
|
* or contact the author, above.
|
1998-03-29 07:16:25 +00:00
|
|
|
*
|
|
|
|
* $Id: apropos.c,v 1.2 1998/03/29 07:15:42 gdr-ftp Exp $
|
1996-01-28 00:41:22 +00:00
|
|
|
*/
|
|
|
|
|
1998-03-29 07:16:25 +00:00
|
|
|
#ifdef __ORCAC__
|
1996-01-28 00:41:22 +00:00
|
|
|
segment "apropos___";
|
1998-03-29 07:16:25 +00:00
|
|
|
#endif
|
1996-01-28 00:41:22 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-03-29 07:16:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <gno/gno.h>
|
1996-01-28 00:41:22 +00:00
|
|
|
#include "man.h"
|
|
|
|
|
1998-03-29 07:16:25 +00:00
|
|
|
static char *versionstr = VERSION_STR;
|
1996-01-28 00:41:22 +00:00
|
|
|
static char *nothing = "nothing appropriate";
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
|
|
|
char *path;
|
|
|
|
int i, matches1, matches2, matches3;
|
|
|
|
short V_flag, M_flag, m_flag, n_flag, err_flag;
|
|
|
|
|
1998-03-29 07:16:25 +00:00
|
|
|
/* make sure GNO is running */
|
1996-01-28 00:41:22 +00:00
|
|
|
if (needsgno()==0) {
|
1998-03-29 07:16:25 +00:00
|
|
|
errx(1, "Requires GNO\n");
|
1996-01-28 00:41:22 +00:00
|
|
|
}
|
|
|
|
|
1998-03-29 07:16:25 +00:00
|
|
|
__REPORT_STACK();
|
1996-01-28 00:41:22 +00:00
|
|
|
|
|
|
|
/* initialization */
|
|
|
|
V_flag = M_flag = m_flag = n_flag = err_flag = 0;
|
|
|
|
matches1 = matches2 = matches3 = 0;
|
|
|
|
|
|
|
|
/* parse command line and check usage */
|
|
|
|
while((i = getopt(argc,argv,"M:m:nV")) != EOF) {
|
|
|
|
switch(i) {
|
|
|
|
case 'M':
|
|
|
|
if (m_flag) err_flag++;
|
|
|
|
M_flag++;
|
|
|
|
path = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (M_flag) err_flag++;
|
|
|
|
m_flag++;
|
|
|
|
path = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
n_flag++;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
V_flag++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err_flag++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argc-optind < 1) err_flag++;
|
|
|
|
if (err_flag || V_flag) {
|
|
|
|
fprintf(stderr,"%s version %s by Devin Reade\n",
|
|
|
|
basename(argv[0]),versionstr);
|
|
|
|
}
|
|
|
|
if (err_flag) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: %s [[-M path] | [-m path]] [-nV] keyword [keyword ...]\n",
|
|
|
|
basename(argv[0]));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do the search */
|
|
|
|
if (M_flag) {
|
|
|
|
manpath = path;
|
|
|
|
} else {
|
|
|
|
manpath = getManpath();
|
|
|
|
}
|
|
|
|
matches1 = apropos(argc-optind, &argv[optind], MAN_K_MODE);
|
|
|
|
if (!M_flag) free(manpath);
|
|
|
|
if (m_flag) {
|
|
|
|
manpath = path;
|
|
|
|
matches2 = apropos(argc-optind, &argv[optind], MAN_K_MODE);
|
|
|
|
}
|
|
|
|
if (!n_flag) {
|
|
|
|
matches3 = apropos(argc-optind, &argv[optind], ORCA_K_MODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
if (matches1>0) i+= matches1;
|
|
|
|
if ( m_flag && matches2>0) i+=matches2;
|
|
|
|
if (!n_flag && matches3>0) i+=matches3;
|
|
|
|
|
|
|
|
if (i==0) {
|
|
|
|
fprintf(stderr,"%s: %s\n",basename(argv[0]),nothing);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((matches1>=0) && (matches2>=0) && (matches3>=0) && i>0) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|