1. Список говнокодов пользователя codemeow

    Всего: 3

  2. bash / Говнокод #27988

    +1

    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
    stop() {
      PIDS=$(/sbin/pidof $PNAME)
      CNT=0
      if [[ $PIDS != "" ]]; then
    	echo -n "Stopping $PNAME: "
    	killall $PNAME && echo "ok" || echo "failed"
      	while [[ $PIDS != "" ]]
      	do 
      		PIDS=$(/sbin/pidof $PNAME)
    		echo -n "."
    		sleep 1
    		CNT=$(($CNT+1))
    		if [[ $CNT -eq 3 ]]; then killall -9 $PNAME;echo -e "\n$PNAME: Force kill";break; fi
      	done
      	echo 
      else echo "$PNAME: don't start"
      fi
    }

    Так автор видел выключение процесса. Процесс работает с файлами на жестком диске и ему важна их целостность, поэтому за 3 секунды не завершался. А еще при gracefully shutdown пишется обновление конфига процесса на диск. Но кого волнуют такие мелочи если оно уже работает в проде 7+ лет

    codemeow, 04 Февраля 2022

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

    +2

    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
    union bitdata {
        struct {
          unsigned int bit1 : 1;
          unsigned int bit2 : 1;
          unsigned int bit3 : 1;
          unsigned int bit4 : 1;
          unsigned int bit5 : 1;
          unsigned int bit6 : 1;
          unsigned int bit7 : 1;
          unsigned int bit8 : 1;
        };
        unsigned char byte;
      } first_byte, second_byte;
    
    <...>
    
    for ( j = 0; j < bytes_count; j++ ) {
          unsigned char t;
    
          ret = gzread( gz_fd, &t, sizeof( t ) );
          if ( ret != sizeof( t ) ) {
        printf( "Failed to read file %s: %s\n", argv[i], strerror( errno ) );
        gzclose( gz_fd );
        return EXIT_FAILURE;
          }
    
          first_byte.byte  = t;
          second_byte.byte = ready_bytes[j];
    
          first_byte.bit1 = first_byte.bit1 == 0 && second_byte.bit1 == 0 ? 0 : 1;
          first_byte.bit2 = first_byte.bit2 == 0 && second_byte.bit2 == 0 ? 0 : 1;
          first_byte.bit3 = first_byte.bit3 == 0 && second_byte.bit3 == 0 ? 0 : 1;
          first_byte.bit4 = first_byte.bit4 == 0 && second_byte.bit4 == 0 ? 0 : 1;
          first_byte.bit5 = first_byte.bit5 == 0 && second_byte.bit5 == 0 ? 0 : 1;
          first_byte.bit6 = first_byte.bit6 == 0 && second_byte.bit6 == 0 ? 0 : 1;
          first_byte.bit7 = first_byte.bit7 == 0 && second_byte.bit7 == 0 ? 0 : 1;
          first_byte.bit8 = first_byte.bit8 == 0 && second_byte.bit8 == 0 ? 0 : 1;
    
          ready_bytes[j] = first_byte.byte;
        }

    Всё еще не можем понять, зачем в конце тернарник. Всё остальное уже не смущает.

    codemeow, 21 Января 2022

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

    +3

    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
    rule_t block_r = ch_p('{') >> *(~ch_p('}') | (~ch_p('{') >> block_r));
    	rule_t bin_r = str_p("0b") >> bin_p[assign(m)];
    	rule_t hex_r = str_p("0x") >> hex_p[assign(m)];
    	rule_t dec_r = uint_p[assign(m)];
      rule_t id_r = alpha_p >> *(alnum_p | ch_p('_') | ch_p('.'));
      rule_t string_r = ch_p('"') >> (*(~ch_p('"')))[assign(s)] >> ch_p('"');
      rule_t channel_r = str_p("channel") >> *(space_p) >> id_r[assign(s)][assign_a(ch.name,s)][push_back_a(lstJSVars_,s)] >> *(space_p) >> ch_p('{') >>
        *(space_p 
    			| (str_p("mode") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
            	(str_p("in")[assign_a(ch.mode,(int)channel::IN)] | str_p("out")[assign_a(ch.mode,(int)channel::OUT)]) >> *(space_p) >> ch_p(';'))
    			| (str_p("number") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.number)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("channel") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.ch)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("gain") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.gain)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("type") >> *(space_p) >> ch_p('=') >> *(space_p) >>
    					(str_p("analog")[assign_a(ch.type,(int)channel::ANALOG)] | str_p("discrete")[assign_a(ch.type,(int)channel::DISCRETE)]) >> *(space_p) >> ch_p(';'))
    			| (str_p("mask") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
    					(bin_r[assign_a(ch.mask,m)] | hex_r[assign_a(ch.mask,m)] | dec_r[assign_a(ch.mask,m)]) >> *(space_p) >> ch_p(';'))
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';'); 
      rule_t device_r = str_p("device_info") >> *(space_p) >> id_r[assign(dev_info_.name)] >> *(space_p) >> ch_p('{') >>
        *(space_p | 
          (str_p("device") >> *(space_p) >> ch_p('=') >> *(space_p) >> string_r[assign_a(dev_info_.dev,s)] >> *(space_p) >> ch_p(';')) | 
          (str_p("blocking") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
            (str_p("true")[assign_a(dev_info_.blocking,true)] | str_p("false")[assign_a(dev_info_.blocking,false)]) >> *(space_p) >> ch_p(';')) |
          (str_p("freq_ch") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.freq_ch)] >> *(space_p) >> ch_p(';')) | 
          (str_p("freq_sel_ch") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.freq_sel_ch)] >> *(space_p) >> ch_p(';')) |
          (str_p("speed") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.speed)] >> *(space_p) >> ch_p(';')) | 
          channel_r[assign_a(v,ch)][push_back_a(lstChannels_,v)]
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';');
      rule_t var_r = (str_p("var") >> *(space_p) >> id_r[assign(s)][push_back_a(lstJSVars_,s)] >>*(~ch_p(';')) >> ch_p(';'))[assign(s)][push_back_a(lstVars,s)];
      rule_t function_r = str_p("function") >> *(~ch_p('`'));
    	//rule_t function_r = str_p("function") >> *(~ch_p('{')) >> block_r;
      rule_t script_r = str_p("script") >> *(space_p) >> ch_p('{') >>
        *(space_p |
          var_r[assign(s)][push_back_a(lstJSVars_,s)] |
          (function_r[assign(s)][push_back_a(lstFunc,s)] >> *(space_p) >> ch_p('`'))
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';');

    Из системы эмуляции полёта на тренажере.

    codemeow, 21 Января 2022

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