-
Notifications
You must be signed in to change notification settings - Fork 0
/
qdos.c
106 lines (95 loc) · 2.96 KB
/
qdos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* $Id: qdos.c 443 2006-05-30 04:37:13Z darren $
*
* Copyright (c) 1999, Thierry Godefroy <godefroy@imaginet.fr>
*
* This source code is released for free distribution under the terms of the
* GNU General Public License.
*
* This module contains functions to handle wildcard expansion and file name
* conversion under QDOS.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <qdos.h>
#include <string.h>
#include <errno.h>
#include "ctags.h"
/* Translate the filenames from UNIX to QDOS conventions on open calls */
int (*_Open) (const char *, int, ...) = qopen;
long _stack = 24576; /* Plenty of stack space */
long _memincr = 10240; /* Big increments to cut fragmentation */
char _prog_name [] = "ctags";
char _version [] = PROGRAM_VERSION;
char _copyright [32] = __DATE__;
char *_endmsg = "\nPress a key to exit.";
int custom_expand (char * param, char ***argvptr, int *argcptr);
int (*_cmdwildcard) () = custom_expand;
struct WINDOWDEF _condetails = { 208, 1, 0, 7, 512, 256, 0, 0};
void (*_consetup) () = consetup_title;
/* custom cmdexpand: also expands directory names */
#define FILEBUF_INIT 1024 /* Initial allocation size for buffer */
#define FILEBUF_INCR 1024 /* Increment size for buffer */
int custom_expand (char * param, char ***argvptr, int *argcptr)
{
int count,sl;
size_t bufsize;
char *filenamebuf;
char *ptr,*safeptr;
/*
* Check to see if we should do wild card expansion.
* We only perform wildcard expansion if the parameter
* was not a string and if it contains one of the
* wild card characters.
*
* We also do not expand any option that starts with '-'
* as we then assume that it is a unix stylew option.
*/
if ((*param == '-') || (strpbrk (param,"*?") == NULL) ) {
return 0;
}
if ((filenamebuf = malloc (bufsize = FILEBUF_INIT)) == NULL) {
return -1;
}
TRYAGAIN:
count = getfnl (param, filenamebuf, bufsize, QDR_ALL);
if (count == -1 && errno == ENOMEM) {
/*
* We have overflowed the buffer, so we try
* to get a bigger buffer and try again.
*/
bufsize += FILEBUF_INCR;
if ((filenamebuf = realloc (filenamebuf, bufsize)) == NULL) {
return -1;
} else {
goto TRYAGAIN;
}
}
/*
* If no files were found, then return unexpanded.
*/
if (count == 0) {
free (filenamebuf);
return 0;
}
/*
* Files were found, so add these to the list instead
* of the original parameter typed by the user.
*/
for ( ptr=filenamebuf ; count > 0 ; count -- ) {
*argvptr = (char **) realloc (*argvptr, (size_t) (((*argcptr) + 2) * sizeof (char *)));
safeptr= (char *) malloc ((size_t) (sl=strlen (ptr) + 1));
if (safeptr == NULL || *argvptr == NULL) {
return -1;
}
(void) memcpy (safeptr,ptr, (size_t) sl);
(*argvptr) [*argcptr] = safeptr;
*argcptr += 1;
ptr += sl;
}
free (filenamebuf);
return *argcptr;
}
/* vi:set tabstop=4 shiftwidth=4: */