forked from wmcbrine/tivodecode-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli_common.cxx
82 lines (68 loc) · 1.68 KB
/
cli_common.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "tdconfig.h"
#include <cctype>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "cli_common.hxx"
#ifdef WIN32
# define HOME_ENV_NAME "USERPROFILE"
# define DEFAULT_EMPTY_HOME "C:"
#else
# define HOME_ENV_NAME "HOME"
# define DEFAULT_EMPTY_HOME ""
#endif
static const char MAK_DOTFILE_NAME[] = "/.tivodecode_mak";
int get_mak_from_conf_file(char *mak)
{
FILE *mak_file = NULL;
const char *home_dir = std::getenv(HOME_ENV_NAME);
if (!home_dir)
home_dir = DEFAULT_EMPTY_HOME;
std::string mak_fname = home_dir;
mak_fname += MAK_DOTFILE_NAME;
if ((mak_file = std::fopen(mak_fname.c_str(), "r")))
{
if (std::fread(mak, 1, 11, mak_file) >= 10)
{
int i;
for (i = 11; i >= 10 && (mak[i] == '\0' || std::isspace(mak[i]));
--i)
{
mak[i] = '\0';
}
}
else if (std::ferror(mak_file))
{
std::perror("reading mak config file");
goto fail;
}
else
{
std::cerr << "mak too short in mak config file\n";
goto fail;
}
std::fclose(mak_file);
}
else
goto fail;
return 1;
fail:
if (mak_file)
std::fclose(mak_file);
return 0;
}
void print_qualcomm_msg()
{
std::cerr << "Encryption by QUALCOMM ;)\n\n";
}
void do_version(int exitval)
{
std::cerr << PACKAGE_STRING "\n"
"Copyright 2006-2015, Jeremy Drake et al.\n"
"See COPYING file in distribution for details\n\n";
print_qualcomm_msg();
std::exit(exitval);
}
/* vi:set ai ts=4 sw=4 expandtab: */