Artifact 3fa2f2b96cb54e3f7a7c07a74d3986af8fbfbea0:
- File doc/l-paper/grep.l — part of check-in [69b737f5a1] at 2016-04-19 20:35:49 on branch little — Fork of Tcl used in the "Little" project. http://www.mcvoy.com/lm/little/index.html (user: dgp, size: 494) [annotate] [blame] [check-ins using]
typedef string FILE; main(int ac, string av[], hash env) { int i; string regex; FILE fd; if (ac < 2) { error("Not enough arguments."); } regex = av[1]; ac--; if (ac == 1) { grep(regex, "stdin"); } else { for (i = 2; defined(av[i]); i++) { fd = open(av[i], "r"); grep(regex, fd); close(fd); } } } void grep(string regex, FILE in) { string buf; while (gets(in, &buf) >= 0) { if (buf =~ /${regex}/) { printf("%s\n", buf); } } }