home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / languages / ami_nuweb0.87c.lha / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-12  |  3.8 KB  |  135 lines

  1. #include "global.h"
  2. void main(int argc, char **argv)
  3. {
  4.   int arg = 1;
  5.   #ifdef _AMIGA
  6.   if(atexit(&CloseSystemResources))
  7.     exit(EXIT_FAILURE); /* Exit trap could not be set up */
  8.   
  9.   if(signal(SIGINT, &catch_break) == SIG_ERR)
  10.     exit(EXIT_FAILURE); /* Interrupt handler could not be set up */
  11.   
  12.   
  13.   if(LocaleBase = OpenLibrary("locale.library", 38L)) {
  14.     if(catalog = OpenCatalog(NULL, "nuweb.catalog", OC_BuiltInLanguage,
  15.                              "english", TAG_DONE)) {
  16.       for(i = MSG_WARNING_11B; i <= MSG_ERROR_62A2; i++)
  17.         AppStrings[i].as_Str = GetCatalogStr(catalog, i, AppStrings[i].as_Str);
  18.     }
  19.   }
  20.   #endif
  21.   
  22.   command_name = argv[0];
  23.   while (arg < argc) {
  24.     char *s = argv[arg];
  25.     if (*s++ == '-') {
  26.       {
  27.         char c = *s++;
  28.         while (c) {
  29.           switch (c) {
  30.             case 'c': compare_flag = FALSE;
  31.                       break;
  32.             case 'n': number_flag = TRUE;
  33.                       break;
  34.             case 'o': output_flag = FALSE;
  35.                       break;
  36.             case 't': tex_flag = FALSE;
  37.                       break;
  38.             case 'v': verbose_flag = TRUE;
  39.                       break;
  40.       #ifdef _AMIGA
  41.             default:  fprintf(stderr, get_string(MSG_WARNING_11B), command_name);
  42.                       fprintf(stderr, get_string(MSG_USAGE_11B), command_name);
  43.       #else
  44.             default:  fprintf(stderr, "%s: unexpected argument ignored.  ",
  45.                               command_name);
  46.                       fprintf(stderr, "Usage is: %s [-cnotv] file...\n",
  47.                               command_name);
  48.       #endif
  49.                       break;
  50.           }
  51.           c = *s++;
  52.         }
  53.       }
  54.       arg++;
  55.     }
  56.     else break;
  57.   }
  58.   {
  59.     if (arg >= argc) {
  60.   #ifdef _AMIGA
  61.       fprintf(stderr, get_string(MSG_ERROR_11C), command_name);
  62.       fprintf(stderr, get_string(MSG_USAGE_11B), command_name);
  63.   #else
  64.       fprintf(stderr, "%s: expected a file name.  ", command_name);
  65.       fprintf(stderr, "Usage is: %s [-cnotv] file-name...\n", command_name);
  66.   #endif
  67.       exit(EXIT_FAILURE);
  68.     }
  69.     do {
  70.       {
  71.         char source_name[100];
  72.         char tex_name[100];
  73.         char aux_name[100];
  74.         {
  75.           char *p = argv[arg];
  76.           char *q = source_name;
  77.           char *trim = q;
  78.           char *dot = NULL;
  79.           char c = *p++;
  80.           while (c) {
  81.             *q++ = c;
  82.         #ifdef _AMIGA
  83.             if ((c == '/') || (c == ':')) {
  84.         #else
  85.             if (c == '/') {
  86.         #endif
  87.               trim = q;
  88.               dot = NULL;
  89.             }
  90.             else if (c == '.')
  91.               dot = q - 1;
  92.             c = *p++;
  93.           }
  94.           *q = '\0';
  95.           if (dot) {
  96.             *dot = '\0'; /* produce HTML when the file extension is ".hw" */
  97.             html_flag = dot[1] == 'h' && dot[2] == 'w' && dot[3] == '\0';
  98.             sprintf(tex_name, "%s.tex", trim);
  99.             sprintf(aux_name, "%s.aux", trim);
  100.             *dot = '.';
  101.           }
  102.           else {
  103.             sprintf(tex_name, "%s.tex", trim);
  104.             sprintf(aux_name, "%s.aux", trim);
  105.             *q++ = '.';
  106.             *q++ = 'w';
  107.             *q = '\0';
  108.           }
  109.         }
  110.         {
  111.           pass1(source_name);
  112.           if (tex_flag) {
  113.             if (html_flag) {
  114.               int saved_number_flag = number_flag;
  115.               number_flag = TRUE;
  116.               collect_numbers(aux_name);
  117.               write_html(source_name, tex_name);
  118.               number_flag = saved_number_flag;
  119.             }
  120.             else {
  121.               collect_numbers(aux_name);
  122.               write_tex(source_name, tex_name);
  123.             }
  124.           }
  125.           if (output_flag)
  126.             write_files(file_names);
  127.           arena_free();
  128.         }
  129.       }
  130.       arg++;
  131.     } while (arg < argc);
  132.   }
  133.   
  134.   exit(EXIT_SUCCESS);