4 * This file is part of flex.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
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
27 /* A file to build "scanner.c". */
28 /* This tests that we can use "yyextra".
29 We buffer all input into a growable array, then print it.
30 We run diff on the input and output.
38 /* We'll store the entire input in this buffer, growing as necessary. */
45 /* Save char into junk array at next position. */
46 static void check_extra ( yyscan_t scanner );
49 void *yyalloc ( size_t size, yyscan_t scanner );
53 %option 8bit outfile="scanner.c" prefix="test"
54 %option nounput nomain noyywrap nodefault
56 %option extra-type="struct Check *"
63 .|\r|\n { check_extra (yyscanner); }
79 testlex_init_extra(&check, &scanner);
80 testset_in(stdin, scanner);
81 testset_out(stdout, scanner);
83 /* Test to confirm that yyalloc was called from
84 * yylex_init_extra with the yyextra argument.
90 testlex_destroy(scanner);
94 void *yyalloc(size_t size, yyscan_t scanner)
97 check = testget_extra(scanner);
100 check->bar = "Hello World";
102 check_extra(scanner);
107 /* Save char into junk array at next position. */
108 static void check_extra(yyscan_t scanner)
111 check = testget_extra(scanner);
113 if (check->foo != 'a') {
114 fprintf(stderr, "foo is not 'a'\n");
117 if (strcmp(check->bar, "Hello World") != 0) {
118 fprintf(stderr, "bar is not Hello World\n");
121 if (check->qux != 'z') {
122 fprintf(stderr, "qux is not 'z'\n");