* Makefile.in, configure.in, configure,
[fw/sdcc] / debugger / mcs51 / sdcdb.c
index 4b9c8bb19d3e7643119b2c3ce789afd0f54d2f4c..fc132d8c87acf772b96d625c79e440e5a8c0d0b1 100644 (file)
 #include "break.h"
 #include "cmd.h"
 #include "newalloc.h"
-#ifdef HAVE_READLINE
+#if defined HAVE_LIBREADLINE && HAVE_LIBREADLINE != -1
+#define HAVE_READLINE_COMPLETITION  1
+#endif
+#ifdef HAVE_LIBREADLINE
 #include <readline/readline.h>
 #include <readline/history.h>
-#endif  /* HAVE_READLINE */
+#endif  /* HAVE_LIBREADLINE */
 
 #ifdef SDCDB_DEBUG
 int   sdcdbDebug = 0;
@@ -52,7 +55,7 @@ short showfull = 0;
 char userinterrupt = 0;
 char nointerrupt = 0;
 char contsim = 0;
-char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX "/small" ;
+char *ssdirl = DATADIR LIB_DIR_SUFFIX ":" DATADIR LIB_DIR_SUFFIX DIR_SEPARATOR_STRING "small" ;
 char *simArgs[40];
 int nsimArgs = 0;
 char model_str[20];
@@ -62,7 +65,7 @@ int lineno = 0;
 int fatalError = 0;
 
 static void commandLoop(FILE *cmdfile);
-#ifdef HAVE_READLINE
+#ifdef HAVE_READLINE_COMPLETITION
 char *completionCmdSource(const char *text, int state);
 char *completionCmdFile(const char *text, int state);
 char *completionCmdInfo(const char *text, int state);
@@ -86,18 +89,18 @@ char *completionCmdSetOption(const char *text, int state);
 #define completionCmdUnDisplay NULL
 #define completionCmdSetUserBp NULL
 #define completionCmdSetOption NULL
-#endif /* HAVE_READLINE */
+#endif /* HAVE_READLINE_COMPLETITION */
 
 /* command table */
 struct cmdtab
 {
     char      *cmd ;  /* command the user will enter */
     int (*cmdfunc)(char *,context *);   /* function to execute when command is entered */
-#ifdef HAVE_READLINE
+#ifdef HAVE_READLINE_COMPLETITION
     rl_compentry_func_t *completion_func;
 #else
     void *dummy;
-#endif  /* HAVE_READLINE */
+#endif  /* HAVE_READLINE_COMPLETITION */
     char *htxt ;    /* short help text */
 
 } cmdTab[] = {
@@ -250,11 +253,11 @@ char *trim_left(char *s)
 
 char *trim_right(char *s)
 {
-    char *p = &s[strlen(s)];
+    char *p = &s[strlen(s) - 1];
 
-    while (p > s && isspace(*--p))
-      ;
-    *p = '\0';
+    while (p >= s && isspace(*p))
+      --p;
+    *++p = '\0';
 
     return s;
 }
@@ -869,7 +872,7 @@ int interpretCmd (char *s)
     } else
         pcmd = strdup(s);
 
-    /* trim tailing blanks */
+    /* trim trailing blanks */
     s = trim_right(s);
 
     if (sim_cmd_mode) {
@@ -958,7 +961,7 @@ void stopCommandList()
     stopcmdlist = 1;
 }
 
-#ifdef HAVE_READLINE
+#ifdef HAVE_READLINE_COMPLETITION
 // helper function for doing readline completion.
 // input: toknum=index of token to find (0=first token)
 // output: *start=first character index of the token,
@@ -977,12 +980,12 @@ int completionHelper_GetTokenNumber(int toknum, int *start, int *end)
     {
         // start = skip blanks from end
         *start = *end;
-        while (p[*start] && isblank( p[*start] ))
+        while (p[*start] && isspace( p[*start] ))
             (*start)++;
 
         // end = skip non-blanks from start
         *end = *start;
-        while (p[*end] && !isblank( p[*end] ))
+        while (p[*end] && !isspace( p[*end] ))
             (*end)++;
 
         if (tok_index == toknum)
@@ -1051,14 +1054,14 @@ char *completionCommandsList(const char *text, int state)
         char *p = rl_line_buffer;
 
         // skip blanks
-        while (p && isblank(*p))
+        while (p && isspace(*p))
         {
             if (p-rl_line_buffer == rl_point)
                 ok = 1;
             p++;
         }
 
-        while (p && !isblank(*p))
+        while (p && !isspace(*p))
         {
             if (p-rl_line_buffer == rl_point)
                 ok = 1;
@@ -1419,7 +1422,7 @@ char *completionMain(const char *text, int state)
 
     return (*compl_func)(text,state);
 }
-#endif  /* HAVE_READLINE */
+#endif  /* HAVE_READLINE_COMPLETITION */
 
 /*-----------------------------------------------------------------*/
 /* commandLoop - the main command loop or loop over command file   */
@@ -1429,11 +1432,13 @@ static void commandLoop(FILE *cmdfile)
     char *line, save_ch, *s;
     char *line_read;
 
-#ifdef HAVE_READLINE
+#ifdef HAVE_LIBREADLINE
     FILE *old_rl_instream, *old_rl_outstream;
     actualcmdfile = cmdfile;
 
+#ifdef HAVE_READLINE_COMPLETITION
     rl_completion_entry_function = completionMain;
+#endif  /* HAVE_READLINE_COMPLETITION */
     rl_readline_name = "sdcdb"; // Allow conditional parsing of the ~/.inputrc file.
 
     // save readline's input/output streams
@@ -1453,9 +1458,9 @@ static void commandLoop(FILE *cmdfile)
           if ( cmdfile == stdin )
           {
               if (sim_cmd_mode)
-                  line_read = (char*)readline ("(sim)");
+                  line_read = (char*)readline ("(sim) ");
               else
-                  line_read = (char*)readline ("(sdcdb)");
+                  line_read = (char*)readline ("(sdcdb) ");
           }
           else
               line_read = (char*)readline ("");
@@ -1497,7 +1502,7 @@ static void commandLoop(FILE *cmdfile)
         //        actualcmdfile,cmdfile);
         if (fgets(cmdbuff,sizeof(cmdbuff),cmdfile) == NULL)
             break;
-#endif  /* HAVE_READLINE */
+#endif  /* HAVE_LIBREADLINE */
 
           if (interpretCmd(cmdbuff))
               break;
@@ -1530,11 +1535,11 @@ static void commandLoop(FILE *cmdfile)
             }
         }
     }
-#ifdef HAVE_READLINE
+#ifdef HAVE_LIBREADLINE
     // restore readline's input/output streams
     rl_instream = old_rl_instream;
     rl_outstream = old_rl_outstream;
-#endif  /* HAVE_READLINE */
+#endif  /* HAVE_LIBREADLINE */
 }
 
 /*-----------------------------------------------------------------*/