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
|
/* $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 FILE *outfile;
extern bool dflag, Fflag, duflag, metafirst, hflag, siflag, noindent;
extern bool colorize, linktargetcolor, hyperflag;
extern const struct linedraw *linedraw;
extern int *dirs;
extern char *scheme, *authority;
static char info[512] = {0};
extern char realbasepath[PATH_MAX], xpattern[PATH_MAX];
extern size_t dirpathoffset;
int unix_printinfo(char *dirname, struct _info *file, int level)
{
UNUSED(dirname);
fillinfo(info, file);
if (metafirst) {
if (info[0] == '[') fprintf(outfile, "%s ",info);
if (!noindent) indent(level);
} else {
if (!noindent) indent(level);
if (info[0] == '[') fprintf(outfile, "%s ",info);
}
return 0;
}
void open_hyperlink(char *dirname, char *filename)
{
fprintf(outfile,"\033]8;;%s", scheme);
url_encode(outfile, authority);
url_encode(outfile, realbasepath);
url_encode(outfile, dirname+dirpathoffset);
fputc('/',outfile);
url_encode(outfile, filename);
fprintf(outfile,"\033\\");
}
void close_hyperlink(void)
{
fprintf(outfile, "\033]8;;\033\\");
}
int unix_printfile(char *dirname, char *filename, struct _info *file, int descend)
{
UNUSED(descend);
bool colored = false;
int c;
if (hyperflag) open_hyperlink(dirname, file->name);
if (file && colorize) {
if (file->lnk && linktargetcolor) colored = color(file->lnkmode, file->name, file->orphan, false);
else colored = color(file->mode, file->name, file->orphan, false);
}
printit(filename);
if (colored) endcolor();
if (hyperflag) close_hyperlink();
if (file) {
if (Fflag && !file->lnk) {
if ((c = Ftype(file->mode))) fputc(c, outfile);
}
if (file->lnk) {
fprintf(outfile," -> ");
if (hyperflag) open_hyperlink(dirname, file->name);
if (colorize) colored = color(file->lnkmode, file->lnk, file->orphan, true);
printit(file->lnk);
if (colored) endcolor();
if (hyperflag) close_hyperlink();
if (Fflag) {
if ((c = Ftype(file->lnkmode))) fputc(c, outfile);
}
}
}
return 0;
}
int unix_error(char *error)
{
fprintf(outfile, " [%s]", error);
return 0;
}
void unix_newline(struct _info *file, int level, int postdir, int needcomma)
{
UNUSED(needcomma);
if (postdir <= 0) fprintf(outfile, "\n");
if (file && file->comment) {
size_t infosize = 0, line, lines;
if (metafirst) infosize = info[0] == '['? strlen(info)+2 : 0;
for(lines = 0; file->comment[lines]; lines++);
dirs[level+1] = 1;
for(line = 0; line < lines; line++) {
if (metafirst) {
printf("%*s", (int)infosize, "");
}
indent(level);
printcomment(line, lines, file->comment[line]);
}
dirs[level+1] = 0;
}
}
void unix_report(struct totals tot)
{
char buf[256];
fputc('\n', outfile);
if (duflag) {
psize(buf, tot.size);
fprintf(outfile,"%s%s usados em ", buf, hflag || siflag ? "" : " bytes");
}
if (dflag)
fprintf(outfile,"%ld diretório%s\n", tot.dirs, (tot.dirs == 1 ? "" : "s"));
else
fprintf(outfile,"%ld diretório%s, %ld arquivo%s\n", tot.dirs, (tot.dirs == 1 ? "" : "s"), tot.files, (tot.files == 1 ? "" : "s"));
}
|