00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 00037 #ifdef USE_PCH 00038 #include "be_com_pch.h" 00039 #endif /* USE_PCH */ 00040 #pragma hdrstop 00041 #include <sys/types.h> 00042 #if defined(BUILD_OS_DARWIN) 00043 #include "darwin_elf.h" 00044 #else /* defined(BUILD_OS_DARWIN) */ 00045 #include <elf.h> 00046 #endif /* defined(BUILD_OS_DARWIN) */ 00047 #include <ctype.h> 00048 #include "wn.h" 00049 #include <stdio.h> 00050 #include "wb_buffer.h" 00051 00052 WB_BUFFER WB_buffer; 00053 00054 //----------------------------------------------------------------------- 00055 // NAME: WB_BUFFER::Load_Buffer 00056 // FUNCTION: Load the '_buffer' up to the next newline character with 00057 // input from 'stdin'. 00058 //----------------------------------------------------------------------- 00059 00060 void WB_BUFFER::Load_Buffer() 00061 { 00062 INT i; 00063 for (i = 0; ; i++) { 00064 _buffer[i] = fgetc(stdin); 00065 if (_buffer[i] == '\n') 00066 break; 00067 } 00068 _buffer_start = 0; 00069 } 00070 00071 //----------------------------------------------------------------------- 00072 // NAME: WB_BUFFER::Load_Buffer 00073 // FUNCTION: Load the '_buffer' up to the next newline character with 00074 // input from 'stdin'. 00075 //----------------------------------------------------------------------- 00076 00077 void WB_BUFFER::Load_Buffer(const char s[]) 00078 { 00079 INT i; 00080 for (i = 0; s[i] != '\0'; i++) { 00081 _buffer[i] = s[i]; 00082 } 00083 _buffer[i] = '\n'; 00084 _buffer_start = 0; 00085 } 00086 00087 //----------------------------------------------------------------------- 00088 // NAME: WB_BUFFER::Scan_Blanks_And_Tabs 00089 // FUNCTION: In the '_buffer' advance '_buffer_start' past all blanks and 00090 // tabs. 00091 //----------------------------------------------------------------------- 00092 00093 void WB_BUFFER::Scan_Blanks_And_Tabs() 00094 { 00095 char ch; 00096 do { 00097 ch = _buffer[_buffer_start++]; 00098 } while (ch == ' ' || ch == '\t'); 00099 _buffer_start--; 00100 } 00101 00102 //----------------------------------------------------------------------- 00103 // NAME: WB_BUFFER::Skip_To_Separator 00104 // FUNCTION: In the '_buffer' advance '_buffer_start' past all blanks and 00105 // tabs. 00106 //----------------------------------------------------------------------- 00107 00108 void WB_BUFFER::Skip_To_Separator(WB_SKIP_CLASS skip_type) 00109 { 00110 switch (skip_type) { 00111 case WB_SKIP_ALPHANUMERIC: 00112 while (_buffer[_buffer_start] != ' ' && _buffer[_buffer_start] != '\t' 00113 && _buffer[_buffer_start] != ';' && _buffer[_buffer_start] != '\n') 00114 _buffer_start++; 00115 break; 00116 case WB_SKIP_NUMERIC: 00117 while (isdigit(_buffer[_buffer_start])) 00118 _buffer_start++; 00119 break; 00120 case WB_SKIP_HEX: 00121 while (isxdigit(_buffer[_buffer_start])) 00122 _buffer_start++; 00123 break; 00124 default: 00125 while (_buffer[_buffer_start] != ' ' && _buffer[_buffer_start] != '\t' 00126 && _buffer[_buffer_start] != ';' && _buffer[_buffer_start] != '\n') 00127 _buffer_start++; 00128 } 00129 if (_buffer[_buffer_start] == '\n') 00130 return; 00131 while (_buffer[_buffer_start] == ' ' || _buffer[_buffer_start] == '\t' 00132 || _buffer[_buffer_start] == ';') 00133 _buffer_start++; 00134 } 00135 00136 //----------------------------------------------------------------------- 00137 // NAME: WB_BUFFER::Load_Loop 00138 // FUNCTION: Query the user for a loop and place the result at '*wn_loop'. 00139 //----------------------------------------------------------------------- 00140 00141 void WB_BUFFER::Load_Loop(WN** wn_loop) 00142 { 00143 Load_Buffer(); 00144 Scan_Blanks_And_Tabs(); 00145 sscanf(_buffer + _buffer_start, "0x%p", wn_loop); 00146 _buffer_start += 2; 00147 Skip_To_Separator(WB_SKIP_HEX); 00148 } 00149 00150 //----------------------------------------------------------------------- 00151 // NAME: WB_BUFFER::Load_UINT32 00152 // FUNCTION: Query the user for an UINT32 and place the result at '*int_value'. 00153 //----------------------------------------------------------------------- 00154 00155 void WB_BUFFER::Load_UINT32(UINT32* int_value) 00156 { 00157 Load_Buffer(); 00158 Scan_Blanks_And_Tabs(); 00159 sscanf(_buffer + _buffer_start, "%d", int_value); 00160 Skip_To_Separator(WB_SKIP_NUMERIC); 00161 } 00162 00163 //----------------------------------------------------------------------- 00164 // NAME: WB_BUFFER::Load_mINT32 00165 // FUNCTION: Query the user for a mINT32 and place the result at '*value'. 00166 //----------------------------------------------------------------------- 00167 00168 void WB_BUFFER::Load_mINT32(mINT32* value) 00169 { 00170 Load_Buffer(); 00171 Scan_Blanks_And_Tabs(); 00172 sscanf(_buffer + _buffer_start, "%d", value); 00173 Skip_To_Separator(WB_SKIP_NUMERIC); 00174 } 00175 00176 //----------------------------------------------------------------------- 00177 // NAME: WB_BUFFER::Load_mINT64 00178 // FUNCTION: Query the user for a mINT64 and place the result at '*value'. 00179 //----------------------------------------------------------------------- 00180 00181 void WB_BUFFER::Load_mINT64(mINT64* value) 00182 { 00183 Load_Buffer(); 00184 Scan_Blanks_And_Tabs(); 00185 sscanf(_buffer + _buffer_start, "%lld", value); 00186 Skip_To_Separator(WB_SKIP_NUMERIC); 00187 } 00188 00189 //----------------------------------------------------------------------- 00190 // NAME: WB_BUFFER::Skip_Chars 00191 // FUNCTION: Skip adhead in the '_buffer' 'count' characters. 00192 //----------------------------------------------------------------------- 00193 00194 void WB_BUFFER::Skip_Chars(INT count) 00195 { 00196 _buffer_start += count; 00197 } 00198 00199 //----------------------------------------------------------------------- 00200 // NAME: WB_BUFFER::Scan_Integer 00201 // FUNCTION: Scan for an Integer and place the result at '*int_value'. 00202 //----------------------------------------------------------------------- 00203 00204 void WB_BUFFER::Scan_Integer(INT* int_value) 00205 { 00206 Scan_Blanks_And_Tabs(); 00207 sscanf(_buffer + _buffer_start, "%d", int_value); 00208 Skip_To_Separator(WB_SKIP_NUMERIC); 00209 } 00210 00211 //----------------------------------------------------------------------- 00212 // NAME: WB_BUFFER::Scan_Unsigned 00213 // FUNCTION: Scan for an unsigned and place the result at '*int_value'. 00214 //----------------------------------------------------------------------- 00215 00216 void WB_BUFFER::Scan_Unsigned(UINT32* int_value) 00217 { 00218 Scan_Blanks_And_Tabs(); 00219 sscanf(_buffer + _buffer_start, "%d", int_value); 00220 Skip_To_Separator(WB_SKIP_NUMERIC); 00221 } 00222 00223 //----------------------------------------------------------------------- 00224 // NAME: WB_BUFFER::Scan_HexInteger 00225 // FUNCTION: Scan for an Integer and place the result at '*int_value'. 00226 //----------------------------------------------------------------------- 00227 00228 void WB_BUFFER::Scan_HexInteger(INT* int_value) 00229 { 00230 Scan_Blanks_And_Tabs(); 00231 sscanf(_buffer + _buffer_start, "0x%x", int_value); 00232 _buffer_start += 2; 00233 Skip_To_Separator(WB_SKIP_HEX); 00234 } 00235 00236 //----------------------------------------------------------------------- 00237 // NAME: WB_BUFFER::Scan_Alphanumeric 00238 // FUNCTION: Scan for an alphanumeric string and place the result in 's'. 00239 //----------------------------------------------------------------------- 00240 00241 void WB_BUFFER::Scan_Alphanumeric(char s[]) 00242 { 00243 Scan_Blanks_And_Tabs(); 00244 sscanf(_buffer + _buffer_start, "%s", s); 00245 INT i; 00246 for (i = 0; s[i] != '\0'; i++) 00247 if (s[i] == '\n' || s[i] == ';') 00248 break; 00249 s[i] = '\0'; 00250 Skip_To_Separator(WB_SKIP_ALPHANUMERIC); 00251 } 00252 00253 //----------------------------------------------------------------------- 00254 // NAME: WB_BUFFER::Scan_Character 00255 // FUNCTION: Scan and return the next character. 00256 //----------------------------------------------------------------------- 00257 00258 char WB_BUFFER::Scan_Character() 00259 { 00260 char ch = _buffer[_buffer_start++]; 00261 return ch; 00262 } 00263 00264 //----------------------------------------------------------------------- 00265 // NAME: WB_BUFFER::Pushback_Character 00266 // FUNCTION: Retract the start pointer, effectively pushing back the last 00267 // last character read out of the buffer. 00268 //----------------------------------------------------------------------- 00269 00270 void WB_BUFFER::Pushback_Character() 00271 { 00272 _buffer_start--; 00273 } 00274 00275 //----------------------------------------------------------------------- 00276 // NAME: WB_BUFFER::Load_Integer 00277 // FUNCTION: Query the user for an Integer and place the result at '*int_value'.//----------------------------------------------------------------------- 00278 00279 void WB_BUFFER::Load_Integer(INT* int_value) 00280 { 00281 Load_Buffer(); 00282 Scan_Blanks_And_Tabs(); 00283 sscanf(_buffer + _buffer_start, "%d", int_value); 00284 Skip_To_Separator(WB_SKIP_NUMERIC); 00285 } 00286 00287 //----------------------------------------------------------------------- 00288 // NAME: WB_BUFFER::Load_Double 00289 // FUNCTION: Query the user for a Double and place the result at '*value'. 00290 //----------------------------------------------------------------------- 00291 00292 void WB_BUFFER::Load_Double(double* value) 00293 { 00294 Load_Buffer(); 00295 Scan_Blanks_And_Tabs(); 00296 sscanf(_buffer + _buffer_start, "%lg", value); 00297 Skip_To_Separator(WB_SKIP_NUMERIC); 00298 } 00299 00300 //----------------------------------------------------------------------- 00301 // NAME: WB_BUFFER::Load_Boolean 00302 // FUNCTION: Query the user for a boolean value, and place the result at 00303 // 'bool_value'. If 'default_present' is TRUE, a default value (either 00304 // 'Y' or 'N' should be assumed, even when the user gives no response. 00305 // When 'default_present' is TRUE, 'default_value' should be set to TRUE 00306 // if the assumed default value is 'TRUE', and to 'FALSE' if the assumed 00307 // value is FALSE. 00308 //----------------------------------------------------------------------- 00309 00310 void WB_BUFFER::Load_Boolean(BOOL* bool_value, 00311 BOOL default_present, 00312 BOOL default_value) 00313 { 00314 Load_Buffer(); 00315 Scan_Blanks_And_Tabs(); 00316 if (!default_present) { 00317 if (_buffer[_buffer_start] == 'Y' || _buffer[_buffer_start] == 'y') 00318 *bool_value = TRUE; 00319 if (_buffer[_buffer_start] == 'N' || _buffer[_buffer_start] == 'n') 00320 *bool_value = FALSE; 00321 return; 00322 } 00323 if (default_value == TRUE) { 00324 *bool_value = TRUE; 00325 if (_buffer[_buffer_start] == 'N' || _buffer[_buffer_start] == 'n') 00326 *bool_value = FALSE; 00327 } else { 00328 *bool_value = FALSE; 00329 if (_buffer[_buffer_start] == 'Y' || _buffer[_buffer_start] == 'y') 00330 *bool_value = TRUE; 00331 } 00332 } 00333 00334 //----------------------------------------------------------------------- 00335 // NAME: WB_BUFFER::Get_Command 00336 // FUNCTION: Using the 'buffer' scan past spaces, tabs, and semicolons to 00337 // get to the next character, and return it as the character represen- 00338 // tation of the next command. 00339 //----------------------------------------------------------------------- 00340 00341 char WB_BUFFER::Get_Command() 00342 { 00343 INT i = _buffer_start; 00344 while (_buffer[i] == ' ' || _buffer[i] == '\t' || _buffer[i] == ';') i++; 00345 _buffer_start = i + 1; 00346 return _buffer[i]; 00347 } 00348 00349 00350 //----------------------------------------------------------------------- 00351 // NAME: WB_BUFFER::Is_Integer 00352 // FUNCTION: Returns TRUE if the next item in the buffer is an integer, 00353 // otherwise returns FALSE. 00354 //----------------------------------------------------------------------- 00355 00356 BOOL WB_BUFFER::Is_Integer() 00357 { 00358 INT start_index 00359 = (_buffer[_buffer_start] == '+' || _buffer[_buffer_start] == '-') 00360 ? _buffer_start + 1 : _buffer_start; 00361 return isdigit(_buffer[start_index]); 00362 }
1.5.6