home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / os2trn.c < prev    next >
Text File  |  1993-01-10  |  29KB  |  760 lines

  1. /************************************************************
  2.  *** OS2: This file contains additional routines          ***
  3.  ***      only needed in the OS/2-version.                ***
  4.  ***                                                      ***
  5.  ***   last modified: 07/28/92                            ***
  6.  ***   Authors:  Thilo Schuster (term@godot.stgt.sub.org) ***
  7.  ***         Herbert Neugebauer (haen@veces.stgt.sub.org) ***
  8.  ***                                                      ***
  9.  ***  please send bug reports to term@godot or haen@veces ***
  10.  ***                                                      ***
  11.  ***  Remark: the things in os2patch.c are used in every  ***
  12.  ***          executable, os2trn.c only in trn            ***
  13.  ************************************************************/
  14.  
  15. #define OS2_TRN_C
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <strings.h>
  20. #include <termio.h>
  21. #include <time.h>
  22. #include "EXTERN.h"
  23. #include "config.h"
  24. #include "common.h"
  25. #include "os2patch.h"
  26. #include "term.h"
  27.  
  28. /*** We need prototypes for some functions ***/
  29. extern char *filexp(char *s);
  30. extern char *headname;
  31.  
  32. /*** And some global variables, defined somewhere else ***/
  33. extern FILE *rcfp;
  34. extern FILE *actfp;
  35. extern ART_POS savefrom;
  36.  
  37. /***************************************************
  38.  ** This function was written to replace the      **
  39.  ** shell-script newsetup. It reads the active    **
  40.  ** file and writes out a .newsrc file, by        **
  41.  ** taking every group out of the active-file     **
  42.  ** strip off the numbers after the name and      **
  43.  ** adding a ":", so all groups are marked as     **
  44.  ** subscribed.                                   **
  45.  ***************************************************/
  46.  
  47. int make_newsrc(char *rcname, char *activename)
  48. {  FILE *activefile, *rcfile;
  49.    char tmpbuffer[80];
  50.    char *tmpcharptr;
  51.  
  52.    if ((activefile = fos2open(activename,"r")) == NULL)
  53.    {  fprintf(stderr,"Cannot open the ACTIVE-file.\n");
  54.       fflush(stderr);
  55.       return 1;   /** not successful **/
  56.    }
  57.    else
  58.    {  if ((rcfile = fos2open(rcname,"w")) == NULL)
  59.       {  fprintf(stderr,"Cannot create the .newsrc-file.\n");
  60.          fflush(stderr);
  61.          return 1;  /** not successful **/
  62.       }
  63.       else
  64.       {  while(fgets(tmpbuffer,80,activefile))    /** read a line **/
  65.          {  if (strtok(tmpbuffer," \r\n"))        /** cut out ng-name **/
  66.                fprintf(rcfile,"%s:\n",tmpbuffer); /** write out name+':' **/
  67.             else
  68.             {  fprintf(stderr,"Perhaps bogus newsgroup-line, didn't write out the group!\n");
  69.                fprintf(stderr,"  line:%s\n",tmpbuffer);
  70.                fflush(stderr);
  71.             }
  72.          }
  73.          fclose(rcfile);
  74.          fclose(activefile);
  75.       }
  76.    }
  77.  
  78.    return 0;   /*success*/
  79. }
  80.  
  81.  
  82. /***************************************************
  83.  ** This function was written to replace the      **
  84.  ** shell-script's mbox.saver and norm.saver      **
  85.  ***************************************************/
  86.  
  87. int article_saver(bool mailbox, char *fromname, char *tosavename)
  88. {   char tmpbuffer[1023+1];     /** make it long because of long From-lines*/
  89.     char *tmpptr;
  90.     int  nobjread;
  91.     FILE *readfile, *writefile;
  92.     bool newfile = FALSE;
  93.     time_t timeinseconds;
  94.  
  95.     if (!fromname)
  96.        strcpy(tmpbuffer,filexp("%A"));
  97.     else
  98.        strcpy(tmpbuffer,fromname);
  99.     if ((readfile = fos2open(tmpbuffer, "r")) == NULL)
  100.     {   fprintf(stderr,"Cannot open article %s for input!\n",tmpbuffer);
  101.         fflush(stderr);
  102.         return 1;
  103.     }
  104.     if (!tosavename)
  105.        strcpy(tmpbuffer,filexp("%b"));
  106.     else
  107.        strcpy(tmpbuffer,tosavename);
  108.     if ((writefile = fos2open(tmpbuffer, "r+")) == NULL)
  109.     {  if ((writefile = fos2open(tmpbuffer, "w")) == NULL)
  110.        {  if (mailbox)
  111.              fprintf(stderr,"Cannot open mailbox %s for output!\n",tmpbuffer);
  112.           else
  113.              fprintf(stderr,"Cannot open file %s for output!\n",tmpbuffer);
  114.           fclose(readfile);
  115.           fflush(stderr);
  116.           return 1;
  117.        }
  118.        else newfile = TRUE;
  119.     }
  120.     if (!newfile)
  121.     {  fseek(writefile, 0l, SEEK_END);    /* go to end of file (append) */
  122.        fprintf(writefile,"\n");
  123.     }
  124.  
  125. /*** OS2: there is a difference between the saver-commands "s" and "w".
  126.           The global variable "savefrom" contains a byte-offset for
  127.           the input-file, which can be used to strip the header off
  128.           when the user used the w-command. But we only use this
  129.           feature if we save an article (this routine is also
  130.           used to save outgoing mail or post to the users
  131.           out-mailboxes)                                      ***/
  132.     if (!fromname)
  133.         if (savefrom)
  134.             fseek(readfile,savefrom,SEEK_SET);
  135.  
  136.     if (mailbox)
  137.     {
  138.        /*** Create a UUPC-compatible Mailbox with the
  139.             following article separator ***/
  140.        fprintf(writefile,"\n");
  141.  
  142.        /*** Create a From-line with the date of the article via
  143.             filexp("%T") filexp("%[date]"). If this doesn't work,
  144.             take easy default data.   ***/
  145.        
  146.        tmpptr = filexp("%T");           
  147.        if ( (tmpptr == NULL) || (strlen(tmpptr) < 3) || (fromname))
  148.            fprintf(writefile,"From %s",uupc_rc_settings.domain);
  149.        else
  150.            fprintf(writefile,"From %s",tmpptr);
  151.  
  152.        tmpptr = filexp("%[date]");
  153.        if ( (tmpptr == NULL) || (strlen(tmpptr) < 3) || (fromname))
  154.        {   timeinseconds = time(NULL);
  155.             strftime(tmpbuffer,255,"%a, %d %b %y %H:%M:%S %Z",
  156.                                   localtime(&timeinseconds));
  157.            fprintf(writefile," %s\n", tmpbuffer);
  158.        }
  159.        else
  160.            fprintf(writefile," %s\n",tmpptr);
  161.     }
  162. /*** OS2: We had a serious problem with this combination of commands.
  163.           The destination filled up the entire disk under certain
  164.           circumstances. The second problem was, that fget's
  165.           changed special characters, so that the save did not
  166.           work for binary (I want to say uuencoded) files ***/
  167. /*    while(fgets(tmpbuffer, 511, readfile))   */
  168. /*          fprintf(writefile,tmpbuffer);      */
  169.  
  170.     while(!feof(readfile)) {
  171.         nobjread = fread(tmpbuffer, 1, 80, readfile);
  172.         fwrite(tmpbuffer, 1, nobjread, writefile);
  173.     }
  174.  
  175.     fprintf(writefile,"\n");
  176.     fclose(writefile);
  177.     fclose(readfile);
  178.  
  179.     return 0;
  180. }
  181.  
  182.  
  183.  
  184. /**************************************************
  185.  ** this function will replace the shellscripts  **
  186.  ** Rnmail. It will use the already prepared     **
  187.  ** header and include the signature. It will    **
  188.  ** also ask the user for a prepared text which  **
  189.  ** will then be included. It will use the       **
  190.  ** UUPC-Program "rmail" to send the mail.       **
  191.  **************************************************/
  192.  
  193. void mail_reply(void)
  194. {   FILE *header_fp, *include_fp, *signature_fp;
  195.     char tmpbuffer[255+1];
  196.     char cmd;
  197.     int  linecounter;
  198.     bool includesig = FALSE;
  199.  
  200.     if (strlen(uupc_rc_settings.signature) > 0) {
  201.         sprintf(tmpbuffer,"%s/%s",uupc_rc_settings.home,
  202.                                   uupc_rc_settings.signature);
  203.         if (signature_fp = fopen(tmpbuffer,"r"))
  204.            includesig = TRUE;
  205.     }
  206.     standout();
  207.     printf("Prepared file to include [NONE]:");
  208.     un_standout();
  209.     printf(" ");
  210.     fflush(stdout);
  211.     fgets(tmpbuffer,255, stdin);
  212.     tmpbuffer[strlen(tmpbuffer) - 1 ] = '\0';
  213.     if(strlen(tmpbuffer) != 0) {
  214.         if(include_fp = fopen(tmpbuffer,"r")) {
  215.             if ((header_fp = fopen(headname,"r+")) != NULL) {
  216.                 fseek(header_fp,0l,SEEK_END);
  217.                 while(fgets(tmpbuffer,255,include_fp)) {
  218.                     fprintf(header_fp,"%s",tmpbuffer); }
  219.                 if (includesig) {
  220.                    printf("\nIncluding Signature...\n");
  221.                    fflush(stdout);
  222.                    fprintf(header_fp,"\n\n--\n");
  223.                    while(fgets(tmpbuffer,255,signature_fp)) {
  224.                        fprintf(header_fp,"%s",tmpbuffer); }
  225.                 }
  226.                 fclose(header_fp);
  227.             }
  228.             else
  229.                printf("\nCannot open %s\n",tmpbuffer);
  230.                fflush(stdout);
  231.             fclose(include_fp);
  232.         }
  233.         if (includesig) fclose(signature_fp);
  234.     } else {
  235.         if (includesig) {
  236.             if ((header_fp = fopen(headname,"r+")) != NULL) {
  237.                 printf("\nIncluding Signature...\n");
  238.                 fflush(stdout);
  239.                 fseek(header_fp,0l,SEEK_END);
  240.                 fprintf(header_fp,"\n\n--\n");
  241.                 while(fgets(tmpbuffer,255,signature_fp))
  242.                     fprintf(header_fp,"%s",tmpbuffer);
  243.                 fclose(header_fp);
  244.             }
  245.             fclose(signature_fp);
  246.         }
  247.         sprintf(tmpbuffer, uupc_rc_settings.editor, headname);
  248.         printf("Invoking %s\n",tmpbuffer);
  249.         fflush(stdout);
  250.         termlib_reset();
  251.         system(tmpbuffer);
  252.         termlib_init();
  253.         un_standout();
  254.     }
  255.  
  256.     cmd = ' ';
  257.     while((cmd != 's')&&(cmd != 'S')&&(cmd != 'a')&&(cmd != 'A')) {
  258.         printf("\n");
  259.         standout();
  260.         printf("Send, abort, edit, or list ?");
  261.         un_standout();
  262.         printf(" ");
  263.         fflush(stdout);
  264.         cmd = _read_kbd(0,1,0);
  265.         printf("\n");
  266.         switch(cmd) {
  267.             case 's': case 'S':
  268.                 sprintf(tmpbuffer,"%s -f %s -t",
  269.                                 uupc_rc_settings.rmailpath,
  270.                                 headname);
  271.                 change_sl2bsl(tmpbuffer);
  272.                 printf("\nInvoking %s\n",tmpbuffer);
  273.                 fflush(stdout);
  274.                 system(tmpbuffer);
  275.                 if (strlen(uupc_rc_settings.mailsent) > 0) {
  276.                     sprintf(tmpbuffer,"%s/%s",uupc_rc_settings.home,
  277.                                               uupc_rc_settings.mailsent);
  278.                     printf("\nSaving mail to %s\n",tmpbuffer);
  279.                     fflush(stdout);
  280.                     if (article_saver(TRUE,headname,tmpbuffer))
  281.                         printf("\nCannot save letter to %s\n",tmpbuffer);
  282.                 }
  283.                 fflush(stdout);
  284.                 break;
  285.             case 'a': case 'A':
  286.                 strcpy(tmpbuffer,uupc_rc_settings.home);
  287.                 strcat(tmpbuffer,"/dead.let");
  288.                 printf("\nSaving letter to %s\n",tmpbuffer);
  289.                 fflush(stdout);
  290.                 if (article_saver(TRUE,headname,tmpbuffer))
  291.                    printf("\nCannot save letter to %s\n",tmpbuffer);
  292.                 fflush(stdout);
  293.                 break;
  294.             case 'e': case 'E':
  295.                 sprintf(tmpbuffer, uupc_rc_settings.editor, headname);
  296.                 printf("\nInvoking %s\n",tmpbuffer);
  297.                 termlib_reset();
  298.                 fflush(stdout);
  299.                 system(tmpbuffer);
  300.                 termlib_init();
  301.                 break;
  302.             case 'l': case 'L':
  303.                 printf("\n");
  304.                 if(header_fp = fopen(headname,"r")) {
  305.                     linecounter = 0;
  306.                     while(fgets(tmpbuffer,255,header_fp))
  307.                     {   linecounter += 1 + (strlen(tmpbuffer) / 80);
  308.                         printf("%s",tmpbuffer);
  309.                         if (linecounter >= LINES - 1)
  310.                         {   linecounter = 0;
  311.                             standout();
  312.                             printf("--more--");
  313.                             un_standout();
  314.                             fflush(stdout);
  315.                             _read_kbd(0,1,0);
  316.                             carriage_return();
  317.                             erase_eol();
  318.                         }
  319.                     }
  320.                 fclose(header_fp);
  321.                 }
  322.                 break;
  323.             default :
  324.                 puts("\nType s to send the message, a to abort and append the message");
  325.                 puts("to dead.let, e to edit the message again, l to list the message.");
  326.                 fflush(stdout);
  327.                 break;
  328.         }
  329.     }
  330. }
  331.  
  332.  
  333.  
  334. /*************************************************
  335.  ** This function will read the article file    **
  336.  ** and look for the header. It will then       **
  337.  ** generate a correct header out of the        **
  338.  ** already existing lines in the headname-file **
  339.  ** and some new lines, that we must figure     **
  340.  ** out first.                                  **
  341.  *************************************************/
  342.  
  343. int complete_header(FILE *header_fp, char *dshortname, time_t timeinseconds)
  344. {   char tmpbuffer[255+1], linebuffer[255+1];
  345.     char *lineptr;
  346.     bool OKline = FALSE;
  347.     unsigned int linecounter = 0;
  348.     FILE *tmp_fp, *body_fp;
  349.  
  350.     if ((tmp_fp = fos2open(dshortname,"w")) != NULL) {
  351.         fprintf(tmp_fp,"Path: %s!%s\n",uupc_rc_settings.domain,
  352.                                        uupc_rc_settings.user);
  353.         fprintf(tmp_fp,"From: %s@%s (%s)\n",
  354.                             uupc_rc_settings.user,
  355.                             uupc_rc_settings.domain,
  356.                             uupc_rc_settings.name);
  357.  
  358.         /*** now look for the newsgroups-line ***/
  359.         while (!OKline) {
  360.             if (!fgets(tmpbuffer,255,header_fp)) break;
  361.             if (!strncmp(tmpbuffer,"Newsgroups:",11)) OKline = TRUE;
  362.         }
  363.         if (!OKline) {
  364.             printf("Cannot find a 'Newsgroups:'-line in your header, nothing sent...\n");
  365.             fclose(tmp_fp);
  366.             fclose(header_fp);
  367.             return 0;
  368.         }
  369.         fflush(stdout);
  370.         fprintf(tmp_fp,"%s",tmpbuffer);
  371.  
  372.         OKline = FALSE;
  373.         fflush(header_fp);
  374.         rewind(header_fp);
  375.  
  376.         /*** now look for the subject-line ***/
  377.         while (!OKline) {
  378.             if (!fgets(tmpbuffer,255,header_fp)) break;
  379.             if (!strncmp(tmpbuffer,"Subject:",8)) OKline = TRUE;
  380.         }
  381.         if (!OKline) {
  382.             printf("Cannot find a 'Subject:'-line in your header, using '<none>'...\n");
  383.             fprintf(tmp_fp,"Subject: <none>\n");
  384.         }
  385.         else fprintf(tmp_fp,"%s",tmpbuffer);
  386.         fflush(stdout);
  387.  
  388.         OKline = FALSE;
  389.         fflush(header_fp);
  390.         rewind(header_fp);
  391.  
  392.         /*** now look for the Distribution-line ***/
  393.         while (!OKline) {
  394.             if (!fgets(tmpbuffer,255,header_fp)) break;
  395.             if (!strncmp(tmpbuffer,"Distribution:",13)) OKline = TRUE;
  396.         }
  397.         if (!OKline) {
  398.             printf("Cannot find a 'Distribution:'-line in your header, using 'world'...\n");
  399.             fprintf(tmp_fp,"Distribution: world\n");
  400.         }
  401.         else fprintf(tmp_fp,"%s",tmpbuffer);
  402.         fflush(stdout);
  403.  
  404.         fprintf(tmp_fp,"Message-ID: <%ld%s.%s@%s>\n",
  405.                             timeinseconds,
  406.                             uupc_rc_settings.user,
  407.                             uupc_rc_settings.newsadmin,
  408.                             uupc_rc_settings.domain);
  409.         fprintf(tmp_fp,"Sender: %s@%s\n",
  410.                             uupc_rc_settings.newsadmin,
  411.                             uupc_rc_settings.domain);
  412. /*** OS2: this ctime-call produced a time-string, which was
  413.           rejected from my news-system. So the corresponding
  414.           article was not transferred to other systems. Now
  415.           I'm producing a string with strftime, which is processed
  416.           by my own newsfeed. Strange is that the posting worked
  417.           correctly on another newsfeed, where a friend of mine
  418.           tested TRN-postings.   ***/
  419. /**        fprintf(tmp_fp,"Date: %s",ctime(&timeinseconds));  **/
  420.         strftime(tmpbuffer,255,"%a, %d %b %y %H:%M:%S %Z",
  421.                                   localtime(&timeinseconds));
  422.         fprintf(tmp_fp,"Date: %s\n",tmpbuffer);
  423.  
  424.         OKline = FALSE;
  425.         fflush(header_fp);
  426.         rewind(header_fp);
  427.  
  428.         while (!OKline) {
  429.             if (!fgets(tmpbuffer,255,header_fp)) break;
  430.             strcpy(linebuffer,tmpbuffer);
  431.             if ((tmpbuffer[0] == ' ') ||
  432.                 (tmpbuffer[0] == '\n') ||
  433.                 (tmpbuffer[0] == '\r')) OKline = TRUE;
  434.             if (!OKline) {
  435.                 /*** Don't copy lines, which we already have
  436.                      in the final article and also skip lines
  437.                      with missing contents or missing ": "***/
  438.                 if ((!strncmp(tmpbuffer,"Path:",5)) ||
  439.                     (!strncmp(tmpbuffer,"From:",5)) ||
  440.                     (!strncmp(tmpbuffer,"Newsgroups:",11)) ||
  441.                     (!strncmp(tmpbuffer,"Subject:",8)) ||
  442.                     (!strncmp(tmpbuffer,"Distribution:",13)) ||
  443.                     (!strncmp(tmpbuffer,"Message-ID:",11)) ||
  444.                     (!strncmp(tmpbuffer,"Sender:",7)) ||
  445.                     (!strncmp(tmpbuffer,"Date:",5))) continue;
  446.  
  447.                 if (!strtok(tmpbuffer,":")) continue;
  448.                 if (!(lineptr = strtok(NULL," "))) continue;
  449.                 if (strlen(lineptr) < 3) continue;
  450.  
  451.                 fprintf(tmp_fp,"%s",linebuffer);
  452.             }
  453.         }
  454.  
  455.         if (!OKline) {
  456.             printf("Cannot find end of header, nothing sent...\n");
  457.             fflush(stdout);
  458.             fclose(tmp_fp);
  459.             fclose(header_fp);
  460.             return 0;
  461.         }
  462.  
  463.         /*** copy rest of article to a temp-file, while counting
  464.              the lines. ***/
  465.  
  466.         if ((body_fp = fos2open("body.art","w")) != NULL) {
  467.             while (fgets(tmpbuffer,255,header_fp)) {
  468.                 fprintf(body_fp,"%s",tmpbuffer);
  469.                 linecounter++;
  470.             }
  471.         }
  472.         else {
  473.             printf("Cannot open tempfile (body.art), nothing sent...\n");
  474.             fflush(stdout);
  475.             fclose(tmp_fp);
  476.             fclose(header_fp);
  477.             return(0);
  478.         }
  479.  
  480.         /*** complete the header ***/
  481.         fprintf(tmp_fp,"Lines: %d\n",linecounter);
  482.         fprintf(tmp_fp,"\n");   /* additional \n marks end of header*/
  483.  
  484.         /** hmm, rewind didn't work on body_fp, so let's
  485.             close and reopen it ***/
  486.         fclose(body_fp);
  487.  
  488.         /*** and finally copy rest of the message ***/
  489.         if ((body_fp = fos2open("body.art","r")) != NULL) {
  490.             while (fgets(tmpbuffer,255,body_fp))
  491.                 fprintf(tmp_fp,"%s",tmpbuffer);
  492.             fclose(body_fp);
  493.             unlink("body.art");
  494.         }
  495.         else {
  496.             printf("Cannot open tempfile (body.art), nothing sent...\n");
  497.             fflush(stdout);
  498.             fclose(tmp_fp);
  499.             fclose(header_fp);
  500.             return 0;
  501.         }
  502.  
  503.         fclose(tmp_fp);
  504.         fclose(header_fp);
  505.         return 1;
  506.     }
  507.     else {
  508.         printf("Cannot open temp file (%s), nothing sent...\n",dshortname);
  509.         fflush(stdout);
  510.         return 0;
  511.     }
  512. }
  513.  
  514.  
  515.  
  516. /**************************************************
  517.  ** this function will replace the shellscripts  **
  518.  ** Pnews and Pnews.header. It will use the      **
  519.  ** header and include the signature. It will    **
  520.  ** also ask the user for a prepared text which  **
  521.  ** will then be included.                       **
  522.  **************************************************/
  523.  
  524. void article_poster(void)
  525. {   FILE *header_fp, *include_fp, *signature_fp, *tmp_fp;
  526.     char tmpbuffer[255+1];
  527.     char dshortname[20+1], dlongname[20+1], xshortname[12+1], xlongname[12+1];
  528.     char cmd;
  529.     int  linecounter;
  530.     bool includesig = FALSE;
  531.     time_t timeinseconds;
  532.  
  533.     if (strlen(uupc_rc_settings.signature) > 0) {
  534.         sprintf(tmpbuffer,"%s/%s",uupc_rc_settings.home,
  535.                                   uupc_rc_settings.signature);
  536.         if (signature_fp = fopen(tmpbuffer,"r"))
  537.            includesig = TRUE;
  538.     }
  539.     standout();
  540.     printf("Prepared file to include [NONE]:");
  541.     un_standout();
  542.     printf(" ");
  543.     fflush(stdout);
  544.     fgets(tmpbuffer,255, stdin);
  545.     tmpbuffer[strlen(tmpbuffer) - 1 ] = '\0';
  546.     if(strlen(tmpbuffer) != 0) {
  547.         if(include_fp = fopen(tmpbuffer,"r")) {
  548.             if ((header_fp = fopen(headname,"r+")) != NULL) {
  549.                 fseek(header_fp,0l,SEEK_END);
  550.                 while(fgets(tmpbuffer,255,include_fp)) {
  551.                     fprintf(header_fp,"%s",tmpbuffer); }
  552.                 if (includesig) {
  553.                    printf("\nIncluding Signature...\n");
  554.                    fflush(stdout);
  555.                    fprintf(header_fp,"\n\n--\n");
  556.                    while(fgets(tmpbuffer,255,signature_fp)) {
  557.                        fprintf(header_fp,"%s",tmpbuffer); }
  558.                 }
  559.                 fclose(header_fp);
  560.             }
  561.             else
  562.                printf("\nCannot open %s\n",tmpbuffer);
  563.             fflush(stdout);
  564.             fclose(include_fp);
  565.         }
  566.         if (includesig) fclose(signature_fp);
  567.     } else {
  568.         if (includesig) {
  569.             if ((header_fp = fopen(headname,"r+")) != NULL) {
  570.                 printf("\nIncluding Signature...\n");
  571.                 fflush(stdout);
  572.                 fseek(header_fp,0l,SEEK_END);
  573.                 fprintf(header_fp,"\n\n--\n");
  574.                 while(fgets(tmpbuffer,255,signature_fp))
  575.                     fprintf(header_fp,"%s",tmpbuffer);
  576.                 fclose(header_fp);
  577.             }
  578.             fclose(signature_fp);
  579.         }
  580.         sprintf(tmpbuffer, uupc_rc_settings.editor, headname);
  581.         printf("Invoking %s\n",tmpbuffer);
  582.         termlib_reset();
  583.         fflush(stdout);
  584.         system(tmpbuffer);
  585.         termlib_init();
  586.         un_standout();
  587.     }
  588.  
  589.     cmd = ' ';
  590.     while((cmd != 's')&&(cmd != 'S')&&(cmd != 'a')&&(cmd != 'A')) {
  591.         printf("\n");
  592.         standout();
  593.         printf("Send, abort, edit, or list ?");
  594.         un_standout();
  595.         printf(" ");
  596.         fflush(stdout);
  597.         cmd = _read_kbd(0,1,0);
  598.         printf("\n");
  599.         switch(cmd) {
  600.             case 's': case 'S':
  601.                 /** ok, now let's complete the header of the article ***/
  602.  
  603. /*** OS2: This posting stuff,....... hmmm
  604.           I hope that we can fix that later ***/
  605.  
  606.                 if ((header_fp = fopen(headname,"r")) != NULL)
  607.                 {   timeinseconds = time(NULL);
  608.                 strncpy(dshortname,uupc_rc_settings.site,8);
  609.             dshortname[8] = '\0';
  610.             strcat(dshortname,".D");
  611.                     sprintf(tmpbuffer,"%04x",
  612.          (unsigned short)((short)(timeinseconds/131072)-(short)timeinseconds));
  613.                     sprintf(dlongname,"D.%s%.4s",uupc_rc_settings.site,
  614.                                                  tmpbuffer);
  615.                 strncpy(xshortname,uupc_rc_settings.site,8);
  616.             xshortname[8] = '\0';
  617.             strcat(xshortname,".X");
  618.                     sprintf(xlongname,"X.%s%.4s",uupc_rc_settings.site,
  619.                                                  tmpbuffer);
  620.                     if (complete_header(header_fp,dshortname,timeinseconds))
  621.                         if ((tmp_fp = fos2open(xshortname,"w")) != NULL)
  622.                         {   fprintf(tmp_fp, "U news %s\n",
  623.                                           uupc_rc_settings.site);
  624.                             fprintf(tmp_fp, "Z\n");
  625.                             fprintf(tmp_fp, "F %s\n", dlongname);
  626.                             fprintf(tmp_fp, "I %s\n", dlongname);
  627.                             fprintf(tmp_fp, "C rnews\n");
  628.                             fclose(tmp_fp);
  629.                             sprintf(tmpbuffer,"uucp -C %s %s!%s",
  630.                                                  xshortname,
  631.                                                  uupc_rc_settings.mail_server,
  632.                                                  xlongname);
  633.                             printf("Invoking %s\n",tmpbuffer);
  634.                             fflush(stdout);
  635.                             system(tmpbuffer);
  636.                             sprintf(tmpbuffer,"uucp -C %s %s!%s",
  637.                                                  dshortname,
  638.                                                  uupc_rc_settings.mail_server,
  639.                                                  dlongname);
  640.                             printf("Invoking %s\n",tmpbuffer);
  641.                             fflush(stdout);
  642.                             system(tmpbuffer);
  643.  
  644.                             printf("Now posting the article locally...\n");
  645.                  /*** Our Rnews is quit  intelligent, it can
  646.                       not only handle compressed batches, it can
  647.                       also handle normal files...  Thanx Jan and Harald
  648.                       But we have a litte problem, the active file is
  649.                       already open....        ***/
  650.                             fclose(actfp);
  651.                             sprintf(tmpbuffer,"rnews <%s",dshortname);
  652.                             printf("Invoking %s\n",tmpbuffer);
  653.                             fflush(stdout);
  654.                             system(tmpbuffer);
  655.                             ngdata_init();  /* re-grab the active file */
  656.                             unlink(dshortname);
  657.                             unlink(xshortname);
  658.                         }
  659.                         else printf("Cannot open temp file (%s), nothing sent...\n",xshortname);
  660.                 }
  661.                 else printf("Cannot open article file, nothing sent...\n");
  662.                 sprintf(tmpbuffer,"%s/Postings",uupc_rc_settings.home);
  663.                 printf("\nSaving article to %s\n",tmpbuffer);
  664.                 fflush(stdout);
  665.                 if (article_saver(TRUE,headname,tmpbuffer))
  666.                     printf("\nCannot save article as letter to %s\n",tmpbuffer);
  667.                 unlink(headname);
  668.                 fflush(stdout);
  669.                 break;
  670.             case 'a': case 'A':
  671.                 strcpy(tmpbuffer,uupc_rc_settings.home);
  672.                 strcat(tmpbuffer,"/deadpost.let");
  673.                 printf("\nSaving to %s\n",tmpbuffer);
  674.                 fflush(stdout);
  675.                 if (article_saver(TRUE,headname,tmpbuffer))
  676.                    printf("\nCannot save letter to %s\n",tmpbuffer);
  677.                 fflush(stdout);
  678.                 break;
  679.             case 'e': case 'E':
  680.                 sprintf(tmpbuffer, uupc_rc_settings.editor, headname);
  681.                 printf("\nInvoking %s\n",tmpbuffer);
  682.                 termlib_reset();
  683.                 fflush(stdout);
  684.                 system(tmpbuffer);
  685.                 termlib_init();
  686.                 break;
  687.             case 'l': case 'L':
  688.                 printf("\n");
  689.                 if(header_fp = fopen(headname,"r")) {
  690.                     linecounter = 0;
  691.                     while(fgets(tmpbuffer,255,header_fp))
  692.                     {   linecounter += 1 + (strlen(tmpbuffer) / 80);
  693.                         printf("%s",tmpbuffer);
  694.                         if (linecounter >= LINES - 1)
  695.                         {   linecounter = 0;
  696.                             standout();
  697.                             printf("--more--");
  698.                             un_standout();
  699.                             fflush(stdout);
  700.                             _read_kbd(0,1,0);
  701.                             carriage_return();
  702.                             erase_eol();
  703.                         }
  704.                     }
  705.                 fclose(header_fp);
  706.                 }
  707.                 break;
  708.             default :
  709.                 puts("\nType s to send the article, a to abort and append the article");
  710.                 puts("to deadpost.let, e to edit the article again, l to list the article.");
  711.                 fflush(stdout);
  712.                 break;
  713.         }
  714.     }
  715. }
  716.  
  717.  
  718.  
  719.  
  720. /**************************************************
  721.  ** this function will replace the shellscript   **
  722.  ** newsgroups. It will use the .newsrc-file     **
  723.  ** to search for unsubscribed newsgroups. It    **
  724.  ** will use the ! or : characters to find out   **
  725.  ** if newsgroup is subscribed or not.           **
  726.  **************************************************/
  727.  
  728. int unsub_group(char *pattern)
  729. {   char tmpbuffer[255+1];
  730.     int  counter;
  731.     FILE *newsrcfp;
  732.  
  733.     strcpy(tmpbuffer,filexp(RCNAME));
  734.     if ((newsrcfp = fos2open(tmpbuffer,"r")) == NULL) {
  735.         printf("Cannot open .newsrc!\n");
  736.         fflush(stdout);
  737.         return 1;
  738.     }
  739.  
  740.     printf("Completely unsubscribed Newsgroups:\n");
  741.     while (fgets(tmpbuffer,255,newsrcfp)) {
  742. /*** OS2: I don't know why, but strtok didn't work ***/
  743.         for (counter = 0; (tmpbuffer[counter] != '\0') &&
  744.                           (tmpbuffer[counter] != ':')      ; counter++)
  745.             if (tmpbuffer[counter] == '!') {
  746.                 tmpbuffer[counter] = '\0';
  747.                 tmpbuffer[counter+1] = '\0';
  748.                 if (strlen(pattern) < 1)
  749.                     printf("%s\n",tmpbuffer);
  750.                 else
  751.                     if (strstr(tmpbuffer,pattern)) printf("%s\n",tmpbuffer);
  752.             }
  753.     }
  754.     fflush(stdout);
  755.  
  756.     fclose(newsrcfp);
  757.     return 0;
  758. }
  759.  
  760.