summaryrefslogtreecommitdiff
path: root/ipl/progs/what.icn
blob: 9b0bbe9a91da7e83879f9d27fdfe7ae111675b2f (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
############################################################################
#
#	File:     what.icn
#
#	Subject:  Program to identify source-code information
#
#	Author:   Phillip Lee Thomas
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
# Writes all strings beginning with "@" followed by "(#)"
#     and ending with null, newline, quotes, greater-than
#     or backslash. Follows UNIX what conventions.
#
############################################################################
#
#  Requires:  Tested with DOS, AIX UNIX
#
############################################################################
#
#  Links:    basename
#
############################################################################

link basename

procedure main(args)
   local ID, line, terminator, key, f, fin, here

   ID := "@(#)what.icn (1.0) - plt - 2 May, 96"
   ID := "@(#)-- Identify source code information."

   line := ""
   terminator := '\0\n\">\\' # ++ char(10)
   key := "@" || "(#)"

   if *args = 0 then  {
      write("Usage: ", basename(&progname, ".EXE"),
         " file1 [file2 [file3]]")
      exit(1)
      }

   while f := pop(args) do  {
      fin := open(f, "ru") | next
      write(f, ":")

      while line ||:= reads(fin, 32768)  do {
         line ? {
            here := 1
            every (tab(here := upto('@')) | next) do {
               if match(key) then  {
                  move(4)
                  write('\t', tab(here := upto(terminator)))
                  }
               }
            line := line[here:0]
            }  # line
         } # while
      close(fin)
      }  # while files
   write("[Time: ", &time / 1000.0, " seconds.]")
   exit(0)
end