token.l revision 250227
1156230Smux%{ 2156230Smux/*- 3156230Smux * Copyright (c) 2003-2004, Maxime Henrion <mux@FreeBSD.org> 4156230Smux * All rights reserved. 5156230Smux * 6156230Smux * Redistribution and use in source and binary forms, with or without 7156230Smux * modification, are permitted provided that the following conditions 8156230Smux * are met: 9156230Smux * 1. Redistributions of source code must retain the above copyright 10156230Smux * notice, this list of conditions and the following disclaimer. 11156230Smux * 2. Redistributions in binary form must reproduce the above copyright 12156230Smux * notice, this list of conditions and the following disclaimer in the 13156230Smux * documentation and/or other materials provided with the distribution. 14156230Smux * 15156230Smux * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16156230Smux * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17156230Smux * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18156230Smux * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19156230Smux * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20156230Smux * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21156230Smux * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22156230Smux * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23156230Smux * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24156230Smux * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25156230Smux * SUCH DAMAGE. 26156230Smux * 27156230Smux * $FreeBSD: head/usr.bin/csup/token.l 250227 2013-05-03 23:51:32Z jkim $ 28156230Smux */ 29156230Smux 30156230Smux#include <err.h> 31156230Smux#include <stdlib.h> 32156230Smux#include <string.h> 33156230Smux 34156230Smux#include "parse.h" 35156230Smux#include "misc.h" 36156230Smux#include "token.h" 37156230Smux 38156230Smuxint lineno = 1; 39156230Smux 40156230Smux%} 41156230Smux 42250227Sjkim%option nounput 43156230Smux%option noyywrap 44156230Smux 45156230Smux%% 46156230Smux 47156230Smux[ \t]+ ; 48156230Smux#.* ; 49156230Smux\*default { return DEFAULT; } 50156230Smuxbase { yylval.i = PT_BASE; return NAME; } 51156230Smuxdate { yylval.i = PT_DATE; return NAME; } 52156230Smuxhost { yylval.i = PT_HOST; return NAME; } 53156230Smuxprefix { yylval.i = PT_PREFIX; return NAME; } 54156230Smuxrelease { yylval.i = PT_RELEASE; return NAME; } 55156230Smuxtag { yylval.i = PT_TAG; return NAME; } 56156230Smuxumask { yylval.i = PT_UMASK; return NAME; } 57156230Smuxlist { yylval.i = PT_LIST; return NAME; } 58156701Smuxnorsync { yylval.i = PT_NORSYNC; return NAME; } 59156230Smux= { return EQUAL; } 60156230Smuxcompress { yylval.i = PT_COMPRESS; return BOOLEAN; } 61156230Smuxdelete { yylval.i = PT_DELETE; return BOOLEAN; } 62156230Smuxuse-rel-suffix { yylval.i = PT_USE_REL_SUFFIX; return BOOLEAN; } 63156230Smux[a-zA-Z0-9./_-]+ { 64156230Smux yylval.str = strdup(yytext); 65156230Smux if (yylval.str == NULL) 66156230Smux err(1, "strdup"); 67156230Smux return STRING; 68156230Smux } 69156230Smux\n lineno++; 70156230Smux 71156230Smux%% 72156230Smux 73156230Smuxvoid 74156230Smuxyyerror(const char *s) 75156230Smux{ 76156230Smux 77156230Smux lprintf(-1, "Parse error line %d: %s: %s\n", lineno, s, yytext); 78156230Smux exit(1); 79156230Smux} 80