Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / RequestChoice.c
blob6a52fb0d9967f30072e583649d0a5967d471a9fc
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: RequestChoice CLI command
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME
13 RequestChoice
15 SYNOPSIS
17 TITLE/A,BODY/A,GADGETS/A/M,PUBSCREEN/K
19 LOCATION
21 Sys:c
23 FUNCTION
25 Allows AmigaDOS scripts to have access to the EasyRequest() function
26 for input.
28 INPUTS
30 TITLE - The text to display in the title bar of the requester.
32 BODY - The text to display in the body of the requester.
34 GADGETS - The text for each of the buttons.
36 PUBSCREEN - The name of the public screen to open the requester
37 upon.
39 RESULT
41 Standard DOS return codes.
43 NOTES
45 To place a newline into the body of the requester use *n or *N.
47 To place a quotation mark in the body of the requester use *".
49 The CLI template gives the GADGETS option as ALWAYS given; this
50 is different from the original program. This way, we do not have
51 to check to see if the gadgets have been given.
53 EXAMPLE
55 RequestChoice "This is a title" "This is*Na body" Okay|Cancel
57 This is self-explanitory, except for the "*N". This is the
58 equivalent of using a '\n' in C to get a newline in the body
59 of the requester. This requester will open on the Workbench
60 screen.
62 RequestChoice Title="This is a title" Body="This is*Na body"
63 Gadgets=Okay|Cancel PubScreen=DOPUS.1
65 This will do exactly the same as before except that it will
66 open on the Directory Opus public screen.
68 BUGS
70 SEE ALSO
72 intuition.library/EasyRequestArgs()
74 INTERNALS
76 HISTORY
78 08-Sep-1997 srittau Use dynamic buffer for gadget-labels
79 Small changes/fixes
81 27-Jul-1997 laguest Initial inclusion into the AROS tree
83 ******************************************************************************/
85 #include <proto/dos.h>
86 #include <proto/exec.h>
87 #include <proto/intuition.h> /* This causes a spilled register error */
89 #include <dos/dos.h>
90 #include <dos/rdargs.h>
91 #include <exec/libraries.h>
92 #include <exec/memory.h>
93 #include <exec/types.h>
94 #include <intuition/intuition.h>
95 #include <intuition/screens.h>
97 #include <string.h>
99 #define ARG_TEMPLATE "TITLE/A,BODY/A,GADGETS/A/M,PUBSCREEN/K"
100 #define ARG_TITLE 0
101 #define ARG_BODY 1
102 #define ARG_GADGETS 2
103 #define ARG_PUBSCREEN 3
104 #define TOTAL_ARGS 4
106 /* To define whether a command line switch was set or not.
108 #define NOT_SET 0
110 const TEXT version[] = "$VER: RequestChoice 41.1 (8.9.1997)\n";
112 static char ERROR_HEADER[] = "RequestChoice";
114 int Do_RequestChoice(STRPTR, STRPTR, STRPTR *, STRPTR);
116 int __nocommandline;
118 int main(void)
120 struct RDArgs * rda;
121 IPTR * args[TOTAL_ARGS] = { NULL, NULL, NULL, NULL };
122 int Return_Value;
124 Return_Value = RETURN_OK;
126 rda = ReadArgs(ARG_TEMPLATE, (IPTR *)args, NULL);
127 if (rda)
129 Return_Value = Do_RequestChoice((STRPTR)args[ARG_TITLE],
130 (STRPTR)args[ARG_BODY],
131 (STRPTR *)args[ARG_GADGETS],
132 (STRPTR)args[ARG_PUBSCREEN]);
133 FreeArgs(rda);
135 else
137 PrintFault(IoErr(), ERROR_HEADER);
138 Return_Value = RETURN_FAIL;
141 return (Return_Value);
142 } /* main */
145 STRPTR ComposeGadgetText(STRPTR *);
147 int Do_RequestChoice(STRPTR Title,
148 STRPTR Body,
149 STRPTR * Gadgets,
150 STRPTR PubScreen)
152 struct Screen * Scr;
153 struct EasyStruct ChoiceES;
154 STRPTR GadgetText;
155 LONG Result;
156 IPTR args[1];
157 int Return_Value;
159 Return_Value = RETURN_OK;
160 Result = 0L;
162 GadgetText = ComposeGadgetText(Gadgets);
163 if (!GadgetText)
164 return RETURN_FAIL;
166 /* Make sure we can open the requester on the specified screen.
168 * If the PubScreen argument is not specified it will contain
169 * NULL, and hence open on the Workbench screen.
171 Scr = (struct Screen *)LockPubScreen((UBYTE *)PubScreen);
172 if (Scr != NULL)
174 ChoiceES.es_StructSize = sizeof(struct EasyStruct);
175 ChoiceES.es_Flags = 0L;
176 ChoiceES.es_Title = Title;
177 ChoiceES.es_TextFormat = Body;
178 ChoiceES.es_GadgetFormat = GadgetText;
180 /* Open the requester.
182 Result = EasyRequestArgs(Scr->FirstWindow, &ChoiceES, NULL, NULL);
183 if (Result != -1)
185 args[0] = (IPTR)Result;
187 VPrintf("%ld\n", args);
189 else
191 Return_Value = RETURN_FAIL;
192 SetIoErr(ERROR_NO_FREE_STORE);
193 PrintFault(IoErr(), ERROR_HEADER);
195 UnlockPubScreen(NULL, Scr);
197 else
199 Return_Value = RETURN_FAIL;
200 SetIoErr(ERROR_NO_FREE_STORE);
201 PrintFault(IoErr(), ERROR_HEADER);
204 FreeVec(GadgetText);
206 return (Return_Value);
208 } /* Do_RequestChoice */
211 STRPTR ComposeGadgetText(STRPTR * Gadgets)
213 STRPTR GadgetText, BufferPos;
214 int GadgetLength = 0;
215 int CurrentGadget;
217 for (CurrentGadget = 0; Gadgets[CurrentGadget]; CurrentGadget++)
219 GadgetLength += strlen(Gadgets[CurrentGadget]) + 1;
222 GadgetText = AllocVec(GadgetLength, MEMF_ANY);
223 if (!GadgetText)
225 SetIoErr(ERROR_NO_FREE_STORE);
226 PrintFault(IoErr(), ERROR_HEADER);
227 return NULL;
230 BufferPos = GadgetText;
231 for (CurrentGadget = 0; Gadgets[CurrentGadget]; CurrentGadget++)
233 int LabelLength = strlen(Gadgets[CurrentGadget]);
234 CopyMem(Gadgets[CurrentGadget], BufferPos, LabelLength);
235 if (Gadgets[CurrentGadget + 1])
237 BufferPos[LabelLength] = '|';
238 BufferPos += LabelLength + 1;
240 else
241 BufferPos[LabelLength] = '\0';
244 return GadgetText;
246 } /* ComposeGadgetText */