// ----------------------------------- // опрос и антидребезг для всех входов // вызывается по таймеру (1 ms) // ----------------------------------- void check_pins(void) { checkbuf(N_SIGNAL_DFK1,SIGNAL_DFK1,50); checkbuf(N_SIGNAL_DFK2,SIGNAL_DFK2,50); checkbuf(N_SIGNAL_DFK3,SIGNAL_DFK3,50); checkbuf(N_SIGNAL_DFK4,SIGNAL_DFK4,50); checkbuf(N_SIGNAL_DFK5,SIGNAL_DFK5,50); checkbuf(N_SIGNAL_UZD1OUT,SIGNAL_UZD1OUT,50); checkbuf(N_SIGNAL_UZD2OUT,SIGNAL_UZD2OUT,50); checkbuf(N_SIGNAL_B1OUT,SIGNAL_B1OUT,50); checkbuf(N_SIGNAL_B2OUT,SIGNAL_B2OUT,50); checkbuf(N_SIGNAL_IKOUT,SIGNAL_IKOUT,50); }
// // Consumer thread for testfile creation and verification. // void* consumer_fn(void* param) { workorder* wo = (workorder*) param; workqueue* q = wo->q; uint32_t shiftreg = PRBS23_INITIAL_VALUE; off_t progress = 0; long int found_corruption = 0; init_progress_display(wo->filesize * sizeof(uint32_t)); while (1) { wbuf* workbuf = (wbuf*) q->dequeue(); if (workbuf->buflen == 0) { q->release(workbuf); break; } if (wo->mode == VERIFY) { checkbuf(workbuf->buf, workbuf->buflen, shiftreg, found_corruption, progress, wo->bmode); } else { uint writtenbytes = 0; do { writtenbytes += write(wo->fd, workbuf->buf+writtenbytes, workbuf->buflen * sizeof(uint32_t) - writtenbytes); } while (writtenbytes < workbuf->buflen * sizeof(uint32_t)); } progress += (workbuf->buflen * sizeof(uint32_t)); q->release(workbuf); display_progress(progress); } return ((void*) found_corruption); }
/** * parse dns request */ int parse(char *buf,size_t len,SA *addr){ if(verbal>1) fprintf(stdout, "--------------in parse-------------\n"); checkbuf(buf,len); struct sockaddr_in tmpaddr = *((struct sockaddr_in*)addr); char* clientIP = inet_ntoa(tmpaddr.sin_addr); char name[MAXLINE] = {0}; char data[MAXLINE] = {0}; packet_t *packet = (packet_t *) buf; unsigned short requestID = packet->header.id; send_packet_t *sendPacket; parseRequestData(packet->data,name); fprintf(stdout,"name: %s\n",name); if(!strcmp(name,REQUESTNAME)){ int datalen=buildResponseData(packet->data,len-HEADER_LEN,data,clientIP); sendPacket=construct_response_packet(requestID,0,datalen,data,addr); checkbuf((char *)(sendPacket->data),datalen+HEADER_LEN); }else{ logWrite(clientIP,name,"0.0.0.0"); sendPacket=construct_response_packet(requestID,3,len-HEADER_LEN,packet->data,addr); } if(sendPacket!=NULL){ char *tmp = sendPacket->data->data; tmp+=len-HEADER_LEN; fprintf(stdout,"%d.%d.%d.%d\n",(int)(*(tmp+12)),(int)(*(tmp+13)),(int)(*(tmp+14)),(int)(*(tmp+15))); enqueue(DNS_stat->send_packets,sendPacket); } if(verbal>1) fprintf(stdout, "--------------in parse - done-------------\n"); return 0; }
void mergeset(aprioriset* res, aprioriset* a, aprioriset* b){ int i; char newval; for(i=0;i<a->length;i++){ res->value[i]=a->value[i]; } for(i=0;i<b->length;i++){ if(checkbuf(res->value, b->value[i], a->length)==0){ newval=b->value[i]; break; } } insertion(res->value, newval, b->length); }
void* getassociationrulefunc(void* thearg){ associationstruct* assstruct=(associationstruct*)thearg; aprioriset* left=assstruct->left, *right=assstruct->right; int k=0, l=0, m=0; for(k=0;k<right->length;k++){ if(checkbuf(left->value, right->value[k], left->length)){ assstruct->dest->left[l]=right->value[k]; l++; } else{ assstruct->dest->right[m]=right->value[k]; m++; } } assstruct->dest->support=((float)right->support)/((float)TRAN); assstruct->dest->confidence=((float)right->support)/((float)left->support); }
void makec1(aprioristruct* target, aprioristruct* data){ char itemlist[ITEM]; int i=0, j, k; aprioriset* nowdata; for(k=0;k<data->num;k++){ if(i==ITEM) break; nowdata=&data->valuelist[k]; for(j=0;j<nowdata->length;j++){ if(checkbuf(itemlist, nowdata->value[j], ITEM)==0){ if(i==0) itemlist[0]=nowdata->value[j]; else{ insertion(itemlist, nowdata->value[j], i); } i++; } } } for(j=0;j<i;j++){ initaprioriset(&nowdata, 1); nowdata->value[0]=itemlist[j]; add(target, nowdata, 1); } }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register int i, j; double r1, r2, x; char buf[100]; setup(); /* temp file is now open */ pi = 4.0 * atan(1.0); /*--------------------------------------------------------------*/ blenter(); for (i = 0; i < 30; i++) for (j = 0; j < 30; j++) { sprintf(buf, "%*.*f", i, j, pi); if (checkbuf(buf, i, j)) { fprintf(temp, "output conversion incorrect."); fprintf(temp, "%*.*f = '%s'", i, j, pi, buf); local_flag = FAILED; } r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } x = fabs(r1 - r2); if (x > ERR) { fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\terr value is %f\n", x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ blenter(); x = 1.0 - exp(-100.0); /* 1.0 - very small number */ sprintf(buf, "%f", x); r1 = atof(buf); if (r1 != 1.0) { fprintf(temp, "\tsprintf small # failed\n"); fprintf(temp, "\t printed '%s', expected 1.0\n", buf); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); for (i = 1; i < 200; i++) { x = 100.0 / (double)i; sprintf(buf, "%f", x); r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } /* * Order subtraction to produce a positive number. * Then subtrace "fudge" factor which should give us * a negative number, as the result fo subtraction should * always be smaller than the fudge factor. */ if (r1 > r2) x = r1 - r2 - 1e-10; else x = r2 - r1 - 1e-10; if (x > 0.0) { fprintf(temp, "\tx = %.15f = %e\n", x, x); fprintf(temp, "\titeration %d\n", i); fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\tcompare fails, %.15f vs %.15f\n", r1, r2); fprintf(temp, "\tbuf = '%s'\n", buf); x = r1 - r2; if (x == 0.0) fprintf(temp, "\tx == 0.0\n"); else fprintf(temp, "\tx != 0.0\n"); fprintf(temp, "\tx = %.15f = %e\n", x, x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ blenter(); for (i = -1; i > -200; i--) { x = 100.0 / (double)i; sprintf(buf, "%f", x); r1 = atof(buf); if (numin(buf, &r2)) { fprintf(temp, "\tnumin('%s') failed\n", buf); local_flag = FAILED; } /* * Same ordering of subtraction as above. */ if (r1 > r2) x = r1 - r2 - 1e-10; else x = r2 - r1 - 1e-10; if (x > 0.0) { fprintf(temp, "\tcompare fails, %f vs %f\n", r1, r2); fprintf(temp, "\tcompare fails, %.15f vs %.15f\n", r1, r2); x = r1 - r2; if (x == 0.0) fprintf(temp, "\tx == 0.0)\n"); else fprintf(temp, "\tx != 0.0\n"); fprintf(temp, "\tx = %.15f = %e\n", x, x); local_flag = FAILED; } if (local_flag == FAILED) break; } blexit(); /*--------------------------------------------------------------*/ tst_exit(); }
int main(int argc, char *argv[]) #endif { spcs_s_info_t ustats; struct timeval tout; fd_set readfds; char *errmessage, *ch; int c, period, prev; int count = 0, dflag = 0; int fd = fileno(stdin); errmessage = NULL; if (strcmp(argv[0], "sd_stats") != 0) errmessage = getenv("SD_STATS_USAGE"); if (errmessage == NULL) errmessage = gettext("Usage: sd_stats [-Mz] " "[-d delay_time] [-l logfile] [-r range]"); if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices, 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) { if (ustats) { /* if SPCS_S_ERROR */ spcs_s_report(ustats, stderr); spcs_s_ufree(&ustats); } (void) fprintf(stderr, gettext("cannot get maxfiles\n")); exit(1); } on_off = calloc(sdbc_max_devices, sizeof (int)); dual_on_off = calloc(sdbc_max_devices, sizeof (int)); updates_prev = calloc(sdbc_max_devices, sizeof (int)); samples = calloc(sdbc_max_devices, sizeof (int)); rate_prev = calloc(sdbc_max_devices, sizeof (double)); cs_cur = malloc(sizeof (_sd_stats_t) + (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); cs_prev = malloc(sizeof (_sd_stats_t) + (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); cs_persec = malloc(sizeof (_sd_stats_t) + (sdbc_max_devices - 1) * sizeof (_sd_shared_t)); range = malloc(100); if (!on_off || !dual_on_off || !updates_prev || !samples || !rate_prev || !cs_cur || !cs_prev || !cs_persec || !range) { (void) fprintf(stderr, gettext("no free memory\n")); exit(1); } *range = '\0'; while ((c = getopt(argc, argv, "DMzd:l:r:h")) != EOF) { prev = c; switch (c) { case 'd': delay = atoi(optarg); ch = optarg; while (*ch != '\0') { if (!isdigit(*ch)) errflg++; ch++; } break; case 'l': logfd = open(optarg, O_CREAT|O_WRONLY|O_TRUNC, 0644); break; case 'r': ch = optarg; while (*ch != '\0') { if ((!isdigit(*ch)) && (*ch != ',') && (*ch != ':')) errflg++; ch++; } if (errflg) break; range = realloc((char *)range, (strlen(range) + strlen(optarg) + 1) * sizeof (char)); if (had_r_option) (void) strcat(range, ","); (void) strcat(range, optarg); had_r_option = 1; break; case 'z': if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) { if (ustats) { spcs_s_report(ustats, stderr); spcs_s_ufree(&ustats); } } break; case 'D': dflag = 1; break; case 'M': mirror_sw = 1; break; case 'h': case '?': default : errflg++; break; } } if (errflg) { (void) fprintf(stderr, "%s\n", errmessage); exit(1); } else if (!prev) { if (argc > 1) { (void) fprintf(stderr, "%s\n", errmessage); exit(1); } } if (dflag) { exit(is_dirty()); } /* * A few curses routines to setup screen and tty interface */ (void) initscr(); (void) cbreak(); (void) noecho(); (void) nonl(); (void) erase(); (void) clear(); (void) refresh(); setup_ranges(range); /* * Set signal handle */ (void) sigset(SIGPIPE, leave); (void) sigset(SIGINT, leave); (void) sigset(SIGQUIT, leave); (void) signal(SIGFPE, leave); (void) signal(SIGSEGV, leave); USEC_INIT(); currtime = USEC_READ(); /* * Wait one second before reading the new values */ (void) sleep(1); /*CONSTCOND*/ while (1) { lasttime = currtime; currtime = USEC_READ(); /* * If less that 1 second, force it to one second */ if ((period = (currtime - lasttime) / 1000000) <= 0) period = 1; /* * Calculate new per/period values for statistics */ Elapsed_Time += period; /* * Display new statistics */ prheading(++count); if (mirror_sw) { if (dual_stats() < 0) mirror_sw = 0; } else if (toggle_total_sw) total_display(); else display_cache(); (void) move(0, 0); (void) refresh(); if (logfd > -1) wrefresh_file(stdscr, logfd); FD_ZERO(&readfds); FD_SET(fd, &readfds); tout.tv_sec = delay; for (;;) { tout.tv_usec = 0; if (select(fd + 1, &readfds, (fd_set *)0, (fd_set *)0, &tout) <= 0) break; if ((c = getch()) == EOF) { (void) sleep(delay); break; } checkbuf(c); tout.tv_sec = 0; } (void) erase(); } #pragma error_messages(off, E_STATEMENT_NOT_REACHED) return (0); #pragma error_messages(default, E_STATEMENT_NOT_REACHED) }
int main(int argc, char **argv) { int rval; char c; int n, i, cc; argc--, argv++; if (argc > 0) { debug = fopen(*argv, "w"); if (debug == 0) exit(1); (void)setbuf(debug, (char *)0); } top: errno = 0; rval = 0; if (read(STDIN_FILENO, &c, 1) != 1) exit(0); switch (c) { case 'O': if (tape >= 0) (void) close(tape); getstring(device); getstring(mode); DEBUG2("rmtd: O %s %s\n", device, mode); /* * XXX the rmt protocol does not provide a means to * specify the permission bits; allow rw for everyone, * as modified by the users umask */ tape = open(device, atoi(mode), 0666); if (tape < 0) goto ioerror; goto respond; case 'C': DEBUG("rmtd: C\n"); getstring(device); /* discard */ if (close(tape) < 0) goto ioerror; tape = -1; goto respond; case 'L': getstring(count); getstring(pos); DEBUG2("rmtd: L %s %s\n", count, pos); rval = lseek(tape, (off_t)strtoll(count, NULL, 10), atoi(pos)); if (rval < 0) goto ioerror; goto respond; case 'W': getstring(count); n = atoi(count); DEBUG1("rmtd: W %s\n", count); record = checkbuf(record, n); for (i = 0; i < n; i += cc) { cc = read(STDIN_FILENO, &record[i], n - i); if (cc <= 0) { DEBUG("rmtd: premature eof\n"); exit(2); } } rval = write(tape, record, n); if (rval < 0) goto ioerror; goto respond; case 'R': getstring(count); DEBUG1("rmtd: R %s\n", count); n = atoi(count); record = checkbuf(record, n); rval = read(tape, record, n); if (rval < 0) goto ioerror; (void)sprintf(resp, "A%d\n", rval); (void)write(STDOUT_FILENO, resp, strlen(resp)); (void)write(STDOUT_FILENO, record, rval); goto top; case 'I': getstring(op); getstring(count); DEBUG2("rmtd: I %s %s\n", op, count); { struct mtop mtop; mtop.mt_op = atoi(op); mtop.mt_count = atoi(count); if (ioctl(tape, MTIOCTOP, (char *)&mtop) < 0) goto ioerror; rval = mtop.mt_count; } goto respond; case 'S': /* status */ DEBUG("rmtd: S\n"); { struct mtget mtget; if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0) goto ioerror; rval = sizeof (mtget); if (rval > 24) /* original mtget structure size */ rval = 24; (void)sprintf(resp, "A%d\n", rval); (void)write(STDOUT_FILENO, resp, strlen(resp)); (void)write(STDOUT_FILENO, (char *)&mtget, rval); goto top; } case 'V': /* version */ getstring(op); DEBUG1("rmtd: V %s\n", op); rval = 2; goto respond; default: DEBUG1("rmtd: garbage command %c\n", c); exit(3); } respond: DEBUG1("rmtd: A %d\n", rval); (void)sprintf(resp, "A%d\n", rval); (void)write(STDOUT_FILENO, resp, strlen(resp)); goto top; ioerror: error(errno); goto top; }