~mmach/netext73/lm-sensors

« back to all changes in this revision

Viewing changes to lib/test/test-scanner.c

  • Committer: mmach
  • Date: 2020-02-05 20:28:34 UTC
  • Revision ID: netbit73@gmail.com-20200205202834-zc3sla47j9e700w5
3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 51 Franklin Street, Fifth Floor, Boston,
 
17
    MA 02110-1301 USA.
 
18
*/
 
19
 
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
 
 
23
#include "../data.h"
 
24
#include "../conf.h"
 
25
#include "../conf-parse.h"
 
26
#include "../scanner.h"
 
27
 
 
28
YYSTYPE sensors_yylval;
 
29
 
 
30
int main(void)
 
31
{
 
32
        int result;
 
33
 
 
34
        /* init the scanner */
 
35
        if ((result = sensors_scanner_init(stdin, NULL)))
 
36
                return result;
 
37
 
 
38
        do {
 
39
                result = sensors_yylex();
 
40
 
 
41
                printf("%d: ", sensors_yylineno);
 
42
 
 
43
                switch (result) {
 
44
 
 
45
                        case 0:
 
46
                                printf("EOF\n");
 
47
                                break;
 
48
 
 
49
                        case NEG:
 
50
                                printf("NEG\n");
 
51
                                break;
 
52
        
 
53
                        case EOL:
 
54
                                printf("EOL\n");
 
55
                                break;
 
56
        
 
57
                        case BUS:
 
58
                                printf("BUS\n");
 
59
                                break;
 
60
        
 
61
                        case LABEL:
 
62
                                printf("LABEL\n");
 
63
                                break;
 
64
        
 
65
                        case SET:
 
66
                                printf("SET\n");
 
67
                                break;
 
68
        
 
69
                        case CHIP:
 
70
                                printf("CHIP\n");
 
71
                                break;
 
72
        
 
73
                        case COMPUTE:
 
74
                                printf("COMPUTE\n");
 
75
                                break;
 
76
        
 
77
                        case IGNORE:
 
78
                                printf("IGNORE\n");
 
79
                                break;
 
80
        
 
81
                        case FLOAT:
 
82
                                printf("FLOAT: %f\n", sensors_yylval.value);
 
83
                                break;
 
84
        
 
85
                        case NAME:
 
86
                                printf("NAME: %s\n", sensors_yylval.name);
 
87
                                free(sensors_yylval.name);
 
88
                                break;
 
89
        
 
90
                        case ERROR:
 
91
                                printf("ERROR\n");
 
92
                                break;
 
93
 
 
94
                        default:
 
95
                                printf("%c\n", (char)result);
 
96
                                break;
 
97
                }
 
98
 
 
99
        } while (result);
 
100
 
 
101
        /* clean up the scanner */
 
102
        sensors_scanner_exit();
 
103
 
 
104
        return 0;
 
105
}
 
106