home *** CD-ROM | disk | FTP | other *** search
-
- The problem this stuff addresses:
-
- I find myself the lone ksh user in a csh community. The tools
- I have to use on a daily basis are set up by a set of csh "source"
- files, which define some of those tools as csh aliases. But,
- dadburn it, I want to use ksh! AND I don't want to have to keep
- redoing my own setup files everytime somebody does something to
- the "standard" environment setup files which everybody is supposed
- to "source". Take it as a given that I'm not going to convince
- anybody that the tool set should be defined in such a way that it
- is independent of which shell you run (the tools in question are
- often aliases for things to convert your environment on the fly -
- stuff like "eval `<gargle>`" where <gargle> is some script that
- generates sources and setenv's).
-
- What I need is to be able to "source" csh scripts under ksh, doing
- the same thing in my ksh environment that the script intended to
- do under csh.
-
- What we got here:
-
- What I do is define a ksh function for "source" which:
-
- 1) uses csh to run the source file, dumping the resultant aliases,
- variables, directory stack, etc. off to a temp file.
-
- 2) runs a translator (the program "korner") over the temp file,
- producing a ksh file to run with "." Korner is in no way
- shape or form intended to handle all the csh constructs
- which could be shoveled into aliases - but it does know
- how to convert simpler argument metasyntax.
-
- 3) does a "." of the file produced in 2), and removes the temp's.
-
- There are LOTS of holes here - the thing is basically a hack - but I've
- been using it and having it work. Doing step 1) alleviates a LOT of
- the problem - let csh figure out its own silly script files and you
- only have to understand what finds its way into the types of aliases
- you need to translate. A pitfall, of course, would be source files
- depending on environmental things set up by preceding source files
- which don't get passed from ksh into csh (cdpath setting, previous
- aliases, etc). You would then have to make a source file of your
- own which sourced all the others, thus letting csh setup the whole
- mess all over again.
-
- This approach even seems to work fast enough to use it on the fly
- as I do - you could also save the output to periodically generate
- your own setup files.
-
- "func" contains my definition for the "source" function. The variable
- KD is defined for use in temp file names. If you define the variable
- KDOUT, the generated ksh "." files will get saved in there. For my
- purposes, I also need to recognize "setenv" and "unsetenv" for the
- generated aliases. You will note that it filters the printenv output
- which gets to the translator. The "source" files I'm using this on do
- "setenv"'s of around 100 variables. Not filtering out the ones that
- the csh "source" didn't change was causing ksh to run out of space
- for variable assignments by reassigning them all the time.
-
- korner.1 is the man page for "korner". The "strtok.c" source
- file may be dispensed with if you have a system strtok() call
- available.
-
- To process the csh directory stack, it is expected that you have
- defined a "pushd" in your ksh definitions. See korner.1.
-
- caveats:
-
- I made no attempt to be comprehensive. I just did a quick look over
- the csh man page, and translated the metasyntax that seemed reasonable
- to translate in processing the aliases.
-
- It's strictly a hand tooled parser - no formal grammar definition or
- anything like that.
-
- I've debugged this only to the extent that it works on the csh source
- files I've had to use.
-
- It's only ever run in one environment - Pyramid OSx, generally in the
- ucb universe, with what I believe is an early ksh version. I haven't
- had occasion to try this thing on other machines / versions of shells,
- etc. Some things, such as the expected output format of the various
- csh commands, were determined simply by examining what the local csh
- did, and slight differences in somebody else's csh might break it.
-
- Because of the above, it will likely have to be tweaked a bit to
- get YOUR set of csh setup files to run through it.
-
- Let me know of significant improvements, fixes, etc.
-
- Bob McQueer
- {amdahl, sun, mtxinu, hoptoad, cpsc6a}!rtech!bobm
-