-
Notifications
You must be signed in to change notification settings - Fork 43
/
doc_check.sh
executable file
·179 lines (130 loc) · 4.92 KB
/
doc_check.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#! /usr/bin/env bash
# This script is used to compare the code base to the documentation and make
# sure that the two match up.
# It does this by creating two lists: one of all the macros defined in the TeX
# code, and one of all the macros documented in the documentation (plus all the
# macros in the code which are marked as deprecated or obsolete, and thus don't
# need documentation. It then compares these two lists and outputs res.tex
# which contains a list of undocumented macros (preceded by >) and macros which
# are documented but which no longer appear in the code (preceded by <).
# The script is not perfect, and especially has trouble with classes of macros
# which have only one entry in the documentation.
#set -x #echo on
HERE=`pwd`
CODEFILE=$HERE/code.txt
DOCFILE=$HERE/doc.txt
DIFFFILE=$HERE/diff.txt
RESFILE=$HERE/res.txt
#Extraction from code
cd tex
#find definitions
grep -h '\\new[a-z]*\\.*' *.tex *.sty > $CODEFILE
grep -hE '\\[gex]?def\\.*' *.tex *.sty >> $CODEFILE
grep -hE '\\let\\.*' *.tex *.sty >> $CODEFILE
grep -h '\\font\\' *.tex *.sty >> $CODEFILE
grep -h '\\gredefsymbol{.*' *.tex *.sty >> $CODEFILE
#remove deprecated code
sed -i.temp 's:.*@empty@.*::' $CODEFILE
sed -i.temp 's:.*OBSOLETE.*::' $CODEFILE
sed -i.temp 's:.*DEPRECATED.*::' $CODEFILE
#remove trailing comments
sed -i.temp 's/%.*$//' $CODEFILE
#remove whitespace
sed -i.temp 's/^[ \t]*//;s/[ \t]*$//' $CODEFILE
#remove new and trailing code
sed -i.temp 's:.*\\new[a-z]*{*\(\\*[a-zA-Z@]*\)[\\}]*.*:\1:' $CODEFILE
#get rid of work around def
sed -i.temp '/\\def\\x/d' $CODEFILE
#accept only first def on line
sed -i.temp -E 's:\\[gex]?def:special:' $CODEFILE
#remove def and definition
sed -i.temp -E 's:.*special[a-z]*(\\[a-zA-Z@]*)[#{[].*:\1:' $CODEFILE
#remove let and definition
sed -i.temp 's:.*\\let[a-z]*\(\\[a-zA-Z@]*\)[\\=].*:\1:' $CODEFILE
#remove gredefsymbol and definition
sed -i.temp 's:.*\\gredefsymbol{\([A-Za-z]*\)}.*:\\\1:' $CODEFILE
#remove csname
sed -i.temp 's:.*\(\\csname.*\\endcsname\).*::' $CODEFILE
#colors
grep -hE '\\definecolor.*' *.sty >> $CODEFILE
sed -i.temp 's:\\definecolor{\([a-zA-Z]*\)}.*:\1:' $CODEFILE
#counts
sed -i.temp 's:.*gre@space@count@\([a-z@]*\).*:\1:' $CODEFILE
#distances
grep -h '\\gre@createdim{.*' gregoriotex-gsp-default.tex >> $CODEFILE
sed -i.temp 's:\\gre@createdim{\([a-z@]*\)}.*:\1:' $CODEFILE
sed -i.temp 's:.*gre@space@.*::' $CODEFILE
#styles
sed -i.temp 's:.*endgre@style@::' $CODEFILE
sed -i.temp 's:.*gre@style@::' $CODEFILE
#fonts
sed -i.temp 's:.*\\font\(\\.*\)=.*:\1:' $CODEFILE
#temp registers
sed -i.temp 's:.*dimen@temp@.*::' $CODEFILE
sed -i.temp 's:.*skip@temp@.*::' $CODEFILE
sed -i.temp 's:.*count@temp@.*::' $CODEFILE
#registers for saved values
sed -i.temp 's:\\gre@saved@.*::' $CODEFILE
sed -i.temp '/\\ifgre@saved@.*/d' $CODEFILE
#macros used to process options
sed -i.temp 's:\\gre@autocompile::' $CODEFILE
sed -i.temp 's:\\gre@forcecompile::' $CODEFILE
sed -i.temp 's:\\gre@nevercompile::' $CODEFILE
#block documented items
sed -i.temp 's:\\gre@pitch.*::' $CODEFILE
sed -i.temp 's:.*gre@char@he@.*::' $CODEFILE
sed -i.temp 's:\\gre@protrusionfactor@.*::' $CODEFILE
#label file
echo "00 Macros Defined in TeX" >> $CODEFILE
#alphabetize and remove duplicates
sort -u -o$CODEFILE $CODEFILE
#Extraction from documentation
cd $HERE/doc
grep -h '\\macroname.*' *.tex > $DOCFILE
grep -h '\\stylename{.*' *.tex >> $DOCFILE
grep -h '\\begin{gdimension}{.*' *.tex >> $DOCFILE
grep -h '\\begin{gcount}{.*' *.tex >> $DOCFILE
#remove all but name
sed -i.temp 's:\\macroname{\([^}]*\)}.*:\1:' $DOCFILE
#replace TeX code with backslash
sed -i.temp 's:\\textbackslash :\\:' $DOCFILE
#styles
sed -i.temp 's:.*stylename{\([a-z]*\)}.*:\1:' $DOCFILE
#distances
sed -i.temp 's:\\begin{gdimension}{\([a-z@]*\)}.*:\1:' $DOCFILE
#counts
sed -i.temp 's:\\begin{gcount}{\([a-z@]*\)}.*:\1:' $DOCFILE
#block documentation items
sed -i.temp 's:.*\.\.\..*::' $DOCFILE
sed -i.temp 's:\\gre@pitch.*::' $DOCFILE
#Other things which need to be removed
sed -i.temp 's:\\newcommand.*::' $DOCFILE
sed -i.temp 's:MacroName::' $DOCFILE
sed -i.temp 's:\\usepackage::' $DOCFILE
sed -i.temp 's:\\NewDocumentEnvironment.*::' $DOCFILE
sed -i.temp 's:\\begin{gdimension.*::' $DOCFILE
#deprecated and obsolete functions (not in documentation because they don't need to be)
cd $HERE/tex
grep -h '\\gre@deprecated.*' *.tex | grep -v '\\def\\' >> $DOCFILE
grep -h '\\gre@obsolete.*' *.tex | grep -v '\\def\\' >> $DOCFILE
#remove whitespace
sed -i.temp 's/^[ \t]*//;s/[ \t]*$//' $DOCFILE
sed -i.temp 's:.*\\gre@deprecated{.*::' $DOCFILE
sed -i.temp 's:.*\\gre@obsolete{.*::' $DOCFILE
sed -i.temp 's:}.*::' $DOCFILE
#label file
echo "00 Macros Documented" >> $DOCFILE
#alphabetize and remove duplicates
sort -u -o$DOCFILE $DOCFILE
#find differences
diff -B $DOCFILE $CODEFILE > $DIFFFILE
grep -h '[<>]' $DIFFFILE > $RESFILE
sort -u -o$RESFILE $RESFILE
#cleanup
rm $DOCFILE.temp
rm $DOCFILE
rm $CODEFILE.temp
rm $CODEFILE
rm $DIFFFILE
#open result
open $RESFILE