-
Notifications
You must be signed in to change notification settings - Fork 33
/
ocamlpack
executable file
·85 lines (82 loc) · 1.65 KB
/
ocamlpack
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# -*- mode: sh -*-
# command line (very primitive...)
if test $1 != "-o"; then
echo "ocamlpack: usage: ocamlpack -o outputmodule -title <str> -intro <intro>
module1 module2 ..."
exit -1
fi
shift
out=$1
shift
if test $1 != "-title"; then
echo "ocamlpack: usage: ocamlpack -o outputmodule -title <str> -intro <intro>
module1 module2 ..."
exit -1
fi
shift
outtitle=$1
shift
if test $1 != "-intro"; then
echo "ocamlpack: usage: ocamlpack -o outputmodule -title <str> -intro <intro>
module1 module2 ..."
exit -1
fi
shift
introfile=$1
shift
# prepare output
/bin/rm -f $out
exec 1>$out;
echo "(** $outtitle *)";
echo "(**";
cat $introfile;
echo "*)";
# iterate on input module,
for i in $*; do
name=$i
# 1.A Look for the first (** *) comment, and output it
awk -v name=$name '
BEGIN {
start=1
nb = split(name, dirname, "/")
name = dirname[nb]
if (RLENGTH>0)
name = substr(name,RINDEX,length(name)-RINDEX)
hd = toupper(substr(name,1,1))
tl = substr(name,2,length(name)-1)
}
{
if (start==1) {
match($0, /\(\*\*([ ]+)([^*]*)([ ]+)\*\)/ )
if (RLENGTH>0){
start=0
title=substr($0,RSTART+4,RLENGTH-7)
print "\n(** {1 Module [",hd tl "]:",title "} *)\n"
print "module",hd tl,": sig"
}
}
}
END {
if (start==1) {
print "\n(** {1 Module [",hd tl "]} *)\n"
print "module",hd tl,": sig"
}
}
' $i.mli;
# 1.B Output the rest of name.mli to out
awk -v name=$name '
{
if (start==1) {
match($0, /\(\*\*([ ]+)([^*]*)([ ]+)\*\)/ )
if (RLENGTH>0)
start=0
else
print $0
}
else
print " ",$0
}
END { print "end\n" }
' $i.mli;
done