/********** Copyright 1991 Regents of the University of California. All rights reserved. **********/ #include #include #ifdef HAVE_STRING_H #include #endif #include "ngspice.h" #include "tilde.h" #ifdef HAVE_PWD_H #include #endif char * tilde_expand(char *string) { #ifdef HAVE_PWD_H struct passwd *pw; /*extern struct passwd *getpwuid( );*/ char buf[BSIZE_SP]; char *k, c; if (!string) return NULL; while (*string && isspace(*string)) string++; if (*string != '~') return copy(string); string += 1; if (!*string || *string == '/') { pw = getpwuid(getuid()); *buf = 0; } else { k = buf; while ((c = *string) && c != '/') *k++ = c, string++; *k = 0; pw = getpwnam(buf); } if (pw) { strcpy(buf, pw->pw_dir); if (*string) strcat(buf, string); } else return NULL; return copy(buf); #else return copy(string); #endif }