home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / PUT_LANG.C < prev    next >
C/C++ Source or Header  |  1990-07-01  |  6KB  |  125 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 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.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.  
  48. #include "language.h"
  49.  
  50. /*
  51.  * put_language -- store compiled language file
  52.  *
  53.  * This is a simple four step operation
  54.  *
  55.  * 1. Open file for write
  56.  * 2. Write out the used part of the fixup array
  57.  * 3. Write out the used part of the memory block
  58.  * 4. Close the file
  59.  *
  60.  */
  61.  
  62. int put_language (name_of_file)
  63. 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.  
  70.    /*
  71.     * Open the file for output now.
  72.     *
  73.     */
  74.  
  75.  
  76.     fpt = fopen (name_of_file, "wb");           /* Open the file             */
  77.     if (fpt == NULL)                            /* Were we successful?       */
  78.         {
  79.         fprintf (stderr, "Can not open output file %s\n", name_of_file);
  80.         return (-1);                            /* Return failure to caller  */
  81.         }
  82.  
  83.    /*
  84.     * OK. Looking good so far. Write out the pointer array.
  85.     * Don't forget that last NULL pointer to terminate it!
  86.     *
  87.     */
  88.  
  89.     wanna_write = 1 + pointer_size;             /* Number of things to write */
  90.     written = fwrite ((char *)pointers, sizeof (char *), wanna_write, fpt);
  91.     if (written != wanna_write)
  92.         {
  93.         fprintf (stderr, "Unable to write fixup array to output file\n");
  94.         fclose (fpt);
  95.         return (-2);
  96.         }
  97.  
  98.    /*
  99.     * Pointer array is there. Now write out the characters.
  100.     *
  101.     */
  102.  
  103.     wanna_write = memory_size;                  /* Number of chars to write  */
  104.     written = fwrite (memory, sizeof (char), wanna_write, fpt);
  105.     if (written != wanna_write)
  106.         {
  107.         fprintf (stderr, "Unable to write characters to output file\n");
  108.         fclose (fpt);
  109.         return (-3);
  110.         }
  111.  
  112.    /*
  113.     * Everything's there now. Close the file.
  114.     */
  115.  
  116.     error = fclose (fpt);
  117.     if (error != 0)
  118.         {
  119.         fprintf (stderr, "Unable to properly close output file %s\n",name_of_file);
  120.         return (-4);
  121.         }
  122.  
  123.     return (0);
  124. }
  125.