opt_v.c revision 1.6
11.6Srillig/* $NetBSD: opt_v.c,v 1.6 2021/11/20 16:54:17 rillig Exp $ */ 21.1Srillig/* $FreeBSD$ */ 31.1Srillig 41.2Srillig/* 51.2Srillig * Tests for the options '-v' and '-nv'. 61.2Srillig * 71.2Srillig * The option '-v' enables verbose mode. It outputs some information about 81.2Srillig * what's going on under the hood, especially when lines are broken. It also 91.2Srillig * outputs a few statistics about line counts and comments at the end. 101.2Srillig * 111.2Srillig * The option '-nv' disables verbose mode. Only errors and warnings are output 121.2Srillig * in this mode, but no progress messages. 131.2Srillig */ 141.2Srillig 151.1Srillig#indent input 161.1Srillig/* 171.6Srillig * A block comment. 181.1Srillig */ 191.1Srilligvoid 201.1Srilligexample(void) 211.1Srillig{ 221.1Srillig printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third"); 231.1Srillig} 241.1Srillig 251.6Srillig/* $ The below comment is neither counted nor formatted. */ 261.1Srillig#define macro1 /* prefix */ suffix 271.1Srillig 281.6Srillig/* $ The below comment is formatted and counted. */ 291.1Srillig#define macro2 prefix /* suffix */ 301.1Srillig#indent end 311.1Srillig 321.1Srillig#indent run -v 331.1Srillig/* 341.6Srillig * A block comment. 351.1Srillig */ 361.1Srilligvoid 371.1Srilligexample(void) 381.1Srillig{ 391.1Srillig printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third"); 401.1Srillig} 411.1Srillig 421.1Srillig#define macro1 /* prefix */ suffix 431.1Srillig 441.1Srillig#define macro2 prefix /* suffix */ 451.1SrilligThere were 10 output lines and 2 comments 461.1Srillig(Lines with comments)/(Lines with code): 0.571 471.1Srillig#indent end 481.1Srillig 491.5Srillig 501.1Srillig#indent input 511.1Srilligvoid 521.1Srilligexample(void) 531.1Srillig{ 541.1Srillig int sum1 = 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21; 551.1Srillig int sum2 = (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21); 561.1Srillig} 571.1Srillig#indent end 581.1Srillig 591.1Srillig#indent run -nv 601.1Srilligvoid 611.1Srilligexample(void) 621.1Srillig{ 631.1Srillig/* $ XXX: The following lines are too long and should thus be broken. */ 641.1Srillig/* $ XXX: If they are broken, -nv does NOT output 'Line broken'. */ 651.1Srillig int sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21; 661.1Srillig int sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21); 671.1Srillig} 681.1Srillig#indent end 691.3Srillig 701.3Srillig 711.3Srillig#indent input 721.3Srillig/* Demonstrates line number counting in verbose mode. */ 731.3Srillig 741.3Srilligint *function(void) 751.3Srillig{} 761.3Srillig#indent end 771.3Srillig 781.3Srillig#indent run -v 791.3Srillig/* Demonstrates line number counting in verbose mode. */ 801.3Srillig 811.3Srilligint * 821.3Srilligfunction(void) 831.3Srillig{ 841.3Srillig} 851.3SrilligThere were 5 output lines and 1 comments 861.3Srillig(Lines with comments)/(Lines with code): 0.250 871.3Srillig#indent end 881.3Srillig/* In the above output, the '5' means 5 non-empty lines. */ 891.3Srillig 901.3Srillig/* 911.3Srillig * XXX: It's rather strange that -v writes to stdout, even in filter mode. 921.3Srillig * This output belongs on stderr instead. 931.3Srillig */ 941.4Srillig 951.4Srillig 961.4Srillig/* 971.4Srillig * Test line counting in preprocessor directives. 981.4Srillig */ 991.4Srillig#indent input 1001.4Srillig#if 0 1011.4Srilligint line = 1; 1021.4Srilligint line = 2; 1031.4Srilligint line = 3; 1041.4Srillig#else 1051.4Srilligint line = 5; 1061.4Srillig#endif 1071.4Srillig#indent end 1081.4Srillig 1091.4Srillig#indent run -v -di0 1101.4Srillig#if 0 1111.4Srilligint line = 1; 1121.4Srilligint line = 2; 1131.4Srilligint line = 3; 1141.4Srillig#else 1151.4Srilligint line = 5; 1161.4Srillig#endif 1171.4SrilligThere were 3 output lines and 0 comments 1181.4Srillig(Lines with comments)/(Lines with code): 0.000 1191.4Srillig#indent end 1201.4Srillig/* 1211.4Srillig * FIXME: The lines within the conditional compilation directives must be 1221.4Srillig * counted as well. TODO: Move stats out of parser_state. 1231.4Srillig */ 124