private-moo.cc 5.9 KB

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