home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / named / tools / nslookup / commands.l next >
Encoding:
Lex Description  |  1991-04-24  |  5.8 KB  |  197 lines

  1. %{
  2.  
  3. /*-
  4.  * Copyright (c) 1985 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  *    This product includes software developed by the University of
  18.  *    California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  */
  35.  
  36. #ifndef lint
  37. static char sccsid[] = "@(#)commands.l    5.13 (Berkeley) 7/24/90";
  38. #endif /* not lint */
  39.  
  40. /*
  41.  *******************************************************************************
  42.  *
  43.  *  commands.l
  44.  *
  45.  *    Andrew Cherenson    CS298-26  Fall 1985
  46.  *
  47.  *    Lex input file for the nslookup program command interpreter.
  48.  *    When a sequence is recognized, the associated action
  49.  *    routine is called. The action routine may need to
  50.  *    parse the string for additional information.
  51.  *
  52.  *  Recognized commands: (identifiers are shown in uppercase)
  53.  *
  54.  *    server NAME    - set default server to NAME, using default server
  55.  *    lserver NAME    - set default server to NAME, using initial server
  56.  *    finger [NAME]    - finger the optional NAME
  57.  *    exit        - exit the program
  58.  *    root        - set default server to the root
  59.  *    ls NAME        - list the domain NAME
  60.  *    view FILE    - sorts and view the file with more
  61.  *    set OPTION    - set an option
  62.  *    help        - print help information
  63.  *    ?        - print help information
  64.  *    NAME        - print info about the host/domain NAME
  65.  *              using default server.
  66.  *    NAME1 NAME2    - as above, but use NAME2 as server
  67.  *
  68.  *
  69.  *   yylex Results:
  70.  *    0        upon end-of-file.
  71.  *    1        after each command.
  72.  *
  73.  *******************************************************************************
  74.  */
  75.  
  76. #include "res.h"
  77. extern char rootServerName[];
  78.  
  79. %}
  80. WS    [ \t]
  81. FLET    [A-Za-z0-9.*\\]
  82. LET    [A-Za-z0-9.*]
  83. NAME    [A-Za-z0-9.*=_/-]
  84. %%
  85. ^{WS}*server{WS}+{LET}{NAME}*{WS}*$    {
  86.                         /*
  87.                          * 0 == use current server to find
  88.                          *        the new one.
  89.                          * 1 == use original server to find
  90.                          *        the new one.
  91.                          */
  92.                         SetDefaultServer(yytext, 0);
  93.                         return(1);
  94.                     }
  95. ^{WS}*lserver{WS}+{LET}{NAME}*{WS}*$    {
  96.                         SetDefaultServer(yytext, 1);
  97.                         return(1);
  98.                     }
  99. ^{WS}*exit{WS}*$            {
  100.                         return(0);
  101.                     }
  102. ^{WS}*root{WS}*$            {
  103.                         SetDefaultServer(rootServerName, 1);
  104.                         return(1);
  105.                     }
  106. ^{WS}*finger({WS}+{LET}{NAME}*)?{WS}+>>?{WS}*{NAME}+{WS}*$    {
  107.                         /*
  108.                          * 2nd arg.
  109.                          *  0 == output to stdout
  110.                          *  1 == output to file
  111.                          */
  112.                         Finger(yytext, 1);
  113.                         return(1);
  114.                     }
  115. ^{WS}*finger({WS}+{LET}{NAME}*)?{WS}*$    {
  116.                         Finger(yytext, 0);
  117.                         return(1);
  118.                     }
  119. ^{WS}*view{WS}+{NAME}+{WS}*$    {
  120.                         ViewList(yytext);
  121.                         return(1);
  122.                     }
  123. ^{WS}*ls{WS}+(("-a"|"-d"|"-h"|"-m"|"-s"){WS}+)?{LET}{NAME}*{WS}+>>?{WS}+{NAME}+{WS}*$    {
  124.                         /*
  125.                          * 2nd arg.
  126.                          *  0 == output to stdout
  127.                          *  1 == output to file
  128.                          */
  129.                         ListHosts(yytext, 1);
  130.                         return(1);
  131.                     }
  132. ^{WS}*ls{WS}+(("-a"|"-d"|"-h"|"-m"|"-s"){WS}+)?{LET}{NAME}*{WS}*$    {
  133.                         ListHosts(yytext, 0);
  134.                         return(1);
  135.                     }
  136. ^{WS}*ls{WS}+-t{WS}+({LET}{NAME}*{WS}+)?{LET}{NAME}*{WS}+>>?{WS}+{NAME}+{WS}*$ {
  137.                         /*
  138.                          * 2nd arg.
  139.                          *  0 == output to stdout
  140.                          *  1 == output to file
  141.                          */
  142.                         ListHostsByType(yytext, 1);
  143.                         return(1);
  144.                     }
  145. ^{WS}*ls{WS}+-t{WS}+({LET}{NAME}*{WS}+)?{LET}{NAME}*{WS}*$ {
  146.                         ListHostsByType(yytext, 0);
  147.                         return(1);
  148.                     }
  149. ^{WS}*set{WS}+{NAME}+{WS}*$        {
  150.                         SetOption(yytext);
  151.                         return(1);
  152.                     }
  153. ^{WS}*help{WS}*$            {
  154.                         extern void PrintHelp();
  155.  
  156.                         PrintHelp();
  157.                         return(1);
  158.                     }
  159. ^{WS}*"?"{WS}*$                {
  160.                         PrintHelp();
  161.                         return(1);
  162.                     }
  163. ^{WS}*{FLET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$    {
  164.                         /*
  165.                          * 0 == output to stdout
  166.                          * 1 == output to file
  167.                          */
  168.                         LookupHost(yytext, 1);
  169.                         return(1);
  170.                     }
  171. ^{WS}*{FLET}{NAME}*{WS}*$        {
  172.                         LookupHost(yytext, 0);
  173.                         return(1);
  174.                     }
  175. ^{WS}*{FLET}{NAME}*{WS}+{LET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$    {
  176.                         /*
  177.                          * 0 == output to stdout
  178.                          * 1 == output to file
  179.                          */
  180.                         LookupHostWithServer(yytext, 1);
  181.                         return(1);
  182.                     }
  183. ^{WS}*{FLET}{NAME}*{WS}+{LET}{NAME}*{WS}*$    {
  184.                         LookupHostWithServer(yytext, 0);
  185.                         return(1);
  186.                     }
  187. ^{WS}*\n                {
  188.                         return(1);
  189.                     }
  190. ^.*\n                    {
  191.                         printf("Unrecognized command: %s",
  192.                             yytext);
  193.                         return(1);
  194.                     }
  195. \n                    { ; }
  196. %%
  197.