home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d325 / farprint.lha / FarPrint / FarPrint.c < prev    next >
C/C++ Source or Header  |  1990-02-27  |  22KB  |  1,028 lines

  1. /* FarPrint.c ***************************************************************
  2. *
  3. *    FarPrint ------    Debugging functions for programs which don't
  4. *            have links to their environment.
  5. *
  6. *            FarPrint 'harbour' to receive and distribute
  7. *            all incoming messages.
  8. *
  9. *    Author --------    Olaf Barthel of MXM
  10. *            Brabeckstrasse 35
  11. *            D-3000 Hannover 71
  12. *
  13. *            Federal Republic of Germany.
  14. *
  15. *    This program truly is in the PUBLIC DOMAIN. Written on a sunny
  16. *    September day in 1989, updated 27 January 1990.
  17. *
  18. *    Compiled using Aztec C 3.6a, CygnusEd Professional 2 & ARexx.
  19. *
  20. ****************************************************************************/
  21.  
  22.     /* Our main includes, note that you MUST have the ARP
  23.      * package to recompile FarPrint!
  24.      */
  25.  
  26. #include <intuition/intuitionbase.h>
  27. #include <libraries/dosextens.h>
  28. #include <libraries/arpbase.h>
  29. #include <graphics/gfxbase.h>
  30. #include <arpfunctions.h>
  31. #include <exec/memory.h>
  32.  
  33.     /* Forward declarations. */
  34.  
  35. extern struct Library    *OpenLibrary();
  36. extern struct Window    *OpenWindow();
  37. extern struct Message    *GetMsg();
  38. extern struct MenuItem    *ItemAddress();
  39. extern struct MsgPort    *CreatePort();
  40. extern struct TextFont    *OpenFont();
  41. extern void        *AllocMem();
  42. extern ULONG         Wait();
  43.  
  44.     /* Signal sources. */
  45.  
  46. #define SIG_WINDOW    (1 << Window -> UserPort -> mp_SigBit)
  47. #define SIG_PORT    (1 << FarPort -> mp_SigBit)
  48.  
  49.     /* Textprint macro. */
  50.  
  51. #define PrintRequest(Request) Text(RPort,Request,strlen(Request))
  52.  
  53.     /* External communication commands. */
  54.  
  55. #define FM_ADDTXT    0
  56. #define FM_REQTXT    1
  57. #define FM_REQNUM    2
  58.  
  59.     /* Custom task <-> task communication message. */
  60.  
  61. struct FarMessage
  62. {
  63.     struct Message    fm_ExecMessage;    /* Exec message link. */
  64.  
  65.     USHORT        fm_Command;    /* Perform which action? */
  66.     STRPTR        fm_Identifier;    /* Who calls? */
  67.     STRPTR        fm_Text;    /* Message to display. */
  68. };
  69.  
  70.     /* Messages to be displayed. */
  71.  
  72. STRPTR TextList[128];
  73. LONG InTextList = 0;
  74.  
  75.     /* Global and shared data structures. */
  76.  
  77. struct ArpBase        *ArpBase;
  78. struct IntuitionBase    *IntuitionBase;
  79. struct GfxBase        *GfxBase;
  80. struct Window        *Window;
  81. struct IntuiMessage    *Massage;
  82. struct RastPort        *RPort;
  83. struct MsgPort        *FarPort;
  84. struct TextFont        *DefaultFont;
  85. BOOL             Pausing = FALSE;
  86. BOOL             Suspended = FALSE;
  87.  
  88.     /* Maximum number of chars in FileRequest path. */
  89.  
  90. #define MAXPATH    ((FCHARS * 10) + DSIZE + 1)
  91.  
  92.     /* FileRequest working data. */
  93.  
  94. UBYTE Filename[FCHARS + 1];
  95. UBYTE Directory[MAXPATH] = "SYS:";
  96.  
  97.     /* ARP FileRequester structure. */
  98.  
  99. struct FileRequester MyRequest =
  100. {
  101.     "Save message texts",
  102.     (BYTE *)Filename,
  103.     (BYTE *)Directory,
  104.     NULL,NULL,NULL,NULL
  105. };
  106.  
  107.     /* Run dump for up arrow gadget. */
  108.  
  109. USHORT UpMap[22] =
  110. {
  111.     0xFFFE,0xFEFE,0xFC7E,0xF83E,0xF01E,0xE00E,0xC006,0xF83E,
  112.     0xF83E,0xF83E,0xFFFE,
  113.  
  114.     0x0000,0x0100,0x0380,0x07C0,0x0FE0,0x1FF0,0x3FF8,0x07C0,
  115.     0x07C0,0x07C0,0x0000
  116. };
  117.  
  118.     /* Run dump for down arrow gadget. */
  119.  
  120. USHORT DnMap[22] =
  121. {
  122.     0xFFFE,0xF83E,0xF83E,0xF83E,0xC006,0xE00E,0xF01E,0xF83E,
  123.     0xFC7E,0xFEFE,0xFFFE,
  124.  
  125.     0x0000,0x07C0,0x07C0,0x07C0,0x3FF8,0x1FF0,0x0FE0,0x07C0,
  126.     0x0380,0x0100,0x0000
  127. };
  128.  
  129.     /* Image structures for bool gadgets. */
  130.  
  131. struct Image UpImage =
  132. {
  133.     0,0,
  134.     15,11,2,
  135.     (USHORT *)UpMap,
  136.     0x03,0x00,
  137.     (struct Image *)NULL
  138. };
  139.  
  140. struct Image DnImage =
  141. {
  142.     0,0,
  143.     15,11,2,
  144.     (USHORT *)DnMap,
  145.     0x03,0x00,
  146.     (struct Image *)NULL
  147. };
  148.  
  149.     /* Our default text definitions. */
  150.  
  151. struct TextAttr DefaultAttr[3] =
  152. {
  153.     {(UBYTE *)"topaz.font",8,FS_NORMAL ,FPF_ROMFONT},
  154.     {(UBYTE *)"topaz.font",8,FSF_BOLD  ,FPF_ROMFONT},
  155.     {(UBYTE *)"topaz.font",8,FSF_ITALIC,FPF_ROMFONT}
  156. };
  157.  
  158.     /* Select the "About..." menuitem to get this text. */
  159.  
  160. struct IntuiText AboutTxt[14] =
  161. {
  162.     {3,1,JAM1,8,  4,&DefaultAttr[1],(UBYTE *)"FarPrint v1.5",            &AboutTxt[ 1]},
  163.  
  164.     {2,1,JAM1,8, 16,&DefaultAttr[0],(UBYTE *)"Was  written  by  Olaf 'Olsen'",    &AboutTxt[ 2]},
  165.     {2,1,JAM1,8, 24,&DefaultAttr[0],(UBYTE *)"Barthel   of   MXM   (formerly",    &AboutTxt[ 3]},
  166.     {2,1,JAM1,8, 32,&DefaultAttr[0],(UBYTE *)"Electronic  Design  Hannover).",    &AboutTxt[ 4]},
  167.     {2,1,JAM1,8, 40,&DefaultAttr[0],(UBYTE *)"The  FarPrint package is meant",    &AboutTxt[ 5]},
  168.     {2,1,JAM1,8, 48,&DefaultAttr[0],(UBYTE *)"to be a simple replacement for",    &AboutTxt[ 6]},
  169.     {2,1,JAM1,8, 56,&DefaultAttr[0],(UBYTE *)"the  debug.lib functions which",    &AboutTxt[ 7]},
  170.     {2,1,JAM1,8, 64,&DefaultAttr[0],(UBYTE *)"are  usually  to transmit text",    &AboutTxt[ 8]},
  171.     {2,1,JAM1,8, 72,&DefaultAttr[0],(UBYTE *)"and  other  data to a terminal",    &AboutTxt[ 9]},
  172.     {2,1,JAM1,8, 80,&DefaultAttr[0],(UBYTE *)"connected  to  the serial port",    &AboutTxt[10]},
  173.     {2,1,JAM1,8, 88,&DefaultAttr[0],(UBYTE *)"of the Amiga.",            &AboutTxt[11]},
  174.  
  175.     {0,1,JAM1,8,104,&DefaultAttr[2],(UBYTE *)"(C) Copyright 1989 by...,",        &AboutTxt[12]},
  176.     {0,1,JAM1,8,112,&DefaultAttr[2],(UBYTE *)"MXM (formerly ED Hannover)",        NULL},
  177.  
  178.     {0,1,JAM1,5,  3,&DefaultAttr[0],(UBYTE *)"Understood",                NULL}
  179. };
  180.  
  181.     /* This will become our menu. */
  182.  
  183. struct IntuiText FarIntTxt[6] =
  184. {
  185.     {0,1,JAM2,2,1,&DefaultAttr[0],(UBYTE *)"About FarPrint...      ",NULL},
  186.     {0,1,JAM1,2,1,&DefaultAttr[1],(UBYTE *)"_______________________",NULL},
  187.     {0,1,JAM2,2,1,&DefaultAttr[0],(UBYTE *)"Save Message texts     ",NULL},
  188.     {0,1,JAM2,2,1,&DefaultAttr[0],(UBYTE *)"Pause/Skip             ",NULL},
  189.     {0,1,JAM2,2,1,&DefaultAttr[0],(UBYTE *)"Iconify Window         ",NULL},
  190.     {0,1,JAM2,2,1,&DefaultAttr[0],(UBYTE *)"Quit FarPrint          ",NULL}
  191. };
  192.  
  193.     /* Now transform it into a chain of menu items. */
  194.  
  195. struct MenuItem FarMenuItem[6] =
  196. {
  197.     {&FarMenuItem[1],0, 0,188,10, 86,0,(APTR)&FarIntTxt[0],NULL,'?',NULL,NULL},
  198.     {&FarMenuItem[2],0, 3,188,10,210,0,(APTR)&FarIntTxt[1],NULL,  0,NULL,NULL},
  199.     {&FarMenuItem[3],0,13,188,10, 86,0,(APTR)&FarIntTxt[2],NULL,'S',NULL,NULL},
  200.     {&FarMenuItem[4],0,23,188,10, 86,0,(APTR)&FarIntTxt[3],NULL,'P',NULL,NULL},
  201.     {&FarMenuItem[5],0,33,188,10, 86,0,(APTR)&FarIntTxt[4],NULL,'I',NULL,NULL},
  202.     {NULL,           0,43,188,10, 86,0,(APTR)&FarIntTxt[5],NULL,'Q',NULL,NULL}
  203. };
  204.  
  205.     /* This binds them into a menu. */
  206.  
  207. struct Menu FarMenu = {NULL,0,0,112,0,257,"FarPrint v1.5",&FarMenuItem[0]};
  208.  
  209.     /* Now comes some gadget data. */
  210.  
  211. UBYTE StrInfStr[81],UndoStrInfStr[81];
  212.  
  213. struct StringInfo FarStrInf  = {&StrInfStr[0],&UndoStrInfStr[0],0,81,0,0,0,0,0,NULL,NULL,NULL};
  214. struct PropInfo   FarPropInf = {AUTOKNOB | FREEVERT,0,0,0,MAXBODY,0,0,0,0,0,0};
  215.  
  216. SHORT FarBrdDat[] =
  217. {
  218.     -1,-1,88,-1,88,14,-1,14,
  219.     -1,-1,632,-1,632,8,-1,8,-1,-1,
  220.     -2,-1,633,-1,633,8,-2,8,-2,-1,
  221.     0,0,-639,0,
  222.     0,0,-637,0,
  223. };
  224.  
  225. struct Border FarBrd[5] =
  226. {
  227.     {  0,  0,0,7,0,4,&FarBrdDat[ 0],NULL},
  228.     {  0,  0,1,0,0,5,&FarBrdDat[ 8],&FarBrd[2]},
  229.     {  0,  0,1,0,0,5,&FarBrdDat[18],NULL},
  230.     {639,116,1,0,0,2,&FarBrdDat[28],&FarBrd[4]},
  231.     {638,116,1,0,0,2,&FarBrdDat[32],NULL}
  232. };
  233.  
  234. struct Gadget FarGad[4] =
  235. {
  236.     {&FarGad[1],  4,128,632, 8,GADGHCOMP | GADGHCOMP | GADGDISABLED,RELVERIFY | GADGIMMEDIATE,              STRGADGET ,(APTR)&FarBrd[1],NULL,NULL,NULL,(APTR)&FarStrInf, 0,NULL},
  237.     {&FarGad[2],621, 11, 15,11,GADGIMAGE | GADGHCOMP               ,RELVERIFY | GADGIMMEDIATE,              BOOLGADGET,(APTR)&UpImage,  NULL,NULL,NULL,NULL,             1,NULL},
  238.     {&FarGad[3],621,104, 15,11,GADGIMAGE | GADGHCOMP               ,RELVERIFY | GADGIMMEDIATE,              BOOLGADGET,(APTR)&DnImage,  NULL,NULL,NULL,NULL,             2,NULL},
  239.     {NULL      ,621, 23, 15,80,GADGHNONE                           ,RELVERIFY | GADGIMMEDIATE | FOLLOWMOUSE,PROPGADGET,(APTR)&FarBrd[0],NULL,NULL,NULL,(APTR)&FarPropInf,3,NULL}
  240. };
  241.  
  242. UBYTE DummyString[77];
  243.  
  244.     /* The main window. */
  245.  
  246. struct NewWindow NewWindow =
  247. {
  248.     0,11,
  249.     640,137,
  250.     0,1,
  251.     CLOSEWINDOW | MOUSEMOVE | GADGETUP | GADGETDOWN | MENUPICK | RAWKEY | ACTIVEWINDOW | INACTIVEWINDOW,
  252.     WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG,
  253.     (struct Gadget *)&FarGad[0],
  254.     (struct Image *)NULL,
  255.     (STRPTR)"FarPrint v1.5",
  256.     (struct Screen *)NULL,
  257.     (struct BitMap *)NULL,
  258.     0,0,
  259.     0,0,
  260.     WBENCHSCREEN
  261. };
  262.  
  263.     /* CLI detach stuff. */
  264.  
  265. long  _stack        = 8000;
  266. long  _priority        = 0;
  267. long  _BackGroundIO    = 0;
  268. char *_procname        = "FarPrint v1.5";
  269.  
  270.     /* DeleteMessage(Msg) :
  271.      *
  272.      *    Deletes a custom message structure or replies
  273.      *    it (as approriate).
  274.      */
  275.  
  276. void
  277. DeleteMessage(Msg)
  278. struct FarMessage *Msg;
  279. {
  280.     if(Msg)
  281.     {
  282.             /* This text can be discarded. */
  283.  
  284.         if(Msg -> fm_Text && Msg -> fm_Command == FM_ADDTXT)
  285.             FreeMem(Msg -> fm_Text,strlen(Msg -> fm_Text) +1);
  286.  
  287.             /* Reply port given or not? */
  288.  
  289.         if(Msg -> fm_ExecMessage . mn_ReplyPort)
  290.             ReplyMsg(Msg);
  291.         else
  292.             FreeMem(Msg,sizeof(struct FarMessage));
  293.     }
  294. }
  295.  
  296.     /* SetPropPosition(Value):
  297.      *
  298.      *    Sets the slider position of the proportional
  299.      *    gadget.
  300.      */
  301.  
  302. void
  303. SetPropPosition(Value)
  304. LONG Value;
  305. {
  306.     LONG MaxText = InTextList - 13;
  307.  
  308.     if(MaxText < 1)
  309.         MaxText = 1;
  310.  
  311.     if(Value > MaxText || Value < 0)
  312.         return;
  313.  
  314.     ModifyProp(&FarGad[3],Window,NULL,AUTOKNOB | FREEVERT,0,Value * (MAXPOT / MaxText),0,FarPropInf . VertBody);
  315. }
  316.  
  317.     /* GetPropPosition():
  318.      *
  319.      *    Returns the slider position of the proportional
  320.      *    gadget.
  321.      */
  322.  
  323. LONG
  324. GetPropPosition()
  325. {
  326.     LONG Value,MaxText = InTextList - 13;
  327.  
  328.     if(MaxText < 1)
  329.         MaxText = 1;
  330.  
  331.     Value = FarPropInf . VertPot / (MAXPOT / MaxText);
  332.  
  333.     return(Value);
  334. }
  335.  
  336.     /* DrawText(From,SaveTime):
  337.      *
  338.      *    Draws the list of recorded messages.
  339.      */
  340.  
  341. void
  342. DrawText(From,SaveTime)
  343. LONG From;
  344. BOOL SaveTime;
  345. {
  346.     LONG i;
  347.     char *LineBuff;
  348.  
  349.     static LONG LastPosition = -1;
  350.  
  351.     if(LastPosition == From && SaveTime)
  352.         return;
  353.  
  354.     LastPosition = From;
  355.  
  356.     for(i = 0 ; i < 13 ; i++)
  357.     {
  358.         Move(RPort,4,17 + 8 * i);
  359.  
  360.         if(i + From >= InTextList || !TextList[i])
  361.             LineBuff = "";
  362.         else
  363.             LineBuff = (char *)TextList[i + From];
  364.  
  365.         if(strlen(LineBuff))
  366.             Text(RPort,LineBuff,strlen(LineBuff));
  367.  
  368.         if(strlen(LineBuff) < 77)
  369.             Text(RPort,DummyString,76 - strlen(LineBuff));
  370.     }
  371. }
  372.  
  373.     /* AddText(Message):
  374.      *
  375.      *    Adds a message to the current list of recorded
  376.      *    texts.
  377.      */
  378.  
  379. void
  380. AddText(Message)
  381. STRPTR *Message;
  382. {
  383.     LONG MaxText;
  384.  
  385.         /* Only 128 messages allowed. */
  386.  
  387.     if(InTextList == 128)
  388.     {
  389.         register LONG i;
  390.  
  391.         FreeMem(TextList[0],strlen(TextList[0]) + 1);
  392.  
  393.         for(i = 0 ; i < 127 ; i++)
  394.             TextList[i] = TextList[i + 1];
  395.  
  396.         InTextList = 127;
  397.     }
  398.  
  399.     if(TextList[InTextList] = (STRPTR)AllocMem(strlen(Message) + 1,MEMF_PUBLIC))
  400.     {
  401.         strcpy(TextList[InTextList],Message);
  402.  
  403.         InTextList++;
  404.  
  405.         if((MaxText = InTextList - 13) < 1)
  406.             MaxText = 1;
  407.  
  408.         ModifyProp(&FarGad[3],Window,NULL,AUTOKNOB | FREEVERT,0,FarPropInf . VertPot,0,MAXBODY / MaxText);
  409.  
  410.         if(GetPropPosition() + 13 < InTextList)
  411.             SetPropPosition(GetPropPosition() + 1);
  412.  
  413.         DrawText(GetPropPosition(),FALSE);
  414.     }
  415. }
  416.  
  417.     /* FreeTextList():
  418.      *
  419.      *    Frees the list of recorded messages.
  420.      */
  421.  
  422. void
  423. FreeTextList()
  424. {
  425.     LONG i;
  426.  
  427.     for(i = 0 ; i < InTextList ; i++)
  428.         if(TextList[i])
  429.             FreeMem(TextList[i],strlen(TextList[i] + 1));
  430. }
  431.  
  432.     /* ClearRequest():
  433.      *
  434.      *    Clears the part of the window above the string
  435.      *    gadget.
  436.      */
  437.  
  438. void
  439. ClearRequest()
  440. {
  441.     SetAPen(RPort,0);
  442.     RectFill(RPort,2,117,637,126);
  443.     SetAPen(RPort,1);
  444.  
  445.     Move(RPort,2,124);
  446. }
  447.  
  448.     /* SaveText():
  449.      *
  450.      *    Saves the list of recorded messages to disk. Uses
  451.      *    the ARP FileRequester.
  452.      */
  453.     
  454. void
  455. SaveText()
  456. {
  457.     char *Selection;
  458.     UBYTE *Title = Window -> Title;
  459.  
  460.     if(!InTextList)
  461.         return;
  462.  
  463.     if(Selection = FileRequest(&MyRequest))
  464.     {
  465.         if(Selection[0])
  466.         {
  467.             UBYTE Destination[FCHARS + 1 + MAXPATH];
  468.             LONG DestFile;
  469.  
  470.             strcpy(Destination,Directory);
  471.  
  472.             if(Directory[strlen(Directory) - 1] != ':' && Directory[strlen(Directory) - 1] != '/')
  473.                 strcat(Destination,"/");
  474.  
  475.             strcat(Destination,Filename);
  476.  
  477.             if(DestFile = Open(Destination,MODE_NEWFILE))
  478.             {
  479.                 LONG i;
  480.  
  481.                 for(i = 0 ; i < InTextList ; i++)
  482.                 {
  483.                     if(Write(DestFile,TextList[i],strlen(TextList[i])) < 1)
  484.                         break;
  485.  
  486.                     if(Write(DestFile,"\n",1) < 1)
  487.                         break;
  488.                 }
  489.  
  490.                 Close(DestFile);
  491.  
  492.                 SetWindowTitles(Window,"Message texts saved",-1);
  493.  
  494.                 Delay(TICKS_PER_SECOND * 2);
  495.  
  496.                 SetWindowTitles(Window,Title,-1);
  497.  
  498.                 return;
  499.             }
  500.         }
  501.     }
  502.  
  503.     SetWindowTitles(Window,"Message texts NOT saved!",-1);
  504.  
  505.     Delay(TICKS_PER_SECOND * 1);
  506.  
  507.     SetWindowTitles(Window,Title,-1);
  508. }
  509.  
  510.     /* CloseAll(ReturnCode):
  511.      *
  512.      *    Frees anything we have allocated and quits.
  513.      */
  514.  
  515. void
  516. CloseAll(ReturnCode)
  517. LONG ReturnCode;
  518. {
  519.     FreeTextList();
  520.  
  521.     if(DefaultFont)
  522.         CloseFont(DefaultFont);
  523.  
  524.     if(FarPort)
  525.     {
  526.         struct Message *TmpMessage;
  527.  
  528.         Forbid();
  529.  
  530.         while(TmpMessage = (struct Message *)GetMsg(FarPort))
  531.             DeleteMessage(TmpMessage);
  532.  
  533.         DeletePort(FarPort);
  534.  
  535.         Permit();
  536.     }
  537.  
  538.     if(Window)
  539.     {
  540.         while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  541.             ReplyMsg(Massage);
  542.  
  543.         ClearMenuStrip(Window);
  544.  
  545.         CloseWindow(Window);
  546.     }
  547.  
  548.     if(ArpBase)
  549.         CloseLibrary(ArpBase);
  550.  
  551.     exit(ReturnCode);
  552. }
  553.  
  554.     /* OpenAll():
  555.      *
  556.      *    Sets up everything we need to execute successfully.
  557.      */
  558.  
  559. LONG
  560. OpenAll()
  561. {
  562.     if(!(ArpBase = (struct ArpBase *)OpenLibrary("arp.library",ArpVersion)))
  563.         CloseAll(20);
  564.  
  565.     IntuitionBase    = (struct IntuitionBase *)ArpBase -> IntuiBase;
  566.     GfxBase        = (struct GfxBase *)ArpBase -> GfxBase;
  567.  
  568.     if(!(FarPort = (struct MsgPort *)CreatePort("FarPort",0)))
  569.         CloseAll(20);
  570.  
  571.     if(!(Window = (struct Window *)OpenWindow(&NewWindow)))
  572.         CloseAll(20);
  573.  
  574.     SetMenuStrip(Window,&FarMenu);
  575.  
  576.     if(!(DefaultFont = (struct TextFont *)OpenFont(&DefaultAttr[0])))
  577.         CloseAll(20);
  578.  
  579.     RPort = Window -> RPort;
  580.  
  581.     SetAPen(RPort,1);
  582.     SetBPen(RPort,0);
  583.     SetDrMd(RPort,JAM2);
  584.  
  585.     DrawBorder(RPort,&FarBrd[3],0,0);
  586.  
  587.     SetFont(RPort,DefaultFont);
  588.  
  589.     return(TRUE);
  590. }
  591.  
  592.     /* Iconify():
  593.      *
  594.      *    Rewritten version of Leo Schwab's Iconify routine.
  595.      */
  596.  
  597. Iconify()
  598. {
  599.         /* Bitmap rundump for icon image. */
  600.  
  601.     static USHORT IconMap[184] =
  602.     {
  603.         0x1FFF,0xFFFF,0xFFFF,0xF000,0x3000,0x0000,0x0000,0x1800,
  604.         0x3000,0x0000,0x0000,0x1800,0x31C0,0x0008,0xD001,0x1800,
  605.         0x3080,0x0001,0x0001,0x1800,0x308E,0x73CB,0x938F,0x1800,
  606.         0x3090,0x8A29,0x1451,0x1800,0x3090,0x8A29,0x17D1,0x1800,
  607.         0x3090,0x8A29,0x1411,0x1800,0x31CE,0x7229,0x138F,0x1800,
  608.         0x3000,0x0000,0x0000,0x1800,0x3000,0x0000,0x0000,0x1800,
  609.         0x3078,0x0000,0x0804,0x1800,0x3040,0x0000,0x0004,0x1800,
  610.         0x3041,0xC778,0xEBCE,0x1800,0x3072,0x2845,0x0A24,0x1800,
  611.         0x3042,0x2845,0x0A24,0x1800,0x3042,0x2845,0x0A24,0x1800,
  612.         0x3041,0xE879,0x0A24,0x1800,0x3000,0x0040,0x0000,0x1800,
  613.         0x3000,0x0000,0x0000,0x1800,0x1FFF,0xFFFF,0xFFFF,0xE800,
  614.         0x0000,0x0000,0x0000,0x0000,
  615.  
  616.         0x1000,0x0000,0x0000,0x1000,0x0FFF,0xFFFF,0xFFFF,0xC000,
  617.         0xC000,0x0000,0x0000,0x6000,0xC000,0x0000,0x0000,0x6000,
  618.         0xC700,0x0032,0xE006,0x6000,0xC300,0x0004,0x0000,0x6000,
  619.         0xC32D,0x6596,0x6B2E,0x6000,0xC363,0x34D6,0x6826,0x6000,
  620.         0xC363,0x34D6,0x6BE6,0x6000,0xC221,0x0CD6,0x6860,0x6000,
  621.         0xC7BD,0xECF6,0x6F3E,0x6000,0xC000,0x0000,0x0000,0x6000,
  622.         0xC000,0x0000,0x0000,0x6000,0xC1B0,0x0000,0x3018,0x6000,
  623.         0xC180,0x0000,0x0010,0x6000,0xC185,0x97B2,0xF598,0x6000,
  624.         0xC1AC,0xD19A,0x34D8,0x6000,0xC18C,0xD19A,0x34D8,0x6000,
  625.         0xC18C,0x1186,0x34D8,0x6000,0xC187,0xF1B6,0x3CD8,0x6000,
  626.         0xC000,0x0180,0x0000,0x6000,0xF000,0x0000,0x0000,0x1800,
  627.         0x3FFF,0xFFFF,0xFFFF,0xC000
  628.     };
  629.  
  630.     static struct Image IconImage =
  631.     {
  632.         0,0,
  633.         53,23,2,
  634.         (USHORT *)IconMap,
  635.         0x03,0x00,
  636.         (struct Image *)NULL
  637.     };
  638.  
  639.         /* This is the 'icon' stuff. */
  640.  
  641.     static struct Gadget IconGadget =
  642.     {
  643.         NULL,
  644.         0,0,53,23,
  645.         GADGHNONE | GRELWIDTH | GRELHEIGHT | GADGIMAGE,
  646.         GADGIMMEDIATE,
  647.         WDRAGGING,
  648.         (APTR)&IconImage,
  649.         NULL,NULL,NULL,NULL,
  650.         0,0
  651.     };
  652.  
  653.     static struct NewWindow IconNewWindow =
  654.     {
  655.         0,11,53,23,
  656.         -1,-1,
  657.         GADGETDOWN | INACTIVEWINDOW,
  658.         BORDERLESS | RMBTRAP,
  659.         &IconGadget,
  660.         NULL,NULL,NULL,NULL,
  661.         0,0,0,0,
  662.         WBENCHSCREEN
  663.     };
  664.  
  665.     struct Window *IconWindow;
  666.  
  667.     register struct IntuiMessage *IconMessage;
  668.     LONG Seconds = 0,Micros = 0,CurrentSeconds,CurrentMicros,Class;
  669.  
  670.     ULONG SignalSet;
  671.  
  672.         /* Free some data. */
  673.  
  674.     NewWindow . TopEdge = Window -> TopEdge;
  675.  
  676.     while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  677.         ReplyMsg(Massage);
  678.  
  679.     ClearMenuStrip(Window);
  680.  
  681.     CloseWindow(Window);
  682.  
  683.     Window = NULL;
  684.  
  685.         /* Build the icon. */
  686.  
  687.     if(!(IconWindow = (struct Window *)OpenWindow(&IconNewWindow)))
  688.         goto Finish;
  689.  
  690.     IconWindow -> UserData = (BYTE *)0x49434F4EL;
  691.  
  692.     FOREVER
  693.     {
  694.             /* Wait for the user to reactivate us. */
  695.  
  696.         SignalSet = Wait(1 << IconWindow -> UserPort -> mp_SigBit);
  697.  
  698.         if(IconMessage = (struct IntuiMessage *)GetMsg(IconWindow -> UserPort))
  699.         {
  700.             Class        = IconMessage -> Class;
  701.             CurrentSeconds    = IconMessage -> Seconds;
  702.             CurrentMicros    = IconMessage -> Micros;
  703.  
  704.             ReplyMsg(IconMessage);
  705.  
  706.             if(Class == GADGETDOWN)
  707.             {
  708.                 if(DoubleClick(Seconds,Micros,CurrentSeconds,CurrentMicros))
  709.                     break;
  710.  
  711.                 Seconds    = CurrentSeconds;
  712.                 Micros    = CurrentMicros;
  713.             }
  714.  
  715.                 /* Say, if you dragged an icon, released
  716.                  * it and did so repeatedly, would you
  717.                  * expect the icon to be double-clicked?
  718.                  * Since Workbench icons don't behave that
  719.                  * way we reset the double-click counter
  720.                  * once the icon is released.
  721.                  */
  722.  
  723.             if(Class == INACTIVEWINDOW)
  724.                 Seconds = Micros = 0;
  725.         }
  726.     }
  727.  
  728.         /* Remember icon position. */
  729.  
  730.     IconNewWindow . LeftEdge= IconWindow -> LeftEdge;
  731.     IconNewWindow . TopEdge    = IconWindow -> TopEdge;
  732.  
  733.     CloseWindow(IconWindow);
  734.  
  735.         /* Restore window and display. */
  736.  
  737. Finish:    if(!(Window = (struct Window *)OpenWindow(&NewWindow)))
  738.         CloseAll(20);
  739.  
  740.     RPort = Window -> RPort;
  741.  
  742.     SetAPen(RPort,1);
  743.     SetBPen(RPort,0);
  744.     SetDrMd(RPort,JAM2);
  745.  
  746.     DrawBorder(RPort,&FarBrd[3],0,0);
  747.  
  748.     SetFont(RPort,DefaultFont);
  749.  
  750.     SetMenuStrip(Window,&FarMenu);
  751.  
  752.     DrawText(GetPropPosition(),FALSE);
  753.  
  754.     ClearRequest();
  755.     PrintRequest("- No pending requests -");
  756.  
  757.     if(Pausing)
  758.         SetWindowTitles(Window,"FarPrint v1.5 (pausing)",-1);
  759. }
  760.  
  761.     /* Some stubs, we don't need these routines. */
  762.  
  763. void _cli_parse() {}
  764. void _wb_parse() {}
  765.  
  766. void
  767. main()
  768. {
  769.     ULONG SignalSet;
  770.  
  771.         /* Startup & initialization. */
  772.  
  773.     OpenAll();
  774.  
  775.     setmem(DummyString,76,' ');
  776.     DummyString[76] = 0;
  777.  
  778.     ClearRequest();
  779.     PrintRequest("- No pending requests -");
  780.  
  781.     FOREVER
  782.     {
  783.             /* Wait for something to wake us up. */
  784.  
  785.         SignalSet = Wait(SIG_WINDOW | SIG_PORT);
  786.  
  787. AskPort:    if(!Suspended)
  788.         {
  789.             struct FarMessage *FarMessage;
  790.  
  791.             while(FarMessage = (struct FarMessage *)GetMsg(FarPort))
  792.             {
  793.                 if(Pausing)
  794.                 {
  795.                     DeleteMessage(FarMessage);
  796.  
  797.                     continue;
  798.                 }
  799.  
  800.                     /* Add a text to the list? */
  801.  
  802.                 if(FarMessage -> fm_Command == FM_ADDTXT)
  803.                 {
  804.                     AddText(FarMessage -> fm_Text);
  805.  
  806.                     DeleteMessage(FarMessage);
  807.  
  808.                     continue;
  809.                 }
  810.  
  811.                     /* External caller requests input. */
  812.  
  813.                 ClearRequest();
  814.                 PrintRequest("\"");PrintRequest(FarMessage -> fm_Identifier);PrintRequest("\"");
  815.  
  816.                     /* Text or number required? */
  817.  
  818.                 if(FarMessage -> fm_Command == FM_REQTXT)
  819.                 {
  820.                     PrintRequest(" requests string input.");
  821.                     FarGad[0] . Activation &= ~LONGINT;
  822.                 }
  823.                 else
  824.                 {
  825.                     PrintRequest(" requests numeric input.");
  826.                     FarGad[0] . Activation |= LONGINT;
  827.                 }
  828.  
  829.                     /* Ask user to enter something. */
  830.  
  831.                 OnGadget(&FarGad[0],Window,NULL);
  832.  
  833.                 ActivateWindow(Window);
  834.                 ActivateGadget(&FarGad[0],Window,NULL);
  835.  
  836.                 ReportMouse(FALSE,Window);
  837.  
  838.                 FOREVER
  839.                 {
  840.                     WaitPort(Window -> UserPort);
  841.  
  842.                     if(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  843.                     {
  844.                         ULONG Class = Massage -> Class;
  845.                         struct Gadget *ID = (struct Gadget *)Massage -> IAddress;
  846.  
  847.                         ReplyMsg(Massage);
  848.  
  849.                         if(Class == GADGETUP && ID -> GadgetID == 0)
  850.                             break;
  851.                     }
  852.                 }
  853.  
  854.                 ReportMouse(FALSE,Window);
  855.  
  856.                 strcpy(FarMessage -> fm_Text,StrInfStr);
  857.                 setmem(StrInfStr,81,0);
  858.  
  859.                 FarStrInf . BufferPos = FarStrInf . DispPos = 0;
  860.  
  861.                 OffGadget(&FarGad[0],Window,NULL);
  862.  
  863.                 ClearRequest();
  864.                 PrintRequest("- No pending requests -");
  865.  
  866.                 DeleteMessage(FarMessage);
  867.             }
  868.         }
  869.  
  870.             /* Examine the window. */
  871.  
  872. AskWindow:    while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  873.         {
  874.             ULONG Class = Massage -> Class;
  875.             USHORT Code = Massage -> Code;
  876.             struct Gadget *ID = (struct Gadget *)Massage -> IAddress;
  877.             USHORT MenuNum;
  878.             struct MenuItem *Item;
  879.             LONG Value;
  880.  
  881.             ReplyMsg(Massage);
  882.  
  883.                 /* First attempt to scroll the bar
  884.                  * via keyboard.
  885.                  */
  886.  
  887.             if(Class == RAWKEY)
  888.             {
  889.                 Value = GetPropPosition();
  890.  
  891.                 if(Code == CURSORUP)
  892.                     SetPropPosition(Value - 1);
  893.  
  894.                 if(Code == CURSORDOWN)
  895.                     SetPropPosition(Value + 1);
  896.  
  897.                 DrawText(GetPropPosition(),TRUE);
  898.  
  899.                 continue;
  900.             }
  901.  
  902.                 /* Scroll the bar? */
  903.  
  904.             if(Class == GADGETDOWN && (ID -> GadgetID == 1 || ID -> GadgetID == 2))
  905.             {
  906.                 FOREVER
  907.                 {
  908.                     Value = GetPropPosition();
  909.  
  910.                     if(ID -> GadgetID == 1)
  911.                         SetPropPosition(Value - 1);
  912.  
  913.                     if(ID -> GadgetID == 2)
  914.                         SetPropPosition(Value + 1);
  915.  
  916.                     DrawText(GetPropPosition(),TRUE);
  917.  
  918.                     if(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  919.                     {
  920.                         Class = Massage -> Class;
  921.  
  922.                         ReplyMsg(Massage);
  923.  
  924.                         if(Class == GADGETUP)
  925.                             break;
  926.                     }
  927.                 }
  928.  
  929.                 continue;
  930.             }
  931.  
  932.                 /* Selected a menu item. */
  933.  
  934.             if(Class == MENUPICK)
  935.             {
  936.                 MenuNum = Code;
  937.  
  938.                 while(MenuNum != MENUNULL)
  939.                 {
  940.                     switch(ITEMNUM(MenuNum))
  941.                     {
  942.                         case 0:    Window -> Flags |= RMBTRAP;
  943.                             AutoRequest(Window,&AboutTxt[0],NULL,&AboutTxt[13],NULL,NULL,278,158);
  944.                             Window -> Flags &= ~RMBTRAP;
  945.  
  946.                             goto AskPort;
  947.  
  948.                         case 2:    SaveText();
  949.  
  950.                             goto AskPort;
  951.  
  952.                         case 3:    if(Pausing)
  953.                             {
  954.                                 FarIntTxt[3] . IText    = (UBYTE *)"Pause/Skip             ";
  955.                                 FarMenuItem[3] . Command= 'P';
  956.  
  957.                                 SetWindowTitles(Window,"FarPrint v1.5",-1);
  958.                             }
  959.                             else
  960.                             {
  961.                                 FarIntTxt[3] . IText    = (UBYTE *)"Continue               ";
  962.                                 FarMenuItem[3] . Command= 'C';
  963.  
  964.                                 SetWindowTitles(Window,"FarPrint v1.5 (pausing)",-1);
  965.                             }
  966.  
  967.                             Pausing ^= TRUE;
  968.  
  969.                             goto AskPort;
  970.  
  971.                         case 4:    Iconify();
  972.                             goto AskPort;
  973.  
  974.                         case 5:    CloseAll(0);
  975.                             
  976.                         default:break;
  977.                     }
  978.  
  979.                     Item = (struct MenuItem *)ItemAddress(&FarMenu,MenuNum);
  980.  
  981.                     MenuNum = Item -> NextSelect;
  982.                 }
  983.  
  984.                 continue;
  985.             }
  986.  
  987.                 /* User activated window, queue all
  988.                  * incoming messages.
  989.                  */
  990.  
  991.             if(Class == ACTIVEWINDOW && !Pausing)
  992.             {
  993.                 Suspended = TRUE;
  994.                 SetWindowTitles(Window,"FarPrint v1.5 (suspended)",-1);
  995.  
  996.                 continue;
  997.             }
  998.  
  999.                 /* De-selected our window, continue to
  1000.                  * display messages.
  1001.                  */
  1002.  
  1003.             if(Class == INACTIVEWINDOW && !Pausing)
  1004.             {
  1005.                 Suspended = FALSE;
  1006.                 SetWindowTitles(Window,"FarPrint v1.5",-1);
  1007.  
  1008.                 continue;
  1009.             }
  1010.  
  1011.                 /* Proportional gadget container selected. */
  1012.  
  1013.             if(Class == GADGETDOWN && ID -> GadgetID == 3)
  1014.                 DrawText(GetPropPosition(),TRUE);
  1015.  
  1016.                 /* User drags the scrollbar. */
  1017.  
  1018.             if(Class == MOUSEMOVE)
  1019.                 DrawText(GetPropPosition(),TRUE);
  1020.  
  1021.                 /* Finis... */
  1022.  
  1023.             if(Class == CLOSEWINDOW)
  1024.                 CloseAll(0);
  1025.         }
  1026.     }
  1027. }
  1028.