comparison src/file-io.cc @ 164:e2c950dd96d2

[project @ 1993-10-18 19:32:00 by jwe]
author jwe
date Mon, 18 Oct 1993 19:32:00 +0000
parents 74d6f5fe70a1
children d981cdce52d9
comparison
equal deleted inserted replaced
163:b4bdbdf95e05 164:e2c950dd96d2
52 52
53 class File_info 53 class File_info
54 { 54 {
55 public: 55 public:
56 File_info (void); 56 File_info (void);
57 File_info (int num, char *nm, FILE *t, char *md); 57 File_info (int num, const char *nm, FILE *t, const char *md);
58 File_info (const File_info& f); 58 File_info (const File_info& f);
59 59
60 File_info& operator = (const File_info& f); 60 File_info& operator = (const File_info& f);
61 61
62 ~File_info (void); 62 ~File_info (void);
104 { 104 {
105 delete [] _name; 105 delete [] _name;
106 delete [] _mode; 106 delete [] _mode;
107 } 107 }
108 108
109 File_info::File_info (int n, char *nm, FILE *t, char *md) 109 File_info::File_info (int n, const char *nm, FILE *t, const char *md)
110 { 110 {
111 _number = n; 111 _number = n;
112 _name = strsave (nm); 112 _name = strsave (nm);
113 _fptr = t; 113 _fptr = t;
114 _mode = strsave (md); 114 _mode = strsave (md);
141 141
142 // double linked list containing relevant information about open files 142 // double linked list containing relevant information about open files
143 static DLList <File_info> file_list; 143 static DLList <File_info> file_list;
144 144
145 void 145 void
146 initialize_file_io () 146 initialize_file_io (void)
147 { 147 {
148 File_info _stdin (0, "stdin", stdin, "r"); 148 File_info _stdin (0, "stdin", stdin, "r");
149 File_info _stdout (1, "stdout", stdout, "w"); 149 File_info _stdout (1, "stdout", stdout, "w");
150 File_info _stderr (2, "stderr", stderr, "w"); 150 File_info _stderr (2, "stderr", stderr, "w");
151 151
155 155
156 file_count = 3; 156 file_count = 3;
157 } 157 }
158 158
159 Pix 159 Pix
160 return_valid_file (tree_constant& arg) 160 return_valid_file (const tree_constant& arg)
161 { 161 {
162 if (arg.is_string_type ()) 162 if (arg.is_string_type ())
163 { 163 {
164 Pix p = file_list.first (); 164 Pix p = file_list.first ();
165 File_info file; 165 File_info file;
196 196
197 return (Pix) NULL; 197 return (Pix) NULL;
198 } 198 }
199 199
200 static Pix 200 static Pix
201 fopen_file_for_user (tree_constant& arg, char *mode) 201 fopen_file_for_user (const tree_constant& arg, const char *mode)
202 { 202 {
203 char *file_name = arg.string_value (); 203 char *file_name = arg.string_value ();
204 204
205 FILE *file_ptr = fopen (file_name, mode); 205 FILE *file_ptr = fopen (file_name, mode);
206 if (file_ptr != (FILE *) NULL) 206 if (file_ptr != (FILE *) NULL)
224 return (Pix) NULL; 224 return (Pix) NULL;
225 } 225 }
226 226
227 227
228 tree_constant * 228 tree_constant *
229 fclose_internal (tree_constant *args) 229 fclose_internal (const tree_constant *args)
230 { 230 {
231 tree_constant *retval = NULL_TREE_CONST; 231 tree_constant *retval = NULL_TREE_CONST;
232 232
233 Pix p = return_valid_file (args[1]); 233 Pix p = return_valid_file (args[1]);
234 234
258 258
259 return retval; 259 return retval;
260 } 260 }
261 261
262 tree_constant * 262 tree_constant *
263 fflush_internal (tree_constant *args) 263 fflush_internal (const tree_constant *args)
264 { 264 {
265 tree_constant *retval = NULL_TREE_CONST; 265 tree_constant *retval = NULL_TREE_CONST;
266 266
267 Pix p = return_valid_file (args[1]); 267 Pix p = return_valid_file (args[1]);
268 268
294 294
295 return retval; 295 return retval;
296 } 296 }
297 297
298 static int 298 static int
299 valid_mode (char *mode) 299 valid_mode (const char *mode)
300 { 300 {
301 if (mode != (char *) NULL) 301 if (mode != (char *) NULL)
302 { 302 {
303 char m = mode[0]; 303 char m = mode[0];
304 if (m == 'r' || m == 'w' || m == 'a') 304 if (m == 'r' || m == 'w' || m == 'a')
309 } 309 }
310 return 0; 310 return 0;
311 } 311 }
312 312
313 tree_constant * 313 tree_constant *
314 fgets_internal (tree_constant *args, int nargout) 314 fgets_internal (const tree_constant *args, int nargout)
315 { 315 {
316 tree_constant *retval = NULL_TREE_CONST; 316 tree_constant *retval = NULL_TREE_CONST;
317 317
318 Pix p = return_valid_file (args[1]); 318 Pix p = return_valid_file (args[1]);
319 319
373 373
374 return retval; 374 return retval;
375 } 375 }
376 376
377 tree_constant * 377 tree_constant *
378 fopen_internal (tree_constant *args) 378 fopen_internal (const tree_constant *args)
379 { 379 {
380 tree_constant *retval = NULL_TREE_CONST; 380 tree_constant *retval = NULL_TREE_CONST;
381 Pix p; 381 Pix p;
382 382
383 if (! args[1].is_string_type ()) 383 if (! args[1].is_string_type ())
438 438
439 return retval; 439 return retval;
440 } 440 }
441 441
442 tree_constant * 442 tree_constant *
443 freport_internal () 443 freport_internal (void)
444 { 444 {
445 tree_constant *retval = NULL_TREE_CONST; 445 tree_constant *retval = NULL_TREE_CONST;
446 Pix p = file_list.first (); 446 Pix p = file_list.first ();
447 447
448 ostrstream output_buf; 448 ostrstream output_buf;
461 461
462 return retval; 462 return retval;
463 } 463 }
464 464
465 tree_constant * 465 tree_constant *
466 frewind_internal (tree_constant *args) 466 frewind_internal (const tree_constant *args)
467 { 467 {
468 tree_constant *retval = NULL_TREE_CONST; 468 tree_constant *retval = NULL_TREE_CONST;
469 469
470 Pix p = return_valid_file (args[1]); 470 Pix p = return_valid_file (args[1]);
471 if (p == (Pix) NULL) 471 if (p == (Pix) NULL)
476 476
477 return retval; 477 return retval;
478 } 478 }
479 479
480 tree_constant * 480 tree_constant *
481 fseek_internal (tree_constant *args, int nargin) 481 fseek_internal (const tree_constant *args, int nargin)
482 { 482 {
483 tree_constant *retval = NULL_TREE_CONST; 483 tree_constant *retval = NULL_TREE_CONST;
484 484
485 Pix p = return_valid_file (args[1]); 485 Pix p = return_valid_file (args[1]);
486 486
530 530
531 return retval; 531 return retval;
532 } 532 }
533 533
534 tree_constant * 534 tree_constant *
535 ftell_internal (tree_constant *args) 535 ftell_internal (const tree_constant *args)
536 { 536 {
537 tree_constant *retval = NULL_TREE_CONST; 537 tree_constant *retval = NULL_TREE_CONST;
538 Pix p = return_valid_file (args[1]); 538 Pix p = return_valid_file (args[1]);
539 539
540 if (p == (Pix) NULL) 540 if (p == (Pix) NULL)
550 550
551 return retval; 551 return retval;
552 } 552 }
553 553
554 void 554 void
555 close_files () 555 close_files (void)
556 { 556 {
557 Pix p = file_list.first (); 557 Pix p = file_list.first ();
558 558
559 for (int i = 0; i < file_count; i++) 559 for (int i = 0; i < file_count; i++)
560 { 560 {
568 file_list.del (p); 568 file_list.del (p);
569 } 569 }
570 } 570 }
571 571
572 static int 572 static int
573 process_printf_format (char *s, tree_constant *args, ostrstream& sb, 573 process_printf_format (const char *s, const tree_constant *args,
574 char *type, int nargin) 574 ostrstream& sb, const char *type, int nargin)
575 { 575 {
576 ostrstream fmt; 576 ostrstream fmt;
577 577
578 fmt << "%"; // do_printf() already blew past this one... 578 fmt << "%"; // do_printf() already blew past this one...
579 579
767 return -1; 767 return -1;
768 } 768 }
769 769
770 770
771 tree_constant * 771 tree_constant *
772 do_printf (char *type, tree_constant *args, int nargin, int nargout) 772 do_printf (const char *type, const tree_constant *args, int nargin,
773 int nargout)
773 { 774 {
774 tree_constant *retval = NULL_TREE_CONST; 775 tree_constant *retval = NULL_TREE_CONST;
775 fmt_arg_count = 1; 776 fmt_arg_count = 1;
776 char *fmt; 777 char *fmt;
777 File_info file; 778 File_info file;
887 888
888 return retval; 889 return retval;
889 } 890 }
890 891
891 static int 892 static int
892 process_scanf_format (char *s, tree_constant *args, ostrstream& fmt, 893 process_scanf_format (const char *s, const tree_constant *args,
893 char *type, int nargout, FILE* fptr, 894 ostrstream& fmt, const char *type, int nargout,
894 tree_constant *values) 895 FILE* fptr, tree_constant *values)
895 { 896 {
896 fmt << "%"; 897 fmt << "%";
897 898
898 tree_constant_rep::constant_type arg_type; 899 tree_constant_rep::constant_type arg_type;
899 900
1048 1049
1049 return -1; 1050 return -1;
1050 } 1051 }
1051 1052
1052 tree_constant * 1053 tree_constant *
1053 do_scanf (char *type, tree_constant *args, int nargin, int nargout) 1054 do_scanf (const char *type, const tree_constant *args, int nargin, int nargout)
1054 { 1055 {
1055 tree_constant *retval = NULL_TREE_CONST; 1056 tree_constant *retval = NULL_TREE_CONST;
1056 char *scanf_fmt = (char *) NULL; 1057 char *scanf_fmt = (char *) NULL;
1057 char *tmp_file = (char *) NULL; 1058 char *tmp_file = (char *) NULL;
1058 int tmp_file_open = 0; 1059 int tmp_file_open = 0;