home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN325SRC.ZIP / makenl-3.2.5 / src / output.c < prev    next >
C/C++ Source or Header  |  2005-02-06  |  4KB  |  123 lines

  1. /* $Id: output.c,v 1.6 2004/07/15 17:44:02 ozzmosis Exp $ */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #include "makenl.h"
  8. #include "fts5.h"
  9. #include "crc16.h"
  10. #include "fileutil.h"
  11.  
  12. #ifdef MALLOC_DEBUG
  13. #include "rmalloc.h"
  14. #endif
  15.  
  16. #ifdef DMALLOC
  17. #include "dmalloc.h"
  18. #endif
  19.  
  20. char ErrorMessage[linelength];
  21.  
  22. int
  23. OutputErrorLine(FILE * file, const char *pre, const char *wrongy,
  24.                 const char *post, unsigned short *crc)
  25. {
  26.     char *linebuf;
  27.     int fputs_result;
  28.  
  29.     if (FTS5Keyword)            /* Do we have an Nodelist line to be
  30.                                    printed also? */
  31.         if (OutputFTS5Line(file, pre, post, crc) == EOF)
  32.             return EOF;
  33.  
  34.     linebuf = malloc(strlen(pre) +
  35.                      strlen(wrongy) + 4 +
  36.                      strlen(ErrorMessage) + strlen(post) + 1);
  37.     if (!linebuf)
  38.         die(253, 1, "No memory left for error message buffer!\n");
  39.     sprintf(linebuf, "%s%s -- %s%s", pre, wrongy, ErrorMessage, post);
  40.     if (crc)
  41.         *crc = CRC16String(linebuf, *crc);
  42.     fputs_result = fputs(linebuf, file);
  43.     free(linebuf);
  44.     return fputs_result;
  45. }
  46.  
  47. int
  48. OutputFTS5Line(FILE * file, const char *prefix, const char *postfix,
  49.                unsigned short *crc)
  50. {
  51.     char *linebuf;
  52.     int fputs_result;
  53.  
  54.     linebuf = malloc(strlen(prefix) +
  55.                      strlen(FTS5Keyword) + 1 +
  56.                      strlen(FTS5Number) + 1 +
  57.                      strlen(FTS5Nodename) + 1 +
  58.                      strlen(FTS5Sysopname) + 1 +
  59.                      strlen(FTS5Location) + 1 +
  60.                      strlen(FTS5Phone) + 1 +
  61.                      strlen(FTS5Baud) + 1 +
  62.                      strlen(FTS5Flags) + strlen(postfix) + 1);
  63.     sprintf(linebuf, "%s%s,%s,%s,%s,%s,%s,%s,%s%s", prefix,
  64.             FTS5Keyword, FTS5Number, FTS5Nodename, FTS5Location,
  65.             FTS5Sysopname, FTS5Phone, FTS5Baud, FTS5Flags, postfix);
  66.     if (crc != NULL)
  67.         *crc = CRC16String(linebuf, *crc);
  68.     fputs_result = fputs(linebuf, file);
  69.     free(linebuf);
  70.     return fputs_result;
  71. }
  72.  
  73. int
  74. CopyComment(FILE * output, char *Copyfile, const char *year,
  75.             unsigned short *crc)
  76.  /* Returns the number of lines written */
  77. {
  78.     const char *yearread;
  79.     char *yearwrite;
  80.     char yearcharbuf;
  81.     char *linebegin;
  82.     int lineno = 0;
  83.     FILE *CopyFILE;
  84.     char fullname[MYMAXDIR];
  85.     char linebuf[linelength];
  86.  
  87.     if (!Copyfile)
  88.         return lineno;
  89.     myfnmerge(fullname, NULL, MasterDir, Copyfile, NULL);
  90.     strcpy(linebuf, ";S");
  91.     CopyFILE = fopen(fullname, "r");
  92.     if (!CopyFILE)
  93.         return lineno;
  94.     while ((linebegin =
  95.             fgets(linebuf + 3, linelength - 3, CopyFILE)) != NULL)
  96.     {
  97.         if (linebegin[0] != ';')
  98.         {
  99.             linebegin = linebuf;
  100.             linebegin[2] = ' '; /* Kill the '\0' after ";S" */
  101.         }
  102.         if (linebegin[1] == 'E')
  103.             linebegin[1] = 'S';
  104.         if (year != NULL)
  105.         {
  106.             if ((yearwrite = strstr(linebegin, "####")) != NULL)
  107.             {
  108.                 for (yearread = year, yearcharbuf = *(yearread++);
  109.                      yearcharbuf; yearcharbuf = *(yearread++))
  110.                     *(yearwrite++) = yearcharbuf;
  111.             }
  112.         }
  113.         cutspaces(linebegin);
  114.         strcat(linebegin, "\r\n");
  115.         *crc = CRC16String(linebegin, *crc);
  116.         if (fputs(linebegin, output) == EOF)
  117.             die(254, 1, "Write error on \"%s\"", OutFile);
  118.         lineno++;
  119.     }
  120.     fclose(CopyFILE);
  121.     return lineno;
  122. }
  123.