home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / LANGLOAD.C < prev    next >
C/C++ Source or Header  |  1990-07-06  |  7KB  |  195 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                    BinkleyTerm Language File Loader                      */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n132.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <sys/types.h>
  49. #include <sys/stat.h>
  50. #include <string.h>
  51.  
  52. #define LANGFILE "BINKLEY.LNG"
  53.  
  54. #ifdef __TURBOC__
  55. #include <alloc.h>
  56. #else
  57. #include <malloc.h>
  58. #endif
  59.  
  60. #include "com.h"
  61. #include "xfer.h"
  62. #include "zmodem.h"
  63. #include "keybd.h"
  64. #include "sbuf.h"
  65. #include "sched.h"
  66. #include "externs.h"
  67. #include "prototyp.h"
  68. #include "msgs.h"
  69.  
  70. /*
  71.  * Read the compiled BinkleyTerm Language file.
  72.  *
  73.  */
  74.  
  75. int load_language (void)
  76. {
  77.     int pointer_size;
  78.     char *memory;
  79.     unsigned int memory_size;
  80.     char *malloc_target;
  81.     char *envptr;
  82.     char LANGpath[128];
  83.     int error;
  84.     int i;
  85.     int read;
  86.     struct stat stbuf;
  87.     FILE           *fpt;                         /* stream pointer           */
  88.  
  89.    envptr = getenv ("BINKLEY");                  /* get path from environment*/
  90.    if ((envptr != NULL)                          /* If there was one, and    */
  91.        && (!dexists (LANGFILE)))                 /* No local language file,  */
  92.       {
  93.       (void) strcpy (LANGpath, envptr);          /* use BINKLEY as our path  */
  94.       (void) add_backslash (LANGpath);
  95.       }
  96.    else
  97.       LANGpath[0] = '\0';
  98.  
  99.    strcat (LANGpath, LANGFILE);
  100.  
  101.    /*
  102.     * Get some info about the file
  103.     */
  104.  
  105.     error = stat (LANGpath, &stbuf);
  106.     if (error != 0)
  107.         {
  108.         fprintf (stderr, "Cannot get information on file %s\n",LANGpath);
  109.         exit (250);
  110.         }
  111.  
  112.    /*
  113.     * Allocate space for the raw character array and for the
  114.     * pointer and fixup arrays
  115.     *
  116.     */
  117.  
  118.     memory_size = (unsigned int) stbuf.st_size;
  119.  
  120.     malloc_target = malloc (memory_size);
  121.     if (malloc_target == NULL)
  122.         {
  123.         fprintf (stderr, "Unable to allocate string memory\n");
  124.         exit (250);
  125.         }
  126.  
  127.    /*
  128.     * Open the input file
  129.     *
  130.     */
  131.  
  132.     fpt = fopen (LANGpath, "rb");               /* Open the file             */
  133.     if (fpt == NULL)                            /* Were we successful?       */
  134.         {
  135.         fprintf (stderr, "Can not open input file %s\n", LANGpath);
  136.         exit (250);
  137.         }
  138.  
  139.    /*
  140.     * Read the entire file into memory now.
  141.     *
  142.     */
  143.  
  144.     read = fread (malloc_target, 1, memory_size, fpt);
  145.     if (read != memory_size)
  146.         {
  147.         fprintf (stderr, "Could not read language data from file %s\n",LANGpath);
  148.         fclose (fpt);
  149.         exit (250);
  150.         }
  151.  
  152.    /*
  153.     * Close the file.
  154.     *
  155.     */
  156.  
  157.     error = fclose (fpt);
  158.     if (error != 0)
  159.         {
  160.         fprintf (stderr, "Unable to close language file %s\n",LANGpath);
  161.         exit (250);
  162.         }
  163.  
  164.    /*
  165.     * Do fixups on the string pointer array as follows:
  166.     *
  167.     * 1. Find the NULL pointer in the mess here.
  168.     * 2. Start of the string memory is the "following pointer".
  169.     * 3. Apply arithmetic correction to entire array.
  170.     *
  171.     */
  172.  
  173.     msgtxt = (char **) malloc_target;
  174.     for (i = 0; msgtxt[i] != NULL; i++)         /* Find NULL marker in array */
  175.         ;
  176.  
  177.     pointer_size = i - 1;                       /* Count of elements w/o NULL*/
  178.     if (pointer_size != X_TOTAL_MSGS)
  179.         {
  180.         fprintf (stderr, "Count of %d from file does not match %d required\n",
  181.                     pointer_size, X_TOTAL_MSGS);
  182.         exit (250);
  183.         }
  184.  
  185.     memory = (char *) &msgtxt[++i];             /* Text starts after NULL    */
  186.  
  187.     for (i = 1; i <= pointer_size; i++)
  188.         {
  189.         msgtxt[i] = memory + (msgtxt[i] - msgtxt[0]);
  190.         }
  191.  
  192.     msgtxt[0] = memory;
  193.     return (1);
  194. }
  195.