ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/cvtcmd.c
Revision: 3.2
Committed: Tue Feb 2 18:05:31 2016 UTC (8 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad5R1
Changes since 3.1: +3 -0 lines
Log Message:
Forgot RCS header

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * Convert a set of arguments into a command line for pipe() or system()
6 *
7 * Defines in paths.h
8 */
9
10 #include "paths.h"
11
12 /* Check if any of the characters in str2 are found in str1 */
13 int
14 matchany(const char *str1, const char *str2)
15 {
16 while (*str1) {
17 const char *cp = str2;
18 while (*cp)
19 if (*cp++ == *str1)
20 return(*str1);
21 ++str1;
22 }
23 return(0);
24 }
25
26 /* Convert a set of arguments into a command line, being careful of specials */
27 char *
28 convert_commandline(char *cmd, const int len, char *av[])
29 {
30 int match;
31 char *cp;
32
33 for (cp = cmd; *av != NULL; av++) {
34 const int n = strlen(*av);
35 if (cp+n >= cmd+(len-3))
36 return(NULL);
37 if (matchany(*av, SPECIALS)) {
38 const int quote =
39 #ifdef ALTQUOT
40 strchr(*av, QUOTCHAR) ? ALTQUOT :
41 #endif
42 QUOTCHAR;
43 *cp++ = quote;
44 strcpy(cp, *av);
45 cp += n;
46 *cp++ = quote;
47 } else {
48 strcpy(cp, *av);
49 cp += n;
50 }
51 *cp++ = ' ';
52 }
53 if (cp <= cmd)
54 return(NULL);
55 *--cp = '\0';
56 return(cmd);
57 }