0c80c3e07dddf2d3f1b2ae0542a9581503197541
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / compression / ps.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* A lexical scanner generated by flex */
24
25 /* scanner skeleton version:
26  * $XConsortium: ps.cc /main/5 1996/08/05 17:05:45 drk $
27  */
28
29 #define FLEX_SCANNER
30
31 #include <stdio.h>
32
33
34 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
35 #ifdef c_plusplus
36 #ifndef __cplusplus
37 #define __cplusplus
38 #endif
39 #endif
40
41
42 #ifdef __cplusplus
43
44 #include <stdlib.h>
45
46 #if defined(__osf__) || defined(linux) || defined(CSRG_BASED) || defined(sun)
47 #include <unistd.h>
48 #else
49 #if !defined(USL)
50 #include <osfcn.h>
51 #endif
52 #endif
53
54 /* use prototypes in function declarations */
55 #define ps_USE_PROTOS
56
57 /* the "const" storage-class-modifier is valid */
58 #define ps_USE_CONST
59
60 #else   /* ! __cplusplus */
61
62 #ifdef __STDC__
63
64 #ifdef __GNUC__
65 #include <stddef.h>
66 void *malloc( size_t );
67 void free( void* );
68 #else
69 #include <stdlib.h>
70 #endif  /* __GNUC__ */
71
72 #define ps_USE_PROTOS
73 #define ps_USE_CONST
74
75 #endif  /* __STDC__ */
76 #endif  /* ! __cplusplus */
77
78
79 #ifdef __TURBOC__
80 #define ps_USE_CONST
81 #endif
82
83
84 #ifndef ps_USE_CONST
85 #define const
86 #endif
87
88
89 #ifdef ps_USE_PROTOS
90 #define ps_PROTO(proto) proto
91 #else
92 #define ps_PROTO(proto) ()
93 /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
94  * so it's got to be a K&R compiler, and therefore there's no standard
95  * place from which to include these definitions
96  */
97 char *malloc();
98 int free();
99 int read();
100 #endif
101
102
103 /* amount of stuff to slurp up with each read */
104 #ifndef ps_READ_BUF_SIZE
105 #define ps_READ_BUF_SIZE 8192
106 #endif
107
108 /* returned upon end-of-file */
109 #define ps_END_TOK 0
110
111 /* copy whatever the last rule matched to the standard output */
112
113 /* cast to (char *) is because for 8-bit chars, pstext is (unsigned char *) */
114 /* this used to be an fputs(), but since the string might contain NUL's,
115  * we now use fwrite()
116  */
117 #define ECHO (void) fwrite( (char *) pstext, psleng, 1, psout )
118
119 /* gets input and stuffs it into "buf".  number of characters read, or ps_NULL,
120  * is returned in "result".
121  */
122 #define ps_INPUT(buf,result,max_size) \
123         if ( (result = read( fileno(psin), (char *) buf, max_size )) < 0 ) \
124             ps_FATAL_ERROR( "read() in flex scanner failed" );
125 #define ps_NULL 0
126
127 /* no semi-colon after return; correct usage is to write "psterminate();" -
128  * we don't want an extra ';' after the "return" because that will cause
129  * some compilers to complain about unreachable statements.
130  */
131 #define psterminate() return ( ps_NULL )
132
133 /* report a fatal error */
134
135 /* The funky do-while is used to turn this macro definition into
136  * a single C statement (which needs a semi-colon terminator).
137  * This avoids problems with code like:
138  *
139  *      if ( something_happens )
140  *              ps_FATAL_ERROR( "oops, the something happened" );
141  *      else
142  *              everything_okay();
143  *
144  * Prior to using the do-while the compiler would get upset at the
145  * "else" because it interpreted the "if" statement as being all
146  * done when it reached the ';' after the ps_FATAL_ERROR() call.
147  */
148
149 #define ps_FATAL_ERROR(msg) \
150         do \
151                 { \
152                 (void) fputs( msg, stderr ); \
153                 (void) putc( '\n', stderr ); \
154                 exit( 1 ); \
155                 } \
156         while ( 0 )
157
158 /* default pswrap function - always treat EOF as an EOF */
159 #define pswrap() 1
160
161 /* enter a start condition.  This macro really ought to take a parameter,
162  * but we do it the disgusting crufty way forced on us by the ()-less
163  * definition of BEGIN
164  */
165 #define BEGIN ps_start = 1 + 2 *
166
167 /* action number for EOF rule of a given start state */
168 #define ps_STATE_EOF(state) (ps_END_OF_BUFFER + state + 1)
169
170 /* special action meaning "start processing a new file" */
171 #define ps_NEW_FILE \
172         do \
173                 { \
174                 ps_init_buffer( ps_current_buffer, psin ); \
175                 ps_load_buffer_state(); \
176                 } \
177         while ( 0 )
178
179 /* default declaration of generated scanner - a define so the user can
180  * easily add parameters
181  */
182 #define ps_DECL int pslex ps_PROTO(( void )) 
183
184 /* code executed at the end of each rule */
185 #define ps_BREAK break;
186
187 #define ps_END_OF_BUFFER_CHAR 0
188
189 #ifndef ps_BUF_SIZE
190 #define ps_BUF_SIZE (ps_READ_BUF_SIZE * 2) /* size of default input buffer */
191 #endif
192
193 typedef struct ps_buffer_state *ps_BUFFER_STATE;
194
195 #define ps_CHAR unsigned char
196 # line 1 "ps.l"
197 #define INITIAL 0
198 /*
199 * $XConsortium: ps.cc /main/5 1996/08/05 17:05:45 drk $
200 *
201 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
202 * All rights reserved.  Unpublished -- rights reserved under
203 * the Copyright Laws of the United States.  USE OF A COPYRIGHT
204 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
205 * OR DISCLOSURE.
206
207 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
208 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
209 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
210 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
211 * INTERNATIONAL, LTD.
212
213 *                         RESTRICTED RIGHTS LEGEND
214 * Use, duplication, or disclosure by the Government is subject
215 * to the restrictions as set forth in subparagraph (c)(l)(ii)
216 * of the Rights in Technical Data and Computer Software clause
217 * at DFARS 252.227-7013.
218 *
219 *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
220 *                  1315 Dell Avenue
221 *                  Campbell, CA  95008
222
223 */
224 # line 37 "ps.l"
225
226 #include "compression/trie.h"
227 #include "compression/abs_agent.h"
228
229 static unsigned char psbuf[LBUFSIZ];
230 static int psbuf_sz = LBUFSIZ;
231 static int psbuffed = 0;
232               
233 #undef pswrap
234 int pswrap();
235
236 #undef ps_INPUT
237 #define ps_INPUT(buf,result,max_size) \
238    { \
239       result = (*fill_buf_func)((unsigned char*)buf,max_size); \
240    }
241
242
243 # line 57 "ps.l"
244
245 /* done after the current pattern has been matched and before the
246  * corresponding action - sets up pstext
247  */
248 #define ps_DO_BEFORE_ACTION \
249         pstext = ps_bp; \
250         psleng = ps_cp - ps_bp; \
251         ps_hold_char = *ps_cp; \
252         *ps_cp = '\0'; \
253         ps_c_buf_p = ps_cp;
254
255 #define EOB_ACT_CONTINUE_SCAN 0
256 #define EOB_ACT_END_OF_FILE 1
257 #define EOB_ACT_LAST_MATCH 2
258
259 /* return all but the first 'n' matched characters back to the input stream */
260 #define psless(n) \
261         do \
262                 { \
263                 /* undo effects of setting up pstext */ \
264                 *ps_cp = ps_hold_char; \
265                 ps_c_buf_p = ps_cp = ps_bp + n; \
266                 ps_DO_BEFORE_ACTION; /* set up pstext again */ \
267                 } \
268         while ( 0 )
269
270 #define unput(c) psunput( c, pstext )
271
272
273 struct ps_buffer_state
274     {
275     FILE *ps_input_file;
276
277     ps_CHAR *ps_ch_buf;         /* input buffer */
278     ps_CHAR *ps_buf_pos;        /* current position in input buffer */
279
280     /* size of input buffer in bytes, not including room for EOB characters*/
281     int ps_buf_size;    
282
283     /* number of characters read into ps_ch_buf, not including EOB characters */
284     int ps_n_chars;
285
286     int ps_eof_status;          /* whether we've seen an EOF on this buffer */
287 #define EOF_NOT_SEEN 0
288     /* "pending" happens when the EOF has been seen but there's still
289      * some text process
290      */
291 #define EOF_PENDING 1
292 #define EOF_DONE 2
293     };
294
295 static ps_BUFFER_STATE ps_current_buffer;
296
297 /* we provide macros for accessing buffer states in case in the
298  * future we want to put the buffer states in a more general
299  * "scanner state"
300  */
301 #define ps_CURRENT_BUFFER ps_current_buffer
302
303
304 /* ps_hold_char holds the character lost when pstext is formed */
305 static ps_CHAR ps_hold_char;
306
307 static int ps_n_chars;          /* number of characters read into ps_ch_buf */
308
309
310
311 #ifndef ps_USER_ACTION
312 #define ps_USER_ACTION
313 #endif
314
315 #ifndef ps_USER_INIT
316 #define ps_USER_INIT
317 #endif
318
319 extern ps_CHAR *pstext;
320 extern int psleng;
321 extern FILE *psin, *psout;
322
323 ps_CHAR *pstext;
324 int psleng;
325
326 FILE *psin = (FILE *) 0, *psout = (FILE *) 0;
327
328 #define ps_END_OF_BUFFER 3
329 typedef int ps_state_type;
330 static const short int ps_accept[6] =
331     {   0,
332         0,    0,    3,    1,    0
333     } ;
334
335 static const ps_CHAR ps_ec[256] =
336     {   0,
337         1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
338         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
339         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
340         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
341         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
342         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
343         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
344         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
345         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
346         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
347
348         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
349         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
350         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
351         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
352         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
353         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
354         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
355         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
356         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
357         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
358
359         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
360         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
361         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
362         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
363         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
364         1,    1,    1,    1,    1
365     } ;
366
367 static const ps_CHAR ps_meta[3] =
368     {   0,
369         1,    1
370     } ;
371
372 static const short int ps_base[6] =
373     {   0,
374         0,    0,    3,    4,    4
375     } ;
376
377 static const short int ps_def[6] =
378     {   0,
379         5,    1,    5,    5,    0
380     } ;
381
382 static const short int ps_nxt[7] =
383     {   0,
384         4,    4,    5,    3,    5,    5
385     } ;
386
387 static const short int ps_chk[7] =
388     {   0,
389         1,    1,    3,    5,    5,    5
390     } ;
391
392 static ps_state_type ps_last_accepting_state;
393 static ps_CHAR *ps_last_accepting_cpos;
394
395 /* the intent behind this definition is that it'll catch
396  * any uses of REJECT which flex missed
397  */
398 #define REJECT reject_used_but_not_detected
399 #define psmore() psmore_used_but_not_detected
400 #define ps_MORE_ADJ 0
401
402 /* these variables are all declared out here so that section 3 code can
403  * manipulate them
404  */
405 /* points to current character in buffer */
406 static ps_CHAR *ps_c_buf_p = (ps_CHAR *) 0;
407 static int ps_init = 1;         /* whether we need to initialize */
408 static int ps_start = 0;        /* start state number */
409
410 /* flag which is used to allow pswrap()'s to do buffer switches
411  * instead of setting up a fresh psin.  A bit of a hack ...
412  */
413 static int ps_did_buffer_switch_on_eof;
414
415 static ps_state_type ps_get_previous_state ps_PROTO(( void ));
416 static ps_state_type ps_try_NUL_trans ps_PROTO(( ps_state_type current_state ));
417 static int ps_get_next_buffer ps_PROTO(( void ));
418 #if 0
419 static void psunput ps_PROTO(( ps_CHAR c, ps_CHAR *buf_ptr ));
420 #endif
421 void psrestart ps_PROTO(( FILE *input_file ));
422 void ps_switch_to_buffer ps_PROTO(( ps_BUFFER_STATE new_buffer ));
423 void ps_load_buffer_state ps_PROTO(( void ));
424 ps_BUFFER_STATE ps_create_buffer ps_PROTO(( FILE *file, int size ));
425 void ps_delete_buffer ps_PROTO(( ps_BUFFER_STATE b ));
426 void ps_init_buffer ps_PROTO(( ps_BUFFER_STATE b, FILE *file ));
427
428 #define ps_new_buffer ps_create_buffer
429
430 #if 0
431 #ifdef __cplusplus
432 static int psinput ps_PROTO(( void ));
433 #else
434 static int input ps_PROTO(( void ));
435 #endif
436 #endif
437
438 ps_DECL
439     {
440     register ps_state_type ps_current_state;
441     register ps_CHAR *ps_cp, *ps_bp;
442     register int ps_act;
443
444
445
446
447     if ( ps_init )
448         {
449         ps_USER_INIT;
450
451         if ( ! ps_start )
452             ps_start = 1;       /* first start state */
453
454         if ( ! psin )
455             psin = stdin;
456
457         if ( ! psout )
458             psout = stdout;
459
460         if ( ps_current_buffer )
461             ps_init_buffer( ps_current_buffer, psin );
462         else
463             ps_current_buffer = ps_create_buffer( psin, ps_BUF_SIZE );
464
465         ps_load_buffer_state();
466
467         ps_init = 0;
468         }
469
470     while ( 1 )         /* loops until end-of-file is reached */
471         {
472         ps_cp = ps_c_buf_p;
473
474         /* support of pstext */
475         *ps_cp = ps_hold_char;
476
477         /* ps_bp points to the position in ps_ch_buf of the start of the
478          * current run.
479          */
480         ps_bp = ps_cp;
481
482         ps_current_state = ps_start;
483 ps_match:
484         do
485             {
486             register ps_CHAR ps_c = ps_ec[*ps_cp];
487             if ( ps_accept[ps_current_state] )
488                 {
489                 ps_last_accepting_state = ps_current_state;
490                 ps_last_accepting_cpos = ps_cp;
491                 }
492             while ( ps_chk[ps_base[ps_current_state] + ps_c] != ps_current_state )
493                 {
494                 ps_current_state = ps_def[ps_current_state];
495                 if ( ps_current_state >= 6 )
496                     ps_c = ps_meta[ps_c];
497                 }
498             ps_current_state = ps_nxt[ps_base[ps_current_state] + ps_c];
499             ++ps_cp;
500             }
501         while ( ps_current_state != 5 );
502         ps_cp = ps_last_accepting_cpos;
503         ps_current_state = ps_last_accepting_state;
504
505 ps_find_action:
506         ps_act = ps_accept[ps_current_state];
507
508         ps_DO_BEFORE_ACTION;
509         ps_USER_ACTION;
510
511 do_action:      /* this label is used only to access EOF actions */
512
513
514         switch ( ps_act )
515             {
516             case 0: /* must backtrack */
517             /* undo the effects of ps_DO_BEFORE_ACTION */
518             *ps_cp = ps_hold_char;
519             ps_cp = ps_last_accepting_cpos;
520             ps_current_state = ps_last_accepting_state;
521             goto ps_find_action;
522
523 case 1:
524 # line 59 "ps.l"
525 {
526            if ( psbuffed >= psbuf_sz ) {
527               //alphabet -> add_letters( psbuf, psbuf_sz );
528               (*lex_action_func)(psbuf, psbuf_sz, 2);
529               psbuffed = 0;
530            }
531
532            psbuf[psbuffed++] = pstext[0];
533         }
534         ps_BREAK
535 case 2:
536 # line 70 "ps.l"
537 ps_FATAL_ERROR( "flex scanner jammed" );
538         ps_BREAK
539 case ps_STATE_EOF(INITIAL):
540     psterminate();
541
542             case ps_END_OF_BUFFER:
543                 {
544                 /* amount of text matched not including the EOB char */
545                 int ps_amount_of_matched_text = ps_cp - pstext - 1;
546
547                 /* undo the effects of ps_DO_BEFORE_ACTION */
548                 *ps_cp = ps_hold_char;
549
550                 /* note that here we test for ps_c_buf_p "<=" to the position
551                  * of the first EOB in the buffer, since ps_c_buf_p will
552                  * already have been incremented past the NUL character
553                  * (since all states make transitions on EOB to the end-
554                  * of-buffer state).  Contrast this with the test in psinput().
555                  */
556                 if ( ps_c_buf_p <= &ps_current_buffer->ps_ch_buf[ps_n_chars] )
557                     /* this was really a NUL */
558                     {
559                     ps_state_type ps_next_state;
560
561                     ps_c_buf_p = pstext + ps_amount_of_matched_text;
562
563                     ps_current_state = ps_get_previous_state();
564
565                     /* okay, we're now positioned to make the
566                      * NUL transition.  We couldn't have
567                      * ps_get_previous_state() go ahead and do it
568                      * for us because it doesn't know how to deal
569                      * with the possibility of jamming (and we
570                      * don't want to build jamming into it because
571                      * then it will run more slowly)
572                      */
573
574                     ps_next_state = ps_try_NUL_trans( ps_current_state );
575
576                     ps_bp = pstext + ps_MORE_ADJ;
577
578                     if ( ps_next_state )
579                         {
580                         /* consume the NUL */
581                         ps_cp = ++ps_c_buf_p;
582                         ps_current_state = ps_next_state;
583                         goto ps_match;
584                         }
585
586                     else
587                         {
588                             ps_cp = ps_last_accepting_cpos;
589                             ps_current_state = ps_last_accepting_state;
590                         goto ps_find_action;
591                         }
592                     }
593
594                 else switch ( ps_get_next_buffer() )
595                     {
596                     case EOB_ACT_END_OF_FILE:
597                         {
598                         ps_did_buffer_switch_on_eof = 0;
599
600                         if ( pswrap() )
601                             {
602                             /* note: because we've taken care in
603                              * ps_get_next_buffer() to have set up pstext,
604                              * we can now set up ps_c_buf_p so that if some
605                              * total hoser (like flex itself) wants
606                              * to call the scanner after we return the
607                              * ps_NULL, it'll still work - another ps_NULL
608                              * will get returned.
609                              */
610                             ps_c_buf_p = pstext + ps_MORE_ADJ;
611
612                             ps_act = ps_STATE_EOF((ps_start - 1) / 2);
613                             goto do_action;
614                             }
615
616                         else
617                             {
618                             if ( ! ps_did_buffer_switch_on_eof )
619                                 ps_NEW_FILE;
620                             }
621                         }
622                         break;
623
624                     case EOB_ACT_CONTINUE_SCAN:
625                         ps_c_buf_p = pstext + ps_amount_of_matched_text;
626
627                         ps_current_state = ps_get_previous_state();
628
629                         ps_cp = ps_c_buf_p;
630                         ps_bp = pstext + ps_MORE_ADJ;
631                         goto ps_match;
632
633                     case EOB_ACT_LAST_MATCH:
634                         ps_c_buf_p =
635                             &ps_current_buffer->ps_ch_buf[ps_n_chars];
636
637                         ps_current_state = ps_get_previous_state();
638
639                         ps_cp = ps_c_buf_p;
640                         ps_bp = pstext + ps_MORE_ADJ;
641                         goto ps_find_action;
642                     }
643                 break;
644                 }
645
646             default:
647 #ifdef FLEX_DEBUG
648                 printf( "action # %d\n", ps_act );
649 #endif
650                 ps_FATAL_ERROR(
651                         "fatal flex scanner internal error--no action found" );
652             }
653         }
654     }
655
656
657 /* ps_get_next_buffer - try to read in a new buffer
658  *
659  * synopsis
660  *     int ps_get_next_buffer();
661  *     
662  * returns a code representing an action
663  *     EOB_ACT_LAST_MATCH - 
664  *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
665  *     EOB_ACT_END_OF_FILE - end of file
666  */
667
668 static int ps_get_next_buffer()
669
670     {
671     register ps_CHAR *dest = ps_current_buffer->ps_ch_buf;
672     register ps_CHAR *source = pstext - 1; /* copy prev. char, too */
673     register int number_to_move, i;
674     int ret_val;
675
676     if ( ps_c_buf_p > &ps_current_buffer->ps_ch_buf[ps_n_chars + 1] )
677         ps_FATAL_ERROR(
678                 "fatal flex scanner internal error--end of buffer missed" );
679
680     /* try to read more data */
681
682     /* first move last chars to start of buffer */
683     number_to_move = ps_c_buf_p - pstext;
684
685     for ( i = 0; i < number_to_move; ++i )
686         *(dest++) = *(source++);
687
688     if ( ps_current_buffer->ps_eof_status != EOF_NOT_SEEN )
689         /* don't do the read, it's not guaranteed to return an EOF,
690          * just force an EOF
691          */
692         ps_n_chars = 0;
693
694     else
695         {
696         int num_to_read = ps_current_buffer->ps_buf_size - number_to_move - 1;
697
698         if ( num_to_read > ps_READ_BUF_SIZE )
699             num_to_read = ps_READ_BUF_SIZE;
700
701         else if ( num_to_read <= 0 )
702             ps_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
703
704         /* read in more data */
705         ps_INPUT( (&ps_current_buffer->ps_ch_buf[number_to_move]),
706                   ps_n_chars, num_to_read );
707         }
708
709     if ( ps_n_chars == 0 )
710         {
711         if ( number_to_move == 1 )
712             {
713             ret_val = EOB_ACT_END_OF_FILE;
714             ps_current_buffer->ps_eof_status = EOF_DONE;
715             }
716
717         else
718             {
719             ret_val = EOB_ACT_LAST_MATCH;
720             ps_current_buffer->ps_eof_status = EOF_PENDING;
721             }
722         }
723
724     else
725         ret_val = EOB_ACT_CONTINUE_SCAN;
726
727     ps_n_chars += number_to_move;
728     ps_current_buffer->ps_ch_buf[ps_n_chars] = ps_END_OF_BUFFER_CHAR;
729     ps_current_buffer->ps_ch_buf[ps_n_chars + 1] = ps_END_OF_BUFFER_CHAR;
730
731     /* pstext begins at the second character in ps_ch_buf; the first
732      * character is the one which preceded it before reading in the latest
733      * buffer; it needs to be kept around in case it's a newline, so
734      * ps_get_previous_state() will have with '^' rules active
735      */
736
737     pstext = &ps_current_buffer->ps_ch_buf[1];
738
739     return ( ret_val );
740     }
741
742
743 /* ps_get_previous_state - get the state just before the EOB char was reached
744  *
745  * synopsis
746  *     ps_state_type ps_get_previous_state();
747  */
748
749 static ps_state_type ps_get_previous_state()
750
751     {
752     register ps_state_type ps_current_state;
753     register ps_CHAR *ps_cp;
754
755     ps_current_state = ps_start;
756
757     for ( ps_cp = pstext + ps_MORE_ADJ; ps_cp < ps_c_buf_p; ++ps_cp )
758         {
759         register ps_CHAR ps_c = (*ps_cp ? ps_ec[*ps_cp] : 1);
760         if ( ps_accept[ps_current_state] )
761             {
762             ps_last_accepting_state = ps_current_state;
763             ps_last_accepting_cpos = ps_cp;
764             }
765         while ( ps_chk[ps_base[ps_current_state] + ps_c] != ps_current_state )
766             {
767             ps_current_state = ps_def[ps_current_state];
768             if ( ps_current_state >= 6 )
769                 ps_c = ps_meta[ps_c];
770             }
771         ps_current_state = ps_nxt[ps_base[ps_current_state] + ps_c];
772         }
773
774     return ( ps_current_state );
775     }
776
777
778 /* ps_try_NUL_trans - try to make a transition on the NUL character
779  *
780  * synopsis
781  *     next_state = ps_try_NUL_trans( current_state );
782  */
783
784 #ifdef ps_USE_PROTOS
785 static ps_state_type ps_try_NUL_trans( register ps_state_type ps_current_state )
786 #else
787 static ps_state_type ps_try_NUL_trans( ps_current_state )
788 register ps_state_type ps_current_state;
789 #endif
790
791     {
792     register int ps_is_jam;
793     register ps_CHAR *ps_cp = ps_c_buf_p;
794
795     register ps_CHAR ps_c = 1;
796     if ( ps_accept[ps_current_state] )
797         {
798         ps_last_accepting_state = ps_current_state;
799         ps_last_accepting_cpos = ps_cp;
800         }
801     while ( ps_chk[ps_base[ps_current_state] + ps_c] != ps_current_state )
802         {
803         ps_current_state = ps_def[ps_current_state];
804         if ( ps_current_state >= 6 )
805             ps_c = ps_meta[ps_c];
806         }
807     ps_current_state = ps_nxt[ps_base[ps_current_state] + ps_c];
808     ps_is_jam = (ps_current_state == 5);
809
810     return ( ps_is_jam ? 0 : ps_current_state );
811     }
812
813
814 #if 0
815 #ifdef ps_USE_PROTOS
816 static void psunput( ps_CHAR c, register ps_CHAR *ps_bp )
817 #else
818 static void psunput( c, ps_bp )
819 ps_CHAR c;
820 register ps_CHAR *ps_bp;
821 #endif
822
823     {
824     register ps_CHAR *ps_cp = ps_c_buf_p;
825
826     /* undo effects of setting up pstext */
827     *ps_cp = ps_hold_char;
828
829     if ( ps_cp < ps_current_buffer->ps_ch_buf + 2 )
830         { /* need to shift things up to make room */
831         register int number_to_move = ps_n_chars + 2; /* +2 for EOB chars */
832         register ps_CHAR *dest =
833             &ps_current_buffer->ps_ch_buf[ps_current_buffer->ps_buf_size + 2];
834         register ps_CHAR *source =
835             &ps_current_buffer->ps_ch_buf[number_to_move];
836
837         while ( source > ps_current_buffer->ps_ch_buf )
838             *--dest = *--source;
839
840         ps_cp += dest - source;
841         ps_bp += dest - source;
842         ps_n_chars = ps_current_buffer->ps_buf_size;
843
844         if ( ps_cp < ps_current_buffer->ps_ch_buf + 2 )
845             ps_FATAL_ERROR( "flex scanner push-back overflow" );
846         }
847
848     if ( ps_cp > ps_bp && ps_cp[-1] == '\n' )
849         ps_cp[-2] = '\n';
850
851     *--ps_cp = c;
852
853     /* note: the formal parameter *must* be called "ps_bp" for this
854      *       macro to now work correctly
855      */
856     ps_DO_BEFORE_ACTION; /* set up pstext again */
857     }
858 #endif
859
860
861 #if 0
862 #ifdef __cplusplus
863 static int psinput()
864 #else
865 static int input()
866 #endif
867
868     {
869     int c;
870     ps_CHAR *ps_cp = ps_c_buf_p;
871
872     *ps_cp = ps_hold_char;
873
874     if ( *ps_c_buf_p == ps_END_OF_BUFFER_CHAR )
875         {
876         /* ps_c_buf_p now points to the character we want to return.
877          * If this occurs *before* the EOB characters, then it's a
878          * valid NUL; if not, then we've hit the end of the buffer.
879          */
880         if ( ps_c_buf_p < &ps_current_buffer->ps_ch_buf[ps_n_chars] )
881             /* this was really a NUL */
882             *ps_c_buf_p = '\0';
883
884         else
885             { /* need more input */
886             pstext = ps_c_buf_p;
887             ++ps_c_buf_p;
888
889             switch ( ps_get_next_buffer() )
890                 {
891                 case EOB_ACT_END_OF_FILE:
892                     {
893                     if ( pswrap() )
894                         {
895                         ps_c_buf_p = pstext + ps_MORE_ADJ;
896                         return ( EOF );
897                         }
898
899                     ps_NEW_FILE;
900
901 #ifdef __cplusplus
902                     return ( psinput() );
903 #else
904                     return ( input() );
905 #endif
906                     }
907                     break;
908
909                 case EOB_ACT_CONTINUE_SCAN:
910                     ps_c_buf_p = pstext + ps_MORE_ADJ;
911                     break;
912
913                 case EOB_ACT_LAST_MATCH:
914 #ifdef __cplusplus
915                     ps_FATAL_ERROR( "unexpected last match in psinput()" );
916 #else
917                     ps_FATAL_ERROR( "unexpected last match in input()" );
918 #endif
919                 }
920             }
921         }
922
923     c = *ps_c_buf_p;
924     ps_hold_char = *++ps_c_buf_p;
925
926     return ( c );
927     }
928 #endif
929
930
931 #ifdef ps_USE_PROTOS
932 void psrestart( FILE *input_file )
933 #else
934 void psrestart( input_file )
935 FILE *input_file;
936 #endif
937
938     {
939     ps_init_buffer( ps_current_buffer, input_file );
940     ps_load_buffer_state();
941     }
942
943
944 #ifdef ps_USE_PROTOS
945 void ps_switch_to_buffer( ps_BUFFER_STATE new_buffer )
946 #else
947 void ps_switch_to_buffer( new_buffer )
948 ps_BUFFER_STATE new_buffer;
949 #endif
950
951     {
952     if ( ps_current_buffer == new_buffer )
953         return;
954
955     if ( ps_current_buffer )
956         {
957         /* flush out information for old buffer */
958         *ps_c_buf_p = ps_hold_char;
959         ps_current_buffer->ps_buf_pos = ps_c_buf_p;
960         ps_current_buffer->ps_n_chars = ps_n_chars;
961         }
962
963     ps_current_buffer = new_buffer;
964     ps_load_buffer_state();
965
966     /* we don't actually know whether we did this switch during
967      * EOF (pswrap()) processing, but the only time this flag
968      * is looked at is after pswrap() is called, so it's safe
969      * to go ahead and always set it.
970      */
971     ps_did_buffer_switch_on_eof = 1;
972     }
973
974
975 #ifdef ps_USE_PROTOS
976 void ps_load_buffer_state( void )
977 #else
978 void ps_load_buffer_state()
979 #endif
980
981     {
982     ps_n_chars = ps_current_buffer->ps_n_chars;
983     pstext = ps_c_buf_p = ps_current_buffer->ps_buf_pos;
984     psin = ps_current_buffer->ps_input_file;
985     ps_hold_char = *ps_c_buf_p;
986     }
987
988
989 #ifdef ps_USE_PROTOS
990 ps_BUFFER_STATE ps_create_buffer( FILE *file, int size )
991 #else
992 ps_BUFFER_STATE ps_create_buffer( file, size )
993 FILE *file;
994 int size;
995 #endif
996
997     {
998     ps_BUFFER_STATE b;
999
1000     b = (ps_BUFFER_STATE) malloc( sizeof( struct ps_buffer_state ) );
1001
1002     if ( ! b )
1003         ps_FATAL_ERROR( "out of dynamic memory in ps_create_buffer()" );
1004
1005     b->ps_buf_size = size;
1006
1007     /* ps_ch_buf has to be 2 characters longer than the size given because
1008      * we need to put in 2 end-of-buffer characters.
1009      */
1010     b->ps_ch_buf = (ps_CHAR *) malloc( (unsigned) (b->ps_buf_size + 2) );
1011
1012     if ( ! b->ps_ch_buf )
1013         ps_FATAL_ERROR( "out of dynamic memory in ps_create_buffer()" );
1014
1015     ps_init_buffer( b, file );
1016
1017     return ( b );
1018     }
1019
1020
1021 #ifdef ps_USE_PROTOS
1022 void ps_delete_buffer( ps_BUFFER_STATE b )
1023 #else
1024 void ps_delete_buffer( b )
1025 ps_BUFFER_STATE b;
1026 #endif
1027
1028     {
1029     if ( b == ps_current_buffer )
1030         ps_current_buffer = (ps_BUFFER_STATE) 0;
1031
1032     free( (char *) b->ps_ch_buf );
1033     free( (char *) b );
1034     }
1035
1036
1037 #ifdef ps_USE_PROTOS
1038 void ps_init_buffer( ps_BUFFER_STATE b, FILE *file )
1039 #else
1040 void ps_init_buffer( b, file )
1041 ps_BUFFER_STATE b;
1042 FILE *file;
1043 #endif
1044
1045     {
1046     b->ps_input_file = file;
1047
1048     /* we put in the '\n' and start reading from [1] so that an
1049      * initial match-at-newline will be true.
1050      */
1051
1052     b->ps_ch_buf[0] = '\n';
1053     b->ps_n_chars = 1;
1054
1055     /* we always need two end-of-buffer characters.  The first causes
1056      * a transition to the end-of-buffer state.  The second causes
1057      * a jam in that state.
1058      */
1059     b->ps_ch_buf[1] = ps_END_OF_BUFFER_CHAR;
1060     b->ps_ch_buf[2] = ps_END_OF_BUFFER_CHAR;
1061
1062     b->ps_buf_pos = &b->ps_ch_buf[1];
1063
1064     b->ps_eof_status = EOF_NOT_SEEN;
1065     }
1066 # line 70 "ps.l"
1067
1068
1069 int pswrap()
1070 {
1071    //alphabet -> add_letters( psbuf, psbuffed );
1072    (*lex_action_func)(psbuf, psbuffed, 2);
1073    return 1;
1074 }
1075