1#/bin/sh
2URL='http://www.cs.auckland.ac.nz/~pgut001/dumpasn1.cfg'
3if [ -x /usr/bin/fetch ]; then
4 /usr/bin/fetch -m $URL
5elif [ -x /usr/bin/wget ]; then
6 /usr/bin/wget -N $URL
7elif [ ! -r dumpasn1.cfg ]; then
8 echo Please download $URL in this directory.
9 exit 1
10fi
11cat dumpasn1.cfg | \
12tr -d '\r' | \
13awk -v url="$URL" '
14 function clean() {
15 oid = "";
16 comment = "";
17 description = "";
18 warning = "false";
19 }
20 BEGIN {
21 FS = "= *";
22 apos = sprintf("%c", 39);
23 clean();
24 print "// Converted from: " url;
25 print "// which is made by Peter Gutmann and whose license states:";
26 print "// You can use this code in whatever way you want,";
27 print "// as long as you don" apos "t try to claim you wrote it.";
28 print "oids = {";
29 }
30 /^OID/ { oid = $2; }
31 /^Comment/ { comment = $2; }
32 /^Description/ { description = $2; }
33 /^Warning/ { warning = "true"; }
34 /^$/ {
35 if (length(oid) > 0) {
36 gsub(" ", ".", oid);
37 gsub("\"", "\\\"", description);
38 gsub("\"", "\\\"", comment);
39 if (++seen[oid] > 1)
40 print "Duplicate OID in line " NR ": " oid > "/dev/stderr";
41 else
42 printf "\"%s\": { \"d\": \"%s\", \"c\": \"%s\", \"w\": %s },\n", oid, description, comment, warning;
43 clean();
44 }
45 }
46 END {
47 print "\"END\": \"\""
48 print "};"
49 }
50' >oids.js
51echo Conversion completed.