home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8708 / 22 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  56.3 KB

  1. From: Stuart.Lynne@van-bc.UUCP (Stuart Lynne)
  2. Newsgroups: comp.sources.misc
  3. Subject: uupc.ami.8.6
  4. Message-ID: <4200@ncoast.UUCP>
  5. Date: 17 Aug 87 01:17:48 GMT
  6. Sender: allbery@ncoast.UUCP
  7. Lines: 2679
  8. Approved: allbery@ncoast.UUCP
  9. X-Archive: comp.sources.misc/8708/22
  10.  
  11. >From uucp Wed Aug 12 02:30 PDT 1987
  12. >From slynne  Wed Aug 12 02:30:19 1987 remote from slmac
  13. Received: by van-bc.uucp (smail2.3)
  14.     id AA17514; 12 Aug 87 02:30:19 PDT (Wed)
  15. Received: by slmac.vnet.van-bc.uucp (pcmail) Wed Aug 12 02:35:17 1987
  16. Date: Wed Aug 12 02:35:17 1987
  17. From: Stuart Lynne - test a mac <slynne@slmac.vnet.van-bc.uucp>
  18. Message-ID: <146@slmac.vnet.van-bc.uucp>
  19. To: sl@van-bc
  20. Subject: shar/uupc.ami.8.6
  21.  
  22. #! /bin/sh
  23. # This is a shell archive, meaning:
  24. # 1. Remove everything above the #! /bin/sh line.
  25. # 2. Save the resulting text in a file.
  26. # 3. Execute the file with /bin/sh (not csh) to create the files:
  27. #    amiga/README.Amiga
  28. #    amiga/Makefile.ami
  29. #    amiga/Makefile
  30. #    amiga/chdir.c
  31. #    amiga/genv.c
  32. #    amiga/genv.dyna
  33. #    amiga/genv.h
  34. #    amiga/getcwd.c
  35. #    amiga/host.c
  36. #    amiga/host.h
  37. #    amiga/mkdir.c
  38. #    amiga/mlib.c
  39. #    amiga/ndir.c
  40. #    amiga/ndir.h
  41. #    amiga/SerialIO.c
  42. #    amiga/sio.c
  43. #    amiga/sleep.c
  44. #    amiga/Timer.c
  45. #    amiga/ulib.c
  46. # This archive created: Wed Aug 12 02:03:37 1987
  47. # By:    Stuart Lynne - test a mac ()
  48. export PATH; PATH=/bin:$PATH
  49. if test -f 'amiga/README.Amiga'
  50. then
  51.        echo shar: will not over-write existing file "'amiga/README.Amiga'"
  52. else
  53. cat << \SHAR_EOF > 'amiga/README.Amiga'
  54. README.Amiga             July 29, 1987        Jeff Lydiatt
  55.  
  56. This directory contains all the support code for the dcp serial
  57. I/O  routines,  the  directory  manipulation  support,  code to
  58. support  a  portable version of the unix getenv() function, and
  59. the  startup  code  for  both  uupc  and  mail.   Here is a brief
  60. description of the files:
  61.  
  62. Directory of PCMail:PCMail/AMIGA
  63.  
  64.   makefile    - compiles support modules for this directory.
  65.   Makefile.ami - makefile for uupc directory
  66.   genv.h    - header file for genv.c
  67.   host.h    - includes for uupc and mail programs.
  68.   ndir.h    - Amiga version of unix directory structures.
  69.   SerialIO.c    - very low level serial I/O device support.
  70.   Timer.c    - provides low level timer device support.
  71.   chdir.c    - chdir( path), makes "path" the current directory. 
  72.   genv.c    - reads the profile, provides getenv() function.
  73.   genv.dyna    - more flexible version of the above, but gurus!
  74.   getcwd.c    - return the path name of the current directory.
  75.   host.c    - prologue and epilogue for both uupc and mail. 
  76.   mkdir.c    - code for mkdir() to make a directory.  
  77.   mlib.c    - not sure: not used by anything I can see.
  78.   ndir.c    - defines opendir(), readdir(), and closedir(). 
  79.   sio.c        - defines SIOInit(), SIOSpeed(), SIOInBuffer(),
  80.           SIOClose(), SIOWrite(), SIORead()
  81.   sleep.c    - implements sleep( seconds ); 
  82.   ulib.c    - implements dcp routines swrite(), sread(), openline(),
  83.           closeline(), rnews(), and shell().
  84.  
  85.  
  86. You  should first compile all the all the files in this directory
  87. using  the  makefile supplied.  Not all files need to be compiled
  88. here.   Some  of  the  object  modules need to be in the primary,
  89. portable-file  directory  and  will  be  included  as needed from
  90. there.
  91.  
  92. BUGS:
  93.  
  94. This  version  has  been  compiled  and tested under Manx Aztec C
  95. v3.40a  with patch 3 installed.  I have been using it extensively
  96. over  the  past couple of weeks with minor problems.  There is an
  97. occasional guru that I can't seem to trace down, so beware.
  98.  
  99. There  seems to be a problem if the functions contained in genv.c
  100. uses  malloc  to  support  environment  variables.   The genv.bac
  101. version  contains  a  slightly  out of date version that would be
  102. much nicer to use if someone can find the problem.
  103.  
  104. If you have any questions, please contact me:
  105.  
  106.    jlydiatt@jlami.van-bc.UUCP   (Jeff Lydiatt)
  107.    {ihnp4!albera!ubc-vision,uunet}!van-bc!jlami!jlydiattSHAR_EOF
  108. cat << \SHAR_EOF > amiga/makefile
  109. MakeThemAll:    getcwd.o chdir.o mkdir.o ndir.o sio.o Timer.o SerialIO.o \
  110.         sleep.o genv.o
  111.  
  112. genv.o:    genv.h
  113.  
  114.  
  115. SHAR_EOF
  116. chmod +x 'amiga/README.Amiga'
  117. fi # end of overwriting check
  118. if test -f 'amiga/Makefile.ami'
  119. then
  120.        echo shar: will not over-write existing file "'amiga/Makefile.ami'"
  121. else
  122. cat << \SHAR_EOF > 'amiga/Makefile.ami'
  123. #        Makefile for uu/dcp with Amiga Aztec C
  124. #
  125. #        Jeff Lydiatt
  126. #        June/87
  127. #        Modeled after Stuart Lynne's for the Mac.
  128. #
  129.  
  130.  
  131. .c.o:
  132.     cc $(CFLAGS) $*.c
  133.  
  134. LFLAGS= -lc
  135. CFLAGS=
  136. AMILIB=    local/getcwd.o local/chdir.o local/mkdir.o local/ndir.o\
  137.     local/genv.o
  138.  
  139. SIOLIB=    local/sio.o local/Timer.o local/SerialIO.o local/sleep.o
  140.  
  141.  
  142. OFILES= dcp.o dcpsys.o dcpxfer.o dcpgpkt.o rmail.o lib.o
  143.  
  144.  
  145. all:     uupc mail
  146.     echo uupc & mail done
  147.  
  148. #
  149. # .o dependicies
  150. #
  151. dcp.o: dcp.c dcp.h local/host.h
  152. dcpsys.o: dcpsys.c dcp.h local/host.h
  153. dcpxfer.o: dcpxfer.c dcp.h local/host.h
  154. dcpgpkt.o: dcpgpkt.c dcp.h local/host.h
  155. lib.o: lib.c local/host.h
  156. lmail.o: pcmail.c lmail.c local/host.h
  157. mailhost.o: local/host.c local/host.h
  158. mail.o: local/host.h
  159. mlib.o: local/mlib.c local/host.h
  160. ulib.o: local/ulib.c local/host.h
  161. uuhost.o: local/host.c local/host.h
  162.  
  163. #
  164. # mail
  165. #
  166. mail: lmail.o mailhost.o mail.o mlib.o lib.o Makefile
  167.     ln mailhost.o mail.o lmail.o mlib.o lib.o $(AMILIB) $(LFLAGS) -o mail
  168.  
  169. #
  170. # uupc
  171. #
  172. uupc:    uuhost.o $(OFILES) ulib.o $(AMILIB) $(SIOLIB) Makefile
  173.     ln uuhost.o $(OFILES) ulib.o $(AMILIB) $(SIOLIB) $(LFLAGS) -o uupc
  174.  
  175. #
  176. # simple shar constructing
  177. #
  178. SDCP     = README.Install README.DCP \
  179.         dcp.c dcp.h dcpgpkt.c dcpsys.c dcpxfer.c
  180. SUU    = README.UU Makefile.ami Makefile.mac \
  181.     host.h ndir.h lib.c lmail.c mail.c mailhost.c mlib.c \
  182.     pcmail.c rmail.c ulib.c uuhost.c systems profile
  183. SMAC    = mac/README.MAC \
  184.     mac/host.c mac/host.h mac/mlib.c mac/ulib.c mac/profile
  185.  
  186. AMI    = amiga/README.Amiga amiga/makefile\
  187.     amiga/genv.h amiga/host.h amiga/ndir.h \
  188.     amiga/SerialIO.c amiga/Timer.c amiga/chdir.c amiga/genv.c \
  189.     amiga/genv.dyna amiga/getcwd.c amiga/host.c amiga/mkdir.c \
  190.     amiga/mlib.c amiga/ndir.c amiga/sio.c amiga/sleep.c amiga/ulib.c
  191.          
  192. #
  193. # Note: Manx's makefile seems to have a bug that forbids indirection
  194. #    such as "shar >lib a.c  b.c c.c"
  195. #    however "make >lib" seems to work fine if you edit out the
  196. #    commands make echos as it proceeds through the makefile.
  197. #
  198. #    Try make >uulib/dcp shardcp for example.
  199. #
  200. shardcp:
  201.     shar  $(SDCP)
  202. sharuu:
  203.     shar $(SUU)
  204. sharami:
  205.     shar $(AMI)
  206.  
  207.  
  208. SHAR_EOF
  209. chmod +x 'amiga/Makefile.ami'
  210. fi # end of overwriting check
  211. if test -f 'amiga/Makefile'
  212. then
  213.        echo shar: will not over-write existing file "'amiga/Makefile'"
  214. else
  215. cat << \SHAR_EOF > 'amiga/Makefile'
  216. MakeThemAll:    getcwd.o chdir.o mkdir.o ndir.o sio.o Timer.o SerialIO.o \
  217.         sleep.o genv.o
  218.  
  219. genv.o:    genv.h
  220.  
  221. SHAR_EOF
  222. fi # end of overwriting check
  223. if test -f 'amiga/chdir.c'
  224. then
  225.        echo shar: will not over-write existing file "'amiga/chdir.c'"
  226. else
  227. cat << \SHAR_EOF > 'amiga/chdir.c'
  228. #include <libraries/dos.h>
  229. #include <exec/memory.h>
  230. #include <functions.h>
  231.  
  232. #ifdef TEST
  233. #include <stdio.h>
  234. #endif
  235.  
  236. #ifndef NULL
  237. #define NULL 0L
  238. #endif
  239.  
  240.  
  241. /*------------------------------------------------------------------*/
  242. /*    chdir(path): make path the current directory. Return Ok/Not */
  243. /*------------------------------------------------------------------*/
  244.  
  245. int chdir( path )
  246. char *path;
  247. {
  248.     register struct Lock *lock;
  249.     struct Lock *oldLock;
  250. #ifdef TEST
  251.     fprintf( stderr, "Changing to directory \"%s\"\n\n", path );
  252. #endif    
  253.  
  254.     lock = Lock( path, ACCESS_READ );
  255.     if ( lock == 0L )
  256.        return (int)IoErr();
  257.     oldLock = CurrentDir( lock );
  258.     if ( oldLock )
  259.        UnLock( oldLock );
  260.     return 0;
  261. }
  262.  
  263.  
  264. #ifdef TEST
  265. main()
  266. {
  267.     char command[108];
  268.     FILE *f;
  269.  
  270.     gets( command );
  271.     fprintf( stderr, "%d\n", chdir( command ));
  272.  
  273.     if (f = fopen("abc", "r"))
  274.       {
  275.        fprintf( stderr, "Opened Ok!\n");
  276.        fclose( f );
  277.       }
  278.     else
  279.        fprintf( stderr, "Can't open abc\n");
  280.  
  281.     exit(NULL);
  282. }
  283.  
  284. #endif
  285.  
  286.  
  287.  
  288. SHAR_EOF
  289. fi # end of overwriting check
  290. if test -f 'amiga/genv.c'
  291. then
  292.        echo shar: will not over-write existing file "'amiga/genv.c'"
  293. else
  294. cat << \SHAR_EOF > 'amiga/genv.c'
  295. /*         genv.c
  296.  
  297.  
  298.  
  299.         copyright (C) 1987 Jeff Lydiatt
  300.  
  301.         Copying and use of this program are controlled by the terms of the
  302.         Free Software Foundations GNU Emacs General Public License.
  303.  
  304.  
  305.         version        0.1        09 July 87
  306.  
  307.  
  308.  
  309. */
  310.  
  311. #include <stdio.h>
  312.  
  313. #include "genv.h"
  314.  
  315.      /* Environment variables are in file "PROFILE" */
  316. #define PROFILE ":usr/lib/uucp/profile"
  317.  
  318. #define SAME    0
  319. #define MAXLINE 255
  320.  
  321. #define DMAILBOX    "mailbox"
  322. #define    DNAME        "noname"
  323. #define    DDOMAIN        "pc.uucp"
  324. #define    DMAILDIR    ":usr/spool/mail"
  325. #define DHOME        ":usr/noname"
  326. #define    DCONFDIR    ":usr/lib/uucp"
  327. #define    DSPOOLDIR    ":usr/spool/uucp"
  328. #define DLOGDIR        ":usr/spool/uucp"
  329. #define DPUBDIR        ":usr/spool/uucppublic"
  330. #define DNEWSDIR    ":usr/spool/rnews"
  331. #define DTEMPDIR    "RAM:T"
  332. #define    DMAILSERVICE    "host"
  333. #define    DNODENAME    "noname"
  334. #define    DDEVICE        "CON:"
  335. #define    DSPEED        "1200"
  336.  
  337. #define    TFILENAME    "tmpfile"
  338. #define    FILENAME     "%s/%s"
  339.  
  340. #include <stdio.h>
  341. #include <ctype.h>
  342.  
  343. struct environment
  344.   {
  345.      char name[16];
  346.      char value[64];
  347.  
  348.   };
  349. typedef struct environment ENV;
  350.  
  351. static ENV profile[]=
  352.   {
  353.     MAILBOX,     "",
  354.     NAME,        "",
  355.     DOMAIN,        "",
  356.     MAILDIR,    "",
  357.     HOME,        "",
  358.     CONFDIR,    "",
  359.     SPOOLDIR,    "",
  360.     LOGDIR,        "",
  361.     PUBDIR,        "",
  362.     NEWSDIR2,    "",
  363.     TEMPDIR,    "",
  364.     MAILSERVICE,    "",
  365.     NODENAME,    "",
  366.     DEVICE,        "",
  367.     SPEED,        "",
  368.     "",        "",
  369.   };    
  370. char    *name = NULL;
  371. char    *mailbox = NULL;
  372. char    *home = NULL;
  373. char    *domain = NULL;
  374. char    *maildir = NULL;
  375. char    *confdir = NULL;
  376. char     *spooldir = NULL;
  377. char    *logdir = NULL;
  378. char    *pubdir = NULL;
  379. char    *mailserv = NULL;
  380. char    *nodename = NULL;
  381. char    *device = NULL;
  382. char    *speed = NULL;
  383. char    *tempdir = NULL;
  384. char    *newsdir = NULL;
  385.  
  386. /*--------------------------------------------------------------*/
  387. /*    getone: get next character file f.  f already open    */
  388. /*--------------------------------------------------------------*/
  389.  
  390. static int getone( f )
  391. FILE *f;
  392. {
  393.    char c, line[256];
  394.    static int pos = 0;
  395.    static int len = 0;
  396.  
  397.    if ( ++pos > len || line[pos] == '\0' ) 
  398.      {
  399.     if ( fgets( line, 255, f ) == NULL )
  400.        return EOF;
  401.     pos = 0;
  402.     len = strlen( line );
  403.      }
  404.  
  405.    c = line[pos];
  406.    return c;
  407.    
  408. }
  409.  
  410. /*--------------------------------------------------------------*/
  411. /*    getsym: get next symbol from file f.  f already open    */
  412. /*--------------------------------------------------------------*/
  413.  
  414. #define ID    1001
  415. #define DELIM    1002
  416. #define STR    1003
  417. #define EOL    1004
  418. #define OTHER    1005
  419. #define UNKNOWN -1000
  420.  
  421. static int getsym( f, sym )
  422. FILE *f;
  423. char *sym;
  424. {
  425.    /* Simple non reentrant, non reuseable get next symbol from file f */
  426.    /* Valid symbols are:
  427.         Type    Symbol Returned    Comment
  428.  
  429.     ID    <identifier>    any valid c identifier.
  430.         DELIM    '='        an equal sign.
  431.     STR    a string    anything between "" or ''.
  432.     EOL    '\n'        a newline.
  433.     EOF            the end of file character.
  434.     OTHER   a character    anything else.
  435.     
  436.     Comments begin with # and are delimited by an end of line
  437.    */
  438.  
  439.    static int lastchar = UNKNOWN; /* Unknown */
  440.    int c, delim;
  441.  
  442.    /* strip leading white space */
  443.  
  444.    if ( lastchar != UNKNOWN )
  445.       c = lastchar;
  446.    else
  447.       c = getone( f );
  448.  
  449.    while ( c == ' ' || c == '\t' )
  450.       c = getone( f );
  451.    lastchar = UNKNOWN;
  452.  
  453.   /* Comments are '#' delimited by EOL character */
  454.  
  455.    if ( c == '#' )
  456.       while ( c != '\n' && c != EOF )
  457.      c = getone( f );
  458.  
  459.    if ( c == EOF )        /* End of file? */
  460.       return EOF;
  461.  
  462.    if ( c == '\n' )        /* End of Line? */
  463.      {
  464.     strcpy( sym, "\n" );
  465.     return EOL;
  466.      }
  467.  
  468.    if ( c == '=' )        /* Delimiter '='? */
  469.      {
  470.     strcpy( sym, "=" );
  471.     return DELIM;
  472.      } 
  473.  
  474.    if ( c == '\"' || c == '\'' )/* String ? */
  475.      {
  476.     delim = c;
  477.     while ( (c = getone( f )) != delim && c != EOF && c != '\n' )
  478.        *sym++ = c;
  479.     *sym = '\0';
  480.     c = getone( f );
  481.     return STR;
  482.      }
  483.  
  484.    if ( isalpha( c ) )        /* Identifier ? */
  485.      {
  486.     *sym++ = c;
  487.     while ( ( c = getone( f )) == '_' || isalnum(c) )
  488.       *sym++ = c;
  489.     *sym = '\0';
  490.     lastchar = c;
  491.     return ID;
  492.      }
  493.  
  494.    *sym++ = c;
  495.    *sym = '\0';
  496.    return OTHER;
  497.  
  498. }
  499.     
  500.  
  501. /*--------------------------------------------------------------*/
  502. /*    setenv: insert an environment variable into my list    */
  503. /*--------------------------------------------------------------*/
  504.  
  505. static void setenv( var, value )
  506. char *var;
  507. char *value;
  508. {
  509.     register ENV *p;
  510.  
  511.     for ( p = &profile[0];
  512.           *(p->name) != '\0';
  513.           ++p ) 
  514.       {
  515.          if ( strcmp( p->name, var ) == SAME )
  516.         {
  517.  
  518.              strcpy( p->name, var );
  519.            strcpy( p->value, value);
  520.            break;
  521.         }
  522.        }
  523. }
  524.  
  525. /*--------------------------------------------------------------*/
  526. /*    getenv: get pointer to value of environment variable    */
  527. /*--------------------------------------------------------------*/
  528.  
  529. static char *getenv( var )
  530. char *var;
  531. {
  532.     register ENV *p;
  533.  
  534.     for ( p = &profile[0];
  535.           *(p->name) != '\0';
  536.           ++p )
  537.       {
  538.          if ( strcmp( p->name, var ) == SAME )
  539.             if ( *p->value != '\0' )
  540.            return p->value;
  541.         else
  542.            break;
  543.       }
  544.     return NULL;
  545. }
  546.  
  547. /*--------------------------------------------------------------*/
  548. /*    readenv: read environment from a file.             */
  549. /*--------------------------------------------------------------*/
  550.  
  551. static void readenv()
  552. {
  553.    FILE *f;
  554.    int symval;
  555.    char name[MAXLINE+1], value[MAXLINE+1];
  556.  
  557.    fprintf( stderr, "Opening profile\n");
  558.    if ( (f = fopen( PROFILE, "r" )) == NULL )
  559.      {
  560.     fprintf( stderr, "Can't open profile file \"%s\"\n",
  561.     PROFILE );
  562.     exit( NULL );
  563.      }
  564.  
  565.     /* File is layed out as follows:
  566.  
  567.     <environment variable> '=' <ID> | <STRING> # comment....
  568.  
  569.      */
  570.  
  571.     while ( (symval = getsym( f, name )) != EOF )
  572.       {
  573.     /* Skip over any comment lines */
  574.  
  575.     while ( symval == EOL )
  576.        symval = getsym( f, name );
  577.     if ( symval == EOF )
  578.        break;
  579.  
  580.     if ( symval != ID )
  581.       {
  582.          fprintf( stderr, "Bad environment variable name %s\n", name );
  583.          exit( NULL );
  584.       }
  585.  
  586.     if ( (symval = getsym( f, value )) != DELIM )
  587.       {
  588.          fprintf( stderr, "Missing '=' in environment file\n" );
  589.          exit( NULL );
  590.       }
  591.  
  592.     if ( (symval = getsym( f, value )) != ID && symval != STR )
  593.       {
  594.          fprintf( stderr, "missing value in environment file\n");
  595.          exit( NULL );
  596.       }
  597.  
  598.     setenv( name, value );
  599.       }
  600.     fclose( f );
  601.  
  602. }
  603.  
  604. /*--------------------------------------------------------------*/
  605. /*    exitenv: free that memory when done!            */
  606. /*--------------------------------------------------------------*/
  607.  
  608. void exitenv()
  609. {
  610. }
  611.  
  612. static void genv(thename, envname, dflt)
  613. char **thename;
  614. char *envname;
  615. char *dflt;
  616. {
  617.     if ((*thename = getenv( envname )) == NULL) {
  618.         fprintf( stderr, "genv: %s not found, using %s\n", envname, dflt );
  619.         *thename = dflt;
  620.     }
  621.     /* fprintf( stderr, "genv: %s \"%s\"\n", envname, *thename ); /**/
  622. }
  623.  
  624. void loadenv()
  625. {
  626.  
  627.     readenv();    /* read the profile from a file */ 
  628.  
  629.     /* get environment var's */
  630.     genv( &name, NAME, DNAME );
  631.     genv( &mailbox, MAILBOX, DMAILBOX );
  632.     genv( &home, HOME, DHOME );
  633.     genv( &domain, DOMAIN, DDOMAIN );
  634.     genv( &maildir, MAILDIR, DMAILDIR );
  635.     genv( &confdir, CONFDIR, DCONFDIR );
  636.     genv( &spooldir, SPOOLDIR, DSPOOLDIR );
  637.     genv( &logdir, LOGDIR, DLOGDIR );
  638.     genv( &pubdir, PUBDIR, DPUBDIR );
  639.     genv( &mailserv, MAILSERVICE, DMAILSERVICE );
  640.     genv( &nodename, NODENAME, DNODENAME );
  641.     genv( &device, DEVICE, DDEVICE );
  642.     genv( &speed, SPEED, DSPEED );
  643.     genv( &tempdir, TEMPDIR, DTEMPDIR );
  644.     genv( &newsdir, NEWSDIR2, DNEWSDIR );
  645. }
  646.  
  647. void mkfilename( filename, dirname, name )
  648. char * filename;
  649. char * dirname;
  650. char * name;
  651. {
  652.     sprintf( filename, FILENAME, dirname, name );    
  653.     fprintf( stderr, "New filename %s\n", filename );  /**/    
  654. }
  655.  
  656.  
  657. #ifdef TEST
  658. main()
  659. {
  660.     register ENV *p;
  661.  
  662.     loadenv();
  663.  
  664.     for ( p = &profile[0];
  665.           *(p->name) != '\0';
  666.           ++p)
  667.  
  668.         fprintf( stderr, "name=\"%s\", value=\"%s\"\n",
  669.              p->name, p->value);
  670.  
  671. #endif
  672.  
  673.  
  674.  
  675. SHAR_EOF
  676. fi # end of overwriting check
  677. if test -f 'amiga/genv.dyna'
  678. then
  679.        echo shar: will not over-write existing file "'amiga/genv.dyna'"
  680. else
  681. cat << \SHAR_EOF > 'amiga/genv.dyna'
  682. /*         genv.c
  683.  
  684.  
  685.  
  686.         copyright (C) 1987 Jeff Lydiatt
  687.  
  688.         Copying and use of this program are controlled by the terms of the
  689.         Free Software Foundations GNU Emacs General Public License.
  690.  
  691.  
  692.         version        0.1        10 July 87
  693.  
  694.  
  695.  
  696. */
  697.  
  698. #include <stdio.h>
  699.  
  700. #include "genv.h"
  701.  
  702.      /* Environment variables are in file "PROFILE" */
  703. #define PROFILE ":usr/lib/uucp/profile"
  704.  
  705. #define SAME    0
  706. #define MAXLINE 255
  707.  
  708. #define DMAILBOX    "mailbox"
  709. #define    DNAME        "noname"
  710. #define    DDOMAIN        "pc.uucp"
  711. #define    DMAILDIR    ":usr/spool/mail"
  712. #define DHOME        ":usr/noname"
  713. #define    DCONFDIR    ":usr/lib/uucp"
  714. #define    DSPOOLDIR    ":usr/spool/uucp"
  715. #define DLOGDIR        ":usr/spool/uucp"
  716. #define DPUBDIR        ":usr/spool/uucppublic"
  717. #define DNEWSSDIR    ":usr/spool/rnews"
  718. #define DTEMPDIR    "RAM:T"
  719. #define    DMAILSERVICE    "host"
  720. #define    DNODENAME    "noname"
  721. #define    DDEVICE        "CON:"
  722. #define    DSPEED        "1200"
  723.  
  724. #define    TFILENAME    "tmpfile"
  725. #define    FILENAME     "%s/%s"
  726.  
  727. #include <stdio.h>
  728. #include <ctype.h>
  729.  
  730. char    *name = NULL;
  731. char    *mailbox = NULL;
  732. char    *home = NULL;
  733. char    *domain = NULL;
  734. char    *maildir = NULL;
  735. char    *confdir = NULL;
  736. char     *spooldir = NULL;
  737. char    *logdir = NULL;
  738. char    *pubdir = NULL;
  739. char    *mailserv = NULL;
  740. char    *nodename = NULL;
  741. char    *device = NULL;
  742. char    *speed = NULL;
  743. char    *tempdir = NULL;
  744.  
  745. /*--------------------------------------------------------------*/
  746. /*    getone: get next character file f.  f already open    */
  747. /*--------------------------------------------------------------*/
  748.  
  749. static int getone( f )
  750. FILE *f;
  751. {
  752.    char c, line[256];
  753.    static int pos = 0;
  754.    static int len = 0;
  755.  
  756.    if ( ++pos > len || line[pos] == '\0' ) 
  757.      {
  758.     if ( fgets( line, 255, f ) == NULL )
  759.        return EOF;
  760.     pos = 0;
  761.     len = strlen( line );
  762.      }
  763.  
  764.    c = line[pos];
  765.    return c;
  766.    
  767. }
  768.  
  769. /*--------------------------------------------------------------*/
  770. /*    getsym: get next symbol from file f.  f already open    */
  771. /*--------------------------------------------------------------*/
  772.  
  773. #define ID    1001
  774. #define DELIM    1002
  775. #define STR    1003
  776. #define EOL    1004
  777. #define OTHER    1005
  778. #define UNKNOWN -1000
  779.  
  780. static int getsym( f, sym )
  781. FILE *f;
  782. char *sym;
  783. {
  784.    /* Simple non reentrant, non reuseable get next symbol from file f */
  785.    /* Valid symbols are:
  786.         Type    Symbol Returned    Comment
  787.  
  788.     ID    <identifier>    any valid c identifier.
  789.         DELIM    '='        an equal sign.
  790.     STR    a string    anything between "" or ''.
  791.     EOL    '\n'        a newline.
  792.     EOF            the end of file character.
  793.     OTHER   a character    anything else.
  794.     
  795.     Comments begin with # and are delimited by an end of line
  796.    */
  797.  
  798.    static int lastchar = UNKNOWN;
  799.    int c, delim;
  800.  
  801.    /* strip leading white space */
  802.  
  803.    if ( lastchar != UNKNOWN )
  804.       c = lastchar;
  805.    else
  806.       c = getone( f );
  807.  
  808.    while ( c == ' ' || c == '\t' )
  809.       c = getone( f );
  810.    lastchar = UNKNOWN;
  811.  
  812.   /* Comments are '#' delimited by EOL character */
  813.  
  814.    if ( c == '#' )
  815.       while ( c != '\n' && c != EOF )
  816.      c = getone( f );
  817.  
  818.    if ( c == EOF )        /* End of file? */
  819.       return EOF;
  820.  
  821.    if ( c == '\n' )        /* End of Line? */
  822.      {
  823.     strcpy( sym, "\n" );
  824.     return EOL;
  825.      }
  826.  
  827.    if ( c == '=' )        /* Delimiter '='? */
  828.      {
  829.     strcpy( sym, "=" );
  830.     return DELIM;
  831.      } 
  832.  
  833.    if ( c == '\"' || c == '\'' )/* String ? */
  834.      {
  835.     delim = c;
  836.     while ( (c = getone( f )) != delim && c != EOF && c != '\n' )
  837.        *sym++ = c;
  838.     *sym = '\0';
  839.     c = getone( f );
  840.     return STR;
  841.      }
  842.  
  843.    if ( isalpha( c ) )        /* Identifier ? */
  844.      {
  845.     *sym++ = c;
  846.     while ( ( c = getone( f )) == '_' || isalnum(c) )
  847.       *sym++ = c;
  848.     *sym = '\0';
  849.     lastchar = c;
  850.     return ID;
  851.      }
  852.  
  853.    *sym++ = c;
  854.    *sym = '\0';
  855.    return OTHER;
  856.  
  857. }
  858.     
  859. /*--------------------------------------------------------------*/
  860. /*    xmalloc: Just alloc with die on allocation failure    */
  861. /*--------------------------------------------------------------*/
  862. static char *xmalloc( size )
  863. unsigned int size;
  864. {
  865.     char *malloc();
  866.     register char *p;
  867.  
  868.  
  869.     if ( (p = malloc( size )) != NULL )
  870.        return p;
  871.  
  872.     fprintf( stderr, "Genv.c: Can't allocated %u bytes\n", size );
  873.     exit( NULL );
  874. }
  875.  
  876. /*--------------------------------------------------------------*/
  877. /*    setenv: insert an environment variable into my list    */
  878. /*--------------------------------------------------------------*/
  879.  
  880. struct environment
  881.    {
  882.     struct environment *next;
  883.     char *name;
  884.     char *value;
  885.    };
  886.  
  887. typedef struct environment ENV;
  888.  
  889. static ENV *envList = NULL;
  890.  
  891. static void setenv( var, value )
  892. char *var;
  893. char *value;
  894. {
  895.     register ENV *envframe;
  896.  
  897.     envframe = (ENV *) xmalloc( sizeof( ENV ));
  898.     envframe->name  = xmalloc( strlen(var)+1 );
  899.     envframe->value = xmalloc( strlen(value)+1 );
  900.     envframe->next  = envList;
  901.     envList        = envframe;
  902.     
  903.     strcpy( envframe->name, var );
  904.     strcpy( envframe->value, value);
  905. }
  906.  
  907. /*--------------------------------------------------------------*/
  908. /*    getenv: get pointer to value of environment variable    */
  909. /*--------------------------------------------------------------*/
  910.  
  911. static char *getenv( var )
  912. char *var;
  913. {
  914.     register ENV *list;
  915.  
  916.     for ( list = envList;
  917.           list != (ENV *)NULL;
  918.           list = list->next )
  919.        if ( strcmp( var, list->name ) == SAME )
  920.         return list->value;
  921.  
  922.     return NULL;
  923. }
  924.  
  925. /*--------------------------------------------------------------*/
  926. /*    readenv: read environment from a file.             */
  927. /*--------------------------------------------------------------*/
  928.  
  929. static void readenv()
  930. {
  931.    FILE *f;
  932.    int symval;
  933.    char name[MAXLINE+1], value[MAXLINE+1];
  934.  
  935.    if ( (f = fopen( PROFILE, "r" )) == NULL )
  936.      {
  937.     fprintf( stderr, "Can't open profile file \"%s\"\n",
  938.     PROFILE );
  939.     exit( NULL );
  940.      }
  941.  
  942.     /* File is layed out as follows:
  943.  
  944.     <environment variable> '=' <ID> | <STRING> # comment....
  945.  
  946.      */
  947.  
  948.     while ( (symval = getsym( f, name )) != EOF )
  949.       {
  950.     /* Skip over any comment lines */
  951.  
  952.     while ( symval == EOL )
  953.        symval = getsym( f, name );
  954.     if ( symval == EOF )
  955.        break;
  956.  
  957.     if ( symval != ID )
  958.       {
  959.          fprintf( stderr, "Bad environment variable name %s\n", name );
  960.          exit( NULL );
  961.       }
  962.  
  963.     if ( (symval = getsym( f, value )) != DELIM )
  964.       {
  965.          fprintf( stderr, "Missing '=' in environment file\n" );
  966.          exit( NULL );
  967.       }
  968.  
  969.     if ( (symval = getsym( f, value )) != ID && symval != STR )
  970.       {
  971.          fprintf( stderr, "missing value in environment file\n");
  972.          exit( NULL );
  973.       }
  974.  
  975.     setenv( name, value );
  976.       }
  977.     fclose( f );
  978.  
  979. }
  980.  
  981. /*--------------------------------------------------------------*/
  982. /*    exitenv: free that memory when done!            */
  983. /*--------------------------------------------------------------*/
  984.  
  985. void exitenv()
  986. {
  987.     register ENV *p, *q;    
  988.  
  989.     for ( p = envList; p != NULL; p = q )
  990.       {
  991.         free( p->name );
  992.         free( p->value);
  993.         q = p->next;
  994.         free( p );
  995.       }
  996.     envList = NULL;
  997. }
  998.  
  999. static void genv(thename, envname, dflt)
  1000. char **thename;
  1001. char *envname;
  1002. char *dflt;
  1003. {
  1004.     if ((*thename = getenv( envname )) == NULL) {
  1005.         fprintf( stderr, "genv: %s not found, using %s\n", envname, dflt );
  1006.         *thename = dflt;
  1007.     }
  1008.     /* fprintf( stderr, "genv: %s \"%s\"\n", envname, *thename ); /**/
  1009. }
  1010.  
  1011. void loadenv()
  1012. {
  1013.  
  1014.     readenv();    /* read the profile from a file */ 
  1015.  
  1016.     /* get environment var's */
  1017.     genv( &name, NAME, DNAME );
  1018.     genv( &mailbox, MAILBOX, DMAILBOX );
  1019.     genv( &home, HOME, DHOME );
  1020.     genv( &domain, DOMAIN, DDOMAIN );
  1021.     genv( &maildir, MAILDIR, DMAILDIR );
  1022.     genv( &confdir, CONFDIR, DCONFDIR );
  1023.     genv( &spooldir, SPOOLDIR, DSPOOLDIR );
  1024.     genv( &logdir, LOGDIR, DLOGDIR );
  1025.     genv( &pubdir, PUBDIR, DPUBDIR );
  1026.     genv( &mailserv, MAILSERVICE, DMAILSERVICE );
  1027.     genv( &nodename, NODENAME, DNODENAME );
  1028.     genv( &device, DEVICE, DDEVICE );
  1029.     genv( &speed, SPEED, DSPEED );
  1030.     genv( &tempdir, TEMPDIR, DTEMPDIR );
  1031. }
  1032.  
  1033. void mkfilename( filename, dirname, name )
  1034. char * filename;
  1035. char * dirname;
  1036. char * name;
  1037. {
  1038.     sprintf( filename, FILENAME, dirname, name );    
  1039.     fprintf( stderr, "New filename %s\n", filename );  /**/    
  1040. }
  1041.  
  1042.  
  1043. #ifdef TEST
  1044. main()
  1045. {
  1046.     register ENV *p;    
  1047.  
  1048.     loadenv();
  1049.  
  1050.     for ( p = envList; p != NULL; p = p->next )
  1051.       fprintf( stderr, "Name=\"%s\" value=\"%s\"\n", 
  1052.            p->name, p->value );
  1053.     
  1054. }
  1055. #endif
  1056.  
  1057.  
  1058.  
  1059. SHAR_EOF
  1060. fi # end of overwriting check
  1061. if test -f 'amiga/genv.h'
  1062. then
  1063.        echo shar: will not over-write existing file "'amiga/genv.h'"
  1064. else
  1065. cat << \SHAR_EOF > 'amiga/genv.h'
  1066. /*    genv.c
  1067.  
  1068.  
  1069.  
  1070.     copyright (C) 1987 Stuart Lynne
  1071.  
  1072.     Copying and use of this program are controlled by the terms of the
  1073.     Free Software Foundations GNU Emacs General Public License.
  1074.  
  1075.  
  1076.     version        0.1        March 31/1987
  1077.  
  1078.     
  1079.  
  1080. environment variables
  1081.  
  1082.     The following evironment variables are defined:
  1083.  
  1084.     MAILBOX        current user's mailbox,     "sl"
  1085.     NAME        current user's name,         "Stuart Lynne"
  1086.     DOMAIN        domain of this machine,     "mac.van-bc.can"
  1087.     MAILDIR        where mail is kept,        "/usr/mail"
  1088.     CONFDIR        where config data is  kept,    "/usr/lib/uucp"
  1089.     SPOOLDIR    where spooled files are     "/usr/spool/uucp"
  1090.     LOGDIR        where log file are placed    "/usr/spool/uucp"
  1091.     PUBDIR        public spool directory        "/usr/spool/uucppublic"
  1092.     NEWSDIR        news directory            "/usr/spool/news"
  1093.     TEMPDIR        where temp files are created    "/tmp"
  1094.     HOME        where uses private files are    "/usr/sl"
  1095.     MAILSERVICE    who do we send remote mail    "van-bc"
  1096.     NODENAME    what is our local nodename    "slmac"
  1097.     DEVICE        what is the default device    ".a"
  1098.     SPEED        what is the default speed    "1200"
  1099.  
  1100. */
  1101.  
  1102.  
  1103. #define    MAILBOX        "MAILBOX"
  1104. #define    NAME        "NAME"
  1105. #define    DOMAIN        "DOMAIN"
  1106. #define    MAILDIR        "MAILDIR"
  1107. #define HOME        "HOME"
  1108.  
  1109. #define    CONFDIR        "CONFDIR"
  1110. #define SPOOLDIR    "SPOOLDIR"
  1111. #define LOGDIR        "LOGDIR"
  1112. #define    PUBDIR        "PUBDIR"
  1113. #define NEWSDIR2    "NEWSDIR"
  1114. #define TEMPDIR        "TEMPDIR"
  1115. #define    MAILSERVICE    "MAILSERVICE"
  1116.  
  1117. #define NODENAME    "NODENAME"
  1118. #define    DEVICE        "DEVICE"
  1119. #define    SPEED        "SPEED"
  1120.  
  1121. extern char    *mailbox;
  1122. extern char    *name;
  1123. extern char    *domain;
  1124. extern char    *maildir;
  1125. extern char    *home;
  1126.  
  1127. extern char    *confdir;
  1128. extern char    *spooldir;
  1129. extern char    *logdir;
  1130. extern char    *pubdir;
  1131. extern char    *tempdir;
  1132. extern char    *mailserv;
  1133.  
  1134. extern char    *nodename;
  1135. extern char    *device;
  1136. extern char    *speed;
  1137. extern char    *newsdir;
  1138.  
  1139. void loadenv();
  1140. void mkfilename();
  1141.  
  1142.  
  1143.  
  1144. SHAR_EOF
  1145. fi # end of overwriting check
  1146. if test -f 'amiga/getcwd.c'
  1147. then
  1148.        echo shar: will not over-write existing file "'amiga/getcwd.c'"
  1149. else
  1150. cat << \SHAR_EOF > 'amiga/getcwd.c'
  1151.  
  1152. #include <libraries/dos.h>
  1153. #include <exec/memory.h>
  1154. #include <functions.h>
  1155.  
  1156. #ifdef TEST
  1157. #include <stdio.h>
  1158. #endif
  1159.  
  1160. #ifndef NULL
  1161. #define NULL 0L
  1162. #endif
  1163.  
  1164. char * malloc();
  1165.  
  1166. /*--------------------------------------------------------------*/
  1167. /*    GetCurrentPath: get full path of the current directory    */
  1168. /*--------------------------------------------------------------*/
  1169.  
  1170. static void GetCurrentPath( path )
  1171. register char *path;
  1172. {
  1173.  
  1174.     char s1[ 108 ];
  1175.     char *name;
  1176.     register struct Lock *locka, *lockb;
  1177.         register struct FileInfoBlock *fib;
  1178.  
  1179.     fib = (struct FileInfoBlock *)AllocMem(
  1180.           (long)sizeof(struct FileInfoBlock), MEMF_CHIP | MEMF_CLEAR);
  1181.     if ( fib == 0L )
  1182.        {
  1183. #ifdef TEST
  1184.          fprintf( stderr, "GetCurrentPath: Oops - Memory allocation failed\n");
  1185. #endif
  1186.          *path = '\0';
  1187.          return;
  1188.        }
  1189.     
  1190.     locka = Lock("", ACCESS_READ );
  1191.     *path = s1[0] = '\0';
  1192.  
  1193.     while ( locka != NULL )
  1194.       {
  1195.         Examine( locka, fib );
  1196.         name = fib->fib_FileName;
  1197.         if ( *name == '\0' )
  1198.         strcpy( path, "RAM" ); /* Patch for Ram disk bug */
  1199.         else
  1200.         strcpy( path, name );
  1201.         lockb = ParentDir( locka );
  1202.         UnLock( locka );
  1203.         
  1204.         if ( lockb == NULL )
  1205.             strcat( path, ":");
  1206.         else if ( s1[0] != '\0' )
  1207.         strcat( path, "/");
  1208.         strcat( path, s1 );
  1209.         strcpy( s1, path );
  1210.         locka = lockb;
  1211.       }
  1212.  
  1213.     FreeMem( fib, (long)sizeof(struct FileInfoBlock) );
  1214. }
  1215.  
  1216. /*--------------------------------------------------------------*/
  1217. /*    getcwd: return the path name of the current directory    */
  1218. /*--------------------------------------------------------------*/
  1219.  
  1220. char *getcwd( path, size )
  1221. char *path;
  1222. int size;
  1223. {
  1224.     if ( path == (char *)NULL )
  1225.        {
  1226.          if ( (path = malloc(108)) == NULL)
  1227.         {
  1228. #ifdef TEST
  1229.            fprintf( stderr, "getcwd: malloc failed to get 108 bytes\n");
  1230. #endif
  1231.            return NULL;
  1232.         }
  1233.        }
  1234.     GetCurrentPath( path );
  1235.     return path;
  1236. }
  1237.  
  1238. #ifdef TEST
  1239. main()
  1240. {
  1241.  
  1242.     fprintf( stderr, "%s\n", getcwd( NULL, 0 ));
  1243. }
  1244.  
  1245. #endif
  1246.  
  1247.  
  1248.  
  1249. SHAR_EOF
  1250. fi # end of overwriting check
  1251. if test -f 'amiga/host.c'
  1252. then
  1253.        echo shar: will not over-write existing file "'amiga/host.c'"
  1254. else
  1255. cat << \SHAR_EOF > 'amiga/host.c'
  1256. /*        host.c
  1257.  
  1258.         Amiga host 
  1259.  
  1260. */
  1261.  
  1262. #include <stdio.h>
  1263. #include "host.h"
  1264.  
  1265. #include <ctype.h>
  1266. #include <setjmp.h>
  1267. #include <errno.h>
  1268.  
  1269. static char *curdir;
  1270. char * getcwd();
  1271. int chdir();
  1272. int    debuglevel;        /* debuglevelging level */
  1273.  
  1274. jmp_buf    dcpexit;
  1275.  
  1276. main( argc, argv )
  1277. int    argc;
  1278. char *argv[];
  1279. {
  1280.  
  1281.     /* Amiga specific prolog */
  1282.  
  1283.     loadenv();
  1284.     curdir = getcwd( NULL, 0 );
  1285.  
  1286. #ifdef CWDSPOOL
  1287.     chdir( spooldir );
  1288. #endif
  1289.  
  1290.     /* setup longjmp for error exit's */
  1291.     if ( setjmp( dcpexit ) == 0 ) {
  1292.  
  1293.         MAIN( argc, argv );
  1294.  
  1295.     }
  1296.  
  1297.     /* Amiga specific epilog */
  1298.  
  1299.     exitenv();
  1300.     chdir( curdir );
  1301.     exit( NULL );
  1302.  
  1303. }
  1304.  
  1305.  
  1306. /* canonical name conversio routines
  1307.  
  1308.     inportpath    canonical -> host
  1309.     exportpath    host -> canonical
  1310.  
  1311.     host        your local pathname format
  1312.     canonical    unix style
  1313. */
  1314.  
  1315. importpath( host, canon )
  1316. char * host;
  1317. char * canon;
  1318. {
  1319.         register char *s;
  1320.  
  1321.     strcpy( host, canon );
  1322.  
  1323.         if ( *host == '/' )
  1324.       *host = ':';
  1325. }
  1326.  
  1327. exportpath( canon, host )
  1328. char * host;
  1329. char * canon;
  1330. {
  1331.     strcpy( canon, host );
  1332.     if ( *canon == ':' )
  1333.        *canon = '/';
  1334. }
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340. SHAR_EOF
  1341. fi # end of overwriting check
  1342. if test -f 'amiga/host.h'
  1343. then
  1344.        echo shar: will not over-write existing file "'amiga/host.h'"
  1345. else
  1346. cat << \SHAR_EOF > 'amiga/host.h'
  1347.  /*        Amiga.h
  1348.  
  1349.         Amiga version
  1350.  
  1351. */
  1352.  
  1353. #include <time.h>
  1354. #include <errno.h>
  1355. #include <ctype.h>
  1356.  
  1357. #define AMIGA   1
  1358. #define SAME     0
  1359. #define    FALSE    0
  1360. #define    TRUE    1
  1361.  
  1362. #define    TFILENAME    "tmpfile.%.7d"
  1363. #define    SFILENAME    "SEQF"
  1364.  
  1365. #define SEPCHAR        '/'    /* path separater character        */
  1366. #define SIGFILE        ".signature"    /* file containing signature    */
  1367. #define COPYFILE    "mail.sent"    /* copy of sent mail    */
  1368.  
  1369. #define HOSTINIT        /* name of function used to initialize    */
  1370.  
  1371. #define FILEMODE(f)
  1372.  
  1373. #define    CALLFILE    "C.%s"
  1374. #define    XQTFILE        "X.%s"
  1375.  
  1376. #include "local/genv.h"
  1377.  
  1378. extern    char * fgets();
  1379. extern    char * index();
  1380.  
  1381. extern     int    debuglevel;                  /* debuglevelging level */
  1382.  
  1383.  
  1384.  
  1385.  
  1386. SHAR_EOF
  1387. fi # end of overwriting check
  1388. if test -f 'amiga/mkdir.c'
  1389. then
  1390.        echo shar: will not over-write existing file "'amiga/mkdir.c'"
  1391. else
  1392. cat << \SHAR_EOF > 'amiga/mkdir.c'
  1393. #include <libraries/dos.h>
  1394. #include <exec/memory.h>
  1395. #include <functions.h>
  1396.  
  1397. #ifdef TEST
  1398. #include <stdio.h>
  1399. #endif
  1400.  
  1401. #ifndef NULL
  1402. #define NULL 0L
  1403. #endif
  1404.  
  1405.  
  1406. /*--------------------------------------------------------------*/
  1407. /*    mkdir(name): make a directory with the given name.    */
  1408. /*--------------------------------------------------------------*/
  1409.  
  1410. int mkdir( name )
  1411. char *name;
  1412. {
  1413.     register struct Lock *lock;
  1414.  
  1415. #ifdef TEST
  1416.     fprintf( stderr, "mkdir: %s\n", name );
  1417. #endif
  1418.     lock = CreateDir( name );
  1419.     if ( !lock )
  1420.        return (int)IoErr();
  1421.     else 
  1422.        UnLock( lock );
  1423.     return 0;
  1424. }
  1425.  
  1426. #ifdef TEST
  1427. main()
  1428. {
  1429.     char command[100];
  1430.  
  1431.     gets( command );
  1432.     fprintf( stderr, "%d\n", mkdir( command ));
  1433. }
  1434.  
  1435. #endif
  1436.  
  1437.  
  1438.  
  1439. SHAR_EOF
  1440. fi # end of overwriting check
  1441. if test -f 'amiga/mlib.c'
  1442. then
  1443.        echo shar: will not over-write existing file "'amiga/mlib.c'"
  1444. else
  1445. cat << \SHAR_EOF > 'amiga/mlib.c'
  1446. /*        lib.c
  1447.  
  1448.  
  1449.         Amiga library
  1450.         
  1451.  
  1452.     Things to do in uu host
  1453.  
  1454.         serial I/O
  1455.         
  1456.         directory stuff
  1457.             opendir, readdir, closedir
  1458.  
  1459.         prolog and epilog
  1460.  
  1461.         system call
  1462.  
  1463. */
  1464.  
  1465. #include <stdio.h>
  1466. #include "host.h"
  1467. #include <sgtty.h>
  1468.  
  1469. int get_one()
  1470. {
  1471.     char c;
  1472.     
  1473.     struct sgttyb stty, sttyo;
  1474.     ioctl( 0, TIOCGETP, &stty );
  1475.     sttyo = stty;
  1476.     stty.sg_flags |= RAW;
  1477. /*    stty.sg_flags &= ~ ECHO; */
  1478.     ioctl( 0, TIOCSETP, &stty );
  1479.  
  1480.     c = fgetc( stdin );
  1481.     ioctl( 0, TIOCSETP, &sttyo );
  1482.  
  1483.     return( c );
  1484. }
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490. SHAR_EOF
  1491. fi # end of overwriting check
  1492. if test -f 'amiga/ndir.c'
  1493. then
  1494.        echo shar: will not over-write existing file "'amiga/ndir.c'"
  1495. else
  1496. cat << \SHAR_EOF > 'amiga/ndir.c'
  1497. #include "ndir.h"
  1498. #include <exec/memory.h>
  1499. #include <functions.h>
  1500.  
  1501. #ifdef TEST
  1502. #include <stdio.h>
  1503. #endif
  1504.  
  1505. /*
  1506.  * support for Berkeley directory reading routine on a V7 file system
  1507.  */
  1508.  
  1509. extern char *malloc();
  1510.  
  1511. /*
  1512.  * open a directory.
  1513.  */
  1514.  
  1515. DIR *
  1516. opendir(name)
  1517. char *name;
  1518. {
  1519.     register DIR *dirp;
  1520.     struct Lock  *lock;
  1521.  
  1522. #ifdef TEST
  1523.     fprintf( stderr, "opendir: Opening \"%s\"\n", name );
  1524. #endif
  1525.     if ( ( lock = Lock( name, ACCESS_READ )) == NULL )
  1526.       {
  1527. #ifdef TEST
  1528.         fprintf( stderr, "opendir: Can't open.\n" );
  1529. #endif
  1530.         return NULL;
  1531.       }
  1532.  
  1533.     if ( (dirp = (DIR *)malloc(sizeof(DIR))) == NULL )
  1534.       {
  1535. #ifdef TEST
  1536.         fprintf( stderr, "opendir: couldn't malloc %d\n",sizeof(DIR));
  1537. #endif
  1538.         UnLock( lock );
  1539.         return NULL;
  1540.       }
  1541.     if ( !Examine( lock, &dirp->fib) )
  1542.       {
  1543. #ifdef TEST
  1544.          fprintf( stderr, "opendir: Couldn't Examine directory\n" );
  1545. #endif
  1546.          free( dirp );
  1547.          UnLock( lock );
  1548.       }
  1549.  
  1550.     dirp->lock = lock;
  1551. #ifdef TEST
  1552.     fprintf( stderr, "opendir: Sucessful\n" );
  1553. #endif
  1554.  
  1555.     return dirp;
  1556. }
  1557.  
  1558.  
  1559. /*
  1560.  * get next entry in a directory.
  1561.  */
  1562. struct direct *
  1563. readdir(dirp)
  1564. register DIR *dirp;
  1565. {
  1566.     static struct direct dir;
  1567.  
  1568.     while ( ExNext( dirp->lock, &dirp->fib ) )
  1569.        {
  1570.         if ( dirp->fib.fib_DirEntryType <= 0 )
  1571.           {
  1572.             dir.d_ino = 0;
  1573.             strcpy( dir.d_name, dirp->fib.fib_FileName );
  1574. #ifdef TEST
  1575.             fprintf( stderr, "readdir: OK \"%s\"\n",  dir.d_name);
  1576. #endif
  1577.             dir.d_namlen = strlen(dir.d_name);
  1578.             dir.d_reclen = DIRSIZ(&dir);
  1579.             return (&dir);
  1580.           }
  1581.         }
  1582.  
  1583. #ifdef TEST
  1584.     fprintf( stderr, "readdir: No More Entries.\n" );
  1585. #endif
  1586.     strcpy( dir.d_name, "" );
  1587.     return NULL;
  1588.  
  1589. }
  1590.  
  1591. /*
  1592.  * close a directory.
  1593.  */
  1594. void
  1595. closedir(dirp)
  1596. register DIR *dirp;
  1597. {
  1598.  
  1599.     UnLock( dirp->lock );
  1600.     free((char *)dirp);
  1601. }
  1602.  
  1603.  
  1604. #ifdef TEST
  1605. #include <errno.h>
  1606.  
  1607. main()
  1608. {
  1609.     char command[100];
  1610.  
  1611.     struct DIR *dirp;
  1612.     struct direct *dp;
  1613.     
  1614.     while(gets(command) != NULL) {
  1615.  
  1616.         fprintf( stderr, "test: %s\n", command );
  1617.  
  1618.         if ((dirp = opendir( command )) == NULL ) {
  1619.             fprintf( stderr, "couldn't open dir %s\n", command );
  1620.         }
  1621.         else
  1622.            {
  1623.             while ((dp = readdir(dirp)) != NULL) 
  1624.                 fprintf( stderr, "%s", dp->d_name );
  1625.         
  1626.             closedir( dirp );
  1627.            }    
  1628.     }
  1629. }
  1630. #endif
  1631.  
  1632.  
  1633. SHAR_EOF
  1634. fi # end of overwriting check
  1635. if test -f 'amiga/ndir.h'
  1636. then
  1637.        echo shar: will not over-write existing file "'amiga/ndir.h'"
  1638. else
  1639. cat << \SHAR_EOF > 'amiga/ndir.h'
  1640. /* @(#)ndir.h    1.4    4/16/85 */
  1641. #include <libraries/dos.h>
  1642. #ifndef DEV_BSIZE
  1643. #define    DEV_BSIZE    512
  1644. #endif
  1645. #define DIRBLKSIZ    DEV_BSIZE
  1646. #define    MAXNAMLEN    255
  1647.  
  1648. struct    direct {
  1649.     long    d_ino;            /* inode number of entry */
  1650.     short    d_reclen;        /* length of this record */ 
  1651.     short    d_namlen;        /* length of string in d_name */
  1652.     char    d_name[MAXNAMLEN + 1];    /* name must be no longer than this */
  1653. };
  1654.  
  1655. /*
  1656.  * The DIRSIZ macro gives the minimum record length which will hold
  1657.  * the directory entry.  This requires the amount of space in struct direct
  1658.  * without the d_name field, plus enough space for the name with a terminating
  1659.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  1660.  */
  1661.  
  1662. #ifdef DIRSIZ
  1663. #undef DIRSIZ
  1664. #endif /* DIRSIZ */
  1665. #define DIRSIZ(dp) \
  1666.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  1667.  
  1668. /*
  1669.  * Definitions for library routines operating on directories.
  1670.  */
  1671. /*
  1672. typedef struct _dirdesc {
  1673.     int    dd_fd;
  1674.     long    dd_loc;
  1675.     long    dd_size;
  1676.     char    dd_buf[DIRBLKSIZ];
  1677. } DIR;
  1678. */
  1679. typedef struct _dirdesc {
  1680.     struct Lock    *lock;
  1681.     struct FileInfoBlock fib;
  1682. } DIR;
  1683. #ifndef NULL
  1684. #define NULL 0L
  1685. #endif
  1686. extern    DIR *opendir();
  1687. extern    struct direct *readdir();
  1688. extern    void closedir();
  1689.  
  1690.  
  1691. SHAR_EOF
  1692. fi # end of overwriting check
  1693. if test -f 'amiga/SerialIO.c'
  1694. then
  1695.        echo shar: will not over-write existing file "'amiga/SerialIO.c'"
  1696. else
  1697. cat << \SHAR_EOF > 'amiga/SerialIO.c'
  1698. /*--------------------------------------------------------------*/
  1699. /*    SerialIO.c: Amiga Serial I/O Device Routines        */
  1700. /*      Created: June 1986 by J.A. Lydiatt            */
  1701. /*                                */
  1702. /*    Note:                            */
  1703. /*      A Task may only open the serial port once.        */
  1704. /*--------------------------------------------------------------*/
  1705.  
  1706. #include <exec/types.h>
  1707. #include <exec/memory.h>
  1708. #include <stdio.h>
  1709. #include <devices/serial.h>
  1710. #include <functions.h>
  1711.  
  1712. /* Allowable Mode Values */
  1713. #define MODEHALF    0
  1714. #define MODEFULL    1
  1715. #define MODEECHO    2
  1716.  
  1717. /* Default starting values */
  1718. #define STARTBAUD   1200  /* default baud rate */
  1719. #define STARTMODE   MODEFULL
  1720. #define SERFLAGS    (SERF_SHARED | SERF_XDISABLED)
  1721. #define CTLCHAR     0x11130501    
  1722.  
  1723. static int Mode = STARTMODE;
  1724. static int amClosing = FALSE;
  1725.  
  1726. /* declarations for the serial stuff */
  1727. static struct IOExtSer *Read_Request = NULL;
  1728. static UBYTE rs_in[2];
  1729. static struct IOExtSer *Write_Request = NULL;
  1730. static UBYTE rs_out[2];
  1731.  
  1732. /* stack to save Serial Port flags */
  1733. #define MAXSTACK 10
  1734. static int stackSize = 0;
  1735. static int   modeStack[ MAXSTACK ];
  1736. static UBYTE flagStack[ MAXSTACK ];
  1737.  
  1738.  
  1739. /*------------------------------------------------------------*/
  1740. /*  GetSerialSigBit: return Read_Request's Signal Bit          */
  1741. /*------------------------------------------------------------*/
  1742.  
  1743. int GetSerialSigBit()
  1744. {
  1745.    return Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit;
  1746. }
  1747.  
  1748. /*------------------------------------------------------------*/
  1749. /*  CheckSerIO : return TRUE if serial port has a character   */
  1750. /*------------------------------------------------------------*/
  1751.  
  1752. BOOL CheckSerIO()
  1753. {
  1754.    return (BOOL)( CheckIO( Read_Request ) != NULL);
  1755. }
  1756.  
  1757. /*------------------------------------------------------------*/
  1758. /*      FlushSerIO: Flush the receive buffer              */
  1759. /*------------------------------------------------------------*/
  1760.  
  1761. void FlushSerIO()
  1762. {
  1763.    register struct IOExtSer *r = Read_Request;
  1764.  
  1765.    AbortIO( r );                 /* abort it */
  1766.    AbortIO( Write_Request );
  1767.  
  1768.    r->IOSer.io_Command = CMD_FLUSH;
  1769.    DoIO( r );                       /* flush all IO requests */
  1770.    r->IOSer.io_Command = CMD_CLEAR;
  1771.    DoIO( r);                       /* flush receive buffer  */
  1772.  
  1773.    if ( !amClosing )
  1774.      {
  1775.         Read_Request->IOSer.io_Command = CMD_READ;
  1776.         BeginIO( r );           /* start receive request */
  1777.      }
  1778. }
  1779.  
  1780.  
  1781. /*------------------------------------------------------------*/
  1782. /*  PushSerState: save current io flags                       */
  1783. /*------------------------------------------------------------*/
  1784. void PushSerState()
  1785. {
  1786.    register struct IOExtSer *r = Read_Request; 
  1787.  
  1788.    if ( stackSize < MAXSTACK )
  1789.      {
  1790.         /* Save the current Mode */
  1791.         modeStack[ stackSize ] = Mode;
  1792.         
  1793.     /* Get the current flags */
  1794.     AbortIO( r );
  1795.     flagStack[ stackSize++ ] = r->io_SerFlags;
  1796.     BeginIO( r );
  1797.      }
  1798. }
  1799.  
  1800. /*------------------------------------------------------------*/
  1801. /*  PullSerState: restore last saved flag state              */
  1802. /*------------------------------------------------------------*/
  1803. void PullSerState()
  1804. {
  1805.    register struct IOExtSer *r = Read_Request; 
  1806.  
  1807.    if ( stackSize > 0 )
  1808.      {
  1809.     /* Reset the Mode */
  1810.     Mode = modeStack[ --stackSize ];
  1811.  
  1812.     /* Set the old flags */
  1813.     AbortIO( r );
  1814.     r->io_SerFlags = flagStack[ stackSize ];
  1815.     r->IOSer.io_Command = SDCMD_SETPARAMS;
  1816.     DoIO( r );
  1817.     r->IOSer.io_Command = CMD_READ;
  1818.     BeginIO( r );
  1819.      }
  1820. }
  1821. /*-------------------------------------------------------------*/
  1822. /*           CloseSerialIO: Close the serial port              */
  1823. /*-------------------------------------------------------------*/
  1824. void CloseSerialIO()
  1825. {
  1826.    register struct IOExtSer *r = Read_Request;
  1827.    register struct IOExtSer *w = Write_Request;
  1828.  
  1829.    if ( r != NULL )
  1830.      {
  1831.     amClosing = TRUE;
  1832.     CloseDevice( r );
  1833.     DeletePort( r->IOSer.io_Message.mn_ReplyPort );
  1834.     FreeMem( r, (long)sizeof( struct IOExtSer ) );
  1835.     Read_Request = NULL;
  1836.       }
  1837.  
  1838.     if ( w != NULL )
  1839.       {
  1840.     CloseDevice( w );
  1841.     DeletePort( w->IOSer.io_Message.mn_ReplyPort );
  1842.     FreeMem( w, (long)sizeof( struct IOExtSer ) );
  1843.     Write_Request = NULL;
  1844.       }
  1845. }
  1846. /*-------------------------------------------------------------*/
  1847. /* InitSerialIO: Open serial IO - return read Port           */
  1848. /*-------------------------------------------------------------*/    
  1849. struct IOExtSer *InitSerialIO()
  1850. {
  1851.    register struct IOExtSer *r, *w;
  1852.  
  1853.    if ( Read_Request != NULL )
  1854.       {
  1855.     fprintf( stderr, "Error: Serial Port already open for read.\n");
  1856.     return NULL;
  1857.       }
  1858.    r = (struct IOExtSer *) AllocMem( (long)sizeof(struct IOExtSer),
  1859.      (long)(MEMF_PUBLIC|MEMF_CLEAR));
  1860.    if (r == NULL)
  1861.     return NULL;
  1862.  
  1863.    Read_Request = r;
  1864.    r->io_SerFlags = SERFLAGS;
  1865.    r->io_CtlChar  = CTLCHAR;
  1866.    r->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",NULL);
  1867.    if(OpenDevice(SERIALNAME,NULL,r,NULL))
  1868.       {
  1869.      fprintf( stderr, "Can't open Read device\n");
  1870.     goto q4;
  1871.       }
  1872.  
  1873.    r->io_Baud = STARTBAUD;
  1874.    r->io_ReadLen = 8;
  1875.    r->io_WriteLen = 8;
  1876.    r->IOSer.io_Command = SDCMD_SETPARAMS;
  1877.    DoIO(r);
  1878.    r->IOSer.io_Command = CMD_READ;
  1879.    r->IOSer.io_Length = 1;
  1880.    r->IOSer.io_Data = (APTR)&rs_in[0];
  1881.  
  1882.  
  1883.    if ( Write_Request != NULL )
  1884.       {
  1885.     fprintf( stderr, "Error: Serial Port already open for writing.\n");
  1886.     goto q3;
  1887.       }
  1888.    w = (struct IOExtSer *)AllocMem( (long)sizeof( struct IOExtSer ),
  1889.       (long)MEMF_PUBLIC|MEMF_CLEAR);
  1890.    if (w == NULL) goto q3;
  1891.  
  1892.    Write_Request = w;
  1893.    w->io_SerFlags = SERFLAGS;
  1894.    w->io_CtlChar  = CTLCHAR;
  1895.    w->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",NULL);
  1896.    if(OpenDevice(SERIALNAME,NULL,w,NULL))
  1897.       {
  1898.     fprintf( stderr, "Can't open Write device\n");
  1899.     goto q1;
  1900.       }
  1901.    w->io_Baud = STARTBAUD;
  1902.    w->io_ReadLen = 8;
  1903.    w->io_WriteLen = 8;
  1904.    w->IOSer.io_Command = SDCMD_SETPARAMS;
  1905.    DoIO(w);
  1906.  
  1907.    w->IOSer.io_Command = CMD_WRITE;
  1908.    w->IOSer.io_Length = 1;
  1909.    w->IOSer.io_Data = (APTR)&rs_out[0];
  1910.  
  1911.    BeginIO( r );
  1912.    stackSize = 0;
  1913.  
  1914.    return r;
  1915.  
  1916. q1:   DeletePort( w->IOSer.io_Message.mn_ReplyPort );
  1917. q2:   FreeMem( w, (long)sizeof( *w) );
  1918. q3:   CloseDevice( r );
  1919. q4:   DeletePort( r->IOSer.io_Message.mn_ReplyPort );
  1920. q5:   FreeMem( r, (long)sizeof( *r) );
  1921.  
  1922.    return NULL;
  1923. }
  1924.  
  1925. /*----------------------------------------------------------*/
  1926. /*         SetXonMode: set Xon On or Off                    */
  1927. /*----------------------------------------------------------*/
  1928.  
  1929. void SetXonMode( status )
  1930. BOOL status;
  1931. {
  1932.  
  1933.    register UBYTE flags;
  1934.    register struct IOExtSer *r = Read_Request; 
  1935.  
  1936.    /* Get the current flags */
  1937.    AbortIO( r );
  1938.    flags = r->io_SerFlags;
  1939.  
  1940.    if ( status )
  1941.       flags &= ~(SERF_XDISABLED);
  1942.    else
  1943.       flags |= SERF_XDISABLED; 
  1944.    r->io_SerFlags = flags;
  1945.    r->IOSer.io_Command = SDCMD_SETPARAMS;
  1946.    DoIO( r );
  1947.    r->IOSer.io_Command = CMD_READ;
  1948.    BeginIO( r );
  1949. }
  1950.  
  1951. /*----------------------------------------------------------*/
  1952. /*         SetSerBaud: set Serial Baud Rate                 */
  1953. /*----------------------------------------------------------*/
  1954.  
  1955. void SetSerBaud( baud )
  1956. int baud;
  1957. {
  1958.    register struct IOExtSer *r = Read_Request; 
  1959.  
  1960.    /* Get the current flags */
  1961.    AbortIO( r );
  1962.    r->io_Baud = baud;
  1963.    r->IOSer.io_Command = SDCMD_SETPARAMS;
  1964.    DoIO( r );
  1965.    r->IOSer.io_Command = CMD_READ;
  1966.    BeginIO( r );
  1967. }
  1968.  
  1969. /*----------------------------------------------------------*/
  1970. /*         SetSerMode: set the Serial Mode            */
  1971. /*----------------------------------------------------------*/
  1972.  
  1973. void SetSerMode( mode )
  1974. int mode;
  1975. {
  1976.    Mode = mode;
  1977. }
  1978.  
  1979. /*----------------------------------------------------------*/
  1980. /*   SerIOWrite: Write a byte out the serial port (no echo) */
  1981. /*----------------------------------------------------------*/
  1982.  
  1983. void SerIOWrite( c )
  1984. register UBYTE c;
  1985. {
  1986.   *rs_out = c;
  1987.   DoIO( Write_Request );
  1988. }
  1989.  
  1990. /*----------------------------------------------------------*/
  1991. /* SerIORead: read a byte from the serial port (no echo)    */
  1992. /*----------------------------------------------------------*/
  1993.  
  1994. UBYTE SerIORead()
  1995. {
  1996.    register struct IOExtSer *r = Read_Request;
  1997.    register UBYTE c;
  1998.  
  1999.    WaitIO( r );
  2000.    c = *rs_in;
  2001.    BeginIO( r );
  2002.    return c;
  2003. }
  2004.  
  2005.  
  2006. SHAR_EOF
  2007. fi # end of overwriting check
  2008. if test -f 'amiga/sio.c'
  2009. then
  2010.        echo shar: will not over-write existing file "'amiga/sio.c'"
  2011. else
  2012. cat << \SHAR_EOF > 'amiga/sio.c'
  2013. /*------------------------------------------------------------------*/
  2014. /*    Sio.c:  Serial I/O for Amiga Version of PCMail            */
  2015. /*    Created: 27Jun87 by J.A. Lydiatt                */
  2016. /*                                    */
  2017. /* Exports the following routines required by PCMail:            */
  2018. /*  SIOInit():        Initialize Serial Port                */
  2019. /*  SIOClose():        Close and free Serial Port resources        */
  2020. /*  SIOSpeed():        Set bps                        */
  2021. /*  SIORead():        read characters from serial port        */
  2022. /*  SIOWrite():        write characters to serial port            */
  2023. /*  SIOInBuffer():    Set Buffer size for read & writes.        */
  2024. /*  SIOOutBuffer():    (Has no effect in Amiga Version)        */
  2025. /*------------------------------------------------------------------*/
  2026.  
  2027. #include <stdio.h>
  2028. #ifndef TRUE
  2029. #define TRUE -1
  2030. #define FALSE 0
  2031. #endif
  2032.  
  2033. /*--- Timer Function Declarations --- */
  2034.  
  2035. extern void CloseTimer();    /* Return Timer's resources to the System */
  2036. extern int  OpenTimer();     /* Returns True if Timer Device Opened OK */ 
  2037. extern void StartTimer();    /* (long)seconds, (long)microseconds      */
  2038. extern int  TimerExpired();     /* Returns True if Timer interval expired */
  2039.  
  2040. /*--- SerialIO Function Declarations --- */
  2041.  
  2042. extern struct EOExtSer *InitSerialIO(); /* problems? return NULL      */
  2043. extern void CloseSerialIO();        /* Return SerialIO resources      */
  2044. extern int  CheckSerIO();        /* TRUE if character available    */
  2045. extern char SerIORead();        /* Returns a Char from serial port*/
  2046. extern void SerIOWrite();         /* Writes one byte to serial port */ 
  2047. extern void SetSerBaud();        /* (int)baud - set baud rate      */
  2048.  
  2049. /*--------------------------------------------------------------*/
  2050. /*     getspeed/getbaud: check for valid baud parameters    */
  2051. /*--------------------------------------------------------------*/
  2052.  
  2053. static struct {
  2054.     unsigned baudr;
  2055.     int speedcode;
  2056.  
  2057. } speeds[] = {
  2058.     300,    300,
  2059.     1200,    1200,
  2060.     2400,    2400,
  2061.     4800,    4800,
  2062.     9600,    9600,
  2063.     19200, 19200,
  2064.     0,
  2065. };
  2066.  
  2067. static unsigned getspeed(code)
  2068. {
  2069.     register n;
  2070.  
  2071.     for (n=0; speeds[n].baudr; ++n)
  2072.         if (speeds[n].speedcode == code)
  2073.             return speeds[n].baudr;
  2074.     return 0;
  2075. }
  2076.  
  2077.  
  2078. static unsigned getbaud(code)
  2079. char *code;
  2080. {
  2081.     register n;
  2082.     register int Baudrate;
  2083.     
  2084.     Baudrate = atoi(code);
  2085.     
  2086.     for (n=0; speeds[n].baudr; ++n)
  2087.         if (speeds[n].baudr == Baudrate)
  2088.             return speeds[n].speedcode;
  2089.     return 0;
  2090. }
  2091.  
  2092. /*--------------------------------------------------------------*/
  2093. /*    SIOInit: initialize serial I/O                */
  2094. /*--------------------------------------------------------------*/
  2095.  
  2096.  
  2097. SIOInit ( whichport, speed )
  2098. char * whichport;
  2099. char * speed;
  2100. {
  2101.     unsigned int baud;
  2102.     extern void SetXonMode();
  2103.  
  2104.     /*  fprintf( stderr, "sioinit %s %s\n", whichport, speed ); /* */
  2105.  
  2106.     if ( InitSerialIO() == NULL ) {
  2107.         fprintf( stderr, "Can't open Serial Port\n" );
  2108.         return( -1 );
  2109.     }
  2110.  
  2111.      if ( baud = getbaud( speed ) )
  2112.     SetSerBaud( baud );
  2113.  
  2114.      if ( !OpenTimer() )
  2115.     {
  2116.        CloseSerialIO();
  2117.        fprintf( stderr, "Can't open the Timer Device\n" );
  2118.        return -1;
  2119.         }
  2120.  
  2121.      SetXonMode( (int)FALSE );
  2122.      return( 0 );
  2123. }
  2124.  
  2125. /*--------------------------------------------------------------*/
  2126. /*    SIOSpeed:  set the serial Baud rate             */
  2127. /*--------------------------------------------------------------*/
  2128.  
  2129. SIOSpeed( speed )
  2130. char *speed;
  2131. {
  2132.     unsigned int baud;
  2133.  
  2134.     if ( baud = getbaud( speed ) )
  2135.     SetSerBaud( baud );
  2136. }
  2137.  
  2138. /*--------------------------------------------------------------*/
  2139. /*    SIOInBuffer/ SIOOutBuffer:    Set Buffer Size.    */
  2140. /*--------------------------------------------------------------*/
  2141.  
  2142. SIOInBuffer ( buf, size )
  2143. char * buf;
  2144. int size;
  2145. {
  2146. }
  2147.  
  2148. SIOOutBuffer ( buf, size )
  2149. char * buf;
  2150. int size;
  2151. {
  2152. }
  2153.  
  2154. /*--------------------------------------------------------------*/
  2155. /*    SIOClose:    Close Serial port.            */
  2156. /*--------------------------------------------------------------*/
  2157.  
  2158. SIOClose ( dtr )
  2159. {
  2160.    CloseSerialIO();
  2161.    CloseTimer();
  2162. }
  2163.  
  2164. /*--------------------------------------------------------------*/
  2165. /*    SIOWrite: send count characters to serial port        */
  2166. /*--------------------------------------------------------------*/
  2167.  
  2168. SIOWrite ( buf, count )
  2169. register char * buf;
  2170. int count;
  2171. {
  2172.     register int nsent;
  2173.  
  2174.     nsent = count;
  2175.     while ( nsent-- )
  2176.        SerIOWrite( *buf++ );
  2177.  
  2178.     return count;
  2179. }
  2180.  
  2181. /*--------------------------------------------------------------*/
  2182. /*    SIORead: read mincount <= #characters <= maxcount    */
  2183. /*    return  # of characters read, or -1 if timed out after    */
  2184. /*    after tenths / 10 seconds.                */
  2185. /*--------------------------------------------------------------*/
  2186.  
  2187.  
  2188. int SIORead ( buf, mincount, maxcount, tenths )
  2189. register char *buf;
  2190. int    mincount;
  2191. int    maxcount;
  2192. int    tenths; /* timeout is in tenth's of seconds */
  2193. {
  2194.         /* A bit of a Kludge to get the project started */
  2195.  
  2196.     long seconds, microSeconds;
  2197.     unsigned long waitMask;
  2198.     int  timerON ;
  2199.     register int received;
  2200.  
  2201.     /* fprintf (stderr, "Read  m= %d T= %ld", maxcount, Ticks  );/**/
  2202.  
  2203.  
  2204.  
  2205.     if ( tenths == 0 )
  2206.        {
  2207.         if ( !CheckSerIO() )
  2208.            return -1;
  2209.         tenths = 10;
  2210.        }
  2211.         seconds = tenths / 10;
  2212.     microSeconds = ((long)(tenths) - seconds * 10L) * 100000L;
  2213.         
  2214.     received = 0;
  2215.     waitMask = (1L << GetSerialSigBit()) | (1L << GetTimerSigBit() ); 
  2216.     timerON = FALSE;
  2217.     do
  2218.       {
  2219.          if ( CheckSerIO() )
  2220.             {
  2221.                 *buf = SerIORead();
  2222.            ++buf;
  2223.            ++received;
  2224.            if ( mincount <= received && received <= maxcount )
  2225.               return received;
  2226.         }
  2227.          if ( !timerON )
  2228.         {
  2229.            StartTimer( seconds, microSeconds );
  2230.            timerON = TRUE;
  2231.         }
  2232.          Wait( waitMask );
  2233.  
  2234.       }    while ( !TimerExpired() );
  2235.  
  2236.     return -1;
  2237. }
  2238.  
  2239.  
  2240. SHAR_EOF
  2241. fi # end of overwriting check
  2242. if test -f 'amiga/sleep.c'
  2243. then
  2244.        echo shar: will not over-write existing file "'amiga/sleep.c'"
  2245. else
  2246. cat << \SHAR_EOF > 'amiga/sleep.c'
  2247. /*--------------------------------------------------------------*/
  2248. /* sleep.c:    Implement sleep( seconds ) on the Amiga.    */
  2249. /*--------------------------------------------------------------*/
  2250.  
  2251. void sleep( seconds )
  2252. unsigned int seconds;
  2253. {
  2254.      if ( seconds > 0 )
  2255.     Delay( (long)( seconds * 50L ));
  2256. }
  2257.  
  2258. SHAR_EOF
  2259. fi # end of overwriting check
  2260. if test -f 'amiga/Timer.c'
  2261. then
  2262.        echo shar: will not over-write existing file "'amiga/Timer.c'"
  2263. else
  2264. cat << \SHAR_EOF > 'amiga/Timer.c'
  2265. /*  
  2266.  *  Timer.c: Functions to invoke the Amiga timer:
  2267.  *  
  2268.  *  External Functions:
  2269.  *
  2270.  *  OpenTimer, CloseTimer, StartTimer, TimerExpired, GetTimerSigBit
  2271.  * 
  2272.  *  Maintenance Notes:
  2273.  *   05Jul86  - Created by Jeff Lydiatt, Vancouver, Canada.
  2274.  */
  2275.  
  2276. #include <exec/types.h>
  2277. #include <exec/nodes.h>
  2278. #include <exec/lists.h>
  2279. #include <exec/ports.h>
  2280. #include <exec/tasks.h>
  2281. #include <exec/io.h>
  2282. #include <devices/timer.h>
  2283. #include <functions.h>
  2284.  
  2285. static struct timerequest TimerIO;
  2286. static struct MsgPort    *TimerPort = NULL;
  2287. static BOOL timerON;
  2288. static BOOL timerExpired;
  2289.  
  2290. /*-------------------------------------------------------------*/
  2291. /*    OpenTimer: return TRUE if timer opened OK           */
  2292. /*-------------------------------------------------------------*/
  2293.  
  2294. BOOL OpenTimer()
  2295. {
  2296.    register struct timerequest *t = &TimerIO;
  2297.    register struct MsgPort *port;
  2298.  
  2299.    timerON = FALSE;
  2300.    timerExpired = TRUE;
  2301.    if ( TimerPort != NULL )
  2302.       return TRUE;
  2303.  
  2304.    if ( (port = CreatePort("Timer Port", 0L)) == NULL )
  2305.       return FALSE;
  2306.    else
  2307.       TimerPort = port;
  2308.  
  2309.    if (OpenDevice(TIMERNAME, UNIT_VBLANK, t, 0L) != 0)
  2310.      {
  2311.     DeletePort( port );
  2312.     TimerPort = NULL;
  2313.     return FALSE;
  2314.      }
  2315.  
  2316.    return TRUE;
  2317. }
  2318.  
  2319. /*-------------------------------------------------------------*/
  2320. /*    CloseTimer: All Done with the timer.               */
  2321. /*-------------------------------------------------------------*/
  2322.  
  2323. void CloseTimer()
  2324. {
  2325.    register struct timerequest *t = &TimerIO;
  2326.  
  2327.    if ( timerON )
  2328.       AbortIO( t );
  2329.  
  2330.    CloseDevice( t );
  2331.    DeletePort( TimerPort );
  2332.    TimerPort = NULL;
  2333. }
  2334.  
  2335. /*-------------------------------------------------------------*/
  2336. /*    GetTimerSigBit: return Timer signal bit               */
  2337. /*-------------------------------------------------------------*/
  2338.  
  2339. int GetTimerSigBit()
  2340. {
  2341.    return TimerPort->mp_SigBit;
  2342. }
  2343.  
  2344. /*-------------------------------------------------------------*/
  2345. /*    StartTimer: launch the timer.                   */
  2346. /*-------------------------------------------------------------*/
  2347.  
  2348. void StartTimer(seconds, micros)
  2349. ULONG seconds, micros;
  2350. {
  2351.    register struct timerequest *t = &TimerIO;
  2352.  
  2353.    if ( timerON )
  2354.      {
  2355.     AbortIO( t );
  2356.     (void) GetMsg( TimerPort );
  2357.     timerON = FALSE;
  2358.         timerExpired = TRUE;
  2359.      }
  2360.  
  2361.    t->tr_time.tv_secs = seconds;
  2362.    t->tr_time.tv_micro = micros;
  2363.    t->tr_node.io_Command = TR_ADDREQUEST;
  2364.    t->tr_node.io_Flags = IOF_QUICK;
  2365.    t->tr_node.io_Error = 0;
  2366.    t->tr_node.io_Message.mn_ReplyPort = TimerPort;
  2367.    SendIO( t );
  2368.    timerExpired = FALSE;
  2369.    timerON = TRUE;
  2370. }
  2371.  
  2372. /*-------------------------------------------------------------*/
  2373. /*    TimerExpired: returns TRUE if timer expired.           */
  2374. /*-------------------------------------------------------------*/
  2375.  
  2376. BOOL TimerExpired()
  2377. {
  2378.    if ( timerON && ( CheckIO( &TimerIO.tr_node ) == NULL) )
  2379.       return FALSE;
  2380.  
  2381.    (void)GetMsg( TimerPort );
  2382.    timerExpired = TRUE;
  2383.    timerON = FALSE;
  2384.  
  2385.    return timerExpired;
  2386. }
  2387.  
  2388.  
  2389. SHAR_EOF
  2390. fi # end of overwriting check
  2391. if test -f 'amiga/ulib.c'
  2392. then
  2393.        echo shar: will not over-write existing file "'amiga/ulib.c'"
  2394. else
  2395. cat << \SHAR_EOF > 'amiga/ulib.c'
  2396. /*        ulib.c
  2397.  
  2398.  
  2399.         Amiga library
  2400.         
  2401.  
  2402.     Things to do in uu host
  2403.  
  2404.         serial I/O
  2405.         
  2406.         directory stuff
  2407.             opendir, readdir, closedir
  2408.  
  2409.         prolog and epilog
  2410.  
  2411.         system call
  2412.  
  2413. */
  2414.  
  2415. #include <stdio.h>
  2416. #include "host.h"
  2417. #include <sgtty.h>
  2418.  
  2419. /**/
  2420. /*
  2421.  *
  2422.  *      login (for slave in PC mode)
  2423.  * Real dumb login handshake
  2424. */
  2425. login()
  2426. {
  2427.     char    logmsg[132];
  2428. #ifdef PC
  2429. lretry:
  2430.     msgtime = 9999;
  2431.     rmsg(logmsg, 0); /* wait for a <CR> or <NL> */
  2432.     msgtime = 2 * MSGTIME;
  2433.     wmsg("Username:", 0);
  2434.     rmsg(logmsg, 0);
  2435.     printmsg( 0, "Username = %s", logmsg );
  2436.     wmsg("Password:", 0);
  2437.     rmsg(logmsg, 0);
  2438.     printmsg( 14, "Password = %s", logmsg );
  2439.     if (strcmp(logmsg, "uucp") != 0) 
  2440.         goto lretry;
  2441. #endif
  2442.     return('I');
  2443. }
  2444.  
  2445.  
  2446. char inbuf[BUFSIZ];
  2447. char outbuf[BUFSIZ];
  2448.  
  2449. swrite(data, num)
  2450. int    num;
  2451. char    *data;
  2452. {
  2453.  
  2454.     int test;
  2455.     unsigned char * cp;
  2456.  
  2457.     if (debuglevel > 14)
  2458.         fputc( '{', stderr );
  2459.     if (debuglevel > 14) {
  2460.         test = num;
  2461.         cp = data;
  2462.         while (test--)
  2463.             fprintf( stderr, isprint(*cp)? "{%c}":"{%02x}", *cp++ );
  2464.     }
  2465.     test = SIOWrite( data, num );
  2466.     if (debuglevel > 14)
  2467.         fputc( '}', stderr );
  2468.     return( test );
  2469.  
  2470. }
  2471.  
  2472. /* non-blocking read essential to "g" protocol */
  2473. /* see "dcpgpkt.c" for description */
  2474. /* This all changes in a mtask systems. Requests for */
  2475. /* I/O should get qued and an event flag given. Then the */
  2476. /* requesting process (e.g.gmachine()) waits for the event */
  2477. /* flag to fire processing either a read or a write. */
  2478. /* Could be implemented on VAX/VMS or DG but not MS-DOS */
  2479. sread(buf, num, timeout)
  2480. char    *buf;
  2481. int    num, timeout;
  2482. {
  2483. /*
  2484.     return( SIORead( buf, num, num, timeout*10 ) );
  2485. */
  2486.     int count;
  2487.     int test;
  2488.     unsigned char * cp;
  2489.  
  2490.     if (debuglevel > 13)
  2491.         fputc( '[', stderr );
  2492.     printmsg( 15, "sread: num: %d  timeout: %d", num, timeout );
  2493.         
  2494.     count = SIORead( buf, num, num, timeout*10 );
  2495.     printmsg( 15, "sread: read: %d ", count );
  2496.  
  2497.     if (debuglevel > 13 && count > 0) {
  2498.         test = count;
  2499.         cp = buf;
  2500.         while (test--)
  2501.             fprintf( stderr, isprint(*cp)? "[%c]":"[%02x]", *cp++ );
  2502.     }
  2503.         
  2504.     if (debuglevel > 13)
  2505.         fputc( ']', stderr );
  2506.     return( count );    
  2507.     
  2508. }
  2509.  
  2510.  
  2511.  
  2512. openline(name, baud)
  2513. char    *name, *baud;
  2514. {
  2515.  
  2516.     printmsg( 3, "openline: name: \"%s\"  baud: \"%s\"", name, baud );
  2517.     if ( SIOInit( name, baud ) )
  2518.        return -1;
  2519.     SIOInBuffer( inbuf, BUFSIZ );
  2520.     SIOOutBuffer( outbuf, BUFSIZ );
  2521.     return( 0 );
  2522. }
  2523.  
  2524.  
  2525. closeline()
  2526. {
  2527.     SIOClose( 1 );
  2528. }
  2529.  
  2530.  
  2531. nodot(string)
  2532. {
  2533. }
  2534.  
  2535.  
  2536.  
  2537. notimp( argc, argv )
  2538. char *argv[];
  2539. {
  2540.     /*debuglevelMsg("\Pcheck argc (08) and argv (0a) ");*/
  2541.     fprintf( stderr, "shell: %s not implemented\n", *argv );
  2542. }
  2543.  
  2544. /*------------------------------------------------------------------*/
  2545. /*    RNews:    my private rnews!                    */
  2546. /*------------------------------------------------------------------*/
  2547. static void RNews( inname )
  2548. char *inname;
  2549. {
  2550.     extern    char *newsdir;
  2551.     register struct tm    *thetm;
  2552.     long    tloc;
  2553.     char    filename[132];
  2554.     char    format[128];
  2555.     FILE     *f, *fin;
  2556.     FILE    *FOPEN();
  2557.     char    buf[BUFSIZ];
  2558.     
  2559.     static int count = 0;
  2560.     int    len;
  2561.     
  2562.     /* inname is of form "D.jlamiBCnnnn".  Pick off the nnnn. */
  2563.     len = strlen( inname ) - 1;
  2564.     while ( len >= 0 )
  2565.       {
  2566.         if ( '0' <= inname[len] && inname[len] <= '9' )
  2567.            --len;
  2568.         else
  2569.            break;
  2570.        }
  2571.  
  2572.     sprintf( filename, "%s/%s", newsdir, &inname[len+1] );
  2573.     if ( (f = FOPEN( filename, "r" )) != NULL )
  2574.        {
  2575.         /* Already exists, so make a timestamped one. */
  2576.         fclose( f );    
  2577.         tloc = time( (long *)NULL );
  2578.         thetm = localtime( &tloc );
  2579.  
  2580.         sprintf( filename, "%s/%02d%02d%02d%02d%02d%02d.%03d",
  2581.             newsdir,
  2582.             thetm->tm_year % 100, thetm->tm_mon,
  2583.             thetm->tm_mday, thetm->tm_hour,
  2584.             thetm->tm_min,  thetm->tm_sec,  count
  2585.             );
  2586.         ++count;
  2587.        }
  2588.     
  2589.     if ( TRUE /*debuglevel > 5*/ )
  2590.         fprintf( stderr, "rnews: %s\n", filename );
  2591.     
  2592.     if ( (f = FOPEN( filename, "w" )) == (FILE *)NULL ) {
  2593.         fprintf( stderr, "rnews: can't open %s\n", filename );
  2594.         return;
  2595.     }
  2596.  
  2597.     if ( (fin = FOPEN( inname, "r" )) == NULL )
  2598.       {
  2599.         fprintf( stderr, "rnews: Couldn't open %s\n", inname );
  2600.         fclose( f );
  2601.         return;
  2602.       }
  2603.     
  2604.     while ( fgets( buf, BUFSIZ, fin ) != (char *)NULL ) 
  2605.         fputs( buf, f );
  2606.  
  2607.     fclose( f );
  2608.     fclose( fin );
  2609. }
  2610.  
  2611.  
  2612.  
  2613. /*         shell
  2614.  
  2615.  
  2616. */
  2617.  
  2618. char * getcwd();
  2619.  
  2620. shell( command, inname, outname, errname )
  2621. char * command;
  2622. char * inname;
  2623. char * outname;
  2624. {
  2625.  
  2626.     char    * argvec[50];
  2627.  
  2628.     int rmail();
  2629.     int rnews();
  2630.     
  2631.     int     argcp;
  2632.  
  2633.     char **argvp;
  2634.     char args;
  2635.     
  2636.  
  2637.     int    (*proto)();
  2638.     
  2639.     argcp = 0;
  2640.  
  2641.     argcp = getargs( command, argvec );
  2642.  
  2643.     argvp = argvec;
  2644.     args = argcp;
  2645.  
  2646.     if ( debuglevel > 5 ) {
  2647.         while ( args ) 
  2648.             fprintf( stderr, "arg: %d  %s\n", args--, *argvp++ );
  2649.         argvp = argvec;
  2650.         args = argcp;
  2651.     }
  2652.     /* */
  2653.     
  2654.     proto = notimp;
  2655.  
  2656.     if ( strcmp( *argvp, "rmail" ) == SAME )
  2657.         proto = rmail;
  2658.  
  2659.     else if ( strcmp( *argvp, "rnews" ) == SAME ) {
  2660.         /* proto = rnews; */
  2661.         RNews( inname );
  2662.         return; 
  2663.     }
  2664.         
  2665.     if ( *inname != '\0' ) {
  2666.         fprintf( stderr, "reopening stdin as %s\n", inname );
  2667.         fprintf( stderr, "curdir: %s\n", getcwd(NULL, 0)); /* */
  2668.         if ( freopen( inname, "r", stdin ) == NULL ) 
  2669.             fprintf( stderr, "Couldn't open %s, %d\n", inname, errno );
  2670.     }
  2671.     (proto)( argcp, argvp );
  2672.  
  2673.     freopen( "con:", "r", stdin );
  2674.  
  2675. }
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682. SHAR_EOF
  2683. fi # end of overwriting check
  2684. #    End of shell archive
  2685. exit 0
  2686.  
  2687. --
  2688. {ubc-vision,uunet}!van-bc!sl                Stuart.Lynne@van-bc.uucp
  2689.