- 1
- 2
- 3
- 4
- 5
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+139
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
Совместимость
+140
HIMAGELIST ImageList_LoadImageV(PVOID ImageBase, PCWSTR a[], int level)
{
PIMAGE_RESOURCE_DATA_ENTRY pirde;
PBITMAPINFOHEADER pbih;
DWORD cx, cy, cb, n, ofs;
if (
0 <= LdrFindResource_U(ImageBase, a, level, &pirde) &&
0 <= LdrAccessResource(ImageBase, pirde, (void**)&pbih, &cb) &&
cb > sizeof(BITMAPINFOHEADER) &&
pbih->biSize >= sizeof(BITMAPINFOHEADER) &&
(cx = pbih->biWidth) <= (cy = pbih->biHeight) &&
!(cy % cx) &&
pbih->biBitCount == 32 &&
(ofs = pbih->biSize) + (cx * cy << 2) == cb
)
{
n = cy / cx, cb = cx * cx << 2;
if (HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR32, n, 0))
{
BITMAPINFO bi = { {sizeof(BITMAPINFOHEADER), cx, cx, 1, 32 } };
if (HDC hdc = GetDC(0))
{
if (HBITMAP hbmp = CreateCompatibleBitmap(hdc, cx, cx))
{
do ; while (
SetDIBits(hdc, hbmp, 0, cx, RtlOffsetToPointer(pbih, ofs), &bi, DIB_RGB_COLORS) &&
0 <= ImageList_Add(himl, hbmp, 0) &&
(ofs += cb, --n)
);
DeleteObject(hbmp);
}
ReleaseDC(0, hdc);
}
if (!n) return himl;
ImageList_Destroy(himl);
}
}
return 0;
}
+135
int log2_floor (unsigned x)
{
#define NIMHTNOE0WNM(n) (((~(x>>n)+1)>>n)&n)
int res, n;
n = NIMHTNOE0WNM(16); res = n; x >>= n;
n = NIMHTNOE0WNM( 8); res |= n; x >>= n;
n = NIMHTNOE0WNM( 4); res |= n; x >>= n;
n = NIMHTNOE0WNM( 2); res |= n; x >>= n;
n = NIMHTNOE0WNM( 1); res |= n;
return res;
}
Кто-то Воррена перечитал.
+138
int fermat (void)
{
const int MAX = 1000;
int a=1,b=1,c=1;
while (1) {
if (((a*a*a) == ((b*b*b)+(c*c*c)))) return 1;
a++;
if (a>MAX) {
a=1;
b++;
}
if (b>MAX) {
b=1;
c++;
}
if (c>MAX) {
c=1;
}
}
return 0;
}
#include <stdio.h>
int main (void)
{
if (fermat()) {
printf ("Fermat's Last Theorem has been disproved.\n");
} else {
printf ("Fermat's Last Theorem has not been disproved.\n");
}
return 0;
}
Fermat's Last Theorem has been disproved
http://blog.regehr.org/archives/140
Если уже было черкните мне на /dev/null@localhost, удалю
+136
/* To the unenlightened: This sets the 20 MSBs to 0 for sanity's sake. */
return four_bytes_to_uint32(four_byte_array) & ~(~0 << 12);
Так приказали K&R.
+139
char* xml_compose_simple_response(char* response, int code, char* description, char* additional_data)
{
size_t resp_length = 0;
char* buff = NULL;
resp_length += strlen(RESPONSE_HEADER_PREFIX);
resp_length += strlen(session_type);
resp_length += strlen(transaction_id);
resp_length += strlen(response) + strlen(EMPTY_TAG);
if(NULL != additional_data)
{
resp_length += strlen(additional_data);
}
resp_length += strlen(description) + strlen(RESULT_INT) + sizeof(int) * 8;
resp_length += strlen(RESPONSE_HEADER_SUFFIX);
resp_length += 1;
if(NULL != (buff = malloc(resp_length)))
{
buff[0] = '\0';
sprintf(buff, RESPONSE_HEADER_PREFIX""EMPTY_TAG, session_type, transaction_id, response);
if (additional_data != NULL)
{
char tmp_desc[_2K];
sprintf(tmp_desc, description, additional_data);
sprintf(&buff[strlen(buff)], RESULT_INT, code, tmp_desc);
}
else
{
sprintf(&buff[strlen(buff)], RESULT_INT, code, description);
}
strcat(buff, RESPONSE_HEADER_SUFFIX);
}
else
{
mng_report_memory_failure_location_and_exit();
}
return buff;
}
XML вручную собирай @ на кавычкай падай. Никакого АПИ, только хардкор.
+135
return (true == is_break) ? resource : NULL;
Вонъ изъ профессiи!
+131
// bg_pmove.c -- both games player movement code
// takes a playerstate and a usercmd as input and returns a modifed playerstate
Дальше идут 11 тысяч строк нечитаемого говна. Это вообще нормально?!
+136
int Sys_FunctionCmp(void *f1, void *f2) {
int i, j, l;
byte func_end[32] = {0xC3, 0x90, 0x90, 0x00};
byte *ptr, *ptr2;
byte *f1_ptr, *f2_ptr;
ptr = (byte *) f1;
if (*(byte *)ptr == 0xE9) {
//Com_Printf("f1 %p1 jmp %d\n", (int *) f1, *(int*)(ptr+1));
f1_ptr = (byte*)(((byte*)f1) + (*(int *)(ptr+1)) + 5);
}
else {
f1_ptr = ptr;
}
//Com_Printf("f1 ptr %p\n", f1_ptr);
ptr = (byte *) f2;
if (*(byte *)ptr == 0xE9) {
//Com_Printf("f2 %p jmp %d\n", (int *) f2, *(int*)(ptr+1));
f2_ptr = (byte*)(((byte*)f2) + (*(int *)(ptr+1)) + 5);
}
else {
f2_ptr = ptr;
}
//Com_Printf("f2 ptr %p\n", f2_ptr);
#ifdef _DEBUG
sprintf((char *)func_end, "%c%c%c%c%c%c%c", 0x5F, 0x5E, 0x5B, 0x8B, 0xE5, 0x5D, 0xC3);
#endif
for (i = 0; i < 1024; i++) {
for (j = 0; func_end[j]; j++) {
if (f1_ptr[i+j] != func_end[j])
break;
}
if (!func_end[j]) {
break;
}
}
#ifdef _DEBUG
l = i + 7;
#else
l = i + 2;
#endif
//Com_Printf("function length = %d\n", l);
for (i = 0; i < l; i++) {
// check for a potential function call
if (*((byte *) &f1_ptr[i]) == 0xE8) {
// get the function pointers in case this really is a function call
ptr = (byte *) (((byte *) &f1_ptr[i]) + (*(int *) &f1_ptr[i+1])) + 5;
ptr2 = (byte *) (((byte *) &f2_ptr[i]) + (*(int *) &f2_ptr[i+1])) + 5;
// if it was a function call and both f1 and f2 call the same function
if (ptr == ptr2) {
i += 4;
continue;
}
}
if (f1_ptr[i] != f2_ptr[i])
return qfalse;
}
return qtrue;
}
Хмм...
+132
#ifndef M_PI
#define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h
#endif
Сишкопроблемы.