1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
/* lex file for analyzing PKCS #11 Module installation instructions */
8
/*----------------------------- Definitions ---------------------------*/
12
#include "install-ds.h" /* defines tokens and data structures */
13
#include "installparse.h" /* produced by yacc -d */
15
static char *putSimpleString(char*); /* return copy of string */
16
static char *putComplexString(char*); /* strip out quotes, deal with */
17
/* escaped characters */
19
void Pk11Install_yyerror(char *);
21
/* Overrides to use NSPR */
22
#define malloc PR_Malloc
23
#define realloc PR_Realloc
26
int Pk11Install_yylinenum=1;
29
#define YY_NEVER_INTERACTIVE 1
30
#define yyunput Pkcs11Install_yyunput
32
/* This is the default YY_INPUT modified for NSPR */
33
#define YY_INPUT(buf,result,max_size) \
34
if ( yy_current_buffer->yy_is_interactive ) { \
37
for ( n = 0; n < max_size && \
38
PR_Read(Pk11Install_FD, &c, 1)==1 && c != '\n'; ++n ) { \
46
result = PR_Read(Pk11Install_FD, buf, max_size); \
51
/*** Regular expression definitions ***/
52
/* simple_string has no whitespace, quotes, or braces */
53
simple_string [^ \t\r\n\""{""}"]+
55
/* complex_string is enclosed in quotes. Inside the quotes, quotes and
56
backslashes must be backslash-escaped. No newlines or carriage returns
57
are allowed inside the quotes. Otherwise, anything goes. */
58
complex_string \"([^\"\\\r\n]|(\\\")|(\\\\))+\"
60
/* Standard whitespace */
65
/*---------------------------- Actions --------------------------------*/
69
"}" return CLOSEBRACE;
70
{simple_string} {Pk11Install_yylval.string =
71
putSimpleString(Pk11Install_yytext);
73
{complex_string} {Pk11Install_yylval.string =
74
putComplexString(Pk11Install_yytext);
77
"\n" Pk11Install_yylinenum++;
81
{other} {err = PR_smprintf("Invalid lexeme: %s",Pk11Install_yytext);
82
Pk11Install_yyerror(err);
83
PR_smprintf_free(err);
88
/*------------------------ Program Section ----------------------------*/
90
PRFileDesc *Pk11Install_FD=NULL;
92
/*************************************************************************/
93
/* dummy function required by lex */
94
int Pk11Install_yywrap(void) { return 1;}
96
/*************************************************************************/
97
/* Return a copy of the given string */
99
putSimpleString(char *str)
101
char *tmp = (char*) PR_Malloc(strlen(str)+1);
106
/*************************************************************************/
107
/* Strip out quotes, replace escaped characters with what they stand for.
108
This function assumes that what is passed in is actually a complex
109
string, so error checking is lax. */
111
putComplexString(char *str)
121
/* Allocate the new space. This string will actually be too big,
122
since quotes and backslashes will be stripped out. But that's ok. */
123
tmp = (char*) PR_Malloc(size+1);
126
for(i=0, j=0; i < size; i++) {
128
continue; /* skip un-escaped quotes */
129
} else if(str[i]=='\\') {
130
++i; /* escaped character. skip the backslash */