]> cygwin.com Git - cygwin-apps/setup.git/blob - cygpackage.cc
2002-04-29 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / cygpackage.cc
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
16 /* this is the parent class for all package operations.
17 */
18
19 #if 0
20 static const char *cvsid =
21 "\n%%% $Id$\n";
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include "String++.h"
28
29 #include "io_stream.h"
30 #include "compress.h"
31
32 #include "package_version.h"
33 #include "cygpackage.h"
34
35 /* this constructor creates an invalid package - further details MUST be provided */
36 cygpackage::cygpackage (String const &pkgname):
37 name (pkgname),
38 vendor (0),
39 packagev (0),
40 canonical (0),
41 fn (0),
42 sdesc (0),
43 ldesc (0),
44 status (package_installed),
45 type (package_binary),
46 listdata (0),
47 listfile (0)
48 {
49 memset( getfilenamebuffer, '\0', _MAX_PATH);
50
51 /* FIXME: query the install database for the currently installed
52 * version details
53 */
54 }
55
56 /* create a package given explicit details - perhaps should be modified to take the
57 filename and do it's own parsing? */
58 cygpackage::cygpackage (String const &pkgname, String const &filename, size_t const fs,
59 String const &version, package_status_t const newstatus,
60 package_type_t const newtype):
61 name (pkgname),
62 fn (filename),
63 sdesc (0),
64 ldesc (0),
65 status (newstatus),
66 type (newtype),
67 listdata (0),
68 listfile (0),
69 filesize (fs)
70 {
71 memset( getfilenamebuffer, '\0', _MAX_PATH);
72 set_canonical_version (version);
73 }
74
75 /* tell the version */
76 void
77 cygpackage::set_canonical_version (String const &version)
78 {
79 canonical = version;
80 char *start = strchr (canonical.cstr_oneuse(), '-');
81 char*curr=start;
82 if (curr)
83 {
84 char *next;
85 while ((next = strchr (curr + 1, '-')))
86 curr = next;
87 /* curr = last - in the version string */
88 packagev = curr + 1;
89 char tvendor [version.size() +1];
90 strcpy (tvendor, version.cstr_oneuse());
91 tvendor[curr - start] = '\0';
92 vendor=tvendor;
93 }
94 else
95 {
96 packagev = 0;
97 vendor = version;
98 }
99 key = canonical;
100 }
101
102 cygpackage::~cygpackage ()
103 {
104 destroy ();
105 }
106
107 /* helper functions */
108
109 void
110 cygpackage::destroy ()
111 {
112 }
113
114 String const
115 cygpackage::getfirstfile ()
116 {
117 if (listdata)
118 delete listdata;
119 listfile =
120 io_stream::open (String ("cygfile:///etc/setup/") + name + ".lst.gz", "rb");
121 listdata = compress::decompress (listfile);
122 if (!listdata)
123 return 0;
124 return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
125 }
126
127 String const
128 cygpackage::getnextfile ()
129 {
130 if (listdata)
131 return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
132 return 0;
133 }
134
135 void
136 cygpackage::uninstall ()
137 {
138 if (listdata)
139 delete listdata;
140 listdata = 0;
141 io_stream::remove (String("cygfile:///etc/setup/") + name + ".lst.gz");
142 }
143
144 String const
145 cygpackage::Name ()
146 {
147 return name;
148 }
149
150 String const
151 cygpackage::Vendor_version ()
152 {
153 return vendor;
154 }
155
156 String const
157 cygpackage::Package_version ()
158 {
159 return packagev;
160 }
161
162 String const
163 cygpackage::Canonical_version ()
164 {
165 return canonical;
166 }
167
168 void
169 cygpackage::set_sdesc (String const &desc)
170 {
171 sdesc = desc;
172 }
173
174 void
175 cygpackage::set_ldesc (String const &desc)
176 {
177 ldesc = desc;
178 }
179
180 #if 0
181 package_stability_t cygpackage::Stability ()
182 {
183 return stability;
184 }
185 #endif
This page took 0.044393 seconds and 5 git commands to generate.