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

    +134

    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
    void MSSequencerPatternCopyToMusicTrack(MSSequencerPatternRef self, MusicTrack track)
    {
        // Get signature and length of pattern
        TimeSignature sign   = MSSequencerPatternGetTimeSignature(self);
        CABarBeatTime length = pattern_barbeat_duration_without_mutes(self);
        CABarBeatTime insert = CABarBeatTime(1, 1);
        // Get muted beats
        CFRange *mutedBeats = (CFRange*)CFDataGetBytePtr(self->mutedBeats);
        CFIndex  mutedCount = CFDataGetLength(self->mutedBeats) / sizeof(CFRange);
        // Copy with muted regions
        if (mutedCount > 0)
        {
            // Clear output track
            MSSequencerTrackClear(self->parent, track);
            // Copy phrase by phrase
            for (int i = 0; i < mutedCount; ++i)
            {
                CFRange muteRange  = mutedBeats[i];
                CFIndex beatsCount = (sign.numerator * sign.denominator);
                
                if ((beatsCount * (i + 1)) > muteRange.location + muteRange.length)
                {
                    if (muteRange.length > 0)
                    {
                        // Copy beats before mute range
                        if (muteRange.location > (beatsCount * i))
                        {
                            CFIndex start = (beatsCount * i);
                            CFIndex end   = muteRange.location;
                            insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                        }
                        // Copy beats after range
                        {
                            CFIndex start = (muteRange.location + muteRange.length);
                            CFIndex end   = (beatsCount * (i + 1));
                            insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                        }
                    }
                    else
                    {
                        // Copy without mutes
                        CFIndex start = (beatsCount * i);
                        CFIndex end   = (beatsCount * (i + 1));
                        insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
                    }
                }
                else
                {
                    // Copy beats
                    CFIndex firstBeat = (muteRange.location + muteRange.length) % beatsCount;
                    CABarBeatTime start = CABarBeatTimeAddBeats(CABarBeatTime(1, 1), sign, (beatsCount * i) + firstBeat);
                    CABarBeatTime end   = CABarBeatTimeAddBeats(start, sign, (beatsCount - muteRange.length));
                    copy_beats_from_pattern_to_track(self, track, start, end, insert);
                    //CFLog("start: {%i, %i}, end: {%i, %i}, insert: {%i, %i}", (int)start.bar, (int)start.beat, (int)end.bar, (int)end.beat, (int)insert.bar, (int)insert.beat);
                    // Update insert time
                    insert = CABarBeatTimeAddBeats(insert, sign, (beatsCount - muteRange.length));
                }
            }
        }
        // Copy without muted regions
        else
        {
            copy_beats_from_pattern_to_track(self, track, insert, length, insert);
        }
        //CAShow(track);
    }

    Вот такая вот какашечка...

    gerasim13, 28 Января 2015

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

    +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
    // For a portable version of timegm(), set the TZ environment variable  to
    // UTC, call mktime(3) and restore the value of TZ.  Something like
    
    #include <time.h>
    #include <stdlib.h>
    
    time_t
    my_timegm(struct tm *tm)
    {
        time_t ret;
        char *tz;
    
        tz = getenv("TZ");
        if (tz)
            tz = strdup(tz);
        setenv("TZ", "", 1);
        tzset();
        ret = mktime(tm);
        if (tz) {
            setenv("TZ", tz, 1);
            free(tz);
        } else
            unsetenv("TZ");
        tzset();
        return ret;
    }

    Цитата из man timegm. Сборка unix timestamp из компонент (год, месяц и т.п.).

    Удобно, наглядно, потокобезопасно.

    bormand, 23 Января 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void	Nay_Prer_Timer2(void)
    {
      Obr_Func_Prer.Sh_Time2 = Obr_Func_Prer.Sh_Time2_Init;
      Spec_Vkl_Indic.Sh_Time2 = Spec_Vkl_Indic.Sh_Time2_Init;
      Spec_Vykl_Indic.Sh_Time2 = Spec_Vykl_Indic.Sh_Time2_Init;
      Flag_Morg=0;	// Флаг моргания для Config_Bibl_Max6954
      Flag_Vykl_Diod=0;
      if(Config_Bibl_Max6954&0x4)	// 2-й бит =1 - Прерывания разрешены
        Vkl_Prer_Timer2();
      return;
    }

    Чел писал тестовое задание для микроконтроллера (поморгать светодиодами).
    На вопрос что означает слово Nay в названии функции был дан ответ - это сокращение от нач. (начало).

    synya, 23 Января 2015

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

    +133

    1. 1
    2. 2
    if (dbg)
    	printf("2\n");

    // This is debug mode

    codemonkey, 22 Января 2015

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

    +133

    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
    //......................................
    void DlPortWritePortUshort(WORD addr, WORD data) {
      DWORD br;
      (&addr)[1]=data;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_USHORT,&addr,4,NULL,0,&br,NULL);
    }
    
    DWORD DlPortReadPortUlong(WORD addr) {
     DWORD br;
     DeviceIoControl(hdriver,IOCTL_READ_PORT_ULONG,&addr,2,&addr,4,&br,NULL);
     return *(DWORD*)&addr;
    }
    
    void DlPortWritePortUlong(WORD addr, DWORD data) {
      DWORD br;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_ULONG,&addr,8,NULL,0,&br,NULL);
    }
    //......................................

    Кусок очередного форка dll-ки для работы с очередным, мать его, форком драйвера inpout32.sys.
    Попался в поисках исправленного драйвера и dll-обёртки для него.

    harvestor, 22 Января 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #include <stdio.h>
    int main(void) 
    {
        puts("1\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99");
        return 0; 
    }

    Выводим все нечетные числа от 0 до 100. Одно число - одна строка.

    GreatMASTERcpp, 19 Января 2015

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

    +134

    1. 1
    2. 2
    if (channel->leftover < 0)		// if nothing left over for next time:
    	printk("ERRRRRRRRRRRRRRRRRRRRRRRRRRRR\n");

    RRRRRRRRRRRRRRetard.

    codemonkey, 19 Января 2015

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

    +136

    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
    struct hostent *rc_gethostbyname(const char *hostname)
    {
    	struct 	hostent *hp;
    #ifdef GETHOSTBYNAME_R
    #if defined (GETHOSTBYNAMERSTYLE_SYSV) || defined (GETHOSTBYNAMERSTYLE_GNU)
    	struct 	hostent hostbuf;
    	size_t	hostbuflen;
    	char	*tmphostbuf;
    	int	res;
    	int	herr;
    	
    	hostbuflen = 1024;
    	tmphostbuf = malloc(hostbuflen);
    #endif
    #endif
    
    #ifdef GETHOSTBYNAME_R
    #if defined (GETHOSTBYNAMERSTYLE_GNU)
    	while ((res = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &hp, &herr)) == ERANGE)
    	{
    		/* Enlarge the buffer */
    		hostbuflen *= 2;
    		tmphostbuf = realloc(tmphostbuf, hostbuflen);
    	}
    	free(tmphostbuf);
    #elif defined (GETHOSTBYNAMERSTYLE_SYSV)
    	hp = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &herr);
    	free(tmphostbuf);
    #else
    	hp = gethostbyname(hostname);
    #endif
    #else
    	hp = gethostbyname(hostname);
    #endif
    
    	if (hp == NULL) {
    		return NULL;
    	}
    	return hp;
    }

    freeradius-client 1.1.6, казалось бы серьезная либа... Говно мамонта, конечно, но оно валяется в репе бубунты 14.10... Неужели никто еще не заметил? :)

    bormand, 15 Января 2015

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

    +138

    1. 1
    if (!GL_TRUE == linkStatus)

    пример из vuforia sdk
    вроде подобного булшита еще не было

    chtulhu, 15 Января 2015

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

    +143

    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
    void ** __attribute__((noinline)) findVoidSortMap(void ** list,void *key)
    {
        if (!list) return 0;
        if (!*list) return 0;
        unsigned int count= **(unsigned int**)list;
        char *p=(char*)*list;
        p+=4;
        Element *b=(Element *)p;
     
        long long skey=(long long)key;
     
        while (count>0) {
            void** kt=(void**)&b[count>>1];
            long long rkey=(long long)kt[0];
            if (skey==rkey) return (void**)&kt[1];
            if (skey>rkey) {b+=(count>>1)+1;count--;}
            count=count>>1;
        }
     
        return (void**)-1;
    }

    гуру осемблира на этом коде доказывал, что Эльбрус сосёт
    http://www.gamedev.ru/flame/forum/?id=196722&page=33#m481

    TarasB, 05 Января 2015

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