home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / doc / quel / macros.doc < prev    next >
Encoding:
Text File  |  1992-11-19  |  13.4 KB  |  327 lines

  1.  
  2.  
  3.  
  4.  
  5.      MACROS(QUEL)                 2/19/79                 MACROS(QUEL)
  6.  
  7.  
  8.  
  9.      NAME
  10.           macros - terminal monitor macro facility
  11.  
  12.      DESCRIPTION
  13.           The terminal monitor macro facility provides the ability  to
  14.           tailor  the  QUEL  language to the user's tastes.  The macro
  15.           facility allows strings of text to be removed from the query
  16.           stream  and  replaced  with other text.  Also, some built in
  17.           macros change the environment upon execution.
  18.  
  19.           _B_a_s_i_c _C_o_n_c_e_p_t_s
  20.  
  21.           All macros are composed of two parts, the _t_e_m_p_l_a_t_e part  and
  22.           the  _r_e_p_l_a_c_e_m_e_n_t  part.   The template part defines when the
  23.           macro should be invoked.  For example, the template  ``ret''
  24.           causes the corresponding macro to be invoked upon encounter-
  25.           ing the word ``ret'' in the input stream.  When a  macro  is
  26.           encountered,  the template part is removed and replaced with
  27.           the replacement part.  For example, if the replacement  part
  28.           of the ``ret'' macro was ``retrieve'', then all instances of
  29.           the word ``ret'' in the input text would  be  replaced  with
  30.           the word ``retrieve'', as in the statement
  31.  
  32.                   ret (p.all)
  33.  
  34.           Macros may have parameters, indicated by a dollar sign.  For
  35.           example,  the  template  ``get  $1''  causes the macro to be
  36.           triggered by the word ``get'' followed by  any  other  word.
  37.           The word following ``get'' is remembered for later use.  For
  38.           example, if the replacement part of the ``get'' macro where
  39.  
  40.                   retrieve (p.all) where p.pnum = $1
  41.  
  42.           then typing ``get 35'' would retrieve all information  about
  43.           part number 35.
  44.  
  45.           _D_e_f_i_n_i_n_g _M_a_c_r_o_s
  46.  
  47.           Macros can be defined using the special macro  called  ``de-
  48.           fine''.  The template for the define macro is (roughly)
  49.  
  50.                   {define; $t; $r}
  51.  
  52.           where $t and $r are the template and  replacement  parts  of
  53.           the macro, respectively.
  54.  
  55.           Let's look at a few examples.  To define the  ``ret''  macro
  56.           discussed above, we would type:
  57.  
  58.                   {define; ret; retrieve}
  59.  
  60.           When this is read, the macro  processor  removes  everything
  61.           between  the  curly  braces  and updates some tables so that
  62.           ``ret'' will be recognized and replaced with the word  ``re-
  63.           trieve''.   The define macro has the null string as replace-
  64.           ment text, so that this macro seems to disappear.
  65.  
  66.           A useful macro is one which shortens range  statements.   It
  67.           can be defined with
  68.  
  69.                   {define; rg $v $r; range of $v is $r}
  70.  
  71.           This macro causes the word ``rg'' followed by the  next  two
  72.           words  to be removed and replaced by the words ``range of'',
  73.           followed by the first word which followed  ``rg'',  followed
  74.           by  the  word ``is'', followed by the second word which fol-
  75.           lowed ``rg''.  For example, the input
  76.  
  77.                   rg p parts
  78.  
  79.           becomes the same as
  80.  
  81.                   range of p is parts
  82.  
  83.  
  84.           _E_v_a_l_u_a_t_i_o_n _T_i_m_e_s
  85.  
  86.           When you type in a define statement, it is not processed im-
  87.           mediately,  just  as queries are saved rather than executed.
  88.           No macro processing  is  done  until  the  query  buffer  is
  89.           evaluated.   The commands \go, \list, and \eval evaluate the
  90.           query buffer.  \go sends the results to INGRES, \list prints
  91.           them  on  your terminal, and \eval puts the result back into
  92.           the query buffer.
  93.  
  94.           It is important to evaluate any  define  statements,  or  it
  95.           will  be  exactly  like  you did not type them in at all.  A
  96.           common way to define macros is to type
  97.  
  98.                   {define . . . }
  99.                   \eval
  100.                   \reset
  101.  
  102.           If the \eval was left out, there is no effect at all.
  103.  
  104.           _Q_u_o_t_i_n_g
  105.  
  106.           Sometimes strings must be passed through the macro processor
  107.           without  being processed.  In such cases the grave and acute
  108.           accent marks (` and ') can be used to surround  the  literal
  109.           text.  For example, to pass the word ``ret'' through without
  110.           converting it to ``retrieve'' we could type
  111.  
  112.                   `ret'
  113.  
  114.           Another use for quoting is during parameter collection.   If
  115.           we  want  to enter more than one word where only one was ex-
  116.           pected, we can surround the parameter with accents.
  117.  
  118.           The backslash character quotes only the next character (like
  119.           surrounding  the  character with accents).  In particular, a
  120.           grave accent can be used literally by preceeding it  with  a
  121.           backslash.
  122.  
  123.           Since macros can normally only be on one line,  it  is  fre-
  124.           quently  useful to use a backslash at the end of the line to
  125.           hide the newline.  For example, to enter  the  long  ``get''
  126.           macro, you might type:
  127.                   {define; get $n; retrieve (e.all) \
  128.                   where e.name = "$n"}
  129.  
  130.           The backslash always quotes the next character even when  it
  131.           is  a  backslash.   So,  to  get  a  real backslash, use two
  132.           backslashes.
  133.  
  134.           _M_o_r_e _P_a_r_a_m_e_t_e_r_s
  135.  
  136.           Parameters need not be limited to the word  following.   For
  137.           example, in the template descriptor for define:
  138.  
  139.                   {define; $t; $r}
  140.  
  141.           the $t parameter ends at the  first  semicolon  and  the  $r
  142.           parameters ends at the first right curly brace.  The rule is
  143.           that the character which  follows  the  parameter  specifier
  144.           terminates the parameter; if this character is a space, tab,
  145.           newline, or the end of the template then one  word  is  col-
  146.           lected.
  147.  
  148.           As with all good rules, this one has  an  exception.   Since
  149.           system  macros  are  always  surrounded by curly braces, the
  150.           macro processor knows that they  must  be  properly  nested.
  151.           Thus, in the statement
  152.  
  153.                   {define; x; {sysfn}}
  154.  
  155.           The first right curly brace will close the ``sysfn''  rather
  156.           than the ``define''.  Otherwise this would have to be typed
  157.  
  158.                   {define; x; `{sysfn}'}
  159.  
  160.  
  161.           Words are defined in the usual way, as  strings  of  letters
  162.           and digits plus the underscore character.
  163.  
  164.           _O_t_h_e_r _B_u_i_l_t_i_n _M_a_c_r_o_s
  165.  
  166.           There are several other macros built in to the macro proces-
  167.           sor.   In  the  following description, some of the parameter
  168.           specifiers are marked with two dollar signs rather than one;
  169.           this will be discussed in the section on prescanning below.
  170.  
  171.           {define; $$t; $$r} defines a macro as discussed above.  Spe-
  172.           cial  processing  occurs  on the template part which will be
  173.           discussed in a later section.
  174.  
  175.           {rawdefine; $$t; $$r} is another form of define,  where  the
  176.           special processing does not take place.
  177.  
  178.           {remove; $$n} removes the macro with name $n.  It can remove
  179.           more  than  one  macro, since it actually removes all macros
  180.           which might conflict with $n under some  circumstance.   For
  181.           example, typing
  182.  
  183.                   {define; get part $n; . . . }
  184.                   {define; get emp $x; . . . }
  185.                   {remove; get}
  186.  
  187.           would cause both the get macros to be removed.  A call to
  188.  
  189.                   {remove; get part}
  190.  
  191.           would have only removed the first macro.
  192.  
  193.           {type $$s} types $s onto the terminal.
  194.  
  195.           {read $$s} types $s and then reads a line from the terminal.
  196.           The line which was typed replaces the macro.  A macro called
  197.           ``{readcount}'' is defined containing the number of  charac-
  198.           ters  read.   A control-D (end of file) becomes -1, a single
  199.           newline becomes zero, and so forth.
  200.  
  201.           {readdefine; $$n; $$s} also types $s and reads a  line,  but
  202.           puts  the  line into a macro named $n.  The replacement text
  203.           is the count of  the  number  of  characters  in  the  line.
  204.           {readcount} is still defined.
  205.  
  206.           {ifsame; $$a; $$b; $t; $f} compares the strings $a  and  $b.
  207.           If  they match exactly then the replacement text becomes $t,
  208.           otherwise it becomes $f.
  209.  
  210.           {ifeq; $$a; $$b; $t; $f} is similar, but the  comparison  is
  211.           numeric.
  212.  
  213.           {ifgt; $$a; $$b; $t; $f} is like ifeq, but the test  is  for
  214.           $a strictly greater than $b.
  215.  
  216.           {substr; $$f; $$t; $$s} returns the part of $s between char-
  217.           acter  positions  $f and $t, numbered from one.  If $f or $t
  218.           are out of range, they are moved in range as much as  possi-
  219.           ble.
  220.  
  221.           {dump; $$n} returns the value of the macro (or macros) which
  222.           match  $n  (using the same algorithm as remove).  The output
  223.           is a rawdefine statement so that it can  be  read  back  in.
  224.           {dump} without arguments dumps all macros.
  225.  
  226.           _M_e_t_a_c_h_a_r_a_c_t_e_r_s
  227.  
  228.           Certain characters are used internally.  Normally  you  will
  229.           not  even  see  them, but they can appear in the output of a
  230.           dump command, and can sometimes be used to create very fancy
  231.           macros.
  232.  
  233.           \| matches any number of spaces, tabs, or newlines.  It will
  234.           even  match  zero, but only between words, as can occur with
  235.           punctuation.  For example, \| will match  the  spot  between
  236.           the last character of a word and a comma following it.
  237.  
  238.           \^ matches exactly one space, tab, or newline.
  239.  
  240.           \& matches exactly zero spaces, tabs, or newlines, but  only
  241.           between words.
  242.  
  243.           _T_h_e _D_e_f_i_n_e _P_r_o_c_e_s_s
  244.  
  245.           When you define a macro using define, a lot of special  pro-
  246.           cessing happens.  This processing is such that define is not
  247.           functionally complete, but still adequate for most  require-
  248.           ments.  If more power is needed, rawdefine can be used; how-
  249.           ever, rawdefine is particularly difficult to use  correctly,
  250.           and should only be used by gurus.
  251.  
  252.           In define, all sequences of spaces, tabs,  and  newlines  in
  253.           the  template,  as well as all ``non-spaces'' between words,
  254.           are turned into a single \| character.  If the template ends
  255.           with a parameter, the \& character is added at the end.
  256.  
  257.           If you want to match a real tab or newline, you can  use  \t
  258.           or \n respectively.  For example, a macro which reads an en-
  259.           tire line and uses it as the name of an  employee  would  be
  260.           defined with
  261.  
  262.                   {define; get $n\n; \
  263.                       ret (e.all) where e.name = "$n"}
  264.  
  265.           This macro might be used by typing
  266.  
  267.                   get *Stan*
  268.  
  269.           to get all information about everyone with a name which  in-
  270.           cluded  ``Stan''.   By the way, notice that it is ok to nest
  271.           the ``ret'' macro inside the ``get'' macro.
  272.  
  273.           _P_a_r_a_m_e_t_e_r _P_r_e_s_c_a_n
  274.  
  275.           Sometimes it is useful to macro process a  parameter  before
  276.           using  it in the replacement part.  This is particularly im-
  277.           portant when using certain builtin macros.
  278.  
  279.           For prescan to occur, two things must be  true:  first,  the
  280.           parameter  must be specified in the template with two dollar
  281.           signs instead of one, and second, the actual parameter  must
  282.           begin with an ``at'' sign (``@'') (which is stripped off).
  283.  
  284.           For an example of the use of prescan, see ``Special Macros''
  285.           below.
  286.  
  287.           _S_p_e_c_i_a_l _M_a_c_r_o_s
  288.  
  289.           Some special macros are used by the terminal monitor to con-
  290.           trol the environment and return results to the user.
  291.  
  292.           {begintrap} is executed at the beginning of a query.
  293.  
  294.           {endtrap} is executed after the body of a query is passed to
  295.           INGRES.
  296.  
  297.           {continuetrap} is executed after the query  completes.   The
  298.           difference  between  this and endtrap is that endtrap occurs
  299.           after the query is submitted, but before the query executes,
  300.           whereas continuetrap is executed after the query executes.
  301.  
  302.           {editor} can be defined to be the pathname of an  editor  to
  303.           use in the \edit command.
  304.  
  305.           {shell} can be defined to be the pathname of a shell to  use
  306.           in the \shell command.
  307.  
  308.           {tuplecount} is set  after  every  query  (but  before  con-
  309.           tinuetrap is sprung) to be the count of the number of tuples
  310.           which satisfied the qualification of  the  query  in  a  re-
  311.           trieve, or the number of tuples changed in an update.  It is
  312.           not set for DBU functions.  If multiple queries are  run  at
  313.           once,  it is set to the number of tuples which satisfied the
  314.           last query run.
  315.  
  316.           For example, to print out the number of tuples  touched  au-
  317.           tomatically after each query, you could enter:
  318.                   {define; {begintrap}; {remove; {tuplecount}}}
  319.                   {define; {continuetrap}; \
  320.                      {ifsame; @{tuplecount}; {tuplecount};; \
  321.                        {type @{tuplecount} tuples touched}}}
  322.  
  323.      SEE ALSO
  324.           monitor(quel)
  325.  
  326.  
  327.