home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 575.lha / DoPro_v1.5 / src.LZH / src / DoPro.c next >
C/C++ Source or Header  |  1991-10-07  |  5KB  |  199 lines

  1. /***************************************************************************/
  2. /*                                       */
  3. /* This magnificient piece of software is real PD, so you do not need to   */
  4. /* send any money to me, but I would like to receive some good sourcecodes */
  5. /* especially for OS2.0 [ amiga, of course ;-) ]               */
  6. /*                                       */
  7. /***************************************************************************/
  8. /*                                       */
  9. /* This program is intended to open a productivity screen instead of       */
  10. /* an interlaced screen, to reduce flicker and to avoid  resyncronisation  */
  11. /* of some multiscan monitors. It is only usefull for amigas equipped with */
  12. /* an ECS Denise and a multiscan monitor. Using productivity with a normal */
  13. /* non-multisync monitor may seriously damage it, and I am not responsible */
  14. /* for any damage while using this program.                   */
  15. /*                                       */
  16. /* Usage :                                   */
  17. /*       Start it with 'DoPro'                       */
  18. /*       to quit and save database, start it a second time           */
  19. /*                                       */
  20. /*    Michael Illgner                            */
  21. /*    Theodorstr. 27                             */
  22. /*    W-4790 Paderborn                           */
  23. /*    Germany                                */
  24. /*    Tel.: 05251/26488 or 05251/60-2331                   */
  25. /*                                       */
  26. /*    email: fillg1@uni-paderborn.de                     */
  27. /*                                       */
  28. /***************************************************************************/
  29. /*                                       */
  30. /*        D O P R O   V1.5                       */
  31. /*                                       */
  32. /***************************************************************************/
  33. /*                                       */
  34. /* BTW. This is my first attempt in writing OS2.0 software           */
  35. /*                                       */
  36. /***************************************************************************/
  37.  
  38. #ifdef DEBUG            /* don't forget to link with ddebug.lib !! */
  39. void DPrintF(char *, ...);
  40. void DPutStr(char *);
  41. #endif
  42.  
  43. #define MyPortName "DoProd.port"
  44.  
  45. long    _stack      = 4000;
  46. char *  _procname    = "DoPro";
  47. long    _priority    = 0;
  48. long    _BackGroundIO    = 0;
  49.  
  50. extern struct IntuitionBase *IntuitionBase = NULL;
  51. extern struct GfxBase        *GfxBase       = NULL;
  52. extern struct GadToolsBase  *GadToolsBase  = NULL;
  53.  
  54. BOOL MayUseProductivity;
  55.  
  56.  
  57. /* Disable SAS/C CTRL/C handling */
  58. void chkabort(void) {}
  59.  
  60. /* dummy message to quit */
  61. static struct Message MyMsg =
  62. {
  63.  {NULL, NULL, NT_MESSAGE, NULL, NULL},
  64.  NULL,
  65.  sizeof(struct Message)
  66. };
  67.  
  68. /* needed to store old OpenScreen */
  69. static struct Screen __regargs *(*OldOpenScreen)(struct NewScreen *);
  70.  
  71. /* a simple requester */
  72. static void MyRequest(char *Text)
  73. {
  74.  struct EasyStruct MyES;
  75.  
  76.  MyES.es_StructSize = sizeof(struct EasyStruct);
  77.  MyES.es_Flags = 0;
  78.  MyES.es_Title = ProgTitle;
  79.  MyES.es_TextFormat = Text;
  80.  MyES.es_GadgetFormat = "Continue";
  81.  
  82.  EasyRequest(IntuitionBase->ActiveWindow, &MyES, NULL, NULL);
  83. }
  84.  
  85. /* a boolean requester */
  86. static BOOL BoolRequest(char *Text)
  87. {
  88.  struct EasyStruct BoolES;
  89.  
  90.  BoolES.es_StructSize = sizeof(struct EasyStruct);
  91.  BoolES.es_Flags = 0;
  92.  BoolES.es_Title = ProgTitle;
  93.  BoolES.es_TextFormat = Text;
  94.  BoolES.es_GadgetFormat = "Yes|No";
  95.  
  96.  return EasyRequest(IntuitionBase->ActiveWindow, &BoolES, NULL, NULL);
  97. }
  98.  
  99. /* open the required libraries */
  100. static void OpenSystem(void)
  101. {
  102.  /* if i can get intuition, i can get graphics too ! ;-) */
  103.  GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37);
  104.  if (!(GadToolsBase = OpenLibrary("gadtools.library", 37)))
  105.  {
  106.   MyRequest("Can't open gadtools.library !");
  107.   exit(10);
  108.  }
  109. }
  110.  
  111. /* close them */
  112. static int CloseSystem(void)
  113. {
  114.  if (GfxBase)        CloseLibrary(GfxBase);
  115.  if (GadToolsBase)  CloseLibrary(GadToolsBase);
  116.  
  117.  return(0);
  118. }
  119.  
  120. /* the new OpenScreen routine */
  121. static struct Screen * __asm __saveds MyOpenScreen(register __a0 struct NewScreen *ns)
  122. {
  123.  ULONG DisplayID;
  124.  
  125.  #if DEBUG
  126.  DPrintF("Screen : %s\n", ns->DefaultTitle);
  127.  #endif
  128.  
  129.  if ((ns->Type & NS_EXTENDED) || (ns->CustomBitMap != NULL))
  130.    return OldOpenScreen(ns);
  131.    /* caller wants special screen ? she gets what she wants */
  132.  else
  133.  {
  134.   DisplayID = CheckScreen(ns);
  135.   return OpenScreenTags(ns,
  136.             SA_DisplayID, DisplayID,
  137.             TAG_DONE
  138.                );
  139.  }
  140. }
  141.  
  142.  
  143.  
  144. void main(void)
  145. {
  146.  struct MsgPort *MyPort;
  147.  struct Message *Msg;
  148.  
  149.  onexit(CloseSystem);
  150.  
  151.  #if DEBUG
  152.  DPrintF("DoPro Start\n");
  153.  #endif
  154.  
  155.  /* you will need OS2.0 to use this program */
  156.  if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37))
  157.  {
  158.   OpenSystem();
  159.  
  160.   /* may i use productivity ? */
  161.   MayUseProductivity = !ModeNotAvailable(VGAPRODUCT_KEY);
  162.  
  163.   /* if this is the second start, send message to myself to quit & restore */
  164.   if (MyPort = FindPort(MyPortName))
  165.   {
  166.    if (BoolRequest("Do you really want to quit DoPro ?")) PutMsg(MyPort, &MyMsg);
  167.   }
  168.   else
  169.   {
  170.    /* install MsgPort */
  171.    if (MyPort = CreatePort(MyPortName, 0))
  172.    {
  173.     /* load database */
  174.     LoadData();
  175.  
  176.     /* patch OpenScreen */
  177.     OldOpenScreen = SetFunction(IntuitionBase, -0xC6, (void *)MyOpenScreen);
  178.  
  179.     /* wait for the end */
  180.     WaitPort(MyPort);
  181.     while (Msg = GetMsg(MyPort)) ReplyMsg(Msg);
  182.     
  183.     /* This's the end, my only friend -- the end */
  184.     DeletePort(MyPort);
  185.  
  186.     /* remove patch */
  187.     SetFunction(IntuitionBase, -0xC6, (void *)OldOpenScreen);
  188.     MyRequest(ProgTitle" removed !");
  189.  
  190.     /* save database */
  191.     SaveData();
  192.    }
  193.   }
  194.  
  195.   /* cleanup */
  196.   CloseLibrary(IntuitionBase);
  197.  }
  198. }
  199.