File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lrzsz / src / zglobal.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Thu Oct 24 15:49:50 2019 UTC (4 years, 11 months ago) by misho
Branches: lrzsz, MAIN
CVS tags: v0_12_20p5, HEAD
lrzsz ver 0.12.20

    1: #ifndef ZMODEM_GLOBAL_H
    2: #define ZMODEM_GLOBAL_H
    3: 
    4: /* zglobal.h - prototypes etcetera for lrzsz
    5: 
    6:   Copyright (C) until 1998 Chuck Forsberg (OMEN Technology Inc)
    7:   Copyright (C) 1994 Matt Porter
    8:   Copyright (C) 1996, 1997 Uwe Ohse
    9: 
   10:   This program is free software; you can redistribute it and/or modify
   11:   it under the terms of the GNU General Public License as published by
   12:   the Free Software Foundation; either version 2, or (at your option)
   13:   any later version.
   14: 
   15:   This program is distributed in the hope that it will be useful,
   16:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   17:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18:   GNU General Public License for more details.
   19: 
   20:   You should have received a copy of the GNU General Public License
   21:   along with this program; if not, write to the Free Software
   22:   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   23:   02111-1307, USA.
   24: */
   25: 
   26: #include "config.h"
   27: #include <sys/types.h>
   28: 
   29: #ifdef __GNUC__
   30: # define alloca __builtin_alloca
   31: # define HAVE_ALLOCA 1
   32: #else
   33: # if defined HAVE_ALLOCA_H || defined _LIBC
   34: #  include <alloca.h>
   35: # else
   36: #  ifdef _AIX
   37: #pragma alloca
   38: #  else
   39: #   ifndef alloca
   40: #    ifndef __GLIBC__
   41: char *alloca ();
   42: #    endif
   43: #   endif
   44: #  endif
   45: # endif
   46: #endif
   47: 
   48: #ifndef __P
   49: #if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
   50: #define __P(args) args
   51: #else
   52: #define __P(args) ()
   53: #endif  /* GCC.  */
   54: #endif  /* Not __P.  */
   55: 
   56: #ifdef __STDC__
   57: #include <stdarg.h>
   58: #else
   59: #include <varargs.h>
   60: #endif
   61: 
   62: #ifdef TIME_WITH_SYS_TIME
   63: #  include <sys/time.h>
   64: #  include <time.h>
   65: #  define INCLUDED_SYS_TIME
   66: #else
   67: #  ifdef HAVE_SYS_TIME_H
   68: #    include <sys/time.h>
   69: #    define INCLUDED_SYS_TIME
   70: #  else
   71: #    include <time.h>
   72: #  endif
   73: #endif
   74: #ifdef SYS_TIME_WITHOUT_SYS_SELECT
   75: # ifdef INCLUDED_SYS_TIME
   76: #  undef HAVE_SYS_SELECT_H
   77: # endif
   78: #endif
   79: 
   80: 
   81: #ifdef HAVE_SYS_SELECT_H
   82: #  include <sys/select.h>
   83: #endif
   84: #ifdef __BEOS__
   85:  /* BeOS 4.0: sys/select.h is almost completely #ifdefd out */
   86: #define  HAVE_SOCKET_H
   87: #ifdef HAVE_SOCKET_H
   88: #include <socket.h>
   89: #endif
   90: #endif
   91: 
   92: #if STDC_HEADERS
   93: # include <string.h>
   94: #else
   95: # ifdef HAVE_STRINGS_H
   96: #   include <strings.h>
   97: # endif
   98: # ifndef HAVE_STRCHR
   99: #  define strchr index
  100: #  define strrchr rindex
  101: # endif
  102: char *strchr (), *strrchr ();
  103: # ifndef HAVE_MEMCPY
  104: #  define memcpy(d, s, n) bcopy ((s), (d), (n))
  105: #  define memmove(d, s, n) bcopy ((s), (d), (n))
  106: # endif
  107: #endif
  108: 
  109: #include <sys/stat.h>
  110: 
  111: /* we need to decide whether readcheck is possible */
  112: #ifdef HAVE_FCNTL_H
  113: #  include <fcntl.h>
  114: #endif
  115: #ifdef HAVE_SYS_IOCTL_H
  116: #  include <sys/ioctl.h>
  117: #endif
  118: #ifdef HAVE_RDCHK
  119: #  define READCHECK
  120: #else
  121: #  ifdef FIONREAD
  122: #    define READCHECK_FIONREAD
  123: #    define READCHECK
  124: #  else
  125: #    ifdef F_GETFL
  126: #      define READCHECK
  127: #      define READCHECK_READS
  128: #      define READCHECK_GETFL
  129: #    endif
  130: #  endif
  131: #endif
  132: 
  133: /* used to use #elif, but native braindead hpux 9.00 c compiler didn't 
  134:  * understand it */
  135: #ifdef HAVE_TERMIOS_H
  136: /* get rid of warnings on SCO ODT 3.2 */
  137: struct termios;
  138: # include <termios.h>
  139: # define USE_TERMIOS
  140: #else
  141: # if defined(HAVE_SYS_TERMIOS_H)
  142: #  include <sys/termios.h>
  143: #  define USE_TERMIOS
  144: # else
  145: #  if defined(HAVE_TERMIO_H)
  146: #   include <termio.h>
  147: #   define USE_TERMIO
  148: #  else
  149: #   if defined(HAVE_SYS_TERMIO_H)
  150: #    include <sys/termio.h>
  151: #    define USE_TERMIO
  152: #   else
  153: #    if defined(HAVE_SGTTY_H)
  154: #     include <sgtty.h>
  155: #     define USE_SGTTY
  156: #     ifdef LLITOUT
  157:        extern long Locmode;		/* Saved "local mode" for 4.x BSD "new driver" */
  158:        extern long Locbit;	/* Bit SUPPOSED to disable output translations */
  159: #     endif
  160: #    else
  161: #     error neither termio.h nor sgtty.h found. Cannot continue.
  162: #    endif
  163: #   endif
  164: #  endif
  165: # endif
  166: #endif
  167: 
  168: #ifdef USE_SGTTY
  169: #  ifdef TIOCSBRK
  170: #    define CANBREAK
  171: #  endif
  172: #endif
  173: #ifdef USE_TERMIO
  174: #  define CANBREAK
  175: #endif
  176: 
  177: 
  178: 
  179: /* Take care of NLS matters.  */
  180: #if HAVE_LOCALE_H
  181: # include <locale.h>
  182: #endif
  183: #if !HAVE_SETLOCALE
  184: # define setlocale(Category, Locale) /* empty */
  185: #endif
  186: 
  187: #if ENABLE_NLS
  188: # include <libintl.h>
  189: # define _(Text) gettext (Text)
  190: #else
  191: # define bindtextdomain(Domain, Directory) /* empty */
  192: # define textdomain(Domain) /* empty */
  193: # define _(Text) Text
  194: #endif
  195: 
  196: #ifndef ENABLE_SYSLOG
  197: #  undef HAVE_SYSLOG
  198: #else
  199: #  ifdef HAVE_SYSLOG_H
  200: #    include <syslog.h>
  201: #  else
  202: #    if defined(HAVE_SYS_SYSLOG_H)
  203: #      include <sys/syslog.h>
  204: #    else
  205: #      undef HAVE_SYSLOG
  206: #    endif
  207: #  endif
  208: #endif
  209: #ifndef ENABLE_SYSLOG
  210: #  define openlog(name,pid,facility) /* void it */
  211: #  define setlogmask(x) /* void it */
  212: #else
  213: extern int enable_syslog;
  214: #endif
  215: 
  216: #if defined HAVE_UNISTD_H
  217: # include <unistd.h>
  218: #endif
  219: /* The following is from pathmax.h.  */
  220: /* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
  221:    PATH_MAX but might cause redefinition warnings when sys/param.h is
  222:    later included (as on MORE/BSD 4.3).  */
  223: #if defined(_POSIX_VERSION) || (defined(HAVE_LIMITS_H) && !defined(__GNUC__))
  224: # include <limits.h>
  225: #endif
  226: 
  227: #ifndef _POSIX_PATH_MAX
  228: # define _POSIX_PATH_MAX 255
  229: #endif
  230: 
  231: #if !defined(PATH_MAX) && defined(_PC_PATH_MAX)
  232: # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX))
  233: #endif
  234: 
  235: /* Don't include sys/param.h if it already has been.  */
  236: #if defined(HAVE_SYS_PARAM_H) && !defined(PATH_MAX) && !defined(MAXPATHLEN)
  237: # include <sys/param.h>
  238: #endif
  239: 
  240: #if !defined(PATH_MAX) && defined(MAXPATHLEN)
  241: # define PATH_MAX MAXPATHLEN
  242: #endif
  243: 
  244: #if !defined(LONG_MAX) && defined(HAVE_LIMITS_H)
  245: # include <limits.h>
  246: #endif
  247: 
  248: #ifndef PATH_MAX
  249: # define PATH_MAX _POSIX_PATH_MAX
  250: #endif
  251: 
  252: #ifdef __GNUC__
  253: 
  254: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 5)
  255: # define LRZSZ_ATTRIB_SECTION(x) __attribute__((section(#x)))
  256: #endif
  257: 
  258: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
  259: # define LRZSZ_ATTRIB_CONST  __attribute__((__const__))
  260: #endif
  261: 
  262:     /* gcc.info sagt, noreturn wäre ab 2.5 verfügbar. HPUX-gcc 2.5.8
  263:      * kann es noch nicht - what's this?
  264:      */
  265: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 5)
  266: # define LRZSZ_ATTRIB_NORET  __attribute__((__noreturn__))
  267: #endif
  268: 
  269: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 5)
  270: # define LRZSZ_ATTRIB_PRINTF(formatnr,firstargnr)  \
  271:     __attribute__((__format__ (printf,formatnr,firstargnr)))
  272: #endif
  273: 
  274: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6)
  275: #define LRZSZ_ATTRIB_UNUSED __attribute__((__unused__))
  276: #endif
  277: 
  278: #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
  279: # define LRZSZ_ATTRIB_REGPARM(n)  \
  280:     __attribute__((__regparm__ (n)))
  281: #endif
  282: #endif /* __GNUC__ */
  283: #ifndef LRZSZ_ATTRIB_REGPARM
  284: #define LRZSZ_ATTRIB_REGPARM(n)
  285: #endif
  286: #ifndef LRZSZ_ATTRIB_UNUSED
  287: #define LRZSZ_ATTRIB_UNUSED
  288: #endif
  289: #ifndef LRZSZ_ATTRIB_NORET
  290: #define LRZSZ_ATTRIB_NORET
  291: #endif
  292: #ifndef LRZSZ_ATTRIB_CONST
  293: #define LRZSZ_ATTRIB_CONST
  294: #endif
  295: #ifndef LRZSZ_ATTRIB_PRINTF
  296: #define LRZSZ_ATTRIB_PRINTF(x,y)
  297: #endif
  298: #ifndef LRZSZ_ATTRIB_SECTION
  299: #define LRZSZ_ATTRIB_SECTION(n)
  300: #endif
  301: #undef LRZSZ_ATTRIB_SECTION
  302: #define LRZSZ_ATTRIB_SECTION(x)
  303: #undef LRZSZ_ATTRIB_REGPARM
  304: #define LRZSZ_ATTRIB_REGPARM(x)
  305: 
  306: 
  307: #define OK 0
  308: #define FALSE 0
  309: #define TRUE 1
  310: #define ERROR (-1)
  311: 
  312: /* Ward Christensen / CP/M parameters - Don't change these! */
  313: #define ENQ 005
  314: #define CAN ('X'&037)
  315: #define XOFF ('s'&037)
  316: #define XON ('q'&037)
  317: #define SOH 1
  318: #define STX 2
  319: #define EOT 4
  320: #define ACK 6
  321: #define NAK 025
  322: #define CPMEOF 032
  323: #define WANTCRC 0103    /* send C not NAK to get crc not checksum */
  324: #define WANTG 0107  /* Send G not NAK to get nonstop batch xmsn */
  325: #define TIMEOUT (-2)
  326: #define RCDO (-3)
  327: #define WCEOT (-10)
  328: 
  329: #define RETRYMAX 10
  330: 
  331: #define UNIXFILE 0xF000  /* The S_IFMT file mask bit for stat */
  332: 
  333: #define DEFBYTL 2000000000L	/* default rx file size */
  334: 
  335: enum zm_type_enum {
  336: 	ZM_XMODEM,
  337: 	ZM_YMODEM,
  338: 	ZM_ZMODEM
  339: };
  340: 
  341: struct zm_fileinfo {
  342: 	char *fname;
  343: 	time_t modtime;
  344: 	mode_t mode;
  345: 	size_t bytes_total;
  346: 	size_t bytes_sent;
  347: 	size_t bytes_received;
  348: 	size_t bytes_skipped; /* crash recovery */
  349: 	int    eof_seen;
  350: };
  351: 
  352: #define R_BYTESLEFT(x) ((x)->bytes_total-(x)->bytes_received)
  353: 
  354: extern enum zm_type_enum protocol;
  355: 
  356: extern const char *program_name;        /* the name by which we were called */
  357: extern int Verbose;
  358: extern int errors;
  359: extern int no_timeout;
  360: extern int Zctlesc;    /* Encode control characters */
  361: extern int under_rsh;
  362: 
  363: RETSIGTYPE bibi __P ((int n));
  364: 
  365: #define sendline(c) putchar((c) & 0377)
  366: #define xsendline(c) putchar(c)
  367: 
  368: /* zreadline.c */
  369: extern char *readline_ptr; /* pointer for removing chars from linbuf */
  370: extern int readline_left; /* number of buffered chars left to read */
  371: #define READLINE_PF(timeout) \
  372:     (--readline_left >= 0? (*readline_ptr++ & 0377) : readline_internal(timeout))
  373: 
  374: int readline_internal __P ((unsigned int timeout));
  375: void readline_purge __P ((void));
  376: void readline_setup __P ((int fd, size_t readnum, 
  377: 	size_t buffer_size)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  378: 
  379: 
  380: /* rbsb.c */
  381: extern int Fromcu;
  382: extern int Twostop;
  383: #ifdef READCHECK_READS
  384: extern unsigned char checked;
  385: #endif
  386: extern int iofd;
  387: extern unsigned Baudrate;
  388: 
  389: void zperr __P ((const char *fmt, ...));
  390: void zpfatal __P ((const char *fmt, ...));
  391: void vfile __P ((const char *format, ...));
  392: #define vchar(x) putc(x,stderr)
  393: #define vstring(x) fputs(x,stderr)
  394: 
  395: #ifdef __GNUC__
  396: #if __GNUC__ > 1
  397: #define vstringf(format,args...) fprintf(stderr,format, ##args)
  398: #endif
  399: #endif
  400: #ifndef vstringf
  401: void vstringf __P ((const char *format, ...));
  402: #endif
  403: #define VPRINTF(level,format_args) do {if ((Verbose)>=(level)) \
  404: 	vstringf format_args ; } while(0)
  405: 
  406: /* rbsb.c */
  407: int from_cu __P ((void)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  408: int rdchk __P ((int fd));
  409: int io_mode __P ((int fd, int n)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  410: void sendbrk __P ((int fd));
  411: #define flushmo() fflush(stdout)
  412: void purgeline __P ((int fd));
  413: void canit __P ((int fd));
  414: 
  415: 
  416: /* crctab.c */
  417: extern unsigned short crctab[256];
  418: #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  419: extern long cr3tab[];
  420: #define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
  421: 
  422: /* zm.c */
  423: #include "zmodem.h"
  424: extern unsigned int Rxtimeout;        /* Tenths of seconds to wait for something */
  425: extern int bytes_per_error;  /* generate one error around every x bytes */
  426: 
  427: /* Globals used by ZMODEM functions */
  428: extern int Rxframeind;     /* ZBIN ZBIN32, or ZHEX type of frame received */
  429: extern int Rxtype;     /* Type of header received */
  430: extern int Zrwindow;       /* RX window size (controls garbage count) */
  431: /* extern int Rxcount; */       /* Count of data bytes received */
  432: extern char Rxhdr[4];      /* Received header */
  433: extern char Txhdr[4];      /* Transmitted header */
  434: extern long Txpos;     /* Transmitted file position */
  435: extern int Txfcs32;        /* TURE means send binary frames with 32 bit FCS */
  436: extern int Crc32t;     /* Display flag indicating 32 bit CRC being sent */
  437: extern int Crc32;      /* Display flag indicating 32 bit CRC being received */
  438: extern int Znulls;     /* Number of nulls to send at beginning of ZDATA hdr */
  439: extern char Attn[ZATTNLEN+1];  /* Attention string rx sends to tx on err */
  440: 
  441: extern void zsendline __P ((int c));
  442: extern void zsendline_init __P ((void)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  443: void zsbhdr __P ((int type, char *hdr));
  444: void zshhdr __P ((int type, char *hdr));
  445: void zsdata __P ((const char *buf, size_t length, int frameend));
  446: void zsda32 __P ((const char *buf, size_t length, int frameend));
  447: int zrdata __P ((char *buf, int length, size_t *received));
  448: int zgethdr __P ((char *hdr, int eflag, size_t *));
  449: void stohdr __P ((size_t pos)) LRZSZ_ATTRIB_REGPARM(1);
  450: long rclhdr __P ((char *hdr)) LRZSZ_ATTRIB_REGPARM(1);
  451: 
  452: int tcp_server __P ((char *buf)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  453: int tcp_connect __P ((char *buf)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  454: int tcp_accept __P ((int d)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  455: 
  456: 
  457: const char * protname __P ((void)) LRZSZ_ATTRIB_SECTION(lrzsz_rare);
  458: void lsyslog __P ((int, const char *,...));
  459: 
  460: 
  461: 
  462: 
  463: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>