/*=============================================================================

                              HydraCom Version 1.00

                         A sample implementation of the
                   HYDRA Bi-Directional File Transfer Protocol

                             HydraCom was written by
                   Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT
                  COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED

                       The HYDRA protocol was designed by
                 Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT and
                             Joaquim H. Homrighausen
                  COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED


  Revision history:
  06 Sep 1991 - (AGL) First tryout
  .. ... .... - Internal development
  11 Jan 1993 - HydraCom version 1.00, Hydra revision 001 (01 Dec 1992)


  For complete details of the Hydra and HydraCom licensing restrictions,
  please refer to the license agreements which are published in their entirety
  in HYDRACOM.C and LICENSE.DOC, and also contained in the documentation file
  HYDRACOM.DOC

  Use of this file is subject to the restrictions contained in the Hydra and
  HydraCom licensing agreements. If you do not find the text of this agreement
  in any of the aforementioned files, or if you do not have these files, you
  should immediately contact LENTZ SOFTWARE-DEVELOPMENT and/or Joaquim
  Homrighausen at one of the addresses listed below. In no event should you
  proceed to use this file without having accepted the terms of the Hydra and
  HydraCom licensing agreements, or such other agreement as you are able to
  reach with LENTZ SOFTWARE-DEVELOMENT and Joaquim Homrighausen.


  Hydra protocol design and HydraCom driver:         Hydra protocol design:
  Arjen G. Lentz                                     Joaquim H. Homrighausen
  LENTZ SOFTWARE-DEVELOPMENT                         389, route d'Arlon
  Langegracht 7B                                     L-8011 Strassen
  3811 BT  Amersfoort                                Luxembourg
  The Netherlands
  FidoNet 2:283/512, AINEX-BBS +31-33-633916         FidoNet 2:270/17
  arjen_lentz@f512.n283.z2.fidonet.org               joho@ae.lu

  Please feel free to contact us at any time to share your comments about our
  software and/or licensing policies.

=============================================================================*/

#define MSGM_NONE 0
#define MSGM_XMIT 1
#define MSGM_POS 2
#define MSGM_FSIZE 4
#define MSGM_CPS 8
#define MSGM_TIME 16
#define MSGM_MSG 32
#define MSGM_FNAME 64

#ifndef WIN_AGL
#define WIN_AGL 0        /* set to 1 for AGL's MS-DOS/AtariST window package */
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#ifdef AMIGA
#define byte foo234234
#include <dos.h>
#undef byte
#else
#include <dos.h>
#endif  /* AMIGA */
#include <time.h>
#include <sys/stat.h>
/*#include <process.h>*/  /* OLSEN */
/*#include <signal.h>*/   /* OLSEN */
#ifdef AMIGA
#include <fcntl.h>    /* OLSEN */
#else
#include <conio.h>      /* MS-DOS Turbo/Borland C(++) console stuff */
#endif
#include "2types.h"
#include "hydra.h"

#ifdef __MSDOS__
#define inteli(x) (x)
#define intell(x) (x)
#endif
#if !WIN_AGL
#define Esc   0x01b
#define Alt_B 0x130
#define Alt_C 0x12e
#define Alt_E 0x112
#define Alt_H 0x123
#define Alt_X 0x12D
#define PgUp  0x149
#define PgDn  0x151
#endif

#ifdef AMIGA
#include "amiga.h"
#define intell(x) (((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24))
#endif  /* AMIGA */

#define PRGNAME "HydraCom"
#define LOGID   "HCom"
#define VERSION "1.00"
#ifdef __MSDOS__
#  define HC_OS  "PC"
#else /*!MSDOS*/
#  ifdef __OS2__
#    define HC_OS  "OS/2"
#  else /*!OS2*/
#    ifdef __TOS__
#      define HC_OS  "ST"
#    endif /*TOS*/
#  endif /*OS2*/
#endif /*MSDOS*/

#ifdef AMIGA
#define HC_OS "AMIGA"
#endif  /* AMIGA */


#ifdef AMIGA    /* OLSEN */
#define PATHLEN 1024
#define MAXARGS 256
#else
#define PATHLEN 90
#define MAXARGS 50
#endif  /* AMIGA */

#define DENY_ALL   0x0000
#define DENY_RDWR  0x0010
#define DENY_WRITE 0x0020
#define DENY_READ  0x0030
#define DENY_NONE  0x0040

#ifdef MAIN
#define global
#else
#define global extern
#endif

global  char     ourname[PATHLEN];
global  char     work[256],
                 buffer[256];
global  char     device[256]; /* OLSEN */
global  int      pri;   /* OLSEN */
global  int      port;
#ifdef AMIGA
global  long     cur_speed;
global  long     com_speed;
#else
global  word     cur_speed;
global  word     com_speed;
#endif
global  boolean  parity;
global  boolean  noinit;
global  boolean  nocarrier;
global  boolean  dropdtr;
global  int      flowflags;
global  int      dcdmask;
#ifdef AMIGA
global  boolean  quiet;
#endif
global  boolean  nobell;
global  boolean  mailer;
global  boolean  nooriginator;
global  boolean  hdxsession;
global  long     hydra_txwindow,
                 hydra_rxwindow;
global  char    **av;
global  int      loglevel;
global  FILE    *logfp;
global  char    *result;
global  char    *download;
#ifdef AMIGA
global  char     single_file[32];
#else
global  char     single_file[20];
#endif  /* AMIGA */
global  boolean  single_done;
global  boolean  noresume;
global  boolean  nostamp;
global  dword    hydra_options;
global  int      opustask;
global  char    *opuslog;
global  boolean  didsome;
#if WIN_AGL
global  WIN_IDX  file_win,
                 log_win,
                 remote_win,
                 local_win;
global  boolean  log_first;
#else
global  void    *term_scr;
global  int      term_x,   term_y,
                 file_x,   file_y,
                           log_y,
                 remote_x, remote_y,
                 local_x,  local_y;
#endif

#define CHAT_TIMEOUT 60
global  word     chatfill;
global  long     chattimer,
                 lasttimer;

struct FileBuffer
{
  struct Node node; // filename in ln_Name

  ULONG BytesTransferred;
  ULONG ActualSize;
  ULONG StartOffset;
  ULONG CPS;
  BOOL WarezFile;
  ULONG ConferenceNum;
};

#include "dos_file_protos.h"
#include "amiga_protos.h"
#include "misc_protos.h"
#include "Main_protos.h"
#include "Hydra_GUI_protos.h"
#include "hydra_protos.h"
