home *** CD-ROM | disk | FTP | other *** search
- /*
- the grammer describing the control file for watcher.
-
- Kenneth Ingham
-
- Copyright (C) 1987 The University of New Mexico
- */
-
- %token PIPELINE NUMBER STRING
- %start command
-
- %{
- #include "defs.h"
- #define SMAXMIN struct max_min_st
- #define SOUTFMT struct out_fmt_st
- #define SCOLOUT struct col_out_st
- #define SRELOUT struct rel_out_st
- #define SCMD struct cmd_st
- #define SCH struct change_fmt_st
- extern char *strval, ostrval[], pipeline[];
- extern int intval, ointval;
- extern struct cmd_st *clist;
- int out_type;
- char alias[MAX_STR];
- union out_fmt_u key;
- %}
-
- %%
- /*
- THE PARSER DESCRIPTION (read aloud to the beginning of
- _Also_sprach_Zarathustra_)
-
- As things are discovered, they are put into the linked list structure
- detailed in defs.h. Some error checking is done, but the messages
- leave a bit to be desired. Yacc and I didn't get along too well in
- figuring out how to handle errors.
-
- Assuming that pointers will fit into YYSTYPE (int on 4.3 vax).
- Should use yacc's union facility.
- */
-
- command : one_command
- {
- if (clist == NULL)
- clist = (SCMD *) $1;
- }
- | command one_command
- {
- SCMD *p;
-
- if (clist != NULL) {
- for (p=clist; p->next!=NULL; p=p->next)
- ;
- p->next = (SCMD *)$2;
- }
- else
- clist = (SCMD *)$1;
- }
- | error '.'
- {
- fprintf(stderr, "Command error near ");
- fprintf(stderr, "'%s'\n", pipeline);
- fprintf(stderr,"Last string read was '%s'\n", strval);
- }
- ;
-
- one_command : PIPELINE alias out_fmt ':' change_fmt '.'
- {
- SCMD *p;
-
- p = (SCMD *) malloc(sizeof(SCMD));
- if (p == NULL) {
- fprintf(stderr,"malloc error\n");
- exit(1);
- }
- p->pipeline = malloc((unsigned)strlen(pipeline)+1);
- if (p->pipeline == NULL) {
- fprintf(stderr,"malloc error\n");
- exit(1);
- }
- (void) strcpy(p->pipeline, pipeline);
-
- if (alias[0]) {
- p->alias = malloc((unsigned)strlen(alias)+1);
- if (p->alias == NULL) {
- fprintf(stderr,"malloc error\n");
- exit(1);
- }
- (void) strcpy(p->alias, alias);
- }
- else
- p->alias = NULL;
-
- p->change_fmt = (SCH *)$5;
- p->next = NULL;
- p->out_type = out_type;
- if (out_type == RELATIVE) {
- p->out_fmt.rel_fmt = (SRELOUT *)$3;
- p->key.rel_fmt = key.rel_fmt;
- }
- else { /* it better be column */
- p->out_fmt.col_fmt = (SCOLOUT *)$3;
- p->key.col_fmt = key.col_fmt;
- }
-
- key.rel_fmt = NULL;
- $$ = (int)p;
- }
- ;
-
- out_fmt : rel_out_fmt
- {
- out_type = RELATIVE;
- $$ = $1;
- }
- | col_out_fmt
- {
- out_type = COLUMN;
- $$ = $1;
- }
- | error '.'
- {
- fprintf(stderr,"Output format error on ");
- fprintf(stderr,"'%s'\n", pipeline);
- fprintf(stderr,"Last string read was '%s'\n",
- strval);
- }
- ;
-
- change_fmt : one_change_fmt
- | change_fmt ';' one_change_fmt
- {
- SCH *p;
-
- for (p=(SCH *)$1; p->next != NULL; p = p->next)
- ;
-
- p->next = (SCH *)$3;
-
- $$ = (int)$1;
- }
- ;
-
- one_change_fmt : pct_change_fmt
- { $$ = $1; } /* Is this default? */
- | abs_change_fmt
- { $$ = $1; }
- | max_min_fmt
- { $$ = $1; }
- | str_change_fmt
- { $$ = $1; }
- | error '.'
- {
- fprintf(stderr,"Unknown change format type ");
- fprintf(stderr,"on '%s'\n", pipeline);
- fprintf(stderr,"Last string read '%s'\n", strval);
- }
- ;
-
- rel_out_fmt : one_rel_fmt
- | rel_out_fmt one_rel_fmt
- {
- SRELOUT *p;
-
- for (p=(SRELOUT *)$1;p->next != NULL; p=p->next)
- ;
- p->next = (SRELOUT *)$2;
- $$ = (int)$1;
- }
- ;
-
- col_out_fmt : one_col_fmt
- | col_out_fmt one_col_fmt
- {
- SCOLOUT *p;
-
- for (p=(SCOLOUT *)$1;p->next != NULL; p=p->next)
- ;
- p->next = (SCOLOUT *)$2;
- $$ = (int)$1;
- }
- /*
- | error '.'
- {
- fprintf(stderr,"Column output format error\n");
- fprintf(stderr,"Last string read '%s'\n", strval);
- }
- */
- ;
-
- one_rel_fmt : NUMBER STRING '%' STRING
- {
- extern int parse_error;
- SRELOUT *p;
-
- p = (SRELOUT *) malloc(sizeof(SRELOUT));
- p->name = malloc((unsigned)strlen(ostrval)+1);
- (void) strcpy(p->name, ostrval);
- p->field = intval;
- p->next = NULL;
-
- if (strval[1] != '\0') {
- fprintf(stderr,"%s: Invalid type specifier '%s'.\n",
- NAME, strval);
- parse_error = True;
- $$ = (int)p;
- }
-
- switch (*strval) {
- case 'd':
- case 'f':
- p->type = NUM;
- break;
- case 's':
- p->type = STRING;
- break;
- case 'k':
- p->type = KEY;
- key.rel_fmt = p;
- break;
- default:
- fprintf(stderr,"%s: Invalid type specifier '%s'.\n",
- NAME, strval);
- parse_error = True;
- }
-
- $$ = (int) p;
- }
- ;
-
- one_col_fmt : NUMBER '-' NUMBER STRING '%' STRING
- {
- extern int parse_error;
- SCOLOUT *p;
-
- p = (SCOLOUT *) malloc(sizeof(SCOLOUT));
- p->name = malloc((unsigned)strlen(ostrval)+1);
- (void) strcpy(p->name, ostrval);
- p->start = ointval;
- p->end = intval;
- p->next = NULL;
-
- if (ointval >= intval) {
- fprintf(stderr,"%s: start %d larger than end %d!\n", NAME, ointval, intval);
- parse_error = True;
- $$ = (int)p;
- }
-
- if (strval[1] != '\0') {
- fprintf(stderr,"%s: Invalid %s '%s'.\n",
- NAME, "type specifier", strval);
- parse_error = True;
- $$ = (int)p;
- }
-
- switch (*strval) {
- case 'd':
- case 'f':
- p->type = NUM;
- break;
- case 's':
- p->type = STRING;
- break;
- case 'k':
- p->type = KEY;
- key.col_fmt = p;
- break;
- default:
- fprintf(stderr,"%s: %s '%s'.\n",
- NAME,
- "Bad type specifier",
- strval);
- parse_error = True;
- }
- $$ = (int) p;
- }
- ;
-
- pct_change_fmt : STRING NUMBER '%'
- {
- SCH *p;
-
- p = (SCH *) malloc(sizeof(SCH));
- p->name = malloc((unsigned)strlen(strval)+1);
- (void) strcpy(p->name, strval);
- p->fmt.percent = (float)intval / 100;
- p->type = PERCENT;
-
- $$ = (int) p;
- }
- ;
-
- abs_change_fmt : STRING NUMBER
- {
- SCH *p;
-
- p = (SCH *) malloc(sizeof(SCH));
- p->name = malloc((unsigned) strlen(strval)+1);
- (void) strcpy(p->name, strval);
- p->fmt.abs_amount = intval;
- p->type = ABSOLUTE;
-
- $$ = (int) p;
- }
- ;
-
- max_min_fmt : STRING NUMBER NUMBER
- {
- SCH *p;
-
- p = (SCH *) malloc(sizeof(SCH));
- p->name = malloc((unsigned)strlen(strval)+1);
- (void) strcpy(p->name, strval);
- p->fmt.max_min.max = intval;
- p->fmt.max_min.min = ointval;
- p->type = MAX_MIN;
-
- $$ = (int) p;
- }
- ;
-
- str_change_fmt : STRING '"' STRING '"'
- {
- SCH *p;
-
- p = (SCH *) malloc(sizeof(SCH));
- p->name = malloc((unsigned)strlen(ostrval)+1);
- (void) strcpy(p->name, ostrval);
- p->fmt.str_value = malloc((unsigned)strlen(strval)+1);
- (void) strcpy(p->fmt.str_value, strval);
- p->type = STRING;
-
- $$ = (int) p;
- }
- ;
-
- alias : '{' STRING '}'
- { (void) strcpy(alias, strval); }
- | empty
- { alias[0] = '\0'; }
- ;
-
- empty : ;
-