From Soiled Agouti, 1 Week ago, written in Plain Text.
  1. # This is the first "gaurd" file for safe imports. We use a chain of @include
  2. # To protect namespace collision and inevitable crash. Oof
  3.  
  4. # The chain is:
  5. #   t0: inital foreign call            -- Original @include request
  6. #   t1: lib/gaurd.dummy.awk            -- Falsely named file to start chain
  7. #   t2: lib/gaurdian.awk               -- Symlink to this file
  8. #   t2: lib/gaurd/gaurdian.init.awk    -- This fiie. Tests request and starts copy
  9. #   t3: lib/gaurd/gaurdian.waiter.awk  -- Another dummy to wait for copy to end
  10. #   xx:  !! DIVERGANCE POINT !!        -- Where the swicth happens
  11. #   t4: $AWK_GAURD_REQUEST             -- Actuall file we wish to source
  12. #   xx:       || OR ||                 -- We found a conflict
  13. #   t4: gaurd.deadend.awk              -- Dummy file to close the loop
  14.  
  15. # t4 gaurd.deadend.awk also resets request chain files and vars.
  16. # these include, clearing AWK_GAURD_REQUEST, resetting AWKPATH, and
  17. # copying dummy files to init positions.
  18.  
  19.  
  20. # Check if $thething we want to @include is in PROCINFO["identifiers"]
  21. # The request is set thru the dummy files that are deadends
  22. # If so we have to deviate the @include chain.
  23. BEGINFILE{
  24.   {FOUND="0"; req=""; reqvec=""; reqid=""}
  25.   # Pull request from current namespace
  26.   #for(req in PROCINFO["identifiers"]) {
  27.   for(req in SYMTAB) {
  28.     if(req=="AWK_GAURD_REQUEST") {
  29.       reqvec=AWK_GAURD_REQUEST
  30.     } else {
  31.       reqvec="AWK_GAURD_NULL"
  32.     }
  33.   }
  34.  
  35.   # Check actual request
  36.   for(reqid in PROCINFO["identifiers"]) {
  37.     if(reqid==reqvec) {
  38.       FOUND=reqvec
  39.       # FOUND $it. aww bugger.
  40.     }
  41.   }
  42. }
  43.  
  44.  
  45. # Next link in chain. Its a dummy file to allow the END{} in this current
  46. # File to run.
  47. #{ print "t1: pre @inc t2" ;}
  48. @include "gaurdian.waiter.awk"
  49. #{ print "t1: post @inc t2" ;}
  50.  
  51.  
  52. # Now call system() and copy prefered version of originally Intended target.
  53. # Fork call with `( foo &)&`. `nohup` is for chumps.
  54. END{
  55.   # ok.. this should work.. system("foo(){ read FOUND && exec;}; foo <<<"FOUND)
  56.   if(FOUND!="0") {
  57.       system("f(){ (cat ~/.awk/lib/gaurd/gaurd.deadend.awk > ~/.awk/lib/${FOUND} 2>/dev/null; exit &)& ;}; g(){ read -N 5 FOUND && f; exit;}; g <<<"FOUND )
  58.     } else {
  59.       system("f(){ (cat ~/.awk/lib/gaurd/vault/${AWK_GAURD_REQUEST} > ~/.awk/lib/${AWK_GAURD_REQUEST} 2>/dev/null; exit &)& ;}; g(){ read -N 5 AWK_GAURD_REQUEST && f; exit;}; g <<<"AWK_GAURD_REQUEST )
  60.     }
  61. }
captcha