aboutsummaryrefslogtreecommitdiff
path: root/pkg/lists/words.x
blob: 42f4f97e8277068d9d99f73cfec4139b39d3822c (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# WORDS -- Break the input up into a series of words or strings.  A word
# is a sequence of characters delimited by whitespace or newline.  A string
# is delimited by single or double quotes, and may not span more than a single
# line.

procedure t_words()

int	fd, list, last_nscan
pointer	sp, fname, word
int	clpopni(), clgfil(), fscan(), nscan(), open()

begin
	call smark (sp)
	call salloc (fname, SZ_FNAME, TY_CHAR)
	call salloc (word, SZ_LINE, TY_CHAR)

	list = clpopni ("files")

	while (clgfil (list, Memc[fname], SZ_FNAME) != EOF) {
	    fd = open (Memc[fname], READ_ONLY, TEXT_FILE)

	    # We do not know how may "words" there are on a line; get words
	    # until no more.
	    while (fscan (fd) != EOF)
		repeat {
		    # When nscan() does not increment after a call to gargwrd(),
		    # we are all done.
		    last_nscan = nscan()
		    call gargwrd (Memc[word], SZ_LINE)
		    if (nscan() > last_nscan) {
			call printf ("%s\n")
			    call pargstr (Memc[word])
		    } else
			break
		}

	    call close (fd)
	}

	call clpcls (list)
	call sfree (sp)
end