43 |
static void multiline_finish __P ((void)); |
static void multiline_finish __P ((void)); |
44 |
static void ident __P((const char *text)); |
static void ident __P((const char *text)); |
45 |
static void sieve_include __P((void)); |
static void sieve_include __P((void)); |
46 |
|
static void sieve_searchpath __P((void)); |
47 |
|
|
48 |
#ifdef FLEX_SCANNER |
#ifdef FLEX_SCANNER |
49 |
#define xinput() (yyin ? getc(yyin) : EOF) |
#define xinput() (yyin ? getc(yyin) : EOF) |
325 |
<COMMENT>"*"+"/" BEGIN(INITIAL); |
<COMMENT>"*"+"/" BEGIN(INITIAL); |
326 |
/* Preprocessor directives (an extension) */ |
/* Preprocessor directives (an extension) */ |
327 |
#[ \t]*include.*\n { sieve_include (); } |
#[ \t]*include.*\n { sieve_include (); } |
328 |
|
#[ \t]*searchpath.*\n { sieve_searchpath (); } |
329 |
/* End-of-line comments */ |
/* End-of-line comments */ |
330 |
#.*\n { sieve_line_num++; } |
#.*\n { sieve_line_num++; } |
331 |
#.* /* end-of-file comment */; |
#.* /* end-of-file comment */; |
363 |
return pop_source(); |
return pop_source(); |
364 |
} |
} |
365 |
|
|
366 |
void |
static char * |
367 |
sieve_include () |
get_file_name (char *p, char *endp, int *usepath) |
368 |
{ |
{ |
369 |
char *p, *startp, *endp = yytext + yyleng, exp, *name; |
char exp, *name, *startp; |
370 |
int n; |
int n; |
371 |
|
|
372 |
p = strstr (yytext, "include"); |
if (usepath) |
373 |
for (p += 7; p < endp && isspace (*p); p++) |
*usepath = 0; |
|
; |
|
|
|
|
374 |
switch (*p) |
switch (*p) |
375 |
{ |
{ |
376 |
case '"': |
case '"': |
379 |
|
|
380 |
case '<': |
case '<': |
381 |
exp = '>'; |
exp = '>'; |
382 |
|
if (usepath) |
383 |
|
*usepath = 1; |
384 |
break; |
break; |
385 |
|
|
386 |
default: |
default: |
387 |
yyerror ("include syntax"); |
yyerror ("preprocessor syntax"); |
388 |
return; |
return NULL; |
389 |
} |
} |
390 |
|
|
391 |
for (startp = ++p; p < endp && *p != exp; p++) |
for (startp = ++p; p < endp && *p != exp; p++) |
393 |
|
|
394 |
if (*p != exp) |
if (*p != exp) |
395 |
{ |
{ |
396 |
yyerror ("missing closing quote in include statement"); |
yyerror ("missing closing quote in preprocessor statement"); |
397 |
return; |
return NULL; |
398 |
} |
} |
399 |
|
|
400 |
n = p - startp; |
n = p - startp; |
401 |
name = sieve_alloc (n + 1); |
name = sieve_alloc (n + 1); |
402 |
memcpy (name, startp, n); |
memcpy (name, startp, n); |
403 |
name[n] = 0; |
name[n] = 0; |
404 |
|
return name; |
405 |
|
} |
406 |
|
|
407 |
|
static int |
408 |
|
_try_include (void *item, void *data) |
409 |
|
{ |
410 |
|
char **dir = data; |
411 |
|
char *name = malloc (strlen (item) + 1 + strlen (*dir) + 1); |
412 |
|
|
413 |
|
if (!name) |
414 |
|
return 0; |
415 |
|
sprintf (name, "%s/%s", (char*) item, *dir); |
416 |
|
if (access (name, R_OK) == 0) |
417 |
|
{ |
418 |
|
*(char**) data = name; |
419 |
|
return 1; |
420 |
|
} |
421 |
|
free (name); |
422 |
|
return 0; |
423 |
|
} |
424 |
|
|
425 |
|
void |
426 |
|
sieve_include () |
427 |
|
{ |
428 |
|
char *p, *endp = yytext + yyleng, *name; |
429 |
|
int usepath; |
430 |
|
|
431 |
|
p = strstr (yytext, "include"); |
432 |
|
for (p += 7; p < endp && isspace (*p); p++) |
433 |
|
; |
434 |
|
|
435 |
|
name = get_file_name (p, endp, &usepath); |
436 |
|
if (!name) |
437 |
|
return; |
438 |
|
|
439 |
|
if (usepath && name[0] != '/' && memcmp (name, "..", 2)) |
440 |
|
{ |
441 |
|
char *p = name; |
442 |
|
if (list_do (sieve_include_path, _try_include, &p)) |
443 |
|
{ |
444 |
|
push_source (p); |
445 |
|
free (name); |
446 |
|
free (p); |
447 |
|
return; |
448 |
|
} |
449 |
|
} |
450 |
|
|
451 |
push_source (name); |
push_source (name); |
452 |
free (name); |
free (name); |
453 |
} |
} |
454 |
|
|
455 |
|
void |
456 |
|
sieve_searchpath () |
457 |
|
{ |
458 |
|
int append = 0; |
459 |
|
char *p, *endp = yytext + yyleng, *name; |
460 |
|
|
461 |
|
p = strstr (yytext, "searchpath"); |
462 |
|
for (p += 10; p < endp && isspace (*p); p++) |
463 |
|
; |
464 |
|
if (strcmp (p, "add") == 0) |
465 |
|
{ |
466 |
|
append = 1; |
467 |
|
for (p += 3; p < endp && isspace (*p); p++) |
468 |
|
; |
469 |
|
} |
470 |
|
name = get_file_name (p, endp, NULL); |
471 |
|
if (name) |
472 |
|
{ |
473 |
|
sieve_load_add_dir (sieve_machine, name); |
474 |
|
free (name); |
475 |
|
} |
476 |
|
} |
477 |
|
|
478 |
int |
int |
479 |
sieve_lex_begin (const char *name) |
sieve_lex_begin (const char *name) |
480 |
{ |
{ |