-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRECHECK
executable file
·222 lines (222 loc) · 5.53 KB
/
PRECHECK
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/sh
#***************************************************************
# Copyright (C) 2006-2009 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#***************************************************************
IN=STRINGS.in
DATA=_strings.data
LIST=_split_words
OUT=/tmp/out$$
MASTER=/tmp/mast$$
TEMP=/tmp/temp$$
C=_precheck.c
DIR=split.dir
PASS=checkstr.OK
SHOW=""
WORDLIST=""
#trap "rm -f $OUT $TEMP; rm -rf save$DIR; mv $DIR save$DIR" 0 # for debugging
trap "rm -f $OUT $MASTER $TEMP; rm -rf $DIR" 0
#
[ -f $LIST ] && WORDLIST="$(grep -v "^#" $LIST)"
case "X$1" in
X-*) PROC=less
SHOW="y"
shift 1 ;;
*) PROC=cat ;;
esac
[ -z "$WORDLIST" ] && WORDLIST="$*"
TRIES=$#
rm -f $PASS
#set -x
awk -v PASS="$PASS" 'BEGIN { f=0; c=1 }
/^%ENTRY% _LT/ { f=1; NAME=$NF }
# Keys can have space in between, so select every field after first field.
/^%KEY%/ { KEY=substr($0, index($0,$2)) }
/^%NOCHECK%/ { c=1 }
/^%STR%/ {
if (f) {
printf("[%s] %s: ", KEY, NAME);
if ($0 !~ "\\(") {
printf("%s", $0);
}
else {
N=length($0); x=0;
for (i=1; i<=N; i++) {
X=substr($0, i, 1);
if (X == "(") {
x++;
}
else if (X == ")") {
X = "_";
x--;
}
Y[i] = !x ? X : "_";
}
for (i=1; i<=N; i++) {
printf("%c", Y[i]);
}
}
printf("\n");
f=0;
if (c) {
cmd = sprintf("echo %s >> %s", NAME, PASS);
system(cmd);
}
c=0;
}
}
' $IN | sed -e 's/%STR%//g' |
tee $TEMP > $DATA
# cp $TEMP file_1 # for debugging...
awk '
BEGIN {
f=0;
}
/^%ENTRY% _LT/ {
f=1;
NAME=$NF;
}
/^%STR%/ {
BUF=substr($0, index($0,$2));
if (f) {
printf("%s: ", NAME);
if (BUF ~ "[(]") {
max = length(BUF);
for (i = 1; i <= max; i++) {
ch = substr(BUF, i, 1);
if (ch == "(") {
nest++;
printf("_");
}
else if (ch == ")") {
nest--;
printf("_");
}
else if (nest) {
printf("_");
}
else {
printf("%c", ch);
}
}
printf("\n");
}
else {
printf("%s\n", BUF);
}
f=0;
}
}' $IN | sed -e 's/ =SOME= /________/g' -e 's/ =ANY= /_______/g' \
-e 's/ =FEW= /_______/g' | sed -e 's/___*/__/g' > $OUT
# cp $OUT file_2 # for debugging
(
mkdir $DIR || exit 1
cat > $C <<@EOF@
#include "nomos.h"
#include "_autodefs.h"
/*
* $(cat ./GenCodeCopyright)
*****
* This source file was auto-generated $(date)
*****
* Changes to this file will NOT be kept; the file will be over-written
* the next time the license-specifications (./STRINGS.in) change!
*****
* Words used for pre-check exclusions:
*/
#if 0
$(grep -v "^#" $LIST)
#endif
#define M(x) ltsr[x] = LTSR_SMASK;
extern int strGrep();
#ifdef PROC_TRACE_SWITCH
extern struct globals gl;
#endif /* PROC_TRACE_SWITCH */
#ifdef LTSR_DEBUG
extern void showLTCache();
#endif /* LTSR_DEBUG */
/* */
void preloadResults(char *filetext, char *ltsr)
{
#if 0
int ret; /* for possible debugging */
#endif
/* */
#ifdef PROC_TRACE
#ifdef PROC_TRACE_SWITCH
if (gl.ptswitch)
#endif /* PROC_TRACE_SWITCH */
printf("== preloadResults(%p, %p,)\n", filetext, ltsr);
#endif /* PROC_TRACE */
/* */
@EOF@
rm -f split_[0-9]*
printf '*** START: %s license-text strings ***\n' $(wc -l < $OUT)
I=1
cp $OUT $MASTER
for WORD in $WORDLIST ; do
# make sure the word regex-matches the string and NOT the tag
grep -i ".*: .*$WORD" $MASTER > $TEMP
WC=$(wc -l < $TEMP)
[ $WC -eq 1 ] && P="" || P="s"
printf "... \"$WORD\" in %d string$P\n" $WC
[ $WC -eq 0 ] && continue
FNAME=$(printf "$DIR/split_%02d.%s" $I "$WORD")
for i in $(seq 1 $WC) ; do
LINE=$(head -n $i $TEMP | tail -1)
TAG=$(expr "$LINE" : '\(.*\): ')
## echo "$LINE" | sed -e 's/.*: //' | grep -iq "$WORD"
## if [ $? -ne 0 ]; then
## echo "\"$WORD\" is NOT in this line:"
## echo "$LINE"
## sed -e "s/$TAG"
## grep -v $TAG $FNAME > X
## mv -f X $FNAME
## continue
## fi
printf "\t\tM(%s);\n" $TAG >> $FNAME
grep -Fv "$LINE" $OUT > X
mv -f X $OUT
done
I=$((I+1))
cat >> $C <<@EOF@
if (!strGrep("$WORD", filetext, REG_ICASE)) { /* match count $WC */
#ifdef LTSR_DEBUG
printf("DEBUG: eliminate searches for \"$WORD\"\n");
#endif /* LTSR_DEBUG */
$(fmt $FNAME)
}
#ifdef LTSR_DEBUG
showLTCache("Cache after cuts for \"$WORD\":");
#endif /* LTSR_DEBUG */
@EOF@
done
printf "\treturn;\n}\n" >> $C
REM=$(wc -l < $OUT)
printf '*** DONE: %s strings have no pre-check exclusions ***\n' $REM
FNAME=split.OTHER
echo "$REM remaining license strings:" > $FNAME
sed -e 's/:.*//g' $OUT >> $FNAME
# The file _autodata.c is always generated before we're called.
for WORD in $(tail -n $REM $FNAME) ; do
echo "==== ====" >> $FNAME
grep "${WORD}=" _autodata.c | grep Phrase >> $FNAME
grep "$WORD" $OUT | sed -e "s/$WORD/-->/" >> $FNAME
done
[ -n "$SHOW" ] && cat $OUT
) | $PROC
sed -e "s/^\[.*\] //g" -e "s/^.*: //g" -e 's,",,g' -e 's/[()]//g' -e 's/|/ /g' < $DATA | tr ' ' \\012 | sort | egrep -v '(___|=FEW=|=SOME=|=ANY=)' | sed -e 's/^[ ]*//g' | uniq -c | sort -nr > words.HISTOGRAM
exit 0