home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / microdot-1 / md1_src_02.lzx / clhydra.c < prev    next >
C/C++ Source or Header  |  2014-05-19  |  11KB  |  498 lines

  1. #include <proto/dos.h>
  2. #define __USE_SYSBASE
  3. #include <proto/exec.h>
  4. #include <proto/intuition.h>
  5. #include <proto/utility.h>
  6. #include <proto/gadtools.h>
  7. #include <proto/graphics.h>
  8. #include <intuition/sghooks.h>
  9.  
  10. #include <devices/timer.h>
  11. #include <exec/execbase.h>
  12. #include <devices/serial.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <dos.h>
  17.  
  18. #include "microdot.h"
  19.  
  20. #define MAIN
  21. #define byte fickdichinsknie
  22. #include "hydracom.h"
  23.  
  24. static ULONG     inabortion;
  25. extern int linespeed;
  26.  
  27. /*
  28. **    Hydra stuff
  29. **
  30. */
  31.  
  32. static  struct NewMenu menus[] = {
  33. NM_TITLE, "Hydra",                      0,   0, 0, NULL,
  34.  NM_ITEM, "Chat...", "C", 0, 0, 0,
  35.  NM_ITEM, NM_BARLABEL, 0, 0, 0, 0,
  36.  NM_ITEM, "Abbruch", "A", 0, 0, 0,
  37. NM_END };
  38.  
  39. extern char *chatbuffer;
  40. int warned;
  41. static void setchattimeout( void )
  42. {
  43.     chattimer = time(NULL) + CHAT_TIMEOUT;
  44.     warned = false;
  45. }
  46.  
  47. extern struct Window *twindow;
  48. static struct Gadget *glist;
  49. static struct VisualInfo *vi;
  50. static int fontheight, llen;
  51.  
  52. static struct List hyd_loglist, hyd_chatinlist, hyd_chatoutlist;
  53. static APTR hydlistpool;
  54.  
  55. static struct Gadget *g_loglist, *g_chatinlist, *g_chatoutlist, *g_stringin;
  56.  
  57. struct hydlistnode {
  58.     struct Node n;
  59.     char text[á1 ];
  60. };
  61.  
  62. static void hyd_addnode2( struct Gadget *g, struct List *l, char *text )
  63. {
  64.     struct hydlistnode *n;
  65.  
  66.     n = LibAllocPooled( hydlistpool, sizeof( struct hydlistnode ) + strlen( text ) );
  67.     n->n.ln_Name = n->text;
  68.     strcpy( n->text, text );
  69.  
  70.     AddTail( l, n );
  71.  
  72.     GT_SetGadgetAttrs( g, twindow, NULL,
  73.         GTLV_Labels, l,
  74.         isv39 ? GTLV_MakeVisible : GTLV_Top, GetNumEntries( l ) - 1,
  75.         TAG_DONE
  76.     );
  77. }
  78.  
  79. // Mit zeilenumbruch
  80. static void hyd_addnode( struct Gadget *g, struct List *l, char *text )
  81. {
  82.     if( !*text )
  83.     {
  84.         hyd_addnode2( g, l, text );
  85.         return;
  86.     }
  87.     while( *text )
  88.     {
  89.         char buff[á256 ];
  90.         struct TextExtent dummy;
  91.  
  92.         int len = TextFit( twindow->RPort, text, strlen( text ), &dummy, NULL,
  93.             1, g->Width - 7, 32767
  94.         );
  95.         len = min( 255, len );
  96.         strncpy( buff, text, len );
  97.         buff[álen ]á= 0;
  98.         hyd_addnode2( g, l, buff );
  99.         text += len;
  100.     }
  101. }
  102.  
  103. void hyd_addlog( char *text )
  104. {
  105.     hyd_addnode( g_loglist, &hyd_loglist, text );
  106. }
  107.  
  108. void hyd_addchatin( char *text )
  109. {
  110.     hyd_addnode( g_chatinlist, &hyd_chatinlist, text );
  111. }
  112.  
  113. void hyd_addchatout( char *text )
  114. {
  115.     hyd_addnode( g_chatoutlist, &hyd_chatoutlist, text );
  116. }
  117.  
  118. static void drawbars( void )
  119. {
  120.     int wx = twindow->GZZWidth;
  121.     // Draw Gauge Frames
  122.  
  123.     SetAPen( twindow->RPort, 2 );
  124.     SetSoftStyle( twindow->RPort, FSF_BOLD, FSF_BOLD );
  125.  
  126.     llen = TextLength( twindow->RPort, "Empfange:", 9 ) + 2;
  127.  
  128.     Move( twindow->RPort, 2, fontheight + 1 );
  129.     Text( twindow->RPort, "Senden:", 7 );
  130.     Move( twindow->RPort, 2, fontheight + 4 + fontheight );
  131.     Text( twindow->RPort, "Empfange:", 9 );
  132.     SetSoftStyle( twindow->RPort, 0, FSF_BOLD );
  133.  
  134.  
  135.     DrawBevelBox( twindow->RPort, llen + 4, 2, wx - llen - 6, fontheight + 4, GTBB_Recessed, TRUE, GT_VisualInfo, vi, TAG_DONE );
  136.     DrawBevelBox( twindow->RPort, llen + 4, 6 + fontheight, wx - llen - 6, fontheight + 4, GTBB_Recessed, TRUE, GT_VisualInfo, vi, TAG_DONE );
  137. }
  138.  
  139. extern struct TextAttr realfontta;
  140. extern struct IOStdReq cr, cw;
  141. static ULONG oldidcmp;
  142. static APTR oldmenustrip;
  143. static struct Menu *menustrip;
  144. static ULONG oldwinflags;
  145.  
  146. static LONG __asm __saveds edithookfunc( register __a1 ULONG *msg, register __a2 struct SGWork *sgw )
  147. {
  148.     if( *msg == SGH_KEY )
  149.     {
  150.         setchattimeout();
  151.  
  152.         if( ( sgw->IEvent->ie_Class == IECLASS_RAWKEY ) &&
  153.             ( sgw->IEvent->ie_Qualifier & ( IEQUALIFIER_LCOMMAND | IEQUALIFIER_RCOMMAND ) ) )
  154.         {
  155.             sgw->Actions = SGA_END | SGA_REUSE;
  156.             sgw->Code = 0x70;
  157.             return( 1 );
  158.         }
  159.         // User pressed ENTER...
  160.         if( sgw->EditOp == EO_ENTER )
  161.         {
  162.             if( strlen( chatbuffer ) + strlen( sgw->WorkBuffer ) < 254 )
  163.             {
  164.                 hyd_addchatout( sgw->WorkBuffer );
  165.                 siso2ibm( sgw->WorkBuffer );
  166.                 strcat( chatbuffer, sgw->WorkBuffer );
  167.                 strcat( chatbuffer, "\n" );
  168.                 *sgw->WorkBuffer = 0;
  169.                 sgw->BufferPos = 0;
  170.                 sgw->NumChars = 0;
  171.                 sgw->Actions |= SGA_REDISPLAY;
  172.             }
  173.             else
  174.                 sgw->Actions |= SGA_BEEP;
  175.             sgw->Actions &= ~SGA_END;
  176.         }
  177.         return( 1 );
  178.     }
  179.     return( 0 );
  180. }
  181.  
  182. static struct Hook edithook={0,0,(HOOKFUNC)edithookfunc};
  183.  
  184. static void init_hydrawin( void )
  185. {
  186.     int wx = twindow->GZZWidth, wy = twindow->GZZHeight;
  187.     struct NewGadget ng = {0};
  188.     struct Gadget *gl;
  189.     static struct TextAttr ta;
  190.  
  191.     ta.ta_Name = twindow->RPort->Font->tf_Message.mn_Node.ln_Name;
  192.     ta.ta_YSize = twindow->RPort->Font->tf_YSize;
  193.  
  194.     oldmenustrip = twindow->MenuStrip;
  195.  
  196.     // Remove con
  197.     CloseDevice( &cr );
  198.  
  199.     oldidcmp = twindow->IDCMPFlags;
  200.     ModifyIDCMP( twindow, LISTVIEWIDCMP | BUTTONIDCMP | IDCMP_MENUPICK | IDCMP_SIZEVERIFY | IDCMP_REFRESHWINDOW );
  201.  
  202.     hydlistpool = LibCreatePool( MEMF_CLEAR, 8192, 4096 );
  203.     NEWLIST( &hyd_loglist );
  204.     NEWLIST( &hyd_chatoutlist );
  205.     NEWLIST( &hyd_chatinlist );
  206.  
  207.     Move( twindow->RPort, 0, 0 );
  208.     SetBPen( twindow->RPort, 0 );
  209.     ClearScreen( twindow->RPort );
  210.  
  211.     vi = GetVisualInfo( twindow->WScreen, TAG_DONE );
  212.     fontheight = twindow->RPort->Font->tf_YSize + 2;
  213.     drawbars();
  214.  
  215.     glist = NULL;
  216.     gl = CreateContext( &glist );
  217.  
  218.     // Create Input String
  219.  
  220.     ng.ng_VisualInfo = vi;
  221.     ng.ng_LeftEdge = 0;
  222.     ng.ng_Width = wx;
  223.     ng.ng_TopEdge = wy - fontheight - 8;
  224.     ng.ng_TextAttr = &ta;
  225.     ng.ng_GadgetID = 1;
  226.     ng.ng_Height = fontheight + 8;
  227.  
  228.     g_stringin = gl = CreateGadget( STRING_KIND, gl, &ng, GTST_MaxChars, 256, GA_Disabled, TRUE, GTST_EditHook, &edithook, TAG_DONE );
  229.  
  230.     // Create Log Listivew
  231.     ng.ng_GadgetID = 42;
  232.     ng.ng_GadgetText = NULL;
  233.     ng.ng_TopEdge = fontheight * 2 + 14;
  234.     ng.ng_Height = ( wy / 4 );
  235.     ng.ng_LeftEdge = 0;
  236.  
  237.     g_loglist = gl = CreateGadget( LISTVIEW_KIND, gl, &ng, GTLV_ReadOnly, TRUE, TAG_DONE );
  238.  
  239.     // Create Chatin Listivew
  240.     ng.ng_Width = wx;
  241.     ng.ng_TopEdge += ng.ng_Height;
  242.     ng.ng_Height = ( wy / 2 );
  243.  
  244.     g_chatinlist = gl = CreateGadget( LISTVIEW_KIND, gl, &ng, GTLV_ReadOnly, TRUE, TAG_DONE );
  245.  
  246.     // Create Chatout  Listivew
  247.     ng.ng_TopEdge += ng.ng_Height;
  248.     ng.ng_Height = wy - fontheight - 8 - ng.ng_TopEdge;
  249.  
  250.     g_chatoutlist = gl = CreateGadget( LISTVIEW_KIND, gl, &ng, GTLV_ReadOnly, TRUE, GA_Disabled, TRUE, TAG_DONE );
  251.  
  252.     // Add Gadgets 
  253.     AddGList( twindow, glist, -1, -1, NULL );
  254.     RefreshGadgets( glist, twindow, NULL );
  255.     GT_RefreshWindow( twindow, NULL );
  256.  
  257.     menustrip = CreateMenus( menus, TAG_DONE );
  258.     LayoutMenus( menustrip, vi, GTMN_NewLookMenus, TRUE, TAG_DONE );
  259.  
  260.     SetMenuStrip( twindow, menustrip );
  261.  
  262.     hyd_addchatin( " * Amiga-C: Chatmodus aktivieren" );
  263.     hyd_addchatin( " * Amiga-A: ▄bertragung abbrechen" );
  264.  
  265.     oldwinflags = twindow->Flags & WFLG_RMBTRAP;
  266.     twindow->Flags &= ~WFLG_RMBTRAP;
  267. }
  268.  
  269. static void exit_hydrawin( void )
  270. {
  271.     ClearMenuStrip( twindow );
  272.     SetMenuStrip( twindow, oldmenustrip );
  273.     if( oldwinflags )
  274.         twindow->Flags |= WFLG_RMBTRAP;
  275.  
  276.     RemoveGList( twindow, glist, -1 );
  277.     FreeGadgets( glist );
  278.     FreeVisualInfo( vi );
  279.     Move( twindow->RPort, 0, 0 );
  280.     ClearScreen( twindow->RPort );
  281.  
  282.     ModifyIDCMP( twindow, oldidcmp );
  283.  
  284.     cr.io_Data = twindow;
  285.     cr.io_Length = sizeof( struct Window );
  286.     OpenDevice( "console.device", (isv37) ? 3 : 0, &cr, 0 );
  287.     cw.io_Device = cr.io_Device;
  288.     cw.io_Unit = cr.io_Unit;
  289. }
  290.  
  291. static int batch_hydra (char *filespec, char *alias)
  292. {
  293.     switch (hydra(filespec,alias))
  294.     {
  295.         case XFER_ABORT:
  296.         case XFER_SKIP:
  297.             return (1);
  298.  
  299.         case XFER_OK:
  300.             message(1,"+Sent-H %s",work);
  301.             break;
  302.     }
  303.     return (0);
  304. }/*batch_hydra()*/
  305.  
  306. static void shortfilename( char *fn )
  307. {
  308.     char b[ 64 ], *p;
  309.  
  310.     strcpy( b, fn );
  311.     p = strchr( b, '.' );
  312.     if( p )
  313.         *p++ = 0;
  314.     strcpy( fn, b );
  315.     fn[á8 ]á= 0;
  316.     if( p )
  317.     {
  318.         p[á3 ]á= 0;
  319.         strcat( fn, "." );
  320.         strcat( fn, p );
  321.     }
  322. }
  323.  
  324. struct sendfilenode {
  325.     struct MinNode n;
  326.     char name[á256 ];
  327. };
  328.  
  329. extern struct mdtprefs mdtprefs;
  330.  
  331. static int recfilecount;
  332. int hydra_xfer( struct MinList *sendfiles )
  333. {
  334.     int error = FALSE;
  335.     struct sendfilenode *sfn;
  336.     static char downloaddir[á256 ];
  337.  
  338. /*    docheckcd = GetTagData( CLXFER_CheckCD, TRUE, tags );
  339.     cur_speed = GetTagData( CLXFER_LineBaud, com_speed = sr->io_Baud, tags );*/
  340.  
  341. /*
  342.  
  343.     download = GetTagData( CLXFER_RecDir, "", tags );;*/
  344.  
  345.     strcpy( downloaddir, download );
  346.     download = downloaddir;
  347.     if( downloaddir[á0 ]á&& downloaddir[ástrlen( downloaddir ) - 1 ]á!= '/'á&& downloaddir[ástrlen( downloaddir ) - 1 ]á!= ':' )
  348.         strcat( downloaddir, "/" );
  349.  
  350.     // Init Hydra
  351.     dcdmask = 0x80;
  352.     loglevel = 2;
  353.     opustask = -1;
  354.  
  355.     cur_speed = linespeed;
  356.     recfilecount = 0;
  357.  
  358.     init_hydrawin();
  359.     sys_init();
  360.  
  361.     hydra_init( 0 );
  362.  
  363.     nocarrier = mdtprefs.flags & 8;
  364.  
  365.     sfn = FIRSTNODE( sendfiles );
  366.     while( !error && NEXTNODE( sfn ) )
  367.     {
  368.         char sendname[á32 ];
  369.  
  370.         strcpy( sendname, FilePart( sfn->name ) );
  371.         shortfilename( sendname );
  372.  
  373.         if( batch_hydra( sfn->name, sendname ) )
  374.             error = TRUE;
  375.         sfn = NEXTNODE( sfn );
  376.     }
  377.     if( !error )
  378.         hydra( NULL, NULL );
  379.     hydra_deinit();
  380.     sys_reset();
  381.     exit_hydrawin();
  382.  
  383.     if( error )
  384.         return( -1 );
  385.     else
  386.         return( recfilecount );
  387. }
  388.  
  389. void endprog( int errcode )
  390. {
  391.        message(1,"+%s v%s %s : end (exitcode=%d)",
  392.                  PRGNAME,VERSION,HC_OS,errcode);
  393.        resultlog(false,NULL,0L,0L);
  394.        if (logfp) fclose(logfp);
  395.        exit (errcode);
  396. }
  397.  
  398. int ConScanKey( void )
  399. {
  400.     if( inabortion == 1 )
  401.     {
  402.         inabortion++;
  403.         return( 1 );
  404.     }
  405.  
  406.     if( !IsMsgPortEmpty( twindow->UserPort ) )
  407.         return( 1 );
  408.  
  409.     return( 0 );
  410. }
  411.  
  412. void enablechat( int state )
  413. {
  414.     GT_SetGadgetAttrs( g_stringin, twindow, NULL, GA_Disabled, !state, TAG_DONE );
  415.     GT_SetGadgetAttrs( g_chatoutlist, twindow, NULL, GA_Disabled, !state, TAG_DONE );
  416.  
  417.     if( state )
  418.         ActivateGadget( g_stringin, twindow, NULL );
  419. }
  420.  
  421. int ConGetKey( void )
  422. {
  423.     struct IntuiMessage *im;
  424.     int rc = 0;
  425.  
  426.     im = GT_GetIMsg( twindow->UserPort );
  427.     if( im )
  428.     {
  429.         switch( im->Class )
  430.         {
  431.             case IDCMP_REFRESHWINDOW:
  432.                 GT_BeginRefresh( twindow );
  433.                 drawbars();
  434.                 GT_EndRefresh( twindow, TRUE );
  435.                 break;
  436.  
  437.             case IDCMP_SIZEVERIFY:
  438.                 im->Code = MENUCANCEL;
  439.                 break;
  440.  
  441.             case IDCMP_MENUPICK:
  442.                 if( !MENUNUM( im->Code ) )
  443.                 {
  444.                     if( ITEMNUM( im->Code ) == 0 )
  445.                         rc = Alt_C;
  446.                     else if( ITEMNUM( im->Code ) == 2 )
  447.                         rc = Esc;
  448.                 }
  449.                 break;
  450.  
  451.         }
  452.         GT_ReplyIMsg( im );
  453.     }
  454.  
  455.     return( rc );
  456. }
  457.  
  458. extern char    txfname[],    rxfname[];    /* fname of current files    */
  459. void __stdargs gaugereport( int xmit, int pos, int filesize, char *txt, ... )
  460. {
  461.     static UWORD fmtfunc[] = {á0x16c0, 0x4e75 };
  462.     char buffer[ 128 ];
  463.     int gx = llen + 6, gxs = twindow->GZZWidth - gx - 6;
  464.     int gy = xmit ? 2 : 6 + fontheight;
  465.     int be;
  466.  
  467.     sprintf( buffer, "%s: ", ( xmit ) ? txfname : rxfname );
  468.     RawDoFmt( txt, &txt+ 1, (APTR)fmtfunc, strchr( buffer, 0 ) );
  469.     SetDrMd( twindow->RPort, JAM1 );
  470.  
  471.     if( filesize > 10 )
  472.         be = ( ( pos / 10 )  * gxs ) / ( filesize / 10 );
  473.     else
  474.         be = gxs;
  475.     if( be )
  476.     {
  477.         SetAPen( twindow->RPort, 3 );
  478.         RectFill( twindow->RPort, gx, gy + 1, gx + be - 1, gy + fontheight + 2 );
  479.     }
  480.     if( be < gxs )
  481.     {
  482.         SetAPen( twindow->RPort, 0 );
  483.         RectFill( twindow->RPort, gx + be, gy + 1, gx + gxs, gy + fontheight + 2 );
  484.     }
  485.     SetAPen( twindow->RPort, 1 );
  486.     Move( twindow->RPort, gx + 8, gy + twindow->RPort->Font->tf_Baseline + 3 );
  487.     Text( twindow->RPort, buffer, strlen( buffer ) );
  488. }
  489.  
  490. void gaugedone( int xmit )
  491. {
  492. }
  493.  
  494. void addrecfile( char *name, long time )
  495. {
  496.     recfilecount++;
  497. }
  498.