home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / loralng.c < prev    next >
C/C++ Source or Header  |  1998-08-01  |  4KB  |  157 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <io.h>
  22. #include <fcntl.h>
  23. #include <string.h>
  24.  
  25. #include "lsetup.h"
  26. #include "language.h"
  27. #include "version.h"
  28.  
  29. /*
  30.  * Assume average length of a string at 32 characters
  31.  *
  32.  */
  33.  
  34. #define MAX_STRINGS 1000
  35. #define MAX_MEMORY (MAX_STRINGS * 32)
  36.  
  37. char **pointers;
  38. int pointer_size;
  39.  
  40. char *memory;
  41. int memory_size;
  42.  
  43.  
  44. /*
  45.  * Read in a raw text file and write out a compiled BinkleyTerm
  46.  * language file.
  47.  *
  48.  */
  49.  
  50. void process_language (type, mpath)
  51. char *type, *mpath;
  52. {
  53.     char *malloc_target, fn[50];
  54.     int error;
  55.  
  56.    /*
  57.     * Print out the copyright notice.
  58.     */
  59.  
  60.    printf ("* Compile the %s Language File\n", type);
  61.  
  62.    /*
  63.     * Allocate space for the raw character array and for the
  64.     * pointer array
  65.     *
  66.     */
  67.  
  68.     malloc_target = malloc (MAX_MEMORY);
  69.     if (malloc_target == NULL)
  70.         {
  71.         fprintf (stderr, "* Unable to allocate string memory\n");
  72.         exit (250);
  73.         }
  74.     memory = malloc_target;
  75.     memory_size = MAX_MEMORY;
  76.  
  77.     malloc_target = malloc ((MAX_STRINGS + 1) * (sizeof (char *)));
  78.     if (malloc_target == NULL)
  79.         {
  80.         fprintf (stderr, "* Unable to allocate pointer array\n");
  81.         exit (250);
  82.         }
  83.     pointers = (char **)malloc_target;
  84.     pointer_size = MAX_STRINGS;
  85.  
  86.  
  87.    /*
  88.     * Now read the stuff into our array.
  89.     *
  90.     */
  91.  
  92.     sprintf(fn, "%s%s.TXT", mpath, type);
  93.     error = get_language (fn);
  94.     if (error != 0)
  95.        exit (240);
  96.  
  97.  
  98.    /*
  99.     * Write our stuff out now.
  100.     *
  101.     */
  102.  
  103.     sprintf(fn, "%s%s.LNG", mpath, type);
  104.     error = put_language (fn);
  105.     if (error != 0)
  106.        exit (230);
  107.  
  108.     free (memory);
  109.     free (pointers);
  110. }
  111.  
  112. struct _configuration config;
  113.  
  114. void main (argc, argv)
  115. int argc;
  116. char *argv[];
  117. {
  118.    int fd, i, doit;
  119.  
  120.    printf("\nLANGCOMP; LoraBBS-OS/2 Language compiler, Version %s\n", LANGCOMP_VERSION);
  121.    printf("          Copyright (c) 1991-96 by Marco Maccaferri, All Rights Reserved\n\n");
  122.  
  123.    fd = open ("CONFIG.DAT", O_RDONLY|O_BINARY);
  124.    if (fd != -1) {
  125.       read (fd, &config, sizeof (struct _configuration));
  126.       close (fd);
  127.    }
  128.  
  129.    doit = 1;
  130.  
  131.    if (argc > 1) {
  132.       for (i = 1; i < argc; i++) {
  133.          if (!strnicmp (argv[i], "-C", 2)) {
  134.             fd = open ((char *)&argv[i][2], O_RDONLY|O_BINARY);
  135.             if (fd != -1) {
  136.                read (fd, &config, sizeof (struct _configuration));
  137.                close (fd);
  138.             }
  139.             else
  140.                fprintf (stderr, "* Configuration file '%s' not found.\n", (char *)&argv[i][2]);
  141.          }
  142.          else {
  143.             process_language (argv[i], config.menu_path);
  144.             doit = 0;
  145.          }
  146.       }
  147.    }
  148.  
  149.    if (doit) {
  150.       for (i = 0; i < MAX_LANG; i++) {
  151.          if (config.language[i].basename[0])
  152.             process_language (config.language[i].basename, config.menu_path);
  153.       }
  154.    }
  155. }
  156.  
  157.