Handle template expressions that may use the << or >> operators
[arduino-ctags.git] / qdos.c
blob2adb8c351f1496041a5c37f5a995ecd98c27c449
1 /*
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.
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <qdos.h>
18 #include <string.h>
19 #include <errno.h>
20 #include "ctags.h"
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)
45 int count,sl;
46 size_t bufsize;
47 char *filenamebuf;
48 char *ptr,*safeptr;
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) ) {
60 return 0;
63 if ((filenamebuf = malloc (bufsize = FILEBUF_INIT)) == NULL) {
64 return -1;
66 TRYAGAIN:
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) {
75 return -1;
76 } else {
77 goto TRYAGAIN;
81 * If no files were found, then return unexpanded.
83 if (count == 0) {
84 free (filenamebuf);
85 return 0;
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) {
95 return -1;
97 (void) memcpy (safeptr,ptr, (size_t) sl);
98 (*argvptr) [*argcptr] = safeptr;
99 *argcptr += 1;
100 ptr += sl;
102 free (filenamebuf);
103 return *argcptr;
106 /* vi:set tabstop=4 shiftwidth=4: */