| 1 | /* |
|---|
| 2 | test-scanner.c - Regression test driver for the libsensors config file scanner. |
|---|
| 3 | Copyright (C) 2006 Mark M. Hoffman <mhoffman@lightlink.com> |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation; version 2 of the License. |
|---|
| 8 | |
|---|
| 9 | This program is distributed in the hope that it will be useful, |
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | GNU General Public License for more details. |
|---|
| 13 | |
|---|
| 14 | You should have received a copy of the GNU General Public License |
|---|
| 15 | along with this program; if not, write to the Free Software |
|---|
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include <stdio.h> |
|---|
| 20 | #include <stdlib.h> |
|---|
| 21 | |
|---|
| 22 | #include "../data.h" |
|---|
| 23 | #include "../conf.h" |
|---|
| 24 | #include "../conf-parse.h" |
|---|
| 25 | #include "../scanner.h" |
|---|
| 26 | |
|---|
| 27 | YYSTYPE sensors_yylval; |
|---|
| 28 | |
|---|
| 29 | int main(void) |
|---|
| 30 | { |
|---|
| 31 | int result; |
|---|
| 32 | |
|---|
| 33 | /* init the scanner */ |
|---|
| 34 | if ((result = sensors_scanner_init(stdin))) |
|---|
| 35 | return result; |
|---|
| 36 | |
|---|
| 37 | do { |
|---|
| 38 | result = sensors_yylex(); |
|---|
| 39 | |
|---|
| 40 | printf("%d: ", sensors_yylineno); |
|---|
| 41 | |
|---|
| 42 | switch (result) { |
|---|
| 43 | |
|---|
| 44 | case 0: |
|---|
| 45 | printf("EOF\n"); |
|---|
| 46 | break; |
|---|
| 47 | |
|---|
| 48 | case NEG: |
|---|
| 49 | printf("NEG\n"); |
|---|
| 50 | break; |
|---|
| 51 | |
|---|
| 52 | case EOL: |
|---|
| 53 | printf("EOL\n"); |
|---|
| 54 | break; |
|---|
| 55 | |
|---|
| 56 | case BUS: |
|---|
| 57 | printf("BUS\n"); |
|---|
| 58 | break; |
|---|
| 59 | |
|---|
| 60 | case LABEL: |
|---|
| 61 | printf("LABEL\n"); |
|---|
| 62 | break; |
|---|
| 63 | |
|---|
| 64 | case SET: |
|---|
| 65 | printf("SET\n"); |
|---|
| 66 | break; |
|---|
| 67 | |
|---|
| 68 | case CHIP: |
|---|
| 69 | printf("CHIP\n"); |
|---|
| 70 | break; |
|---|
| 71 | |
|---|
| 72 | case COMPUTE: |
|---|
| 73 | printf("COMPUTE\n"); |
|---|
| 74 | break; |
|---|
| 75 | |
|---|
| 76 | case IGNORE: |
|---|
| 77 | printf("IGNORE\n"); |
|---|
| 78 | break; |
|---|
| 79 | |
|---|
| 80 | case FLOAT: |
|---|
| 81 | printf("FLOAT: %f\n", sensors_yylval.value); |
|---|
| 82 | break; |
|---|
| 83 | |
|---|
| 84 | case NAME: |
|---|
| 85 | printf("NAME: %s\n", sensors_yylval.name); |
|---|
| 86 | free(sensors_yylval.name); |
|---|
| 87 | break; |
|---|
| 88 | |
|---|
| 89 | case ERROR: |
|---|
| 90 | printf("ERROR\n"); |
|---|
| 91 | break; |
|---|
| 92 | |
|---|
| 93 | default: |
|---|
| 94 | printf("%c\n", (char)result); |
|---|
| 95 | break; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | } while (result); |
|---|
| 99 | |
|---|
| 100 | /* clean up the scanner */ |
|---|
| 101 | sensors_scanner_exit(); |
|---|
| 102 | |
|---|
| 103 | return 0; |
|---|
| 104 | } |
|---|
| 105 | |
|---|