comparison src/oct-stream.cc @ 3341:14cfc9475fe4

[project @ 1999-11-05 08:11:58 by jwe]
author jwe
date Fri, 05 Nov 1999 08:11:59 +0000
parents 585a8809fd9b
children d8d3700fb4ab
comparison
equal deleted inserted replaced
3340:585a8809fd9b 3341:14cfc9475fe4
2636 { 2636 {
2637 return (instance_ok ()) ? instance->do_insert (os) : octave_value (-1.0); 2637 return (instance_ok ()) ? instance->do_insert (os) : octave_value (-1.0);
2638 } 2638 }
2639 2639
2640 octave_stream 2640 octave_stream
2641 octave_stream_list::lookup (int fid) 2641 octave_stream_list::lookup (int fid, const string& who)
2642 { 2642 {
2643 return (instance_ok ()) ? instance->do_lookup (fid) : octave_stream (); 2643 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2644 } 2644 }
2645 2645
2646 octave_stream 2646 octave_stream
2647 octave_stream_list::lookup (const octave_value& fid) 2647 octave_stream_list::lookup (const octave_value& fid, const string& who)
2648 { 2648 {
2649 return (instance_ok ()) ? instance->do_lookup (fid) : octave_stream (); 2649 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2650 } 2650 }
2651 2651
2652 int 2652 int
2653 octave_stream_list::remove (int fid) 2653 octave_stream_list::remove (int fid, const string& who)
2654 { 2654 {
2655 return (instance_ok ()) ? instance->do_remove (fid) : -1; 2655 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2656 } 2656 }
2657 2657
2658 int 2658 int
2659 octave_stream_list::remove (const octave_value& fid) 2659 octave_stream_list::remove (const octave_value& fid, const string& who)
2660 { 2660 {
2661 return (instance_ok ()) ? instance->do_remove (fid) : -1; 2661 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2662 } 2662 }
2663 2663
2664 void 2664 void
2665 octave_stream_list::clear (void) 2665 octave_stream_list::clear (void)
2666 { 2666 {
2734 } 2734 }
2735 2735
2736 return octave_value (os, stream_number); 2736 return octave_value (os, stream_number);
2737 } 2737 }
2738 2738
2739 static void
2740 gripe_invalid_file_id (int fid, const string& who)
2741 {
2742 if (who.empty ())
2743 ::error ("invalid stream number = %d", fid);
2744 else
2745 ::error ("%s: invalid stream number = %d", who.c_str (), fid);
2746 }
2747
2739 octave_stream 2748 octave_stream
2740 octave_stream_list::do_lookup (int fid) const 2749 octave_stream_list::do_lookup (int fid, const string& who) const
2741 { 2750 {
2742 octave_stream retval; 2751 octave_stream retval;
2743 2752
2744 if (fid >= 0 && fid < curr_len) 2753 if (fid >= 0 && fid < curr_len)
2745 retval = list(fid); 2754 retval = list(fid);
2755 else
2756 gripe_invalid_file_id (fid, who);
2746 2757
2747 return retval; 2758 return retval;
2748 } 2759 }
2749 2760
2750 octave_stream 2761 octave_stream
2751 octave_stream_list::do_lookup (const octave_value& fid) const 2762 octave_stream_list::do_lookup (const octave_value& fid,
2763 const string& who) const
2752 { 2764 {
2753 octave_stream retval; 2765 octave_stream retval;
2754 2766
2755 int i = get_file_number (fid); 2767 int i = get_file_number (fid);
2756 2768
2757 if (! error_state) 2769 if (! error_state)
2758 retval = do_lookup (i); 2770 retval = do_lookup (i, who);
2759 2771
2760 return retval; 2772 return retval;
2761 } 2773 }
2762 2774
2763 int 2775 int
2764 octave_stream_list::do_remove (int fid) 2776 octave_stream_list::do_remove (int fid, const string& who)
2765 { 2777 {
2766 int retval = -1; 2778 int retval = -1;
2767 2779
2768 // Can't remove stdin (cin), stdout (cout), or stderr (cerr). 2780 // Can't remove stdin (cin), stdout (cout), or stderr (cerr).
2769 2781
2770 if (fid > 2 && fid < curr_len) 2782 if (fid > 2 && fid < curr_len)
2771 { 2783 {
2772 octave_stream os = list(fid); 2784 octave_stream os = list(fid);
2773 2785
2774 if (os) 2786 if (os.is_valid ())
2775 { 2787 {
2776 os.close (); 2788 os.close ();
2777 list(fid) = octave_stream (); 2789 list(fid) = octave_stream ();
2778 retval = 0; 2790 retval = 0;
2779 } 2791 }
2780 } 2792 else
2793 gripe_invalid_file_id (fid, who);
2794 }
2795 else
2796 gripe_invalid_file_id (fid, who);
2781 2797
2782 return retval; 2798 return retval;
2783 } 2799 }
2784 2800
2785 int 2801 int
2786 octave_stream_list::do_remove (const octave_value& fid) 2802 octave_stream_list::do_remove (const octave_value& fid, const string& who)
2787 { 2803 {
2788 int retval = -1; 2804 int retval = -1;
2789 2805
2790 int i = get_file_number (fid); 2806 int i = get_file_number (fid);
2791 2807
2792 if (! error_state) 2808 if (! error_state)
2793 retval = do_remove (i); 2809 retval = do_remove (i, who);
2794 2810
2795 return retval; 2811 return retval;
2796 } 2812 }
2797 2813
2798 void 2814 void
2814 { 2830 {
2815 string_vector retval; 2831 string_vector retval;
2816 2832
2817 octave_stream os = do_lookup (fid); 2833 octave_stream os = do_lookup (fid);
2818 2834
2819 if (os) 2835 if (os.is_valid ())
2820 { 2836 {
2821 retval.resize (3); 2837 retval.resize (3);
2822 2838
2823 retval(0) = os.name (); 2839 retval(0) = os.name ();
2824 retval(1) = octave_stream::mode_as_string (os.mode ()); 2840 retval(1) = octave_stream::mode_as_string (os.mode ());
2825 retval(2) = oct_mach_info::float_format_as_string (os.float_format ()); 2841 retval(2) = oct_mach_info::float_format_as_string (os.float_format ());
2826 } 2842 }
2827 else 2843 else
2828 ::error ("invalid file id"); 2844 ::error ("invalid file id = %d", fid);
2829 2845
2830 return retval; 2846 return retval;
2831 } 2847 }
2832 2848
2833 string_vector 2849 string_vector