#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include "pkgstrct.h"
#include "pkglib.h"
int
putcfile(struct cfent *a_ept, FILE *a_fp)
{
struct pinfo *pinfo;
if (a_ept->ftype == 'i') {
return (0);
}
if (a_ept->path == NULL) {
return (-1);
}
if (fputs(a_ept->path, a_fp) == EOF) {
return (-1);
}
if (a_ept->ainfo.local) {
if (putc('=', a_fp) == EOF) {
return (-1);
}
if (fputs(a_ept->ainfo.local, a_fp) == EOF)
return (-1);
}
if (a_ept->volno) {
if (fprintf(a_fp, " %d", a_ept->volno) < 0) {
return (-1);
}
}
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (putc(a_ept->ftype, a_fp) == EOF) {
return (-1);
}
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (fputs(a_ept->pkg_class, a_fp) == EOF) {
return (-1);
}
if ((a_ept->ftype == 'c') || (a_ept->ftype == 'b')) {
if (a_ept->ainfo.major == BADMAJOR) {
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (putc('?', a_fp) == EOF) {
return (-1);
}
} else {
if (fprintf(a_fp, " %ld", a_ept->ainfo.major) < 0)
return (-1);
}
if (a_ept->ainfo.minor == BADMINOR) {
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (putc('?', a_fp) == EOF) {
return (-1);
}
} else {
if (fprintf(a_fp, " %ld", a_ept->ainfo.minor) < 0)
return (-1);
}
}
if ((a_ept->ftype == 'd') || (a_ept->ftype == 'x') ||
(a_ept->ftype == 'c') || (a_ept->ftype == 'b') ||
(a_ept->ftype == 'p') || (a_ept->ftype == 'f') ||
(a_ept->ftype == 'v') || (a_ept->ftype == 'e')) {
if (fprintf(a_fp,
((a_ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
a_ept->ainfo.mode) < 0)
return (-1);
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (fputs(a_ept->ainfo.owner, a_fp) == EOF) {
return (-1);
}
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (fputs(a_ept->ainfo.group, a_fp) == EOF) {
return (-1);
}
}
if ((a_ept->ftype == 'f') || (a_ept->ftype == 'v') ||
(a_ept->ftype == 'e')) {
if (fprintf(a_fp,
((a_ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
a_ept->cinfo.size) < 0)
return (-1);
if (fprintf(a_fp,
((a_ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
a_ept->cinfo.cksum) < 0)
return (-1);
if (fprintf(a_fp,
((a_ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
a_ept->cinfo.modtime) < 0)
return (-1);
}
pinfo = a_ept->pinfo;
while (pinfo) {
if (putc(' ', a_fp) == EOF) {
return (-1);
}
if (pinfo->status) {
if (fputc(pinfo->status, a_fp) == EOF) {
return (-1);
}
}
if (fputs(pinfo->pkg, a_fp) == EOF) {
return (-1);
}
if (pinfo->editflag) {
if (putc('\\', a_fp) == EOF) {
return (-1);
}
}
if (pinfo->aclass[0]) {
if (putc(':', a_fp) == EOF) {
return (-1);
}
if (fputs(pinfo->aclass, a_fp) == EOF) {
return (-1);
}
}
pinfo = pinfo->next;
}
if (putc('\n', a_fp) == EOF) {
return (-1);
}
return (0);
}
int
putcvfpfile(struct cfent *a_ept, VFP_T *a_vfp)
{
struct pinfo *pinfo;
if (a_ept->ftype == 'i') {
return (0);
}
if (a_ept->path == NULL) {
return (-1);
}
(void) vfpSetModified(a_vfp);
vfpPuts(a_vfp, a_ept->path);
if (a_ept->ainfo.local) {
vfpPutc(a_vfp, '=');
vfpPuts(a_vfp, a_ept->ainfo.local);
}
if (a_ept->volno) {
vfpPutc(a_vfp, ' ');
vfpPutInteger(a_vfp, a_ept->volno);
}
vfpPutc(a_vfp, ' ');
vfpPutc(a_vfp, a_ept->ftype);
vfpPutc(a_vfp, ' ');
vfpPuts(a_vfp, a_ept->pkg_class);
if ((a_ept->ftype == 'c') || (a_ept->ftype == 'b')) {
if (a_ept->ainfo.major == BADMAJOR) {
vfpPutc(a_vfp, ' ');
vfpPutc(a_vfp, '?');
} else {
vfpPutc(a_vfp, ' ');
vfpPutInteger(a_vfp, a_ept->ainfo.major);
}
if (a_ept->ainfo.minor == BADMINOR) {
vfpPutc(a_vfp, ' ');
vfpPutc(a_vfp, '?');
} else {
vfpPutc(a_vfp, ' ');
vfpPutInteger(a_vfp, a_ept->ainfo.minor);
}
}
if ((a_ept->ftype == 'd') || (a_ept->ftype == 'x') ||
(a_ept->ftype == 'c') || (a_ept->ftype == 'b') ||
(a_ept->ftype == 'p') || (a_ept->ftype == 'f') ||
(a_ept->ftype == 'v') || (a_ept->ftype == 'e')) {
vfpPutFormat(a_vfp,
((a_ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
a_ept->ainfo.mode);
vfpPutc(a_vfp, ' ');
vfpPuts(a_vfp, a_ept->ainfo.owner);
vfpPutc(a_vfp, ' ');
vfpPuts(a_vfp, a_ept->ainfo.group);
}
if ((a_ept->ftype == 'f') || (a_ept->ftype == 'v') ||
(a_ept->ftype == 'e')) {
vfpPutFormat(a_vfp,
((a_ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
a_ept->cinfo.size);
vfpPutFormat(a_vfp,
((a_ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
a_ept->cinfo.cksum);
vfpPutFormat(a_vfp,
((a_ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
a_ept->cinfo.modtime);
}
pinfo = a_ept->pinfo;
while (pinfo) {
vfpPutc(a_vfp, ' ');
if (pinfo->status) {
vfpPutc(a_vfp, pinfo->status);
}
vfpPuts(a_vfp, pinfo->pkg);
if (pinfo->editflag) {
vfpPutc(a_vfp, '\\');
}
if (pinfo->aclass[0]) {
vfpPutc(a_vfp, ':');
vfpPuts(a_vfp, pinfo->aclass);
}
pinfo = pinfo->next;
}
vfpPutc(a_vfp, '\n');
return (0);
}