home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / korner / read.me < prev    next >
Encoding:
Text File  |  1988-01-31  |  4.1 KB  |  94 lines

  1.  
  2. The problem this stuff addresses:
  3.  
  4.     I find myself the lone ksh user in a csh community.  The tools
  5.     I have to use on a daily basis are set up by a set of csh "source"
  6.     files, which define some of those tools as csh aliases.  But,
  7.     dadburn it, I want to use ksh!  AND I don't want to have to keep
  8.     redoing my own setup files everytime somebody does something to
  9.     the "standard" environment setup files which everybody is supposed
  10.     to "source".  Take it as a given that I'm not going to convince
  11.     anybody that the tool set should be defined in such a way that it
  12.     is independent of which shell you run (the tools in question are
  13.     often aliases for things to convert your environment on the fly -
  14.     stuff like "eval `<gargle>`" where <gargle> is some script that
  15.     generates sources and setenv's).
  16.  
  17.     What I need is to be able to "source" csh scripts under ksh, doing
  18.     the same thing in my ksh environment that the script intended to
  19.     do under csh.
  20.  
  21. What we got here:
  22.  
  23.     What I do is define a ksh function for "source" which:
  24.  
  25.         1) uses csh to run the source file, dumping the resultant aliases,
  26.         variables, directory stack, etc. off to a temp file.
  27.  
  28.         2) runs a translator (the program "korner") over the temp file,
  29.         producing a ksh file to run with "."  Korner is in no way
  30.         shape or form intended to handle all the csh constructs
  31.         which could be shoveled into aliases - but it does know
  32.         how to convert simpler argument metasyntax.
  33.  
  34.         3) does a "." of the file produced in 2), and removes the temp's.
  35.  
  36.     There are LOTS of holes here - the thing is basically a hack - but I've
  37.     been using it and having it work.  Doing step 1) alleviates a LOT of
  38.     the problem - let csh figure out its own silly script files and you
  39.     only have to understand what finds its way into the types of aliases
  40.     you need to translate.  A pitfall, of course, would be source files
  41.     depending on environmental things set up by preceding source files
  42.     which don't get passed from ksh into csh (cdpath setting, previous
  43.     aliases, etc).   You would then have to make a source file of your
  44.     own which sourced all the others, thus letting csh setup the whole
  45.     mess all over again.
  46.  
  47.     This approach even seems to work fast enough to use it on the fly
  48.     as I do - you could also save the output to periodically generate
  49.     your own setup files.
  50.  
  51.     "func" contains my definition for the "source" function.  The variable
  52.     KD is defined for use in temp file names.  If you define the variable
  53.     KDOUT, the generated ksh "." files will get saved in there.  For my
  54.     purposes, I also need to recognize "setenv" and "unsetenv" for the
  55.     generated aliases.  You will note that it filters the printenv output
  56.     which gets to the translator.  The "source" files I'm using this on do
  57.     "setenv"'s of around 100 variables.  Not filtering out the ones that
  58.     the csh "source" didn't change was causing ksh to run out of space
  59.     for variable assignments by reassigning them all the time.
  60.  
  61.     korner.1 is the man page for "korner".  The "strtok.c" source
  62.     file may be dispensed with if you have a system strtok() call
  63.     available.
  64.  
  65.     To process the csh directory stack, it is expected that you have
  66.     defined a "pushd" in your ksh definitions.  See korner.1.
  67.  
  68. caveats:
  69.  
  70.     I made no attempt to be comprehensive.  I just did a quick look over
  71.     the csh man page, and translated the metasyntax that seemed reasonable
  72.     to translate in processing the aliases.
  73.  
  74.     It's strictly a hand tooled parser - no formal grammar definition or
  75.     anything like that.
  76.  
  77.     I've debugged this only to the extent that it works on the csh source
  78.     files I've had to use.
  79.  
  80.     It's only ever run in one environment - Pyramid OSx, generally in the
  81.     ucb universe, with what I believe is an early ksh version.  I haven't
  82.     had occasion to try this thing on other machines / versions of shells,
  83.     etc.  Some things, such as the expected output format of the various
  84.     csh commands, were determined simply by examining what the local csh
  85.     did, and slight differences in somebody else's csh might break it.
  86.  
  87.     Because of the above, it will likely have to be tweaked a bit to
  88.     get YOUR set of csh setup files to run through it.
  89.  
  90.     Let me know of significant improvements, fixes, etc.
  91.  
  92. Bob McQueer
  93. {amdahl, sun, mtxinu, hoptoad, cpsc6a}!rtech!bobm
  94.