mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-10-03 20:55:15 +00:00
167 lines
4.2 KiB
C
167 lines
4.2 KiB
C
|
#ifdef __CCFRONT__
|
||
|
#include <14:pragma.h>
|
||
|
#endif
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <ctype.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <gsos.h>
|
||
|
#include <orca.h>
|
||
|
|
||
|
#include "makewhatis.h"
|
||
|
|
||
|
#ifdef TEST_PROCESS
|
||
|
short v_flag = 1;
|
||
|
#endif
|
||
|
|
||
|
extern GSString255Ptr __C2GSMALLOC (char *s);
|
||
|
extern char buffer[];
|
||
|
extern FILE *output_fp;
|
||
|
extern FILE *error_fp;
|
||
|
|
||
|
/*
|
||
|
* void process (char *filename, char *tmp_file, FILE *whatis_fp);
|
||
|
*
|
||
|
* 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.
|
||
|
*
|
||
|
* Post: The name, section number, and description from the man page is
|
||
|
* appended to <whatis_fp>.
|
||
|
*/
|
||
|
|
||
|
void process (char *filename, char *tmp_file, FILE *whatis_fp) {
|
||
|
|
||
|
FileInfoRecGS info_record; /* used to get the file type */
|
||
|
char *suffix; /* points to the start of the file suffix */
|
||
|
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 */
|
||
|
int sufflen; /* length of the filename suffix */
|
||
|
|
||
|
if (v_flag) fprintf(output_fp,"Working on file %s ...\n",filename);
|
||
|
|
||
|
/*
|
||
|
* get the file basename and suffix
|
||
|
*/
|
||
|
|
||
|
if ((name = malloc (strlen(filename)+1)) == NULL) {
|
||
|
if (v_flag)
|
||
|
fprintf(error_fp,"malloc failed when processing %s -- file skipped\n",
|
||
|
filename);
|
||
|
return;
|
||
|
}
|
||
|
strcpy(name,filename);
|
||
|
if ((suffix = strchr(name,'.')) == NULL) {
|
||
|
if (v_flag)
|
||
|
fprintf(error_fp,"%s has no suffix -- file skipped\n",
|
||
|
filename);
|
||
|
return;
|
||
|
}
|
||
|
*suffix = '\0';
|
||
|
suffix++;
|
||
|
sufflen = strlen(suffix);
|
||
|
|
||
|
/*
|
||
|
* find out the file type
|
||
|
*/
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Process the file according to type: nroff, aroff, freeze, and compress.
|
||
|
* The digested result is placed in buffer.
|
||
|
*/
|
||
|
|
||
|
if ((info_record.fileType == 0x50u) && (info_record.auxType == 0x8010u)) {
|
||
|
|
||
|
/* is it an Appleworks GS word processor document? Use aroff */
|
||
|
sprintf(command_buf,"aroff -b %s >%s",filename,tmp_file);
|
||
|
system(command_buf);
|
||
|
fillbuffer(tmp_file);
|
||
|
|
||
|
} else if ( (toupper(*(suffix+sufflen-1))=='Z') &&
|
||
|
(*(suffix+sufflen-2)=='.')) {
|
||
|
|
||
|
/* Compressed man page; uncompress it */
|
||
|
sprintf(command_buf,"compress -dc %s >%s",filename,tmp_file);
|
||
|
system(command_buf);
|
||
|
fillbuffer(tmp_file);
|
||
|
|
||
|
/* fix suffix for printout */
|
||
|
sufflen -= 2;
|
||
|
*(suffix + sufflen) = '\0';
|
||
|
|
||
|
} else if ( (toupper(*(suffix+sufflen-1))=='F') &&
|
||
|
(*(suffix+sufflen-2)=='.')) {
|
||
|
|
||
|
/* Frozen man page; melt it */
|
||
|
sprintf(command_buf,"freeze -dc %s >%s",filename,tmp_file);
|
||
|
system(command_buf);
|
||
|
fillbuffer(tmp_file);
|
||
|
|
||
|
/* fix suffix for printout */
|
||
|
sufflen -= 2;
|
||
|
*(suffix + sufflen) = '\0';
|
||
|
|
||
|
} else if ((toupper(*suffix)=='L') && (*(suffix+1)=='\0')) {
|
||
|
|
||
|
/* It's a link to another man page; do nothing. */
|
||
|
return;
|
||
|
|
||
|
} else {
|
||
|
|
||
|
/* Assume that it's a text file */
|
||
|
fillbuffer(filename);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
|
p1 = buffer;
|
||
|
while (isspace(*p1)) p1++;
|
||
|
namelength = strlen(name) + strlen(suffix) + 4;
|
||
|
|
||
|
if (namelength > (TABLENGTH * 3)) {
|
||
|
fprintf(whatis_fp,"%s (%s) - %s\n", name, suffix, p1);
|
||
|
} else if (namelength > (TABLENGTH * 2)) {
|
||
|
fprintf(whatis_fp,"%s (%s)\t- %s\n", name, suffix, p1);
|
||
|
} else if (namelength > TABLENGTH ) {
|
||
|
fprintf(whatis_fp,"%s (%s)\t\t- %s\n", name, suffix, p1);
|
||
|
} else {
|
||
|
fprintf(whatis_fp,"%s (%s)\t\t\t- %s\n", name, suffix, p1);
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#ifdef TEST_PROCESS
|
||
|
|
||
|
int main (int argc, char **argv) {
|
||
|
|
||
|
if (argc != 2) {
|
||
|
printf("Usage: %s <man_page_file_name>\n",argv[0]);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
process (argv[1], ":tmp:garbage", stdout);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
#endif
|