]> www.wagner.pp.ru Git - oss/tclsyslog.git/commitdiff
reapplyed 2.0 changes master
authorVictor Wagner <vitus@wagner.pp.ru>
Fri, 24 Feb 2006 14:13:07 +0000 (14:13 +0000)
committerVictor Wagner <vitus@wagner.pp.ru>
Fri, 24 Feb 2006 14:13:07 +0000 (14:13 +0000)
Makefile
README
syslog.n
tclsyslog.c

index 1ec1f84a9e0f3abf98ba1ce75152de241d23237f..fc32a3cb0fb7613cce99f32f716939018f5d2e9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=1.1
+VERSION=2.0
 # This is root of installation tree
 PREFIX=/usr/local
 CC=gcc
@@ -6,10 +6,11 @@ CC=gcc
 # Don't forget to change if your CC is not gcc
 #
 CFLAGS=-Wall -fPIC
-LDFLAGS=-shared
-# No need to link with libtcl8.0 on ELF system. Your setup might be
-# different
-LOADLIBES=
+LDFLAGS=-shared -L/usr/local/lib
+# Have to set it manually becouse otherwise gcc would pick includes from
+# 8.0 on my system
+INCLUDES=-I/usr/local/include
+LOADLIBES=-ltclstub8.2
 # This is where package would be installed
 LIBDIR=${PREFIX}/lib
 # On my Debian system this would be
@@ -28,7 +29,7 @@ INSTALL=/usr/bin/install
 all: libsyslog.so.${VERSION} pkgIndex.tcl
 
 libsyslog.so.${VERSION}: tclsyslog.o
-       gcc ${LDFLAGS} -o libsyslog.so.${VERSION} -DVERSION=\"${VERSION}\" tclsyslog.o ${LOADLIBES}
+       gcc ${LDFLAGS} -o libsyslog.so.${VERSION} -DUSE_TCL_STUBS -DVERSION=\"${VERSION}\" tclsyslog.o ${LOADLIBES}
 
 tclsyslog.o: tclsyslog.c
        ${CC} ${CFLAGS} ${INCLUDES} -DVERSION=\"${VERSION}\" -c tclsyslog.c
diff --git a/README b/README
index 76e411f0e376f95f95b56b978e6458225f9b9760..41ebb708c5d005c909ac5e156bde464e8c2a8ce2 100644 (file)
--- a/README
+++ b/README
@@ -8,10 +8,11 @@ got time for writing proper autoconf configuration, but should be fairly
 easy to configure and build by anybody who knows what syslog is and why
 to use it.
 
-This version is designed for Tcl 8.0 or below. It uses old string-based
-API and should be compatible with any Tcl version down to 7.4
+This version is designed for Tcl 8.1 and above. It is unicode-aware and
+convert messages to current system encoding before sending them to
+syslog. And it uses stubs.
 
-If you use tcl 8.1 or above go and get tclsyslog-2.0 
+If you use tcl 8.0.x go and get tclsyslog-1.1 
 
 Home site of this package is at
 
@@ -21,7 +22,7 @@ Installation
 
 1. Edit variables on the top of Makefile
 2. Do make all
-3. Test extension by loading it into tclsh via load ./libsyslog.so.1.1 
+3. Test extension by loading it into tclsh via load ./libsyslog.so.2.0 
    and sending couple of messages from command line
 4. Verify that PREFIX variable set so that ${PREFIX}/lib is included in
    your tcl_pkgPath (or set LIBDIR to directory in tcl_pkgPath)
index ae90ce0df8a664ebd6f4b74eebcd0eafbb8c4b0b..b74903fa0be83b4e7f40c90ffaf67bf086b33e96 100644 (file)
--- a/syslog.n
+++ b/syslog.n
@@ -2,7 +2,7 @@
 '\" Copyright (c) 1999 Victor B. Wagner
 '\"
 '\" 
-'\" RCS: @(#) $Id: syslog.n,v 1.1 2006-02-24 14:11:33 vitus Exp $
+'\" RCS: @(#) $Id: syslog.n,v 1.2 2006-02-24 14:13:07 vitus Exp $
 '\" 
 '\" The definitions below are for supplemental macros used in Tcl/Tk
 '\" manual entries.
@@ -65,7 +65,7 @@
 '\" .UL arg1 arg2
 '\"    Print arg1 underlined, then print arg2 normally.
 '\"
-'\" RCS: @(#) $Id: syslog.n,v 1.1 2006-02-24 14:11:33 vitus Exp $
+'\" RCS: @(#) $Id: syslog.n,v 1.2 2006-02-24 14:13:07 vitus Exp $
 '\"
 '\"    # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
 .if t .wh -1.3i ^B
index ca97600065e3b0d1ad0730fa44184ba8101c309e..c2409058fdaa461119dcf70c5d73662c56b00b10 100644 (file)
@@ -30,22 +30,23 @@ void SyslogHelp(Tcl_Interp *interp,char *cmdname)
  */
 
 
-int Syslog_Log(ClientData data, Tcl_Interp *interp, int argc, char **argv)
+int Syslog_Log(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST  objv[])
 {    SyslogInfo *info=(SyslogInfo *)data;
-    char *message = NULL;
+    Tcl_DString *message = NULL;
     int priority;
     int i=1;
-    if (argc<=1) {
-        SyslogHelp(interp,argv[0]);
+    if (objc<=1) {
+        SyslogHelp(interp,Tcl_GetString(objv[0]));
         return TCL_ERROR;
     }
-  while (i<argc-1) {
-    if (!strcmp(argv[i],"-facility")) {
-        Tcl_HashEntry * entry=Tcl_FindHashEntry(info->facilities,argv[i+1]);
+  while (i<objc-1) {
+    if (!strncmp(Tcl_GetString(objv[i]),"-facility",10)) {
+       char *facility_name = Tcl_GetString(objv[i+1]);
+        Tcl_HashEntry * entry=Tcl_FindHashEntry(info->facilities,facility_name);
         if (!entry) {
-           Tcl_AppendResult(interp,"Invalid facility name: \"",argv[i+1],
-                  "\" available facilities:",
-               NULL);
+           Tcl_AppendResult(interp,"Invalid facility name: \"",Tcl_GetString(objv[i+1]),"\"",
+                " available facilities: ",
+                  NULL);
           Syslog_ListHash(interp,info->facilities);
            return TCL_ERROR;
         }
@@ -54,43 +55,56 @@ int Syslog_Log(ClientData data, Tcl_Interp *interp, int argc, char **argv)
             closelog();
             info-> logOpened=0;
         }
-     } else if (!strcmp(argv[i],"-options")) {
-         int tmp;
-        if (Tcl_GetInt(interp,argv[i+1],&tmp)==TCL_ERROR)
+     } else if (!strncmp(Tcl_GetString(objv[i]),"-options",9)) {
+         long tmp;
+        if (Tcl_GetLongFromObj(interp,objv[i+1],&tmp)==TCL_ERROR)
              return TCL_ERROR;
         info->options=tmp;
         if (info->logOpened) {
             closelog();
             info->logOpened=0;
         }
-     } else if (!strcmp(argv[i],"-ident")) {
-        strncpy(info->ident, argv[i+1],32);
+     } else if (!strncmp(Tcl_GetStringFromObj(objv[i],NULL),"-ident",7)) {
+        char *ident_name=Tcl_GetString(objv[i+1]);
+       Tcl_DString *dstring=(Tcl_DString *)Tcl_Alloc(sizeof(Tcl_DString));
+       Tcl_DStringInit(dstring);
+       Tcl_UtfToExternalDString(NULL,ident_name,strlen(ident_name),
+          dstring);             
+        strncpy(info->ident,Tcl_DStringValue(dstring),32);
+        Tcl_DStringFree(dstring);
+        Tcl_Free((char *)dstring);
         info->ident[31]=0;
         if (info->logOpened) {
             closelog();
             info->logOpened=0;
         }
      } else {
-       Tcl_HashEntry *entry=Tcl_FindHashEntry(info->priorities,argv[i]);
+        char *messageutf;
+       Tcl_HashEntry *entry=Tcl_FindHashEntry(info->priorities,Tcl_GetString(objv[i]));
        if (!entry) {
-          Tcl_AppendResult(interp,"Invalid syslog level \"",argv[i],
-                 "\" available levels:",
+          Tcl_AppendResult(interp,"Invalid syslog level \"",Tcl_GetString(objv[i]),"\"",
+                 " available levels: ",
                NULL);
          Syslog_ListHash(interp,info->priorities); 
           return TCL_ERROR;
        }
        priority=(int)Tcl_GetHashValue(entry);
-       message=argv[i+1];
+       message=(Tcl_DString *)Tcl_Alloc(sizeof(Tcl_DString));
+       Tcl_DStringInit(message);
+       messageutf=Tcl_GetString(objv[i+1]);
+       Tcl_UtfToExternalDString(NULL,messageutf,strlen(messageutf),
+               message);
+      
        i+=2;
-       if (i<argc-1) {
-           SyslogHelp(interp,argv[0]);
+       if (i<objc-1) {
+           SyslogHelp(interp,Tcl_GetString(objv[0]));
            return TCL_ERROR;
        }
      }
      i+=2;
   }
-  if (i<argc-1) {
-     SyslogHelp(interp,argv[0]);
+  if (i<objc-1) {
+     SyslogHelp(interp,Tcl_GetString(objv[0]));
      return TCL_ERROR;
   }
   if (message) {
@@ -98,10 +112,28 @@ int Syslog_Log(ClientData data, Tcl_Interp *interp, int argc, char **argv)
          openlog(info->ident,info->options,info->facility);
          info->logOpened=1;
       }
-      syslog(priority,"%s",message);
+      syslog(priority,"%s",Tcl_DStringValue(message));
+      Tcl_DStringFree(message);
+      Tcl_Free((char *)message);
   }
   return TCL_OK;
 }
+/* 
+ *  Syslog_Delete - Tcl_CmdDeleteProc for syslog command.
+ *  Frees all hash tables and closes log if it was opened.
+ */
+void Syslog_Delete(ClientData data)
+{ SyslogInfo *info=(SyslogInfo *)data;
+  Tcl_DeleteHashTable(info->facilities);
+  Tcl_Free((char *)info->facilities);
+  Tcl_DeleteHashTable(info->priorities);
+  Tcl_Free((char *)info->priorities);
+  if (info->logOpened) {
+     closelog();
+  }
+  Tcl_Free((char *)info);
+}
+
 /*
  * Syslog_ListHash - appends to interp result all the values of given
  * hash table
@@ -120,21 +152,6 @@ void Syslog_ListHash(Tcl_Interp *interp,Tcl_HashTable *table)
     }   
     Tcl_Free((char *)searchPtr);
 } 
-/* 
- *  Syslog_Delete - Tcl_CmdDeleteProc for syslog command.
- *  Frees all hash tables and closes log if it was opened.
- */
-void Syslog_Delete(ClientData data)
-{ SyslogInfo *info=(SyslogInfo *)data;
-  Tcl_DeleteHashTable(info->facilities);
-  Tcl_Free((char *)info->facilities);
-  Tcl_DeleteHashTable(info->priorities);
-  Tcl_Free((char *)info->priorities);
-  if (info->logOpened) {
-     closelog();
-  }
-  Tcl_Free((char *)info);
-}
 /*
  * My simplified wrapper for add values into hash
  *
@@ -152,7 +169,11 @@ void AddEntry(Tcl_HashTable *table,char *key,int value)
  */
 int Syslog_Init(Tcl_Interp *interp)
 {  char *argv0;
-   SyslogInfo *info=(SyslogInfo *)Tcl_Alloc(sizeof(SyslogInfo));
+    SyslogInfo *info;
+   if (Tcl_InitStubs(interp,"8.1",0)==NULL) {
+      return TCL_ERROR;
+   }     
+   info=(SyslogInfo *)Tcl_Alloc(sizeof(SyslogInfo));
    info->logOpened=0;
    info->options=0;
    info->facility=LOG_USER;
@@ -198,7 +219,7 @@ int Syslog_Init(Tcl_Interp *interp)
    AddEntry(info->priorities,"notice",LOG_NOTICE);
    AddEntry(info->priorities,"info",LOG_INFO);
    AddEntry(info->priorities,"debug",LOG_DEBUG);
-   Tcl_CreateCommand(interp,"syslog",Syslog_Log,(ClientData) info,
+   Tcl_CreateObjCommand(interp,"syslog",Syslog_Log,(ClientData) info,
             Syslog_Delete); 
    return Tcl_PkgProvide(interp,"Syslog",VERSION);
 }