home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / bbs / eazybbs / source / news2eazy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-12  |  2.9 KB  |  152 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. #define VERSION "1.8"
  12. static char *version = "\0$VER: news2eazy " VERSION " " __AMIGADATE__ "";
  13. /* static char *version = "\0$VER: news2eazy " VERSION " (" __DATE__ ")"; */
  14.  
  15.  
  16.  
  17. void space2under(char *s)
  18. {
  19.     while (s && *s) {
  20.         if (*s == ' ')
  21.             *s = '_';
  22.         s++;
  23.     }
  24. }
  25.  
  26.  
  27.  
  28. void kill_quotes(char *s)
  29. {
  30.     while (s && *s) {
  31.         if (*s == '\"')
  32.             *s = '\'';
  33.         s++;
  34.     }
  35. }
  36.  
  37.  
  38.  
  39. char *DOS_escape(char *str)
  40. /* put * (escape char) before " and * */
  41. {
  42.     if (str) {
  43.         char *s = str;
  44.         while (*s) {
  45.             if (*s == '"' || *s == '*') {
  46.                 strins(s, "*");
  47.                 s++;
  48.             }
  49.             s++;
  50.         }
  51.         /* strins(str,"\""); */
  52.         /* strcat(str,"\""); */
  53.     }
  54.     return (str);
  55. }
  56.  
  57.  
  58. int main(int argc, char *argv[])
  59. {
  60.     if (argc == 3) {
  61.         char tmp[80];
  62.         FILE *fp;
  63.  
  64.         sprintf(tmp, "%s%ld", "MB_TMP:News2Eazy.tmp", (long) FindTask(NULL));
  65.  
  66.         if (fp = fopen(tmp, "w")) {
  67.             register int c = 0;
  68.             char username[256];
  69.             char uucpadr[256];
  70.             char *board1 = argv[1];
  71.             char *board2 = argv[2];
  72.             char subject[256];
  73.             char exec[256];
  74.             char str[1024];
  75.             BOOL ende = FALSE;
  76.  
  77.             strcpy(username, "unknown");
  78.             strcpy(subject, "none");
  79.             strcpy(uucpadr, "");
  80.  
  81.             while (!ende && fgets(str, 1023, stdin)) {
  82.                 if (strlen(str) == 0 || strcmp(str, "\n") == 0)
  83.                     ende = TRUE;
  84.                 else if ((strnicmp(str, "From: ", 6) == 0 && strlen(uucpadr) == 0) || strnicmp(str, "Reply-To: ", 10) == 0) {
  85.                     char *p;
  86.                     char *str2;
  87.                     str2 = strstr(str, ": ") + 2;
  88.  
  89.                     strcpy(uucpadr, str2);
  90.                     kill_quotes(uucpadr);
  91.                     if (strchr(uucpadr, '\n'))
  92.                         *strchr(uucpadr, '\n') = 0;
  93.  
  94. #if 0
  95.                     strcpy(username, str2);
  96.                     p = username;
  97.                     while (*p && *p != '@') {
  98.                         p++;
  99.                     }
  100.                     if (*p == '@')
  101.                         *p = 0;
  102. #endif
  103.                     if (p = strchr(str2, '@')) {
  104.                         int pos;
  105.                         for (pos = 0, p--; p >= str2 && *p != ' ' && *p != '\t' && *p != '<'; p--)
  106.                             username[pos++] = *p;
  107.                         username[pos] = 0;
  108.                         strrev(username);
  109.                     }
  110.  
  111.                     if (strchr(username, '\n'))
  112.                         *strchr(username, '\n') = 0;
  113.                     username[15] = 0;
  114.                     kill_quotes(username);
  115.                 }
  116.                 else if (strnicmp(str, "Subject: ", 9) == 0) {
  117.                     strcpy(subject, str + 9);
  118.                     kill_quotes(subject);
  119.                     if (strchr(subject, '\n'))
  120.                         *strchr(subject, '\n') = 0;
  121.                     subject[40] = 0;
  122.                 }
  123.             }
  124.  
  125.             while ((c = fgetc(stdin)) != EOF) {
  126.                 if (c == '\\')
  127.                     fputc('\\', fp);
  128.                 fputc(c, fp);
  129.             }
  130.             fprintf(fp, "\n");
  131.  
  132.             fclose(fp);
  133.  
  134. #if 0
  135.             DOS_escape(username);
  136.             DOS_escape(uucpadr);
  137.             DOS_escape(subject);
  138. #endif
  139.  
  140.             sprintf(exec, "MB:C/ImportMessage \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", board1, board2, username, uucpadr, subject, tmp);
  141.             System(exec, NULL);
  142.             DeleteFile(tmp);
  143.         }
  144.     }
  145.     else {
  146.         fprintf(stderr, "\033[1;33mEazyBBS\033[0m © 1988-1995 Andreas M. Kirchwitz\n"
  147.         "Usage: news2eazy \033[3m<board1> <board2> \033[0m <text\n");
  148.     }
  149.  
  150.     exit(0);
  151. }
  152.