📄 prcommandline.cpp
字号:
/* * * prcommandline.cpp * * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com */#include "prcommandline.h"#include "utils.h"BOOL GuessDataTypeFromFileName(IN LPCTSTR lptstrDataFileName, OUT ::PrintPreviewDataSource& ppds) ;BOOL IsBlankSpace(IN TCHAR tc);TCHAR ToUpper(IN TCHAR tc);// *********************************************************************************// ** MODULE PUBLIC ROUTINES ****************************************************// *********************************************************************************BOOL MakeCommandLine(IN LPCTSTR lptstrAppPath, IN PrintPreviewDataSource ppds, IN LPCTSTR lptstrDataFileName, OUT tstring& tstrCommandLine) { BOOL bRetValue; if (ppds == ::PrintPreviewDataSources::eUnspecified) { ::GuessDataTypeFromFileName(lptstrDataFileName, ppds); } if (ppds != ::PrintPreviewDataSources::eUnspecified) { LPCTSTR lptstrTypeSwitch = NULL; switch(ppds) { case ::PrintPreviewDataSources::eBitmap: lptstrTypeSwitch = TEXT("/bmp"); break; case ::PrintPreviewDataSources::ePosterDataFile: lptstrTypeSwitch = TEXT("/psr"); break; case ::PrintPreviewDataSources::ePrintSpoolerDataFile: lptstrTypeSwitch = TEXT("/spl"); break; default: // DEBUG / FIX -- MAKE THIS COMPILE TIME ASSERTFAIL(); break; } tstrCommandLine = lptstrAppPath; tstrCommandLine += TEXT(" "); tstrCommandLine += lptstrTypeSwitch; tstrCommandLine += TEXT(" "); tstrCommandLine += lptstrDataFileName; bRetValue = TRUE; } return bRetValue;}BOOL ParseCommandLine(IN LPCTSTR lptstrCommandLine, OUT tstring& tstrDataFileName, OUT PrintPreviewDataSource& ppds) { enum ParseState { eInit, eAppName, eTypeSpecifierOrPosterFileName, eTypeSpecifier, eFileName, eDone, eError }; BOOL bRetValue = FALSE; tstring tstrFileNameTemp; PrintPreviewDataSource ppdsTemp = ::PrintPreviewDataSources::eUnspecified; ParseState ps = eInit; TCHAR tc; while(ps != eDone && ps != eError && (tc = * lptstrCommandLine ++) != 0) { switch(ps) { case eInit: if (::IsBlankSpace(tc)) { break; } ps = eAppName; // FALL THRU case eAppName: if (::IsBlankSpace(tc)) { ps = eTypeSpecifierOrPosterFileName; } break; case eTypeSpecifierOrPosterFileName: if (! ::IsBlankSpace(tc)) { if (tc == L'/') { ps = eTypeSpecifier; } else { ps = eFileName; -- lptstrCommandLine; } } break; case eTypeSpecifier: if ( ::ToUpper(tc) == L'B' && ::ToUpper(*lptstrCommandLine ++) == L'M' && ::ToUpper(*lptstrCommandLine ++) ==L'P' && ::IsBlankSpace(*lptstrCommandLine ++) ) { ppdsTemp = ::PrintPreviewDataSources::eBitmap; ps = eFileName; } else if ( ::ToUpper(tc) == L'P' && ::ToUpper(*lptstrCommandLine ++) == L'S' && ::ToUpper(*lptstrCommandLine ++) ==L'R' && ::IsBlankSpace(*lptstrCommandLine ++) ) { ppdsTemp = ::PrintPreviewDataSources::ePosterDataFile; ps = eFileName; } else if ( ::ToUpper(tc) == L'S' && ::ToUpper(*lptstrCommandLine ++) == L'P' && ::ToUpper(*lptstrCommandLine ++) ==L'L' && ::IsBlankSpace(*lptstrCommandLine ++) ) { ppdsTemp = ::PrintPreviewDataSources::ePrintSpoolerDataFile; ps = eFileName; } else { ps = eError; } break; case eFileName: if (! ::IsBlankSpace(tc)) { tstrFileNameTemp = lptstrCommandLine - 1; ps = eDone; } break; default: ASSERTFAIL(); break; } } if (ps == eDone && tstrFileNameTemp.length() != 0) { if (ppdsTemp == ::PrintPreviewDataSources::eUnspecified) { if (! ::GuessDataTypeFromFileName(tstrFileNameTemp.c_str(), ppdsTemp)) { ps = eError; } } } else { ps = eError; } if (ps != eError) { ASSERT(ppdsTemp != ::PrintPreviewDataSources::eUnspecified); tstrDataFileName = tstrFileNameTemp; ppds = ppdsTemp; bRetValue = TRUE; } return bRetValue;}// *********************************************************************************// ** MODULE PRIVATE ROUTINES ****************************************************// *********************************************************************************static BOOL GuessDataTypeFromFileName(IN LPCTSTR lptstrDataFileName, OUT ::PrintPreviewDataSource& ppds) { BOOL bRetValue = FALSE; LPTSTR lptstrExt = ::GetFileExt(lptstrDataFileName); if (lptstrExt != NULL) { if ( ::lstrcmpi(lptstrExt, TEXT(".bmp")) == 0) { ppds = ::PrintPreviewDataSources::eBitmap; bRetValue = TRUE; } else if (::lstrcmpi(lptstrExt, TEXT(".psr")) == 0) { ppds = ::PrintPreviewDataSources::ePosterDataFile; bRetValue = TRUE; } free(lptstrExt); } return bRetValue;}static BOOL IsBlankSpace(IN TCHAR tc) { BOOL b = (tc == L' ') || (tc == L'\t') || (tc == L'\n') || (tc == L'\r'); return b;}static TCHAR ToUpper(IN TCHAR tc) { if (L'a' <= tc && tc <= L'z') { tc += (L'A' - L'a'); } return tc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -