xref: /minix3/external/bsd/flex/dist/tests/test-multiple-scanners-r/main.c (revision 0b98e8aad89f2bd4ba80b523d73cf29e9dd82ce1)
1 /*	$NetBSD: main.c,v 1.1.1.1 2009/10/26 00:29:19 christos Exp $	*/
2 
3 /*
4  * This file is part of flex.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the University nor the names of its contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE.
24  */
25 
26 #include "scanner-1.h"
27 #include "scanner-2.h"
28 
29 int
30 main ( int argc, char** argv )
31 {
32     int S1_ok=1, S2_ok=1;
33     FILE * fp;
34     YY_BUFFER_STATE buff1, buff2;
35     yyscan_t scan1, scan2;
36 
37     S1_lex_init(&scan1);
38     S2_lex_init(&scan2);
39 
40     if((fp = fopen("scanner-1.tables","r")) == 0){
41         fprintf(stderr,"Could not open scanner-1.tables.\n");
42         exit(1);
43     }
44     if(S1_tables_fload(fp,scan1) != 0){
45         fprintf(stderr,"Could not load scanner-1.tables.\n");
46         exit(1);
47     }
48     fclose(fp);
49 
50     if((fp = fopen("scanner-2.tables","r")) == 0){
51         fprintf(stderr,"Could not open scanner-2.tables.\n");
52         exit(1);
53     }
54     if(S2_tables_fload(fp,scan2) != 0){
55         fprintf(stderr,"Could not load scanner-2.tables.\n");
56         exit(1);
57     }
58     fclose(fp);
59 
60     S1_set_out(stdout,scan1);
61     S2_set_out(S1_get_out(scan1),scan2);
62 
63     buff1 = S1__scan_string("foo on bar off", scan1);
64     buff2 = S2__scan_string("on blah blah off foo on bar off", scan2);
65 
66     /* scan simultaneously. */
67     while(S1_ok || S2_ok)
68     {
69         if (S1_ok)
70             S1_ok = S1_lex(scan1);
71         if (S2_ok)
72             S2_ok = S2_lex(scan2);
73     }
74     S1__delete_buffer(buff1, scan1);
75     S2__delete_buffer(buff2, scan2);
76 
77     S1_tables_destroy(scan1);
78     S2_tables_destroy(scan2);
79 
80     S1_lex_destroy(scan1);
81     S2_lex_destroy(scan2);
82     printf("TEST RETURNING OK.\n");
83     return 0;
84 }
85 
86 
87 /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */
88