2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 RequestFile CLI command.
8 /*****************************************************************************
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
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).
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
47 Standard DOS error codes.
59 ******************************************************************************/
61 #include <proto/asl.h>
62 #include <proto/dos.h>
63 #include <proto/exec.h>
66 #include <dos/rdargs.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>
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 const TEXT version
[] = "$VER: RequestFile 42.3 (30.8.2012)\n";
92 struct TagItem FileTags
[] =
94 /* Note: The ordering of these is _important_! */
95 { ASLFR_InitialDrawer
, (IPTR
) NULL
},
96 { ASLFR_InitialFile
, (IPTR
) NULL
},
97 { ASLFR_InitialPattern
, (IPTR
) NULL
},
98 { ASLFR_TitleText
, (IPTR
) NULL
},
99 { ASLFR_PositiveText
, (IPTR
) NULL
},
100 { ASLFR_NegativeText
, (IPTR
) NULL
},
101 { ASLFR_AcceptPattern
, (IPTR
) NULL
},
102 { ASLFR_RejectPattern
, (IPTR
) NULL
},
103 { ASLFR_DoSaveMode
, FALSE
},
104 { ASLFR_DoMultiSelect
, FALSE
},
105 { ASLFR_DrawersOnly
, FALSE
},
106 { ASLFR_RejectIcons
, FALSE
},
107 { ASLFR_PubScreenName
, (IPTR
) NULL
},
108 { ASLFR_DoPatterns
, FALSE
},
109 { ASLFR_InitialShowVolumes
, TRUE
},
110 { TAG_DONE
, (IPTR
) NULL
}
115 static UBYTE
*ParsePatternArg(IPTR
**args
, UWORD ArgNum
);
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
,
126 int Return_Value
= RETURN_OK
;
132 Buffer
= (char *)AllocVec(MAX_PATH_LEN
, MEMF_ANY
| MEMF_CLEAR
);
135 rda
= ReadArgs(ARG_TEMPLATE
, (IPTR
*)args
, NULL
);
138 FileTags
[ARG_DRAWER
].ti_Data
= (IPTR
)args
[ARG_DRAWER
];
139 FileTags
[ARG_FILE
].ti_Data
= (IPTR
)args
[ARG_FILE
];
140 FileTags
[ARG_PATTERN
].ti_Data
= (IPTR
)args
[ARG_PATTERN
];
141 FileTags
[ARG_TITLE
].ti_Data
= (IPTR
)args
[ARG_TITLE
];
142 FileTags
[ARG_POSITIVE
].ti_Data
= (IPTR
)args
[ARG_POSITIVE
];
143 FileTags
[ARG_NEGATIVE
].ti_Data
= (IPTR
)args
[ARG_NEGATIVE
];
144 ParsePatternArg(args
, ARG_ACCEPTPAT
);
145 ParsePatternArg(args
, ARG_REJECTPAT
);
146 FileTags
[ARG_SAVEMODE
].ti_Data
= (IPTR
)args
[ARG_SAVEMODE
];
147 FileTags
[ARG_MULTISELECT
].ti_Data
= (IPTR
)args
[ARG_MULTISELECT
];
148 FileTags
[ARG_DRAWERSONLY
].ti_Data
= (IPTR
)args
[ARG_DRAWERSONLY
];
149 FileTags
[ARG_NOICONS
].ti_Data
= (IPTR
)args
[ARG_NOICONS
];
150 FileTags
[ARG_PUBSCREEN
].ti_Data
= (IPTR
)args
[ARG_PUBSCREEN
];
151 FileTags
[ARG_PUBSCREEN
+ 1].ti_Data
= args
[ARG_PATTERN
] != NULL
;
152 if (!args
[ARG_INITIALVOLUMES
])
154 FileTags
[ARG_INITIALVOLUMES
+ 1].ti_Tag
= TAG_IGNORE
;
157 FileReq
= (struct FileRequester
*)AllocAslRequest(ASL_FileRequest
,
161 Success
= AslRequest(FileReq
, NULL
);
165 if(!(IPTR
)args
[ARG_MULTISELECT
])
167 strncpy(Buffer
, FileReq
->fr_Drawer
, MAX_PATH_LEN
);
169 /* FileReq->fr_File is NULL when using DRAWERSONLY */
170 Success
= AddPart(Buffer
,
171 FileReq
->fr_File
? FileReq
->fr_File
: (STRPTR
)"",
176 DisplayArgs
[0] = (IPTR
)Buffer
;
177 VPrintf("\"%s\"\n", DisplayArgs
);
182 WBFiles
= FileReq
->fr_ArgList
;
184 for (i
= 0; i
!= FileReq
->fr_NumArgs
; i
++)
186 strncpy(Buffer
, FileReq
->fr_Drawer
, MAX_PATH_LEN
);
188 Success
= AddPart(Buffer
,
194 DisplayArgs
[0] = (IPTR
)Buffer
;
195 VPrintf("\"%s\" ", DisplayArgs
);
208 Return_Value
= RETURN_WARN
;
210 SetIoErr(ERROR_BREAK
);
214 PrintFault(IoErr(), NULL
);
215 Return_Value
= RETURN_FAIL
;
219 FreeAslRequest((struct FileRequester
*)FileReq
);
223 PrintFault(IoErr(), "RequestFile");
224 Return_Value
= RETURN_ERROR
;
231 PrintFault(IoErr(), "RequestFile");
232 Return_Value
= RETURN_ERROR
;
235 FreeVec((APTR
)FileTags
[ARG_ACCEPTPAT
].ti_Data
);
236 FreeVec((APTR
)FileTags
[ARG_REJECTPAT
].ti_Data
);
241 SetIoErr(ERROR_NO_FREE_STORE
);
242 PrintFault(IoErr(), NULL
);
243 Return_Value
= RETURN_FAIL
;
250 static UBYTE
*ParsePatternArg(IPTR
**args
, UWORD ArgNum
)
252 if (!args
[ArgNum
]) /* AROS crashes on strlen(NULL) */
254 FileTags
[ArgNum
].ti_Tag
= TAG_IGNORE
;
258 UBYTE
*PatternBuffer
= NULL
;
259 LONG PatternBufferSize
;
260 STRPTR pattern
= (STRPTR
)args
[ArgNum
];
262 PatternBufferSize
= 2 * strlen((char *)pattern
);
263 PatternBuffer
= AllocVec(PatternBufferSize
, MEMF_PUBLIC
);
264 if (PatternBuffer
!= NULL
)
266 if (ParsePatternNoCase((STRPTR
)pattern
,
267 PatternBuffer
, PatternBufferSize
) >= 0)
269 FileTags
[ArgNum
].ti_Data
= (IPTR
)PatternBuffer
;
273 FreeVec(PatternBuffer
);
274 PatternBuffer
= NULL
;
275 FileTags
[ArgNum
].ti_Tag
= TAG_IGNORE
;
279 return PatternBuffer
;