[Com0com-cvs] hub4com hub4com.cpp, 1.12, 1.13 utils.cpp, 1.3, 1.4 utils.h, 1.3, 1.4
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-08-28 15:53:17
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13325 Modified Files: hub4com.cpp utils.cpp utils.h Log Message: Added ability to load arguments from standard input and to select fragment for loading Index: utils.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/utils.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** utils.cpp 16 Apr 2008 14:07:12 -0000 1.3 --- utils.cpp 28 Aug 2008 15:53:13 -0000 1.4 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.4 2008/08/28 15:53:13 vfrolov + * Added ability to load arguments from standard input and + * to select fragment for loading + * * Revision 1.3 2008/04/16 14:07:12 vfrolov * Extended STRQTOK_R() *************** *** 85,100 **** char *pSave; ! char *pFile = STRQTOK_R(pTmp, ":", &pSave); ! if (!pFile || !*pFile) { ! cerr << "No file name in " << arg << endl; ! exit(1); } ! ifstream ifile(pFile); ! if (ifile.fail()) { ! cerr << "Can't open file " << pFile << endl; ! exit(1); } --- 89,124 ---- char *pSave; ! char *pFileSpec = STRQTOK_R(pTmp, ":", &pSave); ! char *pFile; ! char *pBegin; ! char *pEnd; ! ! if (pFileSpec) { ! char *pSave2; ! ! pFile = STRQTOK_R(pFileSpec, ",", &pSave2); ! pBegin = STRQTOK_R(NULL, ",", &pSave2); ! pEnd = STRQTOK_R(NULL, ",", &pSave2); ! } else { ! pFile = NULL; ! pBegin = NULL; ! pEnd = NULL; } ! ifstream ifile; ! istream *pInStream; ! if (pFile && *pFile) { ! ifile.open(pFile); ! ! if (ifile.fail()) { ! cerr << "Can't open file " << pFile << endl; ! exit(1); ! } ! ! pInStream = &ifile; ! } else { ! pInStream = &cin; } *************** *** 104,115 **** paramsLoad.push_back(p); ! free(pTmp); ! ! while (ifile.good()) { stringstream line; ! ifile.get(*line.rdbuf()); ! if (!ifile.fail()) { string str = line.str(); string::size_type first_non_space = string::npos; --- 128,137 ---- paramsLoad.push_back(p); ! while (pInStream->good()) { stringstream line; ! pInStream->get(*line.rdbuf()); ! if (!pInStream->fail()) { string str = line.str(); string::size_type first_non_space = string::npos; *************** *** 118,127 **** for (string::size_type i = 0 ; i < str.length() ; i++) { if (!isspace(str[i])) { ! if (first_non_space == string::npos) { ! if (str[i] == '#') ! break; ! first_non_space = i; - } last_non_space = i; --- 140,145 ---- for (string::size_type i = 0 ; i < str.length() ; i++) { if (!isspace(str[i])) { ! if (first_non_space == string::npos) first_non_space = i; last_non_space = i; *************** *** 132,135 **** --- 150,166 ---- str = str.substr(first_non_space, last_non_space + 1 - first_non_space); + if (pBegin && *pBegin) { + if (str == pBegin) + pBegin = NULL; + + continue; + } + + if (pEnd && *pEnd && str == pEnd) + break; + + if (str[0] == '#') + continue; + if (num_recursive > 256) { cerr << "Too many recursive options " << arg << endl; *************** *** 142,152 **** } } else { ! ifile.clear(); } char ch; ! ifile.get(ch); } } /////////////////////////////////////////////////////////////// --- 173,186 ---- } } else { ! if (!pInStream->eof()) ! pInStream->clear(); } char ch; ! pInStream->get(ch); } + + free(pTmp); } /////////////////////////////////////////////////////////////// *************** *** 161,171 **** } /////////////////////////////////////////////////////////////// ! char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave) { if (!pStr) pStr = *ppSave; ! while (IsDelim(*pStr, pDelims)) ! pStr++; if (!*pStr) { --- 195,207 ---- } /////////////////////////////////////////////////////////////// ! char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave, BOOL skipLeadingDelims) { if (!pStr) pStr = *ppSave; ! if (skipLeadingDelims) { ! while (IsDelim(*pStr, pDelims)) ! pStr++; ! } if (!*pStr) { *************** *** 192,202 **** char **ppSave, const char *pQuotes, ! BOOL discard) { if (!pStr) pStr = *ppSave; ! while (IsDelim(*pStr, pDelims)) ! pStr++; if (!*pStr) { --- 228,241 ---- char **ppSave, const char *pQuotes, ! BOOL discardQuotes, ! BOOL skipLeadingDelims) { if (!pStr) pStr = *ppSave; ! if (skipLeadingDelims) { ! while (IsDelim(*pStr, pDelims)) ! pStr++; ! } if (!*pStr) { *************** *** 212,216 **** if (quoted ? (*pStr == pQuotes[1]) : (*pStr == pQuotes[0])) { if (cntMask%2 == 0) { ! if (discard) memmove(pStr, pStr + 1, strlen(pStr + 1) + 1); quoted = !quoted; --- 251,255 ---- if (quoted ? (*pStr == pQuotes[1]) : (*pStr == pQuotes[0])) { if (cntMask%2 == 0) { ! if (discardQuotes) memmove(pStr, pStr + 1, strlen(pStr + 1) + 1); quoted = !quoted; *************** *** 321,327 **** char *pSave; ! for (argv[argc] = STRQTOK_R(pTmp, " ", &pSave) ; argv[argc] ; ! argv[argc] = STRQTOK_R(NULL, " ", &pSave)) { argc++; --- 360,366 ---- char *pSave; ! for (argv[argc] = STRQTOK_R(pTmp, " ", &pSave, "\"\"", TRUE, TRUE) ; argv[argc] ; ! argv[argc] = STRQTOK_R(NULL, " ", &pSave, "\"\"", TRUE, TRUE)) { argc++; Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** hub4com.cpp 25 Aug 2008 08:15:02 -0000 1.12 --- hub4com.cpp 28 Aug 2008 15:53:13 -0000 1.13 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.13 2008/08/28 15:53:13 vfrolov + * Added ability to load arguments from standard input and + * to select fragment for loading + * * Revision 1.12 2008/08/25 08:15:02 vfrolov * Itilized TimerAPCProc() *************** *** 74,81 **** << endl << "Common options:" << endl ! << " --load=<file>[:<prms>] - load arguments from a file (one argument per line)" << endl ! << " and insert them to the command line. The syntax of" << endl ! << " <prms> is <PRM1>[,<PRM2>...], where <PRMn> will" << endl ! << " replace %%n%%." << endl << " --help - show this help." << endl << " --help=* - show help for all modules." << endl --- 78,91 ---- << endl << "Common options:" << endl ! << " --load=[<file>][,<begin>[,<end>]][:<prms>]" << endl ! << " - load arguments (one argument per line) between" << endl ! << " <begin> and <end> lines from a file <file> (use" << endl ! << " standard input if empty) and insert them into the" << endl ! << " command line. The syntax of <prms> is" << endl ! << " <PRM1>[,<PRM2>...], where <PRMn> will replace" << endl ! << " %%n%% in the arguments. Do loading since begining" << endl ! << " if <begin> is empty. Do loading till end-of-file" << endl ! << " if <end> is empty. Ignore arguments begining with" << endl ! << " '#'." << endl << " --help - show this help." << endl << " --help=* - show help for all modules." << endl *************** *** 136,139 **** --- 146,161 ---- << " " << pProgPath << " --echo-route=0 COM2" << endl << " - receive data from COM2 and send it back to COM2." << endl + << " " << pProgPath << " --load=" << endl + << " --echo-route=0" << endl + << " COM2" << endl + << " ^Z" << endl + << " - the same as above." << endl + << " " << pProgPath << " --load=,_BEGIN_,_END_" << endl + << " blah blah blah" << endl + << " _BEGIN_" << endl + << " --echo-route=0" << endl + << " COM2" << endl + << " _END_" << endl + << " - the same as above." << endl ; } *************** *** 513,526 **** } delete pPlugins; ! if (plugged < 2) { ! if (plugged < 1) { ! Usage(argv[0], *pPlugins); ! exit(1); ! } ! } ! else ! if (defaultRouteData) { Route(hub, "0:All", FALSE, FALSE, routeDataMap); Route(hub, "1:0", FALSE, FALSE, routeDataMap); --- 535,546 ---- } + if (plugged < 1) { + Usage(argv[0], *pPlugins); + exit(1); + } + delete pPlugins; ! if (plugged > 1 && defaultRouteData) { Route(hub, "0:All", FALSE, FALSE, routeDataMap); Route(hub, "1:0", FALSE, FALSE, routeDataMap); Index: utils.h =================================================================== RCS file: /cvsroot/com0com/hub4com/utils.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** utils.h 16 Apr 2008 14:07:12 -0000 1.3 --- utils.h 28 Aug 2008 15:53:13 -0000 1.4 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.4 2008/08/28 15:53:13 vfrolov + * Added ability to load arguments from standard input and + * to select fragment for loading + * * Revision 1.3 2008/04/16 14:07:12 vfrolov * Extended STRQTOK_R() *************** *** 49,53 **** }; /////////////////////////////////////////////////////////////// ! char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave); char *STRQTOK_R( char *pStr, --- 53,57 ---- }; /////////////////////////////////////////////////////////////// ! char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave, BOOL skipLeadingDelims = FALSE); char *STRQTOK_R( char *pStr, *************** *** 55,59 **** char **ppSave, const char *pQuotes = "\"\"", ! BOOL discard = TRUE); BOOL StrToInt(const char *pStr, int *pNum); const char *GetParam(const char *pArg, const char *pPattern); --- 59,64 ---- char **ppSave, const char *pQuotes = "\"\"", ! BOOL discardQuotes = TRUE, ! BOOL skipLeadingDelims = FALSE); BOOL StrToInt(const char *pStr, int *pNum); const char *GetParam(const char *pArg, const char *pPattern); |