| 1 |
% file: ctan_chk.w |
| 2 |
% |
| 3 |
\def\Tex{\TeX} |
| 4 |
\def\cweb{\Cweb} |
| 5 |
\def\Cweb{{\prgstyle Cweb}} |
| 6 |
\def\prgstyle{\tt \sl } |
| 7 |
\def\NOsign{ |
| 8 |
{\tt{\char`\#}} |
| 9 |
} |
| 10 |
\def\Verticalbar{{\tt \char`|}} |
| 11 |
\def\GTsign{ |
| 12 |
\ifmmode |
| 13 |
> |
| 14 |
\else |
| 15 |
$>$ |
| 16 |
\fi |
| 17 |
} |
| 18 |
\def\Arrow{$\Rightarrow$} |
| 19 |
\def\prtobrace{$\{$} |
| 20 |
\def\prtcbrace{$\}$} |
| 21 |
\def\Backslash{ |
| 22 |
{\tt\char`\\} |
| 23 |
} |
| 24 |
|
| 25 |
\def\printlistinglineno{\hskip .7 in \llap{\the\lineno:\quad}} |
| 26 |
\def\ptindent#1{\line{\hskip.5in{#1}\hfill}} |
| 27 |
\def\Yacco2{Ya$c_2o_2$} |
| 28 |
\def\yacco2{\Yacco2} |
| 29 |
\def\O2{$O_2$} |
| 30 |
\def\o2{\O2} |
| 31 |
\def\Cpp{C\kern-.25em \raise.25ex\hbox{\tt $+\kern-0.2ex+$}} |
| 32 |
\def\Olinker{$O_{2}^{linker}$} |
| 33 |
\def\olinker{$O_{2}^{linker}$} |
| 34 |
\def\TILDE{\catcode`\~=11{}~} |
| 35 |
\def\INDENT#1#2{\line{\hskip#1{#2}\hfill}} |
| 36 |
\def\fbreak{\hfill\break} |
| 37 |
|
| 38 |
|
| 39 |
@* Gawk program |ctan_chk.gawk|.\fbreak |
| 40 |
Basic Gawk program that uses Ctan's published guidelines for authors to help eliminate slopiness in uploaded files/project. |
| 41 |
It is completely open for users to program additional guidelines and Ctan's future adjustments. |
| 42 |
The program came about when I first attempted to upload ``Yacco2'' for Ctan consideration. |
| 43 |
As Yacco2 was quite large, it took me 3 attempts to clean up my project. |
| 44 |
Depending on how u develop your project, in my case the Yacco2 project for Ctan upload is a subset of the complete system |
| 45 |
and so each uplift required the guideline assessment/purging process. |
| 46 |
|
| 47 |
This is my attempt to help both the author in getting the new system in shape for Ctan uplift |
| 48 |
and to lower the Ctan volanteers interaction to aid for publishing on their servers. |
| 49 |
It is my thank you to these volanteers / Ctan. |
| 50 |
\fbreak |
| 51 |
\fbreak |
| 52 |
This |gawk| program verifies whether an upload project for CTAN |
| 53 |
follows its published guidelines on their website:\fbreak |
| 54 |
\ptindent{http://ctan.org/upload/} |
| 55 |
\fbreak |
| 56 |
Here is the link to the awk/gawk reference manual for people needing a refresher to its programming statements:\fbreak |
| 57 |
\ptindent{https://www.gnu.org/software/gawk/manual/gawk.html\#Reading-Files} |
| 58 |
|
| 59 |
@*1 License.\fbreak |
| 60 |
ctan\_chk's distributed source code is subject to the terms of the GNU General Public License (version 3). |
| 61 |
If a copy of the MPL was not distributed with this file, you can obtain one at https://gnu.org/licenses/gpl.html. |
| 62 |
\fbreak |
| 63 |
\fbreak |
| 64 |
\ptindent{Project: ctan guidelines verifier and corrector program for uploading projects} |
| 65 |
\ptindent{Distributed under license: GNU General Public License (version 3).} |
| 66 |
\ptindent{Distribution Date: \today} |
| 67 |
\ptindent{Distribution version: 1.0} |
| 68 |
\ptindent{Comments: Currently for the Unix flavoured Platforms running Gawk} |
| 69 |
\ptindent{Author: Dave Bone} |
| 70 |
\fbreak |
| 71 |
\ptindent{Contributors list:} |
| 72 |
\ptindent{ Dave Bone} |
| 73 |
|
| 74 |
@*2 |Ctan_chk| reference.\fbreak |
| 75 |
Unzip the |ctan_chk.zip| file. |
| 76 |
Please read |ctan_chk.pdf| document. It instructs one in ``how to'' use the gawk |ctan_chk.gawk| program. |
| 77 |
|
| 78 |
@*2 Literate Programming genre.\fbreak |
| 79 |
|ctan_chk.pdf| user manual and |ctan_chk.gawk| program are generated by the Cweb system's |
| 80 |
{\it{cweave}} and {\it{ctangle}} programs along with the {\it{pdftex}}. |
| 81 |
The |ctan_chk_bash| script does it all for u; have a read it doesn't bite. |
| 82 |
Please consider using Cweb and joining |
| 83 |
``www.tug.org'' where u'll find the Cweb system. |
| 84 |
|
| 85 |
@*1 Comments on program's functions.\fbreak |
| 86 |
Normally u edit the |ctan_chk.gawk| file (using gawk comments) as to what "verification function" is called to check out your project's files. |
| 87 |
Here is a list of the verification functions to call:\fbreak |
| 88 |
Helper functions:\fbreak |
| 89 |
\ptindent{|is_file_a_directory| --- is file a directory type rather than a data type?} |
| 90 |
\ptindent{|is_file_an_executable| --- Maybe too platform dependent: is it an executable} |
| 91 |
\fbreak |
| 92 |
Verification functions:\fbreak |
| 93 |
\ptindent{|chk_auxiliary_files| --- files that should be removed / deleted} |
| 94 |
\ptindent{|chk_file_permissions| --- file execute permissions check} |
| 95 |
\ptindent{|chk_extended_file_attributes| --- does file have extended attribute like @@} |
| 96 |
\ptindent{|chk_empty_files| --- zero byte size file?} |
| 97 |
\ptindent{|chk_empty_directory| --- empty folder} |
| 98 |
\ptindent{|chk_file_to_bypass_in_zip| --- file to bypass by zip using its -x option} |
| 99 |
\fbreak |
| 100 |
Correction functions:\fbreak |
| 101 |
\ptindent{|remove_file_s_execute_attribute| --- Read ``Remove file's execute attribute'' section for details} |
| 102 |
\ptindent{|delete_file| --- interacts with user. Used by itself or from other functions like |chk_auxiliary_files|} |
| 103 |
\ptindent{|remove_file_s_extended_attributes| --- Remove extended attribute from file (platform dependent)} |
| 104 |
|
| 105 |
@*2 Running Gawk program has 2 run/pass attitude.\fbreak |
| 106 |
U run this program twice with appropriate editing sessions inbetween the run passes:\fbreak |
| 107 |
\ptindent{run Pass 1 function where your edited functions to call and capturing output with {\it{tee}} utility} |
| 108 |
\ptindent{\Arrow{} pass 1's input file is an absolute pathed files list. See |How to use this gawk program| section} |
| 109 |
\ptindent{\Arrow{} assess the messages outputted as to what guidelines need to be corrected} |
| 110 |
\ptindent{\Arrow{} outputted messages have 2 parts: part 1 the filename and part 2 the quoted message} |
| 111 |
\fbreak |
| 112 |
\ptindent{run Pass 2 function where u comment out pass 1 call and uncomment pass 2 function call} |
| 113 |
\ptindent{\Arrow{} inside the |pass2_correct| function, uncomment the appropriate correction function to call} |
| 114 |
\ptindent{\Arrow{} the captured messages from {\it{tee}} of pass 1 is its inputted file} |
| 115 |
\ptindent{\Arrow{} in awk/gawk terms this |gawk|'s record is composed of fields where the field separator is space} |
| 116 |
\ptindent{\Arrow{} so the 2nd pass receives the 2 fields filename, and message} |
| 117 |
\fbreak |
| 118 |
\fbreak |
| 119 |
Output example of guideline violations from Pass 1:\fbreak |
| 120 |
\ptindent{\Arrow{} "/yacco2/.DS\_Store" 'Extended attributes -rwxr-xr-x@@'} |
| 121 |
\ptindent{\Arrow{} "/yacco2/.DS\_Store" 'Write permissions -rwxr-xr-x@@ to possibly delete file type: data'} |
| 122 |
\ptindent{\Arrow{} "/yacco2/.DS\_Store" 'Bypass file in zip'} |
| 123 |
\ptindent{\Arrow{} "/yacco2/.gitignore" 'Auxilary file to be deleted'} |
| 124 |
\ptindent{\Arrow{} "/yacco2/.nbattrs" 'Extended attributes -rwxr-xr-x+'} |
| 125 |
\ptindent{\Arrow{} "/yacco2/.nbattrs" 'Write permissions -rwxr-xr-x+ to possibly delete file type: XML'} |
| 126 |
\ptindent{\Arrow{} "/yacco2/.nbattrs" 'Bypass file in zip'} |
| 127 |
\ptindent{\Arrow{} "/yacco2/bin/.DS\_Store" 'Extended attributes -rwxr-xr-x@@'} |
| 128 |
\ptindent{\Arrow{} "/yacco2/bin/.DS\_Store" 'Write permissions -rwxr-xr-x@@ to possibly delete file type: data'} |
| 129 |
\ptindent{\Arrow{} "/yacco2/bin/.DS\_Store" 'Bypass file in zip'} |
| 130 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/1lrerrors.log" 'Auxilary file to be deleted'} |
| 131 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/1lrerrors.log" 'Empty file to be deleted'} |
| 132 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/1lrtracings.log" 'Auxilary file to be deleted'} |
| 133 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/1lrtracings.log" 'Empty file to be deleted'} |
| 134 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/o2.man" 'Extended attributes -rw-r--r--@@'} |
| 135 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/o2linker.man" 'Extended attributes -rw-r--r--@@'} |
| 136 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/yacco2.man" 'Extended attributes -rw-r--r--@@'} |
| 137 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/yacco2cmd.tmp" 'Auxilary file to be deleted'} |
| 138 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/yacco2cmd.tmp" 'Empty file to be deleted'} |
| 139 |
\ptindent{\Arrow{} "/yacco2/bld\_bash\_APPLE" 'Extended attributes -rwxr-xr-x@@'} |
| 140 |
\ptindent{\Arrow{} "/yacco2/bld\_bash\_APPLE" 'Write permissions -rwxr-xr-x@@ to possibly delete file type: ASCII'} |
| 141 |
\ptindent{\Arrow{} "/yacco2/book/appendix\_a.aux" 'Auxilary file to be deleted'} |
| 142 |
\ptindent{\Arrow{} "/yacco2/book/ch\_fsm.tex" 'Write permissions -rwxr-xr-x@@ to possibly delete file type: LaTeX'} |
| 143 |
\fbreak |
| 144 |
Running the initial program could potentially output the above sampling. |
| 145 |
If there are just 1 message type outputted then u would just focus on ``pass 2'' to correct it. |
| 146 |
Having a mix of messages means ``pass 1'' should be edited to just deal with the 1 message type |
| 147 |
at a time. This allows the homogenous output to be captured and edit the removal of files to bypass. |
| 148 |
Now the program can be edited to support the message type action correcting the violation |
| 149 |
and rerun. |
| 150 |
Each listed guideline type would go thru this edit behaviour: ``pass 1'' to see the violations, analyse its outcome, |
| 151 |
re-edit program, and then run the correction. |
| 152 |
|
| 153 |
@*2 Anatomy of this |gawk| program.\fbreak |
| 154 |
It contains 3 |gawk| actions: BEGIN, Body, and END. |
| 155 |
This program's BEGIN and END actions are just read record stats. |
| 156 |
U can add your own code as this program is open to your creativity. |
| 157 |
The action Body contains the 2 passes: |pass1_guidelines_verify| and |pass2_correct|. |
| 158 |
To comment out a function call, add a \NOsign{} at the beginning of its line. |
| 159 |
To activate a commented out function call, just remove its |gawk|'s comment character: \NOsign. |
| 160 |
|
| 161 |
@*2 How to generate the pdf document and this gawk program.\fbreak |
| 162 |
The \Cweb{} ``literate programming'' framework is used to generate |
| 163 |
its pdf document and its gawk program from |ctan_chk.w|. |
| 164 |
Though Cweb emits a ``c'' type code, gawk code is very similar to ``c''.\fbreak |
| 165 |
0) Run from a terminal using bash.\fbreak |
| 166 |
\ptindent{{\bf{. ctan\_chk\_bash}}} |
| 167 |
\ptindent{\Arrow{} The various utilities used are outputed on the terminal} |
| 168 |
|
| 169 |
U are open to add your own code to the |ctan_chk.w| program and rerun the above script. |
| 170 |
If u do not have the \Cweb{} framework installed, u can |
| 171 |
add the code to the |ctan_chk.gawk| file. |
| 172 |
|
| 173 |
@*2 How to use this gawk program.\fbreak |
| 174 |
0) Run from a terminal using bash.\fbreak |
| 175 |
1) Generate a file containing your project's files whose path is absolute\fbreak |
| 176 |
\ptindent{{\bf{find /absolute path of your project \GTsign{} xxx}}} |
| 177 |
\ptindent{\Arrow{} xxx is a holding file containing your project's files} |
| 178 |
\ptindent{\Arrow{} example of an absolute path: {\bf {/usr/local/yacco2}}} |
| 179 |
2) Edit |ctan_chk.gawk| to what function calls u want to use inside |pass1_guidelines_verify|\fbreak |
| 180 |
3) Run gawk ctan\_chk program verifying your project\fbreak |
| 181 |
\ptindent{{\bf{gawk -f ctan\_chk.gawk xxx}} \NOsign xxx is the file read containing the files to assess}\fbreak |
| 182 |
\ptindent{\Arrow{} it outputs files to correct on the terminal with appropriate guideline message} |
| 183 |
\ptindent{\Arrow{} no outputted messages means your project passed with flying colours :\prtcbrace} |
| 184 |
\fbreak |
| 185 |
\ptindent{\Arrow{} To capture the verification output:} |
| 186 |
\ptindent{{\bf{gawk -f ctan\_chk.gawk xxx\Verticalbar{}tee yyy}}}\fbreak |
| 187 |
\ptindent{\Arrow{} Use of {\it{tee}} utility to capture the output into yyy file} |
| 188 |
|
| 189 |
@*3 Example: Checking auxilary files to delete.\fbreak |
| 190 |
Here are the steps to see whether there are files to remove/delete. |
| 191 |
File xxx contains the files to verify as exampled earlier in this document.\fbreak |
| 192 |
1) {\bf{gawk -f ctan\_chk.gawk xxx}}\fbreak |
| 193 |
\fbreak |
| 194 |
2) Its output should have messages similar to this:\fbreak |
| 195 |
\ptindent{\Arrow{} "/yacco2/bin/man/man1/1lrerrors.log" 'Auxilary file to be deleted'} |
| 196 |
\fbreak |
| 197 |
3) Rerun {\bf{gawk -f ctan\_chk.gawk xxx\Verticalbar{}tee yyy}} where the output messages are put in {\bf{yyy}} file.\fbreak |
| 198 |
\break |
| 199 |
4) Edit: comment out pass1\_guidelines\_verify and uncomment \#pass2\_correct in Body action code:\fbreak |
| 200 |
The gened |ctan_chk.gawk| program could have different commented ``section no:'' used in the below |
| 201 |
edit session. What is important are function names referenced: for example, |pass1_guidelines_verify| which |
| 202 |
you'll find in your |ctan_chk.gawk| program. Same comments apply against the other pieces of code being edited.\fbreak |
| 203 |
\ptindent{\# section no:22*/} |
| 204 |
\ptindent{\# section no28:*/} |
| 205 |
\ptindent{\prtobrace} |
| 206 |
\ptindent{ pass1\_guidelines\_verify(\$1);} |
| 207 |
\ptindent{ \#pass2\_correct(\$1,\$2);} |
| 208 |
\ptindent{\prtcbrace} |
| 209 |
to\fbreak |
| 210 |
\ptindent{\# section no:22*/} |
| 211 |
\ptindent{\# section no28:*/} |
| 212 |
\ptindent{\prtobrace} |
| 213 |
\ptindent{ \#pass1\_guidelines\_verify(\$1);} |
| 214 |
\ptindent{ pass2\_correct(\$1,\$2);} |
| 215 |
\ptindent{\prtcbrace} |
| 216 |
\fbreak |
| 217 |
5) Edit: uncomment out \#delete\_file in pass2\_correct:\fbreak |
| 218 |
\ptindent{\# section no:28*/} |
| 219 |
\ptindent{\# section no29:*/} |
| 220 |
\ptindent{function pass2\_correct(filename,message)} |
| 221 |
\ptindent{\prtobrace} |
| 222 |
\ptindent{ \#remove\_file\_s\_execute\_attribute(filename,message);} |
| 223 |
\ptindent{ \#remove\_file\_s\_extended\_attributes(filename,message);} |
| 224 |
\ptindent{ \#delete\_file(filename);} |
| 225 |
\ptindent{\prtcbrace} |
| 226 |
to\break |
| 227 |
\ptindent{\# section no:28*/} |
| 228 |
\ptindent{\# section no29:*/} |
| 229 |
\ptindent{function pass2\_correct(filename,message)} |
| 230 |
\ptindent{\prtobrace} |
| 231 |
\ptindent{ \#remove\_file\_s\_execute\_attribute(filename,message);} |
| 232 |
\ptindent{ \#remove\_file\_s\_extended\_attributes(filename,message);} |
| 233 |
\ptindent{ delete\_file(filename);} |
| 234 |
\ptindent{\prtcbrace} |
| 235 |
\fbreak |
| 236 |
\fbreak |
| 237 |
\fbreak |
| 238 |
\fbreak |
| 239 |
\fbreak |
| 240 |
\fbreak |
| 241 |
6) Save edited |ctan_chk.gawk| program and rerun with {\bf{yyy}}:\fbreak |
| 242 |
\ptindent{\Arrow{} {\bf {gawk -f ctan\_chk.gawk yyy}}} |
| 243 |
Each file being deleted is questioned and allows u to bypass it.\fbreak |
| 244 |
This is due to the {\bf{-i}} option used in {\it{rm -i file-to-delete}}\fbreak |
| 245 |
\fbreak |
| 246 |
Other guideline contraints would follow the same run / edit / rerun template above adjusting |
| 247 |
the program accordingly.\fbreak |
| 248 |
\ptindent{\Arrow{} {\bf{Just remember to reset the program back to its initial setting.}}} |
| 249 |
As an aside comment, u could have uncommented the |delete_file| call inside the |
| 250 |
|chk_auxiliary_files| function and do the correction while in the ``assess guideline'' pass. |
| 251 |
So why did u not express this before :\prtobrace? |
| 252 |
Well the normal correction pattern is see what guidelines are violated by ``pass 1', edit the program, |
| 253 |
and then rerun against ``pass 2'' correction. |
| 254 |
Once u are familiar with the program throw out my patterns and jig your own :\prtcbrace. |
| 255 |
@* Function code sections. |
| 256 |
@*2 ctan gawk's comments --- author, license etc. |
| 257 |
@<Emit gawk comments@>= |
| 258 |
# |
| 259 |
# Program: ctan_chk.gawk |
| 260 |
# |
| 261 |
# Author: Dave Bone |
| 262 |
# |
| 263 |
# License: |
| 264 |
# This Source Code Form is subject to the terms of the GNU General Public License (version 3). |
| 265 |
# If a copy of the MPL was not distributed with this file, |
| 266 |
# You can obtain one at: "https://gnu.org/licenses/gpl.html". |
| 267 |
# |
| 268 |
# Purpose: Implementation of some suggested CTAN guidelines that an upload project should respect. |
| 269 |
# Correction functions help u cleanup the droppings. |
| 270 |
# See www.ctan.org website for "upload guideline" document |
| 271 |
# Read ctan_chk.pdf document describing the program with various run scenarios. |
| 272 |
# |
| 273 |
# |
| 274 |
|
| 275 |
@*1 Helper functions. |
| 276 |
@*2 Is file a directory.\fbreak |
| 277 |
Directory found returns 1. |
| 278 |
@<|is_file_a_directory|@>= |
| 279 |
function is_file_a_directory(filename, filetype)@\ |
| 280 |
{ |
| 281 |
x="file \"%s\""; |
| 282 |
y=sprintf(x,filename); |
| 283 |
y|getline a; |
| 284 |
close(y); |
| 285 |
split(a,parts); |
| 286 |
filetype[1] = parts[2]; |
| 287 |
xx = parts[2]; |
| 288 |
str= "^directory$"; |
| 289 |
if (xx ~ str) { |
| 290 |
return 1; |
| 291 |
} |
| 292 |
return 0; |
| 293 |
} |
| 294 |
|
| 295 |
@*2 Is file an executable.\fbreak |
| 296 |
This function {\bf{might be too platform dependent}}.\fbreak |
| 297 |
If so then don't call it or find an alternative.\fbreak |
| 298 |
A return 1 means it's an executable. |
| 299 |
@<|is_file_an_executable|@>= |
| 300 |
function is_file_an_executable(filename, filetype)@\ |
| 301 |
{ |
| 302 |
x="file %s"; |
| 303 |
y=sprintf(x,filename); |
| 304 |
y|getline a; |
| 305 |
close(y); |
| 306 |
split(a,parts); |
| 307 |
filetype[1] = parts[2]; |
| 308 |
xx = parts[2]; |
| 309 |
str= "(executable|POSIX|Mach-O|ELF)$"; |
| 310 |
if (xx ~ str) { |
| 311 |
return 1; |
| 312 |
} |
| 313 |
return 0; |
| 314 |
} |
| 315 |
|
| 316 |
@*1 Guideline assessment functions. |
| 317 |
@*2 Check for auxiliary type files.\fbreak |
| 318 |
``str'' contains a regular expression of file extensions to search for starting with a ``.'' followed by |
| 319 |
the round bracket expression of extensions to search on ending by the end-of-string regular expression indicator: \$. |
| 320 |
Inside the rounded bracket expression is the choice of extensions separated by \Verticalbar{} |
| 321 |
which is the ``or'' operator of a regular expression.\fbreak |
| 322 |
\fbreak |
| 323 |
The double \Backslash{} in str is due to how gawk parses the program code: |
| 324 |
it does a double pass:\fbreak |
| 325 |
\ptindent{1) on the string: str} |
| 326 |
\ptindent{2) on the regular expression called} |
| 327 |
Just having a ``.'' at the start of regular expression means it is a single ``wild character'' to accept. |
| 328 |
To accept a period ``.'' that starts the file extension, u have to escape it. |
| 329 |
Pass 1 for the literal string is the first escape sequence on \Backslash{} the 2nd backslash. |
| 330 |
In pass 2 for the regular expession called, the \Backslash{} escapes the ``.'' to not interpret |
| 331 |
as the regular expression wild character.\fbreak |
| 332 |
\fbreak |
| 333 |
str can be added to. Make sure u include the added extension started with the \Verticalbar{} when appended to before |
| 334 |
the closing off rounded bracked ``)''. \fbreak |
| 335 |
\fbreak |
| 336 |
|chk_auxiliary_files| outputs a 2 part message: file name and message it considers as an auxiliary file to be deleted. |
| 337 |
Calling |delete_file| interacts with the user whether to delete it or not. |
| 338 |
It is commented out so that the messages can saved and reviewed before the correction pass takes place: |
| 339 |
See |Pass 2 --- correct violated guidelines| section providing more information. |
| 340 |
U can uncomment the |delete_file| statement below if u prefer to delete the file in the assessment pass |
| 341 |
rather than the correction pass. Your call and temperment. |
| 342 |
@<|chk_auxiliary_files|@>= |
| 343 |
function chk_auxiliary_files(filename)@\ |
| 344 |
{ |
| 345 |
if (is_file_a_directory(filename) == 1) |
| 346 |
return 0; |
| 347 |
|
| 348 |
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)$"; |
| 349 |
if (filename ~ str) { |
| 350 |
a= "\"%s\" 'Auxilary file to be deleted'"; |
| 351 |
b= sprintf(a,filename); |
| 352 |
print b; |
| 353 |
#delete_file(filename); |
| 354 |
return 1; |
| 355 |
} |
| 356 |
return 0; |
| 357 |
} |
| 358 |
|
| 359 |
@*2 Check for extended attributes.\fbreak |
| 360 |
Basicly looks at the output from the ``ls -al'' of a file. |
| 361 |
If there are extended attributes it will be displayed at the end of the first field as ``@@'' or ``+''. |
| 362 |
It outputs the filename and message to the terminal. |
| 363 |
Return 1 if found. |
| 364 |
@<|chk_extended_file_attributes|@>= |
| 365 |
function chk_extended_file_attributes(filename)@\ |
| 366 |
{ |
| 367 |
x="ls -al \"%s\""; |
| 368 |
y=sprintf(x,filename); |
| 369 |
y|getline a; |
| 370 |
close(y); |
| 371 |
number_of_fields = split(a,parts); |
| 372 |
if (number_of_fields < 9) |
| 373 |
return 0; |
| 374 |
|
| 375 |
xx=parts[1]; |
| 376 |
str= "(@@|+)$"; |
| 377 |
if (xx !~ str) { |
| 378 |
return 0; |
| 379 |
} |
| 380 |
|
| 381 |
a="\"%s\" 'Extended attributes %s'"; |
| 382 |
b=sprintf(a,filename,parts[1]); |
| 383 |
print b; |
| 384 |
#remove_file_s_extended_attributes(filename,b); |
| 385 |
return 1; |
| 386 |
} |
| 387 |
@*2 Check for empty files.\fbreak |
| 388 |
Uncomment out the |delete_file| statement below if u want to remove it in the assessment phase. |
| 389 |
Asks whether to delete the zero sized file and returns 1. |
| 390 |
@<|chk_empty_files|@>= |
| 391 |
function chk_empty_files(filename)@\ |
| 392 |
{ |
| 393 |
if (is_file_a_directory(filename) == 1) |
| 394 |
return 0; |
| 395 |
|
| 396 |
x="ls -al \"%s\""; |
| 397 |
y=sprintf(x,filename); |
| 398 |
y|getline a; |
| 399 |
close(y); |
| 400 |
number_of_fields = split(a,parts); |
| 401 |
if (number_of_fields < 9)@\ |
| 402 |
{ |
| 403 |
print "ERROR ===> ls -al should be 9 fields and it isn't: " a " no fields: " number_of_fields; |
| 404 |
return 0; |
| 405 |
} |
| 406 |
i=strtonum(parts[5]); |
| 407 |
if (i > 0){ |
| 408 |
return 0; |
| 409 |
} |
| 410 |
a="\"%s\" 'Empty file to be deleted'"; |
| 411 |
|
| 412 |
b=sprintf(a,filename); |
| 413 |
print b; |
| 414 |
#delete_file(filename); |
| 415 |
return 1; |
| 416 |
} |
| 417 |
|
| 418 |
@*2 Check for empty directory.\fbreak |
| 419 |
Empty directory found returns a 1.\fbreak |
| 420 |
This check requires u to assess what u want to do: delete it, or add an ``info.txt'' file inside it. |
| 421 |
For example in the ``Yacco2'' project, it is a full |
| 422 |
development framework of a compiler/compile, and its API library. |
| 423 |
It has empty Debug folders. Its Release folders contained content. |
| 424 |
Depending on what the user wanted to debug and link against, the empty Debug folder |
| 425 |
provided consistency to the framework and hence it was needed. So an ``info.txt'' file |
| 426 |
was created inside each Debug folder expressing their intent/use to the developer. |
| 427 |
|
| 428 |
@<|chk_empty_directory|@>= |
| 429 |
function chk_empty_directory(filename)@\ |
| 430 |
{ |
| 431 |
if (is_file_a_directory(filename) == 0) |
| 432 |
return 0; |
| 433 |
|
| 434 |
x="du -sk \"%s\""; |
| 435 |
y=sprintf(x,filename); |
| 436 |
y|getline a; |
| 437 |
close(y); |
| 438 |
number_of_fields = split(a,parts); |
| 439 |
|
| 440 |
i=strtonum(parts[1]); |
| 441 |
if (i > 0) |
| 442 |
return 0; |
| 443 |
|
| 444 |
a="\"%s\" 'Empty directory to be deleted or needs to add info.txt file inside it'"; |
| 445 |
|
| 446 |
b=sprintf(a,filename); |
| 447 |
print b; |
| 448 |
return 1; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
@*2 Check file permissions.\fbreak |
| 453 |
Bypass a directory. |
| 454 |
If the file does not have an executable attribute then exit stage gracefully. |
| 455 |
|
| 456 |
@<|chk_file_permissions|@>= |
| 457 |
function chk_file_permissions(filename)@\ |
| 458 |
{ |
| 459 |
filetype[1]=""; |
| 460 |
if (is_file_a_directory(filename, filetype) == 1) |
| 461 |
return 0; |
| 462 |
if (is_file_an_executable(filename,filetype) == 1) |
| 463 |
return 0; |
| 464 |
|
| 465 |
x="ls -al \"%s\""; |
| 466 |
y=sprintf(x,filename); |
| 467 |
y|getline a; |
| 468 |
close(y); |
| 469 |
|
| 470 |
number_fields = split(a,parts); |
| 471 |
|
| 472 |
str= "x"; |
| 473 |
if (parts[1] ~ str) { |
| 474 |
a="\"%s\" 'Write permissions %s to possibly delete file type: %s'"; |
| 475 |
b=sprintf(a,filename,parts[1],filetype[1]); |
| 476 |
print b; |
| 477 |
return 1; |
| 478 |
} |
| 479 |
return 0; |
| 480 |
} |
| 481 |
|
| 482 |
@*2 Check file to bypass in zip.\fbreak |
| 483 |
This is just a check function that lists files to bypass in the zip file creation process.\fbreak |
| 484 |
An example of creating a zip file:\fbreak |
| 485 |
\ptindent{{\bf{zip -r -ll yacco2.zip yacco2 -x '*DS\_Store' -x '*.nbattrs'}}} |
| 486 |
\ptindent{\Arrow{} -r recurse through the folder getting all its subfolders and their contents} |
| 487 |
\ptindent{\Arrow{} -ll parameter reduces carriage return/line feed combo to line feed} |
| 488 |
\ptindent{\Arrow{} -x parameter lists by regular expression the file(s) to bypass} |
| 489 |
\ptindent{\Arrow{} The bypassed exampled files are Apple OSX specific} |
| 490 |
|
| 491 |
@<|chk_file_to_bypass_in_zip|@>= |
| 492 |
function chk_file_to_bypass_in_zip(filename) |
| 493 |
{ |
| 494 |
str= ".(DS_Store|.nbattrs)$"; |
| 495 |
if (filename ~ str) { |
| 496 |
a="\"%s\" 'Bypass file in zip'"; |
| 497 |
b=sprintf(a,filename); |
| 498 |
print b; |
| 499 |
return 1; |
| 500 |
} |
| 501 |
return 0; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
@*1 Correct guideline violations. |
| 506 |
@*2 Remove file's execute attribute.\fbreak |
| 507 |
Due to security reasons, u cannot have an indirect bash script run against a list of files |
| 508 |
to change their ownership attributes. |
| 509 |
It will run but nothing will be changed.\fbreak |
| 510 |
So what to do?\fbreak |
| 511 |
\ptindent{\Arrow{} gawk -f |ctan_chk.gawk| xxx \Verticalbar{}tee yyy} |
| 512 |
\ptindent{\Arrow{} \ \ \ \ u can use your own temporary file name instead of yyy} |
| 513 |
\ptindent{\Arrow{} \ \ \ \ just remember to substitute your file name in place of yyy} |
| 514 |
\ptindent{\Arrow{} where the |chk_file_permissions| function is the only function run} |
| 515 |
\ptindent{\Arrow{} and the other functions have been commented out} |
| 516 |
\fbreak |
| 517 |
\ptindent{Edit yyy file containing the list of potential files, removing files keeping their execute attribute.} |
| 518 |
\break |
| 519 |
\ptindent{Run this below gawk script interactively from your bash terminal} |
| 520 |
\ptindent{\Arrow{} This means copy the below script line and paste it in the bash terminal} |
| 521 |
\ptindent{\ \ \ \ \ gawk '\prtobrace x="chmod a-x \%s;";y=sprint(x,\$1);system(y);\prtcbrace' yyy} |
| 522 |
\fbreak |
| 523 |
Some comments on the above interactive |gawk| program:\fbreak |
| 524 |
1) It reads the yyy file where each line read contains 2 fields: filename, and message separated by a space\fbreak |
| 525 |
2) It runs the {\it{chmod}} utility by the {\bf{system}} statement\fbreak |
| 526 |
3) Not sure about {\bf{chmod}} utility, do a ``man chmod'' on your bash terminal for more information\fbreak |
| 527 |
4) If u boobooed on a file and removed the execute attribute, here is a correction:\fbreak |
| 528 |
\ptindent{\Arrow{} {\bf{chmod a+x file-to-reimplement}}} |
| 529 |
|
| 530 |
@<|remove_file_s_execute_attribute|@>= |
| 531 |
function remove_file_s_execute_attribute(filename, message)@\ |
| 532 |
{ |
| 533 |
print "Please read |ctan_chk.pdf| to find instructions on how remove execute attribute from a file"; |
| 534 |
} |
| 535 |
|
| 536 |
@*2 Remove file's with extended attributes.\fbreak |
| 537 |
This function is platform dependent. |
| 538 |
The {\it{xattr}} is the utility to run on Apple's OSx platform to remove the extension. |
| 539 |
@<|remove_file_s_extended_attributes|@>= |
| 540 |
function remove_file_s_extended_attributes(filename, message)@\ |
| 541 |
{ |
| 542 |
x="echo %s\";xattr -c %s"; |
| 543 |
y=sprintf(x,message,filename); |
| 544 |
print y; |
| 545 |
#y|getline a; |
| 546 |
#close(y); |
| 547 |
} |
| 548 |
|
| 549 |
@*2 Delete file.\fbreak |
| 550 |
The file name passed to it is displayed and asks whether it should be deleted. |
| 551 |
@<|delete_file|@>= |
| 552 |
function delete_file(filename)@\ |
| 553 |
{ |
| 554 |
x="rm -i \"%s\""; |
| 555 |
y=sprintf(x,filename); |
| 556 |
y|getline a; |
| 557 |
close(y); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
@* Pass 1 / 2 guidelines assessment and correction.\fbreak |
| 562 |
@*2 Pass 1 --- guidelines assessment.\fbreak |
| 563 |
Using a text editor (un)comment out the appropriate function calls in |ctan_chk.gawk| that u'd like to verify. |
| 564 |
For example checking just the files to be deleted, comment out all the below functions except |
| 565 |
|chk_auxiliary_files|. |
| 566 |
|
| 567 |
U can run pass 1 as is to see whether any of your files for upload do not |
| 568 |
pass the guidelines. |
| 569 |
From there u can adjust what function to deal with by commenting out the others fuctions |
| 570 |
and teeing out its found infidelities for pass 2 correction. |
| 571 |
|
| 572 |
@<pass 1 guidelines verify@>= |
| 573 |
function pass1_guidelines_verify(filename) |
| 574 |
{ |
| 575 |
chk_auxiliary_files(filename); |
| 576 |
chk_extended_file_attributes(filename); |
| 577 |
chk_empty_files(filename); |
| 578 |
chk_empty_directory(filename); |
| 579 |
chk_file_permissions(filename); |
| 580 |
chk_file_to_bypass_in_zip(filename); |
| 581 |
} |
| 582 |
|
| 583 |
@*2 Pass 2 --- correct violated guidelines.\fbreak |
| 584 |
There are 3 functions whereby 2 of them do usefull things.\fbreak |
| 585 |
\ptindent{|delete_file| function asks whether its passed file should be deleted} |
| 586 |
\ptindent{\Arrow{} Remove the -i in {\bf{rm -i}} statement if u don't want the interactive question} |
| 587 |
\fbreak |
| 588 |
\ptindent{|remove_file_s_extended_attributes| function is tailored to the Apple platform} |
| 589 |
\ptindent{\Arrow{} Other platforms should have an equivalent {\it{xattr -c}} utility} |
| 590 |
\ptindent{\Arrow{} {\bf{Caveat:}} know what utility to use and adjust accordingly to remove the extension attribute} |
| 591 |
\ptindent{\Arrow{} Have a read at https://en.wikipedia.org/wiki/Extended\_file\_attributes\#cite\_note-14} |
| 592 |
\fbreak |
| 593 |
\ptindent{|remove_file_s_execute_attribute| tells u to read the {\bf{ctan\_chk.pdf}} document} |
| 594 |
\ptindent{\Arrow{} on ``how to remove'' the execute attribute from a file} |
| 595 |
\fbreak |
| 596 |
Uncomment the appropriate below function to call. |
| 597 |
And comment out |pass1_guidelines_verify| statement, and uncomment |pass2_correct| statement |
| 598 |
in |Body| action before reruning this program. |
| 599 |
@<pass 2 guidelines correction@>= |
| 600 |
function pass2_correct(filename, message) |
| 601 |
{ |
| 602 |
#remove_file_s_execute_attribute(filename,message); |
| 603 |
#remove_file_s_extended_attributes(filename,message); |
| 604 |
#delete_file(filename); |
| 605 |
} |
| 606 |
|
| 607 |
@* Gawk Begin, Body, End actions. |
| 608 |
@*2 Begin. |
| 609 |
@<|BEGIN|@>= |
| 610 |
BEGIN{ |
| 611 |
rec_cnt = 0; |
| 612 |
} |
| 613 |
|
| 614 |
@*2 Body. |
| 615 |
@<|Body|@>= |
| 616 |
{ |
| 617 |
pass1_guidelines_verify($1); |
| 618 |
#pass2_correct($1,$2); |
| 619 |
} |
| 620 |
|
| 621 |
@*2 END. |
| 622 |
@<|END|@>= |
| 623 |
END{ |
| 624 |
#print "no records read: " NR; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
@ Write out gawk program. |
| 630 |
@(ctan_chk.gawk@>= |
| 631 |
@<Emit gawk comments@>; |
| 632 |
@<|is_file_a_directory|@>; |
| 633 |
@<|is_file_an_executable|@>; |
| 634 |
@<|chk_auxiliary_files|@>; |
| 635 |
@<|remove_file_s_extended_attributes|@>; |
| 636 |
@<|chk_file_permissions|@>; |
| 637 |
@<|chk_extended_file_attributes|@>; |
| 638 |
@<|chk_empty_files|@>; |
| 639 |
@<|chk_empty_directory|@>; |
| 640 |
@<|delete_file|@>; |
| 641 |
@<|chk_file_to_bypass_in_zip|@>; |
| 642 |
@<pass 1 guidelines verify@>; |
| 643 |
@<pass 2 guidelines correction@>; |
| 644 |
@<|BEGIN|@>; |
| 645 |
@<|Body|@>; |
| 646 |
@<|END|@>; |
| 647 |
|
| 648 |
@** Index. |