00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <maloc/maloc.h>
00035
00036 #define VEMBED(rctag) VPRIVATE const char* rctag; \
00037 static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid);
00038 VEMBED(rcsid="$Id: main.c,v 1.12 2008/03/12 05:14:00 fetk Exp $")
00039
00040
00041 typedef enum APPcommand {
00042 app_none,
00043 app_help,
00044 app_stat,
00045 app_hello,
00046 app_bye
00047 } APPcommand;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 VPRIVATE APPcommand APPgetCmd(void *thee, int argc, char *argv[])
00059 {
00060 APPcommand theCmd = app_none;
00061 if (!strcmp(argv[0],"")) {
00062 theCmd = app_none;
00063 } else if (!strcmp(argv[0],"help")) {
00064 theCmd = app_help;
00065 } else if (!strcmp(argv[0],"stat")) {
00066 theCmd = app_stat;
00067 } else if (!strcmp(argv[0],"hello")) {
00068 theCmd = app_hello;
00069 } else if (!strcmp(argv[0],"bye")) {
00070 theCmd = app_bye;
00071 } else {
00072 theCmd = app_none;
00073 }
00074 return theCmd;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 VPRIVATE int APPsh(void *pthee, int argc, char *argv[])
00094 {
00095 Vsh *thee = (Vsh*)pthee;
00096
00097 int rc;
00098 APPcommand theCmd;
00099 static int init=0;
00100
00101
00102 if (!init) {
00103 init=1;
00104 }
00105
00106
00107 rc = 1;
00108
00109
00110 theCmd = APPgetCmd(thee, argc, argv);
00111
00112
00113 switch (theCmd) {
00114
00115 case app_help:
00116 if (argc==1) {
00117 Vnm_print(1,"%s: Application-layer Help Menu:\n",
00118 Vsh_getenv(thee,"SHELL"));
00119 Vnm_print(1," help --> Print this menu.\n");
00120 Vnm_print(1," stat --> Print some environ variables.\n");
00121 Vnm_print(1," hello --> Print 'Hello, World!'.\n");
00122 Vnm_print(1," bye --> Print 'Bye, World!' and exit.\n");
00123 rc = 0;
00124 } else {
00125 rc = 0;
00126 }
00127 break;
00128
00129 case app_stat:
00130 Vnm_print(1,"%s(APPsh): IFNAM=<%s> LMAX=<%d> LTOL=<%e>\n",
00131 Vsh_getenv(thee,"SHELL"),
00132 Vsh_getenv(thee,"IFNAM"),
00133 Vsh_getenvInt(thee,"LMAX"),
00134 Vsh_getenvReal(thee,"LTOL"));
00135 break;
00136
00137 case app_hello:
00138 Vnm_print(1,"%s(APPsh): Hello, World!\n",
00139 Vsh_getenv(thee,"SHELL"));
00140 break;
00141
00142 case app_bye:
00143 Vnm_print(1,"%s(APPsh): Bye, World!\n",
00144 Vsh_getenv(thee,"SHELL"));
00145 rc = 2;
00146 break;
00147
00148 default:
00149 rc = 0;
00150 break;
00151 }
00152 return rc;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 int main(int argc, char **argv)
00165 {
00166 int rc;
00167 Vsh *vsh;
00168
00169
00170
00171
00172
00173 vsh = Vsh_ctor(VNULL, argc, argv);
00174 rc = Vsh_shell(vsh, VNULL, vsh, &APPsh);
00175 Vsh_dtor(&vsh);
00176
00177
00178 Vnm_print(1,"\n");
00179 Vnm_print(1,"maloc_leaks = [\n");
00180 Vnm_print(1,"%% --------------------------------------"
00181 "--------------------------------------\n");
00182 Vnm_print(1,"%% Footprint Areas Malloc Free"
00183 " Highwater Class\n"),
00184 Vnm_print(1,"%% --------------------------------------"
00185 "--------------------------------------\n");
00186 Vmem_print(VNULL);
00187 Vmem_printTotal();
00188 Vnm_print(1,"%% --------------------------------------"
00189 "--------------------------------------\n");
00190 Vnm_print(1,"];\n");
00191
00192
00193 return rc;
00194 }
00195