getopt.cpp
来自「把doc文档转成pdf后刻录成CD,用VC++开发,用了Nero的SDK和CXI」· C++ 代码 · 共 1,042 行 · 第 1/3 页
CPP
1,042 行
" |_______________|\n"
" | --dvdvideo | Create DVD-Video compatible disc.\n"
" | _cmpt | --create_iso_fs --create_udf_fs and \n"
" | | --iso_no_joliet also need to be specified.\n"
" |_______________|\n"
" | --import | Obsolete option; will be ignored.\n"
" | rockridge |\n"
" |_______________|\n"
" | --import_udf | Import UDF format.\n"
" |_______________|\n"
" | --import_vms | Import Virtual Multisession (VMS) session\n"
" | _session | (session number treated as VMS session).\n"
" |_______________|\n"
" | --import | Obsolete option; will be ignored.\n"
" | _iso_only |\n"
" |_______________|\n"
" | --import | Import session number (if omitted, the last\n"
" | <session #> | session is imported).\n"
" |_______________|\n"
" | --prefer | Obsolete option; will be ignored.\n"
" | _rockridge |\n"
" |_______________|\n"
" | --freestyle_ | Burn the file in mode 1.\n"
" | mode1 |\n"
" |_______________|\n"
" | --freestyle_ | Burn the file in mode 2.\n"
" | mode2 |\n"
" |_______________|\n"
" | --freestyle_ | Burn the file in audio mode.\n"
" | audio |\n"
" |_______________|\n"
" | --disable_ | Disables disc ejection after burn completion.\n"
" | eject |\n"
" |_______________|\n"
" | --verify | Verify ISO filesystem after writing.\n"
" |_______________|\n"
" | --dvd_high_ | Used for better compatibility of burned DVDs.\n"
" | compatibility| At least 1GB will be written.\n"
" |_______________|\n"
" | --dvd | Select DVD as media type.\n"
" |_______________|\n"
" | --recursive | Do a recursive file search.\n"
" |_______________|\n"
" | --force_erase_| Delete disc without user interaction\n"
" | cdrw | (requires --detect_non_empty_cdrw).\n"
" |_______________|\n"
" | --nero_log_ | Add a timestamp to the log's file name.\n"
" | timestamp |\n"
" |_______________|\n"
" | --temp_path | Specify a temporary path for Video CD files.\n"
" |_______________|\n"
" | --media_type | Specify a media type (combine with +) \n"
" | <type> | media_cd, media_ddcd, media_dvd_m, media_dvd_p,\n"
" | | media_dvd_any, media_dvd_ram, media_ml, media_mrw,\n"
" | | media_no_cdr, media_no_cdrw, media_cdrw, media_cdr\n"
" | | media_dvd_rom, media_cdrom, media_no_dvd_m_rw,\n"
" | | media_no_dvd_m_r, media_no_dvd_p_rw,\n"
" | | media_no_dvd_p_r, media_dvd_m_r, media_dvd_m_rw,\n"
" | | media_dvd_p_r, media_dvd_p_rw, media_fpacket,\n"
" | | media_vpacket, media_packetw or media_hdb).\n"
" |_______________|\n"
" | --no_user_ | Allow the whole process to take place with no user\n"
" | interaction | interaction (no questions asked).\n"
" |_______________|\n"
" | --output_image| Specify output image file name if image recorder is used\n"
" | | to avoid prompting for filename.\n"
" |_______________|\n"
" | --use_allspace| Use all space on the media.\n"
" |_______________|\n"
" | --relax_joliet| Relax Joliet file name length limitations.\n"
" |_______________|\n"
" | --japanese_ | CD Text is treated as Japanese CD Text (must include\n"
" | cd_text | --cd_text as well).\n"
" |_______________|\n"
" |--disable_eject| Do not eject the RW media after erasing it.\n"
" | _after_erase |\n"
" |_______________|\n"
" | --force_eject | Force disc ejection after erasing the RW media.\n"
" | _after_erase |\n"
" |_______________|\n"
" | --system_ | <text> is the \"system identifier\" of an ISO track.\n"
" | identifier |\n"
" | <text> |\n"
" |_______________|\n"
" | --volume_set | <text> is the \"volume set\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" | --publisher | <text> is the \"publisher\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" | --data_ | <text> is the \"data preparer\" of an ISO track.\n"
" |preparer <text>|\n"
" |_______________|\n"
" | --application | <text> is the \"application\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" | --copyright | <text> is the \"copyright\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" | --abstract | <text> is the \"abstract\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" |--bibliographic| <text> is the \"bibliographic\" of an ISO track.\n"
" | <text> |\n"
" |_______________|\n"
" | --backup | Replace imported files only if newer are found.\n"
" |_______________|\n"
" | --booktype | The book type of a burned DVD will be set to\n"
" | _dvdrom | DVD-ROM.\n"
" |_______________|\n"
" | --no_booktype | Do not change the book type of a DVD even if the default\n"
" | _change | setting is to change the book type to DVD-ROM.\n"
" |_______________|\n"
" | --estimate_no | Do not include the file system overhead in calculation.\n"
" | fs_overhead |\n"
" |_______________|\n"
" | --estimate_no | Do not include data in calculation.\n"
" | data |\n"
" |_______________|\n"
" | --estimate_no | Do not calculate the exact size (quicker).\n"
" | exact_size |\n"
" |_______________|\n"
" | @param_file | param_file contains the command line arguments.\n"
" |_______________|\n";
// The following piece of code prints the usage screen by screen.
int iLine;
int iLen = strlen (psMessage);
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo (hConsole, &csbi);
iLine = csbi.dwCursorPosition.Y;
while (*psMessage)
{
char buffer[81];
int iToCopy;
LPCSTR p;
p = strchr (psMessage, '\n');
iToCopy = (p)? p - psMessage + 1: iLen;
iToCopy = min (sizeof (buffer) - 1, iToCopy);
strncpy (buffer, psMessage, iToCopy);
buffer[iToCopy] = 0;
iLen -= iToCopy;
psMessage += iToCopy;
printf ("%s", buffer);
if (++iLine == csbi.srWindow.Bottom - csbi.srWindow.Top)
{
printf ("-- PRESS ANY KEY TO CONTINUE LISTING OR ESCAPE TO QUIT! --");
char ch = getch ();
printf ("\r \r");
if (ch == 27)
{
break;
}
iLine = 0;
}
}
}
// ReadParameterFile is responsible for reading and parsing the parameter list from a
// disk file. Once the parameters are parsed, they are passed on to the getopt
// function for decoding.
static bool ReadParameterFile (PARAMETERS & params, LPCSTR psFilename)
{
FILE * fh;
char ch;
int iStart = -1;
bool bStartWasQuote;
bool bStartWasSemicolon;
bool bLastWasBackslash = false;
static CSimpleStringArray args;
// Open the file in binary mode. Text mode retrieves a DOS newline
// as 0x0A, though it really is 0x0D+0x0A, thus compromising
// the command length calculation.
fh = fopen (psFilename, "rb");
if (NULL == fh)
{
printf ("Could not open parameter file '%s'\n", psFilename);
return false;
}
// The following code parses the file into argc/argv type of arguments.
do
{
ch = getc (fh);
// Handle the start of a command or parameter string
if (!isspace (ch) && ch != EOF && iStart == -1)
{
// ftell returns the current position of the file pointer
// Here we are at start of the string.
iStart = ftell (fh);
// Check if a quote character was read and remember it.
// This facilitates usage of blanks in file names.
bStartWasQuote = ch == '"';
// Check and remember that a comment was started
// Comments are discarded later.
bStartWasSemicolon = ch == ';';
// If the string started with a quote, we don't want that,
// so we leave the file pointer on the current position.
if (!bStartWasQuote)
{
// We did not start with a quote, so lets set the
// start value, which is one less than the current
// position
iStart--;
}
}
// Handle the end of comments
else if (iStart != -1 && bStartWasSemicolon &&
(isspace(ch) || ch == EOF))
{
// Comments are discarded
if (ch == '\n')
{
iStart = -1;
}
}
// Handle the end of a command or parameter string
else if (iStart != -1 && ((isspace (ch) && !bStartWasQuote) ||
(ch == '"' && bStartWasQuote) ||
ch == ';' || ch == EOF))
{
// Get the current file pointer position
// and calculate the command string length
int iCurPos = ftell (fh);
int iLen = iCurPos - iStart;
// Set the file pointer to the start of the command
// by moving it back by iLen bytes.
fseek (fh, -iLen, SEEK_CUR);
// Normally getc reads a character and then moves the file
// pointer to the next character. At the end of the input stream,
// the file pointer cannot go beyond EOF,
// thus we must not decrement the length in that case because we
// would delete parts of a command string.
if (ch != EOF)
{
iLen--;
}
// Allocate enough space for the command string and the
// termination character
LPSTR p = new char [iLen + 1];
if (!p)
{
printf ("Out of memory while parsing parameter file '%s'\n", psFilename);
fclose (fh);
return false;
}
// Copy the command string
fread (p, 1, iLen, fh);
p[iLen] = 0;
// Return to the previous last position
// by seting the file pointer to an absolute position
fseek (fh, iCurPos, SEEK_SET);
// Add the string to the string vector
args.Add (p);
// Make sure we discard the end of the line even
// if there was no blank between the command
// line parameter and a comment character ";"
bStartWasSemicolon = ch == ';';
// If the command was terminated by ";" we
// do not start another command yet.
if (!bStartWasSemicolon)
{
// Set the flag to get the next command
iStart = -1;
}
}
else if (bLastWasBackslash && ch != EOF)
{
if (ch != '"' && ch != '\\')
{
ungetc (ch, fh);
}
bLastWasBackslash = false;
}
} while (ch != EOF);
fclose (fh);
char ** argv = new char*[args.vect.size ()];
if (!argv)
{
printf ("Out of memory while parsing parameter file '%s'\n", psFilename);
return false;
}
for (int i = 0; i < (int)(args.vect.size()); i ++)
{
argv[i] = args.vect[i];
}
bool bRet = getopt (params, args.vect.size (), argv);
delete [] argv;
return bRet;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?