1. C++ / Говнокод #6530

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    void tolowerStr(char *Str)
    {
         #include <windows.h>
         #include <ctype.h>
    
         SetConsoleCP(1251);
         SetConsoleOutputCP(1251);
         setlocale(LC_CTYPE,"Russian");
         
         int len = strlen(Str);
         for(int c=0; c<len; c++)
           Str[c] = tolower(Str[c]);
    }

    инклайд в теле ф-и :D

    Antichat, 02 Мая 2011

    Комментарии (9)
  2. C++ / Говнокод #6523

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    #define цой_жив(...) , ## __VA_ARGS__
    
    #define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _, ...) _
    #define REPEAT_PARAMS(...) (__VA_ARGS__)
    #define COUNT_PARMS(...) \
       COUNT_PARMS2 REPEAT_PARAMS(цой_жив(__VA_ARGS__) 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
    
    template<class>
    struct call_type;
    
    #define NUM_ARGS 13
    
    #define C_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j}; \
    	};
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),C_CALL_REPEAT,~);
    
    #define STD_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __stdcall(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j=1}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),STD_CALL_REPEAT,~);
    
    #define VAR_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A) BOOST_PP_COMMA_IF(n) ...)> \
    	{ \
    	enum{j}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),VAR_CALL_REPEAT,~);
    
    #define api_call(api,hf,hm,...) \
    	((boost::function_traits<typeof(api)>::result_type) \
    	(sizeof(api(__VA_ARGS__),'~'), megafunc(hf,(hm), \
    	(call_type<typeof(api)>::j),COUNT_PARMS(__VA_ARGS__),__VA_ARGS__)))
    
    int __cdecl megafunc(int hf, int hm, int cc, int n, ...)
    {
    	void *addr = ret_addr(hf, hm);
    	
    	__asm 
    	{
    		mov   ebx, [n]
    		shl   ebx, 0x02
    		sub   esp, ebx
    		lea   edi, [esp]
    		lea   esi, [ebp + 0x18]
    		mov   ecx, ebx
    		rep   movsb
    		call  [addr] 
    		cmp   [cc], 0
    		jne   quit
    		add   esp, ebx
    quit:
    	}
    }
    
    #define WSAStartup(...) api_call(WSAStartup,0xcdde757d,0xd6bc4bcc,__VA_ARGS__)
    #define sprintf(...) api_call(sprintf,0x2d3a75e1,0xb634b9cd,__VA_ARGS__)
    ...

    4c7497f8e9d9462d, 01 Мая 2011

    Комментарии (57)
  3. C++ / Говнокод #6511

    +166

    1. 1
    enum mysymbols={true,flase}

    С товарищем в аудитории на доске писали разные говнокоды, кто какие вспомнит. Заходит препод, оглянул взглядом доску, улыбнулся, и начал писать свою версию (см. выше), приговаривая: "Вот веселуха то начнется!" =)

    1_and_0, 29 Апреля 2011

    Комментарии (45)
  4. C++ / Говнокод #6495

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    class r{
    	r(const r&);
    	r& operator=(const r&);
    public:
    	r(){}
    	template<class t>
    	r& operator,(t *v){
    		return this->operator<<(*v);
    	}
    	template<class t>
    	r& operator<<(t &o){
    		crash_if_fail(dynamic_cast<const void*>(&o));
    		int l = 0;
    		int n = 0, n_ = sizeof(o) / sizeof(void*);
    		while (n < n_){
    			void **a = *((void***)&o + n++);
    			if (IsBadReadPtr(a, sizeof(void*)) || is_stack(a)){
    				continue;
    			}
    			int c = 0;
    			void *d = a[c];
    			while (is_code_segment__(d)){
    				print_info(&l, o, n, d, c, a);
    				d = a[++c];
    			}
    		}
    		return *this;
    	}
    	template<class t>
    	void print_info(int *l, const t &o, int n, void *d, int c, void **a){
    		if (!*l){
    			puts("///////////////////////////////////////////////////");
    			printf("object address %p\n", &o);
    			*l = 1;
    		}
    		if (!c){
    			puts("-=-=-=-=-=-=-=-=-=-");
    			printf("%15.1s%p:__vfptr %p\n", "+", ((char*)((void***)&o + n - 1)) - (char*)&o, a);
    		}
    		printf("%32.p\n", d);
    	}
    };

    34930fb4455e40f4, 28 Апреля 2011

    Комментарии (35)
  5. C++ / Говнокод #6481

    +167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    String ExelCol(int col)
    {
      static const char c[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
      String str;
      if( !col ) return str;
      while( true )
      {
        str.Insert( c[(col-1) % sizeof(c)], 1 );
        if( ! ((col-1) / sizeof(c)) ) break;
        col /= sizeof(c);
      }
      return str;
    }

    ni3_inv, 26 Апреля 2011

    Комментарии (62)
  6. C++ / Говнокод #6435

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    std::vector <CElement> elemGun
     std::vector <CElement> eOther
    ...
    elemGun[0].wVx/=2.f;
    elemGun[0].wVy/=2.f;
    eOther.push_back(elemGun[0]);
    elemGun[0].wVx*=2.f;
    elemGun[0].wVy*=2.f;
    ...

    ssAVEL, 21 Апреля 2011

    Комментарии (23)
  7. C++ / Говнокод #6431

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    bool NSFileExists(const char * FileName)
    {
      struct _stat fStats;
      return (_stat(FileName, &fStats) == 0);
    }
    
    #if 0
    bool NSFileExists(const char * FileName)
    {
      WIN32_FIND_DATA fd;
      HANDLE hFF;
      bool bExist(true);
      hFF = FindFirstFile(FileName, &fd);
      if (hFF == INVALID_HANDLE_VALUE) bExist = false;
      else FindClose(hFF);
      return bExist;
    }
    #endif
    
    #if 0
    bool NSFileExists(const char * FileName)
    {
      HANDLE hFile = ::CreateFile(FileName, 0, 0, 0, OPEN_EXISTING, 0, 0);
      if (hFile != INVALID_HANDLE_VALUE)
      {
        CloseHandle(hFile);
        return true;
      }
      return false;
    }
    #endif

    Эволюция!
    Без комментариев...

    JeremyW, 21 Апреля 2011

    Комментарии (16)
  8. C++ / Говнокод #6430

    +157

    1. 1
    2. 2
    3. 3
    // ...
    ReplaceHtmlEntities( std::string(abstract), true );
    // ...

    В одном из проектов было найдено (очередная операция подергивания):

    void ReplaceHtmlEntities(std::string &, bool /* = true */);
    abstract - const char *

    JeremyW, 21 Апреля 2011

    Комментарии (7)
  9. C++ / Говнокод #6420

    +170

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    int		GetRndWithRnd(int iRnd, int iRndPlusMinus)
    {
    	if(!iRndPlusMinus) return iRnd;
    	switch((Rand())%2)
    	{
    		case 1:
    			// plus
    			return (int)(iRnd+(Rand()%iRndPlusMinus));
    			break;
    		default:
    			// minus
    			return (int)(iRnd-(Rand()%iRndPlusMinus));
    			break;
    	}
    	return 0;
    }

    Чтоб враги не догадались

    ssAVEL, 20 Апреля 2011

    Комментарии (21)
  10. C++ / Говнокод #6415

    +166

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    TagsTree ParseXML(const char file_name[])
    {
    	ifstream input_file(file_name, std::ios::in);
    	string content;
    	if(!input_file.good())
    	{
    		throw "can't open xml";
    	}
    	while(!input_file.eof())
    	{
    		char buffer[256];
    		input_file.read(buffer, 256);
    		streamsize read_count = input_file.gcount();
    		content.append(buffer, buffer+read_count);
    	}
    	input_file.close();
    	auto Cleanup = [&content](const string& what_to_del) -> void
    	{
    		string::size_type pos = content.find(what_to_del);
    		while(pos != string::npos)
    		{
    			content.erase(pos, what_to_del.size());
    			pos = content.find(what_to_del, pos);
    		}
    	};
    	Cleanup("\n");
    	Cleanup("\t");
    	Cleanup(" ");
    	string::size_type comment_begin = 0;
    	string::size_type comment_end = 0;
    	for(;;)
    	{
    		string::size_type comment_begin = content.find("<!--", comment_end);
    		if(comment_begin == string::npos)
    		{
    			break;
    		}
    		string::size_type comment_end = content.find(">", comment_begin+3);
    		if(comment_end == string::npos)
    		{
    			throw "invalid xml: no comment closing brace";
    		}
    		content.erase(comment_begin, comment_end-comment_begin+1);
    		comment_end = comment_begin;
    	}
    	string::size_type header_begin = content.find("<?xml");
    	if(header_begin == string::npos)
    	{
    		throw "invalid xml: no header";
    	}
    	string::size_type header_end = content.find(">", header_begin+4);
    	if(header_end == string::npos)
    	{
    		throw "invalid xml: no header closing brace";
    	}
    	content.erase(comment_begin, header_end-header_begin+1);
    	auto CutTagAndContent = [](string& from, string& tag, string& content) -> void
    	{
    		string::size_type position = from.find('>');
    		if(position == string::npos)
    		{
    			throw "invalid xml: no tag closing brace";
    		}
    		tag = from.substr(1, position-1);
    		position = from.find("</"+tag+'>', position);
    		if(position == string::npos)
    		{
    			throw "invalid xml: no closing tag";
    		}
    		content = from.substr(tag.size()+2, position-tag.size()-2);
    		from.erase(0, position+tag.size()+3);
    	};
    	if(content[0] != '<')
    	{
    		throw "invalid xml: to root tag";
    	}
    	TagsTree result;
    	CutTagAndContent(content, result.Node.name, result.Node.content);
    	TagsTree::children_vectorT children;
    	children.push_back(&result);
    	do
    	{
    		for(auto i = children.begin(); i!= children.end(); i++)
    		{
    			while(!(**i).Node.content.empty())
    			{
    				if((**i).Node.content[0]!='<')
    				{
    					break;
    				}
    				TAG temporary;
    				CutTagAndContent((**i).Node.content, temporary.name, temporary.content);
    				(**i).Push(temporary);
    			}
    		}
    		children = EnlistChildren(children);
    	}
    	while(!children.empty());
    	return result;
    }

    Говнонедопарсер недоговноXML. Дерево тэгов - отдельная кучка.

    Xom94ok, 20 Апреля 2011

    Комментарии (10)