[a0a02d]: utils / lint.cpp Maximize Restore History

Download this file

lint.cpp    169 lines (138 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (C) 2008-2009 David Sugar, Tycho Softworks.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <bayonne-config.h>
#include <bayonne.h>
using namespace BAYONNE_NAMESPACE;
using namespace UCOMMON_NAMESPACE;
class lint : public Script::interp
{
public:
};
static Script::keyword_t keywords[] = {
{NULL}};
static shell::flagopt helpflag('h',"--help", _TEXT("display this list"));
static shell::flagopt althelp('?', NULL, NULL);
static shell::flagopt ver('v', "--version", _TEXT("version of application"));
static void version(void)
{
printf("Bayonne Lint " VERSION "\n"
"Copyright (C) 2009 David Sugar, Tycho Softworks\n"
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n");
exit(0);
}
static void usage(void)
{
printf("%s\n", _TEXT("usage: baylint [options] scriptfile\n"
"Options:"));
shell::help();
printf("\n%s\n", _TEXT("Report bugs to dyfet@gnu.org"));
exit(0);
}
PROGRAM_MAIN(argc, argv)
{
linked_pointer<Script::error> ep;
const char *fn;
Script *lib = NULL;
char buffer[256];
const char *ext;
size_t len;
fsys_t dir;
shell::bind("baylint");
shell args(argc, argv);
Env::tool(&args);
if(is(helpflag) || is(althelp))
usage();
if(is(ver))
version();
argv = args.argv();
fn = *(argv++);
if(!fn) {
fprintf(stderr, "*** baylint: no filename specified\n");
exit(-1);
}
ext = strrchr(fn, '.');
if(!fsys::isfile(fn)) {
fprintf(stderr, "*** baylint: %s: not found\n", fn);
exit(-1);
}
if(!String::equal(ext, ".bcs") && !String::equal(ext, ".scr")) {
fprintf(stderr, "*** %s: not a valid script file name\n", fn);
exit(1);
}
Script::init();
Script::assign(keywords);
String::set(buffer, sizeof(buffer), Env::env("definitions"));
fsys::open(dir, buffer, fsys::ACCESS_DIRECTORY);
if(!is(dir))
shell::log(shell::ERR, "cannot compile definitions from %s", buffer);
else {
shell::debug(2, "compiling definitions from %s", buffer);
len = strlen(buffer);
buffer[len++] = '/';
while(is(dir) && fsys::read(dir, buffer + len, sizeof(buffer) - len) > 0) {
char *ep = strrchr(buffer + len, '.');
if(!ep)
continue;
if(!String::equal(ep, ".bcs"))
continue;
shell::log(shell::INFO, "compiling %s", buffer + len);
lib = Script::compile(lib, buffer, NULL);
}
fsys::close(dir);
}
String::set(buffer, sizeof(buffer), Env::env("modules"));
fsys::open(dir, buffer, fsys::ACCESS_DIRECTORY);
if(!is(dir))
shell::log(shell::ERR, "cannot use module definitions from %s", buffer);
else {
shell::debug(2, "using module definitions from %s", buffer);
len = strlen(buffer);
buffer[len++] = '/';
while(is(dir) && fsys::read(dir, buffer + len, sizeof(buffer) - len) > 0) {
char *ep = strrchr(buffer + len, '.');
if(!ep)
continue;
if(!String::equal(ep, ".bcs"))
continue;
shell::log(shell::INFO, "module %s", buffer + len);
lib = Script::compile(lib, buffer, NULL);
}
fsys::close(dir);
}
if(lib)
ep = lib->getListing();
while(is(ep)) {
fprintf(stderr, "%s:%d: warning: %s\n", ep->filename, ep->errline, ep->errmsg);
ep.next();
}
Script *img = Script::compile(NULL, fn, lib);
if(!img) {
fprintf(stderr, "*** baylint: %s: failed to compile\n", fn);
exit(-1);
}
unsigned errors = img->getErrors();
if(errors) {
fprintf(stderr, "*** %d total errors in %s\n", errors, fn);
ep = img->getListing();
while(is(ep)) {
fprintf(stderr, "%s:%d: error: %s\n", ep->filename, ep->errline, ep->errmsg);
ep.next();
}
exit(2);
}
PROGRAM_EXIT(0);
}