2 * $Id: qdos.c 443 2006-05-30 04:37:13Z darren $
4 * Copyright (c) 1999, Thierry Godefroy <godefroy@imaginet.fr>
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions to handle wildcard expansion and file name
10 * conversion under QDOS.
22 /* Translate the filenames from UNIX to QDOS conventions on open calls */
23 int (*_Open
) (const char *, int, ...) = qopen
;
25 long _stack
= 24576; /* Plenty of stack space */
26 long _memincr
= 10240; /* Big increments to cut fragmentation */
27 char _prog_name
[] = "ctags";
28 char _version
[] = PROGRAM_VERSION
;
29 char _copyright
[32] = __DATE__
;
30 char *_endmsg
= "\nPress a key to exit.";
31 int custom_expand (char * param
, char ***argvptr
, int *argcptr
);
32 int (*_cmdwildcard
) () = custom_expand
;
35 struct WINDOWDEF _condetails
= { 208, 1, 0, 7, 512, 256, 0, 0};
36 void (*_consetup
) () = consetup_title
;
38 /* custom cmdexpand: also expands directory names */
40 #define FILEBUF_INIT 1024 /* Initial allocation size for buffer */
41 #define FILEBUF_INCR 1024 /* Increment size for buffer */
43 int custom_expand (char * param
, char ***argvptr
, int *argcptr
)
51 * Check to see if we should do wild card expansion.
52 * We only perform wildcard expansion if the parameter
53 * was not a string and if it contains one of the
54 * wild card characters.
56 * We also do not expand any option that starts with '-'
57 * as we then assume that it is a unix stylew option.
59 if ((*param
== '-') || (strpbrk (param
,"*?") == NULL
) ) {
63 if ((filenamebuf
= malloc (bufsize
= FILEBUF_INIT
)) == NULL
) {
67 count
= getfnl (param
, filenamebuf
, bufsize
, QDR_ALL
);
68 if (count
== -1 && errno
== ENOMEM
) {
70 * We have overflowed the buffer, so we try
71 * to get a bigger buffer and try again.
73 bufsize
+= FILEBUF_INCR
;
74 if ((filenamebuf
= realloc (filenamebuf
, bufsize
)) == NULL
) {
81 * If no files were found, then return unexpanded.
88 * Files were found, so add these to the list instead
89 * of the original parameter typed by the user.
91 for ( ptr
=filenamebuf
; count
> 0 ; count
-- ) {
92 *argvptr
= (char **) realloc (*argvptr
, (size_t) (((*argcptr
) + 2) * sizeof (char *)));
93 safeptr
= (char *) malloc ((size_t) (sl
=strlen (ptr
) + 1));
94 if (safeptr
== NULL
|| *argvptr
== NULL
) {
97 (void) memcpy (safeptr
,ptr
, (size_t) sl
);
98 (*argvptr
) [*argcptr
] = safeptr
;
106 /* vi:set tabstop=4 shiftwidth=4: */