|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 3314 (0xcf2) Types: TextFile Names: »arg2str.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Lib/util/arg2str.c«
/* arg2str: list of arguments to string */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/util/RCS/arg2str.c,v 5.0 90/09/20 16:17:00 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Lib/util/RCS/arg2str.c,v 5.0 90/09/20 16:17:00 pp Exp Locker: pp $ * * $Log: arg2str.c,v $ * Revision 5.0 90/09/20 16:17:00 pp * rcsforce : 5.0 public release * */ #include "util.h" #include "retcode.h" extern void err_abrt (); /* convert an array of strings to one or more lines of 'arguments'. * * this is intended to be used along with the str2arg() routine. */ void arg2vstr (linelen, maxlen, buf, argv) /* convert the list to a string */ int linelen; int maxlen; /* length of string */ char *buf; /* where to put the output string */ char **argv; /* the argument vector */ { unsigned totlen, /* total length of current line */ len; /* length of current argument */ unsigned gotdelim; /* a delimiter char is in arg */ unsigned gotpair; /* key/value pair */ char tmpstr[BUFSIZ]; /* string under construction */ register char *src, *dest = NULLCP; for (totlen = gotpair = 0, buf[0] = '\0'; *argv != (char *) 0; argv++) { if (gotpair == 0 && strcmp ("=", *argv) == 0) { dest = tmpstr; gotpair = 2; /* take the next two arguments */ continue; } if(**argv == '\0'){ gotdelim = TRUE; goto nextone; } for (src = *argv, gotdelim = FALSE; *src != '\0'; src++) switch (*src) { case ' ': case '\t': case '=': case ',': case ';': case ':': case '/': case '|': case '.': gotdelim = TRUE; goto nextone; } nextone: if (gotpair == 0) dest = tmpstr; if (gotdelim) *dest++ = '"'; for (src = *argv; *src != '\0'; src++) { switch (*src) { case '\b': *dest++ = '\\'; *dest++ = 'b'; break; case '\t': *dest++ = '\\'; *dest++ = 't'; break; case '\f': *dest++ = '\\'; *dest++ = 'f'; break; case '\r': *dest++ = '\\'; *dest++ = 'r'; break; case '\n': *dest++ = '\\'; *dest++ = 'n'; break; case '\\': /* Added by Doug Kingston */ case '\"': *dest++ = '\\'; *dest++ = *src; break; default: if (iscntrl (*src)) { *dest++ = '\\'; *dest++ = ((*src >> 6) & 07) + '0'; *dest++ = ((*src >> 3) & 07) + '0'; *dest++ = (*src & 07) + '0'; } else *dest++ = *src; } } if (gotdelim) *dest++ = '"'; switch (gotpair) /* handle key/value differently */ { case 2: *dest++ = '='; gotpair--; continue; case 1: gotpair = 0; } *dest = '\0'; len = dest - tmpstr; if (totlen != 0) { if ((linelen > 0) && ((totlen + len) > linelen)) { (void) strcat (buf, "\n\t"); maxlen -= 2; totlen = 8; } else { (void) strcat (buf, " "); maxlen --; totlen += 1; } } if (maxlen < len) err_abrt (RP_MECH, "String too long in arg2vstr"); maxlen -= len; (void) strcat (buf, tmpstr); totlen += len; } }