home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 563.lha / Request_v1.03 / Request.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-25  |  5.8 KB  |  220 lines

  1. /*
  2.  *  Request.c - open an "EasyRqeuester()" from script files
  3.  *
  4.  *  PUBLIC DOMAIN
  5.  *
  6.  *  by Stefan Sticht
  7.  *
  8.  *  V1.00             Stefan Sticht initial release
  9.  *  V1.01             Stefan Sticht using cres.o for residentability
  10.  *  V1.02 08 Sep 1991 Stefan Sticht added options "defpubscreen", "frontpubscreen"
  11.  *                                  renamed option "screen" in "pubscreen"
  12.  *  V1.03 16 Sep 1991 Stefan Sticht removed error in lockfrontpubscr()
  13.  */
  14.  
  15. #define VERSION "V1.03"
  16.  
  17. #include <stdlib.h>
  18. #include <intuition/intuition.h>
  19. #include <intuition/intuitionbase.h>
  20.  
  21. #include <clib/dos_protos.h>
  22. #include <pragmas/dos_pragmas.h>
  23. #include <clib/exec_protos.h>
  24. #include <pragmas/exec_pragmas.h>
  25. #include <clib/intuition_protos.h>
  26. #include <pragmas/intuition_pragmas.h>
  27.  
  28. struct Screen *lockfrontpubscr(void);
  29.  
  30. /*
  31.  *  some SAS/C specularities, change for other compilers!
  32.  */
  33. #ifdef __SASC
  34. extern struct Library *DOSBase; /* Library base pointer from startup code */
  35. extern struct Library *SysBase; /* Library base pointer from startup code */
  36. void chkabort(void) {}          /* disable Ctrl-C detect */
  37. #endif
  38.  
  39. #define PROGRAMTITLE "Request"
  40.  
  41. /*
  42.  *  a string, which will be found by Version
  43.  */
  44. char version[] ="\0$VER: " PROGRAMTITLE " " VERSION;
  45.  
  46. struct IntuitionBase *IntuitionBase;
  47.  
  48. /*
  49.  *  dummy window, we have to open
  50.  */
  51. struct NewWindow dummywindow = {
  52.     0, 0,
  53.     1, 1,
  54.     -1, -1,
  55.     0l,
  56.     BORDERLESS | BACKDROP | SIMPLE_REFRESH,
  57.     NULL,
  58.     NULL,
  59.     NULL,
  60.     NULL,
  61.     NULL,
  62.     0, 0,
  63.     0, 0,
  64.     CUSTOMSCREEN
  65. };
  66.  
  67. struct EasyStruct textreq = {
  68.     sizeof (struct EasyStruct), /* ULONG es_StructSize      */
  69.     0l,                         /* ULONG es_Flags           */
  70.     NULL,                       /* UBYTE *es_Title          */
  71.     NULL,                       /* UBYTE *es_TextFormat     */
  72.     NULL,                       /* UBYTE *es_GadgetFormat   */
  73.     };
  74.  
  75. #define TEMPLATE "Text/A,Title/K,Gadgets/K,PubScreen/K,DefaultPubScreen/S,FrontPubScreen/S"
  76. #define OPT_TEXT            0
  77. #define OPT_TITLE           1
  78. #define OPT_GADGETS         2
  79. #define OPT_PUBSCREEN       3
  80. #define OPT_DEFPUBSCREEN    4
  81. #define OPT_FRONTPUBSCREEN  5
  82. #define OPT_COUNT           6
  83.  
  84. /*
  85.  *  this array will be filled by ReadArgs()
  86.  */
  87. long options[OPT_COUNT];
  88.  
  89. struct Screen *lockfrontpubscr(void)
  90. {
  91.     struct Screen *scr;
  92.     struct Screen *pubscr = NULL;
  93.     struct List *pslist;
  94.     struct PubScreenNode *psnode;
  95.     unsigned long lock;
  96.     unsigned short screentype;
  97.  
  98.     lock = LockIBase(0l);
  99.  
  100.     if (scr = IntuitionBase->FirstScreen) {
  101.  
  102.         screentype = scr->Flags & SCREENTYPE;
  103.  
  104.         UnlockIBase(lock);
  105.  
  106.         if (screentype == PUBLICSCREEN || screentype == WBENCHSCREEN) {
  107.  
  108.             if (pslist = LockPubScreenList()) {
  109.  
  110.                 for (psnode = (struct PubScreenNode *)pslist->lh_Head;
  111.                      psnode->psn_Node.ln_Succ && (psnode->psn_Screen != scr);
  112.                      psnode = (struct PubScreenNode *)psnode->psn_Node.ln_Succ);
  113.  
  114.                 if (psnode && (psnode->psn_Screen == scr) && !(psnode->psn_Flags & PSNF_PRIVATE)) {
  115.  
  116.                     pubscr = LockPubScreen(psnode->psn_Node.ln_Name);
  117.  
  118.                     }
  119.  
  120.                 UnlockPubScreenList();
  121.  
  122.                 }
  123.  
  124.             }
  125.  
  126.         }
  127.  
  128.     else UnlockIBase(lock);
  129.  
  130.     return(pubscr);
  131. }
  132.  
  133. void _main(char *line)
  134. {
  135.     struct RDArgs *args;
  136.     struct Screen *scr = NULL;
  137.     struct Window *win;
  138.     char *screen = NULL;
  139.     long rc;
  140.     unsigned short defpubscreen = TRUE;
  141.  
  142.     if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37l)) {
  143.  
  144.         if (args = ReadArgs((UBYTE *)TEMPLATE, options, NULL)) {
  145.  
  146.             if (options[OPT_TITLE])   textreq.es_Title = (UBYTE *)options[OPT_TITLE];
  147.             if (options[OPT_GADGETS]) textreq.es_GadgetFormat = (UBYTE *)options[OPT_GADGETS];
  148.             else textreq.es_GadgetFormat = "Ok";
  149.             if (options[OPT_TEXT])    textreq.es_TextFormat = (UBYTE *)options[OPT_TEXT];
  150.             if (options[OPT_PUBSCREEN]) {
  151.                 screen = (char *)options[OPT_PUBSCREEN];
  152.                 defpubscreen = FALSE;
  153.                 }
  154.             if (options[OPT_DEFPUBSCREEN]) defpubscreen = TRUE;
  155.  
  156.             /*
  157.              *  try to lock a screen according to switches
  158.              */
  159.             if ((options[OPT_FRONTPUBSCREEN] && (scr = lockfrontpubscr())) ||
  160.                 (!scr && screen && *screen && (scr = LockPubScreen(screen))) ||
  161.                 (!scr && defpubscreen && (scr = LockPubScreen(NULL)))) {
  162.  
  163.                 dummywindow.Screen = scr;
  164.                 /*
  165.                  *  try to open visitor window
  166.                  */
  167.                 win = OpenWindow(&dummywindow);
  168.                 /*
  169.                  *  now open the requester (win may be NULL)
  170.                  */
  171.                 rc = EasyRequestArgs(win, &textreq, NULL, NULL);
  172.                 /*
  173.                  *  don't forget closing the window
  174.                  */
  175.                 if (win) CloseWindow(win);
  176.                 /*
  177.                  *  now unlock the screen
  178.                  */
  179.                 UnlockPubScreen(NULL, scr);
  180.                 }
  181.  
  182.             else {
  183.                 /*
  184.                  * public screen not found
  185.                  */
  186.                 PutStr("Can't find or lock screen!\n");
  187.                 rc = 20l;
  188.                 }
  189.  
  190.             }
  191.  
  192.         else {
  193.             /*
  194.              * error parsing options
  195.              */
  196.             PutStr("wrong number of arguments\n");
  197.             rc = 40l;
  198.             }
  199.  
  200.         /*
  201.          *  free arguments and close the lib
  202.          */
  203.         FreeArgs(args);
  204.         CloseLibrary((struct Library *)IntuitionBase);
  205.  
  206.         }
  207.  
  208.     else {
  209.         /*
  210.          *  we really need intuition lib
  211.          *
  212.          *  don't use PutStr() here, because dos.library could be < v36
  213.          */
  214.         Write(Output(), "Can't open intuition.library V37+!\n", 35l);
  215.         rc = 30l;
  216.         }
  217.  
  218.     exit(rc);
  219. }
  220.