home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 4.ddi / ONLINE.ZIP / UTILS.DOC < prev   
Encoding:
Text File  |  1990-10-23  |  46.2 KB  |  1,266 lines

  1. =======================================================================
  2.                        Turbo Pascal Utilities
  3. =======================================================================
  4.  
  5. -----------------------------------------------------------------------
  6.                          Table of Contents
  7. -----------------------------------------------------------------------
  8.  1. Using TPUMOVER, the unit mover
  9.      A review of unit files
  10.      Using TPUMOVER
  11.  2. The Stand-Alone MAKE Utility
  12.      Creating makefiles
  13.       Comments
  14.       Explicit rules
  15.       Implicit rules
  16.       Command lists
  17.       Macros
  18.        Defined test macro ($d)
  19.        Base file name macro ($*)
  20.        Full file name macro ($<)
  21.        File name path macro ($:)
  22.        File name and extension macro ($.)
  23.        File name only macro ($&)
  24.       Directives
  25.      Using MAKE
  26.       The BUILTINS.MAK file
  27.       How MAKE searches for files
  28.       MAKE command-line options
  29.       MAKE error messages
  30.        Fatal errors
  31.        Errors
  32.  3. The TOUCH utility
  33.  4. The GREP utility
  34.      The GREP switches
  35.      How to search using GREP
  36.      Examples using GREP
  37.  5. The BINOBJ utility
  38. -----------------------------------------------------------------------
  39.  
  40. This file describes five stand-alone utility programs that come with
  41. Turbo Pascal: TPUMOVER, MAKE, TOUCH, GREP, and BINOBJ.
  42.  
  43. ===================================
  44.  1. Using TPUMOVER, the Unit Mover
  45. ===================================
  46.  
  47. When you write units, you want to make them easily available to any
  48. programs that you develop. (Chapter mysteries, "Units and Related
  49. Mysteries," explains what a unit is and tells how to create your own
  50. units.) We'll now show you how to use TPUMOVER to remove seldom-used units
  51. from TURBO.TPL, and how to insert often-used units into TURBO.TPL.
  52.  
  53.  
  54.  A Review of Unit Files
  55. ========================
  56.  
  57. There are two types of unit files: .TPU files and .TPL files. When you
  58. compile a unit, Turbo Pascal puts the resulting object code in a .TPU
  59. (Turbo Pascal Unit) file, which always contains exactly one unit.
  60.  
  61. A .TPL (Turbo Pascal Library) file, on the other hand, can contain multiple
  62. units. For example, all the units that come on your Turbo Pascal disk are
  63. in the file TURBO.TPL. The file TURBO.TPL is currently the only library
  64. file Turbo Pascal will load units from.
  65.  
  66. You may have noticed, though, that you can use the standard Turbo Pascal
  67. units without giving a file name. That's because these units are stored in
  68. the Turbo Pascal standard unit file--TURBO.TPL on your distribution disk.
  69. Because the units are in that file, any program can use them without
  70. "knowing" their location.
  71.  
  72. Suppose you have a unit called TOOLS.TPU, and you use it in many different
  73. programs. Though adding Tools to TURBO.TPL takes up memory (TURBO.TPL is
  74. automatically loaded into memory by the compiler), adding it to the
  75. resident library makes "using" Tools faster because the unit is in memory
  76. instead of on disk.
  77.  
  78. There are five standard units already in TURBO.TPL: System, Overlay,
  79. Printer, Crt, and Dos.
  80.  
  81.  
  82.  Using TPUMOVER
  83. ================
  84.  
  85. You can use several command-line parameters that let you manipulate units
  86. quickly. The syntax for these parameters is
  87.  
  88.    TPUMOVER filename operations
  89.  
  90. where filename is either a .TPU file or a .TPL file,
  91.       and operations is an optional list of one or more of the following
  92.       commands:
  93.  
  94.          +unitname    Add a unit to the library.
  95.          -unitname    Delete a unit from the library.
  96.          *unitname    Extract a unit from the library.
  97.  
  98. If no operations are specified, TPUMOVER lists the units in the library
  99. file along with size and dependency information.
  100.  
  101.  
  102. =================================
  103.  2. The Stand-Alone MAKE Utility
  104. =================================
  105.  
  106. This section contains complete documentation for creating makefiles and
  107. using MAKE.
  108.  
  109.  
  110.  Creating Makefiles
  111. ====================
  112.  
  113. A makefile contains the definitions and relationships needed to help MAKE
  114. keep your program(s) up to date. You can create as many makefiles as you
  115. want and name them whatever you want. If you don't specify a makefile when
  116. you run MAKE (using the -f option), then MAKE looks for a file with the
  117. default name MAKEFILE.
  118.  
  119. You create a makefile with any ASCII text editor, such as Turbo Pascal's
  120. built-in interactive editor. All rules, definitions, and directives end
  121. with a carriage return; if a line is too long, you can continue it to the
  122. next line by placing a backslash (\) as the last character on the line.
  123.  
  124. Whitespace--spaces and tabs--is used to separate adjacent identifiers (such
  125. as dependencies) and to indent commands within a rule.
  126.  
  127. Creating a makefile is almost like writing a program--with definitions,
  128. commands, and directives. 
  129.  
  130.  Comments
  131. ----------
  132.  
  133. Comments begin with a number sign (#); the rest of the line following the #
  134. is ignored by MAKE. Comments can be placed anywhere and never have to start
  135. in a particular column.
  136.  
  137.  
  138.  Explicit Rules
  139. ----------------
  140.  
  141. Explicit rules take the form
  142.  
  143.    target [target ... ]: [source source ... ]
  144.       [command]
  145.       [command]
  146.       ...
  147.  
  148. where target is the file to be updated, source is a file upon which target
  149. depends, and command is any valid MS-DOS command (including invocation of
  150. .BAT files and execution of .COM and .EXE files).
  151.  
  152. Explicit rules define one or more target names, zero or more source files,
  153. and an optional list of commands to be performed. Target and source file
  154. names listed in explicit rules can contain normal MS-DOS drive and
  155. directory specifications, but they cannot contain wildcards.
  156.  
  157. Syntax here is important. target must be at the start of a line (in column
  158. 1), and each command must be indented (preceded by at least one space
  159. character or tab). As mentioned before, the backslash (\) can be used as a
  160. continuation character if the list of source files or a given command is
  161. too long for one line. Finally, both the source files and the commands are
  162. optional; it is possible to have an explicit rule consisting only of
  163.  
  164.    target [target ...] followed by a colon.
  165.  
  166. The idea behind an explicit rule is that the command or commands listed
  167. will create or update target, usually using the source files. When MAKE
  168. encounters an explicit rule, it first checks to see if any of the source
  169. files are target files elsewhere in the makefile. If so, those rules are
  170. evaluated first.
  171.  
  172. Once all the source files have been created or updated based on other
  173. explicit (or implicit) rules, MAKE checks to see if target exists. If not,
  174. each command is invoked in the order given. If target does exist, its time
  175. and date of last modification are compared against the time and date for
  176. each source. If any source has been modified more recently than target, the
  177. list of commands is executed.
  178.  
  179. A given file name can occur on the left side of an explicit rule only once
  180. in a given execution of MAKE.
  181.  
  182. Each command line in an explicit rule begins with whitespace. MAKE
  183. considers all lines following an explicit rule to be part of the command
  184. list for that rule, up to the next line that begins in column 1 (without
  185. any preceding whitespace) or up to the end of the file. Blank lines are
  186. ignored.
  187.  
  188. An explicit rule, with no command lines following it, is treated a little
  189. differently than an explicit rule with command lines.
  190.  
  191.    o If an explicit rule exists for a target with commands, the only files
  192.      that the target depends on are the ones listed in the explicit rule.
  193.  
  194.    o If an explicit rule has no commands, the targets depend on the files
  195.      given in the explicit rule, and they also depend on any file that
  196.      matches an implicit rule for the target(s).
  197.  
  198. Here are some examples of explicit rules from a makefile:
  199.  
  200.    myutil.obj: myutil.asm
  201.      tasm myutil.asm,myutil.obj;
  202.  
  203.    myapp.exe:  myapp.pas myglobal.tpu myutils.tpu
  204.      tpc myapp /Tc:\tp5\bin
  205.  
  206.    o The first explicit rule states that MYUTIL.OBJ depends upon
  207.      MYUTIL.ASM, and that MYUTIL.OBJ is created by executing the given
  208.      TASM command.
  209.  
  210.    o The second rule states that MYAPP.EXE depends upon MYAPP.PAS,
  211.      MYGLOBAL.TPU, and MYUTILS.TPU, and is created by the given TPC
  212.      command. (The /T plus path name in these examples will be explained
  213.      later.)
  214.  
  215. If you reorder the rules so that the one for MYAPP.EXE comes first,
  216. followed by the others, MAKE will recompile (or reassemble) only the files
  217. that it has to in order to update everything correctly. This is because a
  218. MAKE with no target on the command line will try to execute the first
  219. explicit rule it finds in the makefile.
  220.  
  221.  
  222.  Implicit Rules
  223. ----------------
  224.  
  225. MAKE also allows you to define implicit rules, which are generalizations of
  226. explicit rules. Here's an example to illustrate the relationship between
  227. the two types. Consider this explicit rule from the previous sample
  228. program:
  229.  
  230.    myutil.obj: myutil.asm
  231.      tasm myutil.asm,myutil.obj;
  232.  
  233. This rule is a common one, because it follows a general principle: An .OBJ
  234. file is dependent on the .ASM file with the same file name and is created
  235. by executing TASM (Turbo Assember). In fact, you might have a makefile
  236. where you have several (or even several dozen) explicit rules following
  237. this same format.
  238.  
  239. By redefining the explicit rule as an implicit rule, you can eliminate all
  240. the explicit rules of the same form. As an implicit rule, it would look
  241. like this:
  242.  
  243.    .asm.obj:
  244.      tasm $*.asm,$*.obj;
  245.  
  246. This rule means, "any file ending with .OBJ depends on the file with the
  247. same name that ends in .ASM, and the .OBJ file is created using the command
  248.  
  249.    tasm $*.asm,$*.obj
  250.  
  251. where $* represents the file's name with no extension." (The symbol $* is a
  252. special macro and is discussed in the next section.)
  253.  
  254. The syntax for an implicit rule follows:
  255.  
  256.    .source_extension.target_extension:
  257.      {command}
  258.      {command}
  259.      ...
  260.  
  261. Note the commands are optional and must be indented. The source_extension
  262. (which must begin in column 1) is the extension of the source file, that
  263. is, it applies to any file having the format
  264.  
  265.    fname.source_extension
  266.  
  267. Likewise, the target_extension refers to the the file
  268.  
  269.    fname.target_extension
  270.  
  271. where fname is the same for both files. In other words, this implicit rule
  272. replaces all explicit rules having the format
  273.  
  274.    fname.target_extension:fname.source_extension
  275.      [command]
  276.      [command]
  277.      ...
  278.  
  279. for any fname.
  280.  
  281. Implicit rules are used if no explicit rule for a given target can be found
  282. or if an explicit rule with no commands exists for the target.
  283.  
  284. The extension of the file name in question is used to determine which
  285. implicit rule to use. The implicit rule is applied if a file is found with
  286. the same name as the target, but with the mentioned source extension. For
  287. example, suppose you had a makefile (named MAKEFILE) whose contents were
  288.  
  289.    .asm.obj:
  290.      tasm $*.asm,$*.obj;
  291.  
  292. If you had an assembly language routine named RATIO.ASM that you wanted to
  293. compile to RATIO.OBJ, you could use the command
  294.  
  295.    make ratio.obj
  296.  
  297. MAKE would take RATIO.OBJ to be the target and create it by executing the
  298. command:
  299.  
  300.    tasm ratio.asm,ratio.obj;
  301.  
  302. Implicit rules are also used if an explicit rule is given with no commands.
  303. Suppose, as mentioned before, you had the following implicit rule at the
  304. start of your makefile:
  305.  
  306.    .pas.tpu:
  307.      tpc $<
  308.  
  309. You could then rewrite some explicit rules as follows:
  310.  
  311.    myglobal.tpu: myglobal.pas
  312.    myutils.tpu: myutils.pas myglobal.tpu myutil.obj
  313.  
  314. Since you don't have explicit information on how to create these .TPU
  315. files, MAKE applies the implicit rule defined earlier.
  316.  
  317. Several implicit rules can be written with the same target extension, but
  318. only one such rule can apply at a time. If more than one implicit rule
  319. exists for a given target extension, each rule is checked in the order the
  320. rules appear in the makefile, until all applicable rules are checked.
  321.  
  322. MAKE uses the first implicit rule that it discovers for a file with the
  323. source extension. Even if the commands of that rule fail, no more implicit
  324. rules are checked.
  325.  
  326. All lines following an implicit rule are considered to be part of the
  327. command list for the rule, up to the next line that begins without
  328. whitespace or to the end of the file. Blank lines are ignored. The syntax
  329. for a command line is provided later in this appendix.
  330.  
  331. MAKE does not know the full file name with an implicit rule, as it does
  332. with explicit rules. For that reason, special macros are provided with MAKE
  333. that allow you to include the name of the file being built by the rule.
  334.  
  335.  
  336.  Command Lists
  337. ---------------
  338.  
  339. Commands in a command list must be indented--that is, preceded by at least
  340. one space character or tab--and take the form
  341.  
  342.    [ prefix ... ] command_body
  343.  
  344. Each command line in a command list consists of an (optional) list of
  345. prefixes, followed by a single command body.
  346.  
  347. The prefixes allowed in a command modify the treatment of these commands by
  348. MAKE. The prefix is either the at (@) sign or a hyphen (-) followed
  349. immediately by a number.
  350.  
  351.    @   Keeps MAKE from displaying the command before executing it. The
  352.        display is hidden even if the -s option was not given on the MAKE
  353.        command line. This prefix applies only to the command on which it
  354.        appears.
  355.  
  356.    -num   Affects how MAKE treats exit codes. If a number (num) is
  357.           provided, then MAKE will abort processing only if the exit status
  358.           exceeds the number given. In this example, MAKE will abort only
  359.           if the exit status exceeds 4:
  360.  
  361.              -4 myprog sample.x
  362.  
  363.           If no -num prefix is given, MAKE checks the exit status for the
  364.           command. If the status is nonzero, MAKE will stop and delete the
  365.           current target file.
  366.  
  367.    -   With a hyphen but no number, MAKE will not check the exit status at
  368.        all. Regardless of what the exit status was, MAKE will continue.
  369.  
  370. The command body is treated exactly as if it were entered as a line to
  371. COMMAND.COM, with the exception that redirection and pipes are not
  372. supported. MAKE executes the following built-in commands by invoking a copy
  373. of COMMAND.COM to perform them:
  374.  
  375.    BREAK      CD      CHDIR      CLS      COPY
  376.    MD         MKDIR   PATH       PROMPT   REN
  377.    RENAME     SET     TIME       TYPE     VER
  378.    VERIFY     VOL
  379.  
  380. MAKE searches for any other command name using the MS-DOS search algorithm:
  381.  
  382.    o The current directory is searched first, followed by each directory
  383.      in the path.
  384.  
  385.    o In each directory, first a file with the extension .COM is checked,
  386.      then an .EXE file, and finally a .BAT.
  387.  
  388.    o If a .BAT file is found, a copy of COMMAND.COM is invoked to execute
  389.      the batch file.
  390.  
  391.  
  392. This command will cause MYPROG.PAS to be searched for, using the full
  393. search algorithm:
  394.  
  395.    tpc myprog.pas /$B+,R+,I+
  396.  
  397.  
  398.  Macros
  399. --------
  400.  
  401. Often certain commands, file names, or options are used again and again in
  402. your makefile. In an example earlier in this appendix, all the TPC commands
  403. used the switch /Tc:\tp5\bin, which means that the files TPC.CFG and
  404. TURBO.TPL are in the subdirectory C:\TP5\BIN. Suppose you wanted to switch
  405. to another subdirectory for those files; what would you do? You could go
  406. through and modify all the /T options, inserting the appropriate path name.
  407. Or, you could define a macro.
  408.  
  409. A macro is a name that represents some string of characters (letters and
  410. digits). A macro definition gives a macro name and the expansion text;
  411. thereafter, when MAKE encounters the macro name, it replaces the name with
  412. the expansion text.
  413.  
  414. Suppose you defined the following macro at the start of your makefile:
  415.  
  416.    TURBO=c:\tp5\bin
  417.  
  418. You've defined the macro TURBO, which is equivalent to the string
  419. c:\tp5\bin. You could now rewrite the makefile as follows:
  420.  
  421.    TURBO=c:\tp5\bin
  422.    myapp.exe:  myapp.pas myglobal.tpu myutils.tpu
  423.      tpc myapp /T$(TURBO)
  424.  
  425.    myutils.tpu: myutils.pas myglobal.tpu myutil.obj
  426.      tpc myutils /T$(TURBO)
  427.  
  428.  
  429. Everywhere the Turbo directory is specified, you use the macro invocation
  430. $(TURBO). When you run MAKE, $(TURBO) is replaced with its expansion text,
  431. c:\TP5.BIN. The result is the same set of commands you had before but with
  432. greater flexibility.
  433.  
  434. In fact, if you leave out the first line altogether, you can specify which 
  435. subdirectory you want each time you run MAKE, using the -D (Define) option:
  436.  
  437.    make -DTURBO=c:\tp5\project
  438.  
  439. Macro definitions take the form
  440.  
  441.    macro_name=expansion text
  442.  
  443. where macro_name is the name of a macro made up of a string of letters and
  444. digits with no whitespace in it, though you can have whitespace between
  445. macro_name and the equal sign (=). [expansion text] is any arbitrary string
  446. containing letters, digits, whitespace, and punctuation; it is ended by a
  447. carriage return.  Note that macros are case sensitive.  Thus the macro
  448. names Turbo, turbo and TURBO are all different.
  449.  
  450. If macro_name has previously been defined, either by a macro definition in
  451. the makefile or by the -D option on the MAKE command line, the new
  452. definition replaces the old.
  453.  
  454. Macros are invoked in your makefile with the format
  455.  
  456.    $(macro_name)
  457.  
  458. Macros in macros: Macros cannot be invoked on the left (macro_name) side of
  459. a macro definition. They can be used on the right (expansion text) side,
  460. but they are not expanded until the macro being defined is invoked. In
  461. other words, when a macro invocation is expanded, any macros embedded in
  462. its expansion text are also expanded.
  463.  
  464. MAKE comes with several special predefined macros built-in: $d, $*, $<, $:,
  465. $., and $&. The first is a defined test macro, used in the conditional
  466. directives !if and !elif; the others are file name macros, used in explicit
  467. and implicit rules. The various file name macros work in similar ways,
  468. expanding to some variation of the full path name of the file being built.
  469. In addition, the current SET environment strings are automatically loaded
  470. as macros, and the macro __MAKE__ is defined to be 1 (one).
  471.  
  472.  
  473.  Defined Test Macro ($d)
  474.  
  475. This macro expands to 1 if the given macro name is defined, or to 0 if it
  476. is not. The content of the macro's expansion text does not matter. This
  477. special macro is allowed only in !if and !elif directives. For example, if
  478. you wanted to modify your makefile so that it would use a particular Turbo
  479. Pascal directory if you didn't specify one, you could put this at the start
  480. of your makefile:
  481.  
  482.    !if !$d(TURBO)            # if TURBO is not defined
  483.    TURBO=c:\tp5\bin          # define it to C:\TP5\BIN
  484.    !endif
  485.  
  486. If you invoke MAKE with the command line
  487.  
  488.    make -DTURBO=c:\tp5\project
  489.  
  490. then TURBO is defined as c:\tp5\project. If, however, you just invoke MAKE
  491. by itself,
  492.  
  493.    make
  494.  
  495. then TURBO is defined as c:\tp5\bin, your "default" subdirectory.
  496.  
  497.  
  498.  Base File Name Macro ($*)
  499.  
  500. This macro is allowed in the commands for an explicit or an implicit rule.
  501. The macro expands to the file name being built, excluding any extension,
  502. like this:
  503.  
  504.    File name is A:\P\TESTFILE.PAS
  505.    $* expands to A:\P\TESTFILE
  506.  
  507. For example, you could modify the explicit MYAPP.EXE rule already given to
  508. look like this:
  509.  
  510.    myapp.exe:  myapp.pas myglobal.tpu myutils.tpu
  511.      tpc $* /T$(TURBO)
  512.  
  513.  
  514.  Full File Name Macro ($<)
  515.  
  516. The full file name macro ($<) is also used in the commands for an explicit
  517. or implicit rule. In an explicit rule, $< expands to the full target file
  518. name (including extension), like this:
  519.  
  520.    File name is A:\P\TESTFILE.PAS
  521.    $< expands to A:\P\TESTFILE.PAS
  522.  
  523. In an implicit rule, $< takes on the file name plus the source extension.
  524. For example, the previous implicit rule
  525.  
  526.    .asm.obj:
  527.      tasm $*.asm,$*.obj;
  528.  
  529. can be rewritten as
  530.  
  531.    .asm.obj:
  532.       tasm $<,$*.obj;
  533.  
  534.  
  535.  File Name Path Macro ($:)
  536.  
  537. This macro expands to the path name (without the file name), like this:
  538.  
  539.    File name is A:\P\TESTFILE.PAS
  540.    $: expands to A:\P\
  541.  
  542.  
  543.  File Name and Extension Macro ($.)
  544.  
  545. This macro expands to the file name, with extension, like this:
  546.  
  547.    File name is A:\P\TESTFILE.PAS
  548.    $. expands to TESTFILE.PAS
  549.  
  550.  
  551.  File Name Only Macro ($&)
  552.  
  553. This macro expands to the file name only, without path or extension, like
  554. this:
  555.  
  556.    File name is A:\P\TESTFILE.PAS
  557.    $& expands to TESTFILE
  558.  
  559.  
  560.  Directives
  561. ------------
  562.  
  563. The version of MAKE bundled with Turbo Pascal allows something that other
  564. versions of MAKE don't: conditional directives similiar to those allowed
  565. for Turbo Pascal. You can use these directives to include other makefiles,
  566. to make the rules and commands conditional, to print out error messages,
  567. and to "undefine" macros.
  568.  
  569. Directives in a makefile begin with an exclamation point (!). Here is the
  570. complete list of MAKE directives:
  571.  
  572.    !include
  573.    !if
  574.    !else
  575.    !elif
  576.    !endif
  577.    !error
  578.    !undef
  579.  
  580. A file-inclusion directive (!include) specifies a file to be included into
  581. the makefile for interpretation at the point of the directive. It takes the
  582. following form:
  583.  
  584.    !include "filename"
  585.  
  586. or
  587.  
  588.    !include <filename>
  589.  
  590. These directives can be nested arbitrarily deep. If an include directive
  591. attempts to include a file that has already been included in some outer
  592. level of nesting (so that a nesting loop is about to start), the inner
  593. include directive is rejected as an error.
  594.  
  595. Conditional directives (!if, !elif, !else, and !endif) give a programmer a
  596. measure of flexibility in constructing makefiles. Rules and macros can be
  597. "conditionalized" so that a command-line macro definition (using the -D
  598. option) can enable or disable sections of the makefile.
  599.  
  600. The format of these directives parallels, but is more extensive than, the
  601. conditional directives allowed by Turbo Pascal:
  602.  
  603.    !if expression
  604.      [ lines ]
  605.    !endif
  606.  
  607.    !if expression
  608.      [ lines ]
  609.    !else
  610.      [ lines ]
  611.    !endif
  612.  
  613.    !if expression
  614.      [ lines ]
  615.    !elif expression
  616.      [ lines ]
  617.    !endif
  618.  
  619. The conditional directives form a group, with at least an !if directive
  620. beginning the group and an !endif directive closing the group.
  621.  
  622. The expression allowed in an !if or an !elif directive uses a syntax
  623. similar to that found in the C programming language. The expression is
  624. evaluated as a simple 32-bit signed integer expression.
  625.  
  626. Numbers can be entered as decimal, octal, or hexadecimal constants. For
  627. example, these are legal constants in an expression:
  628.  
  629.    4536       # decimal constant
  630.    0677       # octal constant (note the leading zero)
  631.    0x23aF     # hexadecimal constant
  632.  
  633. and any of the following unary operators:
  634.  
  635.    -     negation
  636.    ~     bit complement
  637.    !     logical not
  638.  
  639. An expression can use any of the following binary operators:
  640.  
  641.    +     addition
  642.    -     subtraction
  643.    *     multiplication
  644.    /     division
  645.    %     remainder
  646.    >>    right shift
  647.    <<    left shift
  648.    &     bitwise and
  649.    |     bitwise or
  650.    ^     bitwise exclusive or
  651.    &&    logical and
  652.    ||    logical or
  653.    >     greater than
  654.    <     less than
  655.    >=    greater than or equal to
  656.    <=    less than or equal to
  657.    ==    equality
  658.    !=    inequality
  659.  
  660. An expression can contain the following ternary operator:
  661.  
  662.    ? :   The operand before the ? is treated as a test.
  663.  
  664.          If the value of that operand is nonzero, then the second
  665.          operand (the part between the ? and the colon) is the
  666.          result. If the value of the first operand is zero, the
  667.          value of the result is the value of the third operand
  668.          (the part after the :).
  669.  
  670. Parentheses can be used to group operands in an expression. In the absence
  671. of parentheses, binary operators are grouped according to the same
  672. precedence given in the C language.
  673.  
  674. Grouping is from left to right for operators of equal precedence, except
  675. for the ternary operator (? :), which is right to left.
  676.  
  677. Macros can be invoked within an expression, and the special macro $d() is
  678. recognized. After all macros have been expanded, the expression must have
  679. proper syntax. Any words in the expanded expression are treated as errors.
  680.  
  681. The error directive (!error) causes MAKE to stop and print a fatal
  682. diagnostic containing the text after !error. It takes the format
  683.  
  684.    !error [any_text]
  685.  
  686. This directive is designed to be included in conditional directives to
  687. allow a user-defined abort condition. 
  688.  
  689. The undefine directive (!undef) causes any definition for the named macro
  690. to be forgotten. If the macro is currently undefined, this directive has no
  691. effect. 
  692.  
  693.  Using MAKE
  694. ============
  695.  
  696. You now know a lot about how to write makefiles; now's the time to learn
  697. how to use them with MAKE. The simplest way to use MAKE is to type the
  698. command
  699.  
  700.    MAKE
  701.  
  702. at the MS-DOS prompt. MAKE then looks for MAKEFILE; if it can't find it, it
  703. looks for MAKEFILE.MAK; if it can't find that, it halts with an error
  704. message.
  705.  
  706. You can specify a file with the -f option:
  707.  
  708.    MAKE -fstars.mak
  709.  
  710. The general syntax for MAKE is
  711.  
  712.    make option option ... target target ...
  713.  
  714. where option is a MAKE option (discussed later) and target is the name of a
  715. target file to be handled by explicit rules.
  716.  
  717. If the command line does not include any target names, MAKE uses the first
  718. target file mentioned in an explicit rule. If one or more targets are
  719. mentioned on the command line, they will be built as necessary.
  720.  
  721. Here are some more examples of MAKE command lines:
  722.  
  723.    make -n -fstars.mak
  724.    make -s
  725.    make -Iinclude -DTURBO=c:\tp5\project
  726.  
  727.  
  728.  The BUILTINS.MAK File
  729. -----------------------
  730.  
  731. As you become familiar with MAKE, you will find that there are macros and
  732. rules (usually implicit ones) that you use again and again. You've got
  733. three ways of handling them. First, you can put them in every makefile you
  734. create. Second, you can put them all in one file and use the !include
  735. directive in each makefile you create. Third, you can put them all in a
  736. file named BUILTINS.MAK.
  737.  
  738. Each time you run MAKE, it looks for a file named BUILTINS.MAK; if it finds
  739. the file, MAKE reads it in before handling MAKEFILE (or whichever makefile
  740. you want it to process).
  741.  
  742. The BUILTINS.MAK file is intended for any rules (usually implicit rules) or
  743. macros that will be commonly used in files anywhere on your computer.
  744.  
  745. There is no requirement that any BUILTINS.MAK file exist. If MAKE finds a
  746. BUILTINS.MAK file, it interprets that file first. If MAKE cannot find a
  747. BUILTINS.MAK file, it proceeds directly to interpreting MAKEFILE (or
  748. whatever makefile you specify).
  749.  
  750.  
  751.  How MAKE Searches for Files
  752. -----------------------------
  753.  
  754. MAKE will search for BUILTINS.MAK in the current directory or in the exec
  755. directory if your computer is running under DOS 3.x. You should place this
  756. file in the same directory as the MAKE.EXE file.
  757.  
  758. MAKE always searches for the makefile in the current directory only. This
  759. file contains the rules for the particular executable program file being
  760. built. The two files have identical syntax rules.
  761.  
  762. MAKE also searches for any !include files in the current directory. If you
  763. use the -I (Include) option, it will also search in the specified
  764. directory.
  765.  
  766.  
  767.  MAKE Command-Line Options
  768. ---------------------------
  769.  
  770.    -Didentifier   Defines the named identifier to the string consisting of
  771.                   the single character 1.
  772.  
  773.    -Diden=string  Defines the named identifier iden to the string after
  774.                   the equal sign. The string cannot contain any spaces or
  775.                   tabs.
  776.  
  777.    -Idirectory    MAKE will search for include files in the indicated
  778.                   directory (as well as in the current directory).
  779.  
  780.    -Uidentifier   Undefines any previous definitions of the named
  781.                   identifier.
  782.  
  783.    -s             Normally, MAKE prints each command as it is about to be
  784.                   executed. With the -s option, no commands are printed
  785.                   before execution.
  786.  
  787.    -n             Causes MAKE to print the commands, but not actually
  788.                   perform them. This is useful for debugging a makefile.
  789.  
  790.    -ffilename     Uses filename as the MAKE file. If filename does not
  791.                   exist and no extension is given, tries filename.MAK.
  792.  
  793.    -? or -h       Prints help message.
  794.  
  795.  
  796.  MAKE Error Messages
  797. ---------------------
  798.  
  799.  Fatal Errors
  800.  
  801. Don't know how to make XXXXXXXX
  802.    This message is issued when MAKE encounters a nonexistent file name in
  803.    the build sequence, and no rule exists that would allow the file name to
  804.    be built.
  805.  
  806. Error directive: XXXX
  807.    This message is issued when MAKE processes an #error directive in the
  808.    source file. The text of the directive is displayed in the message.
  809.  
  810. Incorrect command line argument: XXX
  811.    This error occurs if MAKE is executed with incorrect command-line
  812.    arguments.
  813.  
  814. Not enough memory
  815.    This error occurs when the total working storage has been exhausted. You
  816.    should try this on a machine with more memory. If you already have 640K
  817.    in your machine, you may have to simplify the source file.
  818.  
  819. Unable to execute command
  820.    This message is issued after attempting to execute a command. This could
  821.    be a result of the command file not being found, or because it was
  822.    misspelled. A less likely possibility is that the command exists but is
  823.    somehow corrupted.
  824.  
  825. Unable to open makefile
  826.    This message is issued when the current directory does not contain a
  827.    file named MAKEFILE.
  828.  
  829.  
  830.  Errors
  831.  
  832. Bad file name format in include statement
  833.    Include file names must be surrounded by quotes or angle brackets. The
  834.    file name was missing the opening quote or angle bracket.
  835.  
  836. Bad undef statement syntax
  837.    An !undef statement must contain a single identifier and nothing else as
  838.    the body of the statement.
  839.  
  840. Character constant too long
  841.    Character constants can be only one or two characters long.
  842.  
  843. Command arguments too long
  844.    The arguments to a command executed by MAKE were more than 127
  845.    characters--a limit imposed by DOS.
  846.  
  847. Command syntax error
  848.    This message occurs if
  849.  
  850.       o the first rule line of the makefile contained any leading
  851.         whitespace.
  852.  
  853.       o an implicit rule did not consist of .ext.ext:.
  854.  
  855.       o an explicit rule did not contain a name before the : character.
  856.  
  857.       o a macro definition did not contain a name before the = character.
  858.  
  859. Division by zero
  860.    A divide or remainder in an !if statement has a zero divisor.
  861.  
  862. Expression syntax error in !if statement
  863.    The expression in an !if statement is badly formed--it contains a
  864.    mismatched parenthesis, an extra or missing operator, or a missing or
  865.    extra constant.
  866.  
  867. File name too long
  868.    The file name given in an !include directive was too long for MAKE to
  869.    process. File path names in MS-DOS must be no more than 78 characters
  870.    long.
  871.  
  872. Illegal character in constant expression X
  873.    MAKE encountered some character not allowed in a constant expression. If
  874.    the character is a letter, this indicates a (probably) misspelled
  875.    identifier.
  876.  
  877. Illegal octal digit
  878.    An octal constant was found containing a digit of 8 or 9.
  879.  
  880. Macro expansion too long
  881.    A macro cannot expand to more than 4096 characters. This error often
  882.    occurs if a macro recursively expands itself. A macro cannot legally
  883.    expand to itself.
  884.  
  885. Misplaced elif statement
  886.    An !elif directive was encountered without any matching !if directive.
  887.  
  888. Misplaced else statement
  889.    An !else directive was encountered without any matching !if directive.
  890.  
  891. Misplaced endif statement
  892.    An !endif directive was encountered without any matching !if directive.
  893.  
  894. No file name ending
  895.    The file name in an include statement was missing the correct closing
  896.    quote or angle bracket.
  897.  
  898. Redefinition of target XXXXXXXX
  899.    The named file occurs on the left-hand side of more than one explicit
  900.    rule.
  901.  
  902. Unable to open include file XXXXXXXXX.XXX
  903.    The named file could not be found. This could also be caused if an
  904.    include file included itself. Check whether the named file exists.
  905.  
  906. Unexpected end of file in conditional started on line #
  907.    The source file ended before MAKE encountered an !endif. The !endif was
  908.    either missing or misspelled.
  909.  
  910. Unknown preprocessor statement
  911.    A ! character was encountered at the beginning of a line, and the
  912.    statement name following was not error, undef, if, elif, include, else,
  913.    or endif.
  914.  
  915.  
  916. ======================
  917.  3. The TOUCH Utility
  918. ======================
  919.  
  920. There are times when you want to force a particular target file to be
  921. recompiled or rebuilt, even though no changes have been made to its
  922. sources. One way to do this is to use the TOUCH utility included with Turbo
  923. Pascal. TOUCH changes the date and time of one or more files to the current
  924. date and time, making it "newer" than the files that depend on it.
  925.  
  926. To force a target file to be rebuilt, "touch" one of the files that target
  927. depends on. To touch a file (or files), enter
  928.  
  929.    touch filename [ filename ... ]
  930.  
  931. at the DOS prompt. TOUCH will then update the file's creation date(s).
  932.  
  933. Once you do this, you can invoke MAKE to rebuild the touched target
  934. file(s).
  935.  
  936.  
  937. =====================
  938.  4. The GREP Utility
  939. =====================
  940.  
  941. GREP is a powerful search utility that can look for text in several files
  942. at once. 
  943.  
  944. The command-line syntax for GREP follows:
  945.  
  946.    GREP [options] searchstring [filespec ... ]
  947.  
  948. where options consists of one or more single characters preceded by a
  949. hyphen, searchstring defines the pattern to search for, and filespec is the
  950. file specification. filespec tells GREP which files (or groups of files) to
  951. search; it can be an explicit file name or a generic file name
  952. incorporating the DOS wildcards (? and *). You can also enter a path as
  953. part of filespec; if you use filespec without a path, GREP only searches
  954. the current directory. If you don't specify filespec, input to GREP must be
  955. specified by redirecting stdin or piping.
  956.  
  957.  
  958.  The GREP Switches
  959. ===================
  960.  
  961. In the command line, options are one or more single characters preceded by
  962. a hyphen (-). Each individual character is a switch that you can turn on or
  963. off: type the plus symbol (+) after a character to turn the option on, or
  964. type a hyphen (-) after the character to turn the option off.
  965.  
  966. The default is on (the + is implied): for example, -R means the same thing
  967. as -R+. You can list multiple options individually like this: -I -D -L). Or
  968. you can combine them like this: -ILD or -IL -D, and so on). It's all the
  969. same to GREP.
  970.  
  971. Here is a list of the switches and their meanings:
  972.  
  973.    -C   Count only: Only a count of matching lines is printed. For each
  974.         file that contains at least one matching line, GREP prints the file
  975.         name and a count of the number of matching lines. Matching lines
  976.         are not printed.
  977.  
  978.    -D   Directories: For each filespec specified on the command line, GREP
  979.         searches for all files that match the file specification, both in
  980.         the directory specified and in all subdirectories below the
  981.         specified directory. If you give a filespec without a path, GREP
  982.         assumes the files are in the current directory.
  983.  
  984.    -I   Ignore case: GREP ignores upper/lowercase differences (case
  985.         folding). GREP treats all letters a-z as being identical to the
  986.         corresponding letters A-Z in all situations.
  987.  
  988.    -L   List match files: Only the name of each file containing a match is
  989.         printed. After GREP finds a match, it prints the file name and
  990.         processing immediately moves on to the next file.
  991.  
  992.    -N   Numbers: Each matching line that GREP prints is preceded by its
  993.         line number.
  994.  
  995.    -O   UNIX output format: Changes the output format of matching lines to
  996.         support more easily the UNIX style of command-line piping. All
  997.         lines of output are preceded by the name of the file which
  998.         contained the matching line.
  999.  
  1000.    -R   Regular expression search: The text defined by searchstring is
  1001.         treated as a regular expression instead of as a literal string.
  1002.  
  1003.    -U   Update options: GREP will combine the options given on the command
  1004.         line with its default options and write these to the GREP.COM file
  1005.         as the new defaults. (In other words, GREP is self-configuring.)
  1006.         This option allows you to tailor the default option settings to
  1007.         your own taste.
  1008.  
  1009.    -V   Non-match: Only non-matching lines are printed. Only lines that do
  1010.         not contain the search string are considered to be non-matching
  1011.         lines.
  1012.  
  1013.    -W   Word search: Text found which matches the regular expression will
  1014.         be considered a match only if the character immediately preceding
  1015.         and following cannot be part of a word. The default word character
  1016.         set includes A-Z, 9-0, and the underbar (_). An alternate form of
  1017.         this option allows you to specify the set of legal word characters.
  1018.         Its form is -W[set], where set is any valid regular expression set
  1019.         definition. If alphabetic characters are used to define the set,
  1020.         the set will automatically be defined to contain both the upper and
  1021.         lower case values for each letter in the set, regardless of how it
  1022.         is typed, even if the search is case-sensitive. If the -W option is
  1023.         used in combination with the -U option, the new set of legal
  1024.         characters is saved as the default set.
  1025.  
  1026.    -Z   Verbose: GREP prints the file name of every file searched. Each
  1027.         matching line is preceded by its line number. A count of matching
  1028.         lines in each file is given, even if the count is zero.
  1029.  
  1030. Several of these options are in direct conflict with each other. In these
  1031. cases, the following order applies (the first one is the one that takes
  1032. precedence):
  1033.  
  1034.    -Z   -L   -C   -N
  1035.  
  1036. Each occurrence of an option overrides the previous definition: Its state
  1037. reflects the way you last set it. At any given time, each option can only
  1038. be on or off.
  1039.  
  1040. You can install your preferred default setting for each option in GREP.COM
  1041. with the -U option. For example, if you want GREP to always do a verbose
  1042. search (-Z on), you can install it with the following command:
  1043.  
  1044.    GREP -U -Z
  1045.  
  1046.  
  1047.  How to Search Using GREP
  1048. ==========================
  1049.  
  1050. The value of searchstring defines the pattern GREP will search for.  A
  1051. search string can be either a (via the -R switch) or a literal string. In
  1052. regular expressions, operators govern the search; literal strings have no
  1053. operators.
  1054.  
  1055. You can enclose the search string in quotation marks to prevent spaces and
  1056. tabs from being treated as delimiters. Matches will not cross line
  1057. boundaries (a match must be contained in a single line).
  1058.  
  1059. When the -R switch is used, the search string is treated as a regular
  1060. expression (as opposed to a literal expression), and the following symbols
  1061. take on special meanings:
  1062.  
  1063.    ^   A caret at the start of the expression matches the start
  1064.        of a line.
  1065.  
  1066.    $   A dollar sign at the end of the expression matches the end
  1067.        of a line.
  1068.  
  1069.    .   A period matches any character.
  1070.  
  1071.    *   An expression followed by an asterisk wildcard matches
  1072.        zero or more occurrences of that expression: fo* matches
  1073.        f, fo, foo, etc.
  1074.  
  1075.    +   An expression followed by a plus sign matches one or more
  1076.        occurrences of that expression: fo+ matches fo, foo, etc.,
  1077.        but not f.
  1078.  
  1079.    []  A string enclosed in brackets matches any character in
  1080.        that string, but no others. If the first character in the
  1081.        string is a caret (^), the expression matches any
  1082.        character except the characters in the string. For
  1083.        example, [xyz] matches x, y, and z, while [^xyz] matches a
  1084.        and b, but not x or y. A range of characters can be
  1085.        specified by two characters separated by a hyphen (-).
  1086.        These can be combined to form expressions like [?a-bd-z]
  1087.        to match ? and any letter except c.
  1088.  
  1089.    \   The backslash "escape character" tells GREP to seach for
  1090.        the literal character that follows it. For example, \.
  1091.        matches a period instead of any character.
  1092.  
  1093.    Note: Four characters (?, +, *, and .) do not have any special
  1094.    meaning when used in a set. The character ^ is only treated
  1095.    specially if it immediately follows the beginning of the set
  1096.    (that is, immediately after the [).
  1097.  
  1098. Any ordinary character not mentioned in this list matches that character. A
  1099. concatenation of regular expressions is a regular expression.
  1100.  
  1101.  
  1102.  Examples Using GREP
  1103. =====================
  1104.  
  1105. The following examples assume all options default to off.
  1106.  
  1107. ----------------------------------------------------------------------
  1108.  
  1109. Search String   grep -n function dirdemo.pas
  1110.  
  1111. Finds       File DIRDEMO.PAS:
  1112.             46      LessFunc = function(X, Y: DirPtr): Boolean;
  1113.             55      function NumStr(N, D: Integer): string;
  1114.             68      function LessName(X, Y: DirPtr): Boolean;
  1115.             73      function LessSize(X, Y: DirPtr): Boolean;
  1116.             78      function LessTime(X, Y: DirPtr): Boolean;
  1117.  
  1118. Remarks     Finds all functions in the file DIRDEMO.PAS. The -N
  1119.             tells GREP to precede each matched line with its line
  1120.             number.
  1121.  
  1122. ----------------------------------------------------------------------
  1123.  
  1124. Search String   grep {\$ dirdemo.pas
  1125.  
  1126. Finds       File DIRDEMO.PAS:
  1127.             {$I-,S-}
  1128.             {$M 8192,8192,655360}
  1129.             {$F+}
  1130.             {$F-}
  1131.  
  1132. Remarks     Finds all compiler directives in DIRDEMO.PAS. The \
  1133.             (backslash) preceding the $ is necessary. Without it,
  1134.             the $ would indicate the end of the line. All lines
  1135.             with { (curly bracket) as the last character would
  1136.             match this pattern and be printed out.
  1137.  
  1138. ----------------------------------------------------------------------
  1139.  
  1140. Search String   grep -i "^ *function.*).*real" *.pas
  1141.  
  1142. Finds       File MCPARSER.PAS:
  1143.             function CellValue(Col, Row: Word): Real;
  1144.             function Parse(S: string; var Att: Word): Real;
  1145.  
  1146. Remarks     Finds all lines that begin with zero or more spaces
  1147.             followed by the word function, followed by any string
  1148.             of zero or more characters, followed by a
  1149.             parenthesis, followed by another string of zero or
  1150.             more characters, followed by the word Real, and
  1151.             ignores case. The net effect is to search for all
  1152.             functions returning a Real. See if you can think of
  1153.             other ways to do this.
  1154.  
  1155.             The double quotes are necessary because of the space
  1156.             in the pattern string. The quotes tell the DOS
  1157.             command-line processor to treat the intervening
  1158.             characters as a single argument. Without the quotes,
  1159.             DOS will think the search string is actually two
  1160.             arguments, and GREP will think that everything after
  1161.             ^ (the caret character) refers to file names, and
  1162.             will complain
  1163.  
  1164.             No files matching: *FUNCTION.*).*.
  1165.  
  1166.  
  1167. =======================
  1168.  5. The BINOBJ Utility
  1169. =======================
  1170.  
  1171. A utility program called BINOBJ.EXE has been added to convert any file to
  1172. an .OBJ file so it can be linked into a Turbo Pascal program as a
  1173. "procedure." This is useful if you have a binary data file that must reside
  1174. in the code segment or is too large to make into a typed constant array.
  1175. For example, you can use BINOBJ with the Graph unit to link the graphics
  1176. driver or font files directly into your .EXE file. Then, to use your graph
  1177. program, you need only have the .EXE file (see the example BGILINK.PAS).
  1178.  
  1179. BINOBJ takes three parameters:
  1180.  
  1181.    BINOBJ  <source[.BIN]>  <destination[.OBJ]>  <public name>
  1182.  
  1183. where source is the binary file to convert, destination is the name of the
  1184. .OBJ to be produced, and public name is the name of the procedure as it
  1185. will be declared in your Turbo Pascal program.
  1186.  
  1187. The following example, the procedure ShowScreen, takes a pointer as a
  1188. parameter and moves 4000 bytes of data to screen memory. The file called
  1189. MENU.DTA contains the image of the main menu screen (80 * 25 * 2 = 4000
  1190. bytes).
  1191.  
  1192. Here's a simple (no error-checking) version of MYPROG.PAS:
  1193.  
  1194.    program MyProg;
  1195.  
  1196.    procedure ShowScreen(var ScreenData : Pointer);
  1197.    { Display a screenful of data--no error-checking! }
  1198.    var
  1199.      ScreenSegment: Word;
  1200.  
  1201.    begin
  1202.      if (Lo(LastMode) = 7) then        { Mono? }
  1203.        ScreenSegment := $B000
  1204.      else
  1205.        ScreenSegment := $B800;
  1206.      Move(@^ScreenData^,               { From pointer }
  1207.       Ptr(ScreenSegment, 0)^,          { To video memory }
  1208.       4000);                           { 80 * 25 * 2 }
  1209.    end;
  1210.  
  1211.    var
  1212.      MenuP : Pointer;
  1213.      MenuF : file;
  1214.    begin
  1215.      Assign(MenuF, 'MENU.DTA');        { Open screen data file }
  1216.      Reset(MenuF, 1);
  1217.      GetMem(MenuP, 4000);              { Allocate buffer on heap }
  1218.      BlockRead(MenuF, MenuP^, 4000);   { Read screen data }
  1219.      Close(MenuF);
  1220.      ShowScreen(MenuP);                { Display screen }
  1221.    end.
  1222.  
  1223. The screen data file (MENU.DTA) is opened and then read into a buffer on
  1224. the heap. Both MYPROG.EXE and MENU.DTA must be present at run-time for this
  1225. program to work. You can use BINOBJ to convert MENU.DTA to an .OBJ file
  1226. (MENUDTA.OBJ) and tell it to associate the data with a procedure called
  1227. MenuData. Then you can declare the fake external procedure MenuData, which
  1228. actually contains the screen data. Once you link in the .OBJ file with the
  1229. $L compiler directive, MenuData will be 4000 bytes long and contain your
  1230. screen data. First, run BINOBJ on MENU.DTA:
  1231.  
  1232.    binobj MENU.DTA MENUDTA MenuData
  1233.  
  1234. The first parameter, MENU.DTA, shows a familiar file of screen data; the
  1235. second, MENUDTA, is the name of the .OBJ file to be created (since you
  1236. didn't specify an extension, .OBJ will be added). The last parameter,
  1237. MenuData, is the name of the external procedure as it will be declared in
  1238. your progam. Now that you've converted MENU.DTA to an .OBJ file, here's
  1239. what the new MYPROG.PAS looks like:
  1240.  
  1241.    program MyProg;
  1242.  
  1243.    procedure ShowScreen(ScreenData : Pointer);
  1244.    { Display a screenful of data--no error checking! }
  1245.    var
  1246.      ScreenSegment: Word;
  1247.    begin
  1248.      if (Lo(LastMode) = 7) then             { Mono? }
  1249.        ScreenSegment := $B000
  1250.      else
  1251.        ScreenSegment := $B800;
  1252.      Move(@^ScreenData^,                    { From pointer }
  1253.       Ptr(ScreenSegment, 0)^,               { To video memory }
  1254.       4000);                                { 80 * 25 * 2 }
  1255.    end;
  1256.  
  1257.    procedure MenuData; external;
  1258.    {$L MENUDTA.OBJ }
  1259.    begin
  1260.      ShowScreen(@MenuData);                 { Display screen }
  1261.    end.
  1262.  
  1263. Notice that ShowScreen didn't change at all, and that the ADDRESS of your
  1264. procedure is passed using the @ operator.
  1265.  
  1266.