%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright (c) 1994, by Sun Microsytems, Inc.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
%}
%a 10000
%o 10000
%{
#include "spec.h"
#include "expr.h"
#include "y.tab.h"
#include <stdlib.h>
#include <string.h>
/*
** we substitute i/o routines defined in main.c for the
** standard fare. This allows us to support the "source"
** function by redirecting the input stream from different
** places
*/
#include "source.h"
#define input() source_input()
#define unput(c) source_unput(c)
#define output(c) source_output(c)
%}
%%
#.* ; /* eat comments */
[ \t]+ ; /* eats whitespace */
\\\n { source_nl(); } /* escaped newline */
= return (EQ);
\, return (COMMA);
\'[^'\n]*\' { yylval.strval = qtstr(yytext); return VALSTR; }
\/([^/\\\n]|\\.)*\/ { yylval.strval = rgstr(yytext); return REGEXP; }
[0-9]+[KkMm]? {
char scale = yytext[yyleng - 1];
yylval.intval = atoi(yytext);
if (scale == 'k' || scale == 'K')
yylval.intval *= 1024;
else if (scale == 'm' || scale == 'M')
yylval.intval *= 1024 * 1024;
return (SCALED_INT);
}
. return (INVAL); /* barf on anything else */
%%
/****************************************************************
qtstr() - shucks a quoted str, and copies it into new memory
****************************************************************/
char *
qtstr (char * instr)
{
char *ptr;
int indx;
/* skip the leading quote in the copy */
ptr = strdup(&instr[1]);
/* null out the trailing quote */
indx = strlen(ptr) - 1;
indx = (indx < 0) ? 0 : indx;
ptr[indx] = '\0';
return ptr;
} /* end qtstr */
/****************************************************************
rgstr() - shucks a decorated regular expression, and copies it
into new memory
****************************************************************/
char *
rgstr (char * instr)
{
char *ptr;
int indx;
/* skip the leading slash in the copy */
ptr = strdup(&instr[1]);
/* null out the trailing slash */
indx = strlen(ptr) - 1;
indx = (indx < 0) ? 0 : indx;
ptr[indx] = '\0';
return (ptr);
} /* end rgstr */