Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 50 lines 1.7 kB view raw
1BEGIN { 2 3 # ppd file keys are separated from their values by a colon, 4 # but "options" may reside between the key name and the colon; 5 # options are separated from the key by spaces 6 # (we also permit tabs to be on the safe side) 7 FS = "[: \t]"; 8 9 # escape regex characters in the old and new command strings 10 gsub(/[]\\.^$(){}|*+?[]/, "\\\\&", old); 11 gsub(/\\/, "\\\\&", new); 12 # ...and surround old command with some regex 13 # that singles out shell command invocations 14 # to avoid replacing other strings that might contain the 15 # command name by accident (like "perl" in "perl-script") 16 new = "\\1" new "\\2"; 17 old = "(^|[;&| \\t\"`(])" old "($|[);&| \\t\"`<>])"; 18 # note that a similar regex is build in the shell script to 19 # filter out unaffected files before this awk script is called; 20 # if the regex here is changed, the shell script should also be checked 21 22 # list of PPD keys that contain executable names or scripts, see 23 # https://refspecs.linuxfoundation.org/LSB_4.0.0/LSB-Printing/LSB-Printing/ppdext.html 24 # https://www.cups.org/doc/spec-ppd.html 25 cmds["*APAutoSetupTool"] = ""; 26 cmds["*APPrinterLowInkTool"] = ""; 27 cmds["*FoomaticRIPCommandLine"] = ""; 28 cmds["*FoomaticRIPPostPipe"] = ""; 29 cmds["*cupsFilter"] = ""; 30 cmds["*cupsFilter2"] = ""; 31 cmds["*cupsPreFilter"] = ""; 32 33} 34 35# since comments always start with "*%", 36# this mechanism also properly recognizes (and ignores) them 37 38{ 39 40 # if the current line starts a new key, 41 # check if it is a command-containing key; 42 # also reset the `isCmd` flag if a new file begins 43 if ($0 ~ /^\*/ || FNR == 1) { isCmd = ($1 in cmds) } 44 45 # replace commands if the current keys might contain commands 46 if (isCmd) { $0 = gensub(old, new, "g") } 47 48 print 49 50}