/*
* HelpPC Reference Library to HTML converter. Ver 1.02
*
* Copyleft (l) Stanislav Sokolov (stanisls@gmail.com)
* The source is published under GNU General Public Licence
* ver. 2 of June 1991.
*
* Visit on-line version on:
* http://heim.ifi.uio.no/~stanisls/helppc/
*
* NOTE: If you want to make HTML version using UNIX, convert first
* all TXT files so that they have UNIX-style new-line.
*
* Revision History
* ----------------
* 2022 May 31 - Increased the maximum file path to 4095 bytes, and
* removed a double free call.
*/
#include
#include
#include
#include
#include
#include
#define BASE_PATH "helppc"
#define MAX_LINE_LENGTH 1024
#define MAX_FILENAME_LENGTH 100
#define MAX_PATH_LENGTH 4095
#define MAX_INDEX_TITLE_LENGTH 45
struct conv {
char *file;
char *orig;
struct conv *next;
};
struct conv *c_head;
void cleanLine(char *);
char *makeFile(char *);
void rmFirst(char *);
char *makeFName(char *);
void convError(char *);
void parseLine(char *);
int buildConv(int argc, char **argv);
void strlower(char *x);
void freeTable(struct conv *);
void idxSortWrt(struct conv[], int, FILE *);
void _qsort(struct conv c_list[], int first, int last);
int main(int argc, char **argv) {
FILE *f = NULL, *fout = NULL;
char *tmp, *fName;
char foutname[MAX_FILENAME_LENGTH + 1];
int i;
char first;
int pending = 0, files;
fprintf(stderr, "\nHelpPC Reference Library to HTML converter. Ver 1.02\n"
"Copyleft (l) Stanislav Sokolov\n\n");
if (argc == 1) {
fprintf(stderr,
"Usage:\n %s [file.txt [file2.txt [...]]]\n"
"or\n %s *.txt\n\n",
argv[0], argv[0]);
return 10;
}
mkdir(BASE_PATH, 0777);
/* Build conversion table */
fprintf(stderr, "Building conversion table and index files...\n");
i = buildConv(argc, argv);
fprintf(stderr, "Found %d keywords corresponding to %d unique entries.\n",
i >> 16, i & 0xFFFF);
/* Parse the files */
for (files = 1; files < argc; files++) { // For all files given to function
char line[MAX_LINE_LENGTH + 1] = {0};
if ((f = fopen(argv[files], "r")) == NULL) {
fprintf(stderr, "Error opening %s\n", argv[files]);
exit(100);
}
fprintf(stderr, "\nParsing %s...\n", argv[files]);
while (fgets(line, MAX_LINE_LENGTH, f) != NULL) {
cleanLine(line);
if (strnlen(line, MAX_LINE_LENGTH)) {
line[strnlen(line, MAX_LINE_LENGTH) - 1] = '\0'; // Strip the newline
}
first = line[0];
if (first == '@') {
/* do nothing */
} else if (first == ':') { /*Make new html file*/
if (pending) {
fprintf(fout, "\n\n