ngspice/src/frontend/quote.c

97 lines
1.7 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
/*
*
* Various things for quoting words. If this is not ascii, quote and
* strip are no-ops, so '' and \ quoting won't work. To fix this, sell
* your IBM machine and buy a vax.
*/
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
2000-04-27 22:03:57 +02:00
#include "quote.h"
/* Strip all the 8th bits from a string (destructively). */
void
cp_wstrip(char *str)
{
char c, d;
2000-04-27 22:03:57 +02:00
if (str)
while ((c = *str) != '\0') { /* assign and test */
d = (char) strip(c);
if (c != d)
*str = d;
str++;
}
2000-04-27 22:03:57 +02:00
}
2000-04-27 22:03:57 +02:00
/* Quote all characters in a word. */
void
cp_quoteword(char *str)
{
if (str)
while (*str) {
*str = (char) quote(*str);
str++;
}
2000-04-27 22:03:57 +02:00
}
2000-04-27 22:03:57 +02:00
/* Print a word (strip the word first). */
void
cp_printword(char *string, FILE *fp)
{
char *s;
if (string)
for (s = string; *s; s++)
(void) putc((strip(*s)), fp);
}
2000-04-27 22:03:57 +02:00
/* (Destructively) strip all the words in a wlist. */
void
cp_striplist(wordlist *wlist)
{
wordlist *wl;
for (wl = wlist; wl; wl = wl->wl_next)
cp_wstrip(wl->wl_word);
}
2000-04-27 22:03:57 +02:00
/* Remove the "" from a string. */
char *
cp_unquote(char *string)
{
char *s;
size_t l;
2000-04-27 22:03:57 +02:00
if (string) {
l = strlen(string);
s = TMALLOC(char, l + 1);
if (l >= 2 && *string == '"' && string[l-1] == '"') {
strncpy(s, string+1, l-2);
s[l-2] = '\0';
} else {
strcpy(s, string);
}
return (s);
} else {
return 0;
}
2000-04-27 22:03:57 +02:00
}