www.pudn.com > tftp.rar > GETCMD.C
/* ** This product contains: ** "Restricted Materials of IBM" ** (c) Copyright IBM Corp. 1987 ** All Rights Reserved ** Licensed Materials-Property of IBM ** ** See Copyright Instructions, G120-2083 ** */ #include#include #include #include #include #include #include "tftpdefs.h" enum commands getcmd (cmdline) char *cmdline; { char token[COMMANDLEN]; char *work; enum commands cmd; int len,i; do { work = cmdline; printf ("%s> ",_whoami); gets(work); SkipWhite (work); } while (*work == '\0'); for (i=0; !isspace(*work) && *work != '\0'; i++,work++) token[i] = *work; token[i] = '\0'; len = strlen(strlwr(token)); if (strncmp(token,"serve", len) == 0) cmd = c_serve; else if (strncmp(token,"spool", len) == 0) cmd = c_spool; else if (strncmp(token,"connect",len) == 0) cmd = c_connect; else if (strncmp(token,"mode", len) == 0) cmd = c_mode; else if (strncmp(token,"get", len) == 0) cmd = c_get; else if (strncmp(token,"put", len) == 0) cmd = c_put; else if (strncmp(token,"quit", len) == 0) cmd = c_quit; else if (strncmp(token,"verbose",len) == 0) cmd = c_verbose; else if (strncmp(token,"trace", len) == 0) cmd = c_trace; else if (strncmp(token,"clobber",len) == 0) cmd = c_clobber; else if (strncmp(token,"eofmark",len) == 0) cmd = c_eofmark; else if (strncmp(token,"status", len) == 0) cmd = c_status; else if (strncmp(token,"binary", len) == 0) cmd = c_binary; else if (strncmp(token,"octet", len) == 0) cmd = c_binary; else if (strncmp(token,"image", len) == 0) cmd = c_binary; else if (strncmp(token,"ascii", len) == 0) cmd = c_ascii; else if (strncmp(token,"netascii",len)== 0) cmd = c_ascii; else if (strncmp(token,"rexmt", len) == 0) cmd = unsupported; else if (strncmp(token,"timeout",len) == 0) cmd = unsupported; else if (strncmp(token,"?", len) == 0) cmd = c_help; else if (strncmp(token,"help", len) == 0) cmd = c_help; else if (strncmp(token,"!",1 ) == 0) cmd = c_shell; else cmd = c_error; if (cmd == c_error) strcpy (cmdline,token); else if (cmd == c_shell) { strcpy( cmdline, cmdline+1 ); /* Toss the '!' */ if ( strlen( cmdline ) == 0 ) { char *shellvar; if ((shellvar = getenv("COMSPEC")) == NULL) strcpy(cmdline,"COMMAND.COM"); else strcpy( cmdline, shellvar ); } } else strcpy( cmdline, work ); return (cmd); }