home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d109 / uupc.lha / UUpc / Source / LOCAL / ulib.c < prev   
C/C++ Source or Header  |  1987-10-28  |  5KB  |  284 lines

  1. /*        ulib.c
  2.  
  3.  
  4.         Amiga library
  5.         
  6.  
  7.     Things to do in uu host
  8.  
  9.         serial I/O
  10.         
  11.         directory stuff
  12.             opendir, readdir, closedir
  13.  
  14.         prolog and epilog
  15.  
  16.         system call
  17.  
  18. */
  19.  
  20. #include <stdio.h>
  21. #include "host.h"
  22. #include <sgtty.h>
  23.  
  24. /**/
  25. /*
  26.  *
  27.  *      login (for slave in PC mode)
  28.  * Real dumb login handshake
  29. */
  30. login()
  31. {
  32.     char    logmsg[132];
  33. #ifdef PC
  34. lretry:
  35.     msgtime = 9999;
  36.     rmsg(logmsg, 0); /* wait for a <CR> or <NL> */
  37.     msgtime = 2 * MSGTIME;
  38.     wmsg("Username:", 0);
  39.     rmsg(logmsg, 0);
  40.     printmsg( 0, "Username = %s", logmsg );
  41.     wmsg("Password:", 0);
  42.     rmsg(logmsg, 0);
  43.     printmsg( 14, "Password = %s", logmsg );
  44.     if (strcmp(logmsg, "uucp") != 0) 
  45.         goto lretry;
  46. #endif
  47.     return('I');
  48. }
  49.  
  50.  
  51. char inbuf[BUFSIZ];
  52. char outbuf[BUFSIZ];
  53.  
  54. swrite(data, num)
  55. int    num;
  56. char    *data;
  57. {
  58.  
  59.     int test;
  60.     unsigned char * cp;
  61.  
  62.     if (debuglevel > 14)
  63.         fputc( '{', stderr );
  64.     if (debuglevel > 14) {
  65.         test = num;
  66.         cp = data;
  67.         while (test--)
  68.             fprintf( stderr, isprint(*cp)? "{%c}":"{%02x}", *cp++ );
  69.     }
  70.     test = SIOWrite( data, num );
  71.     if (debuglevel > 14)
  72.         fputc( '}', stderr );
  73.     return( test );
  74.  
  75. }
  76.  
  77. /* non-blocking read essential to "g" protocol */
  78. /* see "dcpgpkt.c" for description */
  79. /* This all changes in a mtask systems. Requests for */
  80. /* I/O should get qued and an event flag given. Then the */
  81. /* requesting process (e.g.gmachine()) waits for the event */
  82. /* flag to fire processing either a read or a write. */
  83. /* Could be implemented on VAX/VMS or DG but not MS-DOS */
  84. sread(buf, num, timeout)
  85. char    *buf;
  86. int    num, timeout;
  87. {
  88. /*
  89.     return( SIORead( buf, num, num, timeout*10 ) );
  90. */
  91.     int count;
  92.     int test;
  93.     unsigned char * cp;
  94.  
  95.     if (debuglevel > 13)
  96.         fputc( '[', stderr );
  97.     printmsg( 15, "sread: num: %d  timeout: %d", num, timeout );
  98.         
  99.     count = SIORead( buf, num, num, timeout*10 );
  100.     printmsg( 15, "sread: read: %d ", count );
  101.  
  102.     if (debuglevel > 13 && count > 0) {
  103.         test = count;
  104.         cp = buf;
  105.         while (test--)
  106.             fprintf( stderr, isprint(*cp)? "[%c]":"[%02x]", *cp++ );
  107.     }
  108.         
  109.     if (debuglevel > 13)
  110.         fputc( ']', stderr );
  111.     return( count );    
  112.     
  113. }
  114.  
  115.  
  116.  
  117. openline(name, baud)
  118. char    *name, *baud;
  119. {
  120.  
  121.     printmsg( 3, "openline: name: \"%s\"  baud: \"%s\"", name, baud );
  122.     if ( SIOInit( name, baud ) )
  123.        return -1;
  124.     SIOInBuffer( inbuf, BUFSIZ );
  125.     SIOOutBuffer( outbuf, BUFSIZ );
  126.     return( 0 );
  127. }
  128.  
  129.  
  130. closeline()
  131. {
  132.     SIOClose( 1 );
  133. }
  134.  
  135.  
  136. nodot(string)
  137. {
  138. }
  139.  
  140.  
  141.  
  142. notimp( argc, argv )
  143. char *argv[];
  144. {
  145.     /*debuglevelMsg("\Pcheck argc (08) and argv (0a) ");*/
  146.     fprintf( stderr, "shell: %s not implemented\n", *argv );
  147. }
  148.  
  149. /*------------------------------------------------------------------*/
  150. /*    RNews:    my private rnews!                    */
  151. /*------------------------------------------------------------------*/
  152. static void RNews( inname )
  153. char *inname;
  154. {
  155.     extern    char *newsdir;
  156.     register struct tm    *thetm;
  157.     long    tloc;
  158.     char    filename[132];
  159.     char    format[128];
  160.     FILE     *f, *fin;
  161.     FILE    *FOPEN();
  162.     char    buf[BUFSIZ];
  163.     
  164.     static int count = 0;
  165.     int    len;
  166.     
  167.     /* inname is of form "D.jlamiBCnnnn".  Pick off the nnnn. */
  168.     len = strlen( inname ) - 1;
  169.     while ( len >= 0 )
  170.       {
  171.         if ( '0' <= inname[len] && inname[len] <= '9' )
  172.            --len;
  173.         else
  174.            break;
  175.        }
  176.  
  177.     sprintf( filename, "%s/%s", newsdir, &inname[len+1] );
  178.     if ( (f = FOPEN( filename, "r", 't' )) != NULL )
  179.        {
  180.         /* Already exists, so make a timestamped one. */
  181.         fclose( f );    
  182.         tloc = time( (long *)NULL );
  183.         thetm = localtime( &tloc );
  184.  
  185.         sprintf( filename, "%s/%02d%02d%02d%02d%02d%02d.%03d",
  186.             newsdir,
  187.             thetm->tm_year % 100, thetm->tm_mon,
  188.             thetm->tm_mday, thetm->tm_hour,
  189.             thetm->tm_min,  thetm->tm_sec,  count
  190.             );
  191.         ++count;
  192.        }
  193.     
  194.     if ( (f = FOPEN( filename, "w", 't' )) == (FILE *)NULL ) {
  195.         fprintf( stderr, "rnews: can't open %s\n", filename );
  196.         return;
  197.     }
  198.  
  199.     if ( (fin = FOPEN( inname, "r", 't' )) == NULL )
  200.       {
  201.         fprintf( stderr, "rnews: Couldn't open %s\n", inname );
  202.         fclose( f );
  203.         return;
  204.       }
  205.     
  206.     while ( fgets( buf, BUFSIZ, fin ) != (char *)NULL ) 
  207.         fputs( buf, f );
  208.  
  209.     fclose( f );
  210.     fclose( fin );
  211. }
  212.  
  213.  
  214.  
  215. /*         shell
  216.  
  217.  
  218. */
  219.  
  220. char * getcwd();
  221.  
  222. shell( command, inname, outname, errname )
  223. char * command;
  224. char * inname;
  225. char * outname;
  226. {
  227.  
  228.     char    * argvec[50];
  229.  
  230.     int rmail();
  231.     int rnews();
  232.     
  233.     int     argcp;
  234.  
  235.     char **argvp;
  236.     char args;
  237.     
  238.  
  239.     int    (*proto)();
  240.     
  241.     argcp = 0;
  242.  
  243.     argcp = getargs( command, argvec );
  244.  
  245.     argvp = argvec;
  246.     args = argcp;
  247.  
  248.     if ( debuglevel > 5 ) {
  249.         while ( args ) 
  250.             fprintf( stderr, "arg: %d  %s\n", args--, *argvp++ );
  251.         argvp = argvec;
  252.         args = argcp;
  253.     }
  254.     /* */
  255.     
  256.     proto = notimp;
  257.  
  258.     if ( strcmp( *argvp, "rmail" ) == SAME )
  259.         proto = rmail;
  260.  
  261.     else if ( strcmp( *argvp, "rnews" ) == SAME ) {
  262.         /* proto = rnews; */
  263.         RNews( inname );
  264.         return; 
  265.     }
  266.         
  267.     if ( *inname != '\0' ) {
  268.         fprintf( stderr, "reopening stdin as %s\n", inname );
  269.         fprintf( stderr, "curdir: %s\n", getcwd(NULL, 0)); /* */
  270.         if ( freopen( inname, "r", stdin ) == NULL ) 
  271.             fprintf( stderr, "Couldn't open %s, %d\n", inname, errno );
  272.     }
  273.     (proto)( argcp, argvp );
  274.  
  275.     if ( *inname != '\0' )
  276.        freopen( "*", "r", stdin );
  277.  
  278. }
  279.  
  280.  
  281.  
  282.  
  283.  
  284.