Browse Source
Applied Stuart's 12-03-2003 patch. Support for readline (disabled) and for node names in the form (x,y).
pre-master-46
Applied Stuart's 12-03-2003 patch. Support for readline (disabled) and for node names in the form (x,y).
pre-master-46
27 changed files with 686 additions and 366 deletions
-
16ChangeLog
-
28configure.in
-
50src/frontend/com_history.c
-
3src/frontend/cpitf.c
-
9src/frontend/display.h
-
10src/frontend/evaluate.c
-
99src/frontend/inpcom.c
-
28src/frontend/misccoms.c
-
5src/frontend/parser/glob.c
-
1src/frontend/plotting/x11.c
-
8src/frontend/resource.c
-
22src/frontend/runcoms.c
-
56src/frontend/signal_handler.c
-
112src/frontend/subckt.c
-
19src/frontend/variable.c
-
7src/include/ftedev.h
-
9src/include/ngspice.h
-
190src/main.c
-
4src/misc/Makefile.am
-
5src/misc/ivars.c
-
89src/misc/string.c
-
106src/misc/tilde.c
-
5src/misc/tilde.h
-
151src/misc/util.c
-
12src/misc/util.h
-
3src/nghelp.c
-
5src/ngmultidec.c
@ -0,0 +1,151 @@ |
|||
/************* |
|||
* Various utility functions. |
|||
* 2002 R. Oktas, <roktas@omu.edu.tr> |
|||
************/ |
|||
|
|||
#ifdef HAVE_STRING_H |
|||
#include <string.h> |
|||
#endif |
|||
|
|||
#include "ngspice.h" |
|||
#include "util.h" |
|||
|
|||
|
|||
/* **************************************************************** */ |
|||
/* */ |
|||
/* Stuff for Filename Handling */ |
|||
/* */ |
|||
/* **************************************************************** */ |
|||
|
|||
/* Canonicalize PATH, and return a new path. The new path differs from PATH |
|||
in that: |
|||
Multple `/'s are collapsed to a single `/'. |
|||
Leading `./'s and trailing `/.'s are removed. |
|||
Trailing `/'s are removed. |
|||
Non-leading `../'s and trailing `..'s are handled by removing |
|||
portions of the path. |
|||
|
|||
Stolen from Bash source (slightly modified). |
|||
Credit goes to Chet Ramey, et al. -- ro */ |
|||
|
|||
char * |
|||
canonicalize_pathname(char *path) |
|||
{ |
|||
int i, start; |
|||
char stub_char; |
|||
char *result; |
|||
|
|||
/* The result cannot be larger than the input PATH. */ |
|||
result = copy(path); |
|||
|
|||
stub_char = (*path == '/') ? '/' : '.'; |
|||
|
|||
/* Walk along RESULT looking for things to compact. */ |
|||
i = 0; |
|||
while (1) { |
|||
if (!result[i]) |
|||
break; |
|||
|
|||
while (result[i] && result[i] != '/') |
|||
i++; |
|||
|
|||
start = i++; |
|||
|
|||
/* If we didn't find any slashes, then there is nothing left to do. */ |
|||
if (!result[start]) |
|||
break; |
|||
|
|||
/* Handle multiple `/'s in a row. */ |
|||
while (result[i] == '/') |
|||
i++; |
|||
|
|||
#if !defined (apollo) |
|||
if ((start + 1) != i) |
|||
#else |
|||
if ((start + 1) != i && (start != 0 || i != 2)) |
|||
#endif /* apollo */ |
|||
{ |
|||
strcpy (result + start + 1, result + i); |
|||
i = start + 1; |
|||
} |
|||
|
|||
#if 0 |
|||
/* Handle backslash-quoted `/'. */ |
|||
if (start > 0 && result[start - 1] == '\\') |
|||
continue; |
|||
#endif |
|||
|
|||
/* Check for trailing `/'. */ |
|||
if (start && !result[i]) { |
|||
zero_last: |
|||
result[--i] = '\0'; |
|||
break; |
|||
} |
|||
|
|||
/* Check for `../', `./' or trailing `.' by itself. */ |
|||
if (result[i] == '.') { |
|||
/* Handle trailing `.' by itself. */ |
|||
if (!result[i + 1]) |
|||
goto zero_last; |
|||
|
|||
/* Handle `./'. */ |
|||
if (result[i + 1] == '/') { |
|||
strcpy(result + i, result + i + 1); |
|||
i = (start < 0) ? 0 : start; |
|||
continue; |
|||
} |
|||
|
|||
/* Handle `../' or trailing `..' by itself. */ |
|||
if (result[i + 1] == '.' && |
|||
(result[i + 2] == '/' || !result[i + 2])) { |
|||
while (--start > -1 && result[start] != '/'); |
|||
strcpy(result + start + 1, result + i + 2); |
|||
i = (start < 0) ? 0 : start; |
|||
continue; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (!*result) { |
|||
*result = stub_char; |
|||
result[1] = '\0'; |
|||
} |
|||
return (result); |
|||
} |
|||
|
|||
|
|||
/* Turn STRING (a pathname) into an absolute pathname, assuming that |
|||
DOT_PATH contains the symbolic location of `.'. This always |
|||
returns a new string, even if STRING was an absolute pathname to |
|||
begin with. |
|||
|
|||
Stolen from Bash source (slightly modified). |
|||
Credit goes to Chet Ramey, et al. -- ro */ |
|||
|
|||
char * absolute_pathname(char *string, char *dot_path) |
|||
{ |
|||
char *result; |
|||
int result_len; |
|||
|
|||
if (!dot_path || *string == '/') |
|||
result = copy(string); |
|||
else { |
|||
if (dot_path && dot_path[0]) { |
|||
result = tmalloc(2 + strlen(dot_path) + strlen(string)); |
|||
strcpy(result, dot_path); |
|||
result_len = strlen(result); |
|||
if (result[result_len - 1] != '/') { |
|||
result[result_len++] = '/'; |
|||
result[result_len] = '\0'; |
|||
} |
|||
} else { |
|||
result = tmalloc(3 + strlen (string)); |
|||
result[0] = '.'; result[1] = '/'; result[2] = '\0'; |
|||
result_len = 2; |
|||
} |
|||
|
|||
strcpy(result + result_len, string); |
|||
} |
|||
|
|||
return (result); |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
/************* |
|||
* Header file for util.c |
|||
* 2002 R. Oktas, <roktas@omu.edu.tr> |
|||
************/ |
|||
|
|||
#ifndef UTIL_H_INCLUDED |
|||
#define UTIL_H_INCLUDED |
|||
|
|||
char *canonicalize_pathname(char *path); |
|||
char *absolute_pathname(char *string, char *dot_path); |
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue