Lines Matching defs:pz
23 * pz header support
29 * read the pz header from pz->io
33 pzheadread(register Pz_t* pz)
41 if (pz->flags & PZ_HEAD)
48 if (s = (unsigned char*)sfreserve(pz->io, 4, 1))
55 if (pz->disc->errorf)
56 (*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzheadread: f=%08x i=%02x n=%02x partition=%s%s", pz->path, pz->flags, i, n, pz->disc->partition, s ? "" : " (nil)");
59 sfread(pz->io, s, 0);
60 if (pz->flags & PZ_SPLIT)
62 if (pz->flags & PZ_DISC)
64 pz->flags &= ~PZ_POP;
67 if (!(pz->flags & (PZ_READ|PZ_WRITE|PZ_STAT)) && (m = pz->prefix.count))
69 if (pz->prefix.terminator >= 0)
73 if (!sfgetr(pz->io, pz->prefix.terminator, 0))
75 if (pz->disc->errorf)
76 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix record%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
81 else if (!sfreserve(pz->io, m, 0))
83 if (pz->disc->errorf)
84 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix byte%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
88 if (!(n = pz->row))
90 if ((pz->flags & PZ_ACCEPT) || !sfsize(pz->io))
92 else if ((n = pzfixed(pz, pz->io, NiL, 0)) <= 0 && pz->disc->partition)
94 pz->flags |= PZ_ROWONLY;
95 if (!pzpartition(pz, pz->disc->partition))
96 n = pz->row;
97 pz->flags &= ~PZ_ROWONLY;
102 if (!(pz->flags & PZ_DELAY) && (pz->disc->partition || !(pz->flags & PZ_FORCE)))
104 if (pz->disc->errorf)
105 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: unknown input format", pz->path);
108 pz->flags |= PZ_UNKNOWN;
111 if (!(pp = vmnewof(pz->vm, 0, Pzpart_t, 1, 0)))
113 pz->major = PZ_MAJOR;
114 pz->minor = PZ_MINOR;
117 return pzpartinit(pz, pp, NiL);
119 sfread(pz->io, s, 2);
120 pz->flags &= ~PZ_FORCE;
121 pz->major = sfgetc(pz->io);
122 pz->minor = sfgetc(pz->io);
123 switch (pz->major)
126 if (pz->minor <= 2)
130 pz->win = sfgetu(pz->io);
135 pz->flags |= PZ_HEAD;
136 return pzpartread(pz);
138 if (pz->disc->errorf)
139 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: data %d.%d not supported by implementation %d.%d", pz->path, pz->major, pz->minor, PZ_MAJOR, PZ_MINOR);
144 * write the pz header to op
148 pzheadwrite(Pz_t* pz, Sfio_t* op)
155 if (pz->flags & PZ_HEAD)
157 pz->oop = op;
158 if (!(pz->flags & PZ_NOGZIP))
160 if (pz->flags & PZ_NOPZIP)
166 sfputc(op, pz->major = PZ_MAJOR);
167 sfputc(op, pz->minor = PZ_MINOR);
168 sfputu(op, pz->win);
169 if (pz->disc->comment)
172 m = strlen(pz->disc->comment) + 1;
174 sfwrite(op, pz->disc->comment, m);
176 if (pz->det && (m = sfstrtell(pz->det)))
179 if (!(s = sfstruse(pz->det)))
181 if (pz->disc->errorf)
182 (*pz->disc->errorf)(pz, pz->disc, ERROR_SYSTEM|2, "out of space");
189 if (i = pz->prefix.count)
192 if (pz->prefix.terminator >= 0)
197 if (!(s = sfgetr(pz->io, pz->prefix.terminator, 0)))
199 if (pz->disc->errorf)
200 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix record%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
203 m += n = sfvalue(pz->io);
204 sfwrite(pz->tmp, s, n);
206 s = sfstrseek(pz->tmp, 0, SEEK_SET);
211 if (!(s = (char*)sfreserve(pz->io, m, 0)))
213 if (pz->disc->errorf)
214 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix byte%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
221 pz->flags |= PZ_HEAD;
222 return pzpartwrite(pz, op);
230 pzheadprint(register Pz_t* pz, register Sfio_t* op, int parts)
235 if (pz->flags & PZ_FORCE)
239 sfprintf(op, "# pzip %d.%d partition\n", pz->major, pz->minor);
240 if (pz->disc->comment)
241 sfprintf(op, "# %s\n", pz->disc->comment);
242 sfprintf(op, "# window %I*u\n", sizeof(pz->win), pz->win);
243 if (pz->prefix.count)
245 sfprintf(op, "\nprefix=%I*u", sizeof(pz->prefix.count), pz->prefix.count);
246 if (pz->prefix.terminator >= 0)
248 t = pz->prefix.terminator;
254 if (pz->headoptions || pz->det)
257 if (pz->headoptions)
258 sfputr(op, pz->headoptions, '\n');
259 if (pz->det)
261 sfwrite(op, sfstrbase(pz->det), sfstrtell(pz->det));
268 pp = pz->partdict ? (Pzpart_t*)dtfirst(pz->partdict) : pz->part;
271 if (pzpartprint(pz, pp, op))
273 if (!pz->partdict)
275 pp = (Pzpart_t*)dtnext(pz->partdict, pp);
288 * 1 another file found (and initialized in pz)
292 pzfile(Pz_t* pz)
303 while (!(i = sfgetc(pz->io)));
304 if (pz->disc->errorf)
305 (*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzfile: i=%02x", pz->path, i);
314 while ((n = sfgetu(pz->io)) && !sferror(pz->io) && !sfeof(pz->io) && (s = (unsigned char*)sfreserve(pz->io, n, 0)))
315 if (pz->disc->eventf && (*pz->disc->eventf)(pz, PZ_TAILREAD, s, n, pz->disc) < 0)
317 if ((i = sfgetc(pz->io)) == -1)
320 j = sfgetc(pz->io);
321 if (pz->disc->errorf)
322 (*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzfile: i=%02x j=%02x", pz->path, i, j);
329 sfungetc(pz->io, j);
330 sfungetc(pz->io, i);
331 return pzopen(pz->disc, (char*)pz, PZ_AGAIN) ? 1 : -1;
333 if (pz->disc->errorf)
334 (*pz->disc->errorf)(pz, pz->disc, 2, "%s: data corrupted", pz->path);