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