plptools
Loading...
Searching...
No Matches
sismain.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of plptools.
3
*
4
* Copyright (C) 2002 Daniel Brahneborg <basic@chello.se>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* along with this program; if not, see <https://www.gnu.org/licenses/>.
18
*
19
*/
20
21
#include "config.h"
22
23
#include "
sisfile.h
"
24
#include "
sisinstaller.h
"
25
#include "
psion.h
"
26
#include "
fakepsion.h
"
27
28
#include <errno.h>
29
#include <fcntl.h>
30
#include <unistd.h>
31
#include <stdint.h>
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <string.h>
35
#include <sys/types.h>
36
#include <sys/stat.h>
37
38
#ifndef _GNU_SOURCE
39
#define _GNU_SOURCE
40
#endif
41
#include <getopt.h>
42
43
static
void
error
(
int
line)
44
{
45
fprintf(stderr,
_
(
"Error %d on line %d: %s\n"
), errno, line,
46
strerror(errno));
47
exit(1);
48
}
49
50
static
struct
option
opts
[] = {
51
{
"help"
, no_argument, 0,
'h'
},
52
{
"version"
, no_argument, 0,
'V'
},
53
{
"verbose"
, required_argument, 0,
'v'
},
54
{
"dry-run"
, no_argument, 0,
'n'
},
55
{ NULL, 0, 0, 0 },
56
};
57
58
void
printHelp
()
59
{
60
printf(
"%s"
,
61
_
(
"Usage: sisinstall [OPTIONS]... SISFILE\n"
62
"\n"
63
"Supported options:\n"
64
"\n"
65
" -h, --help Display this text.\n"
66
" -V, --version Print version and exit.\n"
67
" -v, --verbose=LEVEL Set the verbosity level, by default 0.\n"
68
" -n, --dry-run Just parse the file.\n"
69
));
70
}
71
72
int
main
(
int
argc,
char
* argv[])
73
{
74
char
* filename = 0;
75
char
option;
76
bool
dryrun =
false
;
77
78
#ifdef LC_ALL
79
setlocale(LC_ALL,
""
);
80
#endif
81
textdomain
(PACKAGE);
82
83
while
(1)
84
{
85
option = getopt_long(argc, argv,
86
"hnv:V"
87
,
opts
, NULL);
88
if
(option == -1)
89
break
;
90
switch
(option)
91
{
92
case
'h'
:
93
case
'?'
:
94
printHelp
();
95
exit(0);
96
case
'v'
:
97
logLevel
= atoi(optarg);
98
break
;
99
case
'n'
:
100
dryrun =
true
;
101
break
;
102
case
'V'
:
103
printf(
"%s %s\n"
,
_
(
"sisinstall Version"
), VERSION);
104
exit(0);
105
}
106
}
107
if
(optind < argc)
108
{
109
filename = argv[optind];
110
printf(
_
(
"Installing sis file %s%s.\n"
), filename,
111
dryrun ?
_
(
", not really"
) :
""
);
112
}
113
else
114
{
115
fprintf(stderr,
"%s"
,
_
(
"Missing SIS filename\n"
));
116
exit(1);
117
}
118
struct
stat st;
119
if
(-1 == stat(filename, &st))
120
error
(__LINE__);
121
off_t len = st.st_size;
122
if
(
logLevel
>= 2)
123
printf(
_
(
"File is %jd bytes long\n"
), (intmax_t)len);
124
uint8_t* buf =
new
uint8_t[len];
125
int
fd = open(filename, O_RDONLY);
126
if
(-1 == fd)
127
error
(__LINE__);
128
if
(-1 == read(fd, buf, len))
129
error
(__LINE__);
130
close(fd);
131
Psion
* psion;
132
if
(dryrun)
133
psion =
new
FakePsion
();
134
else
135
psion =
new
Psion
();
136
if
(!psion->
connect
())
137
{
138
printf(
"%s"
,
_
(
"Couldn't connect with the Psion\n"
));
139
}
140
else
141
{
142
createCRCTable
();
143
SISFile
sisFile;
144
SisRC
rc = sisFile.
fillFrom
(buf, len);
145
if
(rc ==
SIS_OK
)
146
{
147
SISInstaller
installer;
148
installer.
setPsion
(psion);
149
installer.
run
(&sisFile, buf, len);
150
}
151
else
152
printf(
"%s"
,
_
(
"Could not parse the sis file.\n"
));
153
psion->
disconnect
();
154
}
155
156
return
0;
157
}
FakePsion
A dummy version of the Psion proxy, mainly for testing the installer.
Definition:
fakepsion.h:29
Psion
Semi smart proxy for communicating with a Psion.
Definition:
psion.h:36
Psion::disconnect
virtual void disconnect()
Definition:
psion.cpp:132
Psion::connect
virtual bool connect()
Definition:
psion.cpp:45
SISFile
The top level container of a SIS file.
Definition:
sisfile.h:36
SISFile::fillFrom
SisRC fillFrom(uint8_t *buf, off_t len)
Populate the fields.
Definition:
sisfile.cpp:48
SISInstaller
A minimal SIS installer.
Definition:
sisinstaller.h:38
SISInstaller::setPsion
void setPsion(Psion *psion)
Set the Psion manager.
Definition:
sisinstaller.cpp:627
SISInstaller::run
SisRC run(SISFile *file, uint8_t *buf, off_t len)
Definition:
sisinstaller.cpp:361
fakepsion.h
_
#define _(String)
Definition:
plpintl.h:35
textdomain
#define textdomain(Domain)
Definition:
plpintl.h:37
psion.h
sisfile.h
sisinstaller.h
printHelp
void printHelp()
Definition:
sismain.cpp:58
main
int main(int argc, char *argv[])
Definition:
sismain.cpp:72
error
static void error(int line)
Definition:
sismain.cpp:43
opts
static struct option opts[]
Definition:
sismain.cpp:50
createCRCTable
void createCRCTable()
Definition:
sistypes.cpp:27
logLevel
int logLevel
Definition:
sistypes.cpp:25
SisRC
SisRC
Return Codes.
Definition:
sistypes.h:29
SIS_OK
@ SIS_OK
Definition:
sistypes.h:30
sisinstall
sismain.cpp
Generated by
1.9.5