1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File main.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 06/10/99 stephen Creation.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-01-21 03:26:21 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2000-01-21 03:26:21 +00:00
|
|
|
|
|
|
|
/* because the file runs under C++ on HPUX */
|
|
|
|
U_CDECL_BEGIN
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "filestrm.h"
|
|
|
|
#include "parse.h"
|
2000-01-21 03:26:21 +00:00
|
|
|
U_CDECL_END
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Protos */
|
|
|
|
static void usage();
|
|
|
|
static void version();
|
|
|
|
static void processFile(const char *filename, UErrorCode *status);
|
|
|
|
int main(int argc, char **argv);
|
|
|
|
|
|
|
|
/* The version of rbdump */
|
|
|
|
#define RBDUMP_VERSION "1.0"
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
int printUsage = 0;
|
|
|
|
int printVersion = 0;
|
|
|
|
int optind = 1;
|
|
|
|
int i;
|
|
|
|
char *arg;
|
|
|
|
UErrorCode status;
|
|
|
|
|
|
|
|
|
|
|
|
/* parse the options */
|
|
|
|
for(optind = 1; optind < argc; ++optind) {
|
|
|
|
arg = argv[optind];
|
|
|
|
|
|
|
|
/* version info */
|
1999-12-28 23:57:50 +00:00
|
|
|
if(uprv_strcmp(arg, "-v") == 0 || uprv_strcmp(arg, "--version") == 0) {
|
1999-08-16 21:50:52 +00:00
|
|
|
printVersion = 1;
|
|
|
|
}
|
|
|
|
/* usage info */
|
1999-12-28 23:57:50 +00:00
|
|
|
else if(uprv_strcmp(arg, "-h") == 0 || uprv_strcmp(arg, "--help") == 0) {
|
1999-08-16 21:50:52 +00:00
|
|
|
printUsage = 1;
|
|
|
|
}
|
|
|
|
/* POSIX.1 says all arguments after -- are not options */
|
1999-12-28 23:57:50 +00:00
|
|
|
else if(uprv_strcmp(arg, "--") == 0) {
|
1999-08-16 21:50:52 +00:00
|
|
|
/* skip the -- */
|
|
|
|
++optind;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* unrecognized option */
|
1999-12-28 23:57:50 +00:00
|
|
|
else if(uprv_strncmp(arg, "-", uprv_strlen("-")) == 0) {
|
1999-08-16 21:50:52 +00:00
|
|
|
printf("rbdump: invalid option -- %s\n", arg+1);
|
|
|
|
printUsage = 1;
|
|
|
|
}
|
|
|
|
/* done with options, start file processing */
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print usage info */
|
|
|
|
if(printUsage) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print version info */
|
|
|
|
if(printVersion) {
|
|
|
|
version();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print out the files */
|
|
|
|
for(i = optind; i < argc; ++i) {
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
processFile(argv[i], &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)) {
|
1999-12-08 23:31:17 +00:00
|
|
|
printf("rbdump: %s processing file \"%s\"\n", u_errorName(status), argv[i]);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Usage information */
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
puts("Usage: rbdump [OPTIONS] [FILES]");
|
|
|
|
puts("Options:");
|
|
|
|
puts(" -h, --help Print this message and exit.");
|
|
|
|
puts(" -v, --version Print the version number of rbdump and exit.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Version information */
|
|
|
|
static void
|
|
|
|
version()
|
|
|
|
{
|
1999-12-22 22:57:04 +00:00
|
|
|
printf("rbdump version %s (ICU version %s).\n",
|
2000-01-12 01:34:41 +00:00
|
|
|
RBDUMP_VERSION, U_ICU_VERSION);
|
1999-12-13 22:28:37 +00:00
|
|
|
puts(U_COPYRIGHT_STRING);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process a file */
|
|
|
|
static void
|
|
|
|
processFile(const char *filename,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
FileStream *in;
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Setup */
|
|
|
|
in = 0;
|
|
|
|
|
|
|
|
/* Open the input file for reading */
|
|
|
|
in = T_FileStream_open(filename, "rb");
|
|
|
|
if(in == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse the data and print it out */
|
|
|
|
parse(in, status);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
T_FileStream_close(in);
|
|
|
|
}
|