- fixed build issues with win32
authorntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 6 Jul 2008 23:22:17 +0000 (23:22 +0000)
committerntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 6 Jul 2008 23:22:17 +0000 (23:22 +0000)
- fixed build warnings for last commit
- set svn props for last commit

git-svn-id: svn://svn.berlios.de/openocd/trunk@760 b42882b7-edfa-0310-969c-e2dbd0fdcd60

12 files changed:
src/helper/binarybuffer.h
src/helper/command.c
src/helper/command.h
src/helper/replacements.h
src/jim.c
src/jim.h
src/main.c
src/openocd.c
src/server/tcl_server.c
src/server/tcl_server.h
src/server/telnet_server.c
src/target/target.c

index 47ae193..0273541 100644 (file)
@@ -94,5 +94,4 @@ static __inline u32 fast_target_buffer_get_u32(u8 *buffer, int little)
                return be_to_h_u32(buffer);
 }
 
-
 #endif /* BINARYBUFFER_H */
index 55f950b..8b7be70 100644 (file)
@@ -305,14 +305,13 @@ int parse_line(char *line, char *words[], int max_words)
        return nwords;
 }
 
-void command_output_text( command_context_t *context, const char *data )
+void command_output_text(command_context_t *context, const char *data)
 {
        if( context && context->output_handler && data  ){
                context->output_handler( context, data );
        }
 }
 
-
 void command_print_n(command_context_t *context, char *format, ...)
 {
        char *string;
@@ -728,10 +727,3 @@ int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
 
        return retval;
 }
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index 8db1675..6381bf3 100644 (file)
@@ -77,20 +77,11 @@ extern int command_run_line(command_context_t *context, char *line);
 extern int command_run_linef(command_context_t *context, char *format, ...);
 extern int command_run_line_internal(command_context_t *context, char *line);
 extern int command_run_file(command_context_t *context, FILE *file, enum command_mode mode);
-
+extern void command_output_text(command_context_t *context, const char *data);
 
 #define                ERROR_COMMAND_CLOSE_CONNECTION          (-600)
 #define                ERROR_COMMAND_SYNTAX_ERROR                      (-601)
 
-
 extern int fast_and_dangerous;
 
 #endif /* COMMAND_H */
-
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index 71e4c66..70c3a40 100644 (file)
 #ifndef MAX
 #define MAX(a,b) (((a)>(b))?(a):(b))
 #endif
-                                                                                                                                
+
+/* for systems that do not support ENOTSUP
+ * win32 being one of them */
+#ifndef ENOTSUP
+#define ENOTSUP 134            /* Not supported */
+#endif
+
 /* gettimeofday() */
 #ifndef HAVE_GETTIMEOFDAY
 
index 4cf4f3d..e9eb588 100644 (file)
--- a/src/jim.c
+++ b/src/jim.c
@@ -38,6 +38,8 @@
 #include <errno.h>
 #include <time.h>
 
+#include "replacements.h"
+
 /* Include the platform dependent libraries for
  * dynamic loading of libraries. */
 #ifdef JIM_DYNLIB
@@ -45,7 +47,9 @@
 #ifndef WIN32
 #define WIN32 1
 #endif
+#ifndef STRICT
 #define STRICT
+#endif
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #if _MSC_VER >= 1000
@@ -12027,8 +12031,7 @@ out:
  * Jim's idea of STDIO..
  * ---------------------------------------------------------------------------*/
 
-int
-Jim_fprintf( Jim_Interp *interp, void *cookie, const char *fmt, ... )
+int Jim_fprintf( Jim_Interp *interp, void *cookie, const char *fmt, ... )
 {
        int r;
 
@@ -12038,10 +12041,8 @@ Jim_fprintf( Jim_Interp *interp, void *cookie, const char *fmt, ... )
        va_end(ap);
        return r;
 }
-       
 
-int 
-Jim_vfprintf( Jim_Interp *interp, void *cookie, const char *fmt, va_list ap )
+int Jim_vfprintf( Jim_Interp *interp, void *cookie, const char *fmt, va_list ap )
 {
        if( (interp == NULL) || (interp->cb_vfprintf == NULL) ){
                errno = ENOTSUP;
@@ -12050,8 +12051,7 @@ Jim_vfprintf( Jim_Interp *interp, void *cookie, const char *fmt, va_list ap )
        return (*(interp->cb_vfprintf))( cookie, fmt, ap );
 }
 
-size_t
-Jim_fwrite( Jim_Interp *interp, const void *ptr, size_t size, size_t n, void *cookie )
+size_t Jim_fwrite( Jim_Interp *interp, const void *ptr, size_t size, size_t n, void *cookie )
 {
        if( (interp == NULL) || (interp->cb_fwrite == NULL) ){
                errno = ENOTSUP;
@@ -12060,8 +12060,7 @@ Jim_fwrite( Jim_Interp *interp, const void *ptr, size_t size, size_t n, void *co
        return (*(interp->cb_fwrite))( ptr, size, n, cookie);
 }
 
-size_t
-Jim_fread( Jim_Interp *interp, void *ptr, size_t size, size_t n, void *cookie )
+size_t Jim_fread( Jim_Interp *interp, void *ptr, size_t size, size_t n, void *cookie )
 {
        if( (interp == NULL) || (interp->cb_fread == NULL) ){
                errno = ENOTSUP;
@@ -12070,8 +12069,7 @@ Jim_fread( Jim_Interp *interp, void *ptr, size_t size, size_t n, void *cookie )
        return (*(interp->cb_fread))( ptr, size, n, cookie);
 }
 
-int
-Jim_fflush( Jim_Interp *interp, void *cookie )
+int Jim_fflush( Jim_Interp *interp, void *cookie )
 {
        if( (interp == NULL) || (interp->cb_fflush == NULL) ){
                /* pretend all is well */
@@ -12080,8 +12078,7 @@ Jim_fflush( Jim_Interp *interp, void *cookie )
        return (*(interp->cb_fflush))( cookie );
 }
 
-char *  
-Jim_fgets( Jim_Interp *interp, char *s, int size, void *cookie )
+char* Jim_fgets( Jim_Interp *interp, char *s, int size, void *cookie )
 {
        if( (interp == NULL) || (interp->cb_fgets == NULL) ){
                errno = ENOTSUP;
@@ -12089,16 +12086,3 @@ Jim_fgets( Jim_Interp *interp, char *s, int size, void *cookie )
        }
        return (*(interp->cb_fgets))( s, size, cookie );
 }
-
-       
-
-
-
-
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index b08c11f..9e9c7dc 100644 (file)
--- a/src/jim.h
+++ b/src/jim.h
@@ -983,11 +983,3 @@ static void Jim_InitEmbedded(void) {
 #endif
 
 #endif /* __JIM__H */
-
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index ef443b2..cc59223 100644 (file)
@@ -1,49 +1,49 @@
-/***************************************************************************\r
- *   Copyright (C) 2005 by Dominic Rath                                    *\r
- *   Dominic.Rath@gmx.de                                                   *\r
- *                                                                         *\r
- *   This program is free software; you can redistribute it and/or modify  *\r
- *   it under the terms of the GNU General Public License as published by  *\r
- *   the Free Software Foundation; either version 2 of the License, or     *\r
- *   (at your option) any later version.                                   *\r
- *                                                                         *\r
- *   This program is distributed in the hope that it will be useful,       *\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
- *   GNU General Public License for more details.                          *\r
- *                                                                         *\r
- *   You should have received a copy of the GNU General Public License     *\r
- *   along with this program; if not, write to the                         *\r
- *   Free Software Foundation, Inc.,                                       *\r
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *\r
- ***************************************************************************/\r
-\r
-/* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling\r
- * OpenOCD fn's. No-op in vanilla OpenOCD\r
- */\r
-void lockBigLock()\r
-{\r
-}\r
-void unlockBigLock()\r
-{\r
-}\r
-\r
-/* \r
-       This is the main entry for developer PC hosted OpenOCD.\r
-       \r
-       OpenOCD can also be used as a library that is linked with\r
-       another application(not mainstream yet, but possible), e.g.\r
-       w/as an embedded application.\r
-       \r
-       Those applications will have their own main() implementation\r
-       and use bits and pieces from openocd.c.\r
-       \r
-*/\r
-\r
-\r
-extern int openocd_main(int argc, char *argv[]);\r
-int main(int argc, char *argv[])\r
-{\r
-       return openocd_main(argc, argv);\r
-}\r
-\r
+/***************************************************************************
+ *   Copyright (C) 2005 by Dominic Rath                                    *
+ *   Dominic.Rath@gmx.de                                                   *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+/* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
+ * OpenOCD fn's. No-op in vanilla OpenOCD
+ */
+void lockBigLock()
+{
+}
+void unlockBigLock()
+{
+}
+
+/* 
+       This is the main entry for developer PC hosted OpenOCD.
+       
+       OpenOCD can also be used as a library that is linked with
+       another application(not mainstream yet, but possible), e.g.
+       w/as an embedded application.
+       
+       Those applications will have their own main() implementation
+       and use bits and pieces from openocd.c.
+       
+*/
+
+
+extern int openocd_main(int argc, char *argv[]);
+int main(int argc, char *argv[])
+{
+       return openocd_main(argc, argv);
+}
+
index b4a9704..ee00f19 100644 (file)
 #include <unistd.h>
 #include <errno.h>
 
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
 #ifdef __ECOS
 /* Jim is provied by eCos */
 #include <cyg/jimtcl/jim.h>
@@ -58,8 +64,7 @@
 #include "jim.h"
 #endif
 
-
-
+#include "replacements.h"
 
 int launchTarget(struct command_context_s *cmd_ctx)
 {
@@ -113,7 +118,6 @@ int handle_daemon_startup_command(struct command_context_s *cmd_ctx, char *cmd,
        return ERROR_OK;
 }
 
-
 void exit_handler(void)
 {
        /* close JTAG interface */
@@ -121,7 +125,6 @@ void exit_handler(void)
                jtag->quit();
 }
 
-
 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
 int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
@@ -135,7 +138,6 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
 
        atexit(exit_handler);
-
        
        if (target_init(cmd_ctx) != ERROR_OK)
                return ERROR_FAIL;
@@ -159,7 +161,6 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                        LOG_DEBUG("jtag examine complete");
                }
        }
-
        
        if (flash_init_drivers(cmd_ctx) != ERROR_OK)
                return ERROR_FAIL;
@@ -184,28 +185,20 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        return ERROR_OK;
 }
 
-
 void lockBigLock();
 void unlockBigLock();
 
-
-
 Jim_Interp *interp;
 command_context_t *active_cmd_ctx;
 
-static int
-new_int_array_element( Jim_Interp * interp, 
-                                          const char *varname, 
-                                          int idx, 
-                                          u32 val )
+static int new_int_array_element(Jim_Interp * interp, const char *varname, int idx, u32 val)
 {
        char *namebuf;
        Jim_Obj *nameObjPtr, *valObjPtr;
        int result;
 
        namebuf = alloc_printf("%s(%d)", varname, idx );
-
-
+       
     nameObjPtr = Jim_NewStringObj(interp, namebuf, -1);
     valObjPtr = Jim_NewIntObj(interp, val );
     Jim_IncrRefCount(nameObjPtr);
@@ -218,8 +211,7 @@ new_int_array_element( Jim_Interp * interp,
     return result;
 }
 
-static int
-Jim_Command_mem2array( Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        target_t *target;
        long l;
@@ -232,7 +224,6 @@ Jim_Command_mem2array( Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        u8 buffer[4096];
        int  i,n,e,retval;
 
-
        /* argv[1] = name of array to receive the data
         * argv[2] = desired width
         * argv[3] = memory address 
@@ -245,7 +236,6 @@ Jim_Command_mem2array( Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        varname = Jim_GetString( argv[1], &len );
        /* given "foo" get space for worse case "foo(%d)" .. add 20 */
 
-
        e = Jim_GetLong( interp, argv[2], &l );
        width = l;
        if( e != JIM_OK ){
@@ -377,8 +367,7 @@ Jim_Command_mem2array( Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
-static void tcl_output(void *privData, const char *file, int line, 
-               const char *function, const char *string)
+static void tcl_output(void *privData, const char *file, int line, const char *function, const char *string)
 {              
        Jim_Obj *tclOutput=(Jim_Obj *)privData;
 
@@ -451,11 +440,7 @@ int jim_command(command_context_t *context, char *line)
 
 int startLoop=0;
 
-static int
-Jim_Command_openocd_ignore(Jim_Interp *interp, 
-                                   int argc,
-                                   Jim_Obj *const *argv,
-                                   int ignore)
+static int Jim_Command_openocd_ignore(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int ignore)
 {
        int retval;
     char *cmd = (char*)Jim_GetString(argv[1], NULL);
@@ -485,30 +470,18 @@ Jim_Command_openocd_ignore(Jim_Interp *interp,
     return (ignore||(retval==ERROR_OK))?JIM_OK:JIM_ERR;
 }
 
-static int
-Jim_Command_openocd(Jim_Interp *interp, 
-                                   int argc,
-                                   Jim_Obj *const *argv)
+static int Jim_Command_openocd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        return Jim_Command_openocd_ignore(interp, argc, argv, 1); 
 }
 
-static int
-Jim_Command_openocd_throw(Jim_Interp *interp, 
-                                   int argc,
-                                   Jim_Obj *const *argv)
+static int Jim_Command_openocd_throw(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        return Jim_Command_openocd_ignore(interp, argc, argv, 0); 
 }
-  
-
-
 
 /* find full path to file */
-static int
-Jim_Command_find(Jim_Interp *interp, 
-                                   int argc,
-                                   Jim_Obj *const *argv)
+static int Jim_Command_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        if (argc!=2)
                return JIM_ERR;
@@ -523,10 +496,7 @@ Jim_Command_find(Jim_Interp *interp,
        return JIM_OK;
 }
 
-static int
-Jim_Command_echo(Jim_Interp *interp, 
-                                   int argc,
-                                   Jim_Obj *const *argv)
+static int Jim_Command_echo(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        if (argc!=2)
                return JIM_ERR;
@@ -535,10 +505,7 @@ Jim_Command_echo(Jim_Interp *interp,
        return JIM_OK;
 }
 
-void command_output_text( command_context_t *context, const char *data );
-
-static size_t
-openocd_jim_fwrite( const void *_ptr, size_t size, size_t n, void *cookie )
+static size_t openocd_jim_fwrite(const void *_ptr, size_t size, size_t n, void *cookie)
 {
        size_t nbytes;
        const char *ptr;
@@ -556,7 +523,6 @@ openocd_jim_fwrite( const void *_ptr, size_t size, size_t n, void *cookie )
                return n;
        }
 
-       
        /* do we have to chunk it? */
        if( ptr[ nbytes ] == 0 ){
                /* no it is a C style string */
@@ -585,16 +551,13 @@ openocd_jim_fwrite( const void *_ptr, size_t size, size_t n, void *cookie )
        return n;
 }
 
-static size_t
-openocd_jim_fread(void *ptr, size_t size, size_t n, void *cookie )
+static size_t openocd_jim_fread(void *ptr, size_t size, size_t n, void *cookie )
 {
        /* TCL wants to read... tell him no */
        return 0;
 }
 
-
-static int
-openocd_jim_vfprintf( void *cookie, const char *fmt, va_list ap )
+static int openocd_jim_vfprintf(void *cookie, const char *fmt, va_list ap)
 {
        char *cp;
        int n;
@@ -611,23 +574,19 @@ openocd_jim_vfprintf( void *cookie, const char *fmt, va_list ap )
        return n;
 }
 
-static int
-openocd_jim_fflush( void *cookie )
+static int openocd_jim_fflush(void *cookie)
 {
        /* nothing to flush */
        return 0;
 }
 
-static char  *
-openocd_jim_fgets( char *s, int size, void *cookie )
+static char* openocd_jim_fgets(char *s, int size, void *cookie)
 {
        /* not supported */
        errno = ENOTSUP;
        return NULL;
 }
 
-
-
 void initJim(void)
 {
     Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, NULL, NULL);
@@ -746,8 +705,7 @@ int openocd_main(int argc, char *argv[])
        
        if (daemon_startup)
                command_run_line(cmd_ctx, "reset");
-
-
+       
        startLoop=1;
 
        /* handle network connections */
@@ -763,12 +721,3 @@ int openocd_main(int argc, char *argv[])
 
        return EXIT_SUCCESS;
 }
-
-
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index 8c47eaf..2771254 100644 (file)
-/***************************************************************************\r
- *   Copyright (C) 2008                                                    *\r
- *                                                                         *\r
- *   This program is free software; you can redistribute it and/or modify  *\r
- *   it under the terms of the GNU General Public License as published by  *\r
- *   the Free Software Foundation; either version 2 of the License, or     *\r
- *   (at your option) any later version.                                   *\r
- *                                                                         *\r
- *   This program is distributed in the hope that it will be useful,       *\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
- *   GNU General Public License for more details.                          *\r
- *                                                                         *\r
- *   You should have received a copy of the GNU General Public License     *\r
- *   along with this program; if not, write to the                         *\r
- *   Free Software Foundation, Inc.,                                       *\r
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *\r
- ***************************************************************************/\r
-\r
-#ifdef HAVE_CONFIG_H\r
-#include "config.h"\r
-#endif\r
-\r
-#include <stdarg.h>\r
-#include "tcl_server.h"\r
-\r
-#include "../jim.h"\r
-#include "log.h"\r
-#include "command.h"\r
-\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-#include <errno.h>\r
-#include <string.h>\r
-#include <ctype.h>\r
-\r
-#define TCL_SERVER_VERSION     "TCL Server 0.1"\r
-#define TCL_MAX_LINE           (4096)\r
-\r
-typedef struct tcl_connection_s {\r
-       int tc_linedrop;\r
-       int tc_lineoffset;\r
-       char tc_line[TCL_MAX_LINE];\r
-\r
-       int tc_outerror; /* flag an output error */\r
-} tcl_connection_t;\r
-\r
-extern Jim_Interp *interp;\r
-static unsigned short tcl_port = 0;\r
-\r
-/* commands */\r
-static int handle_tcl_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);\r
-\r
-/* handlers */\r
-static int tcl_new_connection(connection_t *connection);\r
-static int tcl_input(connection_t *connection);\r
-static int tcl_output(connection_t *connection, const void *buf, ssize_t len);\r
-static int tcl_closed(connection_t *connection);\r
-\r
-/* write data out to a socket.\r
- *\r
- * this is a blocking write, so the return value must equal the length, if\r
- * that is not the case then flag the connection with an output error.\r
- */\r
-int tcl_output(connection_t *connection, const void *data, ssize_t len)\r
-{\r
-       ssize_t wlen;\r
-       tcl_connection_t *tclc;\r
-\r
-       tclc = connection->priv;\r
-       if (tclc->tc_outerror)\r
-               return ERROR_SERVER_REMOTE_CLOSED;\r
-\r
-       wlen = write_socket(connection->fd, data, len);\r
-       if (wlen == len)\r
-               return ERROR_OK;\r
-\r
-       LOG_ERROR("error during write: %d != %d", (int)wlen, (int)len);\r
-       tclc->tc_outerror = 1;\r
-       return ERROR_SERVER_REMOTE_CLOSED;\r
-}\r
-\r
-\r
-/* connections */\r
-static int tcl_new_connection(connection_t *connection)\r
-{\r
-       tcl_connection_t *tclc;\r
-\r
-       tclc = malloc(sizeof(tcl_connection_t));\r
-       if (tclc == NULL)\r
-               return ERROR_CONNECTION_REJECTED;\r
-\r
-       memset(tclc, 0, sizeof(tcl_connection_t));\r
-       connection->priv = tclc;\r
-       return ERROR_OK;\r
-}\r
-\r
-static int tcl_input(connection_t *connection)\r
-{\r
-       int retval;\r
-       int i;\r
-       ssize_t rlen;\r
-       const char *result;\r
-       int reslen;\r
-       tcl_connection_t *tclc;\r
-       char in[256];\r
-\r
-       rlen = read_socket(connection->fd, &in, sizeof(in));\r
-       if (rlen <= 0) {\r
-               if (rlen < 0)\r
-                       LOG_ERROR("error during read: %s", strerror(errno));\r
-               return ERROR_SERVER_REMOTE_CLOSED;\r
-       }\r
-\r
-       tclc = connection->priv;\r
-       if (tclc == NULL)\r
-               return ERROR_CONNECTION_REJECTED;\r
-\r
-       /* push as much data into the line as possible */\r
-       for (i = 0; i < rlen; i++)\r
-       {\r
-               if (!isprint(in[i]) && !isspace(in[i]))\r
-               {\r
-                       /* drop this line */\r
-                       tclc->tc_linedrop = 1;\r
-                       continue;\r
-               }\r
-\r
-               /* buffer the data */\r
-               tclc->tc_line[tclc->tc_lineoffset] = in[i];\r
-               if (tclc->tc_lineoffset < TCL_MAX_LINE)\r
-                       tclc->tc_lineoffset++;\r
-               else\r
-                       tclc->tc_linedrop = 1;\r
-\r
-               if (in[i] != '\n')\r
-                       continue;\r
-\r
-               /* process the line */\r
-               if (tclc->tc_linedrop) {\r
-#define ESTR "line too long\n"\r
-                       retval = tcl_output(connection, ESTR, sizeof(ESTR));\r
-                       if (retval != ERROR_OK)\r
-                               return retval;\r
-#undef ESTR\r
-               } else {\r
-                       tclc->tc_line[tclc->tc_lineoffset-1] = '\0';\r
-                       retval = Jim_Eval(interp, tclc->tc_line);\r
-                       result = Jim_GetString(Jim_GetResult(interp), &reslen);\r
-                       retval = tcl_output(connection, result, reslen);\r
-                       if (retval != ERROR_OK)\r
-                               return retval;\r
-                       if (memchr(result, '\n', reslen) == NULL)\r
-                               tcl_output(connection, "\n", 1);\r
-               }\r
-               tclc->tc_lineoffset = 0;\r
-               tclc->tc_linedrop = 0;\r
-       }\r
-\r
-       return ERROR_OK;\r
-}\r
-\r
-static int tcl_closed(connection_t *connection)\r
-{\r
-       /* cleanup connection context */\r
-       if (connection->priv) {\r
-               free(connection->priv);\r
-               connection->priv = NULL;\r
-       }\r
-       return ERROR_OK;\r
-}\r
-\r
-int tcl_init(void)\r
-{\r
-       int retval;\r
-\r
-       if (tcl_port == 0)\r
-       {\r
-               LOG_WARNING("no tcl port specified, using default port 6666");\r
-               tcl_port = 6666;\r
-       }\r
-\r
-       retval = add_service("tcl", CONNECTION_TCL, tcl_port, 1, tcl_new_connection, tcl_input, tcl_closed, NULL);\r
-       return retval;\r
-}\r
-\r
-\r
-int tcl_register_commands(command_context_t *cmd_ctx)\r
-{\r
-       register_command(cmd_ctx, NULL, "tcl_port", handle_tcl_port_command, COMMAND_CONFIG, "");\r
-       return ERROR_OK;\r
-}\r
-\r
-static int handle_tcl_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)\r
-{\r
-       if (argc == 1) {\r
-               tcl_port = strtoul(args[0], NULL, 0);\r
-       }\r
-       return ERROR_OK;\r
-}\r
+/***************************************************************************
+ *   Copyright (C) 2008                                                    *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdarg.h>
+#include "tcl_server.h"
+
+#include "../jim.h"
+#include "log.h"
+#include "command.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+
+#define TCL_SERVER_VERSION     "TCL Server 0.1"
+#define TCL_MAX_LINE           (4096)
+
+typedef struct tcl_connection_s {
+       int tc_linedrop;
+       int tc_lineoffset;
+       char tc_line[TCL_MAX_LINE];
+
+       int tc_outerror; /* flag an output error */
+} tcl_connection_t;
+
+extern Jim_Interp *interp;
+static unsigned short tcl_port = 0;
+
+/* commands */
+static int handle_tcl_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+
+/* handlers */
+static int tcl_new_connection(connection_t *connection);
+static int tcl_input(connection_t *connection);
+static int tcl_output(connection_t *connection, const void *buf, ssize_t len);
+static int tcl_closed(connection_t *connection);
+
+/* write data out to a socket.
+ *
+ * this is a blocking write, so the return value must equal the length, if
+ * that is not the case then flag the connection with an output error.
+ */
+int tcl_output(connection_t *connection, const void *data, ssize_t len)
+{
+       ssize_t wlen;
+       tcl_connection_t *tclc;
+
+       tclc = connection->priv;
+       if (tclc->tc_outerror)
+               return ERROR_SERVER_REMOTE_CLOSED;
+
+       wlen = write_socket(connection->fd, data, len);
+       if (wlen == len)
+               return ERROR_OK;
+
+       LOG_ERROR("error during write: %d != %d", (int)wlen, (int)len);
+       tclc->tc_outerror = 1;
+       return ERROR_SERVER_REMOTE_CLOSED;
+}
+
+
+/* connections */
+static int tcl_new_connection(connection_t *connection)
+{
+       tcl_connection_t *tclc;
+
+       tclc = malloc(sizeof(tcl_connection_t));
+       if (tclc == NULL)
+               return ERROR_CONNECTION_REJECTED;
+
+       memset(tclc, 0, sizeof(tcl_connection_t));
+       connection->priv = tclc;
+       return ERROR_OK;
+}
+
+static int tcl_input(connection_t *connection)
+{
+       int retval;
+       int i;
+       ssize_t rlen;
+       const char *result;
+       int reslen;
+       tcl_connection_t *tclc;
+       char in[256];
+
+       rlen = read_socket(connection->fd, &in, sizeof(in));
+       if (rlen <= 0) {
+               if (rlen < 0)
+                       LOG_ERROR("error during read: %s", strerror(errno));
+               return ERROR_SERVER_REMOTE_CLOSED;
+       }
+
+       tclc = connection->priv;
+       if (tclc == NULL)
+               return ERROR_CONNECTION_REJECTED;
+
+       /* push as much data into the line as possible */
+       for (i = 0; i < rlen; i++)
+       {
+               if (!isprint(in[i]) && !isspace(in[i]))
+               {
+                       /* drop this line */
+                       tclc->tc_linedrop = 1;
+                       continue;
+               }
+
+               /* buffer the data */
+               tclc->tc_line[tclc->tc_lineoffset] = in[i];
+               if (tclc->tc_lineoffset < TCL_MAX_LINE)
+                       tclc->tc_lineoffset++;
+               else
+                       tclc->tc_linedrop = 1;
+
+               if (in[i] != '\n')
+                       continue;
+
+               /* process the line */
+               if (tclc->tc_linedrop) {
+#define ESTR "line too long\n"
+                       retval = tcl_output(connection, ESTR, sizeof(ESTR));
+                       if (retval != ERROR_OK)
+                               return retval;
+#undef ESTR
+               } else {
+                       tclc->tc_line[tclc->tc_lineoffset-1] = '\0';
+                       retval = Jim_Eval(interp, tclc->tc_line);
+                       result = Jim_GetString(Jim_GetResult(interp), &reslen);
+                       retval = tcl_output(connection, result, reslen);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       if (memchr(result, '\n', reslen) == NULL)
+                               tcl_output(connection, "\n", 1);
+               }
+               tclc->tc_lineoffset = 0;
+               tclc->tc_linedrop = 0;
+       }
+
+       return ERROR_OK;
+}
+
+static int tcl_closed(connection_t *connection)
+{
+       /* cleanup connection context */
+       if (connection->priv) {
+               free(connection->priv);
+               connection->priv = NULL;
+       }
+       return ERROR_OK;
+}
+
+int tcl_init(void)
+{
+       int retval;
+
+       if (tcl_port == 0)
+       {
+               LOG_WARNING("no tcl port specified, using default port 6666");
+               tcl_port = 6666;
+       }
+
+       retval = add_service("tcl", CONNECTION_TCL, tcl_port, 1, tcl_new_connection, tcl_input, tcl_closed, NULL);
+       return retval;
+}
+
+
+int tcl_register_commands(command_context_t *cmd_ctx)
+{
+       register_command(cmd_ctx, NULL, "tcl_port", handle_tcl_port_command, COMMAND_CONFIG, "");
+       return ERROR_OK;
+}
+
+static int handle_tcl_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+       if (argc == 1) {
+               tcl_port = strtoul(args[0], NULL, 0);
+       }
+       return ERROR_OK;
+}
index 7ce8f2f..c90dc8e 100644 (file)
@@ -1,28 +1,28 @@
-/***************************************************************************\r
- *   Copyright (C) 2008                                                    *\r
- *                                                                         *\r
- *   This program is free software; you can redistribute it and/or modify  *\r
- *   it under the terms of the GNU General Public License as published by  *\r
- *   the Free Software Foundation; either version 2 of the License, or     *\r
- *   (at your option) any later version.                                   *\r
- *                                                                         *\r
- *   This program is distributed in the hope that it will be useful,       *\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
- *   GNU General Public License for more details.                          *\r
- *                                                                         *\r
- *   You should have received a copy of the GNU General Public License     *\r
- *   along with this program; if not, write to the                         *\r
- *   Free Software Foundation, Inc.,                                       *\r
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *\r
- ***************************************************************************/\r
-\r
-#ifndef _TCL_SERVER_H_\r
-#define _TCL_SERVER_H_\r
-\r
-#include "server.h"\r
-\r
-extern int tcl_init(void);\r
-extern int tcl_register_commands(command_context_t *cmd_ctx);\r
-\r
-#endif /* _TCL_SERVER_H_ */\r
+/***************************************************************************
+ *   Copyright (C) 2008                                                    *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#ifndef _TCL_SERVER_H_
+#define _TCL_SERVER_H_
+
+#include "server.h"
+
+extern int tcl_init(void);
+extern int tcl_register_commands(command_context_t *cmd_ctx);
+
+#endif /* _TCL_SERVER_H_ */
index fc39c72..cc79ea4 100644 (file)
@@ -658,11 +658,3 @@ int handle_exit_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
 {
        return ERROR_COMMAND_CLOSE_CONNECTION;
 }
-
-/*
- * Local Variables: **
- * tab-width: 4 **
- * c-basic-offset: 4 **
- * End: **
- */
-
index 86b42db..da70f3e 100644 (file)
@@ -2671,4 +2671,3 @@ int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **
        
        return ERROR_OK;
 }
-