New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / RequestFile.c
blob189651597febf112beed14f3c309ed7412346b08
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 RequestFile CLI command.
6 */
8 /*****************************************************************************
10 NAME
12 RequestFile
14 SYNOPSIS
16 DRAWER,FILE/K,PATTERN/K,TITLE/K,POSITIVE/K,NEGATIVE/K,
17 ACCEPTPATTERN/K,REJECTPATTERN/K,SAVEMODE/S,MULTISELECT/S,
18 DRAWERSONLY/S,NOICONS/S,PUBSCREEN/K,INITIALVOLUMES/S
20 LOCATION
22 Workbench:c
24 FUNCTION
26 Creates file requester. The selected files will be displayed separated
27 by spaces. If no file is selected the return code is 5 (warn).
29 INPUTS
30 DRAWER -- initial content of drawer field
31 FILE -- initial content of file field
32 PATTERN -- content of pattern field (e.g. #?.c)
33 TITLE -- title of the dialog box
34 POSITIVE -- string for the left button
35 NEGATIVE -- string for the right button
36 ACCEPTPATTERN -- only files which match the pattern are displayed
37 REJECTPATTERN -- files which match the pattern aren't displayed
38 SAVEMODE -- requester is displayed as save requester
39 MULTISELECT -- more than one file can be selected
40 DRAWERSONLY -- only drawers are displayed
41 NOICONS -- no icon files (#?.info) are displayed
42 PUBSCREEN -- requester is opened on the given public screen
43 INITIALVOLUMES -- shows the volumes
45 RESULT
47 Standard DOS error codes.
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
57 INTERNALS
59 ******************************************************************************/
61 #include <proto/asl.h>
62 #include <proto/dos.h>
63 #include <proto/exec.h>
65 #include <dos/dos.h>
66 #include <dos/rdargs.h>
67 #include <dos/var.h>
68 #include <dos/dosasl.h>
69 #include <exec/types.h>
70 #include <exec/memory.h>
71 #include <libraries/asl.h>
72 #include <utility/tagitem.h>
73 #include <workbench/startup.h>
75 #include <string.h>
77 #define ARG_TEMPLATE "DRAWER,FILE/K,PATTERN/K,TITLE/K,POSITIVE/K," \
78 "NEGATIVE/K,ACCEPTPATTERN/K,REJECTPATTERN/K," \
79 "SAVEMODE/S,MULTISELECT/S,DRAWERSONLY/S," \
80 "NOICONS/S,PUBSCREEN/K,INITIALVOLUMES/S"
82 #define MAX_PATH_LEN 512
85 enum { ARG_DRAWER = 0, ARG_FILE, ARG_PATTERN, ARG_TITLE, ARG_POSITIVE,
86 ARG_NEGATIVE, ARG_ACCEPTPAT, ARG_REJECTPAT, ARG_SAVEMODE,
87 ARG_MULTISELECT, ARG_DRAWERSONLY, ARG_NOICONS, ARG_PUBSCREEN,
88 ARG_INITIALVOLUMES, TOTAL_ARGS };
90 static const char version[] = "$VER: RequestFile 42.1 (18.10.2005)\n";
92 extern struct Library *AslBase;
94 struct TagItem FileTags[] =
96 /* Note: The ordering of these is _important_! */
97 { ASLFR_InitialDrawer , (IPTR) NULL },
98 { ASLFR_InitialFile , (IPTR) NULL },
99 { ASLFR_InitialPattern, (IPTR) NULL },
100 { ASLFR_TitleText , (IPTR) NULL },
101 { ASLFR_PositiveText , (IPTR) NULL },
102 { ASLFR_NegativeText , (IPTR) NULL },
103 { ASLFR_AcceptPattern , (IPTR) NULL },
104 { ASLFR_RejectPattern , (IPTR) NULL },
105 { ASLFR_DoSaveMode , FALSE },
106 { ASLFR_DoMultiSelect , FALSE },
107 { ASLFR_DrawersOnly , FALSE },
108 { ASLFR_RejectIcons , FALSE },
109 { ASLFR_PubScreenName , (IPTR) NULL },
110 { ASLFR_DoPatterns , FALSE },
111 { ASLFR_InitialShowVolumes, TRUE },
112 { TAG_DONE , (IPTR) NULL }
115 int __nocommandline;
117 int main(void)
119 struct RDArgs *rda;
120 struct FileRequester *FileReq;
121 struct WBArg *WBFiles;
122 IPTR *args[TOTAL_ARGS] = { NULL, NULL, NULL, NULL,
123 NULL, NULL, NULL, NULL,
124 NULL, NULL, NULL, NULL,
125 NULL, NULL };
126 int Return_Value = RETURN_OK;
127 IPTR DisplayArgs[1];
128 char *Buffer;
129 BOOL Success;
130 int i;
132 #define DoSave (args[ARG_SAVEMODE] != NULL)
133 #define DoMulti (args[ARG_MULTISELECT] != NULL)
134 #define DoDrawers (args[ARG_DRAWERSONLY] != NULL)
135 #define DoIcons (args[ARG_NOICONS] != NULL)
136 #define DoPattern (args[ARG_PATTERN] != NULL)
138 Buffer = (char *)AllocVec(MAX_PATH_LEN, MEMF_ANY | MEMF_CLEAR);
139 if (Buffer != NULL)
141 rda = ReadArgs(ARG_TEMPLATE, (IPTR *)args, NULL);
142 if(rda != NULL)
144 FileTags[ARG_DRAWER].ti_Data = (ULONG)args[ARG_DRAWER];
145 FileTags[ARG_FILE].ti_Data = (ULONG)args[ARG_FILE];
146 FileTags[ARG_PATTERN].ti_Data = (ULONG)args[ARG_PATTERN];
147 FileTags[ARG_TITLE].ti_Data = (ULONG)args[ARG_TITLE];
148 FileTags[ARG_POSITIVE].ti_Data = (ULONG)args[ARG_POSITIVE];
149 FileTags[ARG_NEGATIVE].ti_Data = (ULONG)args[ARG_NEGATIVE];
150 FileTags[ARG_ACCEPTPAT].ti_Data = (ULONG)args[ARG_ACCEPTPAT];
151 FileTags[ARG_REJECTPAT].ti_Data = (ULONG)args[ARG_REJECTPAT];
152 FileTags[ARG_SAVEMODE].ti_Data = DoSave;
153 FileTags[ARG_MULTISELECT].ti_Data = DoMulti;
154 FileTags[ARG_DRAWERSONLY].ti_Data = DoDrawers;
155 FileTags[ARG_NOICONS].ti_Data = DoIcons;
156 FileTags[ARG_PUBSCREEN].ti_Data = (ULONG)args[ARG_PUBSCREEN];
157 FileTags[ARG_PUBSCREEN + 1].ti_Data = DoPattern;
158 if (!args[ARG_INITIALVOLUMES])
160 FileTags[ARG_INITIALVOLUMES + 1].ti_Tag = TAG_IGNORE;
163 FileReq = (struct FileRequester *)AllocAslRequest(ASL_FileRequest,
164 FileTags);
165 if(FileReq != NULL)
167 Success = AslRequest(FileReq, NULL);
169 if(Success != FALSE)
171 if(DoMulti == FALSE)
173 strncpy(Buffer, FileReq->fr_Drawer, MAX_PATH_LEN);
175 Success = AddPart(Buffer,
176 FileReq->fr_File,
177 MAX_PATH_LEN);
179 if(Success != FALSE)
181 DisplayArgs[0] = (IPTR)Buffer;
182 VPrintf("\"%s\"\n", DisplayArgs);
185 else
187 WBFiles = FileReq->fr_ArgList;
189 for (i = 0; i != FileReq->fr_NumArgs; i++)
191 strncpy(Buffer, FileReq->fr_Drawer, MAX_PATH_LEN);
193 Success = AddPart(Buffer,
194 WBFiles[i].wa_Name,
195 MAX_PATH_LEN);
197 if(Success != FALSE)
199 DisplayArgs[0] = (IPTR)Buffer;
200 VPrintf("\"%s\" ", DisplayArgs);
204 PutStr("\n");
207 else
209 if (IoErr() == 0)
211 /* We cancelled it!!
213 Return_Value = RETURN_WARN;
215 SetIoErr(ERROR_BREAK);
217 else
219 PrintFault(IoErr(), NULL);
220 Return_Value = RETURN_FAIL;
224 FreeAslRequest((struct FileRequester *)FileReq);
226 else
228 PrintFault(IoErr(), "RequestFile");
229 Return_Value = RETURN_ERROR;
232 FreeArgs(rda);
234 else
236 PrintFault(IoErr(), "RequestFile");
237 Return_Value = RETURN_ERROR;
240 FreeVec(Buffer);
242 else
244 SetIoErr(ERROR_NO_FREE_STORE);
245 PrintFault(IoErr(), NULL);
246 Return_Value = RETURN_FAIL;
249 return Return_Value;
251 } /* main */