vimja

Untitled

Jul 10th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. // Copyright (c) 2012 by Bash Vi
  2. // This code is released under the terms
  3. // of the WTFPL (What the Fuck Pulic License) version 2.0
  4. // http://sam.zoy.org/wtfpl/
  5. //   ___
  6. // 3| 2 |4
  7. //  |___|
  8. // 5| 1 |6
  9. //  |___|
  10. //    0
  11. #include <iostream>
  12. #include <boost/program_options.hpp>
  13. #include <sstream>
  14. #include <cstring>
  15. #include <bitset>
  16. #include <map>
  17.  
  18. using namespace std;
  19. namespace po = boost::program_options;
  20.  
  21. map<char, char> mymap;
  22.  
  23. string convert(int number)
  24. {
  25.   stringstream stream;
  26.   stream << number;
  27.   return stream.str();
  28. }
  29.  
  30. // function copied (and then modified) from here:
  31. // http://icfun.blogspot.ch/2009/04/get-n-th-bit-value-of-any-integer.html
  32. // all rights stay with the original author.
  33. // This function's copyright might differ from the rest of the program!
  34. bool bit_set(char chr, int i)
  35. {
  36.   int con = 1 << (i-1);
  37.   return chr & con;
  38. }
  39.  
  40. void draw(char c, int i)
  41. {
  42.   // 0,1,2 ==> _
  43.   // 2,4,5,6 ==> |
  44.   if(bit_set(mymap.find(c)->second, i+1))
  45.   {
  46.     if(i>2)
  47.     {
  48.       cout << "|";
  49.     }
  50.     else
  51.     {
  52.       cout << "_";
  53.     }
  54.   }
  55.   else
  56.   {
  57.     cout << " ";
  58.   }
  59. }
  60.  
  61. int main(int ac, char* av[])
  62. {
  63.   int number = 0;
  64.  
  65.   po::options_description generic("Generic options");
  66.   generic.add_options()
  67.     ("version,v", "Print version string")
  68.     ("help,h", "Show this help message");
  69.  
  70.   po::options_description hidden("Hidden options");
  71.   hidden.add_options()
  72.     ("number", po::value<int>(&number), "Number to print");
  73.  
  74.   po::options_description cmdline_options;
  75.   cmdline_options.add(generic).add(hidden);
  76.  
  77.   po::options_description visible("Allowed options");
  78.   visible.add(generic);
  79.  
  80.   po::positional_options_description p;
  81.   p.add("number", -1);
  82.  
  83.   po::variables_map vm;
  84.   store(po::command_line_parser(ac, av).options(cmdline_options).positional(p).run(), vm);
  85.   notify(vm);
  86.  
  87.   if(vm.count("help"))
  88.   {
  89.     cout << visible << "\n";
  90.     return 0;
  91.   }
  92.   if(vm.count("version"))
  93.   {
  94.     cout << "This is version 0.5" << "\n";
  95.     return 0;
  96.   }
  97.  
  98.   string str = convert(number);
  99.   char cstr[str.size()+1];
  100.   strcpy( cstr, str.c_str());
  101.  
  102.   mymap.insert( pair <char, char> ('1', 'P'));
  103.   mymap.insert( pair <char, char> ('2', '7'));
  104.   mymap.insert( pair <char, char> ('3', 'W'));
  105.   mymap.insert( pair <char, char> ('4', 'Z'));
  106.   mymap.insert( pair <char, char> ('5', 'O'));
  107.   mymap.insert( pair <char, char> ('6', 'o'));
  108.   mymap.insert( pair <char, char> ('7', 'T'));
  109.   // unable to write 01111111 char...
  110.   char c1 = '?';
  111.   char c2 = '@';
  112.   mymap.insert( pair <char, char> ('8', c1 | c2)); // not yet solved
  113.   mymap.insert( pair <char, char> ('9', '_'));
  114.   mymap.insert( pair <char, char> ('0', '}'));
  115.  
  116.   for(int i=0; i< strlen(cstr); i++)
  117.   {
  118.     cout << " ";
  119.     draw(cstr[i], 2);
  120.     cout << " ";
  121.   }
  122.   cout << endl;
  123.  
  124.   for(int i=0; i< strlen(cstr); i++)
  125.   {
  126.     draw(cstr[i], 3);
  127.     draw(cstr[i], 1);
  128.     draw(cstr[i], 4);
  129.   }
  130.   cout << endl;
  131.  
  132.   for(int i=0; i< strlen(cstr); i++)
  133.   {
  134.     draw(cstr[i], 5);
  135.     draw(cstr[i], 0);
  136.     draw(cstr[i], 6);
  137.   }
  138.   cout << endl;
  139.  
  140.   return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment