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