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

tnconfig.cpp
Go to the documentation of this file.
00001 
00002 //Telnet Win32 : an ANSI telnet client.
00003 //Copyright (C) 1998-2000 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 
00026 // tnconfig.cpp
00027 // Written by Paul Brannan <pbranna@clemson.edu>
00028 // Last modified August 30, 1998
00029 //
00030 // This is a class designed for use with Brad Johnson's Console Telnet
00031 // see the file tnconfig.h for more information
00032 
00033 #include "precomp.h"
00034 
00035 // Turn off the "forcing value to bool 'true' or 'false'" warning
00036 #ifdef _MSC_VER
00037 #pragma warning(disable: 4800)
00038 #endif
00039 
00040 // This is the ini variable that is used for everybody
00041 TConfig ini;
00042 
00043 TConfig::TConfig() {
00044     // set all default values
00045     startdir[0] = '\0';
00046     keyfile[0] = '\0';
00047     inifile[0] = '\0';
00048     dumpfile[0] = '\0';
00049     term[0] = '\0';
00050     default_config[0] = '\0';
00051     strcpy(printer_name, "LPT1");
00052 
00053     input_redir = 0;
00054     output_redir = 0;
00055     strip_redir = FALSE;
00056 
00057     dstrbksp = FALSE;
00058     eightbit_ansi = FALSE;
00059     vt100_mode = FALSE;
00060     disable_break = FALSE;
00061     speaker_beep = TRUE;
00062     do_beep = TRUE;
00063     preserve_colors = FALSE;
00064     wrapline = TRUE;
00065     lock_linewrap = FALSE;
00066     fast_write = TRUE;
00067     enable_mouse = TRUE;
00068     alt_erase = FALSE;
00069     wide_enable = FALSE;
00070     keyboard_paste = FALSE;
00071     set_title = TRUE;
00072 
00073     blink_bg = -1;
00074     blink_fg = 2;
00075     underline_bg = -1;
00076     underline_fg = 3;
00077     ulblink_bg = -1;
00078     ulblink_fg = 1;
00079     normal_bg = -1;
00080     normal_fg = -1;
00081     scroll_bg = 0;
00082     scroll_fg = 7;
00083     status_bg = 1;
00084     status_fg = 15;
00085 
00086     buffer_size = 2048;
00087 
00088     term_width = -1;
00089     term_height = -1;
00090     window_width = -1;
00091     window_height = -1;
00092 
00093     strcpy(escape_key, "]");
00094     strcpy(scrollback_key, "[");
00095     strcpy(dial_key, "\\");
00096     strcpy(default_config, "ANSI");
00097     strcpy(term, "ansi");
00098 
00099     strcpy(scroll_mode, "DUMP");
00100     scroll_size=32000;
00101     scroll_enable=TRUE;
00102 
00103     host[0] = '\0';
00104     port = "23";
00105 
00106     init_varlist();
00107 
00108     aliases = NULL;
00109 }
00110 
00111 TConfig::~TConfig() {
00112     if(aliases) {
00113         for(int j = 0; j < alias_total; j++) delete[] aliases[j];
00114         delete[] aliases;
00115     }
00116 }
00117 
00118 enum ini_data_type {
00119     INI_STRING,
00120     INI_INT,
00121     INI_BOOL
00122 };
00123 
00124 enum {
00125     INIFILE,
00126     KEYFILE,
00127     DUMPFILE,
00128     DEFAULT_CONFIG,
00129     TERM,
00130     INPUT_REDIR,
00131     OUTPUT_REDIR,
00132     STRIP_REDIR,
00133     DSTRBKSP,
00134     EIGHTBIT_ANSI,
00135     VT100_MODE,
00136     DISABLE_BREAK,
00137     SPEAKER_BEEP,
00138     DO_BEEP,
00139     PRESERVE_COLORS,
00140     WRAP_LINE,
00141     LOCK_LINEWRAP,
00142     FAST_WRITE,
00143     TERM_WIDTH,
00144     TERM_HEIGHT,
00145     WINDOW_WIDTH,
00146     WINDOW_HEIGHT,
00147     WIDE_ENABLE,
00148     CTRLBREAK_AS_CTRLC,
00149     BUFFER_SIZE,
00150     SET_TITLE,
00151     BLINK_BG,
00152     BLINK_FG,
00153     UNDERLINE_BG,
00154     UNDERLINE_FG,
00155     ULBLINK_BG,
00156     ULBLINK_FG,
00157     NORMAL_BG,
00158     NORMAL_FG,
00159     SCROLL_BG,
00160     SCROLL_FG,
00161     STATUS_BG,
00162     STATUS_FG,
00163     PRINTER_NAME,
00164     ENABLE_MOUSE,
00165     ESCAPE_KEY,
00166     SCROLLBACK_KEY,
00167     DIAL_KEY,
00168     ALT_ERASE,
00169     KEYBOARD_PASTE,
00170     SCROLL_MODE,
00171     SCROLL_SIZE,
00172     SCROLL_ENABLE,
00173     SCRIPTNAME,
00174     SCRIPT_ENABLE,
00175     NETPIPE,
00176     IOPIPE,
00177 
00178     MAX_INI_VARS            // must be last
00179 };
00180 
00181 struct ini_variable {
00182     const char *name;               // variable name
00183     const char *section;            // name of ini file section the variable is in
00184     enum ini_data_type data_type;       // type of data
00185     void *ini_data;         // pointer to data
00186     int  max_size;          // max size if string
00187 };
00188 
00189 // Note: default values are set in the constructor, TConfig()
00190 ini_variable ini_varlist[MAX_INI_VARS];
00191 
00192 enum {
00193     KEYBOARD,
00194     TERMINAL,
00195     COLORS,
00196     MOUSE,
00197     PRINTER,
00198     SCROLLBACK,
00199     SCRIPTING,
00200     PIPES,
00201 
00202     MAX_INI_GROUPS                      // Must be last
00203 };
00204 
00205 char *ini_groups[MAX_INI_GROUPS];
00206 
00207 void TConfig::init_varlist() {
00208     static const ini_variable static_ini_varlist[MAX_INI_VARS] = {
00209         {"Inifile",     NULL,           INI_STRING,     &inifile,   sizeof(inifile)},
00210         {"Keyfile",     "Keyboard",     INI_STRING,     &keyfile,   sizeof(keyfile)},
00211         {"Dumpfile",    "Terminal",     INI_STRING,     &dumpfile,  sizeof(dumpfile)},
00212         {"Default_Config","Keyboard",   INI_STRING,     &default_config, sizeof(default_config)},
00213         {"Term",        "Terminal",     INI_STRING,     &term,      sizeof(term)},
00214         {"Input_Redir", "Terminal",     INI_INT,        &input_redir, 0},
00215         {"Output_Redir","Terminal",     INI_INT,        &output_redir, 0},
00216         {"Strip_Redir", "Terminal",     INI_BOOL,       &strip_redir, 0},
00217         {"Destructive_Backspace","Terminal",INI_BOOL,   &dstrbksp, 0},
00218         {"EightBit_Ansi","Terminal",    INI_BOOL,       &eightbit_ansi, 0},
00219         {"VT100_Mode",  "Terminal",     INI_BOOL,       &vt100_mode, 0},
00220         {"Disable_Break","Terminal",    INI_BOOL,       &disable_break, 0},
00221         {"Speaker_Beep","Terminal",     INI_BOOL,       &speaker_beep, 0},
00222         {"Beep",        "Terminal",     INI_BOOL,       &do_beep, 0},
00223         {"Preserve_Colors","Terminal",  INI_BOOL,       &preserve_colors, 0},
00224         {"Wrap_Line",   "Terminal",     INI_BOOL,       &wrapline, 0},
00225         {"Lock_linewrap","Terminal",    INI_BOOL,       &lock_linewrap, 0},
00226         {"Fast_Write",  "Terminal",     INI_BOOL,       &fast_write, 0},
00227         {"Term_Width",  "Terminal",     INI_INT,        &term_width, 0},
00228         {"Term_Height", "Terminal",     INI_INT,        &term_height, 0},
00229         {"Window_Width","Terminal",     INI_INT,        &window_width, 0},
00230         {"Window_Height","Terminal",    INI_INT,        &window_height, 0},
00231         {"Wide_Enable", "Terminal",     INI_BOOL,       &wide_enable, 0},
00232         {"Ctrlbreak_as_Ctrlc","Keyboard", INI_BOOL,     &ctrlbreak_as_ctrlc, 0},
00233         {"Buffer_Size", "Terminal",     INI_INT,        &buffer_size, 0},
00234         {"Set_Title",   "Terminal",     INI_BOOL,       &set_title, 0},
00235         {"Blink_bg",    "Colors",       INI_INT,        &blink_bg, 0},
00236         {"Blink_fg",    "Colors",       INI_INT,        &blink_fg, 0},
00237         {"Underline_bg","Colors",       INI_INT,        &underline_bg, 0},
00238         {"Underline_fg","Colors",       INI_INT,        &underline_fg, 0},
00239         {"UlBlink_bg",  "Colors",       INI_INT,        &ulblink_bg, 0},
00240         {"UlBlink_fg",  "Colors",       INI_INT,        &ulblink_fg, 0},
00241         {"Normal_bg",   "Colors",       INI_INT,        &normal_bg, 0},
00242         {"Normal_fg",   "Colors",       INI_INT,        &normal_fg, 0},
00243         {"Scroll_bg",   "Colors",       INI_INT,        &scroll_bg, 0},
00244         {"Scroll_fg",   "Colors",       INI_INT,        &scroll_fg, 0},
00245         {"Status_bg",   "Colors",       INI_INT,        &status_bg, 0},
00246         {"Status_fg",   "Colors",       INI_INT,        &status_fg, 0},
00247         {"Enable_Mouse","Mouse",        INI_BOOL,       &enable_mouse, 0},
00248         {"Printer_Name","Printer",      INI_STRING,     &printer_name, sizeof(printer_name)},
00249         {"Escape_Key",  "Keyboard",     INI_STRING,     &escape_key, 1},
00250         {"Scrollback_Key","Keyboard",   INI_STRING,     &scrollback_key, 1},
00251         {"Dial_Key",    "Keyboard",     INI_STRING,     &dial_key, 1},
00252         {"Alt_Erase",   "Keyboard",     INI_BOOL,       &alt_erase, 0},
00253         {"Keyboard_Paste","Keyboard",   INI_BOOL,       &keyboard_paste, 0},
00254         {"Scroll_Mode", "Scrollback",   INI_STRING,     &scroll_mode, sizeof(scroll_mode)},
00255         {"Scroll_Size", "Scrollback",   INI_INT,        &scroll_size, 0},
00256         {"Scroll_Enable","Scrollback",  INI_BOOL,       &scroll_enable, 0},
00257         {"Scriptname",  "Scripting",    INI_STRING,     &scriptname, sizeof(scriptname)},
00258         {"Script_enable","Scripting",   INI_BOOL,       &script_enable, 0},
00259         {"Netpipe",     "Pipes",        INI_STRING,     &netpipe, sizeof(netpipe)},
00260         {"Iopipe",      "Pipes",        INI_STRING,     &iopipe, sizeof(iopipe)}
00261     };
00262 
00263     static const char *static_ini_groups[MAX_INI_GROUPS] = {
00264         "Keyboard",
00265         "Terminal",
00266         "Colors",
00267         "Mouse",
00268         "Printer",
00269         "Scrollback",
00270         "Scripting",
00271         "Pipes"
00272     };
00273 
00274     memcpy(ini_varlist, static_ini_varlist, sizeof(ini_varlist));
00275     memcpy(ini_groups, static_ini_groups, sizeof(ini_groups));
00276 }
00277 
00278 void TConfig::init(char *dirname, char *execname) {
00279     // Copy temporary dirname to permanent startdir
00280     strncpy(startdir, dirname, sizeof(startdir));
00281     startdir[sizeof(startdir) - 1] = 0;
00282 
00283     // Copy temp execname to permanent exename (Thomas Briggs 12/7/98)
00284     strncpy(exename, execname, sizeof(exename));
00285     exename[sizeof(exename) - 1] = 0;
00286 
00287     // Initialize INI file
00288     inifile_init();
00289 
00290     // Initialize redir
00291     // Note that this must be done early, so error messages will be printed
00292     // properly
00293     redir_init();
00294 
00295     // Initialize aliases (Paul Brannan 1/1/99)
00296     init_aliases();
00297 
00298     // Make sure the file that we're trying to work with exists
00299     int iResult = access(inifile, 04);
00300 
00301     // Thomas Briggs 9/14/98
00302     if( iResult == 0 )
00303         // Tell the user what file we are reading
00304         // We cannot print any messages before initializing telnet_redir
00305         printm(0, FALSE, MSG_CONFIG, inifile);
00306     else
00307         // Tell the user that the file doesn't exist, but later read the
00308         // file anyway simply to populate the defaults
00309         printm(0, FALSE, MSG_NOINI, inifile);
00310 
00311     init_vars();                                // Initialize misc. vars
00312     keyfile_init();                             // Initialize keyfile
00313 }
00314 
00315 // Alias support (Paul Brannan 1/1/99)
00316 void TConfig::init_aliases() {
00317     char *buffer;
00318     alias_total = 0;
00319 
00320     // Find the correct buffer size
00321     // FIX ME!! some implementations of Mingw32 don't have a
00322     // GetPrivateProfileSecionNames function.  What do we do about this?
00323 #ifndef __MINGW32__
00324     {
00325         int size=1024, Result = 0;
00326         for(;;) {
00327             buffer = new char[size];
00328             Result = GetPrivateProfileSectionNames(buffer, size, inifile);
00329             if(Result < size - 2) break;
00330             size *= 2;
00331             delete[] buffer;
00332         }
00333     }
00334 #else
00335     return;
00336 #endif
00337 
00338     // Find the maximum number of aliases
00339     int max = 0;
00340     char *tmp;
00341     for(tmp = buffer; *tmp != 0; tmp += strlen(tmp) + 1)
00342         max++;
00343 
00344     aliases = new char*[max];
00345 
00346     // Load the aliases into an array
00347     for(tmp = buffer; *tmp != 0; tmp += strlen(tmp) + 1) {
00348         int flag = 0;
00349         for(int j = 0; j < MAX_INI_GROUPS; j++) {
00350             if(!stricmp(ini_groups[j], tmp)) flag = 1;
00351         }
00352         if(!flag) {
00353             aliases[alias_total] = new char[strlen(tmp)+1];
00354             strcpy(aliases[alias_total], tmp);
00355             alias_total++;
00356         }
00357     }
00358 
00359     delete[] buffer;
00360 }
00361 
00362 void TConfig::print_aliases() {
00363     for(int j = 0; j < alias_total; j++) {
00364         char alias_name[20];
00365         set_string(alias_name, aliases[j], sizeof(alias_name));
00366         for(unsigned int i = strlen(alias_name); i < sizeof(alias_name) - 1; i++)
00367             alias_name[i] = ' ';
00368         alias_name[sizeof(alias_name) - 1] = 0;
00369         printit(alias_name);
00370         if((j % 4) == 3) printit("\n");
00371     }
00372     printit("\n");
00373 }
00374 
00375 bool find_alias(const char *alias_name) {
00376     return false;
00377 }
00378 
00379 void TConfig::print_vars() {
00380     int j;
00381     for(j = 0; j < MAX_INI_VARS; j++) {
00382         if(print_value(ini_varlist[j].name) > 40) printit("\n");
00383         else if(j % 2) printit("\n");
00384         else printit("\t");
00385     }
00386     if(j % 2) printit("\n");
00387 }
00388 
00389 // Paul Brannan 9/3/98
00390 void TConfig::print_vars(char *s) {
00391     if(!strnicmp(s, "all", 3)) {                    // Print out all vars
00392         print_vars();
00393         return;
00394     }
00395 
00396     // See if the group exists
00397     int j;
00398     for(j = 0; j < MAX_INI_GROUPS; j++)
00399         if(!stricmp(ini_groups[j], s)) break;
00400     // If not, print out the value of the variable by that name
00401     if(j == MAX_INI_GROUPS) {
00402         print_value(s);
00403         printit("\n");
00404         return;
00405     }
00406 
00407     // Print out the vars in the given group
00408     int count = 0;
00409     for(j = 0; j < MAX_INI_VARS; j++) {
00410         if(ini_varlist[j].section == NULL) continue;
00411         if(!stricmp(ini_varlist[j].section, s)) {
00412             if(print_value(ini_varlist[j].name) > 40) printit("\n");
00413             else if(count % 2) printit("\n");
00414             else printit("\t");
00415             count++;
00416         }
00417     }
00418     if(count % 2) printit("\n");
00419 }
00420 
00421 // Paul Brannan 9/3/98
00422 void TConfig::print_groups() {
00423     for(int j = 0; j < MAX_INI_GROUPS; j++) {
00424         char group_name[20];
00425         set_string(group_name, ini_groups[j], sizeof(group_name));
00426         for(unsigned int i = strlen(group_name); i < sizeof(group_name) - 1; i++)
00427             group_name[i] = ' ';
00428         group_name[sizeof(group_name) - 1] = 0;
00429         printit(group_name);
00430         if((j % 4) == 3) printit("\n");
00431     }
00432     printit("\n");
00433 }
00434 
00435 // Ioannou : The index in the while causes segfaults if there is no match
00436 // changes to for(), and strcmp to stricmp (prompt gives rong names)
00437 
00438 bool TConfig::set_value(const char *var, const char *value) {
00439    //int j = 0;
00440    //while(strcmp(var, ini_varlist[j].name) && j < MAX_INI_VARS) j++;
00441    for (int j = 0; j < MAX_INI_VARS; j++)
00442    {
00443       if (stricmp(var, ini_varlist[j].name) == 0)
00444       {
00445          switch(ini_varlist[j].data_type) {
00446             case INI_STRING:
00447                set_string((char *)ini_varlist[j].ini_data, value,
00448                   ini_varlist[j].max_size);
00449                break;
00450             case INI_INT:
00451                *(int *)ini_varlist[j].ini_data = atoi(value);
00452                break;
00453             case INI_BOOL:
00454                set_bool((bool *)ini_varlist[j].ini_data, value);
00455                break;
00456          }
00457          // j = MAX_INI_VARS;
00458          return TRUE;
00459       }
00460    }
00461    return FALSE;
00462 }
00463 
00464 int TConfig::print_value(const char *var) {
00465     //int j = 0;
00466     //while(strcmp(var, ini_varlist[j].name) && j < MAX_INI_VARS) j++;
00467     int Result = 0;
00468     for (int j = 0; j < MAX_INI_VARS; j++)
00469     {
00470         if (stricmp(var, ini_varlist[j].name) == 0)
00471         {
00472             char var_name[25];
00473             set_string(var_name, var, sizeof(var_name));
00474             for(unsigned int i = strlen(var_name); i < sizeof(var_name) - 1; i++)
00475                 var_name[i] = ' ';
00476             var_name[sizeof(var_name) - 1] = 0;
00477             Result = sizeof(var_name);
00478 
00479             printit(var_name);
00480             printit("\t");
00481             Result = Result / 8 + 8;
00482 
00483             switch(ini_varlist[j].data_type) {
00484             case INI_STRING:
00485                 printit((char *)ini_varlist[j].ini_data);
00486                 Result += strlen((char *)ini_varlist[j].ini_data);
00487                 break;
00488             case INI_INT:
00489                 char buffer[20]; // this may not be safe
00490                 // Ioannou : Paul this was _itoa, but Borland needs itoa !!
00491                 itoa(*(int *)ini_varlist[j].ini_data, buffer, 10);
00492                 printit(buffer);
00493                 Result += strlen(buffer);
00494                 break;
00495             case INI_BOOL:
00496                 if(*(bool *)ini_varlist[j].ini_data == true) {
00497                     printit("on");
00498                     Result += 2;
00499                 } else {
00500                     printit("off");
00501                     Result += 3;
00502                 }
00503             }
00504             // printit("\n");
00505             j = MAX_INI_VARS;
00506         }
00507     }
00508     return Result;
00509 }
00510 
00511 void TConfig::init_vars() {
00512     char buffer[4096];
00513     for(int j = 0; j < MAX_INI_VARS; j++) {
00514         if(ini_varlist[j].section != NULL) {
00515             GetPrivateProfileString(ini_varlist[j].section, ini_varlist[j].name, "",
00516                 buffer, sizeof(buffer), inifile);
00517             if(*buffer != 0) set_value(ini_varlist[j].name, buffer);
00518         }
00519     }
00520 }
00521 
00522 void TConfig::inifile_init() {
00523     // B. K. Oxley 9/16/98
00524     char* env_telnet_ini = getenv (ENV_TELNET_INI);
00525     if (env_telnet_ini && *env_telnet_ini) {
00526         strncpy (inifile, env_telnet_ini, sizeof(inifile));
00527         return;
00528     }
00529 
00530     strcpy(inifile, startdir);
00531     if (sizeof(inifile) >= strlen(inifile)+strlen("telnet.ini")) {
00532         strcat(inifile,"telnet.ini"); // add the default filename to the path
00533     } else {
00534         // if there is not enough room set the path to nothing
00535         strcpy(inifile,"");
00536     }
00537 }
00538 
00539 void TConfig::keyfile_init() {
00540     // check to see if there is a key config file environment variable.
00541     char *k;
00542     if ((k = getenv(ENV_TELNET_CFG)) == NULL){
00543         // if there is no environment variable
00544         GetPrivateProfileString("Keyboard", "Keyfile", "", keyfile,
00545             sizeof(keyfile), inifile);
00546         if(keyfile == 0 || *keyfile == 0) {
00547             // and there is no profile string
00548             strcpy(keyfile, startdir);
00549             if (sizeof(keyfile) >= strlen(keyfile)+strlen("telnet.cfg")) {
00550                 struct stat buf;
00551 
00552                 strcat(keyfile,"telnet.cfg"); // add the default filename to the path
00553                 if(stat(keyfile, &buf) != 0) {
00554                     char *s = keyfile + strlen(keyfile) - strlen("telnet.cfg");
00555                     strcpy(s, "keys.cfg");
00556                 }
00557             } else {
00558                 // if there is not enough room set the path to nothing
00559                 strcpy(keyfile,"");
00560             }
00561 
00562         // Vassili Bourdo (vassili_bourdo@softhome.net)
00563         } else {
00564             // check that keyfile really exists
00565             if( access(keyfile,04) == -1 ) {
00566                 //it does not...
00567                 char pathbuf[MAX_PATH], *fn;
00568                 //substitute keyfile path with startdir path
00569                 if((fn = strrchr(keyfile,'\\'))) strcpy(keyfile,fn);
00570                     strcat(strcpy(pathbuf,startdir),keyfile);
00571                 //check that startdir\keyfile does exist
00572                 if( access(pathbuf,04) == -1 ) {
00573                     //it does not...
00574                     //so, look for it in all paths
00575                     _searchenv(keyfile, "PATH", pathbuf);
00576                     if( *pathbuf == 0 ) //no luck - revert it to INI file value
00577                         GetPrivateProfileString("Keyboard", "Keyfile", "",
00578                             keyfile, sizeof(keyfile), inifile);
00579                 } else {
00580                     strcpy(keyfile, pathbuf);
00581                 }
00582             }
00583         }
00585 
00586     } else {
00587         // set the keyfile to the value of the environment variable
00588         strncpy(keyfile, k, sizeof(keyfile));
00589     }
00590 }
00591 
00592 void TConfig::redir_init() {
00593     // check to see if the environment variable 'TELNET_REDIR' is not 0;
00594     char* p = getenv(ENV_TELNET_REDIR);
00595     if (p) {
00596         input_redir = output_redir = atoi(p);
00597         if((p = getenv(ENV_INPUT_REDIR))) input_redir = atoi(p);
00598         if((p = getenv(ENV_OUTPUT_REDIR))) output_redir = atoi(p);
00599     } else {
00600         input_redir = output_redir = GetPrivateProfileInt("Terminal",
00601             "Telnet_Redir", 0, inifile);
00602         input_redir = GetPrivateProfileInt("Terminal",
00603             "Input_Redir", input_redir, inifile);
00604         output_redir = GetPrivateProfileInt("Terminal",
00605             "Output_Redir", output_redir, inifile);
00606     }
00607     if ((input_redir > 1) || (output_redir > 1))
00608         setlocale(LC_CTYPE,"");
00609     // tell isprint() to not ignore local characters, if the environment
00610     // variable "LANG" has a valid value (e.g. LANG=de for german characters)
00611     // and the file LOCALE.BLL is installed somewhere along the PATH.
00612 }
00613 
00614 // Modified not to use getopt() by Paul Brannan 12/17/98
00615 bool TConfig::Process_Params(int argc, char *argv[]) {
00616     int optind = 1;
00617     char *optarg = argv[optind];
00618     char c;
00619 
00620     while(optind < argc) {
00621         if(argv[optind][0] != '-') break;
00622 
00623         // getopt
00624         c = argv[optind][1];
00625         if(argv[optind][2] == 0)
00626             optarg = argv[++optind];
00627         else
00628             optarg = &argv[optind][2];
00629         optind++;
00630 
00631         switch(c) {
00632             case 'd':
00633                 set_string(dumpfile, optarg, sizeof(dumpfile));
00634                 printm(0, FALSE, MSG_DUMPFILE, dumpfile);
00635                 break;
00636             // added support for setting options on the command-line
00637             // (Paul Brannan 7/31/98)
00638             case '-':
00639                 {
00640                     int j;
00641                     for(j = 0; optarg[j] != ' ' && optarg[j] != '=' && optarg[j] != 0; j++);
00642                     if(optarg == 0) {
00643                         printm(0, FALSE, MSG_USAGE);        // print a usage message
00644                         printm(0, FALSE, MSG_USAGE_1);
00645                         return FALSE;
00646                     }
00647                     optarg[j] = 0;
00648                     if(!set_value(optarg, &optarg[j+1]))
00649                         printm(0, FALSE, MSG_BADVAL, optarg);
00650                 }
00651                 break;
00652             default:
00653                 printm(0, FALSE, MSG_USAGE);        // print a usage message
00654                 printm(0, FALSE, MSG_USAGE_1);
00655                 return FALSE;
00656         }
00657     }
00658     if(optind < argc)
00659         set_string(host, argv[optind++], sizeof(host)-1);
00660     if(!strnicmp(host, "telnet://", 9)) {
00661         // we have a URL to parse
00662         char *s, *t;
00663 
00664         for(s = host+9, t = host; *s != 0; *(t++) = *(s++));
00665         *t = 0;
00666         for(s = host; *s != ':' && *s != 0; s++);
00667         if(*s != 0) {
00668             *(s++) = 0;
00669             port = s;
00670         }
00671     }
00672     if(optind < argc)
00673         port = argv[optind++];
00674 
00675     return TRUE;
00676 }
00677 
00678 void TConfig::set_string(char *dest, const char *src, const int length) {
00679    int l = length;
00680    strncpy(dest, src, l);
00681  //  dest[length-1] = '\0';
00682  // Ioannou : this messes strings - is this really needed ?
00683  // The target string, dest, might not be null-terminated
00684  // if the length of src is length or more.
00685  // it should be dest[length] = '\0' for strings with length 1
00686  // (Escape_string etc), but doesn't work with others (like host).
00687  // dest is long enough to avoid this in all the tested cases
00688 }
00689 
00690 // Ioannou : ignore case for true or on
00691 
00692 void TConfig::set_bool(bool *boolval, const char *str) {
00693    if(!stricmp(str, "true")) *boolval = true;
00694    else if(!stricmp(str, "on")) *boolval = true;
00695     else *boolval = (bool)atoi(str);
00696 }
00697 

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.