1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/* $Copyright: $
* Copyright (c) 1996 - 2024 by Steve Baker (steve.baker.llc@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tree.h"
extern bool dflag, pflag, sflag, uflag, gflag;
extern bool Dflag, inodeflag, devflag, cflag, duflag;
extern bool noindent;
extern const char *charset;
extern const mode_t ifmt[];
extern const char *ftype[];
extern FILE *outfile;
/*
<tree>
<directory name="name" mode=0777 size=### user="user" group="group" inode=### dev=### time="00:00 00-00-0000">
<link name="name" target="name" ...>
... if link is followed, otherwise this is empty.
</link>
<file name="name" mode=0777 size=### user="user" group="group" inode=### dev=### time="00:00 00-00-0000"></file>
<socket name="" ...><error>some error</error></socket>
<block name="" ...></block>
<char name="" ...></char>
<fifo name="" ...></fifo>
<door name="" ...></door>
<port name="" ...></port>
...
</directory>
<report>
<size>#</size>
<files>#</files>
<directories>#</directories>
</report>
</tree>
*/
void xml_indent(int maxlevel)
{
int i;
fprintf(outfile, " ");
for(i=0; i<maxlevel; i++)
fprintf(outfile, " ");
}
void xml_fillinfo(struct _info *ent)
{
#ifdef __USE_FILE_OFFSET64
if (inodeflag) fprintf(outfile," inode=\"%lld\"",(long long)ent->inode);
#else
if (inodeflag) fprintf(outfile," inode=\"%ld\"",(long int)ent->inode);
#endif
if (devflag) fprintf(outfile, " dev=\"%d\"", (int)ent->dev);
#ifdef __EMX__
if (pflag) fprintf(outfile, " mode=\"%04o\" prot=\"%s\"",ent->attr, prot(ent->attr));
#else
if (pflag) fprintf(outfile, " mode=\"%04o\" prot=\"%s\"", ent->mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX), prot(ent->mode));
#endif
if (uflag) fprintf(outfile, " user=\"%s\"", uidtoname(ent->uid));
if (gflag) fprintf(outfile, " group=\"%s\"", gidtoname(ent->gid));
if (sflag) fprintf(outfile, " size=\"%lld\"", (long long int)(ent->size));
if (Dflag) fprintf(outfile, " time=\"%s\"", do_date(cflag? ent->ctime : ent->mtime));
}
void xml_intro(void)
{
extern char *_nl;
fprintf(outfile,"<?xml version=\"1.0\"");
if (charset) fprintf(outfile," encoding=\"%s\"",charset);
fprintf(outfile,"?>%s<tree>%s",_nl,_nl);
}
void xml_outtro(void)
{
fprintf(outfile,"</tree>\n");
}
int xml_printinfo(char *dirname, struct _info *file, int level)
{
UNUSED(dirname);
mode_t mt;
int t;
if (!noindent) xml_indent(level);
if (file != NULL) {
if (file->lnk) mt = file->mode & S_IFMT;
else mt = file->mode & S_IFMT;
} else mt = 0;
for(t=0;ifmt[t];t++)
if (ifmt[t] == mt) break;
if (file) file->tag = ftype[t];
fprintf(outfile,"<%s", ftype[t]);
return 0;
}
int xml_printfile(char *dirname, char *filename, struct _info *file, int descend)
{
UNUSED(dirname);UNUSED(descend);
int i;
fprintf(outfile, " name=\"");
html_encode(outfile, filename);
fputc('"',outfile);
if (file && file->comment) {
fprintf(outfile, " info=\"");
for(i=0; file->comment[i]; i++) {
html_encode(outfile, file->comment[i]);
if (file->comment[i+1]) fprintf(outfile, "\n");
}
fputc('"', outfile);
}
if (file && file->lnk) {
fprintf(outfile, " target=\"");
html_encode(outfile,file->lnk);
fputc('"',outfile);
}
if (file) xml_fillinfo(file);
fputc('>',outfile);
return 1;
}
int xml_error(char *error)
{
fprintf(outfile,"<error>%s</error>", error);
return 0;
}
void xml_newline(struct _info *file, int level, int postdir, int needcomma)
{
UNUSED(file);UNUSED(level);UNUSED(needcomma);
if (postdir >= 0) fprintf(outfile, "\n");
}
void xml_close(struct _info *file, int level, int needcomma)
{
UNUSED(needcomma);
if (!noindent && level >= 0) xml_indent(level);
fprintf(outfile,"</%s>%s", file? file->tag : "unknown", noindent? "" : "\n");
}
void xml_report(struct totals tot)
{
extern char *_nl;
fprintf(outfile,"%s<report>%s",noindent?"":" ", _nl);
if (duflag) fprintf(outfile,"%s<size>%lld</size>%s", noindent?"":" ", (long long int)tot.size, _nl);
fprintf(outfile,"%s<directories>%ld</directories>%s", noindent?"":" ", tot.dirs, _nl);
if (!dflag) fprintf(outfile,"%s<files>%ld</files>%s", noindent?"":" ", tot.files, _nl);
fprintf(outfile,"%s</report>%s",noindent?"":" ", _nl);
}
|