home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hcshdemo.zip / csh-os2.zip / SAMPLES / SH_2_CSH / EXPR2.SED < prev    next >
Text File  |  1993-11-24  |  799b  |  40 lines

  1. #    Second-pass expression fixups:
  2.  
  3. #        Optimize expressions (for performance, not functionality) by
  4. #        removing superfluous quoting and curly braces:
  5.  
  6. #        1.    Inside ( ... ) expressions:
  7.  
  8. #                "${foo}"        -->    foo
  9. #                "$foo"        -->    foo
  10. #                "123"            -->    123
  11.  
  12. #        2.    In @ (assignment statements):
  13.  
  14. #                ${foo}        -->    foo
  15. #                $foo            -->    foo
  16.  
  17. #        3. Fixup earlier fixups that were looking for the end of a wordlist:
  18.  
  19. #                A[0] != ""    -->        A != ""
  20.  
  21. #        4. Fixup any assignments not already rewritten:
  22.  
  23. #                foo=...        -->        set foo=...
  24.  
  25. /^[^#]* (.*)/{
  26.     s/"\${\([^}]*\)}"/\1/g
  27.     s/"\$\([^"]*\)"/\1/g
  28.     s/"\([1-9][0-9]*\)"/\1/g
  29.     s/"0"/0/g
  30.     }
  31.  
  32. /^[^#]*@ /{
  33.     s/\${\([^}]*\)}/\1/g
  34.     s/\$\([a-zA-Z0-9_]*\)/\1/g
  35.     }
  36.  
  37. s/\[0\] != ""/ != ""/
  38.  
  39. /^[     ]*[a-zA-Z][a-zA-Z0-9_]*[     ]*=/s/[a-zA-Z]/set &/
  40.