From da7c413d9b557a45c17a5af5d13de0825507a22d Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 9 Jan 2001 20:38:53 +0000 Subject: [PATCH] r368: Additions to ctsimtext --- ChangeLog | 4 ++ acconfig.h | 2 + config.h.in | 1 + configure.in | 1 + msvc/ctsim/ctsim.plg | 65 ----------------------- tools/ctsimtext.cpp | 122 ++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 122 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff11c49..680fb1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ * ctsim: Fixed initialization of min/max for PlotFiles + * ctsimtext: First version. All command-line tools are now accessed + through this master shell. Has both command-line and interactive + interface + * ezplot: Cleaned up y-tick label placement * sgp: Added better support for projection/reconstruction animation diff --git a/acconfig.h b/acconfig.h index 38cafdd..437d66d 100644 --- a/acconfig.h +++ b/acconfig.h @@ -78,3 +78,5 @@ #undef HAVE_USLEEP #undef HAVE_SSTREAM + +#undef HAVE_READLINE diff --git a/config.h.in b/config.h.in index eabb2ad..a1b85be 100644 --- a/config.h.in +++ b/config.h.in @@ -185,3 +185,4 @@ /* Version number of package */ #undef VERSION +#undef HAVE_READLINE diff --git a/configure.in b/configure.in index 40872ac..511304e 100644 --- a/configure.in +++ b/configure.in @@ -39,6 +39,7 @@ AC_CHECK_LIB(m, sin) AC_CHECK_LIB(curses, main, [curses=true], [curses=false]) AC_CHECK_LIB(ncurses, main, [ncurses=true], [ncurses=false]) AC_CHECK_LIB(g2, main, [g2=true], [g2=false]) +AC_CHECK_LIB(readline, main, [readline=true; AC_DEFINE(HAVE_READLINE)], readline=false) wxwin=false AC_CHECK_LIB(wx_gtk, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS)]) AC_CHECK_LIB(wx, main, [wxwin=true; wx_msw=true; AC_DEFINE(HAVE_WXWINDOWS)]) diff --git a/msvc/ctsim/ctsim.plg b/msvc/ctsim/ctsim.plg index 485dcd6..80c16f3 100644 --- a/msvc/ctsim/ctsim.plg +++ b/msvc/ctsim/ctsim.plg @@ -3,74 +3,9 @@
 

Build Log

---------------------Configuration: libctsim - Win32 Debug-------------------- -

-

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP35.tmp" with contents -[ -/nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c -"C:\ctsim\libctsim\projections.cpp" -] -Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP35.tmp" -Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP36.tmp" with contents -[ -/nologo /out:"Debug\libctsim.lib" -.\Debug\array2dfile.obj -.\Debug\backprojectors.obj -.\Debug\clip.obj -.\Debug\consoleio.obj -.\Debug\ezplot.obj -.\Debug\ezset.obj -.\Debug\ezsupport.obj -.\Debug\filter.obj -.\Debug\fnetorderstream.obj -.\Debug\fourier.obj -.\Debug\getopt.obj -.\Debug\getopt1.obj -.\Debug\hashtable.obj -.\Debug\imagefile.obj -.\Debug\mathfuncs.obj -.\Debug\phantom.obj -.\Debug\plotfile.obj -.\Debug\pol.obj -.\Debug\procsignal.obj -.\Debug\projections.obj -.\Debug\reconstruct.obj -.\Debug\scanner.obj -.\Debug\sgp.obj -.\Debug\strfuncs.obj -.\Debug\syserror.obj -.\Debug\trace.obj -.\Debug\transformmatrix.obj -.\Debug\xform.obj -] -Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP36.tmp" -

Output Window

-Compiling... -projections.cpp -Creating library... -

--------------------Configuration: ctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP37.tmp" with contents -[ -comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../libctsim/Debug/libctsim.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\lpng108\msvc\win32\libpng\lib_dbg\libpng.lib ..\..\..\lpng108\msvc\win32\zlib\lib_dbg\zlib.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib ../../../wx2/lib/wxd.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrtd.lib" /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"..\..\..\lpng108\msvc\win32\libpng\lib" /libpath:"..\..\..\lpng108\msvc\win32\zlib\lib" -.\Debug\ctsim.obj -.\Debug\dialogs.obj -.\Debug\dlgprojections.obj -.\Debug\dlgreconstruct.obj -.\Debug\docs.obj -.\Debug\views.obj -.\Debug\wx.res -\ctsim\msvc\libctsim\Debug\libctsim.lib -"\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib" -"\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib" -\wx2\lib\wxd.lib -] -Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP37.tmp" -

Output Window

-Linking... diff --git a/tools/ctsimtext.cpp b/tools/ctsimtext.cpp index 0362a7a..cd02ac6 100644 --- a/tools/ctsimtext.cpp +++ b/tools/ctsimtext.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsimtext.cpp,v 1.2 2001/01/08 03:06:37 kevin Exp $ +** $Id: ctsimtext.cpp,v 1.3 2001/01/09 20:38:53 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -27,7 +27,19 @@ #include "ct.h" -static const char* g_szIdStr = "$Id: ctsimtext.cpp,v 1.2 2001/01/08 03:06:37 kevin Exp $"; +#ifdef HAVE_READLINE +#include +#include +#endif + + +// Master shell for all command-line tools +// If called as ctsimtext, program will look to next token on command-line as the function name +// If linked to ctsimtext, but executed as another name, eg pjrec, then program will use that +// linked name as name of function. + +static const char* const g_szIdStr = "$Id: ctsimtext.cpp,v 1.3 2001/01/09 20:38:53 kevin Exp $"; +static const char* const s_szProgramName = "ctsimtext"; extern int if1_main (int argc, char* const argv[]); extern int if2_main (int argc, char* const argv[]); @@ -39,6 +51,10 @@ extern int pj2if_main (int argc, char* const argv[]); extern int pjinfo_main (int argc, char* const argv[]); extern int pjrec_main (int argc, char* const argv[]); +static int processCommand (int argc, char* const argv[]); +static void convertStringToArgcv (char* szLine, int* piArgc, char*** pppArgv); + + void ctsimtext_usage (const char *program) @@ -60,14 +76,104 @@ ctsimtext_usage (const char *program) int ctsimtext_main (int argc, char * argv[]) { - if (argc < 2) { - ctsimtext_usage (argv[0]); - return (1); + int iReturn = 0; + + if (strcmp(argv[0],s_szProgramName) == 0) { + argv = &argv[1]; + argc--; + iReturn = processCommand (argc, argv); + } else if (argc > 1){ + iReturn = processCommand (argc, argv); + } else { + char szPrompt[] = "CTSim> "; + std::string strInput; + while (1) { + std::cout << "CTSimText Interactive mode\nType quit to end"; +#ifdef HAVE_READLINE + char* pszInput = readline (szPrompt); +#else + std::cout << szPrompt; + std::cin >> strInput; + char* pszInput = new char [strInput.length() + 1]; + strncpy (pszInput, strInput.c_str(), sizeof(pszInput)); +#endif + if (strncasecmp (pszInput, "quit", 4) == 0) { + delete pszInput; + break; + } + convertStringToArgcv (pszInput, &argc, &argv); + delete pszInput; + iReturn = processCommand (argc, argv); + } + } + + return iReturn; +} + +static void +convertStringToArgcv (char* pszLine, int* piArgc, char*** pppArgv) +{ + char* pCurrentPos = pszLine; + int nTokens = 0; + std::vector vecpszToken; + + // Process line + bool bInDoubleQuote = false; + bool bInSingleQuote = false; + bool bInToken = false; + + while (*pCurrentPos) { + if (iswhite (*pCurrentPos)) { + if (! bInToken) + *pCurrentPos = 0; + else if (bInSingleQuote || bInDoubleQuote) + ; + else { // in non-quote token + *pCurrentPos = 0; + bInToken = false; + } + } + else if (*pCurrentPos = '\"') { + if (bInSingleQuote) { + bInSingleQuote = false; + } else { + bInSingleQuote = true; + if (! bInToken) { + bInToken = true; + nTokens++; + vecpszToken.push_back (pCurrentPos+1); + } + } + } else if (*pCurrentPos = '\'') { + if (bInDoubleQuote) { + bInDoubleQuote = false; + } else { + bInDoubleQuote = true; + if (! bInToken) { + bInToken = true; + nTokens++; + vecpszToken.push_back (pCurrentPos+1); + } + } + } else if (! bInToken) { // nonwhite, non-quote character + bInToken = true; + nTokens++; + vecpszToken.push_back (pCurrentPos); + } + + pCurrentPos++; } - const char* const pszFunction = argv[1]; - argv = &argv[1]; - argc--; + *piArgc = nTokens; + pppArgv = new char** [nTokens]; + for (unsigned int iToken = 0; iToken < vecpszToken.size(); iToken++) + (*pppArgv)[iToken] = vecpszToken[iToken]; +} + +static int +processCommand (int argc, char* const argv[]) +{ + const char* const pszFunction = argv[0]; if (strcasecmp (pszFunction, "if1") == 0) return if1_main (argc, argv); -- 2.34.1