2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: RequestChoice CLI command
9 /*****************************************************************************
17 TITLE/A,BODY/A,GADGETS/A/M,PUBSCREEN/K
25 Allows AmigaDOS scripts to have access to the EasyRequest() function
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
41 Standard DOS return codes.
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.
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
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.
72 intuition.library/EasyRequestArgs()
78 08-Sep-1997 srittau Use dynamic buffer for gadget-labels
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 */
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>
99 #define ARG_TEMPLATE "TITLE/A,BODY/A,GADGETS/A/M,PUBSCREEN/K"
102 #define ARG_GADGETS 2
103 #define ARG_PUBSCREEN 3
106 /* To define whether a command line switch was set or not.
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
);
121 IPTR
* args
[TOTAL_ARGS
] = { NULL
, NULL
, NULL
, NULL
};
124 Return_Value
= RETURN_OK
;
126 rda
= ReadArgs(ARG_TEMPLATE
, (IPTR
*)args
, NULL
);
129 Return_Value
= Do_RequestChoice((STRPTR
)args
[ARG_TITLE
],
130 (STRPTR
)args
[ARG_BODY
],
131 (STRPTR
*)args
[ARG_GADGETS
],
132 (STRPTR
)args
[ARG_PUBSCREEN
]);
137 PrintFault(IoErr(), ERROR_HEADER
);
138 Return_Value
= RETURN_FAIL
;
141 return (Return_Value
);
145 STRPTR
ComposeGadgetText(STRPTR
*);
147 int Do_RequestChoice(STRPTR Title
,
153 struct EasyStruct ChoiceES
;
159 Return_Value
= RETURN_OK
;
162 GadgetText
= ComposeGadgetText(Gadgets
);
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
);
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
);
185 args
[0] = (IPTR
)Result
;
187 VPrintf("%ld\n", args
);
191 Return_Value
= RETURN_FAIL
;
192 SetIoErr(ERROR_NO_FREE_STORE
);
193 PrintFault(IoErr(), ERROR_HEADER
);
195 UnlockPubScreen(NULL
, Scr
);
199 Return_Value
= RETURN_FAIL
;
200 SetIoErr(ERROR_NO_FREE_STORE
);
201 PrintFault(IoErr(), ERROR_HEADER
);
206 return (Return_Value
);
208 } /* Do_RequestChoice */
211 STRPTR
ComposeGadgetText(STRPTR
* Gadgets
)
213 STRPTR GadgetText
, BufferPos
;
214 int GadgetLength
= 0;
217 for (CurrentGadget
= 0; Gadgets
[CurrentGadget
]; CurrentGadget
++)
219 GadgetLength
+= strlen(Gadgets
[CurrentGadget
]) + 1;
222 GadgetText
= AllocVec(GadgetLength
, MEMF_ANY
);
225 SetIoErr(ERROR_NO_FREE_STORE
);
226 PrintFault(IoErr(), ERROR_HEADER
);
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;
241 BufferPos
[LabelLength
] = '\0';
246 } /* ComposeGadgetText */