| Line |  | 
|---|
| 1 | #include "File.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <stdlib.h> | 
|---|
| 4 |  | 
|---|
| 5 | File::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 |  | 
|---|
| 12 | File::~File() | 
|---|
| 13 | { | 
|---|
| 14 | if (f) | 
|---|
| 15 | fclose(f); | 
|---|
| 16 | } | 
|---|
| 17 |  | 
|---|
| 18 | char File::Getc() const | 
|---|
| 19 | { | 
|---|
| 20 | return fgetc(f); | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 | int File::Eof() const | 
|---|
| 24 | { | 
|---|
| 25 | return feof(f); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | void File::Seek(long pos) const | 
|---|
| 29 | { | 
|---|
| 30 | fseek(f, pos, SEEK_SET); | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | void File::Reset() const | 
|---|
| 34 | { | 
|---|
| 35 | fseek(f, 0, SEEK_SET); | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | long File::Tell() const | 
|---|
| 39 | { | 
|---|
| 40 | return ftell(f); | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | long 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 |  | 
|---|
| 52 | char *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 |  | 
|---|
| 61 | void File::Newline() const | 
|---|
| 62 | { | 
|---|
| 63 | int g; | 
|---|
| 64 | do g=fgetc(f); | 
|---|
| 65 | while (g!=0x0A && g!=EOF); | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | int 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 |  | 
|---|
| 77 | float 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 |  | 
|---|
| 86 | void 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.