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