1. Си / Говнокод #17904

    +139

    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
    ...
    // GRAY SCALE:
    
    #define ER_COLOR_BLACK_DEEP3        ccc3(0, 0, 0)
    #define ER_COLOR_BLACK_DEEP4        ccc4(0, 0, 0, 255)
    
    #define ER_COLOR_BLACK3             ccc3(38, 38, 38)
    #define ER_COLOR_BLACK4             ccc4(38, 38, 38, 255)
    
    #define ER_COLOR_SIDEMENU_SELECTED3 ccc3(47, 47, 47)
    
    #define ER_COLOR_LETTER_VIEW3       ccc3(51, 51, 51)
    
    #define ER_COLOR_SIDEBAR_BG3        ccc3(58, 58, 58)
    #define ER_COLOR_SIDEBAR_BG4        ccc4(58, 58, 58, 255)
    
    #define ER_COLOR_BAR_BG_GRAY3       ccc3(82, 82, 82)
    
    #define ER_COLOR_AUTHOR_NAME3       ccc3(103, 103, 103)
    
    #define ER_COLOR_SIDE_WIDGET3       ccc3(255, 255, 255)
    #define ER_COLOR_SIDE_WIDGET4       ccc4(255, 255, 255, 255)
    
    #define ER_COLOR_GRAY_TUT3          ccc3(115, 115, 115)
    
    #define ER_COLOR_GRAY3              ccc3(130, 130, 130)
    
    #define ER_COLOR_PULL_LABEL3        ccc3(142, 142, 142)
    
    #define ER_COLOR_SEND_BG4           ccc4(158, 158, 158, 255)
    #define ER_COLOR_SEND_BG3           ccc3(158, 158, 158)
    
    #define ER_COLOR_BADGE_GRAY3        ccc3(149, 149, 149)
    #define ER_COLOR_BADGE_GRAY4        ccc4(149, 149, 149, 255)
    
    #define ER_COLOR_SEPARATOR3         ccc3(195, 195, 195)
    
    #define ER_COLOR_LABELS_GRAY3       ccc3(170, 170, 170)
    
    #define ER_COLOR_AUTHOR_CAPTION3    ccc3(173, 173, 173)
    
    #define ER_COLOR_SAFE_EXIT_BG4      ccc4(189, 189, 189, 255)
    #define ER_COLOR_SAFE_EXIT_BG3      ccc3(189, 189, 189)
    
    #define ER_COLOR_MENU_GRAY_ONE3     ccc3(204, 204, 204)
    
    #define ER_COLOR_PUSHED_ELEMENT3    ccc3(205, 205, 205)
    
    #define ER_COLOR_GRAY_208_3         ccc3(208, 208, 208)
    #define ER_COLOR_GRAY_208_4         ccc4(208, 208, 208, 255)
    
    #define ER_COLOR_MENU_GRAY_TWO3     ccc3(216, 216, 216)
    
    #define ER_COLOR_NEW_GAME_BACK3     ccc3(216, 216, 216)
    #define ER_COLOR_NEW_GAME_BACK4     ccc4(216, 216, 216, 255)
    
    #define ER_COLOR_WHITE_222_3        ccc3(222, 222, 222)
    
    #define ER_COLOR_WHITE_232_3        ccc3(232, 232, 232)
    
    #define ER_COLOR_WHITE_MY_PLATE3        ccc3(243, 243, 243)
    
    #define ER_COLOR_WHITE_INTRO4       ccc4(232, 232, 232, 255)
    
    #define ER_COLOR_WHITE3             ccc3(255, 255, 255)
    #define ER_COLOR_WHITE4             ccc4(255, 255, 255, 255)

    50 оттенков серого в нашем приложении.

    tirinox, 01 Апреля 2015

    Комментарии (256)
  2. Си / Говнокод #17899

    +137

    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
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    for (i = 1; i < argc; i++) {
    		p = argv[i];
    		if ((*p != '-') && (*p != '/'))
    		{
    			printf("Unknown option %s\n", p);
    			return 1;
    		}
    		p++;
    		if (strncmp(p, "pcir=", 5) == 0)	
    		{
    			sscanf(p+5, "%lli", &pci_raddr);
    			opt |= 1;
    		}
    		if (strncmp(p, "pciw=", 5) == 0)
    		{
    			sscanf(p+5, "%lli", &pci_waddr);
    			opt |= 2;
    		}
    		if (strncmp(p, "rwlen=", 6) == 0)
    			sscanf(p+6, "%i", &rwlen);
    		if (strncmp(p, "count=", 6) == 0)
    			sscanf(p+6, "%i", &count);
    		if (strncmp(p, "ch=", 3) == 0)
    			channel = p+3;
    		if (strncmp(p, "poll", 4) == 0)
    			poll = 1;
    		if (strncmp(p, "fpga_read=", 10) == 0)
    		{
    			sscanf(p+10, "%i", &offset);
    			fpga_read_flag = 1;
    		}
    		if (strncmp(p, "fpga_write=", 11) == 0)
    		{
    			sscanf(p+11, "%i", &offset);
    			fpga_write_flag = 1;
    		}
    		if (strncmp(p, "data=", 5) == 0)
    		{
    			sscanf(p+5, "%i", &data);
    			data_valid = 1;
    		}
    
    		if (strncmp(p, "dump_to_file=", 13) == 0)
    		{
    			filename = p+13;
    			dump_to_file = 1;
    		}
    		if (strncmp(p, "loadnios", 8) == 0)
    		{
    			filename = p+8;
    			load_nios = 1;
    		}
    		if (strncmp(p, "DUMP", 4) == 0) // -DUMP
    			dump = 1;
    		if (strncmp(p, "flash_read", 10) == 0) // -flash_read
    		{
    			flash_read_flag = 1;
    		}
    
    		if (strncmp(p, "file_to_flash", 13) == 0) // -file_to_flash
    			file_to_flash = 1;
    		if (strncmp(p, "file=", 5) == 0) // -file
    		{
    			fname = p+5;
    		}
    
    		if (strncmp(p, "base=", 5) == 0) // -base
    		{
    			sscanf(p+5, "%i", &base);
    			basevalid = 1;
    		}
    		if (strncmp(p, "card=", 5) == 0) // -crd
    			sscanf(p+5, "%i", &card);
    		if (strncmp(p, "ver", 3) == 0)
    			ver = 1;
    		if (strncmp(p, "dev=", 4) == 0) // -deм
    			dev = p+4;
    	}

    "А я напишу свой собственный комманд лайн парсер, с хуитой и говном"

    codemonkey, 31 Марта 2015

    Комментарии (0)
  3. Си / Говнокод #17893

    +141

    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
    int fpga_read(char *dev, unsigned int base_addr, unsigned int offset, int len, unsigned char *buf)
    {
        unsigned long long pci_raddr;
        int actual;
        FILE    *fi;
    
        fi = fopen(dev, "r");
        if (fi == NULL) {
            printf("Failed to read from FPGA - Error opening device\n");
            return 1;
        }
    
        pci_raddr = (unsigned long long) 2 << 32 | (base_addr + offset);
        setvbuf(fi, NULL, _IONBF, 0);       // disable file buffering
        fseeko(fi, pci_raddr, SEEK_SET);        // go to the address
        actual = fread(buf, 1, len, fi);        // read the data
        fclose(fi);
        if (actual <= 0) {
            printf("Error  %d reading from device (dev %s, base addr 0x%x, offset 0x%x, len %i)\n", errno, dev, base_addr, offset, len);
            return 2;
        }
        return 0;
    }

    По многочисленным просьбам говнокодеров, выделил в отдельный пост.

    codemonkey, 30 Марта 2015

    Комментарии (3)
  4. Си / Говнокод #17892

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    fi = fopen("kokoko.tmp", "rb");
    
            fseek(fi, 0, SEEK_END);
            file_size = ftell(fi);
            fseek(fi, 0, SEEK_SET);

    rewind? system call? Не, не слышали.

    codemonkey, 30 Марта 2015

    Комментарии (96)
  5. Си / Говнокод #17823

    +139

    1. 1
    #define LIFMT(X) (long int) (X)

    Всё тот же квантовохимический пакет. Что характерно, от обычных кастов дальше никто не отказывается.

    dxd, 20 Марта 2015

    Комментарии (172)
  6. Си / Говнокод #17821

    +135

    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
    #include "mono-math.h"
    
    #ifndef HAVE_SIGNBIT
    
    int
    mono_signbit_float (float x)
    {
    	union { float f; int i; } u;
    
    	u.f = x;
    
    	return u.i < 0;
    }
    
    int
    mono_signbit_double (double x)
    {
    	union { double d; int i[2]; } u;
    
    	u.d = x;
    
    #if G_BYTE_ORDER == G_LITTLE_ENDIAN
    	return u.i [1] < 0;
    #else
    	return u.i [0] < 0;
    #endif
    }
    
    #endif

    Говно тут в том, что int далеко не везде будет 32 бит.
    https://github.com/mono/mono/blob/master/mono/utils/mono-math.c оттуда

    j123123, 19 Марта 2015

    Комментарии (5)
  7. Си / Говнокод #17808

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    /*
     * BIG UGLY WARNING! This is so damn ugly I wanna puke.  Unfortunately, some
     * macros that use ASN1_const_CTX still insist on writing in the input
     * stream.  ARGH! ARGH! ARGH! Let's get rid of this macro package. Please? --
     * Richard Levitte      
     */

    OpenSSL...

    bormand, 17 Марта 2015

    Комментарии (30)
  8. Си / Говнокод #17804

    +138

    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
    #define poff    acurp + curp * (nSQs+2)        /*probs: offset*/
    long psum() {return  c(poff+ 1);}    long pmax()    {return c(poff+2);}
    long pn     (long n)                {return          c(poff+2+n);   }
    void setp   (long n, long x){set    (poff+2+n, x);} /*prob changes:*/ 
    void setmax         (long x){set    (poff+2,   x);} /*metasearching*/
    void setsum         (long x){set    (poff+1,   x);}
    long get2ndmax()    {long n= poff+2, x=pmax(), m=n,  s=0,end=n+nSQs;   
         do     {n++;}   while  (c(n) != x);  /*find 2nd-highest <=pmax*/     
         do     {m++;    if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
                 while      (s < x    && m < end);       return  s;}
    void addtoSQ(long i, long val) {long x;   /*increase prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  psum()+val;if (x > maxint) return;   /*has max normalizer*/
         setsum (x);    /*normalizer +*/ x =  pn(i)+val; setp(i, x); 
         if (x > pmax()) setmax (x);}   /*maximal SQprob has increased */    
    void subofSQ(long i, long val) {long x;   /*decrease prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  pn(i)-val; if (x < 0)      return;/*no neg probabilities!*/
         setsum (psum()- val);           setp(i,x);/*don't check if =0!*/   
         if (x + val  == pmax()) setmax (get2ndmax());} /*change of max*/
    void incSQ()        {long i= top();  addtoSQ(i,1);} /*top, not pop!*/
    void decSQ()        {long i= top(),  x,y,z; /*decrem prob of the SQ*/
         if  (i> nSQs   || i< 1) return;/*no such search Q number known*/
         x =  pn(i);     if     (x==0)   return;        /*SQ: already 0*/
         y  = psum();    z =     pmax();              
         if  (x == 1 &&  y    <= z+1)    stop    /*leave at least 2 SQs*/
         if  (x == z)    setmax         (get2ndmax());  /*change of max*/
         setp(i, x-1);   setsum (y-1);}                 /*normalizer -1*/
    long upSQ;          /*SQ probability:enumerator  +=  upSQ: increase*/
    void oldSQ()   {long a=pop()+ndecl,  n,i; if(a<0||a> oldp)stop/*bad*/
         n=old[a].size;  a=old[a].start;/*all SQs of old nondecl: +upSQ*/
         tncheck  n+=a;  for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q],     upSQ);}
    
    void setpat()       {long i= pop(); /*instantiate my search pattern*/
         if  (i<0 || i > patp)     stop /*no such search pattern exists*/
         set (acurp,i);}/*next SQ-search defined via new probabilities!*/
    void pupat()        {long    i  =    apatp;   /*push search pattern*/ 
         if  (i>maxpat)  stop    i++;    set(apatp,i);  /*not too many?*/
         cpabn  (poff+1, acurp + 1 + i *(2+ nSQs),       2 + nSQs,  
                                         acurp + 1,      aendpats);     }  
    void popat()        {long i= apatp;  if(i==0)   stop
         set(apatp,i-1); push(i); }                /*pop search pattern*/

    Полный исходник http://www.idsia.ch/~juergen/oopscode.c

    j123123, 17 Марта 2015

    Комментарии (11)
  9. Си / Говнокод #17802

    +138

    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
    void print_tetral(int i){
        switch(i){
        case 1:
            printf("      January                February                March\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 2:
            printf("       April                   May                    June\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 3:
            printf("        July                  August               September\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 4:
            printf("      October                 November               December\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        default:
            break;
        }
    }

    alobanov, 16 Марта 2015

    Комментарии (24)
  10. Си / Говнокод #17801

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int weeks_in_month(int month, int year){
        int weeks=1, first, i=0;  //i - числа месяца
        first = weekday(1, 1, 1, 1, 1, month, year);
        i += 8 - first;
        while(i <= days_in_month(month, year)){
            ++weeks;
            i += 7;
        }
        return weeks;
    }

    alobanov, 16 Марта 2015

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