]> cygwin.com Git - cygwin-apps/setup.git/blob - concat.cc
* coding standards fixups, many files
[cygwin-apps/setup.git] / concat.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* See concat.h. Note that we canonicalize the result, this avoids
17 multiple slashes being interpreted as UNCs. */
18
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 char *
24 concat (char *s, ...)
25 {
26 int len;
27 char *rv, *arg;
28 va_list v;
29
30 if (!s)
31 return 0;
32
33 len = strlen (s);
34
35 va_start (v, s);
36 while (1)
37 {
38 arg = va_arg (v, char *);
39 if (arg == 0)
40 break;
41 len += strlen (arg);
42 }
43 va_end (v);
44
45 rv = (char *) malloc (len+1);
46 strcpy (rv, s);
47 va_start (v, s);
48 while (1)
49 {
50 arg = va_arg (v, char *);
51 if (arg == 0)
52 break;
53 strcat (rv, arg);
54 }
55 va_end (v);
56
57 /* concat is only used for urls and files, so we can safely
58 canonicalize the results */
59 char *d;
60 for (s=rv; *s; s++)
61 if (*s == '\\')
62 *s = '/';
63 for (s=d=rv; *s; s++)
64 {
65 *d++ = *s;
66 /* special case for URLs */
67 if (*s == ':' && s[1] == '/' &&s[2] == '/')
68 {
69 *d++ = *++s;
70 *d++ = *++s;
71 }
72 else if (*s == '/')
73 while (s[1] == '/')
74 s++;
75 }
76 *d = 0;
77
78 return rv;
79 }
80
81 char *
82 backslash (char *s)
83 {
84 for (char *t = s; *t; t++)
85 if (*t == '/')
86 *t = '\\';
87 return s;
88 }
This page took 0.036697 seconds and 5 git commands to generate.