source: trunk/MagicSoft/Cosy/base/File.cc@ 8846

Last change on this file since 8846 was 2407, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 1.2 KB
Line 
1#include "File.h"
2
3#include <stdlib.h>
4
5File::File(const char *name, const char *flags)
6{
7 f = fopen(name, flags);
8 if (!f)
9 printf("WARNING: Cannot open '%s'\n", name);
10}
11
12File::~File()
13{
14 if (f)
15 fclose(f);
16}
17
18char File::Getc() const
19{
20 return fgetc(f);
21}
22
23int File::Eof() const
24{
25 return feof(f);
26}
27
28void File::Seek(long pos) const
29{
30 fseek(f, pos, SEEK_SET);
31}
32
33void File::Reset() const
34{
35 fseek(f, 0, SEEK_SET);
36}
37
38long File::Tell() const
39{
40 return ftell(f);
41}
42
43long File::Size() const
44{
45 long l = ftell(f);
46 fseek(f, 0, SEEK_END);
47 long s = ftell(f);
48 fseek(f, l, SEEK_SET);
49 return s;
50}
51
52char *File::Gets(char *c, int cnt) const
53{
54 for (int i=0; i<cnt; i++)
55 *c++=fgetc(f);
56 *c='\0';
57
58 return c;
59}
60
61void File::Newline() const
62{
63 int g;
64 do g=fgetc(f);
65 while (g!=0x0A && g!=EOF);
66}
67
68int File::Geti(int cnt) const
69{
70 char *c = new char[cnt+1];
71 Gets(c, cnt);
72 int result = atoi(c);
73 delete c;
74 return result;
75}
76
77float File::Getf(int cnt) const
78{
79 char *c = new char[cnt+1];
80 Gets(c, cnt);
81 float result = atof(c);
82 delete c;
83 return result;
84}
85
86void File::Skip(int cnt) const
87{
88 char *c = new char[cnt+1];
89 Gets(c, cnt);
90 delete c;
91}
92
Note: See TracBrowser for help on using the repository browser.