Deleted Added
full compact
xolint.pl (273562) xolint.pl (274672)
1#!/usr/bin/env perl
2#
3# Copyright (c) 2014, Juniper Networks, Inc.
4# All rights reserved.
5# This SOFTWARE is licensed under the LICENSE provided in the
6# ../Copyright file. By downloading, installing, copying, or otherwise
7# using the SOFTWARE, you agree to be bound by the terms of that
8# LICENSE.

--- 14 unchanged lines hidden (view full) ---

23 $opt_debug = 1 if /^-d/;
24 extract_docs() if /^-D/;
25 $opt_info = $opt_vocabulary = 1 if /^-I/;
26 $opt_print = 1 if /^-p/;
27 $opt_vocabulary = 1 if /^-V/;
28 extract_samples() if /^-X/;
29 }
30
1#!/usr/bin/env perl
2#
3# Copyright (c) 2014, Juniper Networks, Inc.
4# All rights reserved.
5# This SOFTWARE is licensed under the LICENSE provided in the
6# ../Copyright file. By downloading, installing, copying, or otherwise
7# using the SOFTWARE, you agree to be bound by the terms of that
8# LICENSE.

--- 14 unchanged lines hidden (view full) ---

23 $opt_debug = 1 if /^-d/;
24 extract_docs() if /^-D/;
25 $opt_info = $opt_vocabulary = 1 if /^-I/;
26 $opt_print = 1 if /^-p/;
27 $opt_vocabulary = 1 if /^-V/;
28 extract_samples() if /^-X/;
29 }
30
31 if ($#ARGV < 0) {
32 print STDERR "xolint [options] files ...\n";
33 print STDERR " -c invoke 'cpp' on input\n";
34 print STDERR " -C flags Pass flags to cpp\n";
35 print STDERR " -d Show debug output\n";
36 print STDERR " -D Extract xolint documentation\n";
37 print STDERR " -I Print xo_info_t data\n";
38 print STDERR " -p Print input data on errors\n";
39 print STDERR " -V Print vocabulary (list of tags)\n";
40 print STDERR " -X Print examples of invalid use\n";
41 exit(1);
42 }
43
31 for $file (@ARGV) {
32 parse_file($file);
33 }
34
35 if ($opt_info) {
36 print "static xo_info_t xo_info_table[] = {\n";
37 for $name (sort(keys(%vocabulary))) {
38 print " { \"", $name, "\", \"type\", \"desc\" },\n";

--- 225 unchanged lines hidden (view full) ---

264 } else {
265 if ($ch eq "{") {
266 check_text($build[0]) if length($build[0]);
267 $braces = 1;
268 @build = ();
269 $last = $prev;
270 next;
271 }
44 for $file (@ARGV) {
45 parse_file($file);
46 }
47
48 if ($opt_info) {
49 print "static xo_info_t xo_info_table[] = {\n";
50 for $name (sort(keys(%vocabulary))) {
51 print " { \"", $name, "\", \"type\", \"desc\" },\n";

--- 225 unchanged lines hidden (view full) ---

277 } else {
278 if ($ch eq "{") {
279 check_text($build[0]) if length($build[0]);
280 $braces = 1;
281 @build = ();
282 $last = $prev;
283 next;
284 }
285 $prev = $ch;
272 }
273
286 }
287
274 $prev = $ch;
275 $build[$phase] .= $ch;
276 }
277
278 if ($braces) {
279 error("missing closing brace");
280 check_field(@build);
281 } else {
282 check_text($build[0]) if length($build[0]);

--- 58 unchanged lines hidden (view full) ---

341 #@ xo_emit("{T:%6.6s}\n", "Max");
342 #@ should be:
343 #@ xo_emit("{T:/%6.6s}\n", "Max");
344 #@ The "%6.6s" will be a literal, not a field format. While
345 #@ it's possibly valid, it's likely a missing "/".
346 info("potential missing slash after N, L, or T with format")
347 if $field[1] =~ /%/;
348
288 $build[$phase] .= $ch;
289 }
290
291 if ($braces) {
292 error("missing closing brace");
293 check_field(@build);
294 } else {
295 check_text($build[0]) if length($build[0]);

--- 58 unchanged lines hidden (view full) ---

354 #@ xo_emit("{T:%6.6s}\n", "Max");
355 #@ should be:
356 #@ xo_emit("{T:/%6.6s}\n", "Max");
357 #@ The "%6.6s" will be a literal, not a field format. While
358 #@ it's possibly valid, it's likely a missing "/".
359 info("potential missing slash after N, L, or T with format")
360 if $field[1] =~ /%/;
361
349 #@ Format cannot be given when content is present (roles: DNLT)
350 #@ xo_emit("{T:Max/%6.6s}", "Max");
351 #@ Fields with the D, N, L, or T roles can't have both
352 #@ static literal content ("{T:Title}") and a
353 #@ format ("{T:/%s}").
354 #@ This error will also occur when the content has a backslash
355 #@ in it, like "{N:Type of I/O}"; backslashes should be escaped,
356 #@ like "{N:Type of I\\/O}". Note the double backslash, one for
357 #@ handling 'C' strings, and one for libxo.
358 error("format cannot be given when content is present")
359 if $field[1] && $field[2];
360
361 #@ An encoding format cannot be given (roles: DNLT)
362 #@ xo_emit("{T:Max//%s}", "Max");
363 #@ Fields with the D, N, L, and T roles are not emitted in
364 #@ the 'encoding' style (JSON, XML), so an encoding format
365 #@ would make no sense.
366 error("encoding format cannot be given when content is present")
367 if $field[3];
368 }
369
362 #@ An encoding format cannot be given (roles: DNLT)
363 #@ xo_emit("{T:Max//%s}", "Max");
364 #@ Fields with the D, N, L, and T roles are not emitted in
365 #@ the 'encoding' style (JSON, XML), so an encoding format
366 #@ would make no sense.
367 error("encoding format cannot be given when content is present")
368 if $field[3];
369 }
370
371 # Field is a decoration, label, or title
372 if ($field[0] =~ /DLN/) {
373 #@ Format cannot be given when content is present (roles: DLN)
374 #@ xo_emit("{N:Max/%6.6s}", "Max");
375 #@ Fields with the D, L, or N roles can't have both
376 #@ static literal content ("{L:Label}") and a
377 #@ format ("{L:/%s}").
378 #@ This error will also occur when the content has a backslash
379 #@ in it, like "{N:Type of I/O}"; backslashes should be escaped,
380 #@ like "{N:Type of I\\/O}". Note the double backslash, one for
381 #@ handling 'C' strings, and one for libxo.
382 error("format cannot be given when content is present")
383 if $field[1] && $field[2];
384 }
385
370 # A value field
371 if (length($field[0]) == 0 || $field[0] =~ /V/) {
372
373 #@ Value field must have a name (as content)")
374 #@ xo_emit("{:/%s}", "value");
375 #@ Should be:
376 #@ xo_emit("{:tag-name/%s}", "value");
377 #@ The field name is used for XML and JSON encodings. These

--- 144 unchanged lines hidden (view full) ---

522 #@ Should be:
523 #@ xo_emit("{:tag/%2.6d}", 55);
524 #@ libxo allows a true 'max width' in addition to the traditional
525 #@ printf-style 'max number of bytes to use for input'. But this
526 #@ is supported only for string values, since it makes no sense
527 #@ for non-strings. This error may occur from a typo,
528 #@ like "{:tag/%6..6d}" where only one period should be used.
529 error("max width only valid for strings")
386 # A value field
387 if (length($field[0]) == 0 || $field[0] =~ /V/) {
388
389 #@ Value field must have a name (as content)")
390 #@ xo_emit("{:/%s}", "value");
391 #@ Should be:
392 #@ xo_emit("{:tag-name/%s}", "value");
393 #@ The field name is used for XML and JSON encodings. These

--- 144 unchanged lines hidden (view full) ---

538 #@ Should be:
539 #@ xo_emit("{:tag/%2.6d}", 55);
540 #@ libxo allows a true 'max width' in addition to the traditional
541 #@ printf-style 'max number of bytes to use for input'. But this
542 #@ is supported only for string values, since it makes no sense
543 #@ for non-strings. This error may occur from a typo,
544 #@ like "{:tag/%6..6d}" where only one period should be used.
545 error("max width only valid for strings")
530 if $#chunks >= 2 && $fc =~ /[sS]/;
546 if $#chunks >= 2 && $fc !~ /[sS]/;
531}
532
533sub error {
534 return if $opt_vocabulary;
535 print STDERR $curfile . ": " .$curln . ": error: " . join(" ", @_) . "\n";
536 print STDERR $replay . "\n" if $opt_print;
537 $errors += 1;
538}

--- 18 unchanged lines hidden ---
547}
548
549sub error {
550 return if $opt_vocabulary;
551 print STDERR $curfile . ": " .$curln . ": error: " . join(" ", @_) . "\n";
552 print STDERR $replay . "\n" if $opt_print;
553 $errors += 1;
554}

--- 18 unchanged lines hidden ---