2
* Copyright (c) 2003-2004 Silicon Graphics, Inc. All Rights Reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of version 2 of the GNU General Public License as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it would be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* Further, this software is distributed without any warranty that it is
13
* free of the rightful claim of any third person regarding infringement
14
* or the like. Any license provided herein, whether implied or
15
* otherwise, applies only to this software file. Patent licenses, if
16
* any, provided herein do not apply to combinations of this program with
17
* other software, or any other product whatsoever.
19
* You should have received a copy of the GNU General Public License along
20
* with this program; if not, write the Free Software Foundation, Inc., 59
21
* Temple Place - Suite 330, Boston MA 02111-1307, USA.
23
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
* Mountain View, CA 94043, or:
28
* For further information regarding this notice, see:
30
* http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33
#include <xfs/libxfs.h>
38
#if defined(ENABLE_READLINE)
39
# include <readline/history.h>
40
# include <readline/readline.h>
41
#elif defined(ENABLE_EDITLINE)
42
# include <histedit.h>
48
static char prompt[FILENAME_MAX + 1];
51
snprintf(prompt, sizeof(prompt), "%s> ", progname);
55
#if defined(ENABLE_READLINE)
61
line = readline(get_prompt());
66
#elif defined(ENABLE_EDITLINE)
67
static char *el_get_prompt(EditLine *e) { return get_prompt(); }
78
hist = history_init();
79
history(hist, &hevent, H_SETSIZE, 100);
80
el = el_init(progname, stdin, stdout, stderr);
82
el_set(el, EL_SIGNAL, 1);
83
el_set(el, EL_PROMPT, el_get_prompt);
84
el_set(el, EL_HIST, history, (const char *)hist);
86
line = strdup(el_gets(el, &count));
91
history(hist, &hevent, H_ENTER, line);
96
# define MAXREADLINESZ 1024
100
char *p, *line = malloc(MAXREADLINESZ);
104
printf(get_prompt());
106
if (!fgets(line, MAXREADLINESZ, stdin)) {
110
p = line + strlen(line);
111
if (p != line && p[-1] == '\n')
124
char **rval = calloc(sizeof(char *), 1);
126
while ((p = strsep(&input, " ")) != NULL) {
130
rval = realloc(rval, sizeof(*rval) * (c + 1));
152
if (!file || (file->flags & IO_FOREIGN)) {
156
*blocksize = file->geom.blocksize;
157
*sectsize = file->geom.sectsize;
161
#define EXABYTES(x) ((long long)(x) << 60)
162
#define PETABYTES(x) ((long long)(x) << 50)
163
#define TERABYTES(x) ((long long)(x) << 40)
164
#define GIGABYTES(x) ((long long)(x) << 30)
165
#define MEGABYTES(x) ((long long)(x) << 20)
166
#define KILOBYTES(x) ((long long)(x) << 10)
177
i = strtoll(s, &sp, 0);
178
if (i == 0 && sp == s)
183
if (*sp == 'b' && sp[1] == '\0')
184
return i * blocksize;
185
if (*sp == 's' && sp[1] == '\0')
186
return i * sectorsize;
187
if (*sp == 'k' && sp[1] == '\0')
189
if (*sp == 'm' && sp[1] == '\0')
191
if (*sp == 'g' && sp[1] == '\0')
193
if (*sp == 't' && sp[1] == '\0')
195
if (*sp == 'p' && sp[1] == '\0')
197
if (*sp == 'e' && sp[1] == '\0')
202
#define TO_EXABYTES(x) ((x) / EXABYTES(1))
203
#define TO_PETABYTES(x) ((x) / PETABYTES(1))
204
#define TO_TERABYTES(x) ((x) / TERABYTES(1))
205
#define TO_GIGABYTES(x) ((x) / GIGABYTES(1))
206
#define TO_MEGABYTES(x) ((x) / MEGABYTES(1))
207
#define TO_KILOBYTES(x) ((x) / KILOBYTES(1))
218
precise = ((double)value * 1000 == (double)(int)value * 1000);
220
if (value >= EXABYTES(1)) {
221
fmt = precise ? "%.f EiB" : "%.3f EiB";
222
snprintf(str, size, fmt, TO_EXABYTES(value));
223
} else if (value >= PETABYTES(1)) {
224
fmt = precise ? "%.f PiB" : "%.3f PiB";
225
snprintf(str, size, fmt, TO_PETABYTES(value));
226
} else if (value >= TERABYTES(1)) {
227
fmt = precise ? "%.f TiB" : "%.3f TiB";
228
snprintf(str, size, fmt, TO_TERABYTES(value));
229
} else if (value >= GIGABYTES(1)) {
230
fmt = precise ? "%.f GiB" : "%.3f GiB";
231
snprintf(str, size, fmt, TO_GIGABYTES(value));
232
} else if (value >= MEGABYTES(1)) {
233
fmt = precise ? "%.f MiB" : "%.3f MiB";
234
snprintf(str, size, fmt, TO_MEGABYTES(value));
235
} else if (value >= KILOBYTES(1)) {
236
fmt = precise ? "%.f KiB" : "%.3f KiB";
237
snprintf(str, size, fmt, TO_KILOBYTES(value));
239
snprintf(str, size, "%f bytes", value);
244
tsub(struct timeval t1, struct timeval t2)
246
t1.tv_usec -= t2.tv_usec;
247
if (t1.tv_usec < 0) {
248
t1.tv_usec += 1000000;
251
t1.tv_sec -= t2.tv_sec;
256
tdiv(double value, struct timeval tv)
258
return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
261
#define HOURS(sec) ((sec) / (60 * 60))
262
#define MINUTES(sec) (((sec) % (60 * 60)) / 60)
263
#define SECONDS(sec) ((sec) % 60)
272
snprintf(ts, size, "%.4f sec",
273
((double) tv->tv_usec / 1000000.0));
275
snprintf(ts, size, "%02u:%02u:%02u.%-u",
276
(unsigned int) HOURS(tv->tv_sec),
277
(unsigned int) MINUTES(tv->tv_sec),
278
(unsigned int) SECONDS(tv->tv_sec),
279
(unsigned int) tv->tv_usec);