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

Last change on this file since 1954 was 748, checked in by tbretz, 24 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 fclose(f);
15}
16
17char File::Getc() const
18{
19 return fgetc(f);
20}
21
22int File::Eof() const
23{
24 return feof(f);
25}
26
27void File::Seek(long pos) const
28{
29 fseek(f, pos, SEEK_SET);
30}
31
32void File::Reset() const
33{
34 fseek(f, 0, SEEK_SET);
35}
36
37long File::Tell() const
38{
39 return ftell(f);
40}
41
42long File::Size() const
43{
44 long l = ftell(f);
45 fseek(f, 0, SEEK_END);
46 long s = ftell(f);
47 fseek(f, l, SEEK_SET);
48 return s;
49}
50
51char *File::Gets(char *c, int cnt) const
52{
53 for (int i=0; i<cnt; i++)
54 *c++=fgetc(f);
55 *c='\0';
56
57 return c;
58}
59
60void File::Newline() const
61{
62 int g;
63 do g=fgetc(f);
64 while (g!=0x0A && g!=EOF);
65}
66
67int File::Geti(int cnt) const
68{
69 char *c = new char[cnt+1];
70 Gets(c, cnt);
71 int result = atoi(c);
72 delete c;
73 return result;
74}
75
76float File::Getf(int cnt) const
77{
78 char *c = new char[cnt+1];
79 Gets(c, cnt);
80 float result = atof(c);
81 delete c;
82 return result;
83}
84
85void File::Skip(int cnt) const
86{
87 char *c = new char[cnt+1];
88 Gets(c, cnt);
89 delete c;
90}
91
Note: See TracBrowser for help on using the repository browser.