home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / simp.c < prev    next >
C/C++ Source or Header  |  1998-06-21  |  5KB  |  289 lines

  1. /**    Simp.c
  2.   *
  3.   *    Implement the basic Simple Requester functions for rexxarplib.library.
  4.   *
  5.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  6.   *   ============
  7.   *
  8.   *    CURRENT VERSION:
  9.   *
  10.   *    This version has been converted to SAS C 6.5 format. It has been modified
  11.   *    for modern definition sequences for ANSI compilation. This no longer works
  12.   *    with OS versions prior to 2.04.
  13.   *
  14.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  15.   *   ============
  16.   *
  17.   **/
  18. #include <functions.h>
  19. #include "ralprotos.h"
  20. #include <intuition/intuition.h>
  21. #include <intuition/intuitionbase.h>
  22. #include <libraries/MyARP.h>
  23. #include <proto/rexxsyslib.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <simpreq.h>
  28. #include "rexxarplib.h"
  29.  
  30. static struct ReqPens reqpen_data = 
  31. {
  32.     3, 2, 0, 1, 2, 1, 1, 3, NULL
  33. };
  34.  
  35.  
  36. /**
  37.  *
  38.  *   This is the simple requester interface
  39.  *
  40. **/
  41. char *rxf_getsimp( long *err, int n, char *args[] )
  42. {
  43.     struct SimpleRequester s;
  44.     struct Screen *psptr = NULL;
  45.     char *sr_prompts[SR_MAXPROMPTS];
  46.     long result = 0L;
  47.     struct DrawInfo *dri;
  48.     char *ps = NULL, *cs = NULL, *os = NULL, *ss = NULL, *resval;
  49.     struct ReqPens reqpens;
  50.     
  51.     *err = 12;
  52.     
  53.     resval = CAS("\0");
  54.     setmem(sr_prompts, SR_MAXPROMPTS << 2, 0);
  55.     setmem(&s, sizeof(struct SimpleRequester), 0);
  56.     movmem(&reqpen_data, &reqpens, sizeof(struct ReqPens));
  57.     
  58.     s.sr_Prompt = sr_prompts;
  59.     
  60.     s.sr_PenList = &reqpens;
  61.     
  62.     if (n >= 7 && args[6]) 
  63.     {
  64.         psptr = LockScreen(args[6]);
  65.         if (psptr) 
  66.         {
  67.             dri = GetScreenDrawInfo(psptr);
  68.             reqpens.reqp_BlockPen  = dri->dri_Pens[BLOCKPEN];
  69.             reqpens.reqp_DetailPen = dri->dri_Pens[DETAILPEN];
  70.             reqpens.reqp_BackPen   = dri->dri_Pens[BACKGROUNDPEN];
  71.             reqpens.reqp_PromptPen = dri->dri_Pens[TEXTPEN];
  72.             reqpens.reqp_BoxPen    = dri->dri_Pens[SHINEPEN];
  73.             reqpens.reqp_ShadowPen = dri->dri_Pens[SHADOWPEN];
  74.             reqpens.reqp_OkayPen   = dri->dri_Pens[TEXTPEN];
  75.             reqpens.reqp_CancelPen = dri->dri_Pens[HIGHLIGHTTEXTPEN];
  76.             FreeScreenDrawInfo(psptr, dri);
  77.         }
  78.     }
  79.     s.sr_Screen = psptr;
  80.     
  81.     if (n >= 1 && args[0])
  82.         s.sr_x = atoi(args[0]);
  83.     
  84.     if (n >= 2 && args[1])
  85.         s.sr_y = atoi(args[1]);
  86.     
  87.     if (n >= 3 && args[2]) 
  88.     {
  89.         ps = mymalloc(strlen(args[2]) + 1);
  90.         if (!ps)
  91.             goto cleanup;
  92.         
  93.         DecodeAutoText(args[2], sr_prompts, ps);
  94.     }
  95.     
  96.     if (n >= 4 && args[3]) 
  97.     {
  98.         ss = mymalloc(256);
  99.         if (!ss)
  100.             goto cleanup;
  101.         strcpy(ss, args[3]);
  102.         s.sr_String = ss;
  103.     }
  104.     
  105.     if (n >= 5 && args[4]) 
  106.     {
  107.         os = mymalloc(strlen(args[4]) + 1);
  108.         if (!os)
  109.             goto cleanup;
  110.         strcpy(os, args[4]);
  111.         s.sr_Okay = os;
  112.     }
  113.     
  114.     if (n >= 6 && args[5]) 
  115.     {
  116.         cs = mymalloc(strlen(args[5]) + 1);
  117.         if (!cs)
  118.             goto cleanup;
  119.         strcpy(cs, args[5]);
  120.         s.sr_Cancel = cs;
  121.     }
  122.     
  123.     result = SimpleRequest(&s);
  124.     
  125.     if (s.sr_ErrorCode)
  126.         result = 0L;
  127.     else
  128.         *err = 0;
  129.     
  130.     if (result == 0L) 
  131.     {
  132.         resval = CAS("\0");
  133.     }
  134.     else
  135.     if (result)
  136.     {
  137.         if (args[3] == NULL) 
  138.         {
  139.             resval = CAS("OKAY");
  140.         }
  141.         else
  142.         {
  143.             resval = CAS(s.sr_String);
  144.         }
  145.     }
  146.     
  147.     cleanup:
  148.     if (ps)
  149.         myfree(ps);
  150.     if (os)
  151.         myfree(os);
  152.     if (cs)
  153.         myfree(cs);
  154.     if (ss)
  155.         myfree(ss);
  156.     
  157.     if (psptr)
  158.         UnlockScreen(args[6], psptr);
  159.     
  160.     return(resval);
  161. }
  162.  
  163. /**
  164.  *
  165.  *   This is the message poster facility
  166.  *
  167. **/
  168. static struct Window *w = NULL;
  169. static struct Screen *hpscr = NULL;
  170. static char pubscr[80];
  171. static struct Library *myBase = NULL;
  172. static int pmsglock = 0;
  173.  
  174. char *rxf_postmsg( long *err, int n, char *args[] )
  175. {
  176.     struct SimpleRequester s;
  177.     struct ReqPens reqpens;
  178.     char *sr_prompts[SR_MAXPROMPTS];
  179.     char *resval, *ps;
  180.     struct Window *SimpleMsgWindow(), *CloseMsgWindow();
  181.     
  182.     resval = CAS("0");
  183.     Forbid();
  184.     if (pmsglock)
  185.         pmsglock = -1;
  186.     else
  187.         pmsglock = 1;
  188.     Permit();
  189.     
  190.     if (pmsglock < 0)
  191.         return(CAS("0"));
  192.     
  193.     *err = 12;
  194.     
  195.     if (n < 3) 
  196.     {
  197.         if (w) 
  198.         {
  199.             w = CloseMsgWindow(w);
  200.             if (hpscr)
  201.                 hpscr = NULL;
  202.         }
  203.         /*
  204.          *   Close ourselves if we opened ourselves...
  205.          */
  206.         if (myBase) 
  207.         {
  208.             CloseLibrary(myBase);
  209.             myBase = NULL;
  210.         }
  211.         *err = 0L;
  212.         pmsglock = 0;
  213.         return(CAS("1"));
  214.     }
  215.     /*
  216.      *   Check the arguments (3 or more already established)
  217.      *   The malloc is done here, so that the goto cleanup doesn't leave a
  218.      *   public screen locked.
  219.      */
  220.     setmem(sr_prompts, SR_MAXPROMPTS << 2, 0);
  221.     setmem(&s, sizeof(struct SimpleRequester), 0);
  222.     
  223.     if (args[0])
  224.         s.sr_x = atoi(args[0]);
  225.     if (args[1])
  226.         s.sr_y = atoi(args[1]);
  227.     
  228.     ps = NULL;
  229.     if (args[2]) 
  230.     {
  231.         ps = mymalloc(strlen(args[2]) + 1);
  232.         if (!ps)
  233.             goto cleanup;
  234.         
  235.         DecodeAutoText(args[2], sr_prompts, ps);
  236.     }
  237.     s.sr_Prompt = sr_prompts;
  238.     /*
  239.      *   If the window isn't open right now, check for public screen
  240.      */
  241.     if (w == NULL) 
  242.     {
  243.         hpscr = NULL;
  244.         if (n >= 4) 
  245.         {
  246.             hpscr = LockScreen(args[3]);
  247.             strcpy(pubscr, args[3]);
  248.         }
  249.     }
  250.     s.sr_Screen = hpscr;
  251.     
  252.     movmem(&reqpen_data, &reqpens, sizeof(struct ReqPens));
  253.     s.sr_PenList = &reqpens;
  254.     
  255.     if (w) 
  256.     {
  257.         UpdateMsgWindow(w, &s);
  258.     }
  259.     else
  260.     {
  261.         w = SimpleMsgWindow(&s);
  262.         /*
  263.          *   Open ourselves to make sure we stay around.
  264.          */
  265.         if (w)
  266.             myBase = OpenLibrary("rexxarplib.library", NULL);
  267.         UnlockScreen(pubscr, hpscr);
  268.     }
  269.     
  270. //    if (w == NULL || s.sr_ErrorCode) 
  271.     if (w != NULL && s.sr_ErrorCode == 0)
  272. //    {
  273. //        resval = CAS("0");
  274. //    }
  275. //    else
  276.     {
  277.         resval = CAS("1");
  278.         *err = 0;
  279.     }
  280.     
  281.     cleanup:
  282.     if (ps)
  283.         myfree(ps);
  284.     
  285.     pmsglock = 0;
  286.     return(resval);
  287. }
  288.  
  289.