ng-spice-rework14-pre2 on solaris


To ng-spice-devel@ieee.ing.uniroma1.it
From mcmahill@mtl.mit.edu
Date Sun, 11 Mar 2001 17:12:06 -0500 (EST)
Delivered-To mailing list ng-spice-devel@ieee.ing.uniroma1.it
In-Reply-To <Pine.LNX.3.96.1010311211310.20914A-100000@ieee.ing.uniroma1.it >
Mailing-List contact ng-spice-devel-help@ieee.ing.uniroma1.it; run by ezmlm
Reply-To ng-spice-devel@ieee.ing.uniroma1.it



Hi!

I spent a week at the in-laws and took the opportunity to get ng-spice
going on a solaris laptop I'd drug along.

On solaris-2.5.1/x86 using gcc 2.8.1, the following
changes were needed:

the configure check for Xaw failed because you have to link -lXmu
whenever you link -lXaw.  I hacked the configure script to just add -lXmu
when it  tested for -lXaw.

solaris was missing getopt.h so I copied getopt.h, getopt.c, and getopt1.c
from GNU into src/.  added getopt.o and getopt1.o to the link lines for
ngspice and ngnutmeg.  I guess there should be an autoconf test for this
since some systems already have getopt, but others don't.  I'm not enough
of an automake expert to know how to do this the right way.

solaris didn't seem to have asprintf so I worked around that.  i guess
either the modified code can be used, or perhaps get a copy of asprintf()
sources from GNU and include those if autoconf determines that asprintf
isn't part of the system.  I attached patches for getting rid of
asprintf().

Sorry this isn't in the form of a much cleaner patch.

-Dan



--- src/main.c.orig     Wed Feb  7 09:34:38 2001
+++ src/main.c  Fri Mar  2 07:19:51 2001

@@ -9,4 +9,7 @@
 
 #include <stdio.h>
+#ifdef HAVE_STRING_H

+#include <string.h>

+#endif

 #include <setjmp.h>
 #include <signal.h>
@@ -501,5 +504,11 @@
 
             pw = getpwuid(getuid());
-           asprintf(&s, "%s/.spiceinit", pw->pw_dir);
+               #define INITSTR "/.spiceinit"

+               if ( (s=(char *) malloc(1 + 
+strlen(pw->pw_dir)+strlen(INITSTR))) == NULL){

+                       fprintf(stderr,"malloc failed\n");

+                       exit(1);

+               }

+           /*asprintf(&s, "%s/.spiceinit", pw->pw_dir);*/

+               sprintf(s,"%s%s",pw->pw_dir,INITSTR);

             if (access(s, 0) == 0)
                 inp_source(s);
--- src/misc/ivars.c.orig       Wed Feb  7 09:34:39 2001
+++ src/misc/ivars.c    Fri Mar  2 08:23:52 2001

@@ -5,4 +5,7 @@
 #include "ngspice.h"
 #include "ivars.h"
+#ifdef HAVE_STRING_H

+#include <string.h>

+#endif

 #include <stdio.h>
 
@@ -29,8 +32,21 @@
     /* Override by environment variables */
     buffer = getenv(env_var);
-    if (buffer)
-       asprintf(p, "%s", buffer);
-    else
-       asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir);
+    if (buffer){

+       if ( (*p = (char *) malloc(strlen(buffer)+1)) == NULL){

+               fprintf(stderr,"malloc failed\n");

+               exit(1);

+       }

+       sprintf(*p,"%s",buffer);

+       /* asprintf(p, "%s", buffer); */

+    }

+    else{

+       if ( (*p = (char *) malloc(strlen(path_prefix) + 

+                       strlen(DIR_PATHSEP) + strlen(var_dir) + 1)) == NULL){

+               fprintf(stderr,"malloc failed\n");

+               exit(1);

+       }

+       sprintf(*p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); 

+       /* asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); */

+    }

 }
 
--- src/spicelib/parser/ifnewuid.c.orig Wed Feb  7 09:34:41 2001
+++ src/spicelib/parser/ifnewuid.c      Fri Mar  2 08:31:10 2001

@@ -6,5 +6,7 @@
 #include "ngspice.h"
 #include <stdio.h>
-
+#ifdef HAVE_STRING_H

+#include <string.h>

+#endif

 #include <wordlist.h>
 #include <bool.h>
@@ -27,7 +29,19 @@
 
     if (olduid) {
-       asprintf(&newname, "%s#%s", (char *) olduid, suffix);
+      if ( (newname = (char *) malloc(strlen((char *) olduid) +

+                                     strlen(suffix) + strlen("#\0"))) 

+          == NULL){

+       fprintf(stderr,"malloc failed\n");

+       exit(1);

+      }

+      sprintf(newname, "%s#%s", (char *) olduid, suffix);

+      /*asprintf(&newname, "%s#%s", (char *) olduid, suffix);*/

     } else {
-       asprintf(&newname, "%s", suffix);
+      if ( (newname = (char *) malloc(strlen(suffix) + 1 )) == NULL){

+       fprintf(stderr,"malloc failed\n");

+       exit(1);

+      }

+      sprintf(newname, "%s", suffix);

+      /* asprintf(&newname, "%s", suffix); */

     }
 
--- src/spicelib/parser/inperror.c.orig Wed Feb  7 09:34:41 2001
+++ src/spicelib/parser/inperror.c      Fri Mar  2 08:38:07 2001

@@ -10,4 +10,7 @@
 #include "ngspice.h"
 #include <stdio.h>
+#ifdef HAVE_STRING_H

+#include <string.h>

+#endif

 #include "fteext.h"
 #include "ifsim.h"
@@ -26,8 +29,21 @@
        return (val);
 
-    if (errRtn)
-       asprintf(&ebuf, "%s detected in routine \"%s\"\n", val, errRtn);
-    else
-       asprintf(&ebuf, "%s\n", val);
+    if (errRtn){

+      if ( (ebuf = (char *) malloc(strlen(val) +

+                                  strlen(errRtn) + 25)) == NULL){

+        fprintf(stderr,"malloc failed\n");

+        exit(1);

+      }

+      sprintf(ebuf, "%s detected in routine \"%s\"\n", val, errRtn);

+      /* asprintf(&ebuf, "%s detected in routine \"%s\"\n", val, errRtn); */

+    }

+    else{

+      if ( (ebuf = (char *) malloc(strlen(val) + 2)) == NULL){

+        fprintf(stderr,"malloc failed\n");

+        exit(1);

+      }

+      sprintf(ebuf, "%s\n", val);

+      /*asprintf(&ebuf, "%s\n", val);*/

+    }

 
     return ebuf;

Partial thread listing: