8 void Console_puts(char* str
)
19 void Console_printf(char* fmt
, ...)
25 vsprintf(buffer
,fmt
,vargs
);
30 void Console_getline(PCH Prompt
, PCH Output
, DWORD OutputLength
)
47 Console_printf("Changing directory to %s\n",s
);
48 if (!SetCurrentDirectory(s
))
50 Console_puts("Failed to change to directory\n");
54 void func_dir(char* s
)
57 WIN32_FIND_DATA FindData
;
59 shandle
= FindFirstFile("*.*",&FindData
);
61 if (shandle
==INVALID_HANDLE_VALUE
)
67 Console_printf("Scanning %s\n",FindData
.cFileName
);
68 } while(FindNextFile(shandle
,&FindData
));
71 int is_builtin(char* name
, char* args
)
73 if (strcmp(name
,"dir")==0)
78 if (strcmp(name
,"cd")==0)
86 int process_command(char* str
)
90 PROCESS_INFORMATION pi
;
92 char process_arg
[255];
94 if (strcmp(str
,"exit")==0)
99 name
= strtok(str
," \t");
100 args
= strtok(NULL
,"");
102 if (is_builtin(name
,args
))
106 memset(&si
,0,sizeof(STARTUPINFO
));
107 si
.cb
=sizeof(STARTUPINFO
);
108 si
.lpTitle
=strdup(name
);
110 strcpy(process_arg
,name
);
111 strcat(process_arg
," ");
114 strcat(process_arg
,args
);
116 Console_printf("name '%s' process_arg '%s'\n",name
,process_arg
);
117 if (!CreateProcess(NULL
,process_arg
,NULL
,NULL
,FALSE
,
121 Console_printf("Failed to execute process\n");
126 void build_prompt(char* prompt
)
130 len
= GetCurrentDirectory(255,prompt
);
142 build_prompt(prompt
);
143 Console_getline(prompt
,line
,255);
144 Console_printf("Processing command '%s'\n",line
);
145 do_exit
= process_command(line
);
149 int STDCALL
WinMain (HINSTANCE hInst
, HINSTANCE hPrev
, LPSTR lpCmd
, int nShow
)
152 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
153 stdout
= GetStdHandle(STD_OUTPUT_HANDLE
);