home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / PUT_LANG.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  10KB  |  258 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-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*            BinkleyTerm Language Compiler File Output Module              */
  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.250.    */
  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:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.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.  
  49. #include "language.h"
  50.  
  51. /*
  52.  * put_language -- store compiled language file
  53.  *
  54.  * This is a simple four step operation
  55.  *
  56.  * 1. Open file for write
  57.  * 2. Write out the used part of the fixup array
  58.  * 3. Write out the used part of the memory block
  59.  * 4. Close the file
  60.  *
  61.  */
  62.  
  63. int put_language (char *name_of_file)
  64. {
  65.     FILE           *fpt;                        /* stream pointer            */
  66.     int             error;                      /* Internal error value      */
  67.     int             wanna_write;                /* How many we wanna write   */
  68.     int             written;                    /* How many we really write  */
  69.     long            total_length;
  70.  
  71.    /*
  72.     * Open the file for output now.
  73.     *
  74.     */
  75.  
  76.  
  77.     fpt = fopen (name_of_file, "wb");           /* Open the file             */
  78.     if (fpt == NULL)                            /* Were we successful?       */
  79.         {
  80.         fprintf (stderr, "Can not open output file %s\n", name_of_file);
  81.         return (-1);                            /* Return failure to caller  */
  82.         }
  83.  
  84.    /*
  85.     * OK. Looking good so far. Write out the pointer array.
  86.     * Don't forget that last NULL pointer to terminate it!
  87.     *
  88.     */
  89.  
  90.     wanna_write = pointer_size;                 /* Number of things to write */
  91.                                              /* Write the string table count */
  92.                                                    /* and string memory size */
  93.     LangHdr.ElemCnt = wanna_write;
  94.     LangHdr.PoolSize = memory_size;
  95.     written = fwrite ((char *)&LangHdr, sizeof (struct _lang_hdr), 1, fpt);
  96.     if (written != 1 )
  97.         {
  98.         fprintf (stderr, "Unable to language file header\n");
  99.         fclose (fpt);
  100.         return (-2);
  101.         }
  102.     written = fwrite ((char *)pointers, sizeof (char *), wanna_write, fpt);
  103.     if (written != wanna_write)
  104.         {
  105.         fprintf (stderr, "Unable to write fixup array to output file\n");
  106.         fclose (fpt);
  107.         return (-2);
  108.         }
  109.    fprintf (stderr, "Pointer Table Elements: %d\n", wanna_write);
  110.  
  111.    /*
  112.     * Pointer array is there. Now write out the characters.
  113.     *
  114.     */
  115.  
  116.     wanna_write = memory_size;                  /* Number of chars to write  */
  117.     written = fwrite (memory, sizeof (char), wanna_write, fpt);
  118.     if (written != wanna_write)
  119.         {
  120.         fprintf (stderr, "Unable to write characters to output file\n");
  121.         fclose (fpt);
  122.         return (-3);
  123.         }
  124.    /*
  125.     * Write the terminal mode remap table, first the count,
  126.     * then the table itself.
  127.     */
  128.  
  129.     written = fwrite ((char *)&TrmnlAccelCnt, sizeof (int), 1, fpt);
  130.     if (written != 1)
  131.         {
  132.         fprintf (stderr, "Unable to write Terminal Accel Count\n");
  133.         fclose (fpt);
  134.         return (-2);
  135.         }
  136.     wanna_write = TrmnlAccelCnt;
  137.  
  138.     written = fwrite ((char *)TrmnlAccelTbl,
  139.                       sizeof (struct _key_fnc),
  140.                       wanna_write,
  141.                       fpt);
  142.  
  143.     if (written != wanna_write)
  144.         {
  145.         fprintf (stderr, "Unable to write terminal accel array to output file\n");
  146.         fclose (fpt);
  147.         return (-2);
  148.         }
  149.  
  150.     fprintf (stderr, "Terminal Mode Remap Table Size: %d\n", wanna_write);
  151.  
  152.    /* 
  153.     * Write the unattended mode remap table, first, the count,
  154.     * then the table itself.
  155.     */
  156.  
  157.     written = fwrite ((char *)&UnattendedAccelCnt, sizeof(int), 1, fpt);
  158.     if (written != 1 )
  159.         {
  160.         fprintf (stderr, "Unable to Write Unattended Accel Count\n");
  161.         fclose (fpt);
  162.         return (-2);
  163.         }
  164.     wanna_write = UnattendedAccelCnt;
  165.  
  166.     written = fwrite ((char *)UnattendedAccelTbl,
  167.                       sizeof (struct _key_fnc),
  168.                       wanna_write,
  169.                       fpt);
  170.  
  171.     if (written != wanna_write)
  172.         {
  173.         fprintf (stderr, "Unable to write terminal accel array to output file\n");
  174.         fclose (fpt);
  175.         return (-2);
  176.         }
  177.  
  178.     fprintf (stderr, "Unattended Mode Remap Table Size: %d\n", wanna_write);
  179.  
  180.    /*
  181.     * Write the product code table, first the string table count and
  182.     * string memory size, then the pointer array.
  183.     */
  184.  
  185.     written = fwrite ((char *)&PrdctHdr, sizeof (struct _lang_hdr), 1, fpt);
  186.     if (written != 1 )
  187.         {
  188.         fprintf (stderr, "Unable to write product code header\n");
  189.         fclose (fpt);
  190.         return (-2);
  191.         }
  192.  
  193.     wanna_write = PrdctHdr.ElemCnt;         /* Number of things to write */
  194.     written = fwrite ((char *)PrdctTbl, sizeof (char *), wanna_write, fpt);
  195.     if (written != wanna_write)
  196.         {
  197.         fprintf (stderr, "Unable to write prdct fixup array to output file\n");
  198.         fclose (fpt);
  199.         return (-2);
  200.         }
  201.    /*
  202.     * Pointer array is there. Now write out the characters.
  203.     *
  204.     */
  205.  
  206.     wanna_write = PrdctHdr.PoolSize;           /* Number of chars to write  */
  207.     written = fwrite (PrdctMem, sizeof (char), wanna_write, fpt);
  208.     if (written != wanna_write)
  209.         {
  210.         fprintf (stderr, "Unable to write characters to output file\n");
  211.         fclose (fpt);
  212.         return (-3);
  213.         }
  214.  
  215.     fprintf (stderr, "Product Code Table Size: %d\n", PrdctHdr.ElemCnt);
  216.  
  217.    /*
  218.     * Write out the ANSI table.
  219.     */
  220.  
  221.     written = fwrite ((char *)&AnsiHdr, sizeof (struct _lang_hdr), 1, fpt);
  222.     if (written != 1 )
  223.         {
  224.         fprintf (stderr, "Unable to write ANSI map header\n");
  225.         fclose (fpt);
  226.         return (-2);
  227.         }
  228.  
  229.     wanna_write = AnsiHdr.PoolSize;
  230.     written = fwrite (AnsiMem, sizeof (char), wanna_write, fpt);
  231.     if (written != wanna_write)
  232.         {
  233.         fprintf (stderr, "Unable to write characters to output file\n");
  234.         fclose (fpt);
  235.         return (-3);
  236.         }
  237.  
  238.     fprintf (stderr, "ANSI Translate Table Size: %d\n", AnsiHdr.ElemCnt);
  239.  
  240.    /*
  241.     * Everything's there now. Close the file.
  242.     */
  243.  
  244.     total_length = ftell (fpt);
  245.  
  246.     fprintf (stderr, "Size of complete table: %ld\n", total_length);
  247.  
  248.     error = fclose (fpt);
  249.     if (error != 0)
  250.         {
  251.         fprintf (stderr, "Unable to properly close output file %s\n",name_of_file);
  252.         return (-4);
  253.         }
  254.  
  255.     return (0);
  256. }
  257.  
  258.