• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/maloc/src/vsh/vpars.c

00001 /*
00002  * ***************************************************************************
00003  * MALOC = < Minimal Abstraction Layer for Object-oriented C >
00004  * Copyright (C) 1994--2008 Michael Holst
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  * rcsid="$Id: vpars.c,v 1.7 2008/03/12 05:13:58 fetk Exp $"
00021  * ***************************************************************************
00022  */
00023 
00024 /*
00025  * ***************************************************************************
00026  * File:     vpars.c
00027  *
00028  * Purpose:  Class Vsh: methods.
00029  *
00030  * Author:   Michael Holst
00031  * ***************************************************************************
00032  */
00033 
00034 #include "vsh_p.h"
00035 
00036 VEMBED(rcsid="$Id: vpars.c,v 1.7 2008/03/12 05:13:58 fetk Exp $")
00037 
00038 VPRIVATE char inbuf[VMAX_BUFSIZE];
00039 VPRIVATE int numRead;
00040 
00041 /*
00042  * ***************************************************************************
00043  * Routine:  Vsh_parse
00044  *
00045  * Purpose:  Parser.
00046  *
00047  * Author:   Michael Holst
00048  * ***************************************************************************
00049  */
00050 void Vsh_parse(void)
00051 {
00052     /* get an input line */
00053     /* numRead = Vsh_input(inbuf,VMAX_BUFSIZE); */
00054     VSH_INPUT(inbuf,numRead,VMAX_BUFSIZE);
00055 }
00056 
00057 /*
00058  * ***************************************************************************
00059  * Routine:  Vsh_parseHandoff
00060  *
00061  * Purpose:  Fake parser.
00062  *
00063  * Author:   Michael Holst
00064  * ***************************************************************************
00065  */
00066 void Vsh_parseHandoff(char *buf)
00067 {
00068     strcpy(inbuf,buf);
00069     numRead = strlen(inbuf);
00070 }
00071 
00072 /*
00073  * ***************************************************************************
00074  * Routine:  Vsh_execute
00075  *
00076  * Purpose:  Executor (execv of a command).
00077  *
00078  * Author:   Michael Holst
00079  * ***************************************************************************
00080  */
00081 void Vsh_execute(void)
00082 {
00083     char inbuf_argv[VMAX_BUFSIZE], *argv[VMAX_ARGNUM];
00084     int i, argc;
00085 
00086     /*
00087      * Init: "cmdKey=0" AFTER possible setJmp/longJmp
00088      *    cmdKey==0  ==> This WAS NOT a builtin command
00089      *    cmdKey==1  ==> This WAS a builtin command (non-exit)
00090      *    cmdKey==2  ==> This WAS the builtin EXIT command
00091      */
00092     cmdKey = 0;
00093     if (numRead == 0) {
00094         if (Vsh_thee->cinUnit == stdin) {
00095             Vnm_print(1,"%s",Vsh_thee->PR_EXIT);
00096             Vnm_print(1,"%s",VNEWLINE_STRING);
00097         }
00098         cmdKey = 2;
00099     } else {
00100         if (*(inbuf+strlen(inbuf)-1) == VNEWLINE_SYMBOL)
00101             *(inbuf+strlen(inbuf)-1) = VNULL_SYMBOL;
00102         strcpy(inbuf_argv,inbuf);
00103         argc = Vnm_gentokens(inbuf_argv,argv,VMAX_ARGNUM," ","#");
00104 
00105         /*
00106          * Vnm_print(1,"   TOKENS: (%d)",argc);
00107          * for (i=0; i<=argc; i++) Vnm_print(1,"   <%s>",argv[i]);
00108          * Vnm_print(1,"\n");
00109          */
00110 
00111         if (argc > 0) {
00112 
00113             /* write out the input to our log file */
00114             /* (We don't want to log "." commands; otherwise running the */
00115             /* history won't recreate same situation it documented... */
00116             /* ...so we will put these in the log file as comments... */
00117             for (i=0; i<argc; i++) {
00118                 if (i==0) {
00119                     if (!strcmp(argv[0],".")) {
00120                         Vnm_print(3,"# ");
00121                     }
00122                 }
00123                 Vnm_print(3,"%s", argv[i]);
00124                 if (i==(argc-1)) {
00125                     Vnm_print(3,"\n");
00126                 } else {
00127                     Vnm_print(3," ");
00128                 }
00129             }
00130             Vsh_addhist(inbuf,strlen(inbuf));
00131             cmdKey = Vsh_builtIn(Vsh_thee,argc,argv);
00132             if (!cmdKey) Vsh_execCmd(Vsh_thee->PR,argc,argv,inbuf);
00133         }
00134     }
00135 }
00136 
00137 /*
00138  * ***************************************************************************
00139  * Routine:  Vsh_yyexecute
00140  *
00141  * Purpose:  Fork a child to exec a command, wait for child to finish.
00142  *
00143  * Author:   Michael Holst
00144  * ***************************************************************************
00145  */
00146 VPUBLIC void Vsh_yyexecute(COMMAND *cmd)
00147 {
00148 }
00149 

Generated on Wed Oct 20 2010 11:12:15 for APBS by  doxygen 1.7.2