home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / pcmail2 / part12 / main / cico.c next >
C/C++ Source or Header  |  1990-01-24  |  5KB  |  170 lines

  1. /*++
  2. /* NAME
  3. /*      cico 1
  4. /* SUMMARY
  5. /*      uucp file transfer
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      cico
  10. /* SYNOPSIS
  11. /*      cico -p password [-d debuglevel]
  12. /* DESCRIPTION
  13. /*      cico is a program that connects to a real unix host
  14. /*      for exchange of spool files. It is a simplified
  15. /*    version of the unix uucico (copy-in-copy-out) program.
  16. /*
  17. /*    Options:
  18. /* .TP
  19. /*    -p password
  20. /*    The password that cico will use when logging in on the
  21. /*    unix host.
  22. /* .TP
  23. /*    -d debuglevel
  24. /*      Set the debugging level. It makes both the local cico
  25. /*      and the remote uucico more verbose. Default debugging
  26. /*    level is 0.
  27. /* FILES
  28. /*      cico manipulates various files in the spool directory.
  29. /*    See path(5) for the implementation of the message data base.
  30. /*
  31. /*      LOGFILE         transaction logging
  32. /*    s00000        communications parameters
  33. /* SEE ALSO
  34. /*      comm(5)        communications parameters
  35. /*    status(5)    error returns
  36. /* DIAGNOSTICS
  37. /*      The program terminates with a non-zero exit status if there
  38. /*      were problems. The error status codes can be translated
  39. /*    to meaningful messages (see status(5)).
  40. /*      More technical messages are written to the logfile.
  41. /* BUGS
  42. /*    cico only supports the functions needed for exchange of
  43. /*    electronic mail. Every incoming data file is treated as
  44. /*    if it were a mail message for the user of the pc.
  45. /* AUTHOR(S)
  46. /*      W.Z. Venema
  47. /*      Eindhoven University of Technology
  48. /*      Department of Mathematics and Computer Science
  49. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  50. /* CREATION DATE
  51. /*      Sat Mar 28 19:58:06 GMT+1:00 1987
  52. /* LAST MODIFICATION
  53. /*    90/01/22 13:01:17
  54. /* VERSION/RELEASE
  55. /*    2.1
  56. /*--*/
  57.  
  58. #include <stdio.h>
  59. #include <setjmp.h>
  60.  
  61. #include "defs.h"
  62. #include "logs.h"
  63. #include "params.h"
  64. #include "comm.h"
  65. #include "status.h"
  66. #include "path.h"
  67.  
  68. public int *systrap;                            /* panic button */
  69. public int dflag = 0;                           /* debug flag */
  70. #ifdef    unix
  71.     public int Debug = 0;            /* UUCP compatibility */
  72. #endif
  73.  
  74. public char *progname = "cico";            /* for diagnostics etc. */
  75.  
  76. hidden void parse_args(),sanity();              /* forward declarations */
  77.  
  78. /* main program - parse command line options and pull the ropes */
  79.  
  80. main(argc,argv)
  81. int argc;
  82. char **argv;
  83. {
  84.     register int status;                        /* most recent error code */
  85.     jmp_buf mainbuf;                            /* catch-all */
  86.  
  87.     parse_args(argc,argv);                      /* process cmd arguments */
  88.  
  89.     sanity();                                   /* check systems parameters */
  90.  
  91.     if (setjmp(systrap = mainbuf))              /* safety net in case of */
  92.     exit(E_CONFUSED);                       /* too many long jumps */
  93.  
  94.     xopen();                                    /* init comm. line */
  95.     if ((status = connect()) == 0               /* login on remote system */
  96.     && (status = startproto()) == 0) {          /* start comm. protocol */
  97.     status = switcher(MASTER);              /* use the protocol */
  98.     endproto();                             /* terminate the protocol */
  99.     }                                           /* (ignore errors) */
  100.     disconnect();                               /* as it says */
  101.     xclose();                                   /* close comm. line */
  102.  
  103.     exit(status);
  104.     /* NOTREACHED */
  105. }
  106.  
  107. /* parse_args - take care of command-line arguments */
  108.  
  109. hidden void parse_args(argc,argv)
  110. int argc;
  111. char **argv;
  112. {
  113.     while (--argc && *++argv && **argv == '-') {
  114.     switch (*++*argv) {
  115.     case 'p':
  116.         if (--argc == 0)
  117.         usage("missing password argument");
  118.         password = *++argv;
  119.         break;
  120.     case 'd':
  121.         if (--argc == 0)
  122.         usage("missing debugging level argument");
  123.         sscanf(*++argv,"%d",&dflag);
  124. #ifdef    unix
  125.         Debug = 
  126. #endif
  127.         dflag = ((dflag < 0 ? 0 : dflag) > 10 ? 10 : dflag);
  128.         break;
  129.     default:
  130.         usage(strcons("invalid option: -%s",*argv));
  131.         break;
  132.     }
  133.     }
  134.     if (argc > 0)
  135.     usage(strcons("unexpected argument: %s",*argv));
  136. }
  137.  
  138. /* sanity - some preliminary work; mainly checks on sanity */
  139.  
  140. hidden void sanity()
  141. {
  142.     register int status;
  143.     register Info *ip;
  144.  
  145.     if (status = pathinit())                            /* check environment */
  146.     exit(status);                                   /* bad environment */
  147.  
  148.     if (status = open_log())                            /* check the logfile */
  149.     exit(status);                                   /* cannot write */
  150.  
  151.     for (ip = comm = getparams(); ip->ident; ip++) {    /* check param. file */
  152.     if (ip->strval == 0 || ip->strval[0] == '\0')
  153.         exit(E_BADSETUP);                           /* incomplete setup */
  154.     debug(6)("%s %s\n",ip->ident,ip->strval ? ip->strval : "");
  155.     }
  156.     if (password == 0 || *password == 0) 
  157.     usage("no password specified");                 /* no password */
  158.  
  159.     strcpy(rmthost,comm[P_HOST].strval);        /* remote host name */
  160. }
  161.  
  162. /* usage - print error message and usage string */
  163.  
  164. usage(str)
  165. char *str;
  166. {
  167.     fprintf(stderr,"%s\nusage: cico -p password [-d debuglevel]\n",str);
  168.     exit(2);
  169. }
  170.