home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / microdot-1 / md1_src_02.lzx / rnews.c < prev    next >
C/C++ Source or Header  |  1989-06-24  |  30KB  |  984 lines

  1. #include "uuconv.h"
  2.  
  3. #ifndef UUXQT_MD
  4. extern char linebuffer[];
  5. extern APTR tx[6];
  6. #endif
  7. extern LONG lastoffset;
  8.  
  9. /* */
  10.  
  11. char tempfile[á128 ];
  12.  
  13. static char *sourcebatchname;
  14.  
  15. #ifndef UUXQT_MD
  16. char *ng2board( char *ngname )
  17. {
  18.         static char boardname[á256 ];
  19.         char *p;
  20.         struct Brett *brett = CLB_FindNewsgroup( ngname );
  21.  
  22.         if( brett )
  23.         {
  24.                 char *bn;
  25.  
  26.                 CLB_Get( brett, CLBA_NAME, &bn, TAG_DONE );
  27.                 return( bn );
  28.         }
  29.  
  30.         boardname[á255 ]á= 0;
  31.         strncpy( boardname, ngname, 255 );
  32.         strupr( boardname );
  33.  
  34.         while( ( p = strchr( boardname, '.' ) ) )
  35.                 *p = '/';
  36.  
  37.         return( boardname );
  38. }
  39. #else
  40. #define ng2board(s) s
  41. #endif
  42.  
  43. /* Get a (possibly folded) line; returns (real) number of bytes read */
  44. int readheaderline( struct AsyncFile *file, int maxlen )
  45. {
  46.         int c, ch;
  47.         int rb = 0;
  48.         int gotlf = 0;
  49.  
  50.         /*Printf("enter readhl\n" );*/
  51.  
  52.         if( !maxlen || maxlen > LBLEN )
  53.                 maxlen = LBLEN;
  54.  
  55.         linebuffer[á0 ]á= 0;
  56.         for( c = 0; c < maxlen - 1; )
  57.         {
  58.                 ch = CLU_ReadCharAsync( file );
  59. /*              Printf( "read: %ld (%lc), c = %ld, gotlf = %ld\n", ch, ch, c, gotlf );*/
  60.                 if( ch < 0 )
  61.                         break;
  62.                 rb++;
  63.                 /* CRs fressen */
  64.                 if( ch == 13 )
  65.                 {
  66.                         continue;
  67.                 }
  68.                 else if( ch == 10 )
  69.                 {
  70.                         if( !c )
  71.                                 return( 1 );
  72.                         if( gotlf )
  73.                         {
  74.                                 /* Ende, Zeichen zurⁿck */
  75.                                 CLU_UnGetCAsync( file );
  76.                                 rb--;
  77.                                 break;
  78.                         }
  79.                         gotlf = TRUE;
  80.                         continue;
  81.                 }
  82.                 /* Gefaltet? */
  83.                 if( gotlf )
  84.                 {
  85.                         /*Printf( "gotlf TRUE, ch = %ld, c = %ld\n", ch, c );*/
  86.                         if( !isspace( ch ) )
  87.                         {
  88.                                 /* NΣchste Zeile, Zeichen zurⁿck */
  89.                                 CLU_UnGetCAsync( file );
  90.                                 rb--;
  91.                                 break;
  92.                         }
  93.                         /* Gefaltet! */
  94.                         while( ( ch == 9 ) || ( ch == 32 ) || ( ch == 13 ) )
  95.                         {
  96.                                 linebuffer[ác++ ]á= ' ';
  97.                                 ch = CLU_ReadCharAsync( file );
  98.                                 rb++;
  99.                         }
  100.  
  101.                         /* Zeile nur mit Leerzeichen */
  102.                         if( ch == 10 )
  103.                         {
  104.                                 break;
  105.                         }
  106.  
  107.                         gotlf = FALSE;
  108.                 }
  109.                 linebuffer[ác++ ]á= ch;
  110.         }
  111.  
  112.         linebuffer[ác ]á= 0;
  113.  
  114. /*      Printf( "exit c %ld rb %ld lenlb %ld lb = %s\n",
  115.                 c, rb, strlen( linebuffer ), linebuffer
  116.         );*/
  117.  
  118.         return( rb );
  119. }
  120.  
  121. char *breakmid( char *ptr )
  122. {
  123.         static char midbuffer[á512 ];
  124.         char *p;
  125.  
  126.         ptr = stpblk( ptr );
  127.  
  128.         strncpy( midbuffer, ( *ptrá== '<' )á? &ptr[á1 ]á: ptr, 511 );
  129.         p = strchr( midbuffer, '>'á);
  130.         if( p )
  131.                 *p = 0;
  132.         return( midbuffer );
  133. }
  134.  
  135. struct tzone
  136. {
  137.         char name[á4 ];
  138.         short offset;
  139.         short dst;
  140. };
  141.  
  142. static struct tzone tzones[] = {
  143.         { "EST", -5 * 60, FALSE },
  144.         { "EDT", -4 * 60, TRUE },
  145.         { "CST", -6 * 60, FALSE },
  146.         { "CDT", -5 * 60, TRUE },
  147.         { "MST", -7 * 60, FALSE },
  148.         { "MDT", -6 * 60, TRUE },
  149.         { "PST", -8 * 60, FALSE },
  150.         { "PDT", -7 * 60, TRUE },
  151.         {á0 }
  152. };
  153.  
  154. char *convertuudate( char *uudate )
  155. {
  156.         char *p;
  157.         char x[6];
  158.         long y;
  159.         int tzoffs = 0, dst = 0;
  160.         static char zcdate[á32 ];
  161.         struct tzone *tzone = tzones;
  162.  
  163.         utunpk( time( NULL ), x );
  164.  
  165.         p = strchr( uudate, ',' );
  166.         if( !p )
  167.                 p = uudate;
  168.         else
  169.                 p++;
  170.  
  171. /* *p -> date time */
  172.         p = stpblk( p );
  173.  
  174. /* Tag */
  175.         x[ 2 ] = atoi(p);
  176.         while( isdigit( *p ) || *p==' ' || *p=='\t' )
  177.                 p++;
  178. /* Monat */
  179.         if(!strnicmp(p,"Jan",3)) x[1]=1;
  180.         else if(!strnicmp(p,"Feb",3)) x[1]=2;
  181.         else if(!strnicmp(p,"Mar",3)) x[1]=3;
  182.         else if(!strnicmp(p,"Apr",3)) x[1]=4;
  183.         else if(!strnicmp(p,"May",3)) x[1]=5;
  184.         else if(!strnicmp(p,"Jun",3)) x[1]=6;
  185.         else if(!strnicmp(p,"Jul",3)) x[1]=7;
  186.         else if(!strnicmp(p,"Aug",3)) x[1]=8;
  187.         else if(!strnicmp(p,"Sep",3)) x[1]=9;
  188.         else if(!strnicmp(p,"Oct",3)) x[1]=10;
  189.         else if(!strnicmp(p,"Nov",3)) x[1]=11;
  190.         else if(!strnicmp(p,"Dec",3)) x[1]=12;
  191.         else
  192.                 goto doex;
  193.         p = stpblk( &p[á4 ]á);
  194.         y = atoi( p );
  195.         if( y < 40 )
  196.             y += 30;
  197.         else if( y>1900 )
  198.                 y -= 1970;
  199.         else
  200.                 y -= 70;
  201.         x[ 0 ] = y;
  202.  
  203. /* Stunde */
  204.         while( isdigit( *p) )
  205.                 p++;
  206.         p = stpblk( p );
  207.         x[3] = atoi( p );
  208.         p = strchr( p, ':' );
  209.         if( !p )
  210.                 goto doex;
  211.         x[ 4 ] = atoi( ++p );
  212.         while( *p && *p!=':' && !isspace( *p ) )
  213.                 p++;
  214.         if( *p == ':'á)
  215.         {
  216.                 x[ 5 ] = atoi( ++p );
  217.                 while( *p && !isspace( *p ) )
  218.                         p++;
  219.         }
  220.         else
  221.                 x[ 5 ] = 0;
  222.  
  223. /* Zeitzone... */
  224.         p = stpblk( p );
  225.  
  226.         if( *p )
  227.         {
  228.                 if( *p == '+'á|| *p == '-' )
  229.                 {
  230.                         zcdate[á0 ]á= p[ 1 ];
  231.                         zcdate[á1 ]á= p[ 2 ];
  232.                         zcdate[á2 ]á= 0;
  233.                         zcdate[á3 ]á= p[ 3 ];
  234.                         zcdate[á4 ]á= p[ 4 ];
  235.                         zcdate[á5 ]á= 0;
  236.                         tzoffs = ( atoi( zcdate ) * 60 ) + atoi( &zcdate[á3 ] );
  237.                         if( *p == '-'á)
  238.                                 tzoffs = -tzoffs;
  239.                 }
  240.                 else
  241.                 {
  242.                         while( tzone->name[á0 ]á)
  243.                         {
  244.                                 if( !strnicmp( tzone->name, p, strlen( tzone->name ) ) )
  245.                                         break;
  246.                                 tzone++;
  247.                         }
  248.                         tzoffs = tzone->offset;
  249.                         dst = tzone->dst;
  250.                 }
  251.         }
  252.  
  253. doex:
  254.  
  255.         sprintf( zcdate, "%04ld%02ld%02ld%02ld%02ld%02ld%lc%lc%ld",
  256.                 x[á0 ]á+ 1970,
  257.                 x[á1 ],
  258.                 x[á2 ],
  259.                 x[á3 ],
  260.                 x[á4 ],
  261.                 x[á5 ],
  262.                 dst ? 'S' : 'W',
  263.                 tzoffs >= 0 ? '+' : '-',
  264.                 abs( tzoffs / 60 )
  265.         );
  266.  
  267.         return( zcdate );
  268. }
  269.  
  270. /* konvertiert rfc-adresse;
  271.  
  272.    entweder "User name" <domainadd>
  273.    oder      User name <domainadd>
  274.    oder     domainadd (user name)
  275.  
  276.    0  = ok
  277.    1  = form1
  278.    -1 = error
  279.  
  280. */
  281.  
  282. int convertadr( char *adr, char *to )
  283. {
  284.         char *p, *p2;
  285.         char rnb[á512 ];
  286.         char dpb[á256 ];
  287.  
  288.         // Printf( "convertadr %s\n", adr );
  289.  
  290.         rnb[á255 ]á= dpb[á255 ]á= 0;
  291.         adr = stpblk( adr );
  292.         if( *adr == '"' )
  293.         {
  294.                 strncpy( rnb, ++adr, 255 );
  295.                 p = strchr( rnb, '"' );
  296.                 if( !p )
  297.                         return( -1 );
  298.                 *p++ = 0;
  299.                 p = strchr( p, '<' );
  300.                 if( !p )
  301.                         return( -1 );
  302.                 strncpy( dpb, ++p, 255 );
  303.                 p = strchr( dpb, '>' );
  304.                 /*if( !p )
  305.                         return( -1 );*/
  306.                 if( p )
  307.                         *p = 0;
  308.                 sprintf( to, "%s (%s)", dpb, rnb );
  309.                 //Printf( "ca: rc1, %s\n", to );
  310.                 return( 1 );
  311.         }
  312.         else if( strchr( adr, '<'á) )
  313.         {
  314.                 strcpy( rnb, adr );
  315.                 p = strchr( rnb, '<'á);
  316.                 *p++ = 0;
  317.                 p2 = strchr( p, '>'á);
  318.                 /*if( !p2 )
  319.                         return( -1 );*/
  320.                 if( p2 )
  321.                         *p2 = 0;
  322.  
  323.                 p2 = &p[-2];
  324.  
  325.                 while( p2 > rnb && isspace( *p2 ) )
  326.                         *p2-- = 0;
  327.  
  328.                 if(*rnb)
  329.                     sprintf( to, "%s (%s)", p, rnb );
  330.                 else
  331.                     sprintf( to, "%s", p );
  332.                 //Printf( "ca: rc1, %s\n", to );
  333.                 return( 1 );
  334.  
  335.         }
  336.  
  337.         // Entweder Domainadresse oder Bang-Pfad; Bang-Pfad mu▀ aufgel÷st werden
  338.         if( strchr( adr, '@'á) )
  339.         {
  340.                 strcpy( to, adr );
  341.                 //Printf( "ca: rc0, %s\n", to );
  342.                 return( 0 );
  343.         }
  344.  
  345.         strncpy( rnb, adr, 255 );
  346.         p = strchr( rnb, ' 'á);
  347.         if( p )
  348.                 *p = 0;
  349.  
  350.         if( !( p = strrchr( rnb, '!'á) ) )
  351.         {
  352.                 //Printf( "ca: rc-1, %s\n", rnb );
  353.                 strcpy( to, rnb );
  354.                 return( 0 );
  355.         }
  356.  
  357.         *p++ = 0;
  358.  
  359.         p2 = strrchr( rnb, '!'á);
  360.         if( !p2 )
  361.                 p2 = rnb;
  362.         else
  363.                 p2++;
  364.  
  365.         // p = Zeiger auf letzte Node
  366.         // p2 = Zeiger auf vorletzte Node
  367.  
  368.         sprintf( to, "%s@%s", p, p2 );
  369.         //Printf( "ca: rc1, %s\n", to );
  370.         return( 1 );
  371. }
  372.  
  373. static char *slheader;
  374. static APTR slpool;
  375. static struct MinList sllist;
  376. struct sl {
  377.         struct MinNode n;
  378.         char *string;
  379. };
  380.  
  381. static void initstringlist( char *header )
  382. {
  383.         slheader = header;
  384.         NewList( ( struct List * ) &sllist );
  385.         slpool = CLU_CreatePool( MEMF_CLEAR, 2048, 1024 );
  386. }
  387.  
  388. static void addstringlist( char *string )
  389. {
  390.         struct sl * new;
  391.  
  392.         new = CLU_AllocPooled( slpool, sizeof( *new ) );
  393.         if( new )
  394.         {
  395.                 new->string = CLU_StrDupPooled( slpool, string );
  396.                 AddTail( ( struct List * ) &sllist, ( struct Node * ) new );
  397.         }
  398.  
  399. }
  400.  
  401. static void dumpstringlist( struct AsyncFile *outfile )
  402. {
  403.         struct sl *sl;
  404.  
  405.         while( ( sl = ( struct sl * ) RemHead( ( struct List * ) &sllist ) ) )
  406.                 CLU_FPrintfAsync( outfile, "%s:%s\n", slheader, sl->string );
  407.         CLU_DeletePool( slpool );
  408. }
  409.  
  410. /* Process article, len bytes */
  411.  
  412. /* Errors
  413.  
  414.         -1   defekte adresse
  415.     -2   defektes datum
  416.  
  417. */
  418.  
  419. #define allocbuffmem(x) AllocVec(x,MEMF_ANY)
  420. #define freebuffmem(x) FreeVec(x)
  421.  
  422. /*static APTR currentbuffmem;
  423. static LONG currentbuffmemlen;
  424. static APTR allocbuffmem( int len )
  425. {
  426.  
  427. }*/
  428.  
  429.  
  430. static int doarticle( struct AsyncFile *fromfile, struct AsyncFile * tofile, int len )
  431. {
  432.         int ch;
  433.         int cr = 0, lf = 0;
  434.         int c;
  435.         int offs;
  436.         int gotfollowuptoposter;
  437.         char *p, *token, *p2;
  438.         char buffer[á512 ];
  439.         char secbuf[á512 ];
  440.         char abs[á512 ], dummy[16];
  441.         BOOL isiso = FALSE;
  442.         BOOL bin = FALSE;
  443.         BOOL ismime = FALSE;
  444.  
  445.         while( len )
  446.         {
  447.                 domui();
  448.  
  449.                 abs[á0 ]á= 0;
  450.                 gotfollowuptoposter = 0;
  451.  
  452.                 //isiso = bin = FALSE;
  453.  
  454.                 ch = readheaderline( fromfile, len );
  455.                 len -= ch;
  456. //              Printf( "rnews: readheaderline ret %ld, %s\n", ch, linebuffer );
  457.  
  458.                 /* Artikelende? */
  459.                 if( !linebuffer[á0 ]á)
  460.                         break;
  461.  
  462.                 p = strchr( linebuffer, ':'á);
  463.                 if( !p )
  464.                         break;
  465.  
  466.                 *p++ = 0;
  467.                 p = stpblk( p );
  468.  
  469.                 strncpy( secbuf, linebuffer, 255 );
  470.                 secbuf[ 255 ]á= 0;
  471.  
  472.                 strlwr( linebuffer );
  473.  
  474.                 if( !strcmp( linebuffer, "organization" ) )
  475.                         CLU_FPrintfAsync( tofile, "ORG:%s\n",  p );
  476.                 else if( !strcmp( linebuffer, "path" ) )
  477.                 {
  478.                         p2 = strrchr( p, '!'á);
  479.                         if( p2 )
  480.                                 *p2 = 0;
  481.                         CLU_FPrintfAsync( tofile, "ROT:%s\n",  p );
  482.                 }
  483.                 else if( !strcmp( linebuffer, "xref" ) )
  484.                         continue;
  485.                 else if( !strcmp( linebuffer, "subject" ) )
  486.                 {
  487.                         CLU_FPrintfAsync( tofile, "BET:%s\n",  p );
  488. #ifndef UUXQT_MD
  489.                         set(tx[4], MUIA_Text_Contents, p);
  490. #endif
  491.                 }
  492.                 else if( !strcmp( linebuffer, "from" ) )
  493.                 {
  494.                         c = convertadr( p, buffer );
  495.                         if( c < 0 )
  496.                                 return( -1 );
  497.                         CLU_FPrintfAsync( tofile, "ABS:%s\n",  buffer );
  498. #ifndef UUXQT_MD
  499.                         set(tx[2], MUIA_Text_Contents, buffer);
  500. #endif
  501.  
  502.                         if( !abs[á0 ]á)
  503.                                 strcpy( abs, buffer );
  504.                         if( c )
  505.                                 CLU_FPrintfAsync( tofile, "U-From:%s\n", p );
  506.                 }
  507.                 else if( !strcmp( linebuffer, "supersedes" ) )
  508.                 {
  509.                         CLU_FPrintfAsync( tofile, "ERSETZT:%s\n", breakmid( p ) );
  510.                 }
  511.                 else if( !strcmp( linebuffer, "date" ) )
  512.                 {
  513.                         token = convertuudate( p );
  514.                         if( !token )
  515.                                 return( -2 );
  516.                         CLU_FPrintfAsync( tofile, "EDA:%s\n",  token );
  517.                         CLU_FPrintfAsync( tofile, "U-Date:%s\n", p );
  518.                 }
  519.                 else if( !strcmp( linebuffer, "reply-to" ) )
  520.                 {
  521.                         c = convertadr( p, buffer );
  522.                         if( c < 0 )
  523.                                 return( -1 );
  524.                         CLU_FPrintfAsync( tofile, "ANTWORT-AN:%s\n",  buffer );
  525.                         strcpy( abs, buffer );
  526.                         if( c )
  527.                                 CLU_FPrintfAsync( tofile, "U-Reply-To:%s\n", p );
  528.                 }
  529.                 else if( !strcmp( linebuffer, "newsgroups" ) )
  530.                 {
  531. #ifndef UUXQT_MD
  532.                         set(tx[3], MUIA_Text_Contents, p);
  533. #endif
  534.                         while( token = strtok( p, "," ) )
  535.                         {
  536.                                 token = stpblk( token );
  537.                                 CLU_FPrintfAsync( tofile, "EMP:/%s\n", ng2board( token ) );
  538.                                 p = NULL;
  539.                         }
  540.                 }
  541.                 else if( !strcmp( linebuffer, "x-gateway" ) )
  542.                 {
  543.                         while( token = strtok( p, "," ) )
  544.                         {
  545.                                 token = stpblk( token );
  546.                                 CLU_FPrintfAsync( tofile, "GATE:%s\n", token );
  547.                                 p = NULL;
  548.                         }
  549.                 }
  550.                 else if( !strcmp( linebuffer, "followup-to" ) )
  551.                 {
  552.                         while( token = strtok( p, "," ) )
  553.                         {
  554.                                 token = stpblk( token );
  555.                                 /* Poster-Syntax */
  556.                                 if( !stricmp( token, "poster" ) )
  557.                                 {
  558.                                         gotfollowuptoposter = 1;
  559.                                 }
  560.                                 else
  561.                                 {
  562.                                         CLU_FPrintfAsync( tofile, "DISKUSSION-IN:/%s\n", ng2board( token ) );
  563.                                 }
  564.                                 p = NULL;
  565.                         }
  566.                 }
  567.                 else if( !strcmp( linebuffer, "references" ) )
  568.                 {
  569.                         initstringlist( "BEZ" );
  570.                         while( token = strtok( p, ">" ) )
  571.                         {
  572.                                 while( *token == ',' || isspace( *token ) )
  573.                                     token++;
  574.                                 addstringlist( breakmid( token ) );
  575.                                 p = NULL;
  576.                         }
  577.                         dumpstringlist( tofile );
  578.                 }
  579.                 else if( !strcmp( linebuffer, "message-id" ) )
  580.                 {
  581.                         CLU_FPrintfAsync( tofile, "MID:%s\n", breakmid( p ) );
  582.                 }
  583.                 else if( !strcmp( linebuffer, "x-charset" ) )
  584.                 {
  585.                         if( !stricmp( p, "ISO-8859-1" ) )
  586.                                 isiso = TRUE;
  587.                 }
  588.                 else if( !strcmp( linebuffer, "content-type" ) )
  589.                 {
  590.                         if( strstr( p, "ISO" ) || strstr( p, "Iso" ) || strstr( p, "iso" ) )
  591.                                 isiso = TRUE;
  592.                 }
  593. #ifndef UUXQT_MD
  594.                 else if( !strcmp( linebuffer, "lines" ) )
  595.                         set(tx[5], MUIA_Text_Contents, p);
  596. #endif
  597.  
  598.                 else if( !strcmp( linebuffer, "mime-version" ) )
  599.                         ismime = TRUE;
  600.  
  601.                 else if( !strcmp( linebuffer, "content-transfer") )
  602.                 {
  603.                         if( stricmp( p, "8bit" ) )
  604.                                 isiso    = TRUE;
  605.                 }
  606.  
  607.                 else if( !strcmp( linebuffer, "x-newsreader" ) )
  608.                         CLU_FPrintfAsync( tofile, "MAILER:%s\n",  p );
  609.                 else if( !strcmp( linebuffer, "x-mailer" ) )
  610.                         CLU_FPrintfAsync( tofile, "MAILER:%s\n",  p );
  611.                 else if( !strcmp( linebuffer, "x-newssoftware" ) )
  612.                         CLU_FPrintfAsync( tofile, "MAILER:%s\n",  p );
  613.                 else if( !strncmp( linebuffer, "x-z-", 4 ) )
  614.                         CLU_FPrintfAsync( tofile, "%s:%s\n", &secbuf[ 4 ], p );
  615.                 else if( !strncmp( linebuffer, "x-zc-", 5 ) )
  616.                         CLU_FPrintfAsync( tofile, "%s:%s\n", &secbuf[ 5 ], p );
  617.                 else
  618.                 {
  619.                     if ( !strnicmp( linebuffer, "X-", 2 ) )
  620.                         CLU_FPrintfAsync( tofile, "%s:%s\n", secbuf, p );
  621.                     else
  622.                         CLU_FPrintfAsync( tofile, "U-%s:%s\n", secbuf, p );
  623.                     }
  624.  
  625.         }
  626.  
  627.         if( gotfollowuptoposter && abs[á0 ] )
  628.                 CLU_FPrintfAsync( tofile, "DISKUSSION-IN:%s", abs );
  629.  
  630. #ifndef UUXQT_MD
  631.         CLU_FPrintfAsync( tofile, "__SOURCEFMT:RFC1036/822\n" );
  632. #endif
  633.  
  634. //      Printf( "rnews: after header\n" );
  635.  
  636.         if( (isiso ) || ( !isiso && !ismime ) )
  637.                 CLU_WriteAsync( tofile, "CHARSET:ISO1\n", 13 );
  638.  
  639.  
  640.         if( len < LBLEN )
  641.         {
  642.                 char *buffmem = allocbuffmem( len * 2 ), *buffptr = buffmem;
  643.  
  644.                 CLU_ReadAsync( fromfile, linebuffer, len );
  645.  
  646.                 for( c = 0; c < len; c++ )
  647.                 {
  648.                         if( linebuffer[ác ]á== 10 )
  649.                                 *buffptr++ = 13;
  650.                         else if( linebuffer[ác ]á== 13 )
  651.                                 continue;
  652.                         *buffptr++ = linebuffer[ác ];
  653.                 }
  654.  
  655.                 CLU_FPrintfAsync( tofile, "LEN:%ld\n\n", buffptr - buffmem );
  656. // #ifndef UUXQT_MD
  657. //                 sprintf(dummy,"%ld Byte",buffptr - buffmem);
  658. //                set(tx[5], MUIA_Text_Contents, dummy);
  659. // #endif
  660.                 CLU_WriteAsync( tofile, buffmem, buffptr - buffmem );
  661.                 freebuffmem( buffmem );
  662.         }
  663.         else    // Langsame, aber Speicherplatzsparende Methode
  664.         {
  665.                 /* Zeilen zΣhlen */
  666.                 if( !bin )
  667.                 {
  668.                         offs = CLU_FtellAsync( fromfile );
  669.                         c = len;
  670.                         while( c-- )
  671.                         {
  672.                                 ch = CLU_ReadCharAsync( fromfile );
  673.                                 if( ch < 0 )
  674.                                         break;
  675.                                 if( ch == 10 )
  676.                                         lf++;
  677.                                 else if( ch == 13 )
  678.                                         cr++;
  679.                         }
  680.                         CLU_SeekAsync( fromfile, offs, ASMODE_START );
  681.                         CLU_FPrintfAsync( tofile, "LEN:%ld\n\n", 
  682.                                 len + lf - cr
  683.                         );
  684.                 }
  685.                 else
  686.                 {
  687.                         CLU_FPrintfAsync( tofile, "LEN:%ld\n\n", 
  688.                                 len );
  689.                 }
  690.  
  691.                 domui();
  692.  
  693.                 /* Artikelinhalt kopieren */
  694.                 while( len-- )
  695.                 {
  696.                         ch = CLU_ReadCharAsync( fromfile );
  697.                         if( ch == 13 )
  698.                                 continue;
  699.                         else if( ch == 10 )
  700.                         {
  701.                                 CLU_WriteCharAsync( tofile, 13 );
  702.                                 CLU_WriteCharAsync( tofile, 10 );
  703.                         }
  704.                         else CLU_WriteCharAsync( tofile, ch );
  705.                 }
  706.         }
  707.  
  708. //      Printf( "rnews: after copy\n" );
  709.  
  710.         domui();
  711.  
  712.         return( 0 );
  713.  
  714. }
  715.  
  716. #ifndef UUXQT_MD
  717. static void trasharticle( int errorc, char *fromname, struct AsyncFile *fromfile, ULONG lastoffs, ULONG len )
  718. {
  719.         char tempname[á128 ];
  720.         char tempcommentname[á128 ];
  721.         BPTR tfh;
  722.         static struct sortinprefs sortinprefs;
  723.         STRPTR destarray[á2 ];
  724.  
  725.         addlog( 8, "trashed article %s/%s@%ld, len %ld, rc %ld", sourcebatchname, fromname, lastoffs, len, errorc );
  726.  
  727.         CLP_GetPrefs( PREFSID_SORTIN, SUBID_SORTIN_PREFS, &sortinprefs, sizeof( sortinprefs ), NULL );
  728.  
  729.         CLP_MakeTempFileName( tempname, len );
  730.         CLP_MakeTempFileName( tempcommentname, 4096 );
  731.  
  732.         CLU_SeekAsync( fromfile, lastoffs, OFFSET_BEGINNING );
  733.         CLU_Copy( fromfile, tempname, len, CLUCOPY_SOURCE_ASYNC | CLUCOPY_DEST_NAME );
  734.         CLU_SeekAsync( fromfile, lastoffs + len, OFFSET_BEGINNING );
  735.  
  736.         tfh = Open( tempcommentname, MODE_NEWFILE );
  737.  
  738.         FPrintf( tfh, 
  739. "Defekte RFC-Nachricht gefunden:\n"
  740. "Quelldatei: %s (%s, Offset @%ld)\n"
  741. "Fehlercode: %ld (%s)\n"
  742. "LΣnge.....: %ld Bytes\n\n",
  743.  
  744.                 sourcebatchname, fromname, lastoffs,
  745.                 errorc, geterror( errorc ),
  746.                 len
  747.         );              
  748.  
  749.         Close( tfh );
  750.  
  751.         destarray[á0 ]á= sortinprefs.trashname;
  752.         destarray[á1 ]á= NULL;
  753.  
  754.         CLMM_SendFileTags( "CLUUXQT", destarray,
  755.                 CLMMT_SourceFile, tempname,
  756.                 CLMMT_SourceCharset, CLMM_CS_ISO,
  757.                 CLMMT_CommentFile, tempcommentname,
  758.                 CLMMT_CommentCharset, CLMM_CS_ISO,
  759.                 CLMMT_Subject, "Defekte RFC-Nachricht",
  760.                 //CLMMT_ContentsType, isbin ? CLMM_CTF_BIN : CLMM_CTF_TEXT,
  761.                 TAG_DONE
  762.         );
  763.  
  764.         DeleteFile( tempname );
  765.         DeleteFile( tempcommentname );
  766. }
  767. #endif
  768.  
  769. /* RNEWS-Batch parsen und in einzelne Artikel zerlegen */
  770.  
  771. static int donews( char *fromname, struct AsyncFile * fromfile, char *toname )
  772. {
  773.         int rc = 0;
  774.         struct AsyncFile * tofile;
  775.         int len;
  776.         int articlecount = 0;
  777.         int lastoffs, rnewslen, tofileoffs;
  778.  
  779.         tofile = CLU_OpenAsync( toname, ASMODE_WRITE, ASYNCBUFF );
  780.         if( !tofile )
  781.                 return( 3 );
  782.  
  783.         for( ;; )
  784.         {
  785. redo:
  786.                 domui();
  787.  
  788.                 tofileoffs = CLU_FtellAsync( tofile );
  789.                 lastoffs = CLU_FtellAsync( fromfile );
  790.  
  791.                 if( !CLU_FGetsAsync( fromfile, linebuffer, 2047 ) )
  792.                         break;
  793.                 if( strnicmp( linebuffer, "#! rnews", 8 ) )
  794.                 {
  795.                         addlog( 8, "Warning: %ld@%s/%s: #! rnews not found, out of sync", lastoffs, sourcebatchname, fromname );
  796.  
  797.                         while( CLU_FGetsAsync( fromfile, linebuffer, 2047 ) ) 
  798.                         {
  799.                                 if( !strnicmp( linebuffer, "#! rnews", 8 ) )
  800.                                 {
  801.                                         int coffs;
  802.  
  803.                                         CLU_SeekAsync( fromfile, -strlen( linebuffer ), OFFSET_CURRENT );
  804.                                         coffs = CLU_FtellAsync( fromfile );
  805.  
  806.                                         addlog( 8, "Warning: resynched at offset %ld, skipped %ld bytes!", coffs, coffs - lastoffs );
  807.                                         goto redo;
  808.                                 }
  809.                         }
  810.  
  811.                         rc = 4;
  812.                         break;
  813.                 }
  814.  
  815.                 rnewslen = CLU_FtellAsync( fromfile ) - lastoffs;
  816.  
  817.                 len = atoi( &linebuffer[ 8 ] );
  818.  
  819. //              Printf( "rnews: msglen %ld\n", len );
  820.  
  821.                 /* Nun gut... */
  822.                 rc = doarticle( fromfile, tofile, len );
  823.  
  824. #ifndef UUXQT_MD
  825.                 // Fehler bei Artikelbearbeitung
  826.                 if( rc )
  827.                 {
  828.                         BPTR tfh;
  829.  
  830.                         CLU_CloseAsync( tofile );
  831.                         tfh = Open( toname, MODE_OLDFILE );
  832.                         if( tfh )
  833.                         {
  834.                                 SetFileSize( tfh, tofileoffs, OFFSET_BEGINNING );
  835.                                 Close( tfh );
  836.                         }
  837.                         tofile = CLU_OpenAsync( toname, ASMODE_APPEND, ASYNCBUFF );
  838.                         if( !tofile )
  839.                         {
  840.                                 rc = 3;
  841.                                 break;
  842.                         }
  843.  
  844.                         trasharticle( rc, fromname, fromfile, lastoffs, len + rnewslen );
  845.                         rc = 0;
  846.                 }
  847. #endif
  848.  
  849.                 articlecount++;
  850.  
  851.                 set_fg( CLU_FtellAsync( fromfile ) );
  852.         }
  853.         CLU_CloseAsync( tofile );
  854.         addlog( 6, "finished processing; %ld articles, error %ld ", articlecount, rc );
  855.         return( rc );
  856. }
  857.  
  858. /*void __asm __saveds doexitsig( register __a0 struct Task *t )
  859. {
  860.         Signal( t, SIGBREAKF_CTRL_D );
  861. }
  862. */
  863.  
  864. extern APTR app;
  865.  
  866. extern char gzipfullpath[];
  867.  
  868. int rnews( char *from, char *to )
  869. {
  870.         struct AsyncFile * newsfile;
  871.         struct AsyncFile * tmpfile;
  872.         BPTR dostmpfile, dosnewsfile;
  873.         int rc;
  874.  
  875.         sourcebatchname = from;
  876.  
  877.         dosnewsfile = Open( from, MODE_OLDFILE );
  878.         if( !dosnewsfile )
  879.                 return( 1 );
  880.  
  881.         SetVBuf( dosnewsfile, NULL, BUF_FULL, ASYNCBUFF );
  882.  
  883.         FGets( dosnewsfile, linebuffer, 2047 );
  884.         Flush( dosnewsfile );
  885.  
  886.         /* Ungebatcht? */
  887.         if( !strnicmp( linebuffer, "#! rnews", 8 ) )
  888.         {
  889.                 set_status( GS( MSG_TXT_CONVERTNEWS ) );
  890.                 Close( dosnewsfile );
  891.                 newsfile = CLU_OpenAsync( from, ASMODE_READ, ASYNCBUFF );
  892.                 rc = donews( from, newsfile, to );
  893.                 lastoffset = CLU_FtellAsync( newsfile );
  894.                 CLU_CloseAsync( newsfile );
  895.                 return( rc );
  896.         }
  897.  
  898.         sprintf( tempfile, "uuconv.%lxtmp", CLU_GetSeqNum() );
  899.  
  900. //      Printf( "rnews: tempfile name %s\n", tempfile );
  901.  
  902.         /* Ohne Header? */
  903.         if( strnicmp( linebuffer, "#! cunbatch", 11 ) &&
  904.                 strnicmp( linebuffer, "#! gunbatch", 11 ) )
  905.         {
  906.                 Seek( dosnewsfile, 0, OFFSET_BEGINNING );
  907.         }
  908.  
  909.         dostmpfile = Open( tempfile, MODE_READWRITE );
  910.         if( !dostmpfile )
  911.         {
  912.                 Close( dosnewsfile );
  913.                 return( 2 );
  914.         }
  915.  
  916.         SetVBuf( dostmpfile, NULL, BUF_FULL, ASYNCBUFF );
  917.  
  918.         /* Entpacken */
  919.  
  920.         addlog( 5, "uncompressing %s to %s", from, tempfile );
  921.  
  922.         domui();
  923.         set_status( GS( MSG_TXT_UNBATCH ) );
  924. //      set_sleep( TRUE );
  925.  
  926. #ifndef UUXQT_MD
  927.         CLP_PK_AllocSem();
  928.         rc = CLU_MUI_RunCommand( app, "UUCP:C/GZip -d",
  929.                 NP_Input, dosnewsfile,
  930.                 NP_Output, dostmpfile,
  931.                 NP_StackSize, 20480,
  932.                 NP_Priority, -1,
  933.                 TAG_DONE
  934.         );
  935.         CLP_PK_FreeSem();
  936. #else
  937.         {
  938.                 char exec[ 256 ];
  939.  
  940.                 strcpy( exec, gzipfullpath );
  941.                 strcat( exec, " -d" );
  942.  
  943.                 rc = SystemTags( exec,
  944.                         SYS_Input, dosnewsfile,
  945.                         SYS_Output, dostmpfile,
  946.                         NP_StackSize, 20480,
  947.                         NP_Priority, -1,
  948.                         TAG_DONE
  949.                 );
  950.                 Close( dosnewsfile );
  951.                 Close( dostmpfile );
  952.         }
  953. #endif
  954.  
  955. //      set_sleep( FALSE );
  956.  
  957.         if( rc > 5 )
  958.         {
  959.                 addlog( 9, "gzip error return %ld!", rc );
  960.         }
  961.  
  962.         rc = CLU_GetFileLen( tempfile );
  963.         addlog( 5, "unbatched size %ld", rc );
  964.         set_file( tempfile, rc );
  965.         domui();
  966.  
  967.         tmpfile = CLU_OpenAsync( tempfile, ASMODE_READ, ASYNCBUFF );
  968.  
  969. //      Printf( "rnews: tmpfile ptr %lx\n", tmpfile );
  970.  
  971.         set_status( GS( MSG_TXT_CONVERTNEWS ) );
  972.         rc = donews( tempfile, tmpfile, to );
  973.  
  974.         lastoffset = CLU_FtellAsync( tmpfile );
  975.         CLU_CloseAsync( tmpfile );
  976.  
  977.         if( !rc )
  978.                 DeleteFile( from );
  979.  
  980.         DeleteFile( tempfile );
  981.  
  982.         return( rc );
  983. }
  984.