ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

tnmain.cpp
Go to the documentation of this file.
00001 
00002 //Telnet Win32 : an ANSI telnet client.
00003 //Copyright (C) 1998  Paul Brannan
00004 //Copyright (C) 1998  I.Ioannou
00005 //Copyright (C) 1997  Brad Johnson
00006 //
00007 //This program is free software; you can redistribute it and/or
00008 //modify it under the terms of the GNU General Public License
00009 //as published by the Free Software Foundation; either version 2
00010 //of the License, or (at your option) any later version.
00011 //
00012 //This program is distributed in the hope that it will be useful,
00013 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //GNU General Public License for more details.
00016 //
00017 //You should have received a copy of the GNU General Public License
00018 //along with this program; if not, write to the Free Software
00019 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 //
00021 //I.Ioannou
00022 //roryt@hol.gr
00023 //
00025 
00027 //
00028 // Module:      tnmain.cpp
00029 //
00030 // Contents:    telnet main program
00031 //
00032 // Product:     telnet
00033 //
00034 // Revisions: August 11, 1998   Thomas Briggs <tbriggs@qmetric.com>
00035 //            May 14, 1998      Paul Brannan <pbranna@clemson.edu>
00036 //            5.April.1997      jbj@nounname.com
00037 //            5.Dec.1996        jbj@nounname.com
00038 //            Version 2.0
00039 //
00040 //            02.Apr.1995       igor.milavec@uni-lj.si
00041 //                    Original code
00042 //
00044 
00045 #include "precomp.h"
00046 
00047 int telCommandLine (Telnet &MyConnection);
00048 
00049 void waitforkey() {
00050     HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
00051     INPUT_RECORD InputRecord;
00052     DWORD dwInput;
00053     BOOL done = FALSE;
00054     while (!done){
00055         WaitForSingleObject( hConsole, INFINITE );
00056         if (!ReadConsoleInput(hConsole, &InputRecord, 1, &dwInput)){
00057             done = TRUE;
00058             continue;
00059         }
00060         if (InputRecord.EventType == KEY_EVENT &&
00061             InputRecord.Event.KeyEvent.bKeyDown )
00062             done = TRUE;
00063     }
00064 }
00065 
00066 //char * cfgets ( char * buf, unsigned int length, char pszHistory[][80], int iHistLength){
00067 struct cmdHistory * cfgets (char *buf, unsigned int length, struct cmdHistory *cmdhist) {
00068 
00069     HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
00070     unsigned int current=0, cursor =0, iEraseLength=0, i;
00071     char chr;
00072     char temp[2];
00073     char temp1[80];
00074 
00075     INPUT_RECORD InputRecord;
00076     BOOL done = FALSE;
00077 
00078     temp[1] = 0;
00079     buf[0] = '\0';
00080 
00081     if(!ini.get_input_redir()) {
00082         while (!done) {
00083             DWORD dwInput;
00084             int MustRefresh = 0;
00085             WaitForSingleObject( hConsole, INFINITE );
00086             if (!ReadConsoleInput(hConsole, &InputRecord, 1, &dwInput)){
00087                 done = TRUE;
00088                 continue;
00089             }
00090             MustRefresh = 0;
00091             if (InputRecord.EventType == KEY_EVENT &&
00092                 InputRecord.Event.KeyEvent.bKeyDown ) {
00093 
00094                 if(InputRecord.Event.KeyEvent.dwControlKeyState &
00095                     (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
00096 
00097                     switch(InputRecord.Event.KeyEvent.wVirtualKeyCode) {
00098                     case 'D': // Thomas Briggs 8/11/98
00099                         buf[0] = '\04';
00100                         buf[1] = '\0';
00101                         current = 1;
00102                         done = true;
00103                         continue;
00104                     case 'U': // Paul Brannan 8/11/98
00105                         buf[0] = '\0';
00106                         current = 0;
00107                         cursor = 0;
00108                         MustRefresh = 1;
00109                         break;
00110                     }
00111                 }
00112 
00113                 switch (InputRecord.Event.KeyEvent.wVirtualKeyCode) {
00114                 case VK_UP:
00115                     // crn@ozemail.com.au
00116                     if (cmdhist != NULL) {
00117                         if (!strcmp(buf, ""))
00118                             strncpy(buf, cmdhist->cmd, 79);
00119                         else if (cmdhist->prev != NULL) {
00120                             cmdhist = cmdhist->prev;
00121                             strncpy(buf, cmdhist->cmd, 79);
00122                         }
00123                         current = strlen(buf);
00124                     }
00126                     MustRefresh = 1;
00127                     break;
00128                 case VK_DOWN:
00129                     // crn@ozemail.com.au
00130                     if (cmdhist != NULL) {
00131                         if (cmdhist->next != NULL) {
00132                             cmdhist = cmdhist->next;
00133                             strncpy(buf, cmdhist->cmd, 79);
00134                         } else {
00135                             strncpy(buf, "", 79);
00136                         }
00137                         current = strlen(buf);
00138                     }
00140                     MustRefresh = 1;
00141                     break;
00142                 case VK_RIGHT:      //crn@ozemail.com.au (added ctrl+arrow)
00143                     if (cursor < current) {
00144                         if (InputRecord.Event.KeyEvent.dwControlKeyState &
00145                             (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
00146                             unsigned int j, k;
00147                             for (j = cursor; j <= current; j++)
00148                                 if (buf[j+1] == ' ' || (j+1)==current)
00149                                     break;
00150                                 for (k = ++j; k <= current; k++)
00151                                     if (buf[k] != ' ' || k == current) {
00152                                         cursor = k == current ? --k : k;
00153                                         break;
00154                                     }
00155                         } else
00156                             cursor++;
00157                         MustRefresh = 1;
00158                         break;
00159                     }
00160                 case VK_LEFT:       //crn@ozemail.com.au (added ctrl+arrow)
00161                     if (cursor > 0) {
00162                         if(InputRecord.Event.KeyEvent.dwControlKeyState &
00163                             (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
00164                             int j, k;
00165                             for (j = cursor; j >= 0; j--)
00166                                 if (buf[j-1] != ' ')
00167                                     break;
00168                                 for (k = --j; k >= 0; k--)
00169                                     if (buf[k] == ' ' || k == 0) {
00170                                         cursor = !k ? k : ++k;
00171                                         break;
00172                                     }
00173                         } else
00174                             cursor--;
00175                         MustRefresh = 1;
00176                         break;
00177                     }
00178                 case VK_HOME:
00179                     if (cursor>0) cursor = 0;
00180                     MustRefresh = 1;
00181                     break;
00182                 case VK_END:
00183                     if (cursor<current) cursor = current;
00184                     MustRefresh = 1;
00185                     break;
00186                 case VK_DELETE:
00187                     if (current > 0 && current > cursor) {
00188                         strcpy(&buf[cursor],&buf[cursor+1]);
00189                         current--;
00190                         buf[current] = 0;
00191                         printit("\r");
00192                         for (i = 0; i < current+strlen("telnet>")+1 ;i++)
00193                             printit(" ");
00194                     }
00195                     MustRefresh = 1;
00196                     break;
00197                 case VK_BACK:
00198                     if (cursor > 0 ) {
00199                         strcpy(&buf[cursor-1],&buf[cursor]);
00200                         current--;
00201                         cursor--;
00202                         buf[current] = 0;
00203                         printit("\r");
00204                         for (i = 0; i < current+strlen("telnet>")+1 ;i++)
00205                             printit(" ");
00206                     }
00207                     MustRefresh = 1;
00208                     break;
00209 
00210                 default:
00211                     chr = InputRecord.Event.KeyEvent.uChar.AsciiChar;
00212                     if (chr == '\r') {
00213                         done = TRUE;
00214                         continue;
00215                     }
00216                     if (current >= length-1){
00217                         done = TRUE;
00218                         continue;
00219                     }
00220                     if ( isprint (chr) ){
00221                         strncpy(temp1,&buf[cursor],79);
00222                         strncpy(&buf[cursor+1],temp1,79-(cursor+1));
00223                         buf[cursor++]=chr;
00224                         current++;
00225                         buf[current] = 0;
00226                         MustRefresh = 1;
00227                     }
00228                     break;
00229                 }
00230                 if (MustRefresh == 1)
00231                 {
00232                     printit("\rtelnet");
00233                     for (i = 0; i <= iEraseLength ;i++)
00234                         printit(" ");
00235                     printit("\rtelnet>");
00236                     printit(buf);
00237                     iEraseLength = strlen(buf);
00238                     for (i = 0; i < current-cursor; i++)
00239                         printit("\b");
00240                 }
00241             }
00242         }
00243         buf[current] = 0;
00244         if (strcmp(buf, "")) {
00245             if (cmdhist == NULL) {
00246                 cmdhist = new struct cmdHistory;
00247                 if (cmdhist == NULL) {
00248                     printit ("\nUnable to allocate memory for history buffer -- use the \"flush\" command to clear the buffer.\n");
00249                     return cmdhist;
00250                 }
00251                 strncpy(cmdhist->cmd, buf, 79);
00252                 cmdhist->next = NULL;
00253                 cmdhist->prev = NULL;
00254             } else {
00255                 while (cmdhist->next != NULL)   //  move to the end of the list
00256                     cmdhist = cmdhist->next;
00257                 cmdhist->next = new struct cmdHistory;
00258                 if (cmdhist->next == NULL) {
00259                     printit ("\nUnable to allocate memory for history buffer -- use the \"flush\" command to clear the buffer.\n");
00260                     return cmdhist;
00261                 }
00262                 cmdhist->next->prev = cmdhist;  //  previous is where we are now
00263                 cmdhist = cmdhist->next;
00264                 strncpy(cmdhist->cmd, buf, 79);
00265                 cmdhist->next = NULL;
00266             }
00267             while (cmdhist->next)
00268                 cmdhist = cmdhist->next;
00269         }
00270         return cmdhist;
00272     } else {
00273         WaitForSingleObject( hConsole, INFINITE );
00274         DWORD dwInput;
00275         DWORD OldMode;
00276         GetConsoleMode(hConsole, &OldMode);
00277         SetConsoleMode(hConsole,
00278             OldMode &~ (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) );
00279         while (ReadFile(hConsole, &chr, 1, &dwInput, NULL)) {
00280             if (chr == '\r') {
00281                 temp[0] = chr;
00282                 printit(&temp[0]);
00283                 break;
00284             }
00285             if (chr == '\b' && current > 0) {
00286                 current--;
00287                 printit("\b \b");
00288             }
00289             if (current >= length-1){
00290                 break;
00291             }
00292             if ( isprint (chr) ){
00293                 temp[0] = chr;
00294                 printit(&temp[0]);
00295                 buf[current++]=chr;
00296             }
00297         }
00298         buf[current] = 0;
00299         SetConsoleMode(hConsole, OldMode);
00300         return NULL;
00301     }
00302 }
00303 
00304 // AVS ** for fix bug in command 'keys load keymapname' without file
00305 // static char keyfile[MAX_PATH*2];
00306 
00307 int main(int ArgC, char* ArgV[]) {
00308 
00309     CONSOLE_SCREEN_BUFFER_INFO  ConsoleScreenBufferInfo;
00310     GetConsoleScreenBufferInfo(
00311         GetStdHandle(STD_OUTPUT_HANDLE),
00312         &ConsoleScreenBufferInfo
00313         );
00314 
00315     char *k;
00316     char startdir[MAX_PATH*2];
00317     char exename[MAX_PATH];
00318 
00319     // strncpy(startdir, ArgV[0],MAX_PATH);
00320     // This should be more accurate than using argv[0] (Paul Brannan 9/16/98)
00321     GetModuleFileName(NULL, startdir, sizeof(startdir));
00322 
00323     // Get the current console title so it can be set later
00324     // ("Pedro A. Aranda Gutiérrez" <paag@coppi.tid.es>)
00325     TCHAR ConsoleTitle[255];
00326     GetConsoleTitle(ConsoleTitle, sizeof(ConsoleTitle));
00327 
00328     k = strrchr(startdir, '\\');
00329     if (k == NULL){                     // if the \ character is not found...
00330         strcpy(exename, startdir);
00331         strcpy(startdir,"");            // set the path to nothing
00332     } else {
00333         // end the string after the last '\' to get rid of the file name
00334         strcpy(exename, k+1);
00335         k[1] = 0;
00336     }
00337 
00338     printm(0, FALSE, MSG_COPYRIGHT);
00339     printm(0, FALSE, MSG_COPYRIGHT_1);
00340 
00341     // set up the ini class
00342     ini.init(startdir, exename);
00343 
00344     // Process the command line arguments and connect to a host if necessary
00345     if(ini.Process_Params(ArgC, ArgV)) {
00346         const char *szHost = ini.get_host();
00347         const char *strPort = ini.get_port();
00348         if(!*szHost) {
00349             Telnet MyConnection;
00350             while(telCommandLine(MyConnection));
00351         } else {
00352             Telnet MyConnection;
00353             if(MyConnection.Open(szHost, strPort) == TNPROMPT) {
00354                 // still connected
00355                 printit("\n");
00356                 telCommandLine(MyConnection);
00357             }
00358         }
00359     }
00361 
00362     if(ini.get_term_width() != -1 || ini.get_term_height() != -1) {
00363         SetConsoleScreenBufferSize(
00364             GetStdHandle(STD_OUTPUT_HANDLE),    // handle of console screen buffer
00365             ConsoleScreenBufferInfo.dwSize      // new size in character rows and cols.
00366             );
00367         SetConsoleWindowInfo(
00368             GetStdHandle(STD_OUTPUT_HANDLE),    // handle of console screen buffer
00369             TRUE,                               // coordinate type flag
00370             &ConsoleScreenBufferInfo.srWindow   // address of new window rectangle
00371             );
00372     }
00373     SetConsoleTextAttribute(
00374         GetStdHandle(STD_OUTPUT_HANDLE),        // handle of console screen buffer
00375         ConsoleScreenBufferInfo.wAttributes     // text and background colors
00376         );
00377 
00378     // Restore the original console title
00379     // ("Pedro A. Aranda Gutiérrez" <paag@coppi.tid.es>)
00380     SetConsoleTitle(ConsoleTitle);
00381 
00382     return 0;
00383 }
00384 
00385 // AVS
00386 enum {
00387     BAD_USAGE = -3,
00388         EMPTY_LINE = -2,
00389         INVALID_CMD = -1,
00390         __FIRST_COMMAND = 0,
00391 
00392         OPEN = __FIRST_COMMAND,
00393         CLOSE,
00394         KEYS,
00395         QUIT,
00396         HELP,
00397         HELP2,              // there is way for synonims
00398         K_LOAD,             // subcommand of 'keys'
00399         K_SWITCH,           // subcommand of 'keys'
00400         K_DISPLAY,          // subcommand of 'keys'
00401 
00402         SET,                // Paul Brannan 5/30/98
00403 
00404         SUSPEND,
00405         FASTQUIT,           // Thomas Briggs 8/11/98
00406         CMD_HISTORY,        // crn@ozemail.com.au
00407         CLEAR_HISTORY,      // crn@ozemail.com.au
00408 
00409         ALIASES,            // Paul Brannan 1/1/99
00410 
00411         __COMMAND_LIST_SIZE // must be last
00412 };
00413 
00414 
00415 struct command {
00416     const char* cmd;                // command
00417     int   minLen,           // minimal length for match
00418           minParms,         // minimal count of parms
00419           maxParms;         // maximal -/- (negative disables)
00420     int   isSubCmd,         // is a subcommand - number of wich command
00421           haveSubCmd;       // have subcommands? 0 or 1
00422     const char* usage;          // text of usage
00423 };
00424 
00425 command cmdList[__COMMAND_LIST_SIZE] = {
00426     {"open",     1, 1,  2,  -1,     0,  "o[pen] host [port]\n"},
00427     {"close",    2, 0,  0,  -1,     0,  NULL},
00428     {"keys",     2, 1,  3,  -1,     1,  "ke[ys] l[oad] keymapname [file]\n"
00429                                         "ke[ys] d[isplay]\n"
00430                                         "ke[ys] s[witch] number\n"},
00431     // Ioannou : i change it to q, to be more compatible with unix telnet
00432     {"quit",     1, 0,  0,  -1,     0,  NULL}, // must type it exactly
00433     {"?",        1, 0,  0,  -1,     0,  NULL},
00434     {"help",     1, 0,  0,  -1,     0,  NULL},
00435     {"load",     1, 1,  2,  KEYS,   0,  NULL},
00436     {"switch",   1, 1,  1,  KEYS,   0,  NULL},
00437     {"display",  1, 0,  0,  KEYS,   0,  NULL},
00438     // Paul Brannan 5/30/98
00439     {"set",      3, 0,  2,  -1,     0,  "set will display available groups.\n"
00440                                         "set groupname will display all variables/values in a group.\n"
00441                                         "set [variable [value]] will set variable to value.\n"},
00442     // Thomas Briggs 8/11/98
00443     {"z",       1,  0,  0,  -1,     0,  "suspend telnet\n"},
00444     {"\04",     1,  0,  0,  -1,     0,  NULL},
00445     // crn@ozemail.com.au
00446     {"history", 2,  0,  0,  -1, 0,  "show command history"},
00447     {"flush",   2,  0,  0,  -1, 0,  "flush history buffer"},
00448     // Paul Brannan 1/1/99
00449     {"aliases", 5,  0,  0,  -1,     0,  NULL}
00450 };
00451 
00452 // a maximal count of parms
00453 #define MAX_PARM_COUNT 3
00454 #define MAX_TOKEN_COUNT (MAX_PARM_COUNT+2)
00455 
00456 static int cmdMatch(const char* cmd, const char* token, int tokenLen, int minM) {
00457     if ( tokenLen < minM ) return 0;
00458     // The (unsigned) gets rid of a compiler warning (Paul Brannan 5/25/98)
00459     if ( (unsigned)tokenLen > strlen(cmd) ) return 0;
00460     if ( strcmp(cmd,token) == 0 ) return 1;
00461 
00462     int i;
00463     for ( i = 0; i < minM; i++ ) if ( cmd[i] != token[i] ) return 0;
00464 
00465     for ( i = minM; i < tokenLen; i++ ) if ( cmd[i] != token[i] ) return 0;
00466 
00467     return 1;
00468 };
00469 
00470 static void printUsage(int cmd) {
00471     if ( cmdList[cmd].usage != NULL ) {
00472         printit(cmdList[cmd].usage);
00473         return;
00474     };
00475     if ( cmdList[cmd].isSubCmd >= 0 ) {
00476         printUsage(cmdList[cmd].isSubCmd);
00477         return;
00478        }
00479        printm(0, FALSE, MSG_BADUSAGE);
00480 };
00481 
00482 int tokenizeCommand(char* szCommand, int& argc, char** argv) {
00483     char* tokens[MAX_TOKEN_COUNT];
00484     char* p;
00485     int   args = 0;
00486 
00487     if(!szCommand || !*szCommand) return EMPTY_LINE;
00488 
00489     // Removed strtok to handle tokens with spaces; this is handled with
00490     // quotes.  (Paul Brannan 3/18/99)
00491     char *token_start = szCommand;
00492     for(p = szCommand;; p++) {
00493         if(*p == '\"') {
00494             char *tmp = p;
00495             for(p++; *p != '\"' && *p != 0; p++);   // Find the next quote
00496             if(*p != 0) strcpy(p, p + 1);           // Remove quote#2
00497             strcpy(tmp, tmp + 1);                   // Remove quote#1
00498         }
00499         if(*p == 0 || *p == ' ' || *p == '\t') {
00500             tokens[args] = token_start;
00501             args++;
00502             if(args >= MAX_TOKEN_COUNT) break;      // Break if too many args
00503             token_start = p + 1;
00504             if(*p == 0) break;
00505             *p = 0;
00506         }
00507     }
00508     // while ( (p = strtok((args?NULL:szCommand), " \t")) != NULL && args < MAX_TOKEN_COUNT ) {
00509     //  tokens[args] = p;
00510     //  args++;
00511     // };
00512 
00513     if ( !args ) return EMPTY_LINE;
00514     argc = args - 1;
00515     args = 0;
00516     int curCmd = -1;
00517     int ok = -1;
00518     while ( ok < 0 ) {
00519         int tokenLen = strlen(tokens[args]);
00520         int match = 0;
00521         for ( int i = 0; i<__COMMAND_LIST_SIZE; i++ ) {
00522             if ( cmdMatch(cmdList[i].cmd, tokens[args], tokenLen, cmdList[i].minLen) ) {
00523                 if (argc < cmdList[i].minParms || argc > cmdList[i].maxParms) {
00524                     printUsage(i);
00525                     return BAD_USAGE;
00526                 };
00527                 if ( cmdList[i].haveSubCmd && curCmd == cmdList[i].isSubCmd) {
00528                     curCmd = i;
00529                     args++;
00530                     argc--;
00531                     match = 1;
00532                     break;
00533                 };
00534                 if ( curCmd == cmdList[i].isSubCmd ) {
00535                     ok = i;
00536                     match = 1;
00537                     break;
00538                 };
00539                 printUsage(i);
00540                 return BAD_USAGE;
00541             };
00542         };
00543         if ( !match ) {
00544             if ( curCmd < 0 ) return INVALID_CMD;
00545             printUsage(curCmd);
00546             return -3;
00547         };
00548     };
00549 
00550     for ( int i = 0; i<argc; i++ ) {
00551         argv[i] = tokens[i+args+1];
00552     };
00553     return ok;
00554 
00555 };
00556 
00557 int telCommandLine (Telnet &MyConnection){
00558 #define HISTLENGTH 25
00559     int i, retval;
00560     char* Parms[MAX_PARM_COUNT];
00561     char szCommand[80];
00562     int bDone = 0;
00563     char *extitle, *newtitle;
00564     struct cmdHistory *cmdhist;
00565     cmdhist = NULL;
00566 
00567     // printit("\n");  // crn@ozemail.com.au 14/12/98
00568     while (!bDone){
00569         // printit("\n"); // Paul Brannan 5/25/98
00570         printit( "telnet>");
00571         cmdhist = cfgets (szCommand, 79, cmdhist);
00572         printit( "\n");
00573 
00574         strlwr(szCommand);  // convert command line to lower
00575         // i = sscanf(szCommand,"%80s %80s %80s %80s", szCmd, szArg1, szArg2, szArg3);
00576         switch ( tokenizeCommand(szCommand, i, Parms) ) {
00577         case BAD_USAGE:   break;
00578         case EMPTY_LINE:
00579             if(MyConnection.Resume() == TNPROMPT) {
00580                 printit("\n");
00581                 break;
00582             }
00583             else
00584                 return 1;
00585         case INVALID_CMD:
00586             printm(0, FALSE, MSG_INVCMD);
00587             break;
00588         case OPEN:
00589             if (i == 1)
00590                 retval = MyConnection.Open(Parms[0], "23");
00591             else
00592                 retval = MyConnection.Open(Parms[0], Parms[1]);
00593             if(retval != TNNOCON && retval != TNPROMPT) return 1;
00594             if(retval == TNPROMPT) printit("\n");
00595             break;
00596         case CLOSE:
00597             MyConnection.Close();
00598             break;
00599         case FASTQUIT: // Thomas Briggs 8/11/98
00600         case QUIT:
00601             MyConnection.Close();
00602             bDone = 1;
00603             break;
00604         case HELP:
00605         case HELP2:
00606             printm(0, FALSE, MSG_HELP);
00607             printm(0, FALSE, MSG_HELP_1);
00608             break;
00609             // case KEYS: we should never get it
00610         case K_LOAD:
00611             if ( i == 1 ) {
00612                 // Ioannou : changed to ini.get_keyfile()
00613                 if(MyConnection.LoadKeyMap( ini.get_keyfile(), Parms[0]) != 1)
00614                     printit("Error loading keymap.\n");
00615                 break;
00616             };
00617             if(MyConnection.LoadKeyMap( Parms[1], Parms[0]) != 1)
00618                 printit("Error loading keymap.\n");
00619             break;
00620         case K_DISPLAY:
00621             MyConnection.DisplayKeyMap();
00622             break;
00623         case K_SWITCH:
00624             MyConnection.SwitchKeyMap(atoi(Parms[0]));
00625             break;
00626 
00627             // Paul Brannan 5/30/98
00628         case SET:
00629             if(i == 0) {
00630                 printit("Available groups:\n");     // Print out groups
00631                 ini.print_groups();                 // (Paul Brannan 9/3/98)
00632             } else if(i == 1) {
00633                 ini.print_vars(Parms[0]);
00634             } else if(i >= 2) {
00635                 ini.set_value(Parms[0], Parms[1]);
00636                 // FIX ME !!! Ioannou: here we must call the parser routine for
00637                 // wrap line, not the ini.set_value
00638                 //  something like Parser.ConLineWrap(Wrap_Line);
00639             }
00640             break;
00641 
00642         case SUSPEND: // Thomas Briggs 8/11/98
00643 
00644             // remind the user we're suspended -crn@ozemail.com.au 15/12/98
00645             extitle = new char[128];
00646             GetConsoleTitle (extitle, 128);
00647 
00648             newtitle = new char[128+sizeof("[suspended]")];
00649             strcpy(newtitle, extitle);
00650             strncat(newtitle, "[suspended]", 128+sizeof("[suspended]"));
00651             if(ini.get_set_title()) SetConsoleTitle (newtitle);
00652             delete[] newtitle;
00653 
00654             if (getenv("comspec") == NULL) {
00655                 switch (GetWin32Version()) {
00656                 case 2:     // 'cmd' is faster than 'command' in NT -crn@ozemail.com.au
00657                     system ("cmd");
00658                     break;
00659                 default:
00660                     system ("command");
00661                     break;
00662                 }
00663             } else {
00664                 system(getenv("comspec"));
00665             }
00666 
00667             if(ini.get_set_title()) SetConsoleTitle (extitle);
00668             delete[] extitle;
00670 
00671             break;
00672 
00673         case CMD_HISTORY:   //crn@ozemail.com.au
00674             if (cmdhist != NULL) {
00675                 while (cmdhist->prev != NULL)
00676                     cmdhist = cmdhist->prev;    //rewind
00677                 printf ("Command history:\n");
00678                 while (1) {
00679                     printf ("\t%s\n", cmdhist->cmd);
00680 
00681                     if (cmdhist->next != NULL)
00682                         cmdhist = cmdhist->next;
00683                     else
00684                         break;
00685                 }
00686             } else
00687                 printf ("No command history available.\n");
00688 
00689             break;
00690 
00691         case CLEAR_HISTORY: //crn@ozemail.com.au
00692             if (cmdhist != NULL) {
00693                 while (cmdhist->next != NULL)
00694                     cmdhist = cmdhist->next;    //fast forward
00695                 while (cmdhist->prev != NULL) {
00696                     cmdhist = cmdhist->prev;
00697                     delete cmdhist->next;
00698                 }
00699                 delete cmdhist;
00700                 cmdhist = NULL;
00701                 printf ("Command history cleared.\n");
00702             } else
00703                 printf ("No command history available.\n");
00704 
00705         case ALIASES: // Paul Brannan 1/1/99
00706             ini.print_aliases();
00707             break;
00708 
00709         default: // paranoik
00710             printm(0, FALSE, MSG_INVCMD);
00711             break;
00712         }
00713 
00714     }
00715 
00716     return 0;
00717 }

Generated on Sun May 27 2012 04:17:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.