Permalink
Browse files

many comment changes, some small code changes

Sweep through and clean up all (most) of the comments in the code.
While there, adjust some variable and function names to be more consistent,
and make a few small code changes - again, mostly for consistency.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent 30a78d4 commit fcfb8169cfa5fefe5610bcc4297500ead2dfaf42 @msteveb committed Jan 11, 2014
Showing with 334 additions and 381 deletions.
  1. +21 −21 jim-aio.c
  2. +1 −2 jim-clock.c
  3. +6 −10 jim-eventloop.c
  4. +10 −8 jim-eventloop.h
  5. +17 −30 jim-exec.c
  6. +6 −11 jim-file.c
  7. +0 −1 jim-format.c
  8. +1 −1 jim-history.c
  9. +1 −1 jim-interactive.c
  10. +5 −1 jim-regexp.c
  11. +18 −16 jim-signal.h
  12. +7 −0 jim-subcmd.c
  13. +2 −2 jim-subcmd.h
  14. +0 −1 jim-syslog.c
  15. +8 −0 jim-win32compat.h
  16. +164 −202 jim.c
  17. +33 −52 jim.h
  18. +4 −3 jimregexp.c
  19. +9 −17 jimregexp.h
  20. +6 −0 nshelper.tcl
  21. +2 −0 stdlib.tcl
  22. +4 −2 tclcompat.tcl
  23. +9 −0 utf8.h
View
@@ -54,7 +54,6 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
-#include <unistd.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -112,7 +111,7 @@ typedef struct AioFile
FILE *fp;
Jim_Obj *filename;
int type;
- int OpenFlags; /* AIO_KEEPOPEN? keep FILE* */
+ int openFlags; /* AIO_KEEPOPEN? keep FILE* */
int fd;
Jim_Obj *rEvent;
Jim_Obj *wEvent;
@@ -284,7 +283,7 @@ static void JimAioDelProc(Jim_Interp *interp, void *privData)
JIM_NOTUSED(interp);
- if (!(af->OpenFlags & AIO_KEEPOPEN)) {
+ if (!(af->openFlags & AIO_KEEPOPEN)) {
fclose(af->fp);
}
@@ -1023,26 +1022,26 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *mode;
- const char *filename;
- if (argc != 2 && argc != 3) {
+ if (argc != 2 && argc != 3)
Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
- return JIM_ERR;
- }
mode = (argc == 3) ? Jim_String(argv[2]) : "r";
- filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
- /* If the filename starts with '|', use popen instead */
- if (*filename == '|') {
- Jim_Obj *evalObj[3];
+ {
+ const char *filename = Jim_String(argv[1]);
+
+ /* If the filename starts with '|', use popen instead */
+ if (*filename == '|') {
+ Jim_Obj *evalObj[3];
- evalObj[0] = Jim_NewStringObj(interp, "::popen", -1);
- evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
- evalObj[2] = Jim_NewStringObj(interp, mode, -1);
+ evalObj[0] = Jim_NewStringObj(interp, "::popen", -1);
+ evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
+ evalObj[2] = Jim_NewStringObj(interp, mode, -1);
- return Jim_EvalObjVector(interp, 3, evalObj);
+ return Jim_EvalObjVector(interp, 3, evalObj);
+ }
}
#endif
return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
@@ -1051,8 +1050,8 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
/**
* Creates a channel for fh/fd/filename.
*
- * If fh is not NULL, uses that as the channel (and set AIO_KEEPOPEN).
- * Otherwise, if fd is >= 0, uses that as the chanel.
+ * If fh is not NULL, uses that as the channel (and sets AIO_KEEPOPEN).
+ * Otherwise, if fd is >= 0, uses that as the channel.
* Otherwise opens 'filename' with mode 'mode'.
*
* hdlfmt is a sprintf format for the filehandle. Anything with %ld at the end will do.
@@ -1065,11 +1064,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
{
AioFile *af;
char buf[AIO_CMD_LEN];
- int OpenFlags = 0;
+ int openFlags = 0;
if (fh) {
filename = Jim_NewStringObj(interp, hdlfmt, -1);
- OpenFlags = AIO_KEEPOPEN;
+ openFlags = AIO_KEEPOPEN;
}
Jim_IncrRefCount(filename);
@@ -1102,11 +1101,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
af->fd = fileno(fh);
af->filename = filename;
#ifdef FD_CLOEXEC
- if ((OpenFlags & AIO_KEEPOPEN) == 0) {
+ if ((openFlags & AIO_KEEPOPEN) == 0) {
fcntl(af->fd, F_SETFD, FD_CLOEXEC);
}
#endif
- af->OpenFlags = OpenFlags;
+ af->openFlags = openFlags;
af->addr_family = family;
snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
@@ -1413,6 +1412,7 @@ FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
{
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
+ /* XXX: There ought to be a supported API for this */
if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) {
return ((AioFile *) cmdPtr->u.native.privData)->fp;
}
View
@@ -1,6 +1,5 @@
-
/*
- * tcl_clock.c
+ * jim-clock.c
*
* Implements the clock command
*/
View
@@ -1,4 +1,3 @@
-
/* Jim - A small embeddable Tcl interpreter
*
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
@@ -84,8 +83,7 @@ typedef struct Jim_FileEvent
typedef struct Jim_TimeEvent
{
jim_wide id; /* time event identifier. */
- int mode; /* restart, repetitive .. UK */
- long initialms; /* initial relativ timer value UK */
+ long initialms; /* initial relative timer value */
jim_wide when; /* milliseconds */
Jim_TimeProc *timeProc;
Jim_EventFinalizerProc *finalizerProc;
@@ -207,7 +205,6 @@ jim_wide Jim_CreateTimeHandler(Jim_Interp *interp, jim_wide milliseconds,
te = Jim_Alloc(sizeof(*te));
te->id = id;
- te->mode = 0;
te->initialms = milliseconds;
te->when = JimGetTime(eventLoop) + milliseconds;
te->timeProc = proc;
@@ -323,17 +320,16 @@ jim_wide Jim_DeleteTimeHandler(Jim_Interp *interp, jim_wide id)
/* Process every pending time event, then every pending file event
* (that may be registered by time event callbacks just processed).
- * Without special flags the function sleeps until some file event
- * fires, or when the next time event occurrs (if any).
+ * The behaviour depends upon the setting of flags:
*
* If flags is 0, the function does nothing and returns.
- * if flags has JIM_ALL_EVENTS set, all the kind of events are processed.
+ * if flags has JIM_ALL_EVENTS set, all event types are processed.
* if flags has JIM_FILE_EVENTS set, file events are processed.
* if flags has JIM_TIME_EVENTS set, time events are processed.
- * if flags has JIM_DONT_WAIT set the function returns ASAP until all
- * the events that's possible to process without to wait are processed.
+ * if flags has JIM_DONT_WAIT set, the function returns as soon as all
+ * the events that are possible to process without waiting are processed.
*
- * The function returns the number of events processed or -1 if
+ * Returns the number of events processed or -1 if
* there are no matching handlers, or -2 on error.
*/
int Jim_ProcessEvents(Jim_Interp *interp, int flags)
View
@@ -36,20 +36,18 @@
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the Jim Tcl Project.
**/
+
/* ------ USAGE -------
- *
- * In order to use this file from other extensions include it in every
- * file where you need to call the eventloop API, also in the init
- * function of your extension call Jim_ImportEventloopAPI(interp)
- * after the Jim_InitExtension() call.
- *
- * See the UDP extension as example.
+ * See jim-aio.c as an example of an event provider.
*/
-
#ifndef __JIM_EVENTLOOP_H__
#define __JIM_EVENTLOOP_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdio.h>
typedef int Jim_FileProc(Jim_Interp *interp, void *clientData, int mask);
@@ -84,4 +82,8 @@ JIM_EXPORT int Jim_EvalObjBackground (Jim_Interp *interp, Jim_Obj *scriptObjPtr)
int Jim_eventloopInit(Jim_Interp *interp);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __JIM_EVENTLOOP_H__ */
View
@@ -81,6 +81,7 @@ int Jim_execInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
return JIM_ERR;
+
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL);
return JIM_OK;
}
@@ -239,6 +240,7 @@ static char **JimBuildEnv(Jim_Interp *interp)
/* Calculate the required size */
num = Jim_ListLength(interp, objPtr);
if (num % 2) {
+ /* Silently drop the last element if not a valid dictionary */
num--;
}
/* We need one \0 and one equal sign for each element.
@@ -284,10 +286,10 @@ static void JimFreeEnv(char **env, char **original_environ)
}
/*
- * Create error messages for unusual process exits. An
- * extra newline gets appended to each error message, but
- * it gets removed below (in the same fashion that an
- * extra newline in the command's output is removed).
+ * Create and store an appropriate value for the global variable $::errorCode
+ * Based on pid and waitStatus.
+ *
+ * Returns JIM_OK for a normal exit with code 0, otherwise returns JIM_ERR.
*/
static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus)
{
@@ -343,15 +345,15 @@ static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus)
struct WaitInfo
{
- pidtype pid; /* Process id of child. */
+ pidtype pid; /* Process id of child. */
int status; /* Status returned when child exited or suspended. */
int flags; /* Various flag bits; see below for definitions. */
};
struct WaitInfoTable {
- struct WaitInfo *info;
- int size;
- int used;
+ struct WaitInfo *info; /* Table of outstanding processes */
+ int size; /* Size of the allocated table */
+ int used; /* Number of entries in use */
};
/*
@@ -388,15 +390,13 @@ static struct WaitInfoTable *JimAllocWaitInfoTable(void)
*/
static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- fdtype outputId; /* File id for output pipe. -1
- * means command overrode. */
- fdtype errorId; /* File id for temporary file
- * containing error output. */
+ fdtype outputId; /* File id for output pipe. -1 means command overrode. */
+ fdtype errorId; /* File id for temporary file containing error output. */
pidtype *pidPtr;
int numPids, result;
/*
- * See if the command is to be run in background; if so, create
+ * See if the command is to be run in the background; if so, create
* the command, detach it, and return.
*/
if (argc > 1 && Jim_CompareStringImmediate(interp, argv[argc - 1], "&")) {
@@ -507,24 +507,11 @@ static pidtype JimWaitForProcess(struct WaitInfoTable *table, pidtype pid, int *
return JIM_BAD_PID;
}
-/*
- *----------------------------------------------------------------------
- *
- * JimDetachPids --
- *
- * This procedure is called to indicate that one or more child
- * processes have been placed in background and are no longer
- * cared about. These children can be cleaned up with JimReapDetachedPids().
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
+/**
+ * Indicates that one or more child processes have been placed in
+ * background and are no longer cared about.
+ * These children can be cleaned up with JimReapDetachedPids().
*/
-
static void JimDetachPids(Jim_Interp *interp, int numPids, const pidtype *pidPtr)
{
int j;
View
@@ -351,10 +351,7 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int file_access(Jim_Interp *interp, Jim_Obj *filename, int mode)
{
- const char *path = Jim_String(filename);
- int rc = access(path, mode);
-
- Jim_SetResultBool(interp, rc != -1);
+ Jim_SetResultBool(interp, access(Jim_String(filename), mode) != -1);
return JIM_OK;
}
@@ -374,9 +371,7 @@ static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *arg
#ifdef X_OK
return file_access(interp, argv[0], X_OK);
#else
- /* XXX: X_OK doesn't work under Windows.
- * In any case, may need to add .exe, etc. so just lie!
- */
+ /* If no X_OK, just assume true. */
Jim_SetResultBool(interp, 1);
return JIM_OK;
#endif
@@ -930,11 +925,11 @@ static int Jim_CdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- const int cwd_len = 2048;
- char *cwd = malloc(cwd_len);
+ char *cwd = Jim_Alloc(MAXPATHLEN);
- if (getcwd(cwd, cwd_len) == NULL) {
+ if (getcwd(cwd, MAXPATHLEN) == NULL) {
Jim_SetResultString(interp, "Failed to get pwd", -1);
+ Jim_Free(cwd);
return JIM_ERR;
}
#if defined(__MINGW32__) || defined(_MSC_VER)
@@ -949,7 +944,7 @@ static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResultString(interp, cwd, -1);
- free(cwd);
+ Jim_Free(cwd);
return JIM_OK;
}
View
@@ -45,7 +45,6 @@
#include <jim.h>
#include "utf8.h"
-#define JIM_UTF_MAX 3
#define JIM_INTEGER_SPACE 24
#define MAX_FLOAT_WIDTH 320
View
@@ -11,7 +11,7 @@ static int history_cmd_getline(Jim_Interp *interp, int argc, Jim_Obj *const *arg
Jim_Obj *objPtr;
char *line = Jim_HistoryGetline(Jim_String(argv[0]));
- /* On EOF returns -1 if varName was specified, or the empty string. */
+ /* On EOF returns -1 if varName was specified; otherwise the empty string. */
if (line == NULL) {
if (argc == 2) {
Jim_SetResultInt(interp, -1);
View
@@ -87,7 +87,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
}
#endif
- printf("Welcome to Jim version %d.%d" JIM_NL,
+ printf("Welcome to Jim version %d.%d\n",
JIM_VERSION / 100, JIM_VERSION % 100);
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
View
@@ -49,8 +49,12 @@
#include <string.h>
#include "jimautoconf.h"
+#if defined(JIM_REGEXP)
+ #include "jimregexp.h"
+#else
+ #include <regex.h>
+#endif
#include "jim.h"
-#include "jimregexp.h"
static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
Oops, something went wrong.

0 comments on commit fcfb816

Please sign in to comment.