Modified version and usage display.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2262 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ywang 2007-01-17 21:31:03 +00:00
parent 92bb9cf637
commit 243009a7bf
3 changed files with 148 additions and 48 deletions

View File

@ -16,8 +16,43 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "string.h" #include "string.h"
#include "stdlib.h" #include "stdlib.h"
//
// Utility Name
//
#define UTILITY_NAME "SplitFile"
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 1
void void
helpmsg ( Version (
void
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT
Arguments:
None
Returns:
None
--*/
{
printf ("%s v%d.%d -Utility to break a file into two pieces at the request offset.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);
printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");
}
void
Usage (
void void
) )
/*++ /*++
@ -35,11 +70,14 @@ Returns:
--*/ --*/
{ {
printf ( Version();
"SplitFile Filename Offset\n"" Filename = Input file to split\n"" Offset = offset at which to split file\n" printf ("\nUsage: \n\
"\n\n""SplitFile will break a file in two pieces at the requested offset\n" SplitFile Filename Offset\n\
" outputting Filename1 and Filename2\n" where:\n\
); Filename: Input file to split\n\
Offset: offset at which to split file\n\
The output files will be named <Filename>1 and <Filename>2 with \n\
<Filename> being given as the input file name.\n");
} }
int int
@ -75,8 +113,24 @@ Returns:
unsigned long splitpoint; unsigned long splitpoint;
char CharC; char CharC;
if (argc == 1) {
Usage();
return -1;
}
if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||
(strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {
Usage();
return -1;
}
if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {
Version();
return -1;
}
if (argc != 3) { if (argc != 3) {
helpmsg (); Usage ();
return -1; return -1;
} }

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2004, Intel Corporation Copyright (c) 2004-2007, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -31,8 +31,6 @@ Abstract:
#include "StrGather.h" #include "StrGather.h"
#include "StringDB.h" #include "StringDB.h"
#define TOOL_VERSION "0.31"
#ifndef MAX_PATH #ifndef MAX_PATH
#define MAX_PATH 255 #define MAX_PATH 255
#endif #endif
@ -237,6 +235,12 @@ wstrcmp (
WCHAR *Str WCHAR *Str
); );
static
void
Version (
VOID
);
static static
void void
Usage ( Usage (
@ -321,7 +325,7 @@ Returns:
{ {
STATUS Status; STATUS Status;
SetUtilityName (PROGRAM_NAME); SetUtilityName (UTILITY_NAME);
// //
// Process the command-line arguments // Process the command-line arguments
// //
@ -1470,7 +1474,7 @@ FindFile (
// Put the path and filename together // Put the path and filename together
// //
if (strlen (List->Str) + strlen (FileName) + 1 > FoundFileNameLen) { if (strlen (List->Str) + strlen (FileName) + 1 > FoundFileNameLen) {
Error (PROGRAM_NAME, 0, 0, NULL, "internal error - cannot concatenate path+filename"); Error (UTILITY_NAME, 0, 0, NULL, "internal error - cannot concatenate path+filename");
return NULL; return NULL;
} }
// //
@ -1519,6 +1523,17 @@ ProcessArgs (
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
if ((strcmp(Argv[0], "-h") == 0) || (strcmp(Argv[0], "--help") == 0) ||
(strcmp(Argv[0], "-?") == 0) || (strcmp(Argv[0], "/?") == 0)) {
Usage();
return STATUS_ERROR;
}
if ((strcmp(Argv[0], "-V") == 0) || (strcmp(Argv[0], "--version") == 0)) {
Version();
return STATUS_ERROR;
}
mGlobals.Mode = MODE_UNKNOWN; mGlobals.Mode = MODE_UNKNOWN;
// //
@ -1570,7 +1585,7 @@ ProcessArgs (
// check for one more arg // check for one more arg
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing include path"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing include path");
return STATUS_ERROR; return STATUS_ERROR;
} }
// //
@ -1580,7 +1595,7 @@ ProcessArgs (
// //
NewList = malloc (sizeof (TEXT_STRING_LIST)); NewList = malloc (sizeof (TEXT_STRING_LIST));
if (NewList == NULL) { if (NewList == NULL) {
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1588,7 +1603,7 @@ ProcessArgs (
NewList->Str = malloc (strlen (Argv[1]) + 2); NewList->Str = malloc (strlen (Argv[1]) + 2);
if (NewList->Str == NULL) { if (NewList->Str == NULL) {
free (NewList); free (NewList);
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1613,7 +1628,7 @@ ProcessArgs (
// Indirection file -- check for one more arg // Indirection file -- check for one more arg
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing indirection file name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing indirection file name");
return STATUS_ERROR; return STATUS_ERROR;
} }
// //
@ -1623,7 +1638,7 @@ ProcessArgs (
// //
NewList = malloc (sizeof (TEXT_STRING_LIST)); NewList = malloc (sizeof (TEXT_STRING_LIST));
if (NewList == NULL) { if (NewList == NULL) {
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1631,7 +1646,7 @@ ProcessArgs (
NewList->Str = malloc (strlen (Argv[1]) + 1); NewList->Str = malloc (strlen (Argv[1]) + 1);
if (NewList->Str == NULL) { if (NewList->Str == NULL) {
free (NewList); free (NewList);
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1654,13 +1669,13 @@ ProcessArgs (
// Check for one more arg (the database file name) // Check for one more arg (the database file name)
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing database file name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing database file name");
return STATUS_ERROR; return STATUS_ERROR;
} }
NewList = malloc (sizeof (TEXT_STRING_LIST)); NewList = malloc (sizeof (TEXT_STRING_LIST));
if (NewList == NULL) { if (NewList == NULL) {
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1668,7 +1683,7 @@ ProcessArgs (
NewList->Str = malloc (strlen (Argv[1]) + 1); NewList->Str = malloc (strlen (Argv[1]) + 1);
if (NewList->Str == NULL) { if (NewList->Str == NULL) {
free (NewList); free (NewList);
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1691,14 +1706,14 @@ ProcessArgs (
// which we can dump our database. // which we can dump our database.
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing database dump output file name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing database dump output file name");
return STATUS_ERROR; return STATUS_ERROR;
} }
if (mGlobals.DumpUFileName[0] == 0) { if (mGlobals.DumpUFileName[0] == 0) {
strcpy (mGlobals.DumpUFileName, Argv[1]); strcpy (mGlobals.DumpUFileName, Argv[1]);
} else { } else {
Error (PROGRAM_NAME, 0, 0, Argv[1], "-ou option already specified with '%s'", mGlobals.DumpUFileName); Error (UTILITY_NAME, 0, 0, Argv[1], "-ou option already specified with '%s'", mGlobals.DumpUFileName);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1709,14 +1724,14 @@ ProcessArgs (
// -hpk option to create an HII export pack of the input database file // -hpk option to create an HII export pack of the input database file
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing raw string data dump output file name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing raw string data dump output file name");
return STATUS_ERROR; return STATUS_ERROR;
} }
if (mGlobals.HiiExportPackFileName[0] == 0) { if (mGlobals.HiiExportPackFileName[0] == 0) {
strcpy (mGlobals.HiiExportPackFileName, Argv[1]); strcpy (mGlobals.HiiExportPackFileName, Argv[1]);
} else { } else {
Error (PROGRAM_NAME, 0, 0, Argv[1], "-or option already specified with '%s'", mGlobals.HiiExportPackFileName); Error (UTILITY_NAME, 0, 0, Argv[1], "-or option already specified with '%s'", mGlobals.HiiExportPackFileName);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1740,7 +1755,7 @@ ProcessArgs (
// check for one more arg // check for one more arg
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output C filename"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing output C filename");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1752,7 +1767,7 @@ ProcessArgs (
// check for one more arg // check for one more arg
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing base name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing base name");
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1765,7 +1780,7 @@ ProcessArgs (
// -oh to specify output .h defines file name // -oh to specify output .h defines file name
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output .h filename"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing output .h filename");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1777,7 +1792,7 @@ ProcessArgs (
// -skipext to skip scanning of files with certain filename extensions // -skipext to skip scanning of files with certain filename extensions
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing filename extension"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing filename extension");
return STATUS_ERROR; return STATUS_ERROR;
} }
// //
@ -1787,7 +1802,7 @@ ProcessArgs (
// //
NewList = malloc (sizeof (TEXT_STRING_LIST)); NewList = malloc (sizeof (TEXT_STRING_LIST));
if (NewList == NULL) { if (NewList == NULL) {
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1795,7 +1810,7 @@ ProcessArgs (
NewList->Str = malloc (strlen (Argv[1]) + 2); NewList->Str = malloc (strlen (Argv[1]) + 2);
if (NewList->Str == NULL) { if (NewList->Str == NULL) {
free (NewList); free (NewList);
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1822,7 +1837,7 @@ ProcessArgs (
// "-lang eng" or "-lang spa+cat" to only output certain languages // "-lang eng" or "-lang spa+cat" to only output certain languages
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing language name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing language name");
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1838,7 +1853,7 @@ ProcessArgs (
// Output database file name -- check for another arg // Output database file name -- check for another arg
// //
if ((Argc <= 1) || (Argv[1][0] == '-')) { if ((Argc <= 1) || (Argv[1][0] == '-')) {
Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output database file name"); Error (UTILITY_NAME, 0, 0, Argv[0], "missing output database file name");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1849,7 +1864,7 @@ ProcessArgs (
// //
// Unrecognized arg // Unrecognized arg
// //
Error (PROGRAM_NAME, 0, 0, Argv[0], "unrecognized option"); Error (UTILITY_NAME, 0, 0, Argv[0], "unrecognized option");
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1896,7 +1911,7 @@ ProcessArgs (
// //
if (mGlobals.Mode == MODE_SCAN) { if (mGlobals.Mode == MODE_SCAN) {
if (Argc < 1) { if (Argc < 1) {
Error (PROGRAM_NAME, 0, 0, NULL, "must specify at least one source file to scan with -scan"); Error (UTILITY_NAME, 0, 0, NULL, "must specify at least one source file to scan with -scan");
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1906,14 +1921,14 @@ ProcessArgs (
while (Argc > 0) { while (Argc > 0) {
NewList = malloc (sizeof (TEXT_STRING_LIST)); NewList = malloc (sizeof (TEXT_STRING_LIST));
if (NewList == NULL) { if (NewList == NULL) {
Error (PROGRAM_NAME, 0, 0, "memory allocation failure", NULL); Error (UTILITY_NAME, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR; return STATUS_ERROR;
} }
memset (NewList, 0, sizeof (TEXT_STRING_LIST)); memset (NewList, 0, sizeof (TEXT_STRING_LIST));
NewList->Str = (CHAR8 *) malloc (strlen (Argv[0]) + 1); NewList->Str = (CHAR8 *) malloc (strlen (Argv[0]) + 1);
if (NewList->Str == NULL) { if (NewList->Str == NULL) {
Error (PROGRAM_NAME, 0, 0, "memory allocation failure", NULL); Error (UTILITY_NAME, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1933,7 +1948,7 @@ ProcessArgs (
// Parse mode -- must specify an input unicode file name // Parse mode -- must specify an input unicode file name
// //
if (Argc < 1) { if (Argc < 1) {
Error (PROGRAM_NAME, 0, 0, NULL, "must specify input unicode string file name with -parse"); Error (UTILITY_NAME, 0, 0, NULL, "must specify input unicode string file name with -parse");
Usage (); Usage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1966,7 +1981,7 @@ AddCommandLineLanguage (
// //
WNewList = MALLOC (sizeof (WCHAR_STRING_LIST)); WNewList = MALLOC (sizeof (WCHAR_STRING_LIST));
if (WNewList == NULL) { if (WNewList == NULL) {
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1974,7 +1989,7 @@ AddCommandLineLanguage (
WNewList->Str = malloc ((strlen (Language) + 1) * sizeof (WCHAR)); WNewList->Str = malloc ((strlen (Language) + 1) * sizeof (WCHAR));
if (WNewList->Str == NULL) { if (WNewList->Str == NULL) {
free (WNewList); free (WNewList);
Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure"); Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");
return STATUS_ERROR; return STATUS_ERROR;
} }
// //
@ -1997,7 +2012,7 @@ AddCommandLineLanguage (
(From[LANGUAGE_IDENTIFIER_NAME_LEN] != L',') (From[LANGUAGE_IDENTIFIER_NAME_LEN] != L',')
) )
) { ) {
Error (PROGRAM_NAME, 0, 0, Language, "invalid format for language name on command line"); Error (UTILITY_NAME, 0, 0, Language, "invalid format for language name on command line");
FREE (WNewList->Str); FREE (WNewList->Str);
FREE (WNewList); FREE (WNewList);
return STATUS_ERROR; return STATUS_ERROR;
@ -2470,6 +2485,31 @@ SkipTo (
return FALSE; return FALSE;
} }
static
void
Version (
VOID
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT
Arguments:
None
Returns:
None
--*/
{
printf ("%s v%d.%d -Utility to process unicode strings file..\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);
printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");
}
static static
void void
Usage ( Usage (
@ -2494,12 +2534,12 @@ Returns:
int Index; int Index;
static const char *Str[] = { static const char *Str[] = {
"", "",
PROGRAM_NAME " version "TOOL_VERSION " -- process unicode strings file", " Usage: "UTILITY_NAME " -parse {parse options} [FileNames]",
" Usage: "PROGRAM_NAME " -parse {parse options} [FileNames]", " "UTILITY_NAME " -scan {scan options} [FileName]",
" "PROGRAM_NAME " -scan {scan options} [FileName]", " "UTILITY_NAME " -dump {dump options}",
" "PROGRAM_NAME " -dump {dump options}",
" Common options include:", " Common options include:",
" -h or -? for this help information", " -h,--help,-?,/? display help messages",
" -V,--version display version information",
" -db Database required name of output/input database file", " -db Database required name of output/input database file",
" -bn BaseName for use in the .h and .c output files", " -bn BaseName for use in the .h and .c output files",
" Default = "DEFAULT_BASE_NAME, " Default = "DEFAULT_BASE_NAME,
@ -2535,6 +2575,9 @@ Returns:
"", "",
NULL NULL
}; };
Version();
for (Index = 0; Str[Index] != NULL; Index++) { for (Index = 0; Str[Index] != NULL; Index++) {
fprintf (stdout, "%s\n", Str[Index]); fprintf (stdout, "%s\n", Str[Index]);
} }

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2004, Intel Corporation Copyright (c) 2004-2007, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -25,7 +25,10 @@ Abstract:
#define MALLOC(size) malloc (size) #define MALLOC(size) malloc (size)
#define FREE(ptr) free (ptr) #define FREE(ptr) free (ptr)
#define PROGRAM_NAME "StrGather" #define UTILITY_NAME "StrGather"
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 31
typedef CHAR16 WCHAR; typedef CHAR16 WCHAR;