1996-01-28 00:41:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995 by Devin Reade <gdr@myrias.com>. For distribution
|
|
|
|
* information see the README file that is part of the manpack archive,
|
|
|
|
* or contact the author, above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
segment "makewhatis";
|
1996-01-28 00:31:34 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gsos.h>
|
|
|
|
#include <orca.h>
|
|
|
|
|
|
|
|
#include "makewhatis.h"
|
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
/* These are the compression types */
|
|
|
|
#define NO_COMPRESS 0
|
|
|
|
#define Z_COMPRESS 1
|
|
|
|
#define F_COMPRESS 2
|
1996-01-28 00:41:22 +00:00
|
|
|
#define G_COMPRESS 3
|
1996-01-28 00:33:14 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
#ifdef TEST_PROCESS
|
1996-01-28 00:41:22 +00:00
|
|
|
short v_flag = 1;
|
|
|
|
FILE *output_fp;
|
|
|
|
FILE *error_fp;
|
1996-01-28 00:33:14 +00:00
|
|
|
#else
|
1996-01-28 00:41:22 +00:00
|
|
|
extern FILE *output_fp;
|
|
|
|
extern FILE *error_fp;
|
1996-01-28 00:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
extern GSString255Ptr __C2GSMALLOC (char *s);
|
1996-01-28 00:31:34 +00:00
|
|
|
extern char buffer[];
|
1996-01-28 00:33:14 +00:00
|
|
|
extern char titlebuf[];
|
1996-01-28 00:31:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void process (char *filename, char *tmp_file, FILE *whatis_fp);
|
|
|
|
*
|
1996-01-28 00:41:22 +00:00
|
|
|
* Pre: <filename> is the name of the file to add to the database.
|
|
|
|
* <tmp_file> is the name for the temporary file. It has not been opened.
|
|
|
|
* <whatis_fp> is a file pointer to the open whatis database file.
|
|
|
|
* (sec> is the section "number". We really only care if it is
|
|
|
|
* either "l" or "local" (because of aroff "links"), otherwise
|
|
|
|
* it is ignored.
|
1996-01-28 00:31:34 +00:00
|
|
|
*
|
|
|
|
* Post: The name, section number, and description from the man page is
|
1996-01-28 00:41:22 +00:00
|
|
|
* appended to <whatis_fp>.
|
1996-01-28 00:31:34 +00:00
|
|
|
*/
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
void process (char *filename, char *tmp_file, FILE *whatis_fp, char *sec) {
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
FileInfoRecGS info_record; /* used to get the file type */
|
1996-01-28 00:31:34 +00:00
|
|
|
char *suffix; /* points to the start of the file suffix */
|
1996-01-28 00:41:22 +00:00
|
|
|
static char command_buf[255]; /* used to call system(2) */
|
|
|
|
char *p1; /* a scratch pointer */
|
|
|
|
int namelength; /* length of 'name (section)' */
|
|
|
|
char *name; /* points to the file basename */
|
|
|
|
short compression; /* the compression type (if nec) */
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
if (v_flag>=2) fprintf(output_fp,"Working on file %s/%s ...\n",sec,filename);
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
/*
|
1996-01-28 00:33:14 +00:00
|
|
|
* get the file basename
|
1996-01-28 00:31:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((name = malloc (strlen(filename)+1)) == NULL) {
|
1996-01-28 00:41:22 +00:00
|
|
|
if (v_flag)
|
|
|
|
fprintf(error_fp,"malloc failed when processing %s -- file skipped\n",
|
|
|
|
filename);
|
1996-01-28 00:31:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(name,filename);
|
1996-01-28 00:33:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for a compression suffix like ".Z" or ".F"
|
|
|
|
*/
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
p1 = name + strlen(name) -1; /* p1 points to last char of name */
|
|
|
|
while ((p1>=name) && (*p1!='.')) p1--;
|
1996-01-28 00:33:14 +00:00
|
|
|
if (p1<=name) { /* <= because we don't want a name beginning with '.' */
|
1996-01-28 00:41:22 +00:00
|
|
|
if (v_flag)
|
|
|
|
fprintf(error_fp,"%s has no suffix -- file skipped\n",
|
|
|
|
filename);
|
1996-01-28 00:31:34 +00:00
|
|
|
return;
|
|
|
|
}
|
1996-01-28 00:41:22 +00:00
|
|
|
if (strcmp(p1,".Z")==0) {
|
|
|
|
compression = Z_COMPRESS;
|
|
|
|
} else if (strcmp(p1,".F")==0) {
|
|
|
|
compression = F_COMPRESS;
|
|
|
|
} else if (strcmp(p1,".gz")==0) {
|
|
|
|
compression = G_COMPRESS;
|
1996-01-28 00:33:14 +00:00
|
|
|
} else compression = NO_COMPRESS;
|
|
|
|
*p1 = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* define the suffix
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (compression == NO_COMPRESS) {
|
1996-01-28 00:41:22 +00:00
|
|
|
suffix = p1 + 1;
|
1996-01-28 00:33:14 +00:00
|
|
|
} else {
|
1996-01-28 00:41:22 +00:00
|
|
|
while ((p1>=name) && (*p1!='.')) --p1;
|
|
|
|
if (p1<=name) { /* <= because we don't want a name beginning with '.' */
|
|
|
|
if (v_flag)
|
|
|
|
fprintf(error_fp,"%s has deformed file name -- file skipped\n",
|
|
|
|
filename);
|
|
|
|
return;
|
|
|
|
}
|
1996-01-28 00:33:14 +00:00
|
|
|
*p1 = '\0';
|
|
|
|
suffix = p1 + 1;
|
|
|
|
}
|
1996-01-28 00:31:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* find out the file type
|
|
|
|
*/
|
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
if (compression == NO_COMPRESS) {
|
1996-01-28 00:41:22 +00:00
|
|
|
info_record.pCount = 5;
|
|
|
|
info_record.pathname = __C2GSMALLOC(filename);
|
|
|
|
GetFileInfoGS(&info_record);
|
|
|
|
if (toolerror()) {
|
|
|
|
if (v_flag)
|
|
|
|
fprintf(error_fp,
|
|
|
|
"malloc failed when processing %s -- file skipped\n", filename);
|
|
|
|
return;
|
|
|
|
}
|
1996-01-28 00:31:34 +00:00
|
|
|
}
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
/*
|
1996-01-28 00:31:34 +00:00
|
|
|
* Process the file according to type: nroff, aroff, freeze, and compress.
|
|
|
|
* The digested result is placed in buffer.
|
|
|
|
*/
|
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
if ((compression == NO_COMPRESS) &&
|
1996-01-28 00:41:22 +00:00
|
|
|
(info_record.fileType == 0x50u) &&
|
1996-01-28 00:33:14 +00:00
|
|
|
(info_record.auxType == 0x8010u)
|
|
|
|
) {
|
1996-01-28 00:41:22 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
/* is it an Appleworks GS word processor document? Use aroff */
|
1996-01-28 00:41:22 +00:00
|
|
|
sprintf(command_buf,"aroff -b %s > %s",filename,tmp_file);
|
|
|
|
if (v_flag>=3) fprintf(stderr,"%s\n",command_buf);
|
1996-01-28 00:31:34 +00:00
|
|
|
system(command_buf);
|
1996-01-28 00:41:22 +00:00
|
|
|
fillbuffer(tmp_file);
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
} else if (compression == Z_COMPRESS) {
|
1996-01-28 00:41:22 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
/* Compressed man page; uncompress it */
|
1996-01-28 00:41:22 +00:00
|
|
|
sprintf(command_buf,"compress -cd %s > %s",filename,tmp_file);
|
|
|
|
if (v_flag>=3) fprintf(stderr,"%s\n",command_buf);
|
|
|
|
system(command_buf);
|
|
|
|
fillbuffer(tmp_file);
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
} else if (compression == F_COMPRESS) {
|
1996-01-28 00:41:22 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
/* Frozen man page; melt it */
|
1996-01-28 00:41:22 +00:00
|
|
|
sprintf(command_buf,"freeze -cd %s > %s",filename,tmp_file);
|
|
|
|
if (v_flag>=3) fprintf(stderr,"%s\n",command_buf);
|
|
|
|
system(command_buf);
|
|
|
|
fillbuffer(tmp_file);
|
|
|
|
|
|
|
|
} else if (compression == G_COMPRESS) {
|
|
|
|
|
|
|
|
/* gzipped man page; zcat it */
|
|
|
|
sprintf(command_buf,"gzip -cd %s > %s",filename,tmp_file);
|
|
|
|
if (v_flag>=3) fprintf(stderr,"%s\n",command_buf);
|
|
|
|
system(command_buf);
|
|
|
|
fillbuffer(tmp_file);
|
|
|
|
|
|
|
|
} else if ((*suffix=='l') && (*(suffix+1)=='\0') &&
|
|
|
|
strcmp("l",sec) && strcmp("local",sec)) {
|
|
|
|
|
|
|
|
/* It's a link to another man page; do nothing. */
|
|
|
|
return;
|
1996-01-28 00:31:34 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
/* Assume that it's a text file */
|
|
|
|
if (v_flag>=3) fprintf(stderr,"assuming text file\n");
|
|
|
|
fillbuffer(filename);
|
1996-01-28 00:31:34 +00:00
|
|
|
}
|
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
/*
|
|
|
|
* If there was an error, or it is an .so reference to another man
|
|
|
|
* page, then return without writing anything to the database
|
|
|
|
*/
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
if ((buffer[0] == '\0') || (titlebuf[0] == '\0')) {
|
|
|
|
return;
|
|
|
|
}
|
1996-01-28 00:33:14 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
/*
|
|
|
|
* At this point, buffer contains the line that we need to print to
|
|
|
|
* whatis_fd. Strip off any leading spaces, then give it a nice
|
|
|
|
* formatting.
|
|
|
|
*/
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
p1 = buffer;
|
1996-01-28 00:31:34 +00:00
|
|
|
while (isspace(*p1)) p1++;
|
1996-01-28 00:41:22 +00:00
|
|
|
namelength = strlen(titlebuf) + strlen(suffix) + 4;
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
if (namelength > (TABLENGTH * 3)) {
|
|
|
|
fprintf(whatis_fp,"%s (%s) - %s\n", titlebuf, suffix, p1);
|
1996-01-28 00:31:34 +00:00
|
|
|
} else if (namelength > (TABLENGTH * 2)) {
|
1996-01-28 00:41:22 +00:00
|
|
|
fprintf(whatis_fp,"%s (%s)\t- %s\n", titlebuf, suffix, p1);
|
1996-01-28 00:31:34 +00:00
|
|
|
} else if (namelength > TABLENGTH ) {
|
1996-01-28 00:33:14 +00:00
|
|
|
fprintf(whatis_fp,"%s (%s)\t\t- %s\n", titlebuf, suffix, p1);
|
1996-01-28 00:31:34 +00:00
|
|
|
} else {
|
1996-01-28 00:33:14 +00:00
|
|
|
fprintf(whatis_fp,"%s (%s)\t\t\t- %s\n", titlebuf, suffix, p1);
|
1996-01-28 00:31:34 +00:00
|
|
|
}
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
return;
|
1996-01-28 00:31:34 +00:00
|
|
|
}
|
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
|
1996-01-28 00:31:34 +00:00
|
|
|
#ifdef TEST_PROCESS
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
1996-01-28 00:41:22 +00:00
|
|
|
|
1996-01-28 00:33:14 +00:00
|
|
|
output_fp = stdout;
|
1996-01-28 00:41:22 +00:00
|
|
|
error_fp = stderr;
|
1996-01-28 00:31:34 +00:00
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr,"Usage: %s <man_page_file_name>\n",argv[0]);
|
1996-01-28 00:31:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1996-01-28 00:41:22 +00:00
|
|
|
process (argv[1], ":tmp:garbage", stdout, "2");
|
1996-01-28 00:31:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|