]> cygwin.com Git - cygwin-apps/setup.git/blob - concat.cc
* net.cc (do_net): Default to direct download.
[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 static char *cvsid = "\n%%% $Id$\n";
20
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 char *
26 concat (char *s, ...)
27 {
28 int len;
29 char *rv, *arg;
30 va_list v;
31
32 if (!s)
33 return 0;
34
35 len = strlen (s);
36
37 va_start (v, s);
38 while (1)
39 {
40 arg = va_arg (v, char *);
41 if (arg == 0)
42 break;
43 len += strlen (arg);
44 }
45 va_end (v);
46
47 rv = (char *) malloc (len+1);
48 strcpy (rv, s);
49 va_start (v, s);
50 while (1)
51 {
52 arg = va_arg (v, char *);
53 if (arg == 0)
54 break;
55 strcat (rv, arg);
56 }
57 va_end (v);
58
59 /* concat is only used for urls and files, so we can safely
60 canonicalize the results */
61 char *d;
62 for (s=rv; *s; s++)
63 if (*s == '\\')
64 *s = '/';
65 for (s=d=rv; *s; s++)
66 {
67 *d++ = *s;
68 /* special case for URLs */
69 if (*s == ':' && s[1] == '/' && s[2] == '/' && s > rv+1)
70 {
71 *d++ = *++s;
72 *d++ = *++s;
73 }
74 else if (*s == '/')
75 while (s[1] == '/')
76 s++;
77 }
78 *d = 0;
79
80 return rv;
81 }
82
83 char *
84 backslash (char *s)
85 {
86 for (char *t = s; *t; t++)
87 if (*t == '/')
88 *t = '\\';
89 return s;
90 }
This page took 0.037373 seconds and 5 git commands to generate.