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