From 3a4195e4293dce547f9fd671063d9b65ca14cc56 Mon Sep 17 00:00:00 2001
From: dos-reis <gdr@axiomatics.org>
Date: Mon, 1 Apr 2013 01:53:29 +0000
Subject: More C cleanups

---
 config/open-axiom.m4            |  1 +
 config/openaxiom-c-macros.h.in  |  6 ++++++
 configure                       | 14 ++++++++++++++
 src/clef/edible.c               |  3 ++-
 src/graph/view2D/spadAction2d.c |  6 +++---
 src/hyper/ex2ht.c               |  3 ++-
 src/hyper/htadd.c               |  3 ++-
 src/hyper/hthits.c              |  3 ++-
 src/hyper/hyper.c               |  4 +++-
 src/hyper/spadbuf.c             |  4 +++-
 src/lib/cfuns-c.c               |  2 ++
 src/sman/session.c              |  4 ++--
 src/sman/sman.c                 |  2 +-
 src/sman/spadclient.c           |  3 ++-
 14 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/config/open-axiom.m4 b/config/open-axiom.m4
index 69645b17..90f3e8cd 100644
--- a/config/open-axiom.m4
+++ b/config/open-axiom.m4
@@ -785,6 +785,7 @@ dnl -----------------------------
 dnl -- OPENAXIOM_CHECK_PROCESS --
 dnl -----------------------------
 AC_DEFUN([OPENAXIOM_CHECK_PROCESS],[
+AC_CHECK_HEADERS([setenv, putenv], [], [], [#include <stdlib.h>])
 AC_CHECK_DECLS([getuid, geteuid, getgid, getegid], [], [],
                [#include <unistd.h>])
 AC_CHECK_HEADERS([sys/wait.h])
diff --git a/config/openaxiom-c-macros.h.in b/config/openaxiom-c-macros.h.in
index e0b7c3f7..8931f245 100644
--- a/config/openaxiom-c-macros.h.in
+++ b/config/openaxiom-c-macros.h.in
@@ -90,6 +90,12 @@
 /* Define to 1 if you have the <pty.h> header file. */
 #undef HAVE_PTY_H
 
+/* Define to 1 if you have the <putenv> header file. */
+#undef HAVE_PUTENV
+
+/* Define to 1 if you have the <setenv,> header file. */
+#undef HAVE_SETENV_
+
 /* Define to 1 if you have the <signal.h> header file. */
 #undef HAVE_SIGNAL_H
 
diff --git a/configure b/configure
index 1b35c1b2..124b626c 100755
--- a/configure
+++ b/configure
@@ -18099,6 +18099,20 @@ rm -f conftest*
 
 
 
+for ac_header in setenv, putenv
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_cxx_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "#include <stdlib.h>
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
 ac_fn_cxx_check_decl "$LINENO" "getuid" "ac_cv_have_decl_getuid" "#include <unistd.h>
 "
 if test "x$ac_cv_have_decl_getuid" = xyes; then :
diff --git a/src/clef/edible.c b/src/clef/edible.c
index dd07181b..71900805 100644
--- a/src/clef/edible.c
+++ b/src/clef/edible.c
@@ -127,6 +127,7 @@ char logpath[30];
 int
 main(int argc, char *argv[])
 {
+   using namespace OpenAxiom;
   fd_set rfds;                  /* the structure for the select call */
   int code;                    /* return code from system calls */
   char out_buff[MAXLINE];       /* from child and stdin */
@@ -137,7 +138,7 @@ main(int argc, char *argv[])
   
   
 
-  putenv((char*) "LC_ALL=C");
+  oa_setenv("LC_ALL", "C");
   setlocale(LC_ALL, "");
   /* try to get a pseudoterminal to play with */
   if (ptyopen(&contNum, &serverNum, serverPath) == -1) {
diff --git a/src/graph/view2D/spadAction2d.c b/src/graph/view2D/spadAction2d.c
index eafd4325..60789eb1 100644
--- a/src/graph/view2D/spadAction2d.c
+++ b/src/graph/view2D/spadAction2d.c
@@ -69,7 +69,7 @@ extern int viewAloned;
 int 
 spadAction(void)
 {
-  int code,viewCommand;
+  int viewCommand;
   float f1,f2;
   int i1,i2,i3,viewGoAhead;
   static int ack = 1;
@@ -121,7 +121,7 @@ spadAction(void)
     break;
 
   case closeAll2D:
-    code = check(write(Socket,&ack,intSize));
+    check(write(Socket,&ack,intSize));
     goodbye(-1);
 
   case ps2D:
@@ -282,7 +282,7 @@ spadAction(void)
 
 
   ack++;
-  code = check(write(Socket,&ack,intSize));
+  check(write(Socket,&ack,intSize));
   return(0);
 
 }
diff --git a/src/hyper/ex2ht.c b/src/hyper/ex2ht.c
index bbb1db14..3637776a 100644
--- a/src/hyper/ex2ht.c
+++ b/src/hyper/ex2ht.c
@@ -267,9 +267,10 @@ exToHt(const char* filename)
 int
 main(int argc, char **argv)
 {
+   using namespace OpenAxiom;
     int i;
 
-    putenv("LC_ALL=C");
+    oa_setenv("LC_ALL", "C");
     setlocale(LC_ALL, "");
     if (argc == 1) {
         fprintf(stderr, "usage: %s exfile.ht ...\n", argv[0]);
diff --git a/src/hyper/htadd.c b/src/hyper/htadd.c
index d8c32a75..e28bd31d 100644
--- a/src/hyper/htadd.c
+++ b/src/hyper/htadd.c
@@ -91,6 +91,7 @@ int fresh = 0;
 int
 main(int argc, char **argv)
 {
+   using namespace OpenAxiom;
     /*int i;*/
     char db_dir[256];           /* the directory where the db file is */
     char dbfilename[256];       /* the database filename */
@@ -98,7 +99,7 @@ main(int argc, char **argv)
     char **fnames = filenames;
     short flag;                 /* flag for deleting or adding */
 
-    putenv("LC_ALL=C");
+    oa_setenv("LC_ALL", "C");
     setlocale(LC_ALL, "");
     parse_args(argv, db_dir, filenames, &flag);
 
diff --git a/src/hyper/hthits.c b/src/hyper/hthits.c
index d2e2cfb9..0dd712c5 100644
--- a/src/hyper/hthits.c
+++ b/src/hyper/hthits.c
@@ -413,7 +413,8 @@ cmdline(int argc, char** argv)
 int
 main(int argc, char** argv)
 {
-    putenv("LC_ALL=C");
+   using namespace OpenAxiom;
+   oa_setenv("LC_ALL", "C");
     setlocale(LC_ALL, "");
     cmdline(argc, argv);
     regcomp(&reg_pattern, pattern, REG_NEWLINE);
diff --git a/src/hyper/hyper.c b/src/hyper/hyper.c
index e88f63f0..f306e0b8 100644
--- a/src/hyper/hyper.c
+++ b/src/hyper/hyper.c
@@ -52,6 +52,7 @@
 #include <locale.h>
 
 #include "debug.h"
+#include "cfuns.h"
 #include "sockio.h"
 #include "hyper.h"
 #include "lex.h"
@@ -196,11 +197,12 @@ clean_socket(void )
 int
 main(int argc, char **argv)
 {
+   using namespace OpenAxiom;
     int ret_status;
 
     /* Initialize some global values */
 /*    fprintf(stderr,"hyper:main:entered\n");*/
-    putenv("LC_ALL=C");
+    oa_setenv("LC_ALL", "C");
     setlocale(LC_ALL, "");
     gArgc = argc;
     gArgv = argv;
diff --git a/src/hyper/spadbuf.c b/src/hyper/spadbuf.c
index e173b86f..18f28c0e 100644
--- a/src/hyper/spadbuf.c
+++ b/src/hyper/spadbuf.c
@@ -49,6 +49,7 @@
 #include <locale.h>
 #include "halloc.h"
 #include "bsdsignal.h"
+#include "cfuns.h"
 #include "sockio.h"
 #include "edible.h"
 #include "com.h"
@@ -215,6 +216,7 @@ init_parent(void)
 int
 main(int argc,char **  argv)
 {
+   using namespace OpenAxiom;
     /*
      * Modified on 6/13/90 for the command line completion abiltities of
      * Since I am only calling this program from within spadint, I decided
@@ -223,7 +225,7 @@ main(int argc,char **  argv)
      * spadbuf page_name [completion_ files]
      *
      */
-    putenv("LC_ALL=C");
+   oa_setenv("LC_ALL", "C");
     setlocale(LC_ALL, "");
     if (argc < 2) {
         fprintf(stderr, "Usage : spadbuf page_name [completion_files] \n");
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c
index 049d7305..1b75219e 100644
--- a/src/lib/cfuns-c.c
+++ b/src/lib/cfuns-c.c
@@ -595,6 +595,8 @@ oa_setenv(const char* var, const char* val)
 {
 #ifdef __WIN32__
    return SetEnvironmentVariable(var, val);
+#elif HAVE_DECL_SETENV
+   return !setenv(var, val, true);
 #else
    const int var_length = strlen(var);
    const int val_length = strlen(val);
diff --git a/src/sman/session.c b/src/sman/session.c
index 2a64dbc2..42c0ada4 100644
--- a/src/sman/session.c
+++ b/src/sman/session.c
@@ -466,13 +466,13 @@ fprintf(stderr,"rd=%u]\n",*((long *)rd.fds_bits));
 int
 main(void)
 {
-
+   using namespace OpenAxiom;
 #ifdef DEBUG2
   /* delay for attaching with debugger before interesting things happen */
    openaxiom_sleep(30);
 #endif
 
-  putenv("LC_ALL=C");
+   oa_setenv("LC_ALL", "C");
   setlocale(LC_ALL, "");
  /* spad_server connects to Lisp server socket         
     read_SpadServer_command handles requests */
diff --git a/src/sman/sman.c b/src/sman/sman.c
index bddbdfc3..1b2a243a 100644
--- a/src/sman/sman.c
+++ b/src/sman/sman.c
@@ -776,7 +776,7 @@ main(int argc, char *argv[])
   command.root_dir = get_systemdir(argc, argv);
   process_options(&command, argc, argv);
 
-  putenv((char*) "LC_ALL=C");
+  oa_setenv("LC_ALL", "C");
   setlocale(LC_ALL, "");
   bsdSignal(SIGINT,  SIG_IGN,RestartSystemCalls);
   init_term_io();
diff --git a/src/sman/spadclient.c b/src/sman/spadclient.c
index dd1d6722..8d23e1d4 100644
--- a/src/sman/spadclient.c
+++ b/src/sman/spadclient.c
@@ -63,7 +63,8 @@ inter_handler(int sig)
 int 
 main(void)
 {
-  putenv("LC_ALL=C");
+   using namespace OpenAxiom;
+   oa_setenv("LC_ALL", "C");
   setlocale(LC_ALL, "");
   sock = connect_to_local_server(SessionServer, InterpWindow, Forever);
   bsdSignal(SIGINT, inter_handler,RestartSystemCalls); 
-- 
cgit v1.2.3