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

    +148

    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
    void DayNumbSat (double day, int month, double year, double days) {
         
         int FirstJan, DayNumb; 
         char *Sat;
    
         FirstJan = (long) days%7 - 1;
         
         
         switch ( month ) {
              case 1: DayNumb = day;
              break;
              case 2: DayNumb = 31 + day;
              break;
              case 3: DayNumb = 31 + 28 + day;
              break;
              case 4: DayNumb = 31*2 + 28 + day;
              break;
              case 5: DayNumb = 31*2 + 28 + 30 + day;
              break;
              case 6: DayNumb = 31*3 + 28 + 30 + day;
              break;
              case 7: DayNumb = 31*3 + 28 + 30*2+day;
              break;
              case 8: DayNumb = 31*4 + 28 + 30*2 + day;
              break;
              case 9: DayNumb = 31*5 + 28 + 30*2 + day;
              break;
              case 10: DayNumb = 31*5 + 28 + 30*3 +day;
              break;
              case 11: DayNumb = 31*6 + 28 + 30*3 +day;
              break;
              case 12: DayNumb = 31*7+30*4+28+day;
              break;
         }
    
         printf("\n%d  PASSED SINCE 1ST OF JANUARY\n", DayNumb);

    govnoval, 12 Мая 2011

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

    +146

    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
    char* a(int pos, char* path)
    { 
        FILE *dbf;
          char value; 
          int i,j,k,l,m,n,o,p,r;
          int numrecs, recnum; 
          Record rec;
          char aa[158];
          char *pp;
          int ln, lp, lc, le, lw, li, ls, lph, lf;    
    
          numrecs = rec.length; 
          recnum = pos;
        dbf = OpenDB(path, &rec);
        ReadRecord(dbf, recnum, &rec);    
        
            ln = strlen(rec.name);
            ls = strlen(rec.surname);
            lp = strlen(rec.patronymic);
            lph = strlen(rec.phone);
            lc = strlen(rec.city);
            le = strlen(rec.edu);
            lw = strlen(rec.work);
            li = strlen(rec.interests);
            lf = strlen(rec.friends);
    
            itoa(recnum, &(aa[0]), 10);
            for (i = 1; i < ln; i++)
                aa[i] = rec.name[i-1];
            for (j = 0; j < ls; j++)
                aa[i+j] = rec.surname[j];
            for (k = 0; k < lp; k++)
                aa[i+j+k] = rec.patronymic[k];
            for (l = 0; l < lph; l++)
                aa[i+j+k+l] = rec.phone[l];
            for (m = 0; m < lc; m++)
                aa[i+j+k+l+m] = rec.city[m];
            for (n = 0; n < le; n++)
                aa[i+j+k+l+m+n] = rec.edu[n];
            for (o = 0; o < lw; o++)
                aa[i+j+k+l+m+n+o] = rec.work[o];
            for (p = 0; p < li; p++)
                aa[i+j+k+l+m+n+o+p] = rec.interests[p];
            for (r = 0; r < lf; r++)
                aa[i+j+k+l+m+n+o+p+r] = rec.friends[r];
    
        pp = strdup(aa);  
        return pp;
    }

    dotnetdeveloper, 12 Мая 2011

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

    +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
    /***   First, attempting to establish a SSL-connection   ***/
    		while(1)
    		{
    			sslConnection = sslConnect((const char *)remoteHost, port, CAFileName, CAPathName, error);
    			if(!sslConnection)
    			{
    				logger(ERR, "receiver: Can not establish SSL connection with %s [description - %s]", remoteHost, error);
    #ifndef DEBUG_MODE
    				if (WaitForSingleObject (hExitEvent, 5000) == WAIT_OBJECT_0)
    				{
    					if(logLevel == DEBUG_LOG_LEVEL)
    						logger(INFO, "receiver: Exit event was set in signaling state");
    					logger(INFO, "receiver: Exit");
    					return(0);
    				}
    #else
    				Sleep(5000);
    #endif
    				continue;
    			}
    			else
    			{
    				if(logLevel == DEBUG_LOG_LEVEL)
    				{
    					logger(INFO, "receiver: Connection with %s is established", remoteHost);
    				}
    				socketError = 0;
    				break;
    			}
    		}

    Пытаемся подключиться к серверу по SSL/TLS, отваливаемся по событию

    cepin, 06 Мая 2011

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

    +132

    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
    static int
    find_entry (int store, int entry, int *buffer)
      {
        int
    	i,
    	next;
    
        if ((entry <= 0) || (entry > Headers[store].size))
          {
    	*buffer = EOL;
    	return (ST_NOENTRY);
          }
    
        if (entry < (Headers[store].size/2))
          {
    		/* search forwards through store */
    		next = Headers[store].first;
    		for (i=1; i<entry; i++)
    			next = Buffers[next].next;
    		*buffer = next;
          }
    	  else
          {
    		/* search backwards through store */
    		next = Headers[store].last;
    		for (i=Headers[store].size; i>entry; i--)
    			next = Buffers[next].prev;
    		*buffer = next;
          }
    
        return (SUCCESS);
      }

    древний и заведомо рабочий код. а ищем-то что?

    ilardm, 04 Мая 2011

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    const bool ejected = (device_type.is_new_protocol() ? device_status.status.stop : (!device_status.status.in_preset && !device_status.status.in_preset)) != 0;
    ...
    if (  (p_ddevice && p_ddevice->preset_state.in_progress ())
       || (p_edevice && p_edevice->preset_state.in_progress ())
       )
       return (CTRL_WAIT);
    ...

    я не повторяюсь никогда никогда

    ilardm, 04 Мая 2011

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

    +102

    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
    if (nchan == 1)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 2)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 3)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 4)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 5)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 6)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 7)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],sub_window_length,main_window_length,out_dir,decon_c);
      }
    ...
      }
      if (nchan >= 14)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],chan_list[7],chan_list[8],chan_list[9],chan_list[10],chan_list[11],chan_list[12],chan_list[13],sub_window_length,main_window_length,out_dir,decon_c);
      }

    Тяжело в сях работать со строками и переменным числом параметров...

    Eyeless, 04 Мая 2011

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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    if ((u[i]!=100500)&&(v[j]==100500))
        v[j]=matr[i+1][j+1].cost-u[i];
    if ((u[i]==100500)&&(v[j]!=100500))
        u[i]=matr[i+1][j+1].cost-v[j];

    пересчет платежей в ТЗЛП

    resettik, 04 Мая 2011

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

    +130

    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
    #include <stdio.h>
    #include <signal.h>
    #include <unistd.h>
    #include <sys/wait.h>
    void sighndlr_1(int signo) { //obrabot4ik dlya 1go processa
        printf("I'm child process #1. I've got SIGINT! :) So, I won't do anything...\n"); //prosto vyvod na ekran soobscheniya o polu4enii signala
    }
    
    void sighndlr_2(int signo) { //dlhya 2go
        printf("I'm child process #2. I've got SIGINT :)\n");
    }
    
    int main(int argc, char **argv) {
        pid_t pid1,pid2,pid3,pid4; //4 do4ernih processa
        static struct sigaction act1,act2,act3; //3 struktury dlya 3h processov
        act1.sa_handler = sighndlr_1; //ustanovka obrabot4ika dlya 1 struktory
        act2.sa_handler = sighndlr_2; //dlya 2i
        act3.sa_handler = SIG_IGN; //ignoriruem signal v 3 strukture
        switch(pid1 = fork()) { //sozdaem 1 do4erniy process
        case -1: //vihodim pri oshibke sozdaniya
    	printf("Error fork\n");
    	exit(1);
    	break;
        case 0:
    	printf("Child process #1 started (pid = %d)\n", getpid()); //soobshenie ob uspeshnom sozdanii i vyvod pid
    	sigaction(SIGINT,&act1,NULL); //ustanovka struktury obrabot4ika dlya SIGINT
    	for(;;) pause(); //beskone4nyi cikl
    	break;
        default:
        switch(pid2 = fork()) { //sozdaem 2 process
        case -1:
    	printf("Error fork\n");
    	exit(1);
    	break;
        case 0:
    	printf("Child process #2 started (pid = %d)\n", getpid());
    	sigaction(SIGINT,&act2,NULL); //dlya SIGINT
    	sigaction(SIGQUIT,&act3,NULL); //ignorim SIGQUIT
    	for(;;) pause();
    	break;
        default:
        switch(pid3 = fork()) { //3 process
        case -1:
    	printf("Error fork\n");
    	exit(1);
    	break;
        case 0:
    	printf("Child process #3 started (pid = %d)\n", getpid());
    	sigaction(SIGINT,&act3,NULL); //ignorim SIGINT
    	for(;;) pause();
    	break;
        default:
        switch(pid4 = fork()) { //4 process
        case -1:
    	printf("Error fork\n");
    	exit(1);
    	break;
        case 0:
    	printf("Child process #4 started (pid = %d)\n", getpid());
    	setsid(); //menyaem identifikator seansa dlya processa
    	printf("Process #4 changed sid\n");
    	for(;;) pause();
    	break;
        default:
        printf("Finishing parent process... (pid = %d)\n", getpid());
        exit(0); //zavershaetsya roditelsky process
        break;
        }        
        break;
        }
        break;
        }
        break;
        }
    }

    Лаба по курсу операционных систем. Нужно было создать 4 дочерних процесса, и для каждого процесса создать свои обработчики для сигнала SIGINT или SIGQUIT. Полученный говнокод полон повторяющихся конструкций, и слишком сильно запутан операторами switch-case.

    Boten, 30 Апреля 2011

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

    +142

    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
    char version[80] = "       POSIX compliant Communications test program version 1.00 4-25-1999\r\n";
       char version1[80] = "          Copyright(C) Mark Zehner/Peter Baumann 1999\r\n";
      
    fputs(version,output);               //display the program introduction
       fputs(version1,output);
       fputs(version2,output);
       fputs(version3,output);
       fputs(version4,output);
       fputs(version5,output);
       fputs(version6,output);
       fputs(version7,output);
       fputs(version8,output);
       fputs(version9,output);
       fputs(version10,output);
       fputs(version11,output); 
       fputs(version12,output);
       fputs(version13,output);

    http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html
    кришну вроде не вызывают. код странным образом напоминает индусский...

    ursus, 26 Апреля 2011

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for(int i=0; i<16; i++) servoPos[i] = 64;
    	for(int i=0; i<16; i++) servoOnOff[i] = SV_OFF;
    	for(int i=0; i<16; i++) servoDirection[i] = SV_FOR;
    	for(int i=0; i<16; i++) servoRange[i] = 15;
    	for(int i=0; i<16; i++) servoCenter[i] = 3000;
    	for(int i=0; i<16; i++) servoSpeed[i] = 127;

    кусочек кетайского дзена.
    Программа управления серво-приводами (хоть бы не аэс, хоть бы не аэс)

    ursus, 26 Апреля 2011

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