File: scopehack.icn

package info (click to toggle)
noweb 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,540 kB
  • sloc: sh: 2,580; ansic: 1,829; makefile: 903; perl: 781; lisp: 757; awk: 174; csh: 3
file content (44 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (8)
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
# scopehack; a replacement for totex but splitting output into multiple files

global totex

procedure main(args)
  totex := "PATH=/usr/local/noweb/lib:/usr/lib/noweb:$PATH totex"  
  every totex ||:= " '" || !args || "'"

  lines := []
  file 

  while line := read() do {
    line ? 
      if ="@fatal" then exit(1)
      else if ="@file " then
        if =\file & pos(0) then # no change
          &null
        else {
          flush(file, lines)
          file := tab(0)
	}
    put(lines, line)
  }
  flush(file, lines)
end

procedure flush(file, lines)
  if /file & *lines > 0 then
    stop("First line is not @file")
  else if *lines = 0 then
    return
  else {
    outfile := suffex(file) || ".tex"
    p := open(totex || " > " || outfile, "wp") | stop ("cannot run ", totex)
    while write(p, get(lines))
    close(p)
    return
  }
end

procedure suffex(s)
  return reverse (reverse(s) ? {tab(upto('.')) & ="."; tab(0)})
end