- 1
- 2
- 3
- 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];
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+140
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];
пересчет платежей в ТЗЛП
+130
#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.
+142
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
кришну вроде не вызывают. код странным образом напоминает индусский...
+142
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;
кусочек кетайского дзена.
Программа управления серво-приводами (хоть бы не аэс, хоть бы не аэс)
+142
if(n==0) m[n][i][j][k+1]=1.5;
if(n==1) m[n][i][j][k+1]=1.0;
if(n==2) m[n][i][j][k+1]=0.0;
if(n==3) m[n][i][j][k+1]=0.4;
долго не мог заметить
+143
for (int i = 0; i < ptr->len; i++)
{
*(((unsigned char *) ptr->payload) + i) = (unsigned char) toupper(*(((unsigned char *) ptr->payload) + i));
}
Перевод символов, находящихся в строке по адресу ptr->payload (типа void *) в верхний регистр.
+145
//Determine padding for use in allocating new memory
int padding = 0;
while ( (width * 3 + padding) % 4 != 0) padding++;
http://www.cplusplus.com/forum/windows/6353/
Ещё одна история о том, как людям не дано запомнить двоичную природу данных.
Если что, вот корректный шаблон на D:
int packed(int alignment)(int location) {
static assert(alignment == 2 | alignment == 4 | alignment == 8);
const badEnd = alignment - 1; //0b11, 0b111, 0b1111
return location & badEnd ? (location & ~badEnd) + alignment : location;
}
+132
int cont[15];
bool stop_access = false;
struct cel container[MAX_SIZE];
struct termios savetty;
struct termios tty;
pthread_t thread[100];
pthread_mutexattr_t muattr;
pthread_mutex_t count_mutex;
int icn=0;//Number elements in container
static int x;
static int y;
void* stack;
pthread_mutex_unlock(&count_mutex);
sleep(1);
};
return (void*)1;
};
void* main_thread(void *arg){
while(true){
sleep(1);
char ic=getchar();
if(ic=='\n'){
printf("Thread\tnumber elements\n");
for(int i=0;i<=x;i++)
pthread_cancel(thread[i]);
for(int i=0;i<=x;i++){
printf("%d ",i);
int cn=0;
for(int j=0;j<=icn;j++){
if(container[j].thrnm==i){ cn++; };
};
printf("\t%d\n",cn);
};
printf("container number element %d\n",icn);
exit(0);
};
};
};
int main(int argc, char * argv[])
{
icn=0;
if(argc<2){printf("1 arg n number of threads, 2 argument maximum number element in container");exit(0);};
x=atoi(argv[1]);
y=atoi(argv[2]);
if(x>64){printf("Число потоков должно быть меньше 64\n");exit(0);}
printf("x %d y %d\n",x,y);
//mutex initialization
int ret;
ret = pthread_mutexattr_init(&muattr);
//switch the keyboard to noncanonical mode
pid_t pt=tcgetsid(0);
// char *var=ctermid (NULL);
printf("pid %d\n",pt);
tcgetattr (0, &tty);
savetty = tty;
tty.c_lflag &= ~(ICANON);
tty.c_cc[VMIN] = 1;
tcsetattr (0, TCSAFLUSH, &tty);
pthread_t mthr;
pthread_attr_t mattr;
pthread_attr_init(&mattr);
pthread_attr_setdetachstate(&mattr,PTHREAD_CREATE_DETACHED);
int mres = pthread_create(&mthr, &mattr, main_thread, NULL);
if (mres == 0) {
printf("Creating main thread\n");
sleep(0.7);
} else {
perror("Creating the main first thread");
return EXIT_FAILURE;
}
for(int i=0;i<=x;i++){
int id1, id2, result;
id1 = 1;
pthread_attr_t attr;
pthread_attr_init(&attr);
// отсоединенный поток - не ждем его возврата
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
result = pthread_create(&thread[i], &attr, thread_func, &i);
if (result == 0) {
printf("Creating thread %d\n",i);
sleep(1);
} else {
perror("Creating the first thread");
+147
void
syslog(int pri, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsyslog(pri, fmt, ap);
va_end(ap);
}
......................................
void
vsyslog(int pri, const char *fmt, va_list ap)
{
vsyslog_r(pri, &sdata, fmt, ap);
}
....................................
void
vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap)
{
int cnt;
char ch, *p, *t;
time_t now;
int fd, saved_errno, error;
#define TBUF_LEN 2048
#define FMT_LEN 1024
char *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
int tbuf_left, fmt_left, prlen;
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
/* Check for invalid bits. */
if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
if (data == &sdata) {
syslog(INTERNALLOG,
"syslog: unknown facility/priority: %x", pri);
} else {
syslog_r(INTERNALLOG, data,
"syslog_r: unknown facility/priority: %x", pri);
}
pri &= LOG_PRIMASK|LOG_FACMASK;
}
.......................
}
......................
Из исходников Bioninc - Android libc.
В реализации сислога, в случае ошибки, вызывается syslog
+146
#define TRUE (rand() > 0.1 ? TRUE : FALSE) // happy debugging losers
понедельничный неговнокод "Где здесь Си" = )
приятного дебага на неделе, коллеги ))