home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / PUT_LANG.C < prev    next >
C/C++ Source or Header  |  1998-05-17  |  3KB  |  98 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.  
  21. #include "language.h"
  22.  
  23. /*
  24.  * put_language -- store compiled language file
  25.  *
  26.  * This is a simple four step operation
  27.  *
  28.  * 1. Open file for write
  29.  * 2. Write out the used part of the fixup array
  30.  * 3. Write out the used part of the memory block
  31.  * 4. Close the file
  32.  *
  33.  */
  34.  
  35. int put_language (name_of_file)
  36. char *name_of_file;
  37. {
  38.     FILE           *fpt;                        /* stream pointer            */
  39.     int             error;                      /* Internal error value      */
  40.     int             wanna_write;                /* How many we wanna write   */
  41.     int             written;                    /* How many we really write  */
  42.  
  43.    /*
  44.     * Open the file for output now.
  45.     *
  46.     */
  47.  
  48.  
  49.     fpt = fopen (name_of_file, "wb");           /* Open the file             */
  50.     if (fpt == NULL)                            /* Were we successful?       */
  51.         {
  52.         fprintf (stderr, "Can not open output file %s\n", name_of_file);
  53.         return (-1);                            /* Return failure to caller  */
  54.         }
  55.  
  56.    /*
  57.     * OK. Looking good so far. Write out the pointer array.
  58.     * Don't forget that last NULL pointer to terminate it!
  59.     *
  60.     */
  61.  
  62.     wanna_write = 1 + pointer_size;             /* Number of things to write */
  63.     written = fwrite ((char *)pointers, sizeof (char *), wanna_write, fpt);
  64.     if (written != wanna_write)
  65.         {
  66.         fprintf (stderr, "Unable to write fixup array to output file\n");
  67.         fclose (fpt);
  68.         return (-2);
  69.         }
  70.  
  71.    /*
  72.     * Pointer array is there. Now write out the characters.
  73.     *
  74.     */
  75.  
  76.     wanna_write = memory_size;                  /* Number of chars to write  */
  77.     written = fwrite (memory, sizeof (char), wanna_write, fpt);
  78.     if (written != wanna_write)
  79.         {
  80.         fprintf (stderr, "Unable to write characters to output file\n");
  81.         fclose (fpt);
  82.         return (-3);
  83.         }
  84.  
  85.    /*
  86.     * Everything's there now. Close the file.
  87.     */
  88.  
  89.     error = fclose (fpt);
  90.     if (error != 0)
  91.         {
  92.         fprintf (stderr, "Unable to properly close output file %s\n",name_of_file);
  93.         return (-4);
  94.         }
  95.  
  96.     return (0);
  97. }
  98.