File: pass2.awk

package info (click to toggle)
libticables3 3.8.9-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,660 kB
  • ctags: 2,190
  • sloc: ansic: 16,302; sh: 9,292; makefile: 517; yacc: 288; awk: 145; sed: 16
file content (39 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (7)
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
#! /usr/bin/awk
# extract - create cross-links starting at index and html files
# Copyright (C) Romain Lievin 2002
# Contact: roms@tilp.info
#

BEGIN {
    if (ARGC < 3) {
	print "usage: cat <src_file> |extract.awk src=<file> tbl=<index> dst=<folder>";
	exit;
    }
}

# Load the 'index' file into an array such as: 
# array[ticablelinkcable.put] = <a href="ticablelinkcable.put.html">put</a>
/<html>/ {
    while ((getline line < tbl) > 0) {
	nf = split(line, array, /\./);
	entry = "@" line "@";
	table[entry] = "<a href=\"" line ".html" "\">" array[nf] "</a>";
    }

    # build filename
    nf = split(src, array, /\//);
    sub(/.html/, "", array[nf]);
    dest = dst "/" array[nf] ".html";
}

# Search & replace by using the array
{ 
#    print $0;
    for (s in table) {
	sub(s, table[s], $0);
    } 
    print $0 > dest;
}

END { 
}