]>
Commit | Line | Data |
---|---|---|
7939f6d1 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
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 Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
fa0c0d10 RC |
16 | /* this is the parent class for all package source (not source code - installation |
17 | * source as in http/ftp/disk file) operations. | |
7939f6d1 RC |
18 | */ |
19 | ||
20 | #if 0 | |
21 | static const char *cvsid = | |
22 | "\n%%% $Id$\n"; | |
23 | #endif | |
bb849dbd RC |
24 | |
25 | #include <stdlib.h> | |
26 | #include <strings.h> | |
27 | #include "package_source.h" | |
28 | ||
a900d1fa RC |
29 | site::site (char const *newkey) |
30 | { | |
31 | key = new char[strlen (newkey) + 1]; | |
32 | strcpy (key, newkey); | |
33 | }; | |
34 | ||
bb849dbd RC |
35 | void |
36 | packagesource::set_canonical (char const *fn) | |
37 | { | |
38 | if (canonical) | |
341988b9 | 39 | delete[] canonical; |
bb849dbd RC |
40 | canonical = new char[strlen (fn) + 1]; |
41 | strcpy (canonical, fn); | |
42 | ||
43 | /* The base is from the last '/' to the first '.' following the last - */ | |
44 | char const *bstart = strchr (fn, '/'); | |
45 | char const *tmp; | |
46 | while (bstart && (tmp = strchr (bstart + 1, '/'))) | |
47 | bstart = tmp; | |
48 | ||
49 | if (!bstart) | |
50 | bstart = fn; | |
51 | char const *bend = strchr (bstart, '-'); | |
52 | while (bend && (tmp = strchr (bend + 1, '-'))) | |
53 | bend = tmp; | |
54 | if (bend) | |
55 | bend = strchr (bend, '.'); | |
56 | else | |
57 | bend = strchr (bstart, '.'); | |
58 | ||
59 | if (!bend) | |
60 | bend = strchr (bstart, '\0'); | |
61 | char const *end = strchr (fn, '\0'); | |
62 | if (base) | |
341988b9 | 63 | delete[] base; |
bb849dbd RC |
64 | base = new char[bend - bstart]; |
65 | memcpy (base, bstart + 1, bend - bstart - 1); | |
66 | base[bend - bstart - 1] = '\0'; | |
67 | ||
68 | if (filename) | |
341988b9 | 69 | delete[] filename; |
071c1c54 RC |
70 | filename = new char[end - bstart]; |
71 | memcpy (filename, bstart + 1, end - bstart - 1); | |
72 | filename[end - bstart - 1] = '\0'; | |
bb849dbd RC |
73 | |
74 | if (cached) | |
341988b9 | 75 | delete[] cached; |
bb849dbd RC |
76 | cached = 0; |
77 | } | |
78 | ||
79 | void | |
80 | packagesource::set_cached (char const *fp) | |
81 | { | |
82 | if (cached) | |
341988b9 | 83 | delete[] cached; |
bb849dbd RC |
84 | cached = new char[strlen (fp) + 1]; |
85 | strcpy (cached, fp); | |
86 | } |