|
Lines 39-44
Link Here
|
| 39 |
# include "dm_error.h" |
39 |
# include "dm_error.h" |
| 40 |
|
40 |
|
| 41 |
# include <ctype.h> |
41 |
# include <ctype.h> |
|
|
42 |
# include <stdbool.h> |
| 42 |
|
43 |
|
| 43 |
static int |
44 |
static int |
| 44 |
DisplayTypeMatch (DisplayType d1, DisplayType d2) |
45 |
DisplayTypeMatch (DisplayType d1, DisplayType d2) |
|
Lines 62-72
Link Here
|
| 62 |
splitIntoWords (char *s) |
63 |
splitIntoWords (char *s) |
| 63 |
{ |
64 |
{ |
| 64 |
char **args, **newargs; |
65 |
char **args, **newargs; |
| 65 |
char *wordStart; |
66 |
char *wordStart, *thisToken; |
| 66 |
int nargs; |
67 |
int nargs; |
| 67 |
|
68 |
bool spaceBreakable, hadQuotes; |
|
|
69 |
static char DOUBLE_QUOTE=34, SINGLE_QUOTE=39; |
| 70 |
|
| 68 |
args = 0; |
71 |
args = 0; |
| 69 |
nargs = 0; |
72 |
nargs = 0; |
|
|
73 |
spaceBreakable = true; |
| 70 |
while (*s) |
74 |
while (*s) |
| 71 |
{ |
75 |
{ |
| 72 |
while (*s && isspace (*s)) |
76 |
while (*s && isspace (*s)) |
|
Lines 74-81
Link Here
|
| 74 |
if (!*s || *s == '#') |
78 |
if (!*s || *s == '#') |
| 75 |
break; |
79 |
break; |
| 76 |
wordStart = s; |
80 |
wordStart = s; |
| 77 |
while (*s && *s != '#' && !isspace (*s)) |
81 |
hadQuotes = false; |
|
|
82 |
while (*s && *s != '#') |
| 83 |
{ |
| 84 |
if (spaceBreakable && isspace (*s)) |
| 85 |
break; |
| 86 |
if (*s == DOUBLE_QUOTE || *s == SINGLE_QUOTE){ |
| 87 |
spaceBreakable = !spaceBreakable; |
| 88 |
hadQuotes = true; |
| 89 |
} |
| 78 |
++s; |
90 |
++s; |
|
|
91 |
} |
| 79 |
if (!args) |
92 |
if (!args) |
| 80 |
{ |
93 |
{ |
| 81 |
args = (char **) malloc (2 * sizeof (char *)); |
94 |
args = (char **) malloc (2 * sizeof (char *)); |
|
Lines 93-106
Link Here
|
| 93 |
} |
106 |
} |
| 94 |
args = newargs; |
107 |
args = newargs; |
| 95 |
} |
108 |
} |
| 96 |
args[nargs] = malloc (s - wordStart + 1); |
109 |
|
|
|
110 |
args[nargs] = malloc (s - wordStart); |
| 111 |
|
| 97 |
if (!args[nargs]) |
112 |
if (!args[nargs]) |
| 98 |
{ |
113 |
{ |
| 99 |
freeFileArgs (args); |
114 |
freeFileArgs (args); |
| 100 |
return NULL; |
115 |
return NULL; |
| 101 |
} |
116 |
} |
|
|
117 |
|
| 102 |
strncpy (args[nargs], wordStart, s - wordStart); |
118 |
strncpy (args[nargs], wordStart, s - wordStart); |
|
|
119 |
|
| 103 |
args[nargs][s-wordStart] = '\0'; |
120 |
args[nargs][s-wordStart] = '\0'; |
|
|
121 |
|
| 122 |
/* Tidy up problems with quotes in file */ |
| 123 |
if (hadQuotes){ |
| 124 |
args[nargs][0] = ' '; |
| 125 |
args[nargs][s-wordStart-1] = ' '; |
| 126 |
} |
| 127 |
|
| 104 |
++nargs; |
128 |
++nargs; |
| 105 |
args[nargs] = NULL; |
129 |
args[nargs] = NULL; |
| 106 |
} |
130 |
} |