home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 532.lha / Request / Request.c < prev    next >
C/C++ Source or Header  |  1991-07-10  |  4KB  |  168 lines

  1. /*
  2.  *  Request.c - open an "EasyRqeuester()" from script files
  3.  *
  4.  *  PUBLIC DOMAIN
  5.  *
  6.  *  by Stefan Sticht
  7.  *
  8.  *  V1.00 initial release
  9.  */
  10.  
  11. #define VERSION "V1.00"
  12.  
  13. #include <stdlib.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <clib/dos_protos.h>
  17. #include <pragmas/dos_pragmas.h>
  18. #include <clib/exec_protos.h>
  19. #include <pragmas/exec_pragmas.h>
  20. #include <clib/intuition_protos.h>
  21. #include <pragmas/intuition_pragmas.h>
  22.  
  23. /*
  24.  *  some SAS/C specularities, change for other compilers!
  25.  */
  26. #ifdef __SASC
  27. extern struct Library *DOSBase; /* Library base pointer from startup code */
  28. extern struct Library *SysBase; /* Library base pointer from startup code */
  29. void chkabort(void) {}          /* disable Ctrl-C detect */
  30. #endif
  31.  
  32. #define PROGRAMTITLE "Request"
  33.  
  34. /*
  35.  *  a string, which will be found by Version
  36.  */
  37. char version[] ="\0$VER: " PROGRAMTITLE " " VERSION;
  38.  
  39. #define USAGE "Usage: Request <text> [TITLE <title>] "\
  40.               "[GADGETS <gad1|gad2|gad3|...>] [Screen <publicscreenname>]"
  41.  
  42. struct Library *IntuitionBase;
  43.  
  44. /*
  45.  *  dummy window, we have to open
  46.  */
  47. struct NewWindow dummywindow = {
  48.     0, 0,
  49.     1, 1,
  50.     -1, -1,
  51.     0l,
  52.     BORDERLESS | BACKDROP | SIMPLE_REFRESH,
  53.     NULL,
  54.     NULL,
  55.     NULL,
  56.     NULL,
  57.     NULL,
  58.     0, 0,
  59.     0, 0,
  60.     CUSTOMSCREEN
  61. };
  62.  
  63. struct EasyStruct textreq = {
  64.     sizeof (struct EasyStruct), /* ULONG es_StructSize      */
  65.     0l,                         /* ULONG es_Flags           */
  66.     NULL,                       /* UBYTE *es_Title          */
  67.     NULL,                       /* UBYTE *es_TextFormat     */
  68.     NULL,                       /* UBYTE *es_GadgetFormat   */
  69.     };
  70.  
  71. #define TEMPLATE "Text/A,Title/K,Gadgets/K,Screen/K"
  72. #define OPT_TEXT    0
  73. #define OPT_TITLE   1
  74. #define OPT_GADGETS 2
  75. #define OPT_SCREEN  3
  76. #define OPT_COUNT   4
  77.  
  78. /*
  79.  *  this array will be filled by ReadArgs()
  80.  */
  81. long options[OPT_COUNT];
  82.  
  83. void _main(char *line)
  84. {
  85.     struct RDArgs *args;
  86.     struct Screen *scr;
  87.     struct Window *win = NULL;
  88.     char *screen = NULL;
  89.     long rc = 0l;
  90.  
  91.     if (IntuitionBase = OpenLibrary("intuition.library", 37l)) {
  92.  
  93.         if (args = ReadArgs((UBYTE *)TEMPLATE, options, NULL)) {
  94.  
  95.             if (options[OPT_TITLE])   textreq.es_Title = (UBYTE *)options[OPT_TITLE];
  96.             if (options[OPT_GADGETS]) textreq.es_GadgetFormat = (UBYTE *)options[OPT_GADGETS];
  97.             else textreq.es_GadgetFormat = "Ok";
  98.             if (options[OPT_TEXT])    textreq.es_TextFormat = (UBYTE *)options[OPT_TEXT];
  99.             if (options[OPT_SCREEN])  screen = (char *)options[OPT_SCREEN];
  100.  
  101.             if (screen && *screen) {
  102.                 /*
  103.                  *  user wants a special screen, lock it
  104.                  */
  105.                 if (scr = LockPubScreen(screen)) {
  106.                     dummywindow.Screen = scr;
  107.                     win = OpenWindow(&dummywindow);
  108.                     /*
  109.                      *  as the window is open, we can unlock
  110.                      *  if the window didn't open, the requester will
  111.                      *  open on the default public screen
  112.                      */
  113.                     UnlockPubScreen(NULL, scr);
  114.                     }
  115.  
  116.                 else {
  117.                     /*
  118.                      * public screen not found
  119.                      */
  120.                     PutStr("Can't find named public screen!\n");
  121.                     rc = 20l;
  122.                     }
  123.  
  124.                 }
  125.  
  126.             if (!rc) {
  127.                 /*
  128.                  *  win may be NULL
  129.                  */
  130.                 rc = EasyRequestArgs(win, &textreq, NULL, NULL);
  131.                 /*
  132.                  *  don't forget closing the window
  133.                  */
  134.                 if (win) CloseWindow(win);
  135.                 }
  136.  
  137.             }
  138.  
  139.         else {
  140.             /*
  141.              *  print out some more help
  142.              */
  143.             PutStr(USAGE "\n");
  144.             rc = 40l;
  145.  
  146.             }
  147.  
  148.         /*
  149.          *  free arguments and close the lib
  150.          */
  151.         FreeArgs(args);
  152.         CloseLibrary(IntuitionBase);
  153.  
  154.         }
  155.  
  156.     else {
  157.         /*
  158.          *  we really need intuition lib
  159.          *
  160.          *  don't use PutStr() here, because dos.library might be < v36
  161.          */
  162.         Write(Output(), "Can't open intuition.library V37+!\n", 35l);
  163.         rc = 30l;
  164.         }
  165.  
  166.     exit(rc);
  167. }
  168.