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

  1. #include "microdot.h"
  2.  
  3. #include <constructor.h>
  4.  
  5. #ifndef NO_RFC
  6.  
  7. #include "uuconv.h"
  8. #include "rmail.c"
  9. #include "rnews.c"
  10.  
  11. #include "ogre.h"
  12. #include "ogre_protos.h"
  13.  
  14. #if 0
  15. char *ng2board( char *ngname )
  16. {
  17.     static char tng[ 80 ];
  18.  
  19.     strcpy( tng, "/" );
  20.     strncat( tng, ngname, 78 );
  21.     tng[á79 ]á= 0;
  22.  
  23.     return( tng );
  24. }
  25. #endif
  26.  
  27. LONG lastoffset;
  28.  
  29. static char *cur_command;
  30. static char *cur_file;
  31. static char *cur_sys;
  32.  
  33. CONSTRUCTOR_P(initcc,500)
  34. {
  35.     cur_command = AllocMem( 1024 + 512, MEMF_CLEAR );
  36.     if( cur_command )
  37.     {
  38.         cur_file = cur_command + 1024;
  39.         cur_sys = cur_file + 256;
  40.         return( 0 );
  41.     }
  42.     outofmem();
  43.     return( 1 );
  44. }
  45.  
  46. DESTRUCTOR_P(initcc,500)
  47. {
  48.     if( cur_command )
  49.         FreeMem(cur_command, 1024 + 512 );
  50. }
  51.  
  52. static void testfilename( void )
  53. {
  54.     BPTR testlock;
  55.     char *p, *p2;
  56.     char temp[á256 ];
  57.     int gotp = 0;
  58.  
  59.     testlock = Lock( cur_file, SHARED_LOCK );
  60.     if( testlock )
  61.     {
  62.         UnLock( testlock );
  63.         return;
  64.     }
  65.  
  66.     p = cur_file;
  67.     p2 = temp;
  68.  
  69.     while( *p )
  70.     {
  71.         if( gotp && isupper( *p ) )
  72.             *p2++ = *p;
  73.         if( *p == '.'á)
  74.             gotp = TRUE;
  75.         *p2++ = *p++;
  76.     }
  77.     *p2 = 0;
  78.  
  79.     strcpy( cur_file, temp );
  80. }
  81.  
  82. static void processXfile( char *name )
  83. {
  84.     BPTR fromfile = Open( name, MODE_OLDFILE );
  85.     char *p;
  86.     char toname[ 64 ];
  87.     int rc = 1;
  88.     int pri;
  89.  
  90.     cur_command[á0 ]á= 0;
  91.     cur_file[ 0 ]á= 0;
  92.     cur_sys[á0 ]á= 0;
  93.     tempfile[á0 ]á= 0;
  94.  
  95.     if( !fromfile )
  96.         return;
  97.  
  98.     while( FGets( fromfile, linebuffer, 2047 ) )
  99.     {
  100.         clnl( linebuffer );
  101.  
  102.         switch( toupper( linebuffer[á0 ]á) )
  103.         {
  104.             case 'C':
  105.                 strncpy( cur_command, stpblk( &linebuffer[á1 ] ), 1023 );
  106.                 break;
  107.  
  108.             case 'U':
  109.                 p = stpblk( &linebuffer[á1 ] );
  110.                 while( !isspace( *p ) )
  111.                     p++;
  112.                 strncpy( cur_sys, stpblk( p ), 255 );
  113.                 p = strchr( cur_sys, '!' );
  114.                 if( p )
  115.                     *p = 0;
  116.                 break;
  117.  
  118.             case 'F':
  119.                 strncpy( cur_file, stpblk( &linebuffer[á1 ] ), 255 );
  120.                 testfilename();
  121.                 break;
  122.         }
  123.     }
  124.     Close( fromfile );
  125.  
  126.     sprintf( toname, "sortin.%lx", prefs.counter++ );
  127.  
  128.     addlog( 0, "executing %s (%s, data %s, to %s)", name, cur_command, cur_file, toname );
  129.  
  130.     set_cmd( "%s (%s)", name, cur_command );
  131.     set_file( cur_file, CLU_GetFileLen( cur_file ) );
  132.  
  133.     pri = 'S';
  134.     if( !strnicmp( cur_command, "rnews", 5 ) )
  135.     {
  136.         rc = rnews( cur_file, toname );
  137.     }
  138.     else if( !strnicmp( cur_command, "frnews", 5 ) )
  139.         rc = rnews( cur_file, toname );
  140.     else if( !strnicmp( cur_command, "rmail", 5 ) )
  141.     {
  142.         pri = 'P';
  143.         rc = rmail( cur_file, toname, stpblk( &cur_command[á5 ] ) );
  144.     }
  145.     else if( !strnicmp( cur_command, "frmail", 5 ) )
  146.     {
  147.         pri = 'P';
  148.         rc = rmail( cur_file, toname, stpblk( &cur_command[á5 ] ) );
  149.     }
  150. #if 0
  151.     else if( !strnicmp( cur_command, "rlharc", 6 ) )
  152.         rc = dorlharc( cur_file );
  153. #endif
  154.     else if( !strnicmp( cur_command, "rsmtp", 5 ) )
  155.         rc = bsmtp( cur_file );
  156.     else if( !strnicmp( cur_command, "rgsmtp", 6 ) )
  157.         rc = cbsmtp( cur_file );
  158.     else if( !strnicmp( cur_command, "rcsmtp", 6 ) )
  159.         rc = cbsmtp( cur_file );
  160.     else addlog( 0, "unknown command %s!", cur_command );
  161.  
  162.     DeleteFile( cur_file );
  163.     DeleteFile( name );
  164.     DeleteFile( tempfile );
  165. }
  166.  
  167. static struct ogwin *ogw;
  168.  
  169. char gzipfullpath[ 256 ];
  170.  
  171. void convrfc( void )
  172. {
  173.     struct Window *iw;
  174.     int rc;
  175.     char buff[ 4096 ], *p;
  176.  
  177.     if( !checkprograminpathfull( "Gzip", gzipfullpath ) )
  178.     {
  179.         askreq( "\"GZip\" nicht gefunden!\nDas Program \"GZip\" mu▀ im Pfad liegen und aufrufbar sein.", "Abbruch" );
  180.         return;
  181.     }
  182.  
  183.     ogw = ogreInitWindow( scr, WFLG_RMBTRAP, NULL, "MicroDot-UUXQT" );
  184.  
  185.     ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );
  186.     ogreAddText( ogw, 0, "Kommando:", 0, "", 50, TRUE );
  187.     ogreAddText( ogw, 1, "    Data:", 1, "" , 50, TRUE );
  188.     ogreAddText( ogw, 2, "  Status:", 2, "" , 50, TRUE );
  189.     ogreAddFuelGauge( ogw, 3, 3, 100 );
  190.     iw = ogreOpenWindow( ogw );
  191.  
  192.     pushdir( prefs.transferdir );
  193.  
  194.     for(;;)
  195.     {
  196.         rc = makefilelist( "", "X.#?", buff, 4096 );
  197.  
  198.         if( rc < 1 )
  199.             break;
  200.  
  201.         p = buff;
  202.  
  203.         while( rc-- )
  204.         {
  205.             char *p2 = strchr( p, 0 ) + 1;
  206.             set_fg( 0 );
  207.             set_status( "Suche X.-Dateien..." );
  208.             set_cmd( "-" );
  209.             set_file( NULL, 0 );
  210.             processXfile( p );
  211.             p = p2;
  212.         }
  213.     }
  214.  
  215.     popdir();
  216.     if( iw )
  217.         ogreExitWindow( ogw );
  218. }
  219.  
  220. static UWORD fmtfunc[] = {á0x16c0, 0x4e75 };
  221. void __stdargs set_cmd( STRPTR str, ... )
  222. {
  223.     char buffer[á256 ];
  224.  
  225.     RawDoFmt( str, &str + 1, (APTR)fmtfunc, buffer );
  226.     ogreSetStringValue( ogw, 0, buffer );
  227. }
  228. void __stdargs set_status( STRPTR str, ... )
  229. {
  230.     char buffer[á256 ];
  231.  
  232.     RawDoFmt( str, &str + 1, (APTR)fmtfunc, buffer );
  233.     ogreSetStringValue( ogw, 2, buffer );
  234. }
  235.  
  236. void set_file( STRPTR name, int bytes )
  237. {
  238.     char buffer[ 128 ];
  239.  
  240.     if( !name )
  241.     {
  242.         ogreSetStringValue( ogw, 1, "-" );
  243.         return;
  244.     }
  245.  
  246.     sprintf( buffer, "%s, %lD Bytes", name, bytes );
  247.     ogreSetStringValue( ogw, 1, buffer );
  248.     ogreSetMaxVal( ogw, 3, bytes );
  249. }
  250.  
  251. void set_fg( int p )
  252. {
  253.     ogreSetValue( ogw, 3, p );
  254. }
  255.  
  256. void __stdargs addlog( int dummy, char *str, ... )
  257. {
  258.     char buffer[á256 ];
  259.  
  260.     RawDoFmt( str, &str + 1, (APTR)fmtfunc, buffer );
  261.     printlog( "%s\n", buffer );    
  262. }
  263.  
  264. #endif
  265.