xref: /freebsd/usr.bin/ar/acplex.l (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
10c099281SKai Wang %{
20c099281SKai Wang /*-
3*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
41de7b4b8SPedro F. Giffuni  *
50c099281SKai Wang  * Copyright (c) 2008 Kai Wang
60c099281SKai Wang  * All rights reserved.
70c099281SKai Wang  *
80c099281SKai Wang  * Redistribution and use in source and binary forms, with or without
90c099281SKai Wang  * modification, are permitted provided that the following conditions
100c099281SKai Wang  * are met:
110c099281SKai Wang  * 1. Redistributions of source code must retain the above copyright
1225f82d56SEd Maste  *    notice, this list of conditions and the following disclaimer.
130c099281SKai Wang  * 2. Redistributions in binary form must reproduce the above copyright
140c099281SKai Wang  *    notice, this list of conditions and the following disclaimer in the
150c099281SKai Wang  *    documentation and/or other materials provided with the distribution.
160c099281SKai Wang  *
1725f82d56SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1825f82d56SEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1925f82d56SEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2025f82d56SEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2125f82d56SEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2225f82d56SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2325f82d56SEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2425f82d56SEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525f82d56SEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2625f82d56SEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2725f82d56SEd Maste  * SUCH DAMAGE.
280c099281SKai Wang  */
290c099281SKai Wang 
300c099281SKai Wang #include <sys/cdefs.h>
310c099281SKai Wang #include <err.h>
320c099281SKai Wang #include <errno.h>
330c099281SKai Wang #include <stdio.h>
3438911b3cSEd Maste #include <stdlib.h>
350c099281SKai Wang #include <string.h>
360c099281SKai Wang 
370c099281SKai Wang #include "y.tab.h"
380c099281SKai Wang 
390c099281SKai Wang int lineno = 1;
400c099281SKai Wang 
410c099281SKai Wang int	yylex(void);
420c099281SKai Wang 
439c5a52cfSJung-uk Kim #define	YY_DECL	int yylex(void)
449c5a52cfSJung-uk Kim 
450c099281SKai Wang %}
460c099281SKai Wang 
47a7880d59SJung-uk Kim %option nounput
48a7880d59SJung-uk Kim %option noinput
490c099281SKai Wang %option noyywrap
500c099281SKai Wang 
510c099281SKai Wang %%
520c099281SKai Wang 
530c099281SKai Wang ADDLIB|addlib		{ return (ADDLIB); }
540c099281SKai Wang ADDMOD|addmod		{ return (ADDMOD); }
550c099281SKai Wang CLEAR|clear		{ return (CLEAR); }
560c099281SKai Wang CREATE|create		{ return (CREATE); }
570c099281SKai Wang DELETE|delete		{ return (DELETE); }
580c099281SKai Wang DIRECTORY|directory	{ return (DIRECTORY); }
590c099281SKai Wang END|end			{ return (END); }
600c099281SKai Wang EXTRACT|extract		{ return (EXTRACT); }
610c099281SKai Wang LIST|list		{ return (LIST); }
620c099281SKai Wang OPEN|open		{ return (OPEN); }
630c099281SKai Wang REPLACE|replace		{ return (REPLACE); }
640c099281SKai Wang VERBOSE|verbose		{ return (VERBOSE); }
650c099281SKai Wang SAVE|save		{ return (SAVE); }
660c099281SKai Wang "("			{ return (LP); }
670c099281SKai Wang ")"			{ return (RP); }
680c099281SKai Wang ","			{ return (COMMA); }
690c099281SKai Wang 
700c099281SKai Wang [-_A-Za-z0-9/:$.\\]+	{
710c099281SKai Wang 	yylval.str = strdup(yytext);
720c099281SKai Wang 	if (yylval.str == NULL)
7338911b3cSEd Maste 		errc(EXIT_FAILURE, errno, "strdup failed");
740c099281SKai Wang 	return (FNAME);
750c099281SKai Wang }
760c099281SKai Wang 
770c099281SKai Wang [ \t]			/* whitespace */
780c099281SKai Wang "*".*			/* comment */
790c099281SKai Wang ";".*			/* comment */
800c099281SKai Wang "+\n"			{ lineno++; /* '+' is line continuation char */ }
810c099281SKai Wang "\n"			{ lineno++; return (EOL); }
82