/*
* scan.c -- scanning routines for Bacula
*
- * Kern Sibbald, MM separated from util.c MMIII
+ * Kern Sibbald, MM separated from util.c MMIII
*
* Version $Id$
*/
/*
* Skip spaces
- * Returns: 0 on failure (EOF)
- * 1 on success
- * new address in passed parameter
+ * Returns: 0 on failure (EOF)
+ * 1 on success
+ * new address in passed parameter
*/
bool skip_spaces(char **msg)
{
/*
* Skip nonspaces
- * Returns: 0 on failure (EOF)
- * 1 on success
- * new address in passed parameter
+ * Returns: 0 on failure (EOF)
+ * 1 on success
+ * new address in passed parameter
*/
bool skip_nonspaces(char **msg)
{
s1=a;
s2=b;
- while (*s1) { /* do it the fast way */
+ while (*s1) { /* do it the fast way */
if ((*s1++ | 0x20) != (*s2++ | 0x20))
- return 0; /* failed */
+ return 0; /* failed */
}
- while (*a) { /* do it over the correct slow way */
+ while (*a) { /* do it over the correct slow way */
if (B_ISUPPER(c1 = *a)) {
- c1 = tolower((int)c1);
+ c1 = tolower((int)c1);
}
if (B_ISUPPER(c2 = *b)) {
- c2 = tolower((int)c2);
+ c2 = tolower((int)c2);
}
if (c1 != c2) {
- return 0;
+ return 0;
}
a++;
b++;
/* skip past spaces to next arg */
for (p=*s; *p && B_ISSPACE(*p); ) {
p++;
- }
+ }
Dmsg1(400, "Next arg=%s\n", p);
for (n = q = p; *p ; ) {
if (*p == '\\') {
- p++;
- if (*p) {
- *q++ = *p++;
- } else {
- *q++ = *p;
- }
- continue;
+ p++;
+ if (*p) {
+ *q++ = *p++;
+ } else {
+ *q++ = *p;
+ }
+ continue;
}
if (*p == '"') { /* start or end of quote */
- if (in_quote) {
- p++; /* skip quote */
- in_quote = false;
- continue;
- }
- in_quote = true;
- p++;
- continue;
+ if (in_quote) {
+ p++; /* skip quote */
+ in_quote = false;
+ continue;
+ }
+ in_quote = true;
+ p++;
+ continue;
}
if (!in_quote && B_ISSPACE(*p)) { /* end of field */
- p++;
- break;
+ p++;
+ break;
}
*q++ = *p++;
}
*/
int parse_args(POOLMEM *cmd, POOLMEM **args, int *argc,
- char **argk, char **argv, int max_args)
+ char **argk, char **argv, int max_args)
{
char *p, *q, *n;
while (*argc < max_args) {
n = next_arg(&p);
if (*n) {
- argk[*argc] = n;
- argv[(*argc)++] = NULL;
+ argk[*argc] = n;
+ argv[(*argc)++] = NULL;
} else {
- break;
+ break;
}
}
/* Separate keyword and value */
for (int i=0; i < *argc; i++) {
p = strchr(argk[i], '=');
if (p) {
- *p++ = 0; /* terminate keyword and point to value */
- /* Unquote quoted values */
+ *p++ = 0; /* terminate keyword and point to value */
+ /* Unquote quoted values */
if (*p == '"') {
for (n = q = ++p; *p && *p != '"'; ) {
if (*p == '\\') {
- p++;
- }
- *q++ = *p++;
- }
- *q = 0; /* terminate string */
- p = n; /* point to string */
- }
- if (strlen(p) > MAX_NAME_LENGTH-1) {
- p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */
- }
+ p++;
+ }
+ *q++ = *p++;
+ }
+ *q = 0; /* terminate string */
+ p = n; /* point to string */
+ }
+ if (strlen(p) > MAX_NAME_LENGTH-1) {
+ p[MAX_NAME_LENGTH-1] = 0; /* truncate to max len */
+ }
}
- argv[i] = p; /* save ptr to value or NULL */
+ argv[i] = p; /* save ptr to value or NULL */
}
#ifdef xxxx
for (int i=0; i < *argc; i++) {
* in the arguments provided.
*/
void split_path_and_filename(const char *fname, POOLMEM **path, int *pnl,
- POOLMEM **file, int *fnl)
+ POOLMEM **file, int *fnl)
{
const char *p, *f;
int slen;
p = fname;
f = fname + len - 1;
/* "strip" any trailing slashes */
- while (slen > 0 && *f == '/') {
+ while (slen > 1 && *f == '/') {
slen--;
f--;
}
f--;
}
if (*f == '/') { /* did we find a slash? */
- f++; /* yes, point to filename */
- } else { /* no, whole thing must be path name */
+ f++; /* yes, point to filename */
+ } else { /* no, whole thing must be path name */
f = fname;
}
Dmsg2(200, "after strip len=%d f=%s\n", len, f);
*fnl = fname - f + len;
if (*fnl > 0) {
*file = check_pool_memory_size(*file, *fnl+1);
- memcpy(*file, f, *fnl); /* copy filename */
+ memcpy(*file, f, *fnl); /* copy filename */
}
(*file)[*fnl] = 0;