Home | History | Annotate | Line # | Download | only in amd
sun_map_tok.l revision 1.2.4.2
      1  1.2.4.2  haad /*	$NetBSD: sun_map_tok.l,v 1.2.4.2 2008/10/19 22:39:33 haad Exp $	*/
      2  1.2.4.2  haad 
      3  1.2.4.2  haad %{
      4  1.2.4.2  haad /*
      5  1.2.4.2  haad  * Copyright (c) 1997-2007 Erez Zadok
      6  1.2.4.2  haad  * Copyright (c) 2005 Daniel P. Ottavio
      7  1.2.4.2  haad  * Copyright (c) 1990 Jan-Simon Pendry
      8  1.2.4.2  haad  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
      9  1.2.4.2  haad  * Copyright (c) 1990 The Regents of the University of California.
     10  1.2.4.2  haad  * All rights reserved.
     11  1.2.4.2  haad  *
     12  1.2.4.2  haad  * This code is derived from software contributed to Berkeley by
     13  1.2.4.2  haad  * Jan-Simon Pendry at Imperial College, London.
     14  1.2.4.2  haad  *
     15  1.2.4.2  haad  * Redistribution and use in source and binary forms, with or without
     16  1.2.4.2  haad  * modification, are permitted provided that the following conditions
     17  1.2.4.2  haad  * are met:
     18  1.2.4.2  haad  * 1. Redistributions of source code must retain the above copyright
     19  1.2.4.2  haad  *    notice, this list of conditions and the following disclaimer.
     20  1.2.4.2  haad  * 2. Redistributions in binary form must reproduce the above copyright
     21  1.2.4.2  haad  *    notice, this list of conditions and the following disclaimer in the
     22  1.2.4.2  haad  *    documentation and/or other materials provided with the distribution.
     23  1.2.4.2  haad  * 3. All advertising materials mentioning features or use of this software
     24  1.2.4.2  haad  *    must display the following acknowledgment:
     25  1.2.4.2  haad  *      This product includes software developed by the University of
     26  1.2.4.2  haad  *      California, Berkeley and its contributors.
     27  1.2.4.2  haad  * 4. Neither the name of the University nor the names of its contributors
     28  1.2.4.2  haad  *    may be used to endorse or promote products derived from this software
     29  1.2.4.2  haad  *    without specific prior written permission.
     30  1.2.4.2  haad  *
     31  1.2.4.2  haad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     32  1.2.4.2  haad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     33  1.2.4.2  haad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     34  1.2.4.2  haad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     35  1.2.4.2  haad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.2.4.2  haad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.2.4.2  haad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.2.4.2  haad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     39  1.2.4.2  haad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     40  1.2.4.2  haad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     41  1.2.4.2  haad  * SUCH DAMAGE.
     42  1.2.4.2  haad  *
     43  1.2.4.2  haad  *
     44  1.2.4.2  haad  * File: am-utils/amd/sun_map_tok.l
     45  1.2.4.2  haad  *
     46  1.2.4.2  haad  */
     47  1.2.4.2  haad 
     48  1.2.4.2  haad #ifdef HAVE_CONFIG_H
     49  1.2.4.2  haad # include <config.h>
     50  1.2.4.2  haad #endif /* HAVE_CONFIG_H */
     51  1.2.4.2  haad /*
     52  1.2.4.2  haad  * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
     53  1.2.4.2  haad  * and their (bad) version of lex defines it too at the very beginning of
     54  1.2.4.2  haad  * the generated lex.yy.c file (before it can be easily undefined),
     55  1.2.4.2  haad  * resulting in a conflict.  So undefine it here before needed.
     56  1.2.4.2  haad  * Luckily, it does not appear that this macro is actually used in the rest
     57  1.2.4.2  haad  * of the generated lex.yy.c file.
     58  1.2.4.2  haad  */
     59  1.2.4.2  haad #ifdef ECHO
     60  1.2.4.2  haad # undef ECHO
     61  1.2.4.2  haad #endif /* ECHO */
     62  1.2.4.2  haad #include <am_defs.h>
     63  1.2.4.2  haad #include <amd.h>
     64  1.2.4.2  haad #include <sun_map_parse.h>
     65  1.2.4.2  haad /* and once again undefine this, just in case */
     66  1.2.4.2  haad #ifdef ECHO
     67  1.2.4.2  haad # undef ECHO
     68  1.2.4.2  haad #endif /* ECHO */
     69  1.2.4.2  haad 
     70  1.2.4.2  haad /*
     71  1.2.4.2  haad  * There are some things that need to be defined only if using GNU flex.
     72  1.2.4.2  haad  * These must not be defined if using standard lex
     73  1.2.4.2  haad  */
     74  1.2.4.2  haad #ifdef FLEX_SCANNER
     75  1.2.4.2  haad # ifndef ECHO
     76  1.2.4.2  haad #  define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
     77  1.2.4.2  haad # endif /* not ECHO */
     78  1.2.4.2  haad #endif /* FLEX_SCANNER */
     79  1.2.4.2  haad 
     80  1.2.4.2  haad int yylex(void);
     81  1.2.4.2  haad int yyerror(const char *);
     82  1.2.4.2  haad 
     83  1.2.4.2  haad /*
     84  1.2.4.2  haad  * We need to configure lex to parse from a string
     85  1.2.4.2  haad  * instead of a file. Each version of lex has it's
     86  1.2.4.2  haad  * own way of doing this (sigh).
     87  1.2.4.2  haad  */
     88  1.2.4.2  haad 
     89  1.2.4.2  haad /* assign the buffer to parse */
     90  1.2.4.2  haad void sun_map_tok_setbuff(const char* buff);
     91  1.2.4.2  haad 
     92  1.2.4.2  haad /* buffer that contains the string to parse */
     93  1.2.4.2  haad const char *sun_map_tok_buff = NULL;
     94  1.2.4.2  haad 
     95  1.2.4.2  haad #ifdef FLEX_SCANNER
     96  1.2.4.2  haad /*
     97  1.2.4.2  haad  * The flex scanner uses the YY_INPUT to parse the input.
     98  1.2.4.2  haad  * We need to redefine it so that it can parse strings.
     99  1.2.4.2  haad  * In addition to the above string buffer we need to have
    100  1.2.4.2  haad  * a position pointer and a end pointer.
    101  1.2.4.2  haad  */
    102  1.2.4.2  haad 
    103  1.2.4.2  haad /* current position of the buffer */
    104  1.2.4.2  haad const char *sun_map_tok_pos = NULL;
    105  1.2.4.2  haad 
    106  1.2.4.2  haad /* size of the buffer */
    107  1.2.4.2  haad const char *sun_map_tok_end = NULL;
    108  1.2.4.2  haad 
    109  1.2.4.2  haad /* copies the current position + maxsize into buff */
    110  1.2.4.2  haad int sun_map_input(char *buff, int maxsize);
    111  1.2.4.2  haad 
    112  1.2.4.2  haad # undef YY_INPUT
    113  1.2.4.2  haad # define YY_INPUT(buff,result,maxsize) (result = sun_map_input(buff,maxsize))
    114  1.2.4.2  haad 
    115  1.2.4.2  haad #else
    116  1.2.4.2  haad /*
    117  1.2.4.2  haad  * If this is not Flex than fall back to an AT&T style lex.
    118  1.2.4.2  haad  * We can parse strings by redefining input and unput.
    119  1.2.4.2  haad  */
    120  1.2.4.2  haad #undef input
    121  1.2.4.2  haad #undef unput
    122  1.2.4.2  haad #define input()  (*(char *)sun_map_tok_buff++)
    123  1.2.4.2  haad #define unput(c) (*(char *)--sun_map_tok_buff = c)
    124  1.2.4.2  haad 
    125  1.2.4.2  haad #endif /* FLEX_SCANNER */
    126  1.2.4.2  haad 
    127  1.2.4.2  haad /*
    128  1.2.4.2  haad  * some systems such as DU-4.x have a different GNU flex in /usr/bin
    129  1.2.4.2  haad  * which automatically generates yywrap macros and symbols.  So I must
    130  1.2.4.2  haad  * distinguish between them and when yywrap is actually needed.
    131  1.2.4.2  haad  */
    132  1.2.4.2  haad #if !defined(yywrap) || defined(yylex)
    133  1.2.4.2  haad int yywrap(void);
    134  1.2.4.2  haad #endif /* not yywrap or yylex */
    135  1.2.4.2  haad 
    136  1.2.4.2  haad /* no need to use yywrap() */
    137  1.2.4.2  haad #define YY_SKIP_YYWRAP
    138  1.2.4.2  haad 
    139  1.2.4.2  haad 
    140  1.2.4.2  haad int sun_map_line = 1;
    141  1.2.4.2  haad int sun_map_tokpos = 1;
    142  1.2.4.2  haad 
    143  1.2.4.2  haad %}
    144  1.2.4.2  haad 
    145  1.2.4.2  haad /* This option causes Solaris lex to fail.  Use flex.  See BUGS file */
    146  1.2.4.2  haad /* no need to use yyunput() */
    147  1.2.4.2  haad %option nounput
    148  1.2.4.2  haad 
    149  1.2.4.2  haad /* allocate more output slots so lex scanners don't run out of mem */
    150  1.2.4.2  haad %o 1024
    151  1.2.4.2  haad 
    152  1.2.4.2  haad WORD_REX       [A-Za-z0-9_/&\.$=]+[A-Za-z0-9_/&\.$=-]*
    153  1.2.4.2  haad COMMENT_REX    ^#.*\n
    154  1.2.4.2  haad WSPACE_REX     [ \t]*
    155  1.2.4.2  haad NEWLINE_REX    [ \t]*\n
    156  1.2.4.2  haad CONTINUE_REX   "\\"\n
    157  1.2.4.2  haad 
    158  1.2.4.2  haad %%
    159  1.2.4.2  haad 
    160  1.2.4.2  haad {WORD_REX}      {
    161  1.2.4.2  haad                   sun_map_tokpos += yyleng;
    162  1.2.4.2  haad                   xstrlcpy((char *)yylval.strval,(const char *)yytext,sizeof(yylval.strval));
    163  1.2.4.2  haad                   return WORD;
    164  1.2.4.2  haad                 }
    165  1.2.4.2  haad 
    166  1.2.4.2  haad {WSPACE_REX}    {
    167  1.2.4.2  haad                   sun_map_tokpos += yyleng;
    168  1.2.4.2  haad                   return WSPACE;
    169  1.2.4.2  haad                 }
    170  1.2.4.2  haad 
    171  1.2.4.2  haad {NEWLINE_REX}   {
    172  1.2.4.2  haad                   sun_map_tokpos = 0;
    173  1.2.4.2  haad                   sun_map_line++;
    174  1.2.4.2  haad                   return NEWLINE;
    175  1.2.4.2  haad                 }
    176  1.2.4.2  haad 
    177  1.2.4.2  haad {CONTINUE_REX}  {
    178  1.2.4.2  haad                   sun_map_tokpos = 0;
    179  1.2.4.2  haad                   sun_map_line++;
    180  1.2.4.2  haad                 }
    181  1.2.4.2  haad 
    182  1.2.4.2  haad {COMMENT_REX}   {
    183  1.2.4.2  haad                   sun_map_line++;
    184  1.2.4.2  haad                 }
    185  1.2.4.2  haad 
    186  1.2.4.2  haad .               {
    187  1.2.4.2  haad                   return yytext[0];
    188  1.2.4.2  haad                 }
    189  1.2.4.2  haad 
    190  1.2.4.2  haad %%
    191  1.2.4.2  haad 
    192  1.2.4.2  haad 
    193  1.2.4.2  haad int
    194  1.2.4.2  haad yyerror(const char* s)
    195  1.2.4.2  haad {
    196  1.2.4.2  haad   return 1;
    197  1.2.4.2  haad }
    198  1.2.4.2  haad 
    199  1.2.4.2  haad #ifdef FLEX_SCANNER
    200  1.2.4.2  haad void
    201  1.2.4.2  haad sun_map_tok_setbuff(const char* buff)
    202  1.2.4.2  haad {
    203  1.2.4.2  haad   sun_map_tok_end = buff + strlen(buff);
    204  1.2.4.2  haad   sun_map_tok_pos = buff;
    205  1.2.4.2  haad   sun_map_tok_buff = buff;
    206  1.2.4.2  haad }
    207  1.2.4.2  haad 
    208  1.2.4.2  haad 
    209  1.2.4.2  haad int
    210  1.2.4.2  haad sun_map_input(char *buff, int maxsize)
    211  1.2.4.2  haad {
    212  1.2.4.2  haad   int size = MIN(maxsize, (sun_map_tok_end - sun_map_tok_pos));
    213  1.2.4.2  haad   if (size > 0) {
    214  1.2.4.2  haad     memcpy(buff,sun_map_tok_pos,size);
    215  1.2.4.2  haad     sun_map_tok_pos += size;
    216  1.2.4.2  haad   }
    217  1.2.4.2  haad 
    218  1.2.4.2  haad   return size;
    219  1.2.4.2  haad }
    220  1.2.4.2  haad #else
    221  1.2.4.2  haad void
    222  1.2.4.2  haad sun_map_tok_setbuff(const char* buff)
    223  1.2.4.2  haad {
    224  1.2.4.2  haad   sun_map_tok_buff = buff;
    225  1.2.4.2  haad }
    226  1.2.4.2  haad 
    227  1.2.4.2  haad #endif /* FLEX_SCANNER */
    228  1.2.4.2  haad 
    229  1.2.4.2  haad /*
    230  1.2.4.2  haad  * some systems such as DU-4.x have a different GNU flex in /usr/bin
    231  1.2.4.2  haad  * which automatically generates yywrap macros and symbols.  So I must
    232  1.2.4.2  haad  * distinguish between them and when yywrap is actually needed.
    233  1.2.4.2  haad  */
    234  1.2.4.2  haad #if !defined(yywrap) || defined(yylex)
    235  1.2.4.2  haad int yywrap(void)
    236  1.2.4.2  haad {
    237  1.2.4.2  haad   return 1;
    238  1.2.4.2  haad }
    239  1.2.4.2  haad #endif /* not yywrap or yylex */
    240