private-moo.cc 6.0 KB

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