summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/envilex.L
blob: 5621a04a44dea1a05ab961f16fdf2ec0ea04e43f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* Copyright (C) 1999-2018
 * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
 * For conditions of distribution and use, see copyright notice in "copyright"
 */
%option noyywrap
%option caseless
%option never-interactive
%option c++

%{
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>

  #include "util.h"
  #include "enviparser.H"

  extern YYSTYPE* envilval;
  extern enviFlexLexer* envilexx;
%}

%x DISCARD
%x BRACKET

D   [0-9]
E   [Ee][+-]?{D}+

/* rules */

%%

<DISCARD>[\n]	{ // special case-- #\n
		  BEGIN INITIAL;
		  yyless(0);             // put back the terminator
		  strcpy(envilval->str,""); // feed a blank string
		  return STRING;
		}

<DISCARD>[^\n]* {  // Discard reset of line
		  BEGIN INITIAL;
		  int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
		  strncpy(envilval->str,yytext,ll);
	          envilval->str[ll] = '\0';
		  return STRING;
		}

\{               {
                  BEGIN BRACKET;
                  return '{';
                }

<BRACKET>\}      {
		  BEGIN INITIAL;
                  return '}';
                }

debug           {return DEBUG_;}
on              {return ON_;}
off             {return OFF_;}

average         {return AVERAGE_;}
band            {return BAND_;}
bands           {return BANDS_;}
bbl             {return BBL_;}
bil             {return BIL_;}
bip             {return BIP_;}
bsq             {return BSQ_;}
byte            {return BYTE_;}
envi            {return ENVI_;}
data            {return DATA_;}
default         {return DEFAULT_;}
description     {return DESCRIPTION_;}
factor          {return FACTOR_;}
frame           {return FRAME_;}
file            {return FILE_;}
fwhm            {return FWHM_;}
gain            {return GAIN_;}
header          {return HEADER_;}
info            {return INFO_;}
ignore          {return IGNORE_;}
interleave      {return INTERLEAVE_;}
limits          {return LIMITS_;}
lines           {return LINES_;}
major           {return MAJOR_;}
map             {return MAP_;}
minor           {return MINOR_;}
names           {return NAMES_;}
offset          {return OFFSET_;}
offsets         {return OFFSETS_;}
order           {return ORDER_;}
pixel           {return PIXEL_;}
pixels          {return PIXELS_;}
plot            {return PLOT_;}
projection      {return PROJECTION_;}
range           {return RANGE_;}
reflectance     {return REFLECTANCE_;}
samples         {return SAMPLES_;}
scale           {return SCALE_;}
scanner         {return SCANNER_;}
sensor          {return SENSOR_;}
size            {return SIZE_;}
stretch         {return STRETCH_;}
titles          {return TITLES_;}
type            {return TYPE_;}
units           {return UNITS_;}
value           {return VALUE_;}
values          {return VALUES_;}
wavelength      {return WAVELENGTH_;}


<BRACKET>[+-]?{D}+ { // Integer
		  envilval->integer = atoi(yytext);
		  return INT;
		}

<BRACKET>[+-]?{D}+"."?({E})? |
<BRACKET>[+-]?{D}*"."{D}+({E})? { // Real Number
		  envilval->real = atof(yytext);
		  return REAL;
		}


<BRACKET>[0-9A-Za-z\-]+	{ // General String
		  int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
		  strncpy(envilval->str,yytext,ll);
	          envilval->str[ll] = '\0';
		  return STRING;
		}

<BRACKET>,      {
                  return ',';
                }

<BRACKET>[ \t]+	{ // White Spaces
		} 

<BRACKET>\n	{ // linefeed
		}

<BRACKET>.      { // other chars, eat it
                }

[+-]?{D}+	{ // Integer
		  envilval->integer = atoi(yytext);
		  return INT;
		}

[+-]?{D}+"."?({E})? |
[+-]?{D}*"."{D}+({E})? { // Real Number
		  envilval->real = atof(yytext);
		  return REAL;
		}


[0-9A-Za-z]+	{ // General String
		  int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
		  strncpy(envilval->str,yytext,ll);
	          envilval->str[ll] = '\0';
		  return STRING;
		}

[ \t]+		{ // White Spaces
		} 

\r\n		{ // windows line feed
		  return '\n';
		}

\n		{ // linefeed
		  return '\n';
		}

<<EOF>>		{ // eof
		  return EOF_;
		}

.		{ // Else, return the char
		  return yytext[0];
		}

%%

void enviDiscard(int doit)
{
  if (envilexx)
    envilexx->begin(DISCARD, doit);
}

void enviFlexLexer::begin(int which, int doit)
{
  BEGIN which;
  if (doit)
    yyless(0);
}