void startc(void) { unsigned long * start = 0; zeromem((char*)c__bss_start,(char*)c__end); zeromem((char*)c__sbss_start,(char*)c__sbss_end); /* Determine if we need to copy initialized data section in or out */ if(savedata) /* If non-zero, we need to restore to the original init data */ { initdata((char*)c_bsavedata,(char*)c_esavedata,(char*)c_bdata); } else /* Copy the init data off before we start */ { savedata = (char*)c_bsavedata; initdata((char*)c_bdata,(char*)c_edata,(char*)c_bsavedata); } while (start < (unsigned long *)0x2000) { *start++ = 0x48000000; } /* Do any platform or board initialization */ // C_Entry(); main(); while (1) {} exit(); }
// Called upon door startup, to initialize the door depending on the doorkit's needs. void startup(int argc, char *argv[]) { char* p; p=getenv("SBBSNODE"); if(p) strcpy(node_dir,p); else { printf("\nUnable to run door.\n"); printf("- If you are trying to run door in local mode, this cannot be done with the\n"); printf(" Synchronet XTRN.DAT version. You must run the door through the BBS, or use\n"); printf(" the Door32 version in local mode instead.\n"); printf("- If you are running the door remotely, be sure it is configured as a 32bit\n door in SCFG. See door's documentation!\n"); exit(0); } for ( short n = 1; n < argc; n++ ) { if ( strcmpi(argv[n], "-window") == 0 || strcmpi(argv[n], "/window") == 0 ) nNoLocalWindow = 0; } initdata(); if ( nNoLocalWindow == 1 ) FreeConsole(); sec_warn = 270; sec_timeout = 300; }
static void allclear_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("allclear_button_callback: %s was pressed\n", data); initdata(); gtk_entry_set_text(GTK_ENTRY(text_entry), ""); }
TrafficSetting::TrafficSetting(QWidget *parent) : QWidget(parent),mLogmanager(NULL),uimanager(NULL), ui(new Ui::TrafficSetting) { ui->setupUi(this); uuid = PLUGIN_UUID; flag = false; mSettings = NULL; mSettings = TrafficSetting::sHandler->getSettings(); uimanager = TrafficSetting::sHandler->getUiManager(); mLogmanager = TrafficSetting::sHandler->getLogManager(); SET_STYLE_PROPERTY(FLEX_BUTTON,ui->pushButton); SET_STYLE_PROPERTY(FLEX_BUTTON,ui->pushButton_2); progressindicator = ui->widget; hourValidator = new QIntValidator(0,11,this); minuteValidator = new QIntValidator(0,59, this); monthLimitValidator = new QIntValidator(0,1000000, this); ui->lineEdit->setValidator(monthLimitValidator); ui->lineEdit_2->setValidator(hourValidator); ui->lineEdit_3->setValidator(minuteValidator); ui->checkBox->setChecked(true); ui->checkBox->setHidden(true); tmp = ""; NewControlOption = "No Limit"; NewMonthlyLimit = "0"; RestartHour = "0"; RestartMinute = "0"; RestartDay = "1"; initdata(); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(apply())); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(startextraturn())); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(startAnimation())); connect(ui->pushButton_2, SIGNAL(clicked()), this, SIGNAL(returnbtclicked())); // connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(stopAnimation())); connect(ui->checkBox,SIGNAL(clicked()), this, SLOT(checkboxchange())); connect(ui->checkBox, SIGNAL(clicked()), this, SLOT(modifyslot())); connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(modifyslot())); connect(ui->comboBox_2, SIGNAL(currentIndexChanged(int)), this, SLOT(modifyslot())); connect(ui->comboBox_3, SIGNAL(currentIndexChanged(int)), this, SLOT(modifyslot())); connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(modifyslot())); connect(ui->lineEdit_2, SIGNAL(textChanged(QString)), this, SLOT(modifyslot())); connect(ui->lineEdit_3, SIGNAL(textChanged(QString)), this, SLOT(modifyslot())); }
int main(int argc,char *argv[]) { int iter; MPI_Init(&argc, &argv); initdata(); // MPI_Barrier(MPI_COMM_WORLD); write_frame(0); MPI_Barrier(MPI_COMM_WORLD); for (iter = 1; iter <= nsteps; iter++) { exchange_ghost_cells(); //MPI_Barrier(MPI_COMM_WORLD); update(); //MPI_Barrier(MPI_COMM_WORLD); // write_frame(iter); //MPI_Barrier(MPI_COMM_WORLD); } MPI_Finalize(); }
void main(int argc, char **argv) { int ro; char *file, *mount; mount = "/n/brzr"; ro = 0; file = "/dev/flash/fs"; ARGBEGIN { case 'D': chatty9p++; break; case 'r': ro++; break; case 'n': nsects = argval(ARGF()); break; case 'z': sectsize = argval(ARGF()); break; case 'f': file = ARGF(); break; case 'm': mount = ARGF(); break; default: usage(); } ARGEND if(argc != 0) usage(); initdata(file, 0); sectbuff = emalloc9p(sectsize); einit(); loadfs(ro); serve(mount); exits(nil); }
void opendata(char *datafile,struct data *d) { /* Initialize data defaults */ initdata(d); /* Check status of data file */ if (stat(datafile,&d->buf) == -1) { fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__); fprintf(stderr," Unable to access %s\n",datafile); fprintf(stderr," Aborting ...\n\n"); fflush(stderr); exit(1); } /* Check to see if input file can be opened */ if ((d->fp=fopen(datafile,"r")) == NULL) { fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__); fprintf(stderr," Unable to open %s\n\n",datafile); fprintf(stderr," Aborting ...\n\n"); fflush(stderr); exit(1); } /* Exit if input file size is less than the VNMR file header size */ if (d->buf.st_size < sizeof(d->fh)) { fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__); fprintf(stderr," Incomplete file header (?)\n"); fprintf(stderr," Aborting ...\n\n"); fflush(stderr); exit(1); } /* Copy filename */ if ((d->file = (char *)malloc((strlen(datafile)+1)*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); strcpy(d->file,datafile); /* Get file header */ getdfh(d); #ifdef DEBUG fprintf(stdout,"\n%s: %s()\n",__FILE__,__FUNCTION__); fprintf(stdout," %s contains %d bytes\n",d->file,(int)d->buf.st_size); fflush(stdout); #endif }
void main(int argc, char **argv) { ulong i; int m, n; char *file; uchar hdr[MAXHDR]; ARGBEGIN { case 'n': nsects = argval(ARGF()); break; case 'z': sectsize = argval(ARGF()); break; default: usage(); } ARGEND if(argc != 1) usage(); file = argv[0]; sectbuff = emalloc9p(sectsize); initdata(file, 1); memmove(hdr, magic, MAGSIZE); m = putc3(&hdr[MAGSIZE], 0); n = putc3(&hdr[MAGSIZE + m], 0); clearsect(0); writedata(0, 0, hdr, MAGSIZE + m + n, 0); for(i = 1; i < nsects - 1; i++) clearsect(i); m = putc3(&hdr[MAGSIZE], 1); n = putc3(&hdr[MAGSIZE + m], 0); clearsect(nsects - 1); writedata(0, nsects - 1, hdr, MAGSIZE + m + n, 0); }
int main(int argc, char *argv[]) { FILE *fp = stdin; static char *buf = NULL; static size_t size = 0; int label, workingtime = 0; const unsigned int procrastination = getlabelid("!*"); const unsigned int work = getlabelid("+"); unsigned int payed = getlabelid(""); ARGBEGIN { case 'c': columns = atoi(EARGF(usage())); if (columns > LENGTH(convert)) columns = LENGTH(convert); break; case 'e': options.efc = atoi(EARGF(usage())); break; case 'd': options.flags |= F_DAY_STAT; break; case 'm': options.flags |= F_MONTH_STAT; break; case 'M': options.mph = atoi(EARGF(usage())); break; case 't': options.flags |= F_PRINT_TASK; break; case 'w': options.flags |= F_WEEK_STAT; break; case 'W': payed = getlabelid(EARGF(usage())); break; default: usage(); } ARGEND; initdata(); while (getline(&buf, &size, fp) > 0) { char * time; struct interval interval; if ((time = istask(buf, &interval))) { const int timeint = interval.stop - interval.start; label = getlabelid(buf); char * tmp = strchr(time, ')'); if (!tmp) continue; tmp[0] = '\0'; if (options.flags & F_PRINT_TASK) { printf("%-2s(%s", buf, time); if (tmp[-1] == '-') printf("%s", sec2str(interval.stop)); printf(") %.2f:%s", (timeint) / 3600.0, tmp + 1); } set(timeint, label); set(timeint, 0); if (strchr(buf, '!')) set(timeint, procrastination); if (convert[label].mark == '+') set(timeint, work); if (label == payed) workingtime += timeint; continue; } int rd; if ((rd = getdayid(buf)) >= 0) { if (options.flags & F_DAY_STAT) printdaystat(); if (options.flags & F_PRINT_TASK) printf("%s", buf); memset(data.day, 0, LENGTH(convert) * sizeof(int)); continue; } if (strstr(buf, WEEK)) { if (options.flags & F_WEEK_STAT) printweekstat(); memset(data.week, 0, LENGTH(convert) * sizeof(int)); continue; } if (isnewmonth(buf)) { if (options.flags & F_MONTH_STAT) printmonthstat(); memset(data.month, 0, LENGTH(convert) * sizeof(int)); continue; } if (!strncmp(buf, PAY_MARK, strlen(PAY_MARK))) { printtopay(workingtime / 3600.0); workingtime = 0; } } printdaystat(); printf("\n"); printweekstat(); printf("\n"); printmonthstat(); printf("\n"); printyearstat(); printf("\n"); printtopay(workingtime / 3600.0); freedata(); free(buf); return EXIT_SUCCESS; }
int main(int argc, char** argv) { MPI_Init(&argc, &argv); double start_time, end_time; int num_procs, rank; // Iterators int i, j, n; // Stores the current time step int ts = 0; // Stores the initial data double array[XDIM][YDIM]; // Stores data from the intermediate calculations // This array excludes the border values double receive_array[XDIM - 2][YDIM - 2]; // Stores the final values after a calculation before saving to file double final_array[XDIM][YDIM]; // Load in the number of processors MPI_Comm_size(MPI_COMM_WORLD, &num_procs); // Load in the rank of this processor MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Calculate the number of processors that will complete work // We remove the master process from this count as it will not // Be performing the same calculations as the rest of the processes int num_workers = num_procs; // Calculate how many rows each process will be calculating for // We subtract 2 as these are the boundary rows, // for which we will not be performing any calculations int num_rows = (XDIM - 2) / num_workers; // Calculate how many rows are not evenly divisible (we will give these to the last node) int leftover_rows = (XDIM - 2) % num_workers; // If this is the master process if(rank == MASTER) { // Initialise the array initdata(XDIM, YDIM, &array[0][0]); printf("%d rows leftover\n", leftover_rows); /* Output the initial array for testing purposes printf("Array initialized to:\n"); for(i = 0; i < XDIM; i++) { for(j = 0; j < YDIM; j++) { printf("%f ", array[i][j]); } printf("\n"); }*/ // Initialise the borders of final_array using our initial data for(i = 0; i < XDIM; i++) { final_array[i][0] = array[i][0]; final_array[i][YDIM - 1] = array[i][YDIM - 1]; } for(j = 0; j < YDIM; j++) { final_array[0][j] = array[0][j]; final_array[XDIM - 1][j] = array[XDIM - 1][j]; } } // The size of array each node will receive int scatter_sizes[num_workers]; // The displacement of elements being sent from the root node int scatter_displs[num_workers]; // The size of the array each node will send back int gather_sizes[num_workers]; // The displacement of the data being sent to the root node int gather_displs[num_workers]; // Calculate the parameters for scatter for(n = 0; n < num_workers; n++) { scatter_displs[n] = n * (num_rows * YDIM); scatter_sizes[n] = (num_rows + 2) * YDIM; } // Give the last worker the left over rows scatter_sizes[num_workers - 1] += leftover_rows * YDIM; int n_array_size, n_ghost_elements, n_rows; int current_displ = 0; // Calculate the parameters for gather for(n = 0; n < num_workers; n++) { // Get the array size that was provided to this worker by the root node n_array_size = scatter_sizes[n]; // Work out the number of rows in the original data n_rows = n_array_size / YDIM; // Calculate the number of ghost elements in the array // We have two ghost cells per row (left and right most columns) // And we have a row above and below which are all ghost cells // Subtract 4 cells, as we count 4 of the cells twice in the stated calculation n_ghost_elements = (n_rows * 2) + (YDIM * 2) - 4; // The size of the array we will be sending back to the root node // Is the original size - the ghost elements around the outside gather_sizes[n] = n_array_size - n_ghost_elements; // The displacements of the data from each of the ranks on the root node gather_displs[n] = current_displ; current_displ += gather_sizes[n]; /*if(rank == MASTER) { printf("Proc: %d, Gather size: %d, Scatter size: %d, Gather displ: %d\n", n, gather_sizes[n], scatter_sizes[n], gather_displs[n]); }*/ } // Store the size of the array we will be receiving from root int my_array_size = scatter_sizes[rank]; // Calculate the number of rows we will receive int row_count = my_array_size / YDIM; // Stores the elements we receive double elements[my_array_size]; // Stores the results of our calculation double updated_elements[gather_sizes[rank]]; // Start the timer on the root node when all processes reach this point MPI_Barrier(MPI_COMM_WORLD); if(rank == MASTER) start_time = MPI_Wtime(); // Spread out the data from the root node to the slave nodes (this includes the root) MPI_Scatterv(&array[0][0], scatter_sizes, scatter_displs, MPI_DOUBLE, elements, my_array_size, MPI_DOUBLE, MASTER, MPI_COMM_WORLD); // Update once outside the loop to avoid unnecessary swapping and data transfer on the last iteration update(row_count, YDIM, elements, updated_elements); ts++; // Perform the calculations for the required number of time steps while(ts < params.nts) { // If the program is set to save to a new file at each timestep if(SAVE_EACH_TIMESTEP) { // Gather all of the calculated data at the root node MPI_Gatherv(updated_elements, gather_sizes[rank], MPI_DOUBLE, receive_array, gather_sizes, gather_displs, MPI_DOUBLE, MASTER, MPI_COMM_WORLD); if(rank == MASTER) { // Place the un-bordered array inside the array with the border data placeinside(XDIM - 2, YDIM - 2, &final_array[0][0], &receive_array[0][0]); // Save the data to a file prtdata(XDIM, YDIM, ts, &final_array[0][0], "final_data"); } } // Swap updated_elements in to elements for(i = 0; i < row_count - 2; i++) { for(j = 0; j < YDIM - 2; j++) { elements[(i + 1) * YDIM + (j + 1)] = updated_elements[i * (YDIM - 2) + j]; } } // Send the updated ghost cells to the above/below processors // First send all of the data to the processors above itself // If the rank is greater than zero then we have data to send to the above process MPI_Status status; if(rank > 0 && rank < num_procs - 1) { MPI_Sendrecv(&updated_elements, YDIM - 2, MPI_DOUBLE, rank - 1, 0, &elements[YDIM * (row_count - 1) + 1], YDIM - 2, MPI_DOUBLE, rank + 1, 0, MPI_COMM_WORLD, &status); } else if(rank == 0) { MPI_Recv(&elements[YDIM * (row_count - 1) + 1], YDIM - 2, MPI_DOUBLE, rank + 1, 0, MPI_COMM_WORLD, &status); } else if(rank == num_procs - 1) { MPI_Send(&updated_elements, YDIM - 2, MPI_DOUBLE, rank - 1, 0, MPI_COMM_WORLD); } // Now send all of the data to the processors below // The start of our index for the send buffer is the original row count (including ghost cells) // minus 2 because updated_elements does not contain ghost cells, minus another 1 to place us at the // start of the last row int send_index = (row_count - (2 + 1)) * (YDIM - 2); if(rank > 0 && rank < num_procs - 1) { MPI_Sendrecv(&updated_elements[send_index], YDIM - 2, MPI_DOUBLE, rank + 1, 1, &elements[1], YDIM - 2, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD, &status); } else if(rank == 0) { MPI_Send(&updated_elements[send_index], YDIM - 2, MPI_DOUBLE, rank + 1, 1, MPI_COMM_WORLD); } else if(rank == num_procs - 1) { MPI_Recv(&elements[1], YDIM - 2, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD, &status); } // Update the data by another time step update(row_count, YDIM, elements, updated_elements); ts++; } // Combine the data that all processors have calculated back in to a single array MPI_Gatherv(updated_elements, gather_sizes[rank], MPI_DOUBLE, receive_array, gather_sizes, gather_displs, MPI_DOUBLE, MASTER, MPI_COMM_WORLD); if(rank == MASTER) { // Store the end time here to discount the time taken to save to file end_time = MPI_Wtime(); // Place the un-bordered array inside the array with the border data placeinside(XDIM - 2, YDIM - 2, &final_array[0][0], &receive_array[0][0]); // Save the data to a file prtdata(XDIM, YDIM, ts, &final_array[0][0], "final_data"); printf("Time taken to calculate: %.3fs\n", end_time - start_time); /*printf("\nOutputting final array: \n"); for(i = 0; i < XDIM; i++) { for(j = 0; j < YDIM; j++) { printf("%.1f ", final_array[i][j]); } printf("\n"); }*/ } MPI_Finalize(); return 0; }
int main(int argc, char **argv) { char str[81],compiler[32],*p; int i,file; FILE *stream; node_dir[0]=0; for(i=1;i<argc;i++) if(!stricmp(argv[i],"/L")) logit=1; else if(!stricmp(argv[i],"/T")) tutor=2; else if(!stricmp(argv[i],"/S")) tutor=1; else strcpy(node_dir,argv[i]); p=getenv("SBBSNODE"); if(!node_dir[0] && p) strcpy(node_dir,p); if(!node_dir[0]) { /* node directory not specified */ printf("usage: sbj <node directory> [/options]\r\n"); printf("\r\noptions: L = log wins/losses for each day\r\n"); getch(); return(1); } if(node_dir[strlen(node_dir)-1]!='\\' && node_dir[strlen(node_dir)-1]!='/') /* make sure node_dir ends in '\' */ strcat(node_dir,"/"); initdata(); /* read XTRN.DAT and more */ credits=user_cdt; total_nodes=sys_nodes; remove("debug.log"); if((file=nopen("sbj.cfg",O_RDONLY))==-1) { /* open config file */ bputs("Error opening sbj.cfg\r\n"); pause(); return(1); } if((stream=fdopen(file,"rb"))==NULL) { /* convert to stream */ bputs("Error converting sbj.cfg handle to stream\r\n"); pause(); return(1); } fgets(str,81,stream); /* number of decks in shoe */ total_decks=sys_decks=atoi(str); fgets(str,81,stream); /* min bet (in k) */ min_bet=atoi(str); fgets(str,81,stream); /* max bet (in k) */ max_bet=atoi(str); fgets(str,81,stream); /* default bet (in k) */ ibet=atoi(str); fclose(stream); if(!total_decks || total_decks>MAX_DECKS) { bputs("Invalid number of decks in sbj.cfg\r\n"); pause(); return(1); } if(!max_bet) { bputs("Invalid max bet in sbj.cfg\r\n"); pause(); return(1); } if(min_bet>max_bet) { bputs("Invalid min bet in sbj.cfg\r\n"); pause(); return(1); } if(ibet>max_bet || ibet<min_bet) { bputs("Invalid default bet in sbj.cfg\r\n"); pause(); return(1); } if(!fexist("card.dab")) { cur_card=0; dc=0; memset(dealer,0,sizeof(dealer)); memset(card,0,sizeof(card)); putcarddat(); } else { getcarddat(); if(total_decks!=sys_decks) { remove("card.dab"); total_decks=sys_decks; putcarddat(); } } if(!fexist("game.dab")) /* File's not there */ create_gamedab(); open_gamedab(); getgamedat(0); if(total_nodes!=sys_nodes) { /* total nodes changed */ close(gamedab); total_nodes=sys_nodes; create_gamedab(); open_gamedab(); } srand((unsigned)time(NULL)); #ifdef __16BIT__ while(_bios_keybrd(1)) /* clear input buffer */ _bios_keybrd(0); #endif putchar(5); /* ctrl-e */ mswait(500); if(keyhit()) { #ifdef __16BIT__ while(_bios_keybrd(1)) _bios_keybrd(0); #else getkey(0); #endif bputs("\r\n\1r\1h\1i*** ATTENTION ***\1n\1h\r\n"); bputs("\r\nSynchronet Blackjack uses Ctrl-E (ENQ) for the 'club' card " "symbol."); bputs("\r\nYour terminal responded to this control character with an " "answerback string."); bputs("\r\nYou will need to disable all Ctrl-E (ENQ) answerback " "strings (Including \r\nCompuserve Quick B transfers) if you wish to " "toggle card symbols on.\r\n\r\n"); symbols=0; pause(); } getgamedat(1); node[node_num-1]=0; putgamedat(); /* Override default mnemonic colors */ mnehigh=RED|HIGH; mnelow=CYAN|HIGH; /* Override default inactivity timeout values */ sec_warn=120; sec_timeout=180; COMPILER_DESC(compiler); #define SBJ_INDENT " " while(1) { cls(); sprintf(str,"\1n\1h\1cSynchronet \1rBlackjack! \1cv3.20 for %s\r\n" ,PLATFORM_DESC); center(str); sprintf(str,"\1w(XSDK v%s %s %s)\r\n\r\n" ,xsdk_ver,compiler,__DATE__); center(str); aborted=0; mnemonics(SBJ_INDENT"~Instructions\r\n"); mnemonics(SBJ_INDENT"~Join/Begin Game\r\n"); mnemonics(SBJ_INDENT"~List Players\r\n"); mnemonics(SBJ_INDENT"~Rules of the Game\r\n"); mnemonics(SBJ_INDENT"~Toggle Card Symbols\r\n"); sprintf(str,SBJ_INDENT"~Quit to %s\r\n",sys_name); mnemonics(str); nodesync(); bprintf("\1_\r\n"SBJ_INDENT"\1y\1hWhich: \1n"); switch(getkeys("IJBLRTQ|!",0)) { #if DEBUG case '!': if(!com_port) autoplay=1; break; case '|': debug(); break; #endif case 'I': cls(); printfile("sbj.msg"); break; case 'L': listplayers(); bprintf(ShoeStatus,cur_card,total_decks*52); break; case 'R': bprintf("\1n\1c\r\nMinimum bet: \1h%uk",min_bet); bprintf("\1n\1c\r\nMaximum bet: \1h%uk\r\n",max_bet); bprintf("\1w\1h\r\nCard decks in shoe: \1h%u\r\n",sys_decks); break; case 'T': symbols=!symbols; bprintf("\1_\1w\r\nCard symbols now: %s\r\n",symbols ? "ON":"OFF"); break; case 'Q': exit(0); case 'J': case 'B': sec_warn=60; /* Override default inactivity timeout values */ sec_timeout=90; play(); sec_warn=120; sec_timeout=180; break; } } }
int main(int argc, char *argv[]) { FILE *fp = stdin; static char *buf = NULL; static size_t size = 0; int label, day = 0; ARGBEGIN { case 'b': options.flags |= F_PRINT_BOTH; break; case 'c': columns = atoi(EARGF(usage())); break; case 'h': options.inhour = atoi(EARGF(usage())); break; case 'm': options.inmin = atoi(EARGF(usage())); break; case 'n': options.flags |= F_PRINT_NUM; break; case 's': options.insec = atoi(EARGF(usage())); break; case 't': options.flags |= F_PRINT_TIME; break; default: usage(); } ARGEND; initdata(); while (getline(&buf, &size, fp) > 0) { char * time; struct interval interval; if ((time = istask(buf, &interval))) { label = getlabelid(buf); set(day, &interval, label); continue; } int rd; if ((rd = getdayid(buf)) >= 0) { day = rd; memset(data + day * arrsize * LENGTH(convert), 0, arrsize * LENGTH(convert) * sizeof(unsigned short)); daycounter[day] = 1; } } initcolumnsinterval(); maketablehdr(); if (options.flags & (F_PRINT_NUM | F_PRINT_BOTH)) maketable(label, numtable); if ((options.flags & (F_PRINT_NUM | F_PRINT_BOTH)) ^ F_PRINT_NUM) maketable(label, marktable); free(data); free(buf); return EXIT_SUCCESS; }
static void swap_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("swap_button_callback: %s was pressed\n", data); if (current_state == Error) return; GCALCTRACE(); reset_input = true; const char *string = gtk_entry_get_text(GTK_ENTRY(text_entry)); errno = 0; double x = strtod(string, NULL); if (isnan(x)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); return; } else if (isinf(x)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else if (errno != 0) { GCALCTRACE(); initdata(Error); char buf[BUFSIZ]; sprintf(buf, "errno=%d", errno); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); return; } GCALCTRACE(); if (isnan(accumulator)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); return; } else if (isinf(accumulator)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else { GCALCTRACE(); char buf[BUFSIZ]; sprintf(buf, "%.14g", accumulator); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } accumulator = x; }
/*tga2gif(ac, av) int ac; char **av;*/ tga2gif(char *filename) { int i, w, h, c, r, g, b; long total; char file[80], /* root of file name */ infile[80], /* input file name */ outfile[80], /* gif file name */ palfile[80]; /* palette file name */ int (*grab_a_pix)(), get_pix(), get_pix_fs(); // strcpy(name, strrchr(filename[0], PATH_SEPARATOR)+1); /* get rid of the path */ // *strchr(name, '.') = 0; /* get rid of the .exe */ // strlwr(name); /* gimmee lower case */ palfile[0] = 0; /* NULL string */ initdata(); grab_a_pix = get_pix; /* default, non dithered function for gif */ /*if(ac < 2) usage(name);*/ infile[0] = '\0'; //for(i=1; i<ac; i++) { /* loop through command line args */ strlwr(filename); strcpy(file, filename); strcpy(infile, filename); strcpy(outfile, filename); strcat(infile, ".tga"); strcat(outfile, ".gif"); //} /* end of i loop through args */ /* Open image file for reading */ infp = fopen(infile, READ_MODE); if(!infp) { fprintf(stderr, "Error opening file %s for input.\n", infile); exit(1); } /* Read targa header. 3rd byte should be 2 signifying a type 2 targa file. Get resolution. */ my_getc(infp); my_getc(infp); if(my_getc(infp) != 2) { fprintf(stderr, "Sorry, but this program only works for type 2 Targa files.\n"); exit(1); } for(i=3; i<12; i++) { my_getc(infp); } /* get res */ xres = my_getc(infp); xres += my_getc(infp)<<8; yres = my_getc(infp); yres += my_getc(infp)<<8; /* get last two bytes of the header */ my_getc(infp); my_getc(infp); printf("image size : %d x %d\n", xres, yres); /* Put width of image in w */ w = xres; width = w; /* Put height of image in h */ h = yres; height = h; /* read in image and build tree if we need to */ if(method==POP || method==MEDIAN_BOX) { printf("Building tree.\n total colors = "); total_pixels = total_colors; total = (long)w * (long)h; while(total > 0) { /* Read color run length */ c = 1; if(c==0) c = 1024; /* read an rgb triple */ b = my_getc(infp); g = my_getc(infp); r = my_getc(infp); add_color(r>>2, g>>2, b>>2, c); /* add to tree */ total -= c; if(total_pixels != total_colors) { if((total_colors % (PRINT_STEP<<2)) == 0) printf("%8ld\b\b\b\b\b\b\b\b", total_colors); total_pixels = total_colors; } } printf("%8ld\b\b\b\b\b\b\b\b", total_colors); printf("\n"); }
static void unaryop_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("unaryop_button_callback: %s was pressed\n", data); if (current_state == Error) return; GCALCTRACE(); reset_input = true; const char *string = gtk_entry_get_text(GTK_ENTRY(text_entry)); errno = 0; double x = strtod(string, NULL); if (isnan(x)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (isinf(x)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else if (errno != 0) { GCALCTRACE(); initdata(Error); char buf[BUFSIZ]; sprintf(buf, "errno=%d", errno); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } else { GCALCTRACE(); for (int op = 0; unaryops[op].name != NULL; ++op) { if (strcmp(data, unaryops[op].name) != 0) continue; GCALCTRACE(); double y = unaryops[op].handler(x); if (isnan(y)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (isinf(y)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else { GCALCTRACE(); char buf[BUFSIZ]; sprintf(buf, "%.14g", y); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } GCALCTRACE(); return; } // should never get here GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), ""); } return; }
Parsefanstat::Parsefanstat() { initdata(); }
void defaultEPI(struct data *d) { int DISCARD=-1; int refEPI=FALSE,refSGE=FALSE; int getscaleref=FALSE; double oversample,lro,lpe; struct data ref1,ref2,ref3,ref4,ref5,ref6; struct segscale scale1,scale2; enum { OFF = 0, POINTWISE = 1, TRIPLE = 2, SCALED_TRIPLE = 3 } epi_pc; #ifdef DEBUG char function[20]; strcpy(function,"defaultEPI"); /* Set function name */ #endif /* Set EPI correction scheme */ if (spar(d,"epi_pc","POINTWISE")) epi_pc=POINTWISE; else if (spar(d,"epi_pc","TRIPLE")) epi_pc=TRIPLE; else if (spar(d,"epi_pc","SCALED_TRIPLE")) epi_pc=SCALED_TRIPLE; else epi_pc=OFF; /* Check whether to output or discard reference scans */ if (spar(d,"imRF","y")) refEPI=TRUE; if (spar(d,"imSGE","y")) refSGE=TRUE; /* Set reference data */ if (epi_pc > OFF) { /* Pointwise or triple reference phase correction */ getpars(d->procpar,&ref1); initdata(&ref1); getpars(d->procpar,&ref3); /* ref3 used in pointwise phase correction of inverted */ initdata(&ref3); /* reference scans if reference output is selected */ } if (epi_pc > POINTWISE) { /* Triple reference phase corrections */ getpars(d->procpar,&ref2); initdata(&ref2); getpars(d->procpar,&ref4); initdata(&ref4); } if (epi_pc > TRIPLE) { /* Scaled triple reference phase correction */ getpars(d->procpar,&ref5); initdata(&ref5); getpars(d->procpar,&ref6); initdata(&ref6); } d->nv=(int)*val("nphase",&d->p); /* Set d->nv for dimorder2D */ d->pssorder=sliceorder(d,d->ns,"pss"); /* Fill pssorder with the slice order */ d->dim2order=phaseorder(d,d->nv,"par_does_not_exist"); /* Set dim2order=-1 for sequential phase encode order */ d->dim3order=phaseorder(d,d->nv,"sgepelist"); /* Fill dim3order with the standard gradient echo phase encode order */ d->nv2=d->nv; /* Set d->nv2 for dim3order */ d->dimorder=IM2D; /* Set dimorder flag */ d->nv=(int)*val("nseg",&d->p); /* Use d->nv for the number of shots */ setnvolsEPI(d); /* Set the number of data volumes */ /* Allow for scaled FOV in ASL test setup expt */ lro=*val("lro",&d->p)**val("aslfov",&d->p); lpe=*val("lpe",&d->p)**val("aslfov",&d->p); /* Set default of no compressed segment scaling just in case it's never set */ scale1.data=FALSE; scale2.data=FALSE; /* Loop over data blocks */ for (d->block=0;d->block<d->nblocks;d->block++) { d->outvol=0; /* Initialise output data volume (that will not include reference scans) */ for (d->vol=0;d->vol<d->nvols;d->vol++) { /* Loop over "volumes" */ setoutvolEPI(d); /* Set output data volume */ if (d->outvol>d->endvol) break; /* Break if last requested volume has been processed */ getblockEPI(d,d->vol,NDCC); /* Get block without applying dbh.lvl and dbh.tlt */ zeromax(d); /* Zero max structure & coordinates of maximum */ zeronoise(d); /* Zero values in noise structure */ #ifdef DEBUG fprintf(stdout,"\n%s: %s()\n",SOURCEFILE,function); switch (epi_pc) { case OFF: fprintf(stdout," Correction: OFF \n"); break; case POINTWISE: fprintf(stdout," Correction: POINTWISE \n"); break; case TRIPLE: fprintf(stdout," Correction: TRIPLE \n"); break; case SCALED_TRIPLE: fprintf(stdout," Correction: SCALED_TRIPLE \n"); break; } fflush(stdout); #endif /* Process data as directed by image parameter */ switch ((int)getelem(d,"image",d->vol)) { case 0: /* Reference, no phase-encode */ setblockEPI(d); /* Set block for 2D data (d->nv > 1) and navigators */ if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */ if (epi_pc > OFF) { /* If there is phase correction */ ftnpEPI(d); /* FT along readout dimension */ clear2Ddata(&ref1); /* Clear ref1 */ copy2Ddata(d,&ref1); /* Copy to ref1 */ ref1.datamode=EPIREF; /* Flag as EPIREF data */ } else { /* else there is no phase correction */ ref1.datamode=NONE; /* Flag as no data */ if (refEPI) ftnpEPI(d); /* FT along readout dimension */ } setsegscale(d,&scale1); /* Set scaling for compressed segments */ segscale(d,&scale1); /* Scale compressed segments */ if (refEPI) /* If reference output is requested */ w2Dfdfs(d,VJ,FLT32,d->vol); /* Output data for the volume */ else w2Dfdfs(d,VJ,FLT32,DISCARD); /* Else use DISCARD to flag skip the volume */ wnifti(d,VJ,FLT32,DISCARD); break; case -1: /* Inverted Readout Reference, with phase-encode */ #ifdef DEBUG fprintf(stdout," Processing reference -1 data ...\n"); fflush(stdout); #endif setblockEPI(d); /* Set block for 2D data (d->nv > 1) and navigators */ if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */ ftnpEPI(d); /* FT along readout dimension */ segscale(d,&scale2); /* Scale compressed segments */ if (epi_pc > POINTWISE) { /* if triple or scaled triple reference phase correction */ clear2Ddata(&ref2); /* Clear ref2 */ copy2Ddata(d,&ref2); /* Copy to ref2 */ ref2.datamode=EPIREF; /* Flag ref2 as EPIREF data */ if (ref3.datamode == EPIREF) { /* if there is ref3 reference data */ phaseEPIref(&ref2,&ref3,&ref4); /* Phase correct ref2 data using ref3 and put result in ref4 */ /* analyseEPInav(&ref4); // Analyse the navigators */ stripEPInav(&ref4); /* Strip the navigator scans */ ftnvEPI(&ref4); /* FT along phase encode dimension */ revreadEPI(&ref4); /* Reverse the data in readout dimension */ getscaleref=TRUE; /* Flag to store the next regular image for scaling in SCALED_TRIPLE */ } } if (refEPI) { /* if reference output is requested */ if (ref3.datamode == EPIREF) { /* if there is ref3 reference data */ phaseEPI(d,&ref3); /* Phase correct with the reference */ } navcorrEPI(d); /* Phase correct with the navigator */ stripEPInav(d); /* Strip the navigator scans */ ftnvEPI(d); /* FT along phase encode dimension */ revreadEPI(d); /* Reverse the data in readout dimension */ w2Dfdfs(d,VJ,FLT32,d->vol); /* Output data for the volume */ } else w2Dfdfs(d,VJ,FLT32,DISCARD); /* Use DISCARD to flag skip the volume */ wnifti(d,VJ,FLT32,DISCARD); break; case -2: /* Inverted Readout Reference, no phase-encode */ #ifdef DEBUG fprintf(stdout," Processing reference -2 data ...\n"); fflush(stdout); #endif setblockEPI(d); /* Set block for 2D data (d->nv > 1) and navigators */ if (refEPI) w2Dfdfs(d,VJ,FLT32,d->vol); ftnpEPI(d); /* FT along readout dimension */ setsegscale(d,&scale2); /* Set scaling for compressed segments */ segscale(d,&scale2); /* Scale compressed segments */ if (epi_pc > POINTWISE) { /* if old triple or triple reference phase correction */ clear2Ddata(&ref3); /* Clear ref3 */ copy2Ddata(d,&ref3); /* Copy to ref3 */ ref3.datamode=EPIREF; /* Flag ref3 as EPIREF data */ if (ref2.datamode == EPIREF) { /* if there is ref2 reference data */ phaseEPIref(&ref2,&ref3,&ref4); /* Phase correct ref2 data using ref3 and put result in ref4 */ /* analyseEPInav(&ref4); // Analyse the navigators */ stripEPInav(&ref4); /* Strip the navigator scans */ ftnvEPI(&ref4); /* FT along phase encode dimension */ revreadEPI(&ref4); /* Reverse the data in readout dimension */ getscaleref=TRUE; /* Flag to store the next regular image for scaling in SCALED_TRIPLE */ } } if (refEPI) { /* if reference output is requested */ if (epi_pc == POINTWISE) { /* if pointwise reference phase correction */ clear2Ddata(&ref3); /* Clear ref3 */ copy2Ddata(d,&ref3); /* Copy to ref3 */ ref3.datamode=EPIREF; /* Flag ref3 as EPIREF data */ } revreadEPI(d); /* Reverse the data in readout dimension */ w2Dfdfs(d,VJ,FLT32,d->vol); /* Output data for the volume */ } else w2Dfdfs(d,VJ,FLT32,DISCARD); /* Use DISCARD to flag skip the volume */ wnifti(d,VJ,FLT32,DISCARD); break; case 1: /* Regular image */ #ifdef DEBUG fprintf(stdout," Processing image 1 data ...\n"); fflush(stdout); #endif setblockEPI(d); /* Set block for 2D data (d->nv > 1) and navigators */ if (d->outvol>=d->startvol) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */ switch (epi_pc) { case SCALED_TRIPLE: /* Scaled triple reference phase correction */ if (getscaleref) { /* If the scale reference has just been acquired */ clear2Ddata(&ref5); /* Clear ref5 */ copy2Ddata(d,&ref5); /* Copy to ref5 */ ref5.datamode=EPIREF; /* Flag ref5 as EPIREF data */ prepEPIref(&ref5,&ref1); /* Prepare ref5 data so it can be used to scale ref4 data */ } break; default: break; } ftnpEPI(d); /* FT along readout dimension */ segscale(d,&scale1); /* Scale compressed segments */ phaseEPI(d,&ref1); /* Phase correct with the reference */ navcorrEPI(d); /* Phase correct with the navigator */ /* analyseEPInav(d); // Analyse the navigators */ stripEPInav(d); /* Strip the navigator scans */ ftnvEPI(d); /* FT along phase encode dimension */ switch (epi_pc) { case TRIPLE: /* Triple reference phase correction */ addEPIref(d,&ref4); /* Add ref4 data to cancel N/2 ghost */ break; case SCALED_TRIPLE: /* Scaled triple reference phase correction */ if (getscaleref) { /* If the scale reference has just been acquired */ addEPIref(d,&ref4); /* Add ref4 data to cancel N/2 ghost */ getscaleref=FALSE; /* Flag that scale reference has been acquired */ } else { addscaledEPIref(d,&ref4,&ref5); /* Scale ref4 data according to d/ref5, then add to d */ } break; default: break; } if (d->outvol>=d->startvol) { phasedata2D(d,VJ); /* Phase data if required */ w2Dfdfs(d,VJ,FLT32,d->vol); /* Write 2D fdf data from volume */ wnifti(d,VJ,FLT32,d->vol); } break; default: /* Reference Standard Gradient Echo */ setblockSGE(d); setval(&d->p,"lro",lro); /* Set suitable lro in case it has been scaled */ setval(&d->p,"lpe",lpe); /* Set suitable lpe in case it has been scaled */ if (refSGE) w2Dfdfs(d,VJ,FLT32,d->vol); /* Output raw data for the volume, if requested */ getmax(d); /* Get coordinates of maximum */ shiftdata2D(d,OPT); /* Shift FID data for fft */ equalizenoise2D(d,STD); /* Scale for equal noise in all receivers */ phaseramp2D(d,READ); /* Phase ramp the data to correct for readout offset pro */ phaseramp2D(d,PHASE); /* Phase ramp the data to correct for phase encode offset ppe */ weightdata2D(d,STD); /* Weight data using standard VnmrJ parameters */ oversample=*val("oversample",&d->p); /* Check to see if there is oversampling */ d->fn *=oversample; /* Correct d->fn for oversample */ zerofill2D(d,STD); /* Zero fill data using standard VnmrJ parameters */ fft2D(d); /* 2D fft */ phasedata2D(d,VJ); /* Phase data if required */ shiftdata2D(d,STD); /* Shift data to get images */ if (oversample>1) zoomEPI(d); /* If oversampled, zoom to get the requested FOV */ if (refSGE) /* If standard gradient echo reference output is requested */ w2Dfdfs(d,VJ,FLT32,d->vol); /* Output data for the volume */ else w2Dfdfs(d,VJ,FLT32,DISCARD); /* Else use DISCARD to flag skip the volume */ wnifti(d,VJ,FLT32,DISCARD); break; } /* end image parameter switch */ clear2Ddata(d); /* Clear data volume from memory */ setdatapars(d); /* Sets d->nv=1 */ d->nv=*val("nseg",&d->p); /* Use d->nv for the number of shots */ d->nv2=(int)*val("nphase",&d->p); /* Use d->nv2 for number of standard gradient echo phase encodes */ d->zerofill=FALSE; /* Make sure setdatapars will not overwrite d->nv */ } /* end volume loop */ } /* end data block loop */ /* Clear all reference data */ if (epi_pc > OFF) { /* Pointwise or triple reference phase correction */ clear2Dall(&ref1); clear2Dall(&ref3); } if (epi_pc > POINTWISE) { /* Triple and scaled triple reference phase correction */ clear2Dall(&ref2); clear2Dall(&ref4); } if (epi_pc > TRIPLE) { /* Scaled triple reference phase correction */ clear2Dall(&ref5); clear2Dall(&ref6); } clear2Dall(d); /* Clear everything from memory */ }
Parsefanstat::Parsefanstat(QList<QFileInfo> name) { statisticsfiles = name; initdata(); }
bool taskMgr::init() { m_openSaml=false; m_openMain = false; initdata(); PMission MainTask = GetMissCur(0); Vec2 origin = Director::getInstance()->getVisibleOrigin(); m_MainTaskICO = MenuItemImage::create("images/Scene/TaskScene/task_rookie_bg.png","images/Scene/TaskScene/task_rookie_bg.png",[&](Ref* Sender){ ShowWin(0); }); m_samlinfo =MenuItemImage::create("images/Scene/TaskScene/task_bg.png","",[&](Ref* Sender){ ShowWin(1); }); m_popsaml =MenuItemImage::create("images/Scene/TaskScene/word_new.png","",[&](Ref* Sender){ ShowSmlSample(); }); m_smlget = MenuItemImage::create("images/Scene/TaskScene/word_success.png","",[&](Ref* Sender){ ShowWin(1); }); m_samltask = Sprite::create("images/Scene/TaskScene/task_light.png"); this->addChild(m_samltask); m_samltask->setPosition(100,450); m_samltask->setVisible(false); m_samltask->runAction(RepeatForever::create(Sequence::create(FadeOut::create(1), FadeIn::create(1), NULL))); m_smlico = Sprite::create(); this->addChild(m_smlico,10); m_smlico->setVisible(false); m_smlico->setPosition(50,460); Vec2 Pos(100,350); auto Menu = Menu::create(m_MainTaskICO,m_samlinfo,m_popsaml,m_smlget,nullptr); this->addChild(Menu); Menu->setPosition(Pos); m_samlinfo->setPosition(0,100); m_popsaml->setPosition(-200,100); m_smlget->setPosition(0,100); m_smlget->setVisible(false); m_samlinfo->setVisible(false); m_samllab = Label::create("", "Arial", 20); this->addChild(m_samllab); m_samllab->setPosition(120,450); m_samllab->setVisible(false); m_MainTaskICO->setVisible(false); if(MainTask->missState != 999999) { m_MainTaskICO->setVisible(true); m_MainTaskLab = LabelAtlas::create("20000","images/Number/shop_coin_num.png",22,28,'0'); this->addChild(m_MainTaskLab,1); m_MainTaskLab->setPosition(Vec2(80,320)); m_maintmlab = Label::create("", "Arial", 24); this->addChild(m_maintmlab); m_maintmlab->setPosition(100,305); float r = 60; m_Partic=ParticleSystemQuad::create("particles/taskAward.plist"); m_Partic->setPositionType(ParticleSystem::PositionType::FREE); m_Partic->setAutoRemoveOnFinish(true); this->addChild(m_Partic,1000); auto array2 = PointArray::create(360); for(int i = 0; i < 360; ++i) { Vec2 l(0,r); l.rotate(Vec2(0,0), i * 10); array2->addControlPoint(Pos + l); } auto action = CatmullRomTo::create(240, array2); m_Partic->setPosition(Pos); m_Partic->runAction(RepeatForever::create(action)); m_taskfail = Sprite::create("images/Scene/TaskScene/word_fail.png"); this->addChild(m_taskfail); m_taskfail->setPosition(100,450); m_taskfail->setVisible(false); } return true; }
static void equal_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("equal_button_callback: %s was pressed\n", data); if (current_state == Error || binary_op == NULL) return; GCALCTRACE(); reset_input = true; const char *string = gtk_entry_get_text(GTK_ENTRY(text_entry)); errno = 0; double x = strtod(string, NULL); if (isnan(x)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); return; } else if (isinf(x)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else if (errno != 0) { GCALCTRACE(); initdata(Error); char buf[BUFSIZ]; sprintf(buf, "errno=%d", errno); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); return; } GCALCTRACE(); if (strcmp("y^x", binary_op) == 0) { GCALCTRACE(); accumulator = pow(accumulator, x); } else if (strcmp("/", binary_op) == 0) { GCALCTRACE(); accumulator /= x; } else if (strcmp("x", binary_op) == 0) { GCALCTRACE(); accumulator *= x; } else if (strcmp("y^1/x", binary_op) == 0) { GCALCTRACE(); accumulator = pow(accumulator, 1.0/x); } else if (strcmp("-", binary_op) == 0) { GCALCTRACE(); accumulator -= x; } else if (strcmp("+", binary_op) == 0) { GCALCTRACE(); accumulator += x; } else { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); return; } GCALCTRACE(); if (isnan(accumulator)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (isinf(accumulator)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); initdata(Start, accumulator); } else { GCALCTRACE(); char buf[BUFSIZ]; sprintf(buf, "%.14g", accumulator); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); initdata(Start, accumulator); } }
int main(int argc, char **argv) { /* network */ int err, listenfd, telnetfd, connfd, maxfdp1, nready; struct sockaddr_in servaddr, tnservaddr; char readline[MAXLINE]; /* data */ struct cmd cmd; struct wthio wio; int ndata = 0; int nobg = 0; int is_command = 0; int o; unsigned char data[MAXBUFF]; char *nakfram = "\x02\x01\x15\xe8\x03"; char *rbuf; fd_set rset; werrno = 0; initdata(&wio); initcmd(&cmd); readconfig(&cmd); /* parse commandline */ while ((o = getopt(argc, argv, "dp:")) != -1) { switch(o) { case 'd': nobg = 1; break; case 'p': cmd.port = strdup(optarg); break; case '?': usaged(1,"command line error",""); break; default: usaged(0, "", ""); } } if ( nobg == 0 ) daemon_init("wthd", LOGFACILITY); else if ( nobg == 1) { openlog("wthd", LOG_PID, LOGFACILITY); printf("wthd: ready\n"); } /* create 1st TCP socket */ listenfd = Socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(atoi(cmd.port)); Bind(listenfd, (SA *) &servaddr, sizeof(servaddr)); Listen(listenfd, LISTENQ); /* create 2nd TCP socket */ telnetfd = Socket(AF_INET, SOCK_STREAM, 0); bzero(&tnservaddr, sizeof(tnservaddr)); tnservaddr.sin_family = AF_INET; tnservaddr.sin_addr.s_addr = htonl(INADDR_ANY); tnservaddr.sin_port = htons(atoi(cmd.tnport)); Bind(telnetfd, (SA *) &tnservaddr, sizeof(tnservaddr)); Listen(telnetfd, LISTENQ); FD_ZERO(&rset); maxfdp1 = max(listenfd, telnetfd) + 1; for ( ; ; ) { FD_SET(listenfd, &rset); FD_SET(telnetfd, &rset); if ( ( nready = select(maxfdp1, &rset, NULL, NULL, NULL)) < 0 ) { if ( errno == EINTR ) continue; else syslog(LOG_INFO, "select error"); } if ( FD_ISSET(listenfd, &rset)) { connfd = accept(listenfd, (SA *) NULL, NULL); Read(connfd, readline, MAXLINE); cmd.command = o = atoi(readline); cmd.argcmd = 0; cmd.netflg = 0; if ( getsrd( data, &ndata, &cmd) == -1 ) { syslog(LOG_INFO,"error reading serial data"); strncpy(data, nakfram, strlen(nakfram)); ndata = strlen(nakfram); } Write(connfd, data, ndata); /* syslog(LOG_INFO,"command request: %s\n", c(o)->descr); */ Close(connfd); } if ( FD_ISSET(telnetfd, &rset)) { connfd = Accept(telnetfd, (SA *) NULL, NULL); snprintf(readline, sizeof(readline), "\n\n%s\n\t%s\n>", "Welcome to wth service","Type h for help"); Write(connfd, readline, strlen(readline)); cmd.argcmd = 0; cmd.netflg = 0; for ( ; ; ) { Read(connfd, readline, MAXLINE); if ( ( err = strncmp(readline, "h", 1)) == 0 ) { snprintf(readline, sizeof(readline), tnusage(0,"","")); Write(connfd, readline, strlen(readline)); } else if ( ( err = strncmp(readline, "0", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "1", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "2", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "3", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "4", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "5", 1)) == 0) { cmd.command = o = atoi(readline); is_command = 1; } else if ( ( err = strncmp(readline, "q", 1)) == 0) break; else if ( ( err = strncmp(readline, "quit", 4)) == 0) break; else { snprintf(readline, sizeof(readline), tnusage(0,"","")); Write(connfd, readline, strlen(readline)); } if ( is_command == 1 ) { rbuf = wcmd(&cmd, &wio); printf("rbuf: %s\n", rbuf); snprintf(readline, sizeof(readline), rbuf); Write(connfd, readline, strlen(readline)); cmd.argcmd = 0; cmd.netflg = 0; is_command = 0; } snprintf(readline, sizeof(readline), ">"); Write(connfd, readline, strlen(readline)); } Close(connfd); } } return(0); }
static void binaryop_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("binaryop_button_callback: %s was pressed\n", data); reset_input = true; switch (current_state) { case Start: { GCALCTRACE(); const char *string = gtk_entry_get_text(GTK_ENTRY(text_entry)); errno = 0; double x = strtod(string, NULL); if (isnan(x)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (errno != 0) { GCALCTRACE(); initdata(Error); char buf[BUFSIZ]; sprintf(buf, "errno=%d", errno); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } else { GCALCTRACE(); accumulator = x; current_state = Binary; binary_op = data; } return; } case Binary: { GCALCTRACE(); if (binary_op != NULL) { GCALCTRACE(); // two binary ops in a row. complete one, then use // result for second op. equal_button_callback(widget, data); if (current_state != Error) { GCALCTRACE(); binary_op = data; current_state = Binary; } } else { GCALCTRACE(); binary_op = data; } return; } case Error: { GCALCTRACE(); return; } default: { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); return; } } }
static void memory_button_callback(GtkWidget *widget, const char *data) { GCALCTRACE(); if (verbose) g_print("button_callback: %s was pressed\n", data); if (current_state == Error) return; GCALCTRACE(); reset_input = true; const char *string = gtk_entry_get_text(GTK_ENTRY(text_entry)); errno = 0; double x = strtod(string, NULL); if (isnan(x)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (isinf(x)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else if (errno != 0) { GCALCTRACE(); initdata(Error); char buf[BUFSIZ]; sprintf(buf, "errno=%d", errno); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } else if (strcmp(data, "MC") == 0) { GCALCTRACE(); memory = 0.0; } else if (strcmp(data, "M+") == 0) { GCALCTRACE(); memory += x; } else if (strcmp(data, "M-") == 0) { GCALCTRACE(); memory -= x; } else if (strcmp(data, "MR") == 0) { GCALCTRACE(); if (isnan(memory)) { GCALCTRACE(); initdata(Error); gtk_entry_set_text(GTK_ENTRY(text_entry), "NaN"); } else if (isinf(memory)) { GCALCTRACE(); gtk_entry_set_text(GTK_ENTRY(text_entry), "INF"); } else { GCALCTRACE(); char buf[BUFSIZ]; sprintf(buf, "%.14g", memory); gtk_entry_set_text(GTK_ENTRY(text_entry), buf); } } }
int main (int argc, char **argv) { int o; char *rbuf; extern int optind; extern char *optarg; struct cmd cmd; /* command structure */ struct wthio wio; /* result */ initdata(&wio); initcmd(&cmd); if ( ( rbuf = readconfig(&cmd)) == NULL ) { perror("Error reading configuration: exit!"); exit(-1); } openlog("wthc", LOG_PID , cmd.logfacility); syslog(LOG_INFO, "%s\n", wth_version); /* parsing command line arguments */ while (( o = getopt(argc, argv, "c:h:i:p:sv")) != -1 ) { switch (o) { case 'c': cmd.command = atoi(optarg); break; case 'h': cmd.hostname = optarg; cmd.netflg = 1; break; case 'i': cmd.argcmd = atoi(optarg); break; case 'p': cmd.port = optarg; break; case 's': if ( cmd.netflg != -1 ) usage(1,"specify serial OR internet connection",""); cmd.netflg = 0; break; case 'v': cmd.verbose = 1; printf("wthc: %s\n", wth_version); printf("%s", rbuf); break; case '?': usage(1, "Commandline error", ""); break; default: usage(0,"", ""); } } /* save command for later use */ o = cmd.command; /* check if intervall time has been set in case cmd.command is request to set intervall time */ if ( cmd.command == 6 ) { if ((cmd.argcmd < 1) || (cmd.argcmd >60)) usage(1,"interval time not been specified or out of range", ""); } /* check on serial/internet connection is been chosen correctly */ if ( cmd.netflg == -1 ) usage(1, "specify serial OR internet connection",""); if (cmd.verbose == 1 ) { if ( ( rbuf = echoconfig(&cmd)) == NULL) { perror("Error echo config parameters: exit!"); exit(-1); } printf("%s\n", rbuf); } /* sending command to weather station */ rbuf = wcmd(&cmd, &wio); printf("%s", rbuf); syslog(LOG_INFO, "wthc : wcmd : %s\n", c(o)->descr); switch (werrno) { case -2: printf("serial line error\n"); break; case -3: printf("chksum error\n"); break; case 0: break; } closelog(); return(0); }