]> git.saurik.com Git - apt.git/blame - apt-private/private-moo.cc
Add statvfs.h.in to CMake directory
[apt.git] / apt-private / private-moo.cc
CommitLineData
b9179170
MV
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Here be cows – but: Never ask, never tell
6
7 ##################################################################### */
8 /*}}}*/
9// Include Files /*{{{*/
10#include<config.h>
11
12#include <apt-pkg/configuration.h>
13#include <apt-pkg/cmndline.h>
14#include <apt-pkg/strutl.h>
15
453b82a3
DK
16#include <apt-private/private-moo.h>
17#include <apt-private/private-output.h>
b9179170 18
453b82a3
DK
19#include <stddef.h>
20#include <string.h>
21#include <time.h>
22#include <iostream>
23#include <sstream>
24#include <string>
b9179170
MV
25
26#include <apti18n.h>
27 /*}}}*/
28
c3ccac92 29static std::string getMooLine() { /*{{{*/
b9179170
MV
30 time_t const timenow = time(NULL);
31 struct tm special;
32 localtime_r(&timenow, &special);
33 enum { NORMAL, PACKAGEMANAGER, APPRECIATION, AGITATION, AIRBORN } line;
34 if (special.tm_mon == 11 && special.tm_mday == 25)
35 line = PACKAGEMANAGER;
36 else if (special.tm_mon == 7 && special.tm_mday == 16)
37 line = APPRECIATION;
38 else if (special.tm_mon == 10 && special.tm_mday == 7)
39 line = AGITATION;
40 else if (special.tm_mon == 1 && special.tm_mday == 18)
41 line = AIRBORN;
42 else
43 line = NORMAL;
44
45 bool const quiet = _config->FindI("quiet") >= 2;
46 std::ostringstream out;
47 if (quiet == false)
48 out << "...\"";
49
50 switch(line)
51 {
52 case PACKAGEMANAGER: out << "Happy package management day!"; break;
53 case APPRECIATION: out << "Three moos for Debian!"; break;
54 case AGITATION: out << "Whoever needs milk, bows to the animal."; break;
55 case AIRBORN: out << "It's a Bird ... It's a Plane ... It's Super Cow!"; break;
56 default: out << "Have you mooed today?"; break;
57 }
58
59 if (quiet == true)
60 out << std::endl;
61 else
62 out << "\"..." << std::endl;
63
64 return out.str();
65}
66 /*}}}*/
c3ccac92 67static bool printMooLine() { /*{{{*/
b9179170
MV
68 std::cerr << getMooLine() << std::endl;
69 return true;
70}
71 /*}}}*/
65512241 72bool DoMoo1(CommandLine &) /*{{{*/
b9179170
MV
73{
74 // our trustworthy super cow since 2001
75 if (_config->FindI("quiet") >= 2)
76 return printMooLine();
77 std::string const moo = getMooLine();
78 size_t const depth = moo.length()/4;
79 c1out <<
80 OutputInDepth(depth, " ") << " (__) \n" <<
81 OutputInDepth(depth, " ") << " (oo) \n" <<
82 OutputInDepth(depth, " ") << " /------\\/ \n" <<
83 OutputInDepth(depth, " ") << " / | || \n" <<
84 OutputInDepth(depth, " ") << " * /\\---/\\ \n" <<
85 OutputInDepth(depth, " ") << " ~~ ~~ \n" <<
86 moo;
87 return true;
88}
89 /*}}}*/
65512241 90bool DoMoo2(CommandLine &) /*{{{*/
b9179170
MV
91{
92 // by Fernando Ribeiro in lp:56125
93 if (_config->FindI("quiet") >= 2)
94 return printMooLine();
95 std::string const moo = getMooLine();
96 size_t const depth = moo.length()/4;
97 if (_config->FindB("APT::Moo::Color", false) == false)
98 c1out <<
99 OutputInDepth(depth, " ") << " (__) \n" <<
100 OutputInDepth(depth, " ") << " _______~(..)~ \n" <<
101 OutputInDepth(depth, " ") << " ,----\\(oo) \n" <<
102 OutputInDepth(depth, " ") << " /|____|,' \n" <<
103 OutputInDepth(depth, " ") << " * /\"\\ /\\ \n" <<
104 OutputInDepth(depth, " ") << " ~ ~ ~ ~ \n" <<
105 moo;
106 else
107 {
108 c1out <<
27511c01
DK
109 OutputInDepth(depth, " ") << " \033[1;97m(\033[0;33m__\033[1;97m)\033[0m\n" <<
110 OutputInDepth(depth, " ") << " \033[31m_______\033[33m~(\033[1;34m..\033[0;33m)~\033[0m\n" <<
111 OutputInDepth(depth, " ") << " \033[33m,----\033[31m\\\033[33m(\033[1;4;35moo\033[0;33m)\033[0m\n" <<
112 OutputInDepth(depth, " ") << " \033[33m/|____|,'\033[0m\n" <<
113 OutputInDepth(depth, " ") << " \033[1;5;97m*\033[0;33m /\\ /\\\033[0m\n" <<
114 "\033[32m";
b9179170
MV
115 for (size_t i = moo.length()/2; i > 1; --i)
116 c1out << "wW";
117
27511c01 118 c1out << "w\033[0m\n" << moo;
b9179170
MV
119 }
120
121 return true;
122}
123 /*}}}*/
65512241 124bool DoMoo3(CommandLine &) /*{{{*/
b9179170
MV
125{
126 // by Robert Millan in deb:134156
127 if (_config->FindI("quiet") >= 2)
128 return printMooLine();
129 std::string const moo = getMooLine();
130 size_t const depth = moo.length()/16;
131 c1out <<
132 OutputInDepth(depth, " ") << " \\_/ \n" <<
133 OutputInDepth(depth, " ") << " m00h (__) -(_)- \n" <<
134 OutputInDepth(depth, " ") << " \\ ~Oo~___ / \\\n" <<
135 OutputInDepth(depth, " ") << " (..) |\\ \n" <<
136 OutputInDepth(depth, "_") << "_________|_|_|__________" <<
137 OutputInDepth((moo.length() - (depth + 27)), "_") << "\n" << moo;
138 return true;
139}
140 /*}}}*/
65512241 141bool DoMooApril(CommandLine &) /*{{{*/
b9179170
MV
142{
143 // by Christopher Allan Webber and proposed by Paul Tagliamonte
144 // in a "Community outreach": https://lists.debian.org/debian-devel/2013/04/msg00045.html
145 if (_config->FindI("quiet") >= 2)
146 {
147 std::cerr << "Have you smashed some milk today?" << std::endl;
148 return true;
149 }
150 c1out <<
151 " _ _\n"
152 " (_\\___( \\,\n"
153 " )___ _ Have you smashed some milk today?\n"
154 " /( (_)-(_) /\n"
155 " ,---------' \\_\n"
156 " //( ',__,' \\ (' ')\n"
157 " // ) '----'\n"
158 " '' ; \\ .--. ,/\n"
159 " | )',_,'----( ;\n"
160 " ||| ''' '||\n";
161 return true;
162}
163 /*}}}*/
164bool DoMoo(CommandLine &CmdL) /*{{{*/
165{
166 time_t const timenow = time(NULL);
167 struct tm april;
168 localtime_r(&timenow, &april);
169 if (april.tm_mday == 1 && april.tm_mon == 3)
170 return DoMooApril(CmdL);
171
172 signed short SuperCow = 1;
173 if (CmdL.FileSize() != 0)
174 for (const char **Moo = CmdL.FileList + 1; *Moo != 0; Moo++)
175 if (strcasecmp(*Moo, "moo") == 0)
176 SuperCow++;
177
178 // time is random enough for our purpose
179 if (SuperCow > 3)
180 {
181 if (april.tm_sec == 1)
182 SuperCow = 1 + (timenow % 4);
183 else
184 SuperCow = 1 + (timenow % 3);
185 }
186
187 switch(SuperCow) {
188 case 1: return DoMoo1(CmdL);
189 case 2: return DoMoo2(CmdL);
190 case 3: return DoMoo3(CmdL);
191 case 4: return DoMooApril(CmdL);
192 default: return DoMoo1(CmdL);
193 }
194
195 return true;
196}
197 /*}}}*/