home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland Pascal with Objects 7.0 / DOC.ZIP / UTILS.DOC < prev   
Encoding:
Text File  |  1992-10-27  |  15.3 KB  |  404 lines

  1. =======================================================================
  2.                       Borland Pascal Utilities
  3. =======================================================================
  4.  
  5. -----------------------------------------------------------------------
  6.                          Table of Contents
  7. -----------------------------------------------------------------------
  8.  1. The TOUCH utility
  9.  2. The GREP utility
  10.      The GREP switches
  11.      How to search using GREP
  12.      Examples using GREP
  13.  3. The BINOBJ utility
  14.  4. The Stand-Alone MAKE Utility
  15. -----------------------------------------------------------------------
  16.  
  17. This file describes three stand-alone utility programs that come
  18. with Borland Pascal: TOUCH, GREP, and BINOBJ.
  19.  
  20. Note: For information regarding the MAKE utility, see the Tools
  21. and Utilities Guide.
  22.  
  23. ======================
  24.  1. The TOUCH Utility
  25. ======================
  26.  
  27. There are times when you want to force a particular target file
  28. to be recompiled or rebuilt, even though no changes have been
  29. made to its sources. One way to do this is to use the TOUCH
  30. utility included with Borland Pascal. TOUCH changes the date and
  31. time of one or more files to the current date and time, making it
  32. "newer" than the files that depend on it.
  33.  
  34. To force a target file to be rebuilt, "touch" one of the files
  35. that target depends on. To touch a file (or files), enter
  36.  
  37.    touch filename [ filename ... ]
  38.  
  39. at the DOS prompt. TOUCH will then update the file's creation
  40. date(s).
  41.  
  42. Once you do this, you can invoke MAKE to rebuild the touched
  43. target file(s).
  44.  
  45.  
  46. =====================
  47.  2. The GREP Utility
  48. =====================
  49.  
  50. GREP is a powerful search utility that can look for text in
  51. several files at once.
  52.  
  53. The command-line syntax for GREP follows:
  54.  
  55.    GREP [options] searchstring [filespec ... ]
  56.  
  57. where options consists of one or more single characters preceded
  58. by a hyphen, searchstring defines the pattern to search for, and
  59. filespec is the file specification. filespec tells GREP which
  60. files (or groups of files) to search; it can be an explicit file
  61. name or a generic file name incorporating the DOS wildcards (?
  62. and *). You can also enter a path as part of filespec; if you use
  63. filespec without a path, GREP only searches the current
  64. directory. If you don't specify filespec, input to GREP must be
  65. specified by redirecting stdin or piping.
  66.  
  67.  
  68.  The GREP Switches
  69. ===================
  70.  
  71. In the command line, options are one or more single characters
  72. preceded by a hyphen (-). Each individual character is a switch
  73. that you can turn on or off: type the plus symbol (+) after a
  74. character to turn the option on, or type a hyphen (-) after the
  75. character to turn the option off.
  76.  
  77. The default is on (the + is implied): for example, -R means the
  78. same thing as -R+. You can list multiple options individually
  79. like this: -I -D -L). Or you can combine them like this: -ILD or
  80. -IL -D, and so on). It's all the same to GREP.
  81.  
  82. Here is a list of the switches and their meanings:
  83.  
  84.    -C   Count only: Only a count of matching lines is printed.
  85.         For each file that contains at least one matching line,
  86.         GREP prints the file name and a count of the number of
  87.         matching lines. Matching lines are not printed.
  88.  
  89.    -D   Directories: For each filespec specified on the command
  90.         line, GREP searches for all files that match the file
  91.         specification, both in the directory specified and in all
  92.         subdirectories below the specified directory. If you give
  93.         a filespec without a path, GREP assumes the files are in
  94.         the current directory.
  95.  
  96.    -I   Ignore case: GREP ignores upper/lowercase differences
  97.         (case folding). GREP treats all letters a-z as being
  98.         identical to the corresponding letters A-Z in all
  99.         situations.
  100.  
  101.    -L   List match files: Only the name of each file containing a
  102.         match is printed. After GREP finds a match, it prints the
  103.         file name and processing immediately moves on to the next
  104.         file.
  105.  
  106.    -N   Numbers: Each matching line that GREP prints is preceded
  107.         by its line number.
  108.  
  109.    -O   UNIX output format: Changes the output format of matching
  110.         lines to support more easily the UNIX style of
  111.         command-line piping. All lines of output are preceded by
  112.         the name of the file which contained the matching line.
  113.  
  114.    -R   Regular expression search: The text defined by
  115.         searchstring is treated as a regular expression instead
  116.         of as a literal string.
  117.  
  118.    -U   Update options: GREP will combine the options given on
  119.         the command line with its default options and write these
  120.         to the GREP.COM file as the new defaults. (In other
  121.         words, GREP is self-configuring.) This option allows you
  122.         to tailor the default option settings to your own taste.
  123.  
  124.    -V   Non-match: Only non-matching lines are printed. Only
  125.         lines that do not contain the search string are
  126.         considered to be non-matching lines.
  127.  
  128.    -W   Word search: Text found which matches the regular
  129.         expression will be considered a match only if the
  130.         character immediately preceding and following cannot be
  131.         part of a word. The default word character set includes
  132.         A-Z, 9-0, and the underbar (_). An alternate form of this
  133.         option allows you to specify the set of legal word
  134.         characters. Its form is -W[set], where set is any valid
  135.         regular expression set definition. If alphabetic
  136.         characters are used to define the set, the set will
  137.         automatically be defined to contain both the upper and
  138.         lower case values for each letter in the set, regardless
  139.         of how it is typed, even if the search is case-sensitive.
  140.         If the -W option is used in combination with the -U
  141.         option, the new set of legal characters is saved as the
  142.         default set.
  143.  
  144.    -Z   Verbose: GREP prints the file name of every file
  145.         searched. Each matching line is preceded by its line
  146.         number. A count of matching lines in each file is given,
  147.         even if the count is zero.
  148.  
  149. Several of these options are in direct conflict with each other.
  150. In these cases, the following order applies (the first one is the
  151. one that takes precedence):
  152.  
  153.    -Z   -L   -C   -N
  154.  
  155. Each occurrence of an option overrides the previous definition:
  156. Its state reflects the way you last set it. At any given time,
  157. each option can only be on or off.
  158.  
  159. You can install your preferred default setting for each option in
  160. GREP.COM with the -U option. For example, if you want GREP to
  161. always do a verbose search (-Z on), you can install it with the
  162. following command:
  163.  
  164.    GREP -U -Z
  165.  
  166.  
  167.  How to Search Using GREP
  168. ==========================
  169.  
  170. The value of searchstring defines the pattern GREP will search
  171. for.  A search string can be either a (via the -R switch) or a
  172. literal string. In regular expressions, operators govern the
  173. search; literal strings have no operators.
  174.  
  175. You can enclose the search string in quotation marks to prevent
  176. spaces and tabs from being treated as delimiters. Matches will
  177. not cross line boundaries (a match must be contained in a single
  178. line).
  179.  
  180. When the -R switch is used, the search string is treated as a
  181. regular expression (as opposed to a literal expression), and the
  182. following symbols take on special meanings:
  183.  
  184.    ^   A caret at the start of the expression matches the start
  185.        of a line.
  186.  
  187.    $   A dollar sign at the end of the expression matches the end
  188.        of a line.
  189.  
  190.    .   A period matches any character.
  191.  
  192.    *   An expression followed by an asterisk wildcard matches
  193.        zero or more occurrences of that expression: fo* matches
  194.        f, fo, foo, etc.
  195.  
  196.    +   An expression followed by a plus sign matches one or more
  197.        occurrences of that expression: fo+ matches fo, foo, etc.,
  198.        but not f.
  199.  
  200.    []  A string enclosed in brackets matches any character in
  201.        that string, but no others. If the first character in the
  202.        string is a caret (^), the expression matches any
  203.        character except the characters in the string. For
  204.        example, [xyz] matches x, y, and z, while [^xyz] matches a
  205.        and b, but not x or y. A range of characters can be
  206.        specified by two characters separated by a hyphen (-).
  207.        These can be combined to form expressions like [?a-bd-z]
  208.        to match ? and any letter except c.
  209.  
  210.    \   The backslash "escape character" tells GREP to search for
  211.        the literal character that follows it. For example, \.
  212.        matches a period instead of any character.
  213.  
  214.    Note: Four characters (?, +, *, and .) do not have any special
  215.    meaning when used in a set. The character ^ is only treated
  216.    specially if it immediately follows the beginning of the set
  217.    (that is, immediately after the [).
  218.  
  219. Any ordinary character not mentioned in this list matches that
  220. character. A concatenation of regular expressions is a regular
  221. expression.
  222.  
  223.  
  224.  Examples Using GREP
  225. =====================
  226.  
  227. The following examples assume all options default to off.
  228.  
  229. ----------------------------------------------------------------
  230.  
  231. Search String   grep -n function dirdemo.pas
  232.  
  233. Finds       File DIRDEMO.PAS:
  234.             51        LessFunc = function(X, Y: DirPtr): Boolean;
  235.             60      function NumStr(N, D: Integer): String;
  236.             73      function LessName(X, Y: DirPtr): Boolean;
  237.             78      function LessSize(X, Y: DirPtr): Boolean;
  238.             83      function LessTime(X, Y: DirPtr): Boolean;
  239.  
  240. Remarks     Finds all functions in the file DIRDEMO.PAS. The -N
  241.             tells GREP to precede each matched line with its line
  242.             number.
  243.  
  244. -----------------------------------------------------------------
  245.  
  246. Search String   grep {\$ dirdemo.pas
  247.  
  248. Finds       File DIRDEMO.PAS:
  249.             {$I-,S-}
  250.             {$M 8192,8192,655360}
  251.             {$F+}
  252.             {$F-}
  253.  
  254. Remarks     Finds all compiler directives in DIRDEMO.PAS. The \
  255.             (backslash) preceding the $ is necessary. Without it,
  256.             the $ would indicate the end of the line. All lines
  257.             with { (curly bracket) as the last character would
  258.             match this pattern and be printed out.
  259.  
  260. -----------------------------------------------------------------
  261.  
  262. Search String   grep -i "^ *function.*).*real" *.pas
  263.  
  264. Finds       File WORKERS.PAS:
  265.             function RoundPay(Wages: Real): Real;
  266.  
  267. Remarks     Finds all lines that begin with zero or more spaces
  268.             followed by the word function, followed by any string
  269.             of zero or more characters, followed by a
  270.             parenthesis, followed by another string of zero or
  271.             more characters, followed by the word Real, and
  272.             ignores case. The net effect is to search for all
  273.             functions returning a Real. See if you can think of
  274.             other ways to do this.
  275.  
  276.             The double quotes are necessary because of the space
  277.             in the pattern string. The quotes tell the DOS
  278.             command-line processor to treat the intervening
  279.             characters as a single argument. Without the quotes,
  280.             DOS will think the search string is actually two
  281.             arguments, and GREP will think that everything after
  282.             ^ (the caret character) refers to file names, and
  283.             will complain
  284.  
  285.             No files matching: *FUNCTION.*).*.
  286.  
  287.  
  288. =======================
  289.  3. The BINOBJ Utility
  290. =======================
  291.  
  292. A utility program called BINOBJ.EXE has been added to convert any
  293. file to an .OBJ file so it can be linked into a pascal program as
  294. a "procedure." This is useful if you have a binary data file that
  295. must reside in the code segment or is too large to make into a
  296. typed constant array. For example, you can use BINOBJ with the
  297. Graph unit to link the graphics driver or font files directly
  298. into your .EXE file. Then, to use your graph program, you need
  299. only have the .EXE file (see the example BGILINK.PAS).
  300.  
  301. BINOBJ takes three parameters:
  302.  
  303.    BINOBJ  <source[.BIN]>  <destination[.OBJ]>  <public name>
  304.  
  305. where source is the binary file to convert, destination is the
  306. name of the .OBJ to be produced, and public name is the name of
  307. the procedure as it will be declared in your pascal program.
  308.  
  309. The following example, the procedure ShowScreen, takes a pointer
  310. as a parameter and moves 4000 bytes of data to screen memory. The
  311. file called MENU.DTA contains the image of the main menu screen
  312. (80 * 25 * 2 = 4000 bytes).
  313.  
  314. Here's a simple (no error-checking) version of MYPROG.PAS:
  315.  
  316.    program MyProg;
  317.  
  318.    uses Crt;
  319.  
  320.    procedure ShowScreen(ScreenData : Pointer);
  321.    { Display a screenful of data--no error-checking! }
  322.    var
  323.      ScreenSegment: Word;
  324.  
  325.    begin
  326.      if (Lo(LastMode) = 7) then      { Mono? }
  327.        ScreenSegment := $B000
  328.      else
  329.        ScreenSegment := $B800;
  330.      Move(ScreenData^,               { From pointer }
  331.       Ptr(ScreenSegment, 0)^,        { To video memory }
  332.       4000);                         { 80 * 25 * 2 }
  333.    end;
  334.  
  335.    var
  336.      MenuP : Pointer;
  337.      MenuF : file;
  338.    begin
  339.      Assign(MenuF, 'MENU.DTA');      { Open screen data file }
  340.      Reset(MenuF, 1);
  341.      GetMem(MenuP, 4000);            { Allocate buffer on heap }
  342.      BlockRead(MenuF, MenuP^, 4000); { Read screen data }
  343.      Close(MenuF);
  344.      ShowScreen(MenuP);              { Display screen }
  345.    end.
  346.  
  347.  
  348. The screen data file (MENU.DTA) is opened and then read into a
  349. buffer on the heap. Both MYPROG.EXE and MENU.DTA must be present
  350. at run-time for this program to work. You can use BINOBJ to
  351. convert MENU.DTA to an .OBJ file (MENUDTA.OBJ) and tell it to
  352. associate the data with a procedure called MenuData. Then you can
  353. declare the fake external procedure MenuData, which actually
  354. contains the screen data. Once you link in the .OBJ file with the
  355. $L compiler directive, MenuData will be 4000 bytes long and
  356. contain your screen data. First, run BINOBJ on MENU.DTA:
  357.  
  358.    binobj MENU.DTA MENUDTA MenuData
  359.  
  360. The first parameter, MENU.DTA, shows a familiar file of screen
  361. data; the second, MENUDTA, is the name of the .OBJ file to be
  362. created (since you didn't specify an extension, .OBJ will be
  363. added). The last parameter, MenuData, is the name of the external
  364. procedure as it will be declared in your program. Now that you've
  365. converted MENU.DTA to an .OBJ file, here's what the new
  366. MYPROG.PAS looks like:
  367.  
  368.    program MyProg;
  369.  
  370.    uses Crt;
  371.  
  372.    procedure ShowScreen(ScreenData : Pointer);
  373.    { Display a screenful of data--no error checking! }
  374.    var
  375.      ScreenSegment: Word;
  376.    begin
  377.      if (Lo(LastMode) = 7) then             { Mono? }
  378.        ScreenSegment := $B000
  379.      else
  380.        ScreenSegment := $B800;
  381.      Move(ScreenData^,                      { From pointer }
  382.       Ptr(ScreenSegment, 0)^,               { To video memory }
  383.       4000);                                { 80 * 25 * 2 }
  384.    end;
  385.  
  386.    procedure MenuData; external;
  387.    {$L MENUDTA.OBJ }
  388.    begin
  389.      ShowScreen(@MenuData);                 { Display screen }
  390.    end.
  391.  
  392. Notice that ShowScreen didn't change at all, and that the ADDRESS
  393. of your procedure is passed using the @ operator.
  394.  
  395. ================================
  396.  4. The Stand-Alone MAKE Utility
  397. ================================
  398.  
  399. For information on the MAKE utility, please refer to the Tools
  400. and Utilities Guide.
  401.  
  402.  
  403. *  *  *  *  *
  404.