home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / comm / bbs / eazybbs / source / eazy2news_direct.c < prev    next >
C/C++ Source or Header  |  1994-09-08  |  3KB  |  120 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8.  
  9.  
  10.  
  11. /* ... from AmigaElm */
  12. #include "getsystime.c"
  13.  
  14.  
  15.  
  16. #define VERSION "1.7"
  17. static char *version = "\0$VER: eazy2news " VERSION " (" __AMIGADATE__ ")";
  18. static char *day_names[] =
  19. {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  20. static char *month_names[] =
  21. {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  22.  
  23.  
  24.  
  25. void space2under(char *s)
  26. {
  27.     while (s && *s) {
  28.         if (*s == ' ')
  29.             *s = '_';
  30.         s++;
  31.     }
  32. }
  33.  
  34.  
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38.     if (argc == 7 && OpenTimer4MsgId()) {
  39.         char tmp[80];
  40.         FILE *fp;
  41.  
  42.         sprintf(tmp, "%s%ld", "MB_TMP:Eazy2News.tmp", (long) FindTask(NULL));
  43.  
  44.         if (fp = fopen(tmp, "w")) {
  45.             register int c = 0, last = 0;
  46.             time_t t;
  47.             struct timeval tv;
  48.             struct tm *ut;
  49.             char uname[16];
  50.             char *sname = argv[3];
  51.             char *ngrps = argv[1];
  52.             char *excld = argv[2];
  53.             char *realn = argv[5];
  54.             char *sbjct = argv[6];
  55.             char exec[256];
  56.  
  57.             /* for Date: */
  58.             time(&t);
  59.             ut = gmtime(&t);
  60.  
  61.             /* for Message-Id: */
  62.             GetTimer4MsgId(&tv);
  63.  
  64.             strcpy(uname, argv[4]);
  65.             space2under(uname);
  66.  
  67.             fprintf(fp, "Path: news\n");
  68.             fprintf(fp, "Newsgroups: %s\n", ngrps);
  69.             fprintf(fp, "From: %s@%s (%s)\n", uname, sname, realn);
  70.             fprintf(fp, "Sender: eazybbs@%s\n", sname);
  71.             fprintf(fp, "Subject: %s\n", sbjct);
  72.             fprintf(fp, "Message-Id: <%lx.%lx-eazybbs@%s>\n", tv.tv_secs, tv.tv_micro, sname);
  73.             fprintf(fp, "Date: %s, %.2d %s %d %.2d:%.2d:%.2d %sGMT\n",
  74.                 day_names[ut->tm_wday],
  75.                 ut->tm_mday, month_names[ut->tm_mon], ut->tm_year + 1900,
  76.                 ut->tm_hour, ut->tm_min, ut->tm_sec, ut->tm_isdst ? "DST" : "");
  77.             fprintf(fp, "MIME-Version: 1.0\n");
  78.             fprintf(fp, "Content-Type: text/plain; charset=ISO-8859-1\n");
  79.             fprintf(fp, "Content-Transfer-Encoding: 8bit\n");
  80.             fprintf(fp, "\n");
  81.  
  82.             while ((c = getchar()) != EOF) {
  83.                 if (last == '\\') {
  84.                     switch (c) {
  85.                     case '\\':
  86.                         fputc(c, fp);
  87.                         break;
  88.                     default:
  89.                         break;
  90.                     }
  91.                     last = 0;
  92.                 }
  93.                 else if (c == '\\') {
  94.                     last = c;
  95.                 }
  96.                 else {
  97.                     fputc(c, fp);
  98.                     last = c;
  99.                 }
  100.             }
  101.             fprintf(fp, "\n");
  102.  
  103.             fclose(fp);
  104.  
  105.             sprintf(exec, "relaynews -x %s -r -s <%s", excld, tmp);
  106.             System(exec, NULL);
  107.             DeleteFile(tmp);
  108.         }
  109.  
  110.         CloseTimer4MsgId();
  111.  
  112.     }
  113.     else {
  114.         fprintf(stderr, "\033[1;33mEazyBBS\033[0m © 1988-1994 Andreas M. Kirchwitz\n"
  115.             "Usage: eazy2news \033[3m<newsgroup> <excl-cmd> <site> <user> <real> <subject> \033[0m <text\n");
  116.     }
  117.  
  118.     exit(0);
  119. }
  120.