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