home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / shroud.zip / READ.ME next >
Text File  |  1989-11-25  |  15KB  |  346 lines

  1.  
  2.                   C-Language Source Code Shrouder, Version 2
  3.  
  4.   Thank you for downloading my C-language source code shrouder!
  5.  
  6.   This program may be used to shroud your C language source code, so that you
  7. can give it to others without giving away your hard work.
  8.  
  9.   I wrote this program so that users of Watcom's excellent C compiler may
  10. safely send their source code to Watcom's customer support staff.  Sometimes,
  11. source code is necessary to isolate and correct bugs in Watcom's products.
  12.  
  13.   By the way, isn't it great to see bugs get fixed quickly?!  How often have
  14. you had to deal with "that other" C compiler vendor because their loop
  15. optimization has bugs?  I would like to commend Karen Ali, Jan Young, Brian
  16. Stecher, Fred Crigger, and others at Watcom for their excellent support of
  17. their important new product!
  18.  
  19.                         What is "Shrouded" Source Code?
  20.  
  21.   Shrouded source code is just your original source code, with comments
  22. removed, and rearranged so that the meaning is the same, but no reasonable
  23. human being would ever want to decipher it.
  24.  
  25.   Sometimes, you may encounter a bug in a compiler that can only be easily
  26. reproduced with your original source code.  In this case, the compiler
  27. vendor's customer support staff will need your source code to reproduce and
  28. correct the problem.
  29.  
  30.   But you, or your employer, may object to sending the source code "off-site",
  31. even if only one module is needed to reproduce the problem.  That is when
  32. shrouding can help.
  33.  
  34.   Just run your source code through this shrouder, and send the shrouded
  35. source code to the compiler vendor.  Chances are that the problem will be
  36. demonstrated by the shrouded source code just as well as by the original
  37. source code.  (So that you don't waste the vendor's time, you should verify
  38. that it does, if possible, before sending it.)
  39.  
  40.                        Distributing Shrouded Source Code
  41.  
  42.   Shrouding has other uses as well.  Some UNIX software vendors distribute
  43. their products in shrouded-source-code form.  This is because UNIX is
  44. available on a number of disparate processors and environments.  A UNIX
  45. software vendor can send his shrouded source code to his customers.  The
  46. customer can then compile it in his own environment.  The vendor has not
  47. disclosed his source code, and yet is able to support numerous environments.
  48.  
  49.   This shrouder can work in this way, within certain limits.  If you write
  50. your source code well, then it can be shrouded with this program and
  51. distributed with confidence that it will work when compiled in various
  52. environments.  See SHROUD.MAN for more information.
  53.  
  54.   More sophisticated shrouders might work with less carefully-written source
  55. code, but I'll wager none are less expensive.
  56.  
  57.                           How Does the Shrouder Work?
  58.  
  59.   The shrouder is actually just a C-language preprocessor, like the one
  60. described in the Kernighan & Ritchie book, and in the ANSI draft standard.
  61. However, it does two thing differently from the standard preprocessor.
  62.  
  63.   First, it replaces all of your identifiers with gobbledygook that nobody
  64. will recognize.
  65.  
  66.   Second, it forms all of your source code (and include files) into long
  67. lines, with no extra spaces.  This makes the code even harder to read.
  68.  
  69.   You won't see any "#define" or "#include" directives in the shrouded source
  70. code, because all of the include files and macro invocations have been
  71. replaced with the text they represent.  "#if" directives are already processed
  72. as well.
  73.  
  74.   You'd be surprised at how awful the result looks to a C programmer!  Who
  75. would have thought that grunging up your source code would have been such a
  76. useful thing to do?
  77.  
  78.                             How To Use the Shrouder
  79.  
  80.   The shrouder is invoked with the following command:
  81.  
  82.         shroud <flags> <files>
  83.  
  84.   We'll talk about the <flags> below.
  85.  
  86.   <files> will generally be just one file, the C source code file that needs
  87. to be shrouded.  For example, to shroud the C source code file EXAMPLE.C, use
  88. the following command:
  89.  
  90.         shroud example.c
  91.  
  92.   The shrouded source code will appear on the screen.  Of course, this doesn't
  93. help if you need to send it to somebody else.  You may use "I/O redirection"
  94. to send the shrouded source code to a file (see your DOS manual).  For
  95. example, the following command will deposit the shrouded source code in the
  96. file EXAMPLE.SHR:
  97.  
  98.         shroud example.c >example.shr
  99.  
  100.   In most cases, this is all that's required.  
  101.  
  102.                              Command Line Options
  103.  
  104.   There are a few options.  These are specified in the <flags> part of the
  105. command.
  106.  
  107.                                 Defining Macros
  108.  
  109.   First, you can define an "empty" macro with the "-d" switch, as follows:
  110.  
  111.         shroud -dMACRO_NAME example.c >example.shr
  112.  
  113.   This macro will be defined as if the first line in the source file was:
  114.  
  115.         #define MACRO_NAME
  116.  
  117.   Note that macro defined in this way have no replacement text.  They are
  118. useful only in "#ifdef" or "#if defined(...)" directives.  We'll see how to
  119. define more complicated macros below.
  120.  
  121.                           Shrouding Library Functions
  122.  
  123.   By default, this shrouder does NOT shroud library functions, variables, and
  124. types.  This is so that it is possible to link the result with the library.
  125. It wouldn't do to replace "printf" with gobbledygook in your code.
  126.  
  127.   However, you may want to shroud library functions as well.  This would make
  128. your source code even more opaque.  You should do this only if simply
  129. compiling your one module demonstrates a problem, and thus need not be linked
  130. with the libraries.
  131.  
  132.   The "-l" switch will cause library functions to be shrouded as well, as
  133. follows:
  134.  
  135.         shroud -l example.c >example.shr
  136.  
  137.   (The shrouder, by default, does not shroud any identifier that is first
  138. encountered in a file that is read as a result of an #include directive with
  139. angle brackets, such as "#include <stdio.h>".  If you use "#include "stdio.h""
  140. instead, the identifiers in STDIO.H will always be shrouded.  The "-l" switch
  141. causes all identifiers to be shrouded, regardless of where they are first
  142. encountered.)
  143.  
  144.                              Retaining Whitespace
  145.  
  146.   By default, the shrouder discards all of the whitespace (spaces, tabs,
  147. newlines, and formfeeds) in your source code.  It forms the shrouded source
  148. code into long lines to make it harder to read.
  149.  
  150.   However, you may want the shrouded source code to resemble your original
  151. source code, so you can retain the original whitespace if you want.
  152.  
  153.   The "-w" switch will cause your original whitespace to be retained, as
  154. follows:
  155.  
  156.         shroud -w example.c >example.shr
  157.  
  158.                           Watcom's Extended Keywords
  159.  
  160.   By default, the shrouder recognizes Watcom's extended keywords, such as
  161. "near" and "huge".  These extended keywords are explained in the Watcom User's
  162. Guide, and are similar to other compilers'.
  163.  
  164.   If you are using a compiler that does not use these unfortunate extensions,
  165. you may want to disable their recognition.
  166.  
  167.   The "-x" switch will disable the recognition of the extended keywords.  They
  168. will be treated as any other identifier.  This is used as follows:
  169.  
  170.         shroud -x example.c >example.shr
  171.  
  172.                         Combining Command Line Switches
  173.  
  174.   You can combine switches, within reason.  For example:
  175.  
  176.         shroud -x -l -w -dMACRO_NAME example.shr >example.shr
  177.  
  178. is equivalent to
  179.  
  180.         shroud -xlwdMACRO_NAME example.shr >example.shr
  181.  
  182.   However, this command line:
  183.  
  184.         shroud -dMACRO_NAMExlw example.shr >example.shr
  185.  
  186. is not equivalent.  It defines the macro named "MACRO_NAMExlw".  Use this
  187. instead:
  188.  
  189.         shroud -dMACRO_NAME -xlw example.shr >example.shr
  190.  
  191.                                  Include Files
  192.  
  193.   Like the Watcom C compiler, #include files will be searched for first in the
  194. current directory, and then in each directory named in the INCLUDE environment
  195. variable (see your DOS manual and the Watcom User's Guide).  This environment
  196. variable may be defined with a DOS command like this one:
  197.  
  198.         set INCLUDE=c:\wcc\h;c:\myincludes
  199.  
  200.                        Using the Shrouder To Report Bugs
  201.  
  202.   More often than not, bugs in the compiler or code generator of your C
  203. compiler will be demonstrated just as well by shrouded source code as by your
  204. original source code.
  205.  
  206.   On the other hand, you probably should not use the shrouder when reporting
  207. bugs in the libraries or debugger.  In these cases, it is generally quite easy
  208. to create a small "dummy" program that simply demonstrates the problem.  Send
  209. the dummy program to the compiler vendor, instead of your source code that
  210. first caused the problem.
  211.  
  212.   When reporting bugs to Watcom, you can generally use the shrouder without
  213. any command line switches.
  214.  
  215.   I have supplied the files WATCOMS, WATCOMM, WATCOMC, WATCOML, and WATCOMH to
  216. define Watcom's predefined macros for each memory model.  For example, if your
  217. source code refers to Watcom's predefined macros, and is compiled for the
  218. "large model" (see the Watcom User's Guide), use the following command line:
  219.  
  220.         shroud watcoml example.c >example.shr
  221.  
  222.   In this case, the shrouder will first read the file WATCOML, which defines
  223. the predefined macros.  (WATCOML will not produce any shrouded output, because
  224. it simply defines macros.)  The shrouder will then read and shroud EXAMPLE.C.
  225.  
  226.   You should compile the shrouded source with a command like the following:
  227.  
  228.         wcc example.shr
  229.  
  230.   If possible, verify that the shrouded source code demonstrates the same
  231. problem as the original source code.  This may be as simple as observing a
  232. compiler error message that should not appear.
  233.  
  234.   In the case of code generation problems, you may need to disassemble the
  235. object code to verify that the problem is demonstrated.  For example:
  236.  
  237.         wdisasm -s -l example
  238.  
  239.   This command will produce the file EXAMPLE.LST, containing the shrouded
  240. source code and the corresponding disassembled object code.  Examine
  241. EXAMPLE.LST with you text editor, and send a note along with the EXAMPLE.SHR
  242. and EXAMPLE.LST specifying on what line number in EXAMPLE.LST the problem may
  243. be found.  This will make it easier for Watcom's customer support staff to
  244. isolate the problem.
  245.  
  246.                           More Watcom Considerations
  247.  
  248.   There are a few more considerations when using the shrouder on source code
  249. written for the Watcom C compiler.
  250.  
  251.                         The -fi (Force Include) Switch
  252.  
  253.   The Watcom compiler has a "-fi" command line switch to force inclusion of a
  254. header file (see the Watcom User's Guide).  The shrouder has no such switch,
  255. but it may be important to include the file.  In this case, instead of
  256. "-fiforce.h", use a command like the following:
  257.  
  258.         shroud watcoml force.h example.c >example.shr
  259.  
  260.                          The -d (Define Macro) Switch
  261.  
  262.   The Watcom compiler has a "-d" command line switch to define macros, like
  263. the shrouder.  However, the Watcom compiler permits "-dMACRO_NAME=value" to
  264. give the macro a value, while the shrouder only permits "-dMACRO_NAME" to
  265. define a macro with an empty replacement text.
  266.  
  267.   If you use the Watcom "-d" switch to define macros with values, you must
  268. instead create a file with equivalent #define directives.  For example, create
  269. the file MYMACROS, containing:
  270.  
  271.         #define MACRO_NAME value
  272.  
  273.   Then force the shrouder to include MYMACROS, as described above.  For
  274. example:
  275.  
  276.         shroud watcoml mymacros example.c >example.shr
  277.  
  278.                            Watcom #pragma Directives
  279.  
  280.   The Watcom compiler provides several #pragma directives.  Even if your
  281. source code doesn't use any of these directives, Watcom's library #include
  282. files do use them.  It is important that the shrouded source code include the
  283. #pragma directives, and that they don't get screwed up by shrouding.  (Since
  284. Watcom's #pragma directives can affect code generation, the shrouded source
  285. code might not demonstrate the same problem as the original if these
  286. directives were discarded.)
  287.  
  288.   For this reason, the shrouder recognizes Watcom's #pragma directives, and
  289. correctly copies them to the shrouded output.  The keywords specific to
  290. #pragmas, like "aux" and "aborts", will not be shrouded.  Other identifiers in
  291. #pragma directives are shrouded normally, since they probably refer to
  292. appearances of the same identifiers elsewhere in the source code.
  293.  
  294.   Like the Watcom compiler, the shrouder replaces macros in #pragma
  295. directives.
  296.  
  297.   Other C compiler vendors may provide other #pragmas.  These may or may not
  298. be handled correctly by this shrouder.
  299.  
  300.                             History of the Shrouder
  301.  
  302.   This shrouder is really just a repackaging of my ANSI-conforming C language
  303. preprocessor, which was described in an article in Computer Language, July
  304. 1988, titled "Using Tomorrow's C Standard Today".
  305.  
  306.   I have found that having source code for a C language preprocessor is a very
  307. handy thing.  I have used it in several projects that would have been quite
  308. difficult otherwise.
  309.  
  310.   I you would find the source code useful, just send me $15, and I will send
  311. you source for the shrouder, preprocessor, and a YACC-generated ANSI C parser.
  312. The parser shows how to handle the ambiguities in the ANSI C language, as well
  313. as how to use my preprocessor to drive a YACC-generated parser for any
  314. language.
  315.  
  316.                           Differences from Version 1
  317.  
  318.   A bug was corrected in the handling of the #elif preprocessor directive.  In
  319. some cases, the argument to #elif was not evaluated.
  320.  
  321.   A bug was corrected in the handling of invalid tokens, such as character
  322. constants or string literals that were missing their ending quotes.  Such
  323. invalid tokens would consume the next newline.  If this occurred in a
  324. preprocessor directive, the directive would consume the next line without
  325. processing it.
  326.  
  327.                                 Commercial Use
  328.  
  329.   This program may be used for private, non-commercial use only.  For
  330. commercial use, such as to use it to distribute a commercial product, or to
  331. incorporate it into a commercial product, contact me to make arrangements.
  332.  
  333.                                   Private Use
  334.  
  335.   Please do use this program for private use, including shrouding the source
  336. code of your commercial products only to demonstrate problems to compiler
  337. vendors.  Please distribute this program freely to others, provided that no
  338. charge is made, and that this file and SHROUD.MAN are retained.
  339.  
  340.                                   Good Luck!
  341.  
  342.   Steven Bruce Williams
  343.   Brewster Station
  344.   P.O. Box 8458
  345.   Bridgeport, CT 06605-0997
  346.