Skip to content

Commit

Permalink
Initial work on adding a progress bar to s1kd-validate
Browse files Browse the repository at this point in the history
  • Loading branch information
kibook committed Dec 26, 2024
1 parent b0cb3c0 commit 4553160
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tools/s1kd-validate/s1kd-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "stats.h"

#define PROG_NAME "s1kd-validate"
#define VERSION "4.2.0"
#define VERSION "4.3.0"

#define ERR_PREFIX PROG_NAME ": ERROR: "
#define SUCCESS_PREFIX PROG_NAME ": SUCCESS: "
Expand All @@ -24,6 +24,11 @@
#define EXIT_MAX_SCHEMAS 2
#define EXIT_MISSING_SCHEMA 3

/* Progress formats. */
#define PROGRESS_OFF 0
#define PROGRESS_CLI 1
#define PROGRESS_ZENITY 2

/* FIXME:
*
* libxml2 XML schema validation does not currently check IDREF/IDREFS, so this
Expand Down Expand Up @@ -191,7 +196,7 @@ static struct s1kd_schema_parser *add_schema_parser(char *url)

static void show_help(void)
{
puts("Usage: " PROG_NAME " [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv^h?] [<object>...]");
puts("Usage: " PROG_NAME " [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elpqTv^h?] [<object>...]");
puts("");
puts("Options:");
puts(" -e, --ignore-empty Ignore empty/non-XML documents.");
Expand All @@ -200,6 +205,7 @@ static void show_help(void)
puts(" -h, -?, --help Show help/usage message.");
puts(" -l, --list Treat input as list of filenames.");
puts(" -o, --output-valid Output valid CSDB objects to stdout.");
puts(" -p, --progress Display progress bar.");
puts(" -q, --quiet Silent (no output).");
puts(" -s, --schema <path> Validate against the given schema.");
puts(" -T, --summary Print a summary of the check.");
Expand All @@ -208,6 +214,7 @@ static void show_help(void)
puts(" -x, --xml Output an XML report.");
puts(" -^, --remove-deleted Validate with elements marked as \"delete\" removed.");
puts(" --version Show version information.");
puts(" --zenity-progress Prints progress information in the zenity --progress format.");
puts(" <object> Any number of CSDB objects to validate.");
LIBXML2_PARSE_LONGOPT_HELP
}
Expand Down Expand Up @@ -516,17 +523,19 @@ int main(int argc, char *argv[])
char *schema = NULL;
int xml = 0;
int show_stats = 0;
int show_progress = PROGRESS_OFF;

xmlNodePtr ignore_ns;

const char *sopts = "vqX:xFfloes:T^h?";
const char *sopts = "vpqX:xFfloes:T^h?";
struct option lopts[] = {
{"version" , no_argument , 0, 0},
{"help" , no_argument , 0, 'h'},
{"valid-filenames", no_argument , 0, 'F'},
{"filenames" , no_argument , 0, 'f'},
{"list" , no_argument , 0, 'l'},
{"output-valid" , no_argument , 0, 'o'},
{"progress" , no_argument , 0, 'p'},
{"quiet" , no_argument , 0, 'q'},
{"verbose" , no_argument , 0, 'v'},
{"exclude" , required_argument, 0, 'X'},
Expand All @@ -535,6 +544,7 @@ int main(int argc, char *argv[])
{"summary" , no_argument , 0, 'T'},
{"xml" , no_argument , 0, 'x'},
{"remove-deleted" , no_argument , 0, '^'},
{"zenity-progress", no_argument , 0, 0},
LIBXML2_PARSE_LONGOPT_DEFS
{0, 0, 0, 0}
};
Expand All @@ -551,8 +561,12 @@ int main(int argc, char *argv[])
show_version();
return EXIT_SUCCESS;
}
else if (strcmp(lopts[loptind].name, "zenity-progress") == 0) {
show_progress = PROGRESS_ZENITY;
}
LIBXML2_PARSE_LONGOPT_HANDLE(lopts, loptind, optarg)
break;
case 'p': show_progress = PROGRESS_CLI; break;
case 'q': verbosity = SILENT; break;
case 'v': verbosity = VERBOSE; break;
case 'X': add_ignore_ns(ignore_ns, optarg); break;
Expand Down Expand Up @@ -591,6 +605,17 @@ int main(int argc, char *argv[])
} else {
err += validate_file(argv[i], schema, ignore_ns, show_fnames, ignore_empty, rem_del);
}

switch (show_progress) {
case PROGRESS_OFF:
break;
case PROGRESS_CLI:
print_progress_bar(i - optind + 1, argc - i);
break;
case PROGRESS_ZENITY:
print_zenity_progress("Performing schema validation...", i - optind + 1, argc - i);
break;
}
}
} else if (is_list) {
err = validate_file_list(NULL, schema, ignore_ns, show_fnames, ignore_empty, rem_del);
Expand Down

0 comments on commit 4553160

Please sign in to comment.