home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / uniflex / ufk.h < prev    next >
C/C++ Source or Header  |  1993-08-22  |  13KB  |  265 lines

  1. /*
  2.  * KERMIT09 - UniFLEX version header file
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7.  
  8. #define VERSION      "V 1.5"
  9.  
  10. /* Also modify VERSION in ufkerm.c !! */
  11.  
  12. #define IDENT        "UniFLEX KERMIT 6809 version "
  13. #define DEFPROMPT    "UF-Kermit>"
  14. #define INITFILE     "kermit.ini"
  15. #define INITFILE1    "/usr/kermit.ini"
  16. #define HELPDIR      "/gen/kermit"
  17. #define PRIVTASK     "/bin/kermit_support"
  18.  
  19. /* Version of protocol between main task and support task */
  20.  
  21. #define PROTOCOL_VERSION  2
  22.  
  23. /* Symbol Definitions */
  24.  
  25. #define SOH          1                    /* Start of header */
  26. #define BELL         7                    /* ASCII Bell */
  27. #define BS           8                    /* ASCII Backspace */
  28. #define TAB          9                    /* ASCII Tab */
  29. #define LF           10                   /* ASCII Linefeed */
  30. #define CR           13                   /* ASCII Carriage Return */
  31. #define ESC          27                   /* ASCII Escape */
  32. #define SP           32                   /* ASCII space */
  33. #define DEL          127                  /* Delete (rubout) */
  34. #define XON          17                   /* Start output */
  35. #define XOFF         19                   /* Stop output */
  36. #define ESCCHR       '^'                  /* Default escape char for CONNECT */
  37. #define PANIC        '\\' - 64            /* Panic abort exit */
  38. #define TOGDBG       'D' - 64             /* Toggle debug on/off */
  39. #define ABORTX       'X' - 64             /* Ctrl-X to abort transfer */
  40. #define ABORTZ       'Z' - 64             /* Ctrl-Z to abort transfer */
  41. #define COMMENT      '!'                  /* Command line comment character */
  42.  
  43. #define TRUE         1
  44. #define FALSE        0
  45. #define ERROR        (-1)
  46. #define TYPERROR     (-2)
  47. #define IN           0
  48. #define OUT          1
  49. #define SEND         0
  50. #define RECEIVE      1
  51. #define READ         0
  52. #define WRITE        1
  53. #define BIG_SIZE     2048 + 8             /* Maximum = (95*94+94+8) */
  54. #define SMALL_SIZE   (94+5)
  55.  
  56. #define TABSIZE      8                    /* Tabstop every eight places */
  57.  
  58. #define I_MYPACKSTART      SOH            /* Start of packet character */
  59. #define I_MAXPACKSIZ       94             /* Maximum packet size */
  60. #define I_MYPACKSIZE       80             /* Default value if no 'S' packet */
  61. #define I_MAXTRY           10             /* Times to retry a packet */
  62. #define I_MYQUOTE          '#'            /* Quote character I will use */
  63. #define I_MYPAD            0              /* Number of padding char's I need */
  64. #define I_MYPCHAR          0              /* Padding character I need (NULL) */
  65. #define I_MYEOL            '\r'           /* End-Of-Line character I need */
  66. #define I_MYTIME           5              /* My timeout in seconds */
  67. #define I_MYRPTQUOTE       '~'            /* Repeat quote character */
  68. #define I_MYEIGHTQUOTE     '&'            /* Eight_bit quote character */
  69. #define I_BLOCKCHECKTYPE   1              /* Initial checksum type */
  70. #define I_SEND_DELAY       5              /* Delay time before sending */
  71. #define I_DEFLONGSIZE      500            /* Default size for long packets */
  72.  
  73. #define TIMEOUT      1            /* Internal codes */
  74. #define REMOTE      -1
  75.  
  76. /*
  77.   UniFLEX kermit error definitions
  78. */
  79.  
  80. #define ER_POPNERR      0       /* Communication port open error */
  81. #define ER_NOPARAM      1       /* No parameter specified */
  82. #define ER_NOMEM        2       /* No memory available */
  83. #define ER_NOLINE       3       /* No line to connect to */
  84. #define ER_LOGWRTER     4       /* Log file write error */
  85. #define ER_DIROPN       5       /* Directory open error */
  86. #define ER_NOHELP       6       /* No help available */
  87. #define ER_NOTOPIC      7       /* No such topic */
  88. #define ER_AMBIG        8       /* Ambiguous command */
  89. #define ER_UNKNOWN      9       /* Unknown command */
  90. #define ER_ONENAME      10      /* Only one name allowed */
  91. #define ER_FSPCREQ      11      /* Filespec required */
  92. #define ER_NOFILSEL     12      /* No files selected */
  93. #define ER_ILLREMOT     13      /* Not allowed if remote */
  94. #define ER_AMBIGSET     14      /* Ambiguous 'set' command */
  95. #define ER_UNKNWSET     15      /* Unknown 'set' command */
  96. #define ER_FILEOPEN     16      /* File already open */
  97. #define ER_OPENERR      17      /* File open error */
  98. #define ER_INVDEV       18      /* Invalid device or no permission */
  99. #define ER_NOREMBD      19      /* Can't set baudrate for remote line */
  100. #define ER_NOBAUD       20      /* Unable to set baudrate */
  101. #define ER_INVBAUD      21      /* Invalid baudrate specified */
  102. #define ER_ILLVALUE     22      /* Illegal value specified */
  103. #define ER_CHRINUSE     23      /* Character already in use */
  104. #define ER_INVLENG      24      /* Invalid length specified */
  105. #define ER_VALOUTRN     25      /* Value out of range */
  106. #define ER_EOLDIF       26      /* Eol must be different of start of packet */
  107. #define ER_STRTDIF      27      /* Start of packet must be different of eol */
  108. #define ER_INVCHK       28      /* Invalid block check type */
  109. #define ER_INVCHAR      29      /* Invalid character */
  110. #define ER_AMBIGSHW     30      /* Ambiguous 'show' command */
  111. #define ER_UNKNWSHW     31      /* Unknown 'show' command */
  112. #define ER_GETPWDID     32      /* Get password id error */
  113. #define ER_INVDIR       33      /* Invalid directory specified */
  114. #define ER_SYNERR       34      /* Syntax error */
  115. #define ER_PRIVSERVER   35      /* Privileged support task error */
  116. #define ER_PRIVPROT     36      /* Invalid support task procotol */
  117. #define ER_PERMS        37      /* Error setting file permissions */
  118. #define ER_SPAWN        38      /* Can't spawn 'shell' */
  119.  
  120. /* Internal error packet error definitions */
  121.  
  122. #define PER_ABORTED     0       /* Aborted command */
  123. #define PER_UNIMPL      1       /* Unimplemented server function */
  124. #define PER_PACKET      2       /* Packet error */
  125. #define PER_DEVFULL     3       /* Device full */
  126. #define PER_WRITE       4       /* File write error */
  127. #define PER_CREATE      5       /* File create error */
  128. #define PER_OPEN        6       /* File open error */
  129.  
  130. #define ERR_PARAM       4       /* Errors > ERR_PARAM have parameters */
  131.  
  132. /* Macro Definitions */
  133.  
  134. /*
  135.  * tochar: converts a control character to a printable one by adding a space.
  136.  *
  137.  * unchar: undoes tochar.
  138.  *
  139.  * ctl:    converts between control characters and printable characters by
  140.  *         toggling the control bit (ie. ^A becomes A and A becomes ^A).
  141.  */
  142. #define tochar(ch)   ((ch) + ' ')
  143. #define unchar(ch)   ((ch) - ' ')
  144. #define ctl(ch)      ((ch) ^ 64 )
  145.  
  146. /*
  147.   pread: read from pipe
  148.   pwrite: write to pipe
  149. */
  150. #define pread(adr,cnt)  read(pd1[READ],(adr),(cnt))
  151. #define pwrite(adr,cnt) write(pd2[WRITE],(adr),(cnt))
  152.  
  153. /* Global Variables */
  154.  
  155. /* Structure used by command parser */
  156.  
  157. typedef struct table_point
  158. {
  159.    char *string;                          /* Command name */
  160.    int funcadr;                           /* Function address */
  161. } TABLE;
  162.  
  163. int   send_delay,             /* Start sending delay time */
  164.       ttyfd,                  /* I/O port address */
  165.       speed,                  /* line speed */
  166.       tabsleft,               /* Tab counter */
  167.       size,                   /* Size of present data */
  168.       spsiz,                  /* Maximum send packet size */
  169.       maxpacksiz,             /* Maximum packet size */
  170.       nak_sent,               /* nak's sent */
  171.       pack_sent,              /* packets sent */
  172.       nak_rec,                /* nak's received */
  173.       pack_rec,               /* packets received */
  174.       data_rate,              /* effective data rate */
  175.       t_nak_sent,             /* total naks sent */
  176.       t_pack_sent,            /* total packets sent */
  177.       t_nak_rec,              /* total nak's received */
  178.       t_pack_rec,             /* total packets received */
  179.       t_data_rate,            /* total effective data rate */
  180.       pd1[2],                 /* pipe decriptors for support task */
  181.       pd2[2];
  182.  
  183. long int chr_sent,            /* characters sent */
  184.          dchr_sent,           /* data characters sent */
  185.          chr_rec,             /* characters received */
  186.          dchr_rec,            /* data characters received */
  187.          t_chr_sent,          /* total characters sent */
  188.          t_dchr_sent,         /* total data characters sent */
  189.          t_chr_rec,           /* total characters received */
  190.          t_dchr_rec,          /* total data characters received */
  191.          transmit_chr_count,  /* Character count for data size calculation */
  192.          file_size;           /* Size of current file in bytes */
  193.  
  194. char  state,                  /* Present state of the automaton */
  195.       padchar,                /* Padding character to send */
  196.       eol,                    /* End-Of-Line character to send */
  197.       escchr,                 /* Connect command escape character */
  198.       quote,                  /* Quote character in incoming data */
  199.       block_check_type,       /* Checksum type */
  200.       eight_quote,            /* eight_bit quote character */
  201.       repeat_quote,           /* repeat quote character */
  202.       timint,                 /* Timeout for foreign host on sends */
  203.       pad,                    /* How much padding to send */
  204.       allowattr,              /* allow or disallow attribute packets */
  205.       attribute,              /* TRUE if attribute packets are used */
  206.       n,                      /* Packet number */
  207.       numtry,                 /* Times this packet retried */
  208.       oldtry,                 /* Times previous packet retried */
  209.       image,                  /* TRUE means 8-bit mode selected with 'set' */
  210.       binfil,                 /* 8-bit mode at runtime with attr packet */
  211.       warning,                /* File conflict warning flag */
  212.       mapping,                /* Filename case mapping flag */
  213.       auto_recover,           /* Auto recovery with extended packet length */
  214.       debug,                  /* indicates debugging output done (0=none) */
  215.       fulldup,                /* TRUE means full duples in connect */
  216.       logfileopen,            /* TRUE means log file open */
  217.       logging,                /* TRUE means logging active */
  218.       dstop,                  /* stop character for remote */
  219.       dstart,                 /* start character for remote */
  220.       filecount,              /* Number of files left to send */
  221.       filenum,                /* current filenumber */
  222.       config,                 /* initialize value */
  223.       numprm,                 /* number of command parameters */
  224.       aborted,                /* TRUE means we're aborted */
  225.       port_open,              /* TRUE means port is open */
  226.       save_file,              /* keep/discard file on abort */
  227.       sflg,                   /* send active flag */
  228.       rflg,                   /* receive active flag */
  229.       cflg,                   /* connect active flag */
  230.       *filnam,                /* Current file name */
  231.       call_baud,              /* Flag if baudrate should be set */
  232.       prvsetdone,             /* privileged task setup done */
  233.       maskflag,               /* mask for RTS and DCD mask option */
  234.       screen,                 /* screen setup can be used */
  235.       nooutput,               /* no output if called with options */
  236.       remote,                 /* Remote line in use */
  237.       bg,                     /* Running in the background */
  238.       **params,               /* parameter list */
  239.       prompt[21],             /* prompt string */
  240.       logfile[50],            /* filename for logfile */
  241.       rec_filnam[128],        /* forced receive filename */
  242.       *recpkt,                /* Receive packet buffer pointer */
  243.       *sndpkt,                /* Transmit packet buffer pointer */
  244.       dbgfname[50],           /* Filename for debug file */
  245.       tty_descr[20],          /* Terminal line in use */
  246.       mypackstart,            /* Start of packet character */
  247.       maxtry,                 /* Times to retry a packet */
  248.       myquote,                /* Quote character I will use */
  249.       mypad,                  /* Number of padding characters I will need */
  250.       mypchar,                /* Padding character I need (NULL) */
  251.       myeol,                  /* End-Of-Line character I need */
  252.       mytime,                 /* Seconds after which I should be timed out */
  253.       myrptquote,             /* Repeat quote character */
  254.       myeightquote,           /* Eight_bit quote character */
  255.       myblock_check_type;     /* My checksum type */
  256.  
  257. FILE  *fp,                    /* File pointer for current disk file */
  258.       *lfp,                   /* File pointer for log file */
  259.       *dbgfil;                /* File pointer for debug file output */
  260.  
  261. long  time(),
  262.       get_free(),
  263.       start_time,
  264.       end_time;
  265.