]> git.saurik.com Git - apt.git/blame - apt-private/private-main.cc
imbue datetime parsing with C.UTF-8 locale
[apt.git] / apt-private / private-main.cc
CommitLineData
453b82a3 1#include <config.h>
b9179170 2
453b82a3 3#include <apt-pkg/cmndline.h>
b9179170 4#include <apt-pkg/configuration.h>
e7e10e47 5#include <apt-pkg/fileutl.h>
ae2a6be8 6#include <apt-pkg/strutl.h>
453b82a3
DK
7
8#include <apt-private/private-main.h>
9
10#include <iostream>
8b79c94a
DK
11#include <locale>
12
453b82a3
DK
13#include <string.h>
14#include <unistd.h>
3163087b 15#include <signal.h>
b9179170
MV
16
17#include <apti18n.h>
18
3163087b 19
570ec96d 20void InitLocale(APT_CMD const binary) /*{{{*/
e7e10e47 21{
62600666
DK
22 try {
23 std::locale::global(std::locale(""));
24 } catch (...) {
25 setlocale(LC_ALL, "");
26 }
570ec96d
DK
27 switch(binary)
28 {
29 case APT_CMD::APT:
30 case APT_CMD::APT_CACHE:
31 case APT_CMD::APT_CDROM:
32 case APT_CMD::APT_CONFIG:
ab07af70 33 case APT_CMD::APT_DUMP_SOLVER:
570ec96d
DK
34 case APT_CMD::APT_HELPER:
35 case APT_CMD::APT_GET:
36 case APT_CMD::APT_MARK:
37 textdomain("apt");
38 break;
39 case APT_CMD::APT_EXTRACTTEMPLATES:
40 case APT_CMD::APT_FTPARCHIVE:
41 case APT_CMD::APT_INTERNAL_SOLVER:
42 case APT_CMD::APT_SORTPKG:
43 textdomain("apt-utils");
44 break;
45 }
e7e10e47 46}
570ec96d 47void InitLocale() {}
e7e10e47
DK
48 /*}}}*/
49void InitSignals() /*{{{*/
3163087b 50{
3163087b
MV
51 signal(SIGPIPE,SIG_IGN);
52}
e7e10e47
DK
53 /*}}}*/
54void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
b9179170 55{
0d5b9da9
DK
56 // disable locking in simulation, but show the message only for users
57 // as root hasn't the same problems like unreadable files which can heavily
58 // distort the simulation.
59 if (_config->FindB("APT::Get::Simulate") == true &&
b9179170
MV
60 (CmdL.FileSize() == 0 ||
61 (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 &&
62 strcmp(CmdL.FileList[0], "changelog") != 0)))
63 {
0d5b9da9 64 if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
ae2a6be8
DK
65 // TRANSLATORS: placeholder is a binary name like apt or apt-get
66 ioprintf(std::cout, _("NOTE: This is only a simulation!\n"
67 " %s needs root privileges for real execution.\n"
b9179170 68 " Keep also in mind that locking is deactivated,\n"
ae2a6be8
DK
69 " so don't depend on the relevance to the real current situation!\n"),
70 _config->Find("Binary").c_str());
b9179170
MV
71 _config->Set("Debug::NoLocking",true);
72 }
73}
e7e10e47
DK
74 /*}}}*/
75void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/
76{
77 if (unlikely(argc < 1)) return;
78
79 if(!isatty(STDOUT_FILENO) &&
80 _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
81 {
82 std::cerr << std::endl
83 << "WARNING: " << flNotDir(argv[0]) << " "
84 << "does not have a stable CLI interface. "
85 << "Use with caution in scripts."
86 << std::endl
87 << std::endl;
88 }
89}
90 /*}}}*/