home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / msub12.zip / MS-SPACE.MS < prev    next >
Text File  |  1995-05-19  |  3KB  |  110 lines

  1. # This file is an Msub script.
  2.  
  3. # See documention at the end of the script, after !end
  4.  
  5. #
  6. # DECLARATIONS:
  7. #
  8.  
  9.  
  10.     # :b = blanks, whitespace except $^
  11.  
  12. !:b=[\ \9]*
  13.  
  14.  
  15.     # :s = search- or replace-expression:
  16.     # Begins with a significant (non-space) character, but not # or !
  17.  
  18. !:s=[^"#!":w].*
  19.  
  20.  
  21. #
  22. # SUBROUTINE doit.
  23. # ARGUMENT: A regular expression with insignificant leading whitespace
  24. #    removed, but not trailing, and including a trailing $
  25. #    (end-of-line).
  26. # DOES: do_todays_work(); /* always a useful subroutine :-) */
  27. # RETURN VALUE: Expressions with proper quotes.
  28. #
  29. !sub doit
  30.     # Leave existing quotes alone:
  31.     \"[^\"$^]*\"
  32.     `
  33.  
  34.     \'[^\'$^]*\'
  35.     `
  36.  
  37.     "\"[^a-zA-Z$^]
  38.     `
  39.  
  40.     # Leave trailing whitespace alone:
  41.     :b$
  42.     `
  43.  
  44.     # Quote spaces, three different ways:
  45.     
  46.     # 1. If followed by a quote, include it in the quote:
  47.     ~1" "+~1~2[\'\"]~2
  48.     ~2~1
  49.  
  50.     # 2. Otherwise, if there are more of them, enclose in quotes:
  51.     /' '' '+/[^:w\'\"]
  52.     \"`\"
  53.  
  54.     # 3. Just one, use a backslash.
  55.     /' '/[^:w\'\"]
  56.     "\ "
  57. !end
  58.  
  59.     # Do changes on search- and replace-lines:
  60. ^:b/:s$/
  61. \doit(`)
  62.  
  63.     # In an option like "!:x=sth", "sth" is a regular expression
  64.     # that must be worked on.
  65. ^:b"!":b":":b[a-zA-Z]:b"="?:b/[^:b$^'='].*$/
  66. \doit(`)
  67.  
  68. !newpass
  69.  
  70.     # Continued lines. Work on the continuation.
  71. "\":b$^:b/[^:b$^].*$/
  72. \doit(`)
  73.  
  74. !end
  75.  
  76. ==================================================
  77. ===  Change of semantics for space character  ====
  78. ==================================================
  79.  
  80. What is changing?
  81. =================
  82. Nothing has changed so far. But starting with the next version, a space
  83. that is not within "..." or '...' quotes, or preceeded with \, will be
  84. ignored. Meaning that e.g. a search-replace pair such as
  85.     John Doe
  86.     someone unknown
  87. will search for "JohnDoe" and replace it with "someoneunknown". 
  88.  
  89. So what do *I* need to do about it?
  90. ===================================
  91. You must make sure the significant spaces in your scripts are quoted. You
  92. don't need to do that by hand, that's what this script is for. Just run
  93. this script on your old scripts, and they will be properly updated.
  94.  
  95. The script is not perfect: It is assumed, that continued lines contains
  96. regular expressions to be updated, and that ".." og '..' quotes are not
  97. broken across lines (which is poor style but presently possible).
  98.  
  99. Why this change?
  100. ================
  101. Because it will give you greater freedom to format your search- and
  102. replace-expressions, making them more readable.  Which is important
  103. because, as I've said before, writing regular expressions is a kind of
  104. programming.
  105.  
  106. Sorry for the inconvenience, but I didn't get it quite right the first
  107. time.
  108.  
  109. -Anders 
  110.