comparison src/load-save.cc @ 4788:82a558043db9

[project @ 2004-02-18 22:31:57 by jwe]
author jwe
date Wed, 18 Feb 2004 22:31:57 +0000
parents 14dc2267c343
children 62f2fb593455
comparison
equal deleted inserted replaced
4787:02c748eb2ddc 4788:82a558043db9
84 static bool Vcrash_dumps_octave_core; 84 static bool Vcrash_dumps_octave_core;
85 85
86 // The default output format. May be one of "binary", "text", 86 // The default output format. May be one of "binary", "text",
87 // "mat-binary", or "hdf5". 87 // "mat-binary", or "hdf5".
88 static std::string Vdefault_save_format; 88 static std::string Vdefault_save_format;
89
90 // The output format for octave-core files. May be one of "binary",
91 // "text", "mat-binary", or "hdf5".
92 static std::string Voctave_core_format;
89 93
90 // The format string for the comment line at the top of text-format 94 // The format string for the comment line at the top of text-format
91 // save files. Passed to strftime. Should begin with `#' and contain 95 // save files. Passed to strftime. Should begin with `#' and contain
92 // no newline characters. 96 // no newline characters.
93 static std::string Vsave_header_format_string; 97 static std::string Vsave_header_format_string;
908 912
909 return saved; 913 return saved;
910 } 914 }
911 915
912 static load_save_format 916 static load_save_format
913 get_default_save_format (void) 917 get_save_format (const std::string& fmt,
914 { 918 load_save_format fallback_format = LS_ASCII)
915 load_save_format retval = LS_ASCII; 919 {
916 920 load_save_format retval = fallback_format;
917 std::string fmt = Vdefault_save_format;
918 921
919 if (fmt == "binary") 922 if (fmt == "binary")
920 retval = LS_BINARY; 923 retval = LS_BINARY;
921 else if (fmt == "mat-binary" || fmt =="mat_binary") 924 else if (fmt == "mat-binary" || fmt =="mat_binary")
922 retval = LS_MAT5_BINARY; 925 retval = LS_MAT5_BINARY;
1044 1047
1045 const char *fname = "octave-core"; 1048 const char *fname = "octave-core";
1046 1049
1047 message (0, "attempting to save variables to `%s'...", fname); 1050 message (0, "attempting to save variables to `%s'...", fname);
1048 1051
1049 load_save_format format = get_default_save_format (); 1052 load_save_format format
1053 = get_save_format (Voctave_core_format, LS_BINARY);
1050 1054
1051 std::ios::openmode mode = std::ios::out|std::ios::trunc; 1055 std::ios::openmode mode = std::ios::out|std::ios::trunc;
1052 if (format == LS_BINARY || 1056 if (format == LS_BINARY ||
1053 format == LS_MAT_BINARY || 1057 format == LS_MAT_BINARY ||
1054 format == LS_MAT5_BINARY) 1058 format == LS_MAT5_BINARY)
1184 1188
1185 bool save_builtins = false; 1189 bool save_builtins = false;
1186 1190
1187 bool save_as_floats = false; 1191 bool save_as_floats = false;
1188 1192
1189 load_save_format format = get_default_save_format (); 1193 load_save_format format = get_save_format (Vdefault_save_format);
1190 1194
1191 bool append = false; 1195 bool append = false;
1192 1196
1193 int i; 1197 int i;
1194 for (i = 1; i < argc; i++) 1198 for (i = 1; i < argc; i++)
1367 Vdefault_save_format = s; 1371 Vdefault_save_format = s;
1368 1372
1369 return status; 1373 return status;
1370 } 1374 }
1371 1375
1376 static int
1377 octave_core_format (void)
1378 {
1379 int status = 0;
1380
1381 std::string s = builtin_string_variable ("octave_core_format");
1382
1383 if (s.empty ())
1384 {
1385 gripe_invalid_value_specified ("octave_core_format");
1386 status = -1;
1387 }
1388 else
1389 Voctave_core_format = s;
1390
1391 return status;
1392 }
1393
1372 static std::string 1394 static std::string
1373 default_save_header_format (void) 1395 default_save_header_format (void)
1374 { 1396 {
1375 return 1397 return
1376 std::string ("# Created by Octave " OCTAVE_VERSION 1398 std::string ("# Created by Octave " OCTAVE_VERSION
1415 @defvr {Built-in Variable} default_save_format\n\ 1437 @defvr {Built-in Variable} default_save_format\n\
1416 This variable specifies the default format for the @code{save} command.\n\ 1438 This variable specifies the default format for the @code{save} command.\n\
1417 It should have one of the following values: @code{\"ascii\"},\n\ 1439 It should have one of the following values: @code{\"ascii\"},\n\
1418 @code{\"binary\"}, @code{float-binary}, or @code{\"mat-binary\"}. The\n\ 1440 @code{\"binary\"}, @code{float-binary}, or @code{\"mat-binary\"}. The\n\
1419 initial default save format is Octave's text format.\n\ 1441 initial default save format is Octave's text format.\n\
1442 @seealso{octave_core_format}\n\
1443 @end defvr");
1444
1445 DEFVAR (octave_core_format, "binary", octave_core_format,
1446 "-*- texinfo -*-\n\
1447 @defvr {Built-in Variable} octave_core_format\n\
1448 If Octave aborts, it attempts to save the contents of the top-level\n\
1449 workspace in a file using this format. The value of\n\
1450 @code{octave_core_format} should have one of the following values:\n\
1451 @code{\"ascii\"}, @code{\"binary\"}, @code{float-binary}, or\n\
1452 @code{\"mat-binary\"}. The default value is Octave's binary format.\n\
1453 @seealso{default_save_format}\n\
1420 @end defvr"); 1454 @end defvr");
1421 1455
1422 DEFVAR (save_header_format_string, default_save_header_format (), 1456 DEFVAR (save_header_format_string, default_save_header_format (),
1423 save_header_format_string, 1457 save_header_format_string,
1424 "-*- texinfo -*-\n\ 1458 "-*- texinfo -*-\n\