1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 /* lex file for analyzing PKCS #11 Module installation instructions */
40 /*----------------------------- Definitions ---------------------------*/
44 #include "install-ds.h" /* defines tokens and data structures */
45 #include "installparse.h" /* produced by yacc -d */
47 static char *putSimpleString(char*); /* return copy of string */
48 static char *putComplexString(char*); /* strip out quotes, deal with */
49 /* escaped characters */
51 void Pk11Install_yyerror(char *);
53 /* Overrides to use NSPR */
54 #define malloc PR_Malloc
55 #define realloc PR_Realloc
58 int Pk11Install_yylinenum=1;
61 #define YY_NEVER_INTERACTIVE 1
62 #define yyunput Pkcs11Install_yyunput
64 /* This is the default YY_INPUT modified for NSPR */
65 #define YY_INPUT(buf,result,max_size) \
66 if ( yy_current_buffer->yy_is_interactive ) { \
69 for ( n = 0; n < max_size && \
70 PR_Read(Pk11Install_FD, &c, 1)==1 && c != '\n'; ++n ) { \
78 result = PR_Read(Pk11Install_FD, buf, max_size); \
83 /*** Regular expression definitions ***/
84 /* simple_string has no whitespace, quotes, or braces */
85 simple_string [^ \t\r\n\""{""}"]+
87 /* complex_string is enclosed in quotes. Inside the quotes, quotes and
88 backslashes must be backslash-escaped. No newlines or carriage returns
89 are allowed inside the quotes. Otherwise, anything goes. */
90 complex_string \"([^\"\\\r\n]|(\\\")|(\\\\))+\"
92 /* Standard whitespace */
97 /*---------------------------- Actions --------------------------------*/
100 "{" return OPENBRACE;
101 "}" return CLOSEBRACE;
102 {simple_string} {Pk11Install_yylval.string =
103 putSimpleString(Pk11Install_yytext);
105 {complex_string} {Pk11Install_yylval.string =
106 putComplexString(Pk11Install_yytext);
109 "\n" Pk11Install_yylinenum++;
113 {other} {err = PR_smprintf("Invalid lexeme: %s",Pk11Install_yytext);
114 Pk11Install_yyerror(err);
115 PR_smprintf_free(err);
120 /*------------------------ Program Section ----------------------------*/
122 PRFileDesc *Pk11Install_FD=NULL;
124 /*************************************************************************/
125 /* dummy function required by lex */
126 int Pk11Install_yywrap(void) { return 1;}
128 /*************************************************************************/
129 /* Return a copy of the given string */
131 putSimpleString(char *str)
133 char *tmp = (char*) PR_Malloc(strlen(str)+1);
138 /*************************************************************************/
139 /* Strip out quotes, replace escaped characters with what they stand for.
140 This function assumes that what is passed in is actually a complex
141 string, so error checking is lax. */
143 putComplexString(char *str)
153 /* Allocate the new space. This string will actually be too big,
154 since quotes and backslashes will be stripped out. But that's ok. */
155 tmp = (char*) PR_Malloc(size+1);
158 for(i=0, j=0; i < size; i++) {
160 continue; /* skip un-escaped quotes */
161 } else if(str[i]=='\\') {
162 ++i; /* escaped character. skip the backslash */