1 /*
2  * sqsh_tok.h - Lexical analysis (tokenizing) of a command line
3  *
4  * Copyright (C) 1995, 1996 by Scott C. Gray
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, write to the Free Software
18  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * You may contact the author :
21  *   e-mail:  gray@voicenet.com
22  *            grays@xtend-tech.com
23  *            gray@xenotropic.com
24  */
25 #ifndef sqsh_tok_h_included
26 #define sqsh_tok_h_included
27 #include "sqsh_varbuf.h"
28 
29 /*-- Possible Tokens --*/
30 #define SQSH_T_EOF         0    /* End-of-line */
31 #define SQSH_T_REDIR_OUT   1    /* A '[n]>', or a '[n]>>' */
32 #define SQSH_T_REDIR_IN    2    /* A '<' */
33 #define SQSH_T_REDIR_DUP   3    /* A '[m]>&[n]' */
34 #define SQSH_T_WORD        4    /* Something other than above */
35 
36 /*
37  * The following is the longest token that we are capable of dealing
38  * with.  I don't really like hard-coding this, but it is better than
39  * constantly dynamically allocating a new buffer each time we need to
40  * tokenize.
41  */
42 #define SQSH_TOKLEN      512
43 
44 typedef struct tok_st {
45 
46 	int   tok_type ;           /* One of the above defines */
47 
48 	/*
49 	 * For SQSH_T_REDIR_OUT, this will be a True or False if we are
50 	 * appending to a file or overwriting it.
51 	 */
52 	int   tok_append ;         /* True/False, Are we to append to file? */
53 
54 	/*
55 	 * The following are use by the various redirection tokens.  In the case
56 	 * of SQSH_T_REDIR_OUT only tok_fd_left will be valid, for SQSH_T_REDIR_DUP,
57 	 * both will be valid (tok_fd_left will always be m, from above), for
58 	 * all other tokens these don't apply.
59 	 */
60 	int   tok_fd_left ;        /* File descriptor to left of token */
61 	int   tok_fd_right ;       /* File descriptor to right of token */
62 
63 	/*
64 	 * All tokens will fill in the text for which they represent
65 	 */
66  	varbuf_t  *tok_value ;
67 
68 } tok_t ;
69 
70 /*
71  * Flags tot the tokenizer.
72  */
73 #define TOK_F_LEAVEQUOTE   (1<<0)   /* Leave quotes in-tact */
74 #define TOK_F_TEST         (1<<1)   /* Expand '[' ']' test operators */
75 
76 /*-- Local Prototypes --*/
77 int   sqsh_tok         _ANSI_ARGS(( char*, tok_t**, int )) ;
78 
79 #define sqsh_tok_value(t)  varbuf_getstr((t)->tok_value)
80 
81 #endif
82