home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d108 / printpop.lha / PrintPop / printpop.c < prev    next >
C/C++ Source or Header  |  1987-10-31  |  19KB  |  577 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /*                                                                         */
  3. /*               PRINTPOP - A "popup" printer setup program                */
  4. /*                                                                         */
  5. /*               by Robbie J Akins, Wellington, NEW ZEALAND                */
  6. /*                                                                         */
  7. /*                            Version 1.0                                  */
  8. /*                            August 1987                                  */
  9. /*                                                                         */
  10. /*  Thanks for help and inspiration for this program must go to:           */
  11. /*                                                                         */
  12. /*      Charles Tyson..................for "Purty" (Fred Fish #66)         */
  13. /*      The Software Distillery........for "PopCLI"                        */
  14. /*      Rob Peck.......................for the examples in RKM             */
  15. /*      Willy Langeveld................for "MXGads" (Fred Fish #52)        */
  16. /*      and especially to Harriet Maybeck Tolly (of TollySoft) and her     */
  17. /*      article in Amazing Computing about Mutual Exclude gadgets.....     */
  18. /*      ...that really helped me to stop tearing my hair out!              */
  19. /*                                                                         */
  20. /*   To compile:  LC:lc1 -iINCLUDE: printpop.c                             */
  21. /*                LC:lc2 -v printpop.c                                     */
  22. /*                                                                         */
  23. /*   To link: Alink with link_printpop                                     */
  24. /*                                                                         */
  25. /*   where "link_printpop" contains: FROM     WBC.o,+*                     */
  26. /*                                   printpop.o                            */
  27. /*                                   TO       PrintPop                     */
  28. /*                                   LIBRARY  lib:lc.lib+lib:amiga.lib     */
  29. /*                                                                         */
  30. /*   SPECIAL NOTE: The way this program has been written (the easy way!)   */
  31. /*                 means that either "printpop.o" (generated by the        */
  32. /*                 compiler) must be 'run through' ATOM, or else the       */
  33. /*                 final executable "printpop" must be run through         */
  34. /*                 FIXHUNK (available on Fred Fish #36) for the program    */
  35. /*                 to run correctly (that is, not crash!) on an Amiga      */
  36. /*                 equipped with expansion memory. Sorry. Maybe the        */
  37. /*                 next version of Lattice C will make this a bit easier!  */
  38. /*                                                                         */
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40.  
  41. #include <exec/types.h>
  42. #include <exec/memory.h>
  43. #include <exec/tasks.h>
  44. #include <exec/execbase.h>
  45. #include <devices/input.h>
  46. #include <devices/printer.h>
  47. #include <intuition/intuition.h>
  48.  
  49. #include <visuals.h>             /* Visual components of program window */
  50.  
  51. /*********************** CONSTANTS **********************/
  52. #define F1_KEY 0x50
  53. #define SIGNON "\x1b[33mPRINTPOP\x1b[0m by Robbie J Akins, Wellington NEW ZEALAND\n"
  54. #define DRAFTBUTTON    1
  55. #define NLQBUTTON    2
  56. #define SETTABBUTTON    3
  57. #define CLEARTABBUTTON    4
  58. #define RESETBUTTON    5
  59. #define TENBUTTON    6
  60. #define TWELVEBUTTON    7
  61. #define FIFTEENBUTTON    8
  62. #define PSBUTTON    9
  63. #define ENLARGEDBUTTON    10
  64. #define LMDOWNBUTTON    11
  65. #define LMUPBUTTON    12
  66. #define RMDOWNBUTTON    13
  67. #define RMUPBUTTON    14
  68.  
  69. /********************** GLOBAL VARIABLES **********************/
  70. struct task          *PopUpTask;
  71. struct Interrupt      handlerStuff;
  72. ULONG                 popupsig;
  73. struct MemEntry       me[20];
  74. struct IntuitionBase *IntuitionBase = NULL;
  75. struct GfxBase       *GfxBase = NULL;
  76. long                  DOSBase = 0;
  77. struct Window        *PopWin;
  78. BOOL                  success;
  79. int                   openError;
  80. union  printerIO {
  81.        struct IOStdReq ios;
  82.        struct IODRPReq iodrp;
  83.        struct IOPrtCmdReq iopc;
  84.        };
  85. union  printerIO     *request;
  86. struct MsgPort       *printerPort;
  87. UBYTE  LeftMargBuf[4];
  88. UBYTE  RightMargBuf[4];
  89. UBYTE  SetMarginsBuffer[12];    /* Buffer for set margins command */
  90. int    LeftMargData    = 15;    /* Initial value of left margin */
  91. int    RightMargData   = 95;    /* Initial value of right margin */
  92. SHORT  LeftOffset;
  93. SHORT  RightOffset;
  94.  
  95. /********************** EXTERNAL ROUTINES **********************/
  96. extern struct MsgPort  *CreatePort();
  97. extern struct IOStdReq *CreateStdIO();
  98. extern void             HandlerInterface();
  99. extern struct task     *FindTask();
  100.  
  101. /************************************************************************
  102. *  The handler subroutine - called through the handler stub
  103. *************************************************************************/
  104. struct InputEvent *myhandler(ev, mydata)
  105.  
  106.    struct InputEvent *ev;      /* and a pointer to a list of events */
  107.    struct MemEntry *mydata[];  /* system will pass me a pointer to my 
  108.                                 * own data space. */
  109.    {
  110.    register struct InputEvent *ep, *laste;
  111.  
  112.    /* scan the list of events to see if "pop-up" key pressed */
  113.    for (ep = ev, laste = NULL; ep != NULL; ep = ep->ie_NextEvent)
  114.       {
  115.       if ((ep->ie_Class == IECLASS_RAWKEY) &&
  116.           (ep->ie_Code  == F1_KEY)     &&
  117.           (ep->ie_Qualifier & IEQUALIFIER_LCOMMAND))
  118.          {
  119.          /* Able to handle this event so take it off the chain */
  120.          if (laste == NULL)
  121.             ev = ep->ie_NextEvent;
  122.          else
  123.             laste->ie_NextEvent = ep->ie_NextEvent;
  124.          /* Signal to "pop-up" task */
  125.          Signal(PopUpTask, popupsig);
  126.          }
  127.       else
  128.          laste = ep;
  129.       }
  130.  
  131.    /* pass on the pointer to the event */
  132.    return(ev);
  133.    }
  134.  
  135. /************************************************************************
  136. * The main program to do the printpop stuff
  137. *************************************************************************/
  138. void _main()
  139. {
  140. int    looping;
  141. ULONG  sig,mclass;
  142. LONG   GadPos;
  143. struct Gadget        *maddress;
  144. struct MsgPort       *inputDevPort;
  145. struct IOStdReq      *inputRequestBlock;
  146. struct IntuiMessage  *mesg;
  147. struct RastPort      *ThisRastPort;
  148.  
  149.    PopUpTask = FindTask(0);
  150.    sig = Output();
  151.    Write(sig, SIGNON, sizeof(SIGNON));
  152.  
  153.    SetTaskPri( PopUpTask, 20);
  154.  
  155.    if ((inputDevPort = CreatePort(0,0)) == NULL) /* for input device */
  156.       goto abort0;
  157.  
  158.    if ((inputRequestBlock = CreateStdIO(inputDevPort)) == 0)
  159.       goto abort;
  160.  
  161.    if ((sig = AllocSignal(-1)) == -1)
  162.       goto abort;
  163.  
  164.    popupsig = 1 << sig;
  165.  
  166.    if ((GfxBase = (struct GfxBase *)
  167.                   OpenLibrary("graphics.library", 33)) == NULL)
  168.       goto abort;
  169.  
  170.    if ((IntuitionBase = (struct IntuitionBase *)
  171.                         OpenLibrary("intuition.library", 33)) == NULL)
  172.       goto abort;
  173.  
  174.    handlerStuff.is_Data = (APTR)&me[0];    /* address of handler data area */
  175.    handlerStuff.is_Code = HandlerInterface;/* addr of handler entry point  */
  176.    handlerStuff.is_Node.ln_Pri = 51;       /* set the priority 1 step higher
  177.                                             than Intuition so that handler
  178.                                             enters chain ahead of Intuition*/
  179.  
  180.    if (OpenDevice("input.device",0,inputRequestBlock,0))
  181.       goto abort;
  182.  
  183.    inputRequestBlock->io_Command = IND_ADDHANDLER;
  184.    inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  185.  
  186.    DoIO(inputRequestBlock);
  187.  
  188.  
  189.    for(;;)         /* FOREVER */
  190.       {
  191.       sig = Wait( popupsig );
  192.  
  193.       if (sig & popupsig)
  194.          {
  195. /*=========================================================================*/
  196.  
  197. WBenchToFront();
  198.  
  199. if((PopWin=(struct Window *) make_window()) == NULL) /* Open window */
  200.     goto CleanUp;
  201.  
  202. /* Draw Borders and Intuitexts in window */
  203.  
  204. ThisRastPort = PopWin -> RPort;
  205. DrawBorder(ThisRastPort,&QualityBorder,0,0); /* Draw boxes around gadgets */
  206. PrintIText(ThisRastPort,&QualityText,0,0);   /* Write titles above gadgets */
  207.  
  208. /* Convert values of margins into strings for IntuiTexts */
  209.  
  210. LeftOffset = IntToText(LeftMargData,LeftMargBuf);
  211. RightOffset = IntToText(RightMargData,RightMargBuf);
  212. LeftMargText.IText = &LeftMargBuf[0];
  213. RightMargText.IText = &RightMargBuf[0];
  214. PrintIText(ThisRastPort,&LeftMargText,LeftOffset,0); /* Print left marg value */
  215. PrintIText(ThisRastPort,&RightMargText,RightOffset,0);/* Print rgt marg value */
  216.  
  217. /* Set up IDCMP read loop and handle events */
  218.  
  219. looping = TRUE;
  220. while (looping)
  221. {
  222. WaitPort(PopWin->UserPort);
  223. while((mesg=(struct IntuiMessage *) GetMsg(PopWin->UserPort))!=NULL)
  224.     {
  225.     mclass = mesg->Class;
  226.     maddress = (struct Gadget *)mesg->IAddress;
  227.     ReplyMsg(mesg);
  228.     
  229.     if(mclass == CLOSEWINDOW) looping = FALSE;
  230.     if(mclass == GADGETDOWN)
  231.         {
  232.         switch (maddress->GadgetID)
  233.         {
  234.         case DRAFTBUTTON:
  235.             MXGads(PopWin,&DraftGadget,&NLQGadget,
  236.                 &NULLGadget1,&NULLGadget2);
  237.             break;
  238.         case NLQBUTTON:
  239.             MXGads(PopWin,&NLQGadget,&DraftGadget,
  240.                 &NULLGadget1,&NULLGadget2);
  241.             break;
  242.         case SETTABBUTTON:
  243.             MXGads(PopWin,&SetTabGadget,&ClearTabGadget,
  244.                 &NULLGadget1,&NULLGadget2);
  245.             break;
  246.         case CLEARTABBUTTON:
  247.             MXGads(PopWin,&ClearTabGadget,&SetTabGadget,
  248.                 &NULLGadget1,&NULLGadget2);
  249.             break;
  250.         case RESETBUTTON:
  251.             /* "Ghost" all gadgets on Reset */
  252.             GadPos = RemoveGList(PopWin,&RightUpGadget,14L);
  253.             ClearTabGadget.Flags ^= GADGDISABLED;
  254.             SetTabGadget.Flags ^= GADGDISABLED;
  255.             NLQGadget.Flags ^= GADGDISABLED;
  256.             DraftGadget.Flags ^= GADGDISABLED;
  257.             RightUpGadget.Flags ^= GADGDISABLED;
  258.             RightDownGadget.Flags ^= GADGDISABLED;
  259.             LeftUpGadget.Flags ^= GADGDISABLED;
  260.             LeftDownGadget.Flags ^= GADGDISABLED;
  261.             EnlargedGadget.Flags ^= GADGDISABLED;
  262.             
  263.             if((EnlargedGadget.Flags & SELECTED) != SELECTED)
  264.                 PSGadget.Flags ^= GADGDISABLED;
  265.             
  266.             FifteenGadget.Flags ^= GADGDISABLED;
  267.             TwelveGadget.Flags ^= GADGDISABLED;
  268.             TenGadget.Flags ^= GADGDISABLED;
  269.             AddGList(PopWin,&RightUpGadget,GadPos,14L,(LONG)NULL);
  270.             RefreshGList(&RightUpGadget,PopWin,(LONG)NULL,14L);
  271.             break;
  272.         case TENBUTTON:
  273.             MXGads(PopWin,&TenGadget,&TwelveGadget,
  274.                 &FifteenGadget,&PSGadget);
  275.             break;
  276.         case TWELVEBUTTON:
  277.             MXGads(PopWin,&TwelveGadget,&TenGadget,
  278.                 &FifteenGadget,&PSGadget);
  279.             break;    
  280.         case FIFTEENBUTTON:
  281.             MXGads(PopWin,&FifteenGadget,&TwelveGadget,
  282.                 &TenGadget,&PSGadget);
  283.             break;
  284.         case PSBUTTON:
  285.             MXGads(PopWin,&PSGadget,&TwelveGadget,
  286.                 &FifteenGadget,&TenGadget);
  287.             break;
  288.         case ENLARGEDBUTTON:
  289.             /* "Ghost" PS pitch gadget on Enlarged */
  290.             /* If PS selected, force to 10 pitch selection*/
  291.             if ((PSGadget.Flags & SELECTED) == SELECTED)
  292.                 MXGads(PopWin,&TenGadget,&TwelveGadget,
  293.                     &FifteenGadget,&PSGadget);
  294.             GadPos = RemoveGList(PopWin,&PSGadget,1L);
  295.             PSGadget.Flags ^= GADGDISABLED;
  296.             AddGList(PopWin,&PSGadget,GadPos,1L,(LONG)NULL);
  297.             RefreshGList(&PSGadget,PopWin,(LONG)NULL,1L);
  298.             break;
  299.         case LMDOWNBUTTON:
  300.             /* Decrement value of left margin */
  301.             if(LeftMargData > 1)
  302.             {
  303.             LeftMargData--;
  304.             LeftOffset = IntToText(LeftMargData,LeftMargBuf);
  305.             LeftMargText.IText = &LeftMargBuf[0];
  306.             PrintIText(ThisRastPort,&BlankText,238,68);
  307.             PrintIText(ThisRastPort,&LeftMargText,LeftOffset,0);
  308.             }
  309.             break;
  310.         case LMUPBUTTON:
  311.             /* Increment value of left margin */
  312.             if(LeftMargData < 998)
  313.             {
  314.             LeftMargData++;
  315.             LeftOffset = IntToText(LeftMargData,LeftMargBuf);
  316.             LeftMargText.IText = &LeftMargBuf[0];
  317.             PrintIText(ThisRastPort,&BlankText,238,68);
  318.             PrintIText(ThisRastPort,&LeftMargText,LeftOffset,0);
  319.             }
  320.             break;    
  321.         case RMDOWNBUTTON:
  322.             /* Decrement value of right margin */
  323.             if(RightMargData > 1)
  324.             {
  325.             RightMargData--;
  326.             RightOffset = IntToText(RightMargData,RightMargBuf);
  327.             RightMargText.IText = &RightMargBuf[0];
  328.             PrintIText(ThisRastPort,&BlankText,322,68);
  329.             PrintIText(ThisRastPort,&RightMargText,RightOffset,0);
  330.             }
  331.             break;
  332.         case RMUPBUTTON:
  333.             /* Increment value of right margin */
  334.             if(RightMargData < 998)
  335.             {
  336.             RightMargData++;
  337.             RightOffset = IntToText(RightMargData,RightMargBuf);
  338.             RightMargText.IText = &RightMargBuf[0];
  339.             PrintIText(ThisRastPort,&BlankText,322,68);
  340.             PrintIText(ThisRastPort,&RightMargText,RightOffset,0);
  341.             }
  342.             break;
  343.         }
  344.         }
  345.     }
  346. }
  347.  
  348. CloseWindow(PopWin); /* Close window on way out */
  349.  
  350. success = FALSE;
  351. printerPort = (struct MsgPort *)CreatePort("HelloPrinter",0);
  352. if(printerPort == NULL) goto ForgetIt;
  353.  
  354. request = (union printerIO *)CreateExtIO(printerPort,sizeof(union printerIO));
  355. if(request == NULL) goto ForgetIt;
  356.  
  357. openError = OpenPrinter(request);
  358. if(openError) goto ForgetIt;
  359. success = TRUE;
  360.  
  361. /* Now execute appropriate printer commands */
  362.  
  363. if((ResetGadget.Flags & SELECTED) == SELECTED)
  364.     PrintString(request,"\x1b#1"); /* aRIN command */
  365. else
  366.     {
  367.     if((NLQGadget.Flags & SELECTED) == SELECTED)
  368.         PrintString(request,"\x1b[2\x22z"); /* aDEN2 command */
  369.     else
  370.         PrintString(request,"\x1b[1\x22z"); /* aDEN1 command */
  371.     /* First "reset" the printer to normal (10) pich */
  372.         PrintString(request,"\x1b[0w"); /* aSHORP0 command */
  373.     if((FifteenGadget.Flags & SELECTED) == SELECTED)
  374.         PrintString(request,"\x1b[4w"); /* aSHORP4 command */
  375.     if((TwelveGadget.Flags & SELECTED) == SELECTED)
  376.         PrintString(request,"\x1b[2w"); /*aSHORP2 command */
  377.     if((PSGadget.Flags & SELECTED) == SELECTED)
  378.         PrintString(request,"\x1b[2p"); /* aPROP2 command */
  379.     else
  380.         PrintString(request,"\x1b[1p"); /* aPROP1 command */
  381.     if((EnlargedGadget.Flags & SELECTED) == SELECTED)
  382.         PrintString(request,"\x1b[6w"); /* aSHORP6 command */
  383.     else
  384.         PrintString(request,"\x1b[5w"); /* aSHORP5 command */
  385.  
  386. /* Set left & right margins using ESC [ n1 ; n2 s */
  387.  
  388.     strcpy(SetMarginsBuffer,"\x1b[");
  389.     strcat(SetMarginsBuffer,LeftMargBuf);
  390.     strcat(SetMarginsBuffer,";");
  391.     strcat(SetMarginsBuffer,RightMargBuf);
  392.     strcat(SetMarginsBuffer,"s");
  393.     PrintString(request,SetMarginsBuffer);
  394.  
  395.     if((SetTabGadget.Flags & SELECTED) == SELECTED)
  396.         PrintString(request,"\x1b#5"); /* aTBSALL command */
  397.     else
  398.         PrintString(request,"\x1b#4");/* aTBCALL command */
  399.     }
  400. PrintString(request,"\x0d"); /* Terminating C/R required by some printers */
  401.  
  402. goto CleanUp; /* Exit gracefully */
  403.  
  404. ForgetIt:
  405.     Apologise("Sorry, but unable to send the",
  406.           "control codes that you requested",
  407.           "to the printer. Maybe in use?");
  408. CleanUp:
  409.     if(success)     ClosePrinter(request);
  410.     if(printerPort) DeletePort(printerPort);
  411.     if(request)     DeleteExtIO(request);
  412.  
  413.  
  414. /*=========================================================================*/
  415.           }
  416.  
  417.       } /* END OF FOREVER LOOP */
  418.  
  419. abort:
  420.    if (IntuitionBase != NULL)
  421.       CloseLibrary(IntuitionBase);
  422.  
  423.    if (GfxBase != NULL)
  424.       CloseLibrary(GfxBase);
  425.  
  426.    DeletePort(inputDevPort);
  427.  
  428. abort0:
  429.    XCEXIT(-1);
  430. }
  431.  
  432. /************************************************************************
  433. *   Function to open window
  434. *************************************************************************/
  435.  
  436. make_window()
  437. {
  438. struct NewWindow NewWindow;
  439.  
  440.     NewWindow.LeftEdge=0;
  441.     NewWindow.TopEdge=0;
  442.     NewWindow.Width=402;
  443.     NewWindow.Height=103;
  444.     NewWindow.DetailPen=0;
  445.     NewWindow.BlockPen=1;
  446.     NewWindow.IDCMPFlags= CLOSEWINDOW | GADGETDOWN;
  447.     NewWindow.Flags= ACTIVATE | WINDOWDRAG | WINDOWDEPTH |
  448.                          WINDOWCLOSE | NOCAREREFRESH | GIMMEZEROZERO;
  449.     NewWindow.FirstGadget=&RightUpGadget;
  450.     NewWindow.CheckMark=NULL;
  451.     NewWindow.Title="PRINTPOP - Printer Setup Utility";
  452.     NewWindow.Screen=NULL;
  453.     NewWindow.BitMap=NULL;
  454.     NewWindow.MinWidth=0;
  455.     NewWindow.MinHeight=0;
  456.     NewWindow.MaxWidth=0;
  457.     NewWindow.MaxHeight=0;
  458.     NewWindow.Type=WBENCHSCREEN;
  459.  
  460.     return(OpenWindow(&NewWindow));
  461. }
  462.  
  463. /********************************************************************
  464. *   This routine fakes mutual-exclude of four gadgets
  465. ********************************************************************/
  466. MXGads(win,gad1,gad2,gad3,gad4)
  467. struct Window *win;
  468. struct Gadget *gad1,*gad2,*gad3,*gad4;
  469. {
  470. LONG GadNumber1,GadNumber2,GadNumber3,GadNumber4;
  471.  
  472.     GadNumber1 = RemoveGList(win,gad1,1L);
  473.     GadNumber2 = RemoveGList(win,gad2,1L);
  474.     GadNumber3 = RemoveGList(win,gad3,1L);
  475.     GadNumber4 = RemoveGList(win,gad4,1L);
  476.  
  477.     gad1->Flags |= SELECTED; /* FORCE TO BE SELECTED! */
  478.     if((gad2->Flags & SELECTED) == SELECTED) (gad2->Flags ^= SELECTED);
  479.     if((gad3->Flags & SELECTED) == SELECTED) (gad3->Flags ^= SELECTED);
  480.     if((gad4->Flags & SELECTED) == SELECTED) (gad4->Flags ^= SELECTED);
  481.  
  482.     AddGList(win,gad4,GadNumber4,1L,(LONG)NULL);        
  483.     RefreshGList(gad4,win,(LONG)NULL,1L);
  484.     AddGList(win,gad3,GadNumber3,1L,(LONG)NULL);
  485.     RefreshGList(gad3,win,(LONG)NULL,1L);
  486.     AddGList(win,gad2,GadNumber2,1L,(LONG)NULL);
  487.     RefreshGList(gad2,win,(LONG)NULL,1L);
  488.     AddGList(win,gad1,GadNumber1,1L,(LONG)NULL);
  489.     RefreshGList(gad1,win,(LONG)NULL,1L);
  490. }
  491. /************************************************************************
  492. *      Printersupport routines from 1.1 Rom Kernel manual
  493. *************************************************************************/
  494.  
  495. /* OPEN THE PRINTER */
  496. int
  497. OpenPrinter(request)
  498.    union printerIO *request;
  499.       {
  500.       return(OpenDevice("printer.device",0,request,0));
  501.       }
  502.  
  503. /* CLOSE THE PRINTER */
  504. int
  505. ClosePrinter(request)
  506.    union printerIO *request;
  507.       {
  508.       CloseDevice(request);
  509.       return(0);
  510.       }
  511.  
  512. /* SEND NULL TERMINATED STRING TO PRINTER */
  513. int
  514. PrintString(request,string)
  515.    union printerIO *request;
  516.     char *string;
  517.     {
  518.     request->ios.io_Command = CMD_WRITE;
  519.     request->ios.io_Data = (APTR)string;
  520.     request->ios.io_Length = -1;
  521.     return(DoIO(request));
  522.     }
  523.     
  524. /************************************************************************
  525. *      Raise an autorequester with (up to) three lines of text
  526. *************************************************************************/
  527.  
  528. Apologise (line1, line2, line3)
  529. UBYTE  *line1, *line2, *line3;
  530.  
  531. {
  532.     Sorry[0].IText = line1;
  533.     Sorry[1].IText = line2;
  534.     Sorry[2].IText = line3;
  535.     AutoRequest (NULL, &Sorry, NULL, &Proceed,  0, 0, 300, 66);
  536. }
  537. /************************************************************************
  538. *      Convert margin value into text for IntuiText
  539. *  (returns value to displace text string by for "good" appearance)
  540. *************************************************************************/
  541.  
  542. IntToText(n,string)
  543. int    n;
  544. UBYTE *string;
  545.  
  546. {
  547. int displace; /* Amount to displace display of text by */
  548.  
  549.     string[0] = n/100 +'0';
  550.     if (string[0] == '0')
  551.         {
  552.         string[0] = (n%100)/10 + '0';
  553.         if (string[0] == '0')
  554.             {
  555.             string[0] = (n%100)%10 + '0';
  556.             string[1] = '\0';
  557.             displace = 8;
  558.             }
  559.         else
  560.             {
  561.             string[1] = (n%100)%10 + '0';
  562.             string[2] = '\0';
  563.             displace = 4;
  564.             }
  565.         }
  566.     else
  567.         {
  568.         string[1] =  (n%100)/10 + '0';
  569.         string[2] =  (n%100)%10 + '0';
  570.         string[3] = '\0';
  571.         displace = 0;
  572.         }
  573.  
  574.     return(displace);
  575. }
  576.  
  577.