home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
Resources
/
System
/
BoingBag1
/
Contributions
/
Workbench
/
RexxArpLib3p6
/
src
/
simp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-06-21
|
5KB
|
289 lines
/** Simp.c
*
* Implement the basic Simple Requester functions for rexxarplib.library.
*
* AUTHOR/DATE: W.G.J. Langeveld, November 1987.
* ============
*
* CURRENT VERSION:
*
* This version has been converted to SAS C 6.5 format. It has been modified
* for modern definition sequences for ANSI compilation. This no longer works
* with OS versions prior to 2.04.
*
* AUTHOR/DATE: Joanne Dow, jdow@bix.com, June 1998.
* ============
*
**/
#include <functions.h>
#include "ralprotos.h"
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/MyARP.h>
#include <proto/rexxsyslib.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <simpreq.h>
#include "rexxarplib.h"
static struct ReqPens reqpen_data =
{
3, 2, 0, 1, 2, 1, 1, 3, NULL
};
/**
*
* This is the simple requester interface
*
**/
char *rxf_getsimp( long *err, int n, char *args[] )
{
struct SimpleRequester s;
struct Screen *psptr = NULL;
char *sr_prompts[SR_MAXPROMPTS];
long result = 0L;
struct DrawInfo *dri;
char *ps = NULL, *cs = NULL, *os = NULL, *ss = NULL, *resval;
struct ReqPens reqpens;
*err = 12;
resval = CAS("\0");
setmem(sr_prompts, SR_MAXPROMPTS << 2, 0);
setmem(&s, sizeof(struct SimpleRequester), 0);
movmem(&reqpen_data, &reqpens, sizeof(struct ReqPens));
s.sr_Prompt = sr_prompts;
s.sr_PenList = &reqpens;
if (n >= 7 && args[6])
{
psptr = LockScreen(args[6]);
if (psptr)
{
dri = GetScreenDrawInfo(psptr);
reqpens.reqp_BlockPen = dri->dri_Pens[BLOCKPEN];
reqpens.reqp_DetailPen = dri->dri_Pens[DETAILPEN];
reqpens.reqp_BackPen = dri->dri_Pens[BACKGROUNDPEN];
reqpens.reqp_PromptPen = dri->dri_Pens[TEXTPEN];
reqpens.reqp_BoxPen = dri->dri_Pens[SHINEPEN];
reqpens.reqp_ShadowPen = dri->dri_Pens[SHADOWPEN];
reqpens.reqp_OkayPen = dri->dri_Pens[TEXTPEN];
reqpens.reqp_CancelPen = dri->dri_Pens[HIGHLIGHTTEXTPEN];
FreeScreenDrawInfo(psptr, dri);
}
}
s.sr_Screen = psptr;
if (n >= 1 && args[0])
s.sr_x = atoi(args[0]);
if (n >= 2 && args[1])
s.sr_y = atoi(args[1]);
if (n >= 3 && args[2])
{
ps = mymalloc(strlen(args[2]) + 1);
if (!ps)
goto cleanup;
DecodeAutoText(args[2], sr_prompts, ps);
}
if (n >= 4 && args[3])
{
ss = mymalloc(256);
if (!ss)
goto cleanup;
strcpy(ss, args[3]);
s.sr_String = ss;
}
if (n >= 5 && args[4])
{
os = mymalloc(strlen(args[4]) + 1);
if (!os)
goto cleanup;
strcpy(os, args[4]);
s.sr_Okay = os;
}
if (n >= 6 && args[5])
{
cs = mymalloc(strlen(args[5]) + 1);
if (!cs)
goto cleanup;
strcpy(cs, args[5]);
s.sr_Cancel = cs;
}
result = SimpleRequest(&s);
if (s.sr_ErrorCode)
result = 0L;
else
*err = 0;
if (result == 0L)
{
resval = CAS("\0");
}
else
if (result)
{
if (args[3] == NULL)
{
resval = CAS("OKAY");
}
else
{
resval = CAS(s.sr_String);
}
}
cleanup:
if (ps)
myfree(ps);
if (os)
myfree(os);
if (cs)
myfree(cs);
if (ss)
myfree(ss);
if (psptr)
UnlockScreen(args[6], psptr);
return(resval);
}
/**
*
* This is the message poster facility
*
**/
static struct Window *w = NULL;
static struct Screen *hpscr = NULL;
static char pubscr[80];
static struct Library *myBase = NULL;
static int pmsglock = 0;
char *rxf_postmsg( long *err, int n, char *args[] )
{
struct SimpleRequester s;
struct ReqPens reqpens;
char *sr_prompts[SR_MAXPROMPTS];
char *resval, *ps;
struct Window *SimpleMsgWindow(), *CloseMsgWindow();
resval = CAS("0");
Forbid();
if (pmsglock)
pmsglock = -1;
else
pmsglock = 1;
Permit();
if (pmsglock < 0)
return(CAS("0"));
*err = 12;
if (n < 3)
{
if (w)
{
w = CloseMsgWindow(w);
if (hpscr)
hpscr = NULL;
}
/*
* Close ourselves if we opened ourselves...
*/
if (myBase)
{
CloseLibrary(myBase);
myBase = NULL;
}
*err = 0L;
pmsglock = 0;
return(CAS("1"));
}
/*
* Check the arguments (3 or more already established)
* The malloc is done here, so that the goto cleanup doesn't leave a
* public screen locked.
*/
setmem(sr_prompts, SR_MAXPROMPTS << 2, 0);
setmem(&s, sizeof(struct SimpleRequester), 0);
if (args[0])
s.sr_x = atoi(args[0]);
if (args[1])
s.sr_y = atoi(args[1]);
ps = NULL;
if (args[2])
{
ps = mymalloc(strlen(args[2]) + 1);
if (!ps)
goto cleanup;
DecodeAutoText(args[2], sr_prompts, ps);
}
s.sr_Prompt = sr_prompts;
/*
* If the window isn't open right now, check for public screen
*/
if (w == NULL)
{
hpscr = NULL;
if (n >= 4)
{
hpscr = LockScreen(args[3]);
strcpy(pubscr, args[3]);
}
}
s.sr_Screen = hpscr;
movmem(&reqpen_data, &reqpens, sizeof(struct ReqPens));
s.sr_PenList = &reqpens;
if (w)
{
UpdateMsgWindow(w, &s);
}
else
{
w = SimpleMsgWindow(&s);
/*
* Open ourselves to make sure we stay around.
*/
if (w)
myBase = OpenLibrary("rexxarplib.library", NULL);
UnlockScreen(pubscr, hpscr);
}
// if (w == NULL || s.sr_ErrorCode)
if (w != NULL && s.sr_ErrorCode == 0)
// {
// resval = CAS("0");
// }
// else
{
resval = CAS("1");
*err = 0;
}
cleanup:
if (ps)
myfree(ps);
pmsglock = 0;
return(resval);
}