Debian Codegraph @

texmf-dist/doc/support/ctan_chk/ctan_chk.gawk

raw
1 # section no34:*/
2 # section no12:*/
3 #
4 # Program: ctan_chk.gawk
5 #
6 # Author: Dave Bone
7 #
8 # License:
9 # This Source Code Form is subject to the terms of the GNU General Public License (version 3).
10 # If a copy of the MPL was not distributed with this file,
11 # You can obtain one at: "https://gnu.org/licenses/gpl.html".
12 #
13 # Purpose: Implementation of some suggested CTAN guidelines that an upload project should respect.
14 # Correction functions help u cleanup the droppings.
15 # See www.ctan.org website for "upload guideline" document
16 # Read ctan_chk.pdf document describing the program with various run scenarios.
17 #
18 #
19 # section no:12*/
20 # section no14:*/
21 function is_file_a_directory(filename,filetype)
22 {
23 x= "file \"%s\"";
24 y= sprintf(x,filename);
25 y|getline a;
26 close(y);
27 split(a,parts);
28 filetype[1]= parts[2];
29 xx= parts[2];
30 str= "^directory$";
31 if(xx~str){
32 return 1;
33 }
34 return 0;
35 }
36 # section no:14*/
37 # section no15:*/
38 function is_file_an_executable(filename,filetype)
39 {
40 x= "file %s";
41 y= sprintf(x,filename);
42 y|getline a;
43 close(y);
44 split(a,parts);
45 filetype[1]= parts[2];
46 xx= parts[2];
47 str= "(executable|POSIX|Mach-O|ELF)$";
48 if(xx~str){
49 return 1;
50 }
51 return 0;
52 }
53 # section no:15*/
54 # section no17:*/
55 function chk_auxiliary_files(filename)
56 {
57 if(is_file_a_directory(filename)==1)
58 return 0;
59 str= "\\.(ps|gitignore|git|aux|log|bbl|bcf|blg|brf|ilg|ind|idx|glo|loa|lof|lot|nav|out|snm|vrb|toc|dvi|glg|gls|tmp|o|bak|mpx|scn|toc)$";
60 if(filename~str){
61 a= "\"%s\" 'Auxilary file to be deleted'";
62 b= sprintf(a,filename);
63 print b;
64 #delete_file(filename);
65 return 1;
66 }
67 return 0;
68 }
69 # section no:17*/
70 # section no25:*/
71 function remove_file_s_extended_attributes(filename,message)
72 {
73 x= "echo %s\";xattr -c %s";
74 y= sprintf(x,message,filename);
75 print y;
76 #y|getline a;
77 #close(y);
78 }
79 # section no:25*/
80 # section no21:*/
81 function chk_file_permissions(filename)
82 {
83 filetype[1]= "";
84 if(is_file_a_directory(filename,filetype)==1)
85 return 0;
86 if(is_file_an_executable(filename,filetype)==1)
87 return 0;
88 x= "ls -al \"%s\"";
89 y= sprintf(x,filename);
90 y|getline a;
91 close(y);
92 number_fields= split(a,parts);
93 str= "x";
94 if(parts[1]~str){
95 a= "\"%s\" 'Write permissions %s to possibly delete file type: %s'";
96 b= sprintf(a,filename,parts[1],filetype[1]);
97 print b;
98 return 1;
99 }
100 return 0;
101 }
102 # section no:21*/
103 # section no18:*/
104 function chk_extended_file_attributes(filename)
105 {
106 x= "ls -al \"%s\"";
107 y= sprintf(x,filename);
108 y|getline a;
109 close(y);
110 number_of_fields= split(a,parts);
111 if(number_of_fields<9)
112 return 0;
113 xx= parts[1];
114 str= "(@|+)$";
115 if(xx!~str){
116 return 0;
117 }
118 a= "\"%s\" 'Extended attributes %s'";
119 b= sprintf(a,filename,parts[1]);
120 print b;
121 #remove_file_s_extended_attributes(filename,b);
122 return 1;
123 }
124 # section no:18*/
125 # section no19:*/
126 function chk_empty_files(filename)
127 {
128 if(is_file_a_directory(filename)==1)
129 return 0;
130 x= "ls -al \"%s\"";
131 y= sprintf(x,filename);
132 y|getline a;
133 close(y);
134 number_of_fields= split(a,parts);
135 if(number_of_fields<9)
136 {
137 print"ERROR ===> ls -al should be 9 fields and it isn't: "a" no fields: "number_of_fields;
138 return 0;
139 }
140 i= strtonum(parts[5]);
141 if(i> 0){
142 return 0;
143 }
144 a= "\"%s\" 'Empty file to be deleted'";
145 b= sprintf(a,filename);
146 print b;
147 #delete_file(filename);
148 return 1;
149 }
150 # section no:19*/
151 # section no20:*/
152 function chk_empty_directory(filename)
153 {
154 if(is_file_a_directory(filename)==0)
155 return 0;
156 x= "du -sk \"%s\"";
157 y= sprintf(x,filename);
158 y|getline a;
159 close(y);
160 number_of_fields= split(a,parts);
161 i= strtonum(parts[1]);
162 if(i> 0)
163 return 0;
164 a= "\"%s\" 'Empty directory to be deleted or needs to add info.txt file inside it'";
165 b= sprintf(a,filename);
166 print b;
167 return 1;
168 }
169 # section no:20*/
170 # section no26:*/
171 function delete_file(filename)
172 {
173 x= "rm -i \"%s\"";
174 y= sprintf(x,filename);
175 y|getline a;
176 close(y);
177 }
178 # section no:26*/
179 # section no22:*/
180 function chk_file_to_bypass_in_zip(filename)
181 {
182 str= ".(DS_Store|.nbattrs)$";
183 if(filename~str){
184 a= "\"%s\" 'Bypass file in zip'";
185 b= sprintf(a,filename);
186 print b;
187 return 1;
188 }
189 return 0;
190 }
191 # section no:22*/
192 # section no28:*/
193 function pass1_guidelines_verify(filename)
194 {
195 chk_auxiliary_files(filename);
196 chk_extended_file_attributes(filename);
197 chk_empty_files(filename);
198 chk_empty_directory(filename);
199 chk_file_permissions(filename);
200 chk_file_to_bypass_in_zip(filename);
201 }
202 # section no:28*/
203 # section no29:*/
204 function pass2_correct(filename,message)
205 {
206 #remove_file_s_execute_attribute(filename,message);
207 #remove_file_s_extended_attributes(filename,message);
208 #delete_file(filename);
209 }
210 # section no:29*/
211 # section no31:*/
212 BEGIN{
213 rec_cnt= 0;
214 }
215 # section no:31*/
216 # section no32:*/
217 {
218 pass1_guidelines_verify($1);
219 #pass2_correct($1,$2);
220 }
221 # section no:32*/
222 # section no33:*/
223 END{
224 #print "no records read: " NR;
225 }
226 # section no:33*/
227 # section no:34*/