Debian Codegraph @

debian/external_deps/fetk/maloc/src/vsh/vpars.c

raw
1 /*
2 * ***************************************************************************
3 * MALOC = < Minimal Abstraction Layer for Object-oriented C >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * rcsid="$Id: vpars.c,v 1.8 2010/08/12 05:40:25 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: vpars.c
27 *
28 * Purpose: Class Vsh: methods.
29 *
30 * Author: Michael Holst
31 * ***************************************************************************
32 */
33
34 #include "vsh_p.h"
35
36 VEMBED(rcsid="$Id: vpars.c,v 1.8 2010/08/12 05:40:25 fetk Exp $")
37
38 VPRIVATE char inbuf[VMAX_BUFSIZE];
39 VPRIVATE int numRead;
40
41 /*
42 * ***************************************************************************
43 * Routine: Vsh_parse
44 *
45 * Purpose: Parser.
46 *
47 * Author: Michael Holst
48 * ***************************************************************************
49 */
50 void Vsh_parse(void)
51 {
52 /* get an input line */
53 /* numRead = Vsh_input(inbuf,VMAX_BUFSIZE); */
54 VSH_INPUT(inbuf,numRead,VMAX_BUFSIZE);
55 }
56
57 /*
58 * ***************************************************************************
59 * Routine: Vsh_parseHandoff
60 *
61 * Purpose: Fake parser.
62 *
63 * Author: Michael Holst
64 * ***************************************************************************
65 */
66 void Vsh_parseHandoff(char *buf)
67 {
68 strcpy(inbuf,buf);
69 numRead = strlen(inbuf);
70 }
71
72 /*
73 * ***************************************************************************
74 * Routine: Vsh_execute
75 *
76 * Purpose: Executor (execv of a command).
77 *
78 * Author: Michael Holst
79 * ***************************************************************************
80 */
81 void Vsh_execute(void)
82 {
83 char inbuf_argv[VMAX_BUFSIZE], *argv[VMAX_ARGNUM];
84 int i, argc;
85
86 /*
87 * Init: "cmdKey=0" AFTER possible setJmp/longJmp
88 * cmdKey==0 ==> This WAS NOT a builtin command
89 * cmdKey==1 ==> This WAS a builtin command (non-exit)
90 * cmdKey==2 ==> This WAS the builtin EXIT command
91 */
92 cmdKey = 0;
93 if (numRead == 0) {
94 if (Vsh_thee->cinUnit == stdin) {
95 Vnm_print(1,"%s",Vsh_thee->PR_EXIT);
96 Vnm_print(1,"%s",VNEWLINE_STRING);
97 }
98 cmdKey = 2;
99 } else {
100 if (*(inbuf+strlen(inbuf)-1) == VNEWLINE_SYMBOL)
101 *(inbuf+strlen(inbuf)-1) = VNULL_SYMBOL;
102 strcpy(inbuf_argv,inbuf);
103 argc = Vnm_gentokens(inbuf_argv,argv,VMAX_ARGNUM," ","#");
104
105 /*
106 * Vnm_print(1," TOKENS: (%d)",argc);
107 * for (i=0; i<=argc; i++) Vnm_print(1," <%s>",argv[i]);
108 * Vnm_print(1,"\n");
109 */
110
111 if (argc > 0) {
112
113 /* write out the input to our log file */
114 /* (We don't want to log "." commands; otherwise running the */
115 /* history won't recreate same situation it documented... */
116 /* ...so we will put these in the log file as comments... */
117 for (i=0; i<argc; i++) {
118 if (i==0) {
119 if (!strcmp(argv[0],".")) {
120 Vnm_print(3,"# ");
121 }
122 }
123 Vnm_print(3,"%s", argv[i]);
124 if (i==(argc-1)) {
125 Vnm_print(3,"\n");
126 } else {
127 Vnm_print(3," ");
128 }
129 }
130 Vsh_addhist(inbuf,strlen(inbuf));
131 cmdKey = Vsh_builtIn(Vsh_thee,argc,argv);
132 if (!cmdKey) Vsh_execCmd(Vsh_thee->PR,argc,argv,inbuf);
133 }
134 }
135 }
136
137 /*
138 * ***************************************************************************
139 * Routine: Vsh_yyexecute
140 *
141 * Purpose: Fork a child to exec a command, wait for child to finish.
142 *
143 * Author: Michael Holst
144 * ***************************************************************************
145 */
146 VPUBLIC void Vsh_yyexecute(COMMAND *cmd)
147 {
148 }
149