r368: Additions to ctsimtext
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 9 Jan 2001 20:38:53 +0000 (20:38 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 9 Jan 2001 20:38:53 +0000 (20:38 +0000)
ChangeLog
acconfig.h
config.h.in
configure.in
msvc/ctsim/ctsim.plg
tools/ctsimtext.cpp

index ff11c491e13e3cc46a407107328f219f10378ceb..680fb1f5e985f3a54c8077c93d2ad99e695589f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        
        * 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
index 38cafddc102c8db3e3362cddc32c684ca8ac0f7f..437d66db3ad99e9c3cf654c1475081065f5b058f 100644 (file)
@@ -78,3 +78,5 @@
 #undef HAVE_USLEEP
 
 #undef HAVE_SSTREAM
+
+#undef HAVE_READLINE
index eabb2ad06279fcb80f1baecbfd234cf59210d530..a1b85bea12a54880de398a10f8eb090c6c33f095 100644 (file)
 /* Version number of package */
 #undef VERSION
 
+#undef HAVE_READLINE
index 40872ace103251858b52832954adcb6f47ce9eba..511304efd77251b95a52bcaf278d154587a0add9 100644 (file)
@@ -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)])
index 485dcd6e8dae57442639c170f7ad68459ad56049..80c16f37e55e17afaaaa953c1c70c7cca6f8867e 100644 (file)
@@ -3,74 +3,9 @@
 <pre>
 <h1>Build Log</h1>
 <h3>
---------------------Configuration: libctsim - Win32 Debug--------------------
-</h3>
-<h3>Command Lines</h3>
-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"
-<h3>Output Window</h3>
-Compiling...
-projections.cpp
-Creating library...
-<h3>
 --------------------Configuration: ctsim - Win32 Debug--------------------
 </h3>
 <h3>Command Lines</h3>
-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"
-<h3>Output Window</h3>
-Linking...
 
 
 
index 0362a7a8b28dbae984d3db1affcf56532f582f3a..cd02ac68fb8569aeb8ed8e2de5db45259d4814f3 100644 (file)
@@ -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
 
 #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 <readline.h>
+#include <history.h>
+#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<char*> 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);