1 a0d146ed 2005-07-12 devnull #include "stdinc.h"
2 a0d146ed 2005-07-12 devnull #include "dat.h"
3 a0d146ed 2005-07-12 devnull #include "fns.h"
6 a0d146ed 2005-07-12 devnull readifile(IFile *f, char *name)
8 a0d146ed 2005-07-12 devnull ZBlock *b;
10 a0d146ed 2005-07-12 devnull b = readfile(name);
11 a0d146ed 2005-07-12 devnull if(b == nil)
12 a0d146ed 2005-07-12 devnull return -1;
13 a0d146ed 2005-07-12 devnull f->name = name;
14 a0d146ed 2005-07-12 devnull f->b = b;
15 a0d146ed 2005-07-12 devnull f->pos = 0;
16 a0d146ed 2005-07-12 devnull return 0;
20 a0d146ed 2005-07-12 devnull freeifile(IFile *f)
22 a0d146ed 2005-07-12 devnull freezblock(f->b);
23 a0d146ed 2005-07-12 devnull f->b = nil;
24 a0d146ed 2005-07-12 devnull f->pos = 0;
28 a0d146ed 2005-07-12 devnull partifile(IFile *f, Part *part, u64int start, u32int size)
30 a0d146ed 2005-07-12 devnull ZBlock *b;
32 a0d146ed 2005-07-12 devnull b = alloczblock(size, 0, part->blocksize);
33 a0d146ed 2005-07-12 devnull if(b == nil)
34 a0d146ed 2005-07-12 devnull return -1;
35 a0d146ed 2005-07-12 devnull if(readpart(part, start, b->data, size) < 0){
36 a0d146ed 2005-07-12 devnull seterr(EAdmin, "can't read %s: %r", part->name);
37 a0d146ed 2005-07-12 devnull freezblock(b);
38 a0d146ed 2005-07-12 devnull return -1;
40 a0d146ed 2005-07-12 devnull f->name = part->name;
41 a0d146ed 2005-07-12 devnull f->b = b;
42 a0d146ed 2005-07-12 devnull f->pos = 0;
43 a0d146ed 2005-07-12 devnull return 0;
47 a0d146ed 2005-07-12 devnull * return the next non-blank input line,
48 a0d146ed 2005-07-12 devnull * stripped of leading white space and with # comments eliminated
51 a0d146ed 2005-07-12 devnull ifileline(IFile *f)
53 a0d146ed 2005-07-12 devnull char *s, *e, *t;
57 a0d146ed 2005-07-12 devnull s = (char*)&f->b->data[f->pos];
58 a0d146ed 2005-07-12 devnull e = memchr(s, '\n', f->b->len - f->pos);
59 a0d146ed 2005-07-12 devnull if(e == nil)
60 a0d146ed 2005-07-12 devnull return nil;
61 a0d146ed 2005-07-12 devnull *e++ = '\0';
62 a0d146ed 2005-07-12 devnull f->pos = e - (char*)f->b->data;
63 a0d146ed 2005-07-12 devnull t = strchr(s, '#');
64 a0d146ed 2005-07-12 devnull if(t != nil)
65 a0d146ed 2005-07-12 devnull *t = '\0';
66 a0d146ed 2005-07-12 devnull for(; c = *s; s++)
67 a0d146ed 2005-07-12 devnull if(c != ' ' && c != '\t' && c != '\r')
68 a0d146ed 2005-07-12 devnull return s;
73 a0d146ed 2005-07-12 devnull ifilename(IFile *f, char *dst)
77 a0d146ed 2005-07-12 devnull s = ifileline(f);
78 a0d146ed 2005-07-12 devnull if(s == nil || strlen(s) >= ANameSize)
79 a0d146ed 2005-07-12 devnull return -1;
80 a0d146ed 2005-07-12 devnull namecp(dst, s);
81 a0d146ed 2005-07-12 devnull return 0;
85 a0d146ed 2005-07-12 devnull ifileu32int(IFile *f, u32int *r)
89 a0d146ed 2005-07-12 devnull s = ifileline(f);
90 a0d146ed 2005-07-12 devnull if(s == nil)
91 a0d146ed 2005-07-12 devnull return -1;
92 a0d146ed 2005-07-12 devnull return stru32int(s, r);