Files
nuweb/main.c

264 lines
6.5 KiB
C

#line 878 "nuweb.w"
#include "global.h"
#line 955 "nuweb.w"
#include <stdlib.h>
int main(int argc, char** argv)
{
int arg = 1;
/* Interpret command-line arguments */
#line 1113 "nuweb.w"
command_name = argv[0];
#line 1119 "nuweb.w"
while (arg < argc) {
char *s = argv[arg];
if (*s++ == '-') {
/* Interpret the argument string \verb|s| */
#line 1139 "nuweb.w"
{
char c = *s++;
while (c) {
switch (c) {
case 'c': compare_flag = FALSE;
break;
case 'd': dangling_flag = TRUE;
break;
case 'h': hyperopt_flag = TRUE;
goto HasValue;
case 'I': includepath_flag = TRUE;
goto HasValue;
case 'l': listings_flag = TRUE;
break;
case 'n': number_flag = TRUE;
break;
case 'o': output_flag = FALSE;
break;
case 'p': prepend_flag = TRUE;
goto HasValue;
case 'r': hyperref_flag = TRUE;
break;
case 's': scrap_flag = FALSE;
break;
case 't': tex_flag = FALSE;
break;
case 'v': verbose_flag = TRUE;
break;
case 'V': version_info_flag = TRUE;
goto HasValue;
case 'x': xref_flag = TRUE;
break;
default: fprintf(stderr, "%s: unexpected argument ignored. ",
command_name);
fprintf(stderr, "Usage is: %s [-cdnostvx] "
"[-I path] [-V version] "
"[-h options] [-p path] file...\n",
command_name);
break;
}
c = *s++;
}
HasValue:;
}
#line 1122 "nuweb.w"
arg++;
/* Perhaps get the prepend path */
#line 1186 "nuweb.w"
if (prepend_flag)
{
if (*s == '\0')
s = argv[arg++];
dirpath = s;
prepend_flag = FALSE;
}
#line 1124 "nuweb.w"
/* Perhaps get the version info string */
#line 1214 "nuweb.w"
if (version_info_flag)
{
if (*s == '\0')
s = argv[arg++];
version_string = s;
version_info_flag = FALSE;
}
#line 1125 "nuweb.w"
/* Perhaps get the hyperref options */
#line 1224 "nuweb.w"
if (hyperopt_flag)
{
if (*s == '\0')
s = argv[arg++];
hyperoptions = s;
hyperopt_flag = FALSE;
hyperref_flag = TRUE;
}
#line 1126 "nuweb.w"
/* Perhaps add an include path */
#line 1196 "nuweb.w"
if (includepath_flag)
{
struct incl * le
= (struct incl *)arena_getmem(sizeof(struct incl));
struct incl ** p = &include_list;
if (*s == '\0')
s = argv[arg++];
le->name = save_string(s);
le->next = NULL;
while (*p != NULL)
p = &((*p)->next);
*p = le;
includepath_flag = FALSE;
}
#line 1127 "nuweb.w"
}
else break;
}
#line 960 "nuweb.w"
/* Set locale information */
#line 1240 "nuweb.w"
{
/* try to get locale information */
char *s=getenv("LC_CTYPE");
if (s==NULL) s=getenv("LC_ALL");
/* set it */
if (s!=NULL)
if(setlocale(LC_CTYPE, s)==NULL)
fprintf(stderr, "Setting locale failed\n");
}
#line 961 "nuweb.w"
initialise_delimit_scrap_array();
/* Process the remaining arguments (file names) */
#line 1259 "nuweb.w"
{
if (arg >= argc) {
fprintf(stderr, "%s: expected a file name. ", command_name);
fprintf(stderr, "Usage is: %s [-cnotv] [-p path] file-name...\n", command_name);
exit(-1);
}
do {
/* Handle the file name in \verb|argv[arg]| */
#line 1281 "nuweb.w"
{
char source_name[FILENAME_MAX];
char tex_name[FILENAME_MAX];
char aux_name[FILENAME_MAX];
/* Build \verb|source_name| and \verb|tex_name| */
#line 1304 "nuweb.w"
{
char *p = argv[arg];
char *q = source_name;
char *trim = q;
char *dot = NULL;
char c = *p++;
while (c) {
*q++ = c;
if (PATH_SEP(c)) {
trim = q;
dot = NULL;
}
else if (c == '.')
dot = q - 1;
c = *p++;
}
/* Add the source path to the include path list */
#line 1344 "nuweb.w"
if (trim != source_name) {
struct incl * le
= (struct incl *)arena_getmem(sizeof(struct incl));
struct incl ** p = &include_list;
char sv = *trim;
*trim = '\0';
le->name = save_string(source_name);
le->next = NULL;
while (*p != NULL)
p = &((*p)->next);
*p = le;
*trim = sv;
}
#line 1320 "nuweb.w"
*q = '\0';
if (dot) {
*dot = '\0'; /* produce HTML when the file extension is ".hw" */
html_flag = dot[1] == 'h' && dot[2] == 'w' && dot[3] == '\0';
sprintf(tex_name, "%s%s%s.tex", dirpath, path_sep, trim);
sprintf(aux_name, "%s%s%s.aux", dirpath, path_sep, trim);
*dot = '.';
}
else {
sprintf(tex_name, "%s%s%s.tex", dirpath, path_sep, trim);
sprintf(aux_name, "%s%s%s.aux", dirpath, path_sep, trim);
*q++ = '.';
*q++ = 'w';
*q = '\0';
}
}
#line 1285 "nuweb.w"
/* Process a file */
#line 1370 "nuweb.w"
{
pass1(source_name);
current_sector = 1;
prev_sector = 1;
if (tex_flag) {
if (html_flag) {
int saved_number_flag = number_flag;
number_flag = TRUE;
collect_numbers(aux_name);
write_html(source_name, tex_name);
number_flag = saved_number_flag;
}
else {
collect_numbers(aux_name);
write_tex(source_name, tex_name);
}
}
if (output_flag)
write_files(file_names);
arena_free();
}
#line 1286 "nuweb.w"
}
#line 1266 "nuweb.w"
arg++;
} while (arg < argc);
}
#line 963 "nuweb.w"
exit(0);
}