History

CWEB — Release 3.3, 1994-12-06.

Andreas Scherer committed 15 years ago

Commit 22cd55e1 parent 6f710fc16 files · +379 −303Browse files

Showing the changes to examples (2 of 16 files). Show all

Unified · Split

2 files
  1. examples/wc.w +23 −8
  2. examples/wmerge.w +1 −1
examples/wc.w+23−8
@@ -19,6 +19,9 @@ A ``word'' is a maximal sequence of consecutive characters other than · 18 unmodified lines
1919 newline, space, or tab, containing at least one visible ASCII code.
2020 (We assume that the standard ASCII code is in use.)
2121
22+This version of \.{wc} has a nonstandard ``silent'' option (\.{-s}),
23+which suppresses printing except for the grand totals over all files.
24+
2225 @ Most \.{CWEB} programs share a common structure. It's probably a
2326 good idea to state the overall structure explicitly at the outset,
2427 even though the various parts could all be introduced in unnamed
@@ -71,18 +74,27 @@ the desired counts and specifying the order in which they should be · 46 unmodified lines
7174 displayed. Each selection is given by the initial character
7275 (lines, words, or characters). For example, `\.{-cl}' would cause
7376 just the number of characters and the number of lines to be printed,
74−in that order.
77+in that order. The default, if no special argument is given, is `\.{-lwc}'.
7578
7679 We do not process this string now; we simply remember where it is.
77− It will be used to control the formatting at output time.
80+It will be used to control the formatting at output time.
81+
82+If the `\.{-}' is immediately followed by `\.{s}', only summary totals
83+are printed.
7884
7985 @<Var...@>=
8086 int file_count; /* how many files there are */
8187 char *which; /* which counts to print */
88+int silent=0; /* nonzero if the silent option was selected */
8289
8390 @ @<Set up o...@>=
8491 which="lwc"; /* if no option is given, print all three values */
85−if (argc>1 && *argv[1] == '-') { which=argv[1]+1; argc--; argv++; }
92+if (argc>1 && *argv[1] == '-') {
93+ argv[1]++;
94+ if (*argv[1]=='s') silent=1,argv[1]++;
95+ if (*argv[1]) which=argv[1];
96+ argc--; argv++;
97+}
8698 file_count=argc-1;
8799
88100 @ Now we scan the remaining arguments and try to open a file, if
@@ -183,9 +195,11 @@ Additionally we must decide here if we know the name of the file · 94 unmodified lines
183195 we have processed or if it was just |stdin|.
184196
185197 @<Write...@>=
186−wc_print(which, char_count, word_count, line_count);
187−if (file_count) printf (" %s\n", *argv); /* not |stdin| */
188−else printf ("\n"); /* |stdin| */
198+if (!silent) {
199+ wc_print(which, char_count, word_count, line_count);
200+ if (file_count) printf (" %s\n", *argv); /* not |stdin| */
201+ else printf ("\n"); /* |stdin| */
202+}
189203
190204 @ @<Upda...@>=
191205 tot_line_count+=line_count;
@@ -196,9 +210,10 @@ tot_char_count+=char_count; · 4 unmodified lines
196210 number of files too.
197211
198212 @<Print the...@>=
199−if (file_count>1) {
213+if (file_count>1 || silent) {
200214 wc_print(which, tot_char_count, tot_word_count, tot_line_count);
201− printf(" total in %d files\n",file_count);
215+ if (!file_count) printf("\n");
216+ else printf(" total in %d file%s\n",file_count,file_count>1?"s":"");
202217 }
203218
204219 @ Here now is the function that prints the values according to the
examples/wmerge.w+1−1
@@ -63,7 +63,7 @@ than |buf_size|, so that |buffer[buf_size-1]| is never filled. · 62 unmodified lines
6363 Some of the routines use the fact that it is safe to refer to
6464 |*(limit+2)| without overstepping the bounds of the array.
6565
66−@d buf_size 100
66+@d buf_size 1024
6767
6868 @<Definitions...@>=
6969 ASCII buffer[buf_size]; /* where each line of input goes */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t