This is the full source code of the cmml-validate program, which parses a CMML instance document and validates it against the cmml.dtd returning true/false. In case of an error the faulty tag including line and col number is reported. It also spits out warnings for strange stuff.
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#ifndef WIN32
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#define BUFSIZE 100000
static void
fprintf(stderr, "Usage: %s [options] filename\n", prog);
fprintf(stderr, "Validate a CMML file.\n\n");
fprintf(stderr, "Possible options:\n");
#ifdef HAVE_GETOPT_LONG
fprintf(stderr, " -i clip_id, --id clip_id\n");
fprintf(stderr, " Start parsing from the named clip.\n");
fprintf(stderr, " -s seconds, --sec seconds\n");
fprintf(stderr, " Start parsing from the given seconds offset\n");
fprintf(stderr, " -u utc, --utc utc\n");
fprintf(stderr, " Start parsing from the given utc time\n");
fprintf(stderr, " -b, --verbose Output parsed file to stdout\n");
fprintf(stderr, " -h, --help Display this help information\n");
fprintf(stderr, " -v, --version Display version information\n");
#else
fprintf(stderr, " -i clip_id Start parsing from the named clip\n");
fprintf(stderr, " -s seconds Start parsing from the given seconds offset\n");
fprintf(stderr, " -u utc Start parsing from the given utc time\n");
fprintf(stderr, " -b Output parsed file to stdout\n");
fprintf(stderr, " -h Display this help information\n");
fprintf(stderr, " -v Display version information\n");
#endif
fprintf(stderr, "\nPlease report bugs to <libcmml-devel@cmis.csiro.au>.\n");
exit(1);
}
static int
fprintf(stderr, "cmml-validate: Parsing stream tag %s\n", buf);
fprintf(stderr, "cmml-validate: Non-recoverable error\n");
return -1;
} else {
fprintf(stdout, "%s\n", buf);
}
} return 0;
}
static int
fprintf(stderr, "cmml-validate: Parsing head tag %s\n", buf);
fprintf(stderr, "cmml-validate: Non-recoverable error\n");
return -1;
} else {
fprintf(stdout, "%s\n", buf);
}
}
return 0;
}
static int
fprintf(stderr, "cmml-validate: Parsing clip %s\n", buf);
fprintf(stderr, "cmml-validate: Skipping clip\n\n");
return -1;
} else {
fprintf(stdout, "%s\n", buf);
}
}
return 0;
}
int main(
int argc,
char *argv[])
{
char *pathfile = NULL;
int i;
long n = 0;
char * clip_id = NULL;
char * utc = NULL;
int sloppy = 0;
while (1) {
char * optstring = "hvbyi:s:u:";
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
{"help",no_argument,0,'h'},
{"version",no_argument,0, 'v'},
{"verbose",no_argument,0,'b'},
{"sloppy",no_argument,0,'y'},
{"id",required_argument,0,'i'},
{"sec",required_argument,0,'s'},
{"utc",required_argument,0,'u'},
{0,0,0,0}
};
i = getopt_long(argc, argv, optstring, long_options, NULL);
#else
i = getopt(argc, argv, optstring);
#endif
if (i == -1) break;
switch (i) {
case 'h':
break;
case 'v':
fprintf(stdout, "cmml-validate version " VERSION "\n");
fprintf(stdout, "# cmml-validate, Copyright (C) 2003 CSIRO Australia www.csiro.au ; www.annodex.net\n");
break;
case 'i':
clip_id = optarg;
break;
case 's':
if (!isalpha(optarg[0])) {
secs = atof(optarg);
}
break;
case 'u':
utc = optarg;
break;
case 'y':
sloppy = 1;
break;
case 'b':
break;
default:
break;
}
}
if (optind > argc) {
}
if (optind == argc) {
pathfile = "-";
} else {
pathfile = argv[optind++];
}
errno=0;
if (strcmp (pathfile, "-") == 0) {
} else {
}
if (doc == NULL) {
if (errno == 0) {
fprintf(stderr, "%s: %s: CMML error opening file\n", argv[0], pathfile);
} else {
fprintf(stderr, "%s: %s: %s\n", argv[0], pathfile, strerror(errno));
}
}
if (sloppy) {
}
fprintf(stdout, "%s\n", buf);
}
if (clip_id != NULL) {
}
if (secs > 0 || utc != NULL) {
if (secs > 0) {
} else {
}
}
char *filename;
filename = (strrchr(pathfile, '/') == NULL ? pathfile
: strrchr(pathfile, '/')+1);
fprintf (stderr, "%s:%s\n", filename, buf);
goto cleanup;
}
}
char *filename;
filename = (strrchr(pathfile, '/') == NULL ? pathfile
: strrchr(pathfile, '/')+1);
fprintf (stderr, "%s:%s\n", filename, buf);
goto cleanup;
}
fprintf(stdout, "</cmml>\n");
}
cleanup:
return 0;
}