File: textfile.h

package info (click to toggle)
mixviews 1.10-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,440 kB
  • ctags: 6,314
  • sloc: cpp: 31,647; ansic: 2,100; makefile: 1,782; sh: 17
file content (145 lines) | stat: -rw-r--r-- 3,834 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// textfile.h

/******************************************************************************
 *
 *  MiXViews - an X window system based sound & data editor/processor
 *
 *  Copyright (c) 1993, 1994 Regents of the University of California
 *
 *  Author:     Douglas Scott
 *  Date:       December 13, 1994
 *
 *  Permission to use, copy and modify this software and its documentation
 *  for research and/or educational purposes and without fee is hereby granted,
 *  provided that the above copyright notice appear in all copies and that
 *  both that copyright notice and this permission notice appear in
 *  supporting documentation. The author reserves the right to distribute this
 *  software and its documentation.  The University of California and the author
 *  make no representations about the suitability of this software for any 
 *  purpose, and in no event shall University of California be liable for any
 *  damage, loss of data, or profits resulting from its use.
 *  It is provided "as is" without express or implied warranty.
 *
 ******************************************************************************/


// This class is unused at this time.

#ifndef BFILE_H 
#ifdef __GNUG__
#pragma interface
#endif
#define BFILE_H

#include "diskfile.h"

class TextFile : public DiskFile {
protected:
	char		*readline (int chunk_number, char terminator);
public:
	TextFile() {}
	TextFile(const char* filename, io_mode m, access_mode a);
	TextFile(const char* filename, const char* m);

	virtual ~TextFile() {}

// binding, rebinding, unbinding to physical files

  DiskFile&			open(const char* filename, io_mode m, access_mode a);
  DiskFile&			open(const char* filename, const char* m);
  TextFile&         open(int  filedesc, io_mode m);
  TextFile&         open(FILE* fileptr);
  
// character IO

  TextFile&         get(char& c);
  TextFile&         put(char  c);
  TextFile&         unget(char c);
  TextFile&         putback(char c); // a synonym for unget

// char* IO

  TextFile&         put(const char* s);
  TextFile&         get    (char* s, int n, char terminator = '\n');
  TextFile&         getline(char* s, int n, char terminator = '\n');
  TextFile&         gets   (char **s, char terminator = '\n');

// binary IO

  TextFile&         read(void* x, int sz, int n);
  TextFile&         write(const void* x, int sz, int n);

// formatted IO

  TextFile&         form(const char* ...);
  TextFile&         scan(const char* ...);

// buffer IO

  TextFile&         flush();
  TextFile&         flush(char ch); // call stdio _flsbuf
  int 		        fill();         // call stdio _filbuf

};

inline TextFile& TextFile::read(void* x, int sz, int n)
{ 
  return failif (!readable() || (stat = fread(x, sz, n, fp)) != n);
} 

inline TextFile& TextFile::write(const void* x, int sz, int n) 
{ 
  return failif (!writable() || (stat = fwrite(x, sz, n, fp)) != n);
}

inline TextFile& TextFile::get(char& c)
{ 
  if (readable())
  {
    int ch = getc(fp);
    c = ch;
    failif (ch == EOF);
  }
  return *this;
}

inline TextFile& TextFile::put(char  c) 
{ 
  return failif (!writable() ||  putc(c, fp) == EOF);
}

inline TextFile& TextFile::unget(char c)
{ 
  return failif(!is_open() || !(rw & 01) || ungetc(c, fp) == EOF);
} 

inline TextFile& TextFile::putback(char c)
{ 
  return failif (!is_open() || !(rw & 01) || ungetc(c, fp) == EOF);
}

inline TextFile& TextFile::flush()
{ 
  return failif(!is_open() || fflush(fp) == EOF);
}

inline TextFile& TextFile::flush(char ch)
{ 
#ifdef VMS
  return failif(!is_open() || c$$flsbuf(ch, fp) == EOF);
#else
  return failif(!is_open() || _flsbuf(ch, fp) == EOF);
#endif
}

inline int TextFile::fill()
{ 
#ifdef VMS
  failif(!is_open() || (stat = c$$filbuf(fp)) == EOF);
#else
  failif(!is_open() || (stat = _filbuf(fp)) == EOF);
#endif
  return stat;
}

#endif