/*
Copyright (C) 2016 Xfennec, CQFD Corp.
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
#include <libgen.h>
#include <time.h>
#include <signal.h>
#include <stdarg.h>
#include <assert.h>
#include <curses.h>
#include <locale.h>
#include <wordexp.h>
#include <getopt.h>
#include <sys/ioctl.h>
// for the BLKGETSIZE64 code section
#include <fcntl.h>
#include <sys/ioctl.h>
#ifdef __APPLE__
# include <unistd.h>
# include <sys/proc_info.h>
# include <libproc.h>
# include <sys/disk.h>
#endif // __APPLE__
#ifdef __linux__
# include <linux/fs.h>
#endif // __linux__
#ifdef __FreeBSD__
# include <sys/disk.h>
#endif // __FreeBSD__
#ifdef __FreeBSD__
# include <sys/param.h>
# include <sys/queue.h>
# include <sys/socket.h>
# include <sys/sysctl.h>
# include <sys/user.h>
# include <libprocstat.h>
#endif
#include "progress.h"
#include "sizes.h"
#include "hlist.h"
// Given -a will dynamically add values to this list, move it to be a dynamic
// list and generate it at runtime.
static int proc_names_cnt;
static char **proc_names;
char *default_proc_names[] = {"cp", "mv", "dd", "tar", "bsdtar", "cat", "rsync", "scp",
"grep", "fgrep", "egrep", "cut", "sort", "md5sum", "sha1sum",
"sha224sum", "sha256sum", "sha384sum", "sha512sum",
#ifdef __FreeBSD__
"md5", "sha1", "sha224", "sha256", "sha512", "sha512t256", "rmd160",
"skein256", "skein512", "skein1024",
#endif
"adb",
"gzip", "gunzip", "bzip2", "bunzip2", "xz", "unxz", "lzma", "unlzma", "7z", "7za", "zip", "unzip",
"zcat", "bzcat", "lzcat",
"coreutils",
"split",
"gpg",
#if defined(__APPLE__) || defined(__FreeBSD__)
"gcp", "gmv",
#endif
NULL
};
// static means initialized to 0/NULL (C standard, ยง6.7.8/10)
static int proc_specifiq_name_cnt;
static char **proc_specifiq_name;
static int ignore_file_list_cnt;
static char **ignore_file_list;
static int proc_specifiq_pid_cnt;
static pid_t *proc_specifiq_pid;
signed char flag_quiet = 0;
signed char flag_debug = 0;
signed char flag_throughput = 0;
signed char flag_monitor = 0;
signed char flag_monitor_continuous = 0;
signed char flag_open_mode = 0;
double throughput_wait_secs = 1;
WINDOW *mainwin;
signed char is_numeric(char *str)
{
while (*str) {
if(!isdigit(*str))
return 0;
str++;
}
return <