comparison src/octave.cc @ 1755:3a9462b655f1

[project @ 1996-01-22 04:47:22 by jwe]
author jwe
date Mon, 22 Jan 1996 04:47:22 +0000
parents fc63680a4dc9
children e8e76be43e79
comparison
equal deleted inserted replaced
1754:5f1938919fdc 1755:3a9462b655f1
162 } 162 }
163 163
164 // Initialize some global variables for later use. 164 // Initialize some global variables for later use.
165 165
166 static void 166 static void
167 initialize_globals (char *name) 167 initialize_globals (const string& name)
168 { 168 {
169 raw_prog_name = strsave (name); 169 raw_prog_name = name;
170 char *tmp = strrchr (raw_prog_name, '/'); 170 size_t pos = raw_prog_name.rfind ('/');
171 prog_name = tmp ? strsave (tmp+1) : strsave (raw_prog_name); 171 if (pos == NPOS)
172 prog_name = raw_prog_name;
173 else
174 prog_name = raw_prog_name.substr (pos+1);
172 175
173 struct passwd *entry = getpwuid (getuid ()); 176 struct passwd *entry = getpwuid (getuid ());
174 if (entry) 177 if (entry)
175 user_name = strsave (entry->pw_name); 178 user_name = entry->pw_name;
176 else 179 else
177 user_name = strsave ("I have no name!"); 180 user_name = "I have no name!";
178 endpwent (); 181 endpwent ();
179 182
180 char hostname[256]; 183 char hostname[256];
181 if (gethostname (hostname, 255) < 0) 184 if (gethostname (hostname, 255) < 0)
182 host_name = strsave ("I have no host!"); 185 host_name = "I have no host!";
183 else 186 else
184 host_name = strsave (hostname); 187 host_name = hostname;
185 188
186 char *hd = getenv ("HOME"); 189 char *hd = getenv ("HOME");
187 if (hd) 190 home_directory = hd ? hd : "I have no home!";
188 home_directory = strsave (hd);
189 else
190 home_directory = strsave ("I have no home!");
191 191
192 exec_path = default_exec_path (); 192 exec_path = default_exec_path ();
193 193
194 load_path = default_path (); 194 load_path = default_path ();
195 195
221 // Execute commands from the site-wide configuration file. First 221 // Execute commands from the site-wide configuration file. First
222 // from the file $(prefix)/lib/octave/site/m/octaverc (if it exists), 222 // from the file $(prefix)/lib/octave/site/m/octaverc (if it exists),
223 // then from the file $(prefix)/lib/octave/$(version)/m/octaverc (if 223 // then from the file $(prefix)/lib/octave/$(version)/m/octaverc (if
224 // it exists). 224 // it exists).
225 225
226 char *lsd = get_local_site_defaults (); 226 string lsd = get_local_site_defaults ();
227 parse_and_execute (lsd, 0, verbose); 227 parse_and_execute (lsd, 0, verbose);
228 228
229 char *sd = get_site_defaults (); 229 string sd = get_site_defaults ();
230 parse_and_execute (sd, 0, verbose); 230 parse_and_execute (sd, 0, verbose);
231 231
232 // Try to execute commands from $HOME/.octaverc and ./.octaverc. 232 // Try to execute commands from $HOME/.octaverc and ./.octaverc.
233 233
234 char *home_rc = 0; 234 int home_rc_already_executed = 0;
235 if (home_directory) 235 string home_rc;
236 { 236 if (! home_directory.empty ())
237 home_rc = strconcat (home_directory, "/.octaverc"); 237 {
238 home_rc = home_directory;
239 home_rc.append ("/.octaverc");
238 parse_and_execute (home_rc, 0, verbose); 240 parse_and_execute (home_rc, 0, verbose);
239 } 241
240 242 // Names alone are not enough.
241 // Names alone are not enough. 243
242 244 struct stat home_rc_statbuf;
243 struct stat home_rc_statbuf; 245 stat (home_rc.c_str (), &home_rc_statbuf);
244 stat (home_rc, &home_rc_statbuf); 246
245 delete [] home_rc; 247 struct stat dot_rc_statbuf;
246 248 stat ("./.octaverc", &dot_rc_statbuf);
247 struct stat dot_rc_statbuf; 249
248 stat ("./.octaverc", &dot_rc_statbuf); 250 if (home_rc_statbuf.st_ino == dot_rc_statbuf.st_ino)
249 251 home_rc_already_executed = 1;
250 if (home_rc_statbuf.st_ino != dot_rc_statbuf.st_ino) 252 }
253
254 if (! home_rc_already_executed)
251 parse_and_execute ("./.octaverc", 0, verbose); 255 parse_and_execute ("./.octaverc", 0, verbose);
252 256
253 run_unwind_frame ("execute_startup_files"); 257 run_unwind_frame ("execute_startup_files");
254 } 258 }
255 259
378 forced_interactive = 1; 382 forced_interactive = 1;
379 break; 383 break;
380 384
381 case 'p': 385 case 'p':
382 if (optarg) 386 if (optarg)
383 load_path = strsave (optarg); 387 load_path = string (optarg);
384 break; 388 break;
385 389
386 case 'q': 390 case 'q':
387 inhibit_startup_message = 1; 391 inhibit_startup_message = 1;
388 break; 392 break;
395 print_version_and_exit (); 399 print_version_and_exit ();
396 break; 400 break;
397 401
398 case EXEC_PATH_OPTION: 402 case EXEC_PATH_OPTION:
399 if (optarg) 403 if (optarg)
400 exec_path = strsave (optarg); 404 exec_path = string (optarg);
401 break; 405 break;
402 406
403 case INFO_FILE_OPTION: 407 case INFO_FILE_OPTION:
404 if (optarg) 408 if (optarg)
405 info_file = strsave (optarg); 409 info_file = string (optarg);
406 break; 410 break;
407 411
408 case INFO_PROG_OPTION: 412 case INFO_PROG_OPTION:
409 if (optarg) 413 if (optarg)
410 info_prog = strsave (optarg); 414 info_prog = string (optarg);
411 break; 415 break;
412 416
413 case TRADITIONAL_OPTION: 417 case TRADITIONAL_OPTION:
414 traditional = 1; 418 traditional = 1;
415 break; 419 break;
481 input_from_command_line_file = 1; 485 input_from_command_line_file = 1;
482 486
483 bind_builtin_variable ("program_invocation_name", 487 bind_builtin_variable ("program_invocation_name",
484 curr_fcn_file_name); 488 curr_fcn_file_name);
485 489
486 const char *tmp = strrchr (curr_fcn_file_name, '/'); 490 size_t pos = curr_fcn_file_name.rfind ('/');
487 tmp = tmp ? tmp+1 : curr_fcn_file_name; 491
492 string tmp = (pos != NPOS)
493 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name;
488 494
489 bind_builtin_variable ("program_name", tmp); 495 bind_builtin_variable ("program_name", tmp);
490 496
491 intern_argv (remaining_args, argv+optind); 497 intern_argv (remaining_args, argv+optind);
492 498