• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/awk -f
2function translate(str) {
3    while (sub(/&/, "#amp;", str) == 1);
4    while (sub(/#amp;/, "\\&", str) == 1); # fun isn't it ?
5    while (sub(/</, "\\&lt;", str) == 1);
6    while (sub(/>/, "\\&gt;", str) == 1);
7    sub(/[0-9][0-9][0-9][0-9][0-9]+/, "<bug number='&'/>", str)
8    return(str)
9}
10BEGIN         {
11		nb_entry = 0
12                in_entry = 0
13                in_item = 0
14		print "<?xml version='1.0' encoding='ISO-8859-1'?>"
15		print "<log>"
16	      }
17END           {
18                if (in_item == 1)  printf("%s</item>\n", translate(item))
19                if (in_entry == 1) print "  </entry>"
20                print "</log>"
21	      }
22/^[ \t]*$/    { next }
23/^[A-Za-z0-9]/ {
24                match($0, "\(.*\) \([A-Z]+\) \([0-9][0-9][0-9][0-9]\) \(.*\) <\(.*\)>", loge)
25                if (in_item == 1)  printf("%s</item>\n", translate(item))
26                if (in_entry == 1) print "  </entry>"
27		nb_entry = nb_entry + 1
28		if (nb_entry > 50) {
29		    in_entry = 0
30		    in_item = 0
31		    exit
32		}
33                in_entry = 1
34                in_item = 0
35		printf("  <entry date='%s' timezone='%s' year='%s'\n         who='%s' email='%s'>\n", loge[1], loge[2], loge[3], loge[4], loge[5])
36	      }
37/^[ \t]*\*/   {
38                if (in_item == 1)  printf("%s</item>\n", translate(item))
39                in_item = 1
40		printf("    <item>")
41                match($0, "[ \t]*. *\(.*\)", loge)
42		item = loge[1]
43              }
44/^[ \t]*[a-zA-Z0-9\#]/    {
45                if (in_item == 1) {
46		    match($0, "[ \t]*\(.*\)[ \t]*", loge)
47		    item = sprintf("%s %s",  item, loge[1])
48		}
49              }
50