# $Header: /work/fixWin2Kpath.awk,v 2.0 2003/06/13 11:16:11 LongPhil Stab $ # This GAWK script is used to help fix the Win2K PATH (as set up by MIS). The # .BAT file `PNWD.bat' invokes PWD.EXE (from the CYGWIN distribution) after # changing to the drive passed as argument 1 so that the actual absolute direc- # tory may be used instead of a relative directory (e.g., we want to have the # path `/w/ORAWIN16/BIN' in the PATH, rather than `W:.' or `W:'). # # Although intended for use with CYGWIN GAWK, the script can probably be used # with DJGPP GAWK as well, because the CYGWIN path functionality has been moved # to `PNWD.bat.' Regardless of which distribution of GAWK runs it, it _MUST_ # be executed in a DOS-box environment, because BASH saves the entire environ- # ment upon startup and restores that same environment upon exit, while DOS # allows ANY process in a process group to change the PATH string. This GAWK # script also expects that the PATH string will be passed in via a pipe, with # elements of the PATH separated by a semicolon (;). The original attempt to # implement this PATH fix used a DOS pipe, which is really a temporary file, but # THIS time, I use a CYGWIN pipe, which is a REAL pipe (see w2kpf.sh in the # /usr/local/bin/ directory, and /cygwin.bat, for details). # # ------------------------------------------------------------------------------ # # $Log: fixWin2Kpath.awk,v $ # Revision 2.0 2003/06/13 11:16:11 LongPhil # o Added diagnostic (commented out, as are all diagnostics) to # dump `j,' the array containing PATH elements; # o Changed all diagnostics to output to STDERR instead of # STDOUT; # o Added code to set `y' to null string before `getline,' because # getline apparently is NOT set to null string if null string is # returned (HEY! That HAS to be either a bug or a d.c.!); # o In PNWD.bat loop, only append `y' to path variable, `m,' if # `y' is NOT null (otherwise, an empty PATH element is added); # o If `m,' the PATH variable, is null at end of parsing loop, # DON'T set `v,' the element separator string, to prevent adding # a null element at the head of the string if the first element # in the string passed in is an invalid drive; # o Since I've made so many changes, bumped revision up to 2.0. # # Revision 1.6 2003/06/12 21:40:37 LongPhil # o Added code to invocation of /PNWD.bat to re-direct STDERR # to /dev/null so that /usr/local/bin/w2kpf.sh doesn't get # any error messages as part of the path. # # Revision 1.5 2003/06/05 14:36:52 LongPhil # o IDIOT! In transferring over the changes I made on my laptop, # I changed the header string so that it would match the check- # out, since I checked it out on my desktop HC machine FROM the # RCSfile on said machine ... but I DELETED the leading `#' # character on the Header line, so the GAWK script failed! # # This simple changed restores the lead `#' sign. # # Revision 1.4 2003/06/05 13:52:10 LongPhil # o Since MIS changed `relative' method of describing PATH to # add `X:' to `X:.' (same thing to DOS), changed comment in # header to reflect this; # o To catch `relative' path with no trailing dot, made dot # optional, and now look for end-of-string in match pattern; # o Added code to detect and remove trailing whitespace in # PATH (don't know what that can do, but I don't think we # want it!); # o Since this script isn't changing very much, and hasn't # really changed in a while, changed state from Exp to Stab. # # Revision 1.3 2002/11/07 00:28:45 LongPhil # o Changed header comment to more accurately reflect what we # currently do; # o Added a line of code to strip trailing semicolon from PATH # string before printing it. # # Revision 1.2 2002/11/07 00:12:09 LongPhil # o Added `/' to front of PNWD.bat command spawned to rectify # relative PATH element; # o Removed `path ' from beginning of final print statement so # that ONLY the PATH string is saved (/bin/x.BAT is the file # that is now run to actually fix the DOS/WIN PATH). # # Revision 1.1 2001/11/01 16:09:37 LONGP # Initial revision # # ------------------------------------------------------------------------------ # { v = "" m = "" n = split( $0, j, ";") # for( i=1; i<=n; i++) print "\t" j[ i] > "/dev/stderr" for( i=1; i<=n; i++) { # print "|" j[i] "|" > "/dev/stderr" if( j[i]~/[[:alpha:]][:][.]?$/) { x = ("/PNWD.bat " substr( j[i], 1, 2) " 2> /dev/null") # print "|" x "|" > "/dev/stderr" y = "" # Clear out Y so we don't pollute next pass! x | getline y close( x) # print y > "/dev/stderr" # Only append Y to PATH if it's NOT null! if( y) m = m v y } else { m = m v j[i] } if( m != "") v = ";" # DON'T change until we have something to append to! # print "v = |" v "|; m = |" m "|" > "/dev/stderr" } gsub( /\15/, "", m) # Strip off any trailing semi-colons, because we don't want to FORCE the user # to have the current directory be in the PATH; let him EXPLICITLY add it! if( substr( m, length( m)) == ";") m = substr( m, 1, (length( m) - 1)) # Strip off any trailing whitespace to prevent confusion in the programmer # (What _does_ that do, anyway?)! k = match( m, /[[:space:]]+$/) if( k) m = substr( m, 1, (RSTART-1)) print m }