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

    Всего: 2

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

    −131

    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
    #!/bin/bash
    
    ######################################################################################
    #
    #	Write a bash script that obtains active processes for the current user, 
    #	breaks them into chains and prints all unique chains containing 3 or more 
    #	PIDs in the following format:
    #		PID1:PID2:PID3:…:PIDn
    #		PID:PID:PID:…:PID
    #		…
    #	So that each next PID is a parent of the previous PID, the first PID in 
    #	each chain does not have children and the last PID in each chain 
    #	does not have parent.
    #
    ######################################################################################
    
    TEMPFILE="/tmp/$0$$"				# file needs to save the process list
    						# it's really needed to divide columns
    						# generated 'ps'
    						
    # parameters:
    # 	-H 	- sorts the list as process forest (it lets to find connection between child and parent faster)
    #	-o	- sets the output format
    #	"%p %P" - thow columns in output: PID and PPID
    #	-u	- sets username
    #	`whoami` - get the current user name
    ps -H -o "%p %P" -u `whoami` > $TEMPFILE
    PIDLIST=(`awk '/[0-9]/ {print $1}' $TEMPFILE`)	# make an array using the first column
    PPIDLIST=(`awk '/[0-9]/ {print $2}' $TEMPFILE`)	# 	and the second
    
    SIZE=${#PIDLIST[*]}
    K=0
    # bypassing the forest using stack which emulates LINKS array. K is the pointer to stack's top
    for (( i=0; i<$SIZE; i++ ))
    do
        if [[ $K = 0 || ${PPIDLIST[$i]} = ${LINKS[$K-1]} ]]	# new tree or new edge in the tree.
        then
            LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
            K=`expr $K + 1`
        else 					# the chain is complete.
    	if [[ $K > 2 ]]				# enough size to print the chain
    	then				# reversed formatted output the chain
    	    echo ${LINKS[*]} | awk '{ printf $NF; for (i = NF-1; i > 0; --i) printf ":"$i}'
    	    echo
    	fi
            until [[ $K == 0 || ${PPIDLIST[$i]} == ${LINKS[$K-1]} ]]
            do 					# deleting elements from stack until find a
        						#	parent or tree is end
        	    unset LINKS[$K-1]
        	    K=`expr $K - 1`
            done
    	LINKS[$K]=${PIDLIST[$i]}		# push PID to stack
    	K=`expr $K + 1`
        fi
    done
    
    rm -rf $TEMPFILE				# removing temp file

    cahekm, 05 Апреля 2011

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

    +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
    #include <iostream>
    #include <cstdlib>
    #include "filesdescrtable.h"
    
    int ___cntr = 0;
    #define _(X) if((X) == EXIT_SUCCESS) {___cntr++;} else {std::cerr << "error on operator: " << ___cntr << std::endl; return (EXIT_FAILURE);}
    
    int main (int argc, char *argv[]) {
    	FilesDescrTable a;
    
    	int d1,d2,d3;
    
    	_(a.setAutoReport(true));
    	_(a.openFile(argv[1], O_RDWR | O_CREAT, 0600, d1));
    	_(a.openFile(argv[2], O_RDWR | O_CREAT, 0600, d2));
    	_(a.openFile(argv[3], O_RDWR | O_CREAT, 0600, d3));
    	_(a.clearFile(argv[3]));
    	_(a.cpy(d3,d2));
    	_(a.closeFile(d1));
    	_(a.closeFile(d2));
    	_(a.closeFile(d3));
    
    	return(EXIT_SUCCESS);
    }

    хитрый макрос для отлова ошибок. такой хитрый

    cahekm, 13 Марта 2011

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