comparison src/variables.cc @ 2095:36903d507b0e

[project @ 1996-04-28 09:00:07 by jwe]
author jwe
date Sun, 28 Apr 1996 09:00:07 +0000
parents 4dcc8b77e84a
children 19ba1a7dcfbb
comparison
equal deleted inserted replaced
2094:a23645b0364e 2095:36903d507b0e
28 #include <cstdio> 28 #include <cstdio>
29 #include <cstring> 29 #include <cstring>
30 30
31 #include <string> 31 #include <string>
32 32
33 #include <iostream.h>
33 #include <strstream.h> 34 #include <strstream.h>
34 35
35 #ifdef HAVE_UNISTD_H 36 #ifdef HAVE_UNISTD_H
36 #include <sys/types.h> 37 #include <sys/types.h>
37 #include <unistd.h> 38 #include <unistd.h>
1120 } 1121 }
1121 1122
1122 // List variable names. 1123 // List variable names.
1123 1124
1124 static void 1125 static void
1125 print_symbol_info_line (ostrstream& output_buf, const symbol_record_info& s) 1126 print_symbol_info_line (ostream& os, const symbol_record_info& s)
1126 { 1127 {
1127 output_buf << (s.is_read_only () ? " -" : " w"); 1128 os << (s.is_read_only () ? " -" : " w");
1128 output_buf << (s.is_eternal () ? "- " : "d "); 1129 os << (s.is_eternal () ? "- " : "d ");
1129 #if 0 1130 #if 0
1130 output_buf << (s.hides_fcn () ? "f" : (s.hides_builtin () ? "F" : "-")); 1131 os << (s.hides_fcn () ? "f" : (s.hides_builtin () ? "F" : "-"));
1131 #endif 1132 #endif
1132 output_buf.form (" %-16s", s.type_as_string ().c_str ()); 1133 os.form (" %-16s", s.type_as_string ().c_str ());
1133 if (s.is_function ()) 1134 if (s.is_function ())
1134 output_buf << " - -"; 1135 os << " - -";
1135 else 1136 else
1136 { 1137 {
1137 output_buf.form ("%7d", s.rows ()); 1138 os.form ("%7d", s.rows ());
1138 output_buf.form ("%7d", s.columns ()); 1139 os.form ("%7d", s.columns ());
1139 } 1140 }
1140 output_buf << " " << s.name () << "\n"; 1141 os << " " << s.name () << "\n";
1141 } 1142 }
1142 1143
1143 static void 1144 static void
1144 print_long_listing (ostrstream& output_buf, symbol_record_info *s) 1145 print_long_listing (ostream& os, symbol_record_info *s)
1145 { 1146 {
1146 if (! s) 1147 if (! s)
1147 return; 1148 return;
1148 1149
1149 symbol_record_info *ptr = s; 1150 symbol_record_info *ptr = s;
1150 while (ptr->is_defined ()) 1151 while (ptr->is_defined ())
1151 { 1152 {
1152 print_symbol_info_line (output_buf, *ptr); 1153 print_symbol_info_line (os, *ptr);
1153 ptr++; 1154 ptr++;
1154 } 1155 }
1155 } 1156 }
1156 1157
1157 static int 1158 static int
1158 maybe_list (const char *header, const string_vector& argv, int argc, 1159 maybe_list (const char *header, const string_vector& argv, int argc,
1159 ostrstream& output_buf, int show_verbose, symbol_table 1160 ostream& os, int show_verbose, symbol_table
1160 *sym_tab, unsigned type, unsigned scope) 1161 *sym_tab, unsigned type, unsigned scope)
1161 { 1162 {
1162 int count; 1163 int count;
1163 int status = 0; 1164 int status = 0;
1164 if (show_verbose) 1165 if (show_verbose)
1165 { 1166 {
1166 symbol_record_info *symbols; 1167 symbol_record_info *symbols;
1167 symbols = sym_tab->long_list (count, argv, argc, 1, type, scope); 1168 symbols = sym_tab->long_list (count, argv, argc, 1, type, scope);
1168 if (symbols && count > 0) 1169 if (symbols && count > 0)
1169 { 1170 {
1170 output_buf << "\n" << header << "\n\n" 1171 os << "\n" << header << "\n\n"
1171 << "prot type rows cols name\n" 1172 << "prot type rows cols name\n"
1172 << "==== ==== ==== ==== ====\n"; 1173 << "==== ==== ==== ==== ====\n";
1173 1174
1174 print_long_listing (output_buf, symbols); 1175 print_long_listing (os, symbols);
1175 status = 1; 1176 status = 1;
1176 } 1177 }
1177 delete [] symbols; 1178 delete [] symbols;
1178 } 1179 }
1179 else 1180 else
1180 { 1181 {
1181 string_vector symbols = sym_tab->list (count, argv, argc, 1, 1182 string_vector symbols = sym_tab->list (count, argv, argc, 1,
1182 type, scope); 1183 type, scope);
1183 if (symbols.length () > 0 && count > 0) 1184 if (symbols.length () > 0 && count > 0)
1184 { 1185 {
1185 output_buf << "\n" << header << "\n\n"; 1186 os << "\n" << header << "\n\n";
1186 symbols.list_in_columns (output_buf); 1187 symbols.list_in_columns (os);
1187 status = 1; 1188 status = 1;
1188 } 1189 }
1189 } 1190 }
1190 return status; 1191 return status;
1191 } 1192 }
1284 { 1285 {
1285 show_functions = (curr_sym_tab == top_level_sym_tab); 1286 show_functions = (curr_sym_tab == top_level_sym_tab);
1286 show_variables = 1; 1287 show_variables = 1;
1287 } 1288 }
1288 1289
1289 ostrstream output_buf;
1290 int pad_after = 0; 1290 int pad_after = 0;
1291 1291
1292 if (show_builtins) 1292 if (show_builtins)
1293 { 1293 {
1294 pad_after += maybe_list ("*** built-in variables:", pats, npats, 1294 pad_after += maybe_list ("*** built-in variables:", pats, npats,
1295 output_buf, show_verbose, global_sym_tab, 1295 octave_stdout, show_verbose, global_sym_tab,
1296 symbol_def::BUILTIN_VARIABLE, 1296 symbol_def::BUILTIN_VARIABLE,
1297 SYMTAB_ALL_SCOPES); 1297 SYMTAB_ALL_SCOPES);
1298 1298
1299 pad_after += maybe_list ("*** built-in functions:", pats, npats, 1299 pad_after += maybe_list ("*** built-in functions:", pats, npats,
1300 output_buf, show_verbose, global_sym_tab, 1300 octave_stdout, show_verbose, global_sym_tab,
1301 symbol_def::BUILTIN_FUNCTION, 1301 symbol_def::BUILTIN_FUNCTION,
1302 SYMTAB_ALL_SCOPES); 1302 SYMTAB_ALL_SCOPES);
1303 } 1303 }
1304 1304
1305 if (show_functions) 1305 if (show_functions)
1306 { 1306 {
1307 pad_after += maybe_list ("*** currently compiled functions:", 1307 pad_after += maybe_list ("*** currently compiled functions:",
1308 pats, npats, output_buf, show_verbose, 1308 pats, npats, octave_stdout, show_verbose,
1309 global_sym_tab, symbol_def::USER_FUNCTION, 1309 global_sym_tab, symbol_def::USER_FUNCTION,
1310 SYMTAB_ALL_SCOPES); 1310 SYMTAB_ALL_SCOPES);
1311 } 1311 }
1312 1312
1313 if (show_variables) 1313 if (show_variables)
1314 { 1314 {
1315 pad_after += maybe_list ("*** local user variables:", pats, npats, 1315 pad_after += maybe_list ("*** local user variables:", pats, npats,
1316 output_buf, show_verbose, curr_sym_tab, 1316 octave_stdout, show_verbose, curr_sym_tab,
1317 symbol_def::USER_VARIABLE, 1317 symbol_def::USER_VARIABLE,
1318 SYMTAB_LOCAL_SCOPE); 1318 SYMTAB_LOCAL_SCOPE);
1319 1319
1320 pad_after += maybe_list ("*** globally visible user variables:", 1320 pad_after += maybe_list ("*** globally visible user variables:",
1321 pats, npats, output_buf, show_verbose, 1321 pats, npats, octave_stdout, show_verbose,
1322 curr_sym_tab, symbol_def::USER_VARIABLE, 1322 curr_sym_tab, symbol_def::USER_VARIABLE,
1323 SYMTAB_GLOBAL_SCOPE); 1323 SYMTAB_GLOBAL_SCOPE);
1324 } 1324 }
1325 1325
1326 if (pad_after) 1326 if (pad_after)
1327 output_buf << "\n"; 1327 octave_stdout << "\n";
1328
1329 output_buf << ends;
1330 maybe_page_output (output_buf);
1331 1328
1332 return retval; 1329 return retval;
1333 } 1330 }
1334 1331
1335 DEFUN_TEXT (who, args, , 1332 DEFUN_TEXT (who, args, ,