int main (int argc, char *argv[]) { if (argc != 2) { printf("usage: %s trace_file\n", argv[0]); exit(1); } int result = 0; int atm_count = 0; int account_count = 0; // open the trace file result = trace_open(argv[1]); if (result == -1) { printf("%s: could not open file %s\n", argv[0], argv[1]); exit (1); } // Get the number of ATMs and accounts: atm_count = trace_atm_count(); account_count = trace_account_count(); trace_close(); // Setup bank pipes: int bankfd[2]; pipe(bankfd); // This is a table of atm_out file descriptors. It will be used by // the bank process to communicate to each of the ATM processes. int atm_out_fd[atm_count]; // TODO: ATM PROCESS FORKING // START YOUR IMPLEMENTATION for(int i =0; i < atm_count; i++){ int atmfd[2]; pipe(atmfd); atm_out_fd[i] =atmfd[1]; if(fork()== 0){ close(atmfd[1]); close(bankfd[0]); int result = atm_run(argv[1],bankfd[1],atmfd[0],i); if(result != SUCCESS){ error_print(); } else{ close(atmfd[0]); } exit(0); } } // END YOUR IMPLEMENTATION // TODO: BANK PROCESS FORKING // START YOUR IMPLEMENTATION //pid_t pid2 = fork(); if(fork() == 0){ close(bankfd[1]); bank_open(atm_count,account_count); int result =run_bank(bankfd[0],atm_out_fd); if(result != SUCCESS){ error_print(); } bank_dump(); bank_close(); exit(0); } // END YOUR IMPLEMENTATION // Wait for each of the child processes to complete. We include // atm_count to include the bank process (i.e., this is not a // fence post error!) for (int i = 0; i <= atm_count; i++) { wait(NULL); } return 0; }
/**************************************************************** * nmi_ecc_isr - ECC NMI Interrupt Handler * * This module handles the NMI caused by an ECC error. * For a Single-bit error it does a read-nodify-write * to correct the error in memory. For a multi-bit or * nibble error it does absolutely nothing. */ void nmi_ecc_isr(void) { UINT32 eccr_register; UINT32* reg32; /* Read current state of ECC register */ eccr_register = *(UINT32 *)ECCR_ADDR; /* Turn off all ecc error reporting */ *(UINT32 *)ECCR_ADDR = 0x4; /* Check for ECC Error 0 */ if(*(UINT32 *)MCISR_ADDR & 0x1) { reg32 = (UINT32*)ELOG0_ADDR; error_print("ELOG0 = 0x%X\n",*reg32,0,0,0); reg32 = (UINT32*)ECAR0_ADDR; error_print("ECC Error Detected at Address 0x%X\n",*reg32,0,0,0); /* Check for single-bit error */ if(!(*(UINT32 *)ELOG0_ADDR & 0x00000100)) { /* call ECC restoration function */ _scrub_ecc(*reg32); /* Clear the MCISR */ *(UINT32 *)MCISR_ADDR = 0x1; } else error_print("Multi-bit or nibble error\n",0,0,0,0); } /* Check for ECC Error 1 */ if(*(UINT32 *)MCISR_ADDR & 0x2) { reg32 = (UINT32*)ELOG1_ADDR; error_print("ELOG0 = 0x%X\n",*reg32,0,0,0); reg32 = (UINT32*)ECAR1_ADDR; error_print("ECC Error Detected at Address 0x%X\n",*reg32,0,0,0); /* Check for single-bit error */ if(!(*(UINT32 *)ELOG1_ADDR & 0x00000100)) { /* call ECC restoration function */ _scrub_ecc(*reg32); /* Clear the MCISR */ *(UINT32 *)MCISR_ADDR = 0x2; } else error_print("Multi-bit or nibble error\n",0,0,0,0); } /* Check for ECC Error N */ if(*(UINT32 *)MCISR_ADDR & 0x4) { /* Clear the MCISR */ *(UINT32 *)MCISR_ADDR = 0x4; error_print("Uncorrectable error during RMW\n",0,0,0,0); } /* Turn on ecc error reporting */ *(UINT32 *)ECCR_ADDR = eccr_register; }
// Process options from command line static int proc_cmd_options(int argc, char ** argv, proc_instance_t * proc, void * type_table) { int op; // qty of labels provided on cmd line for members parsed from input events int label_cnt = 0; // limited to 128 while ((op = getopt(argc, argv, "lIP:pt:F:r:is:d:N")) != EOF) { switch (op) { case 'l': // use first element in event as container label proc->first_el_label = 1; break; case 'I': // use inline labels proc->inline_labels = 1; free(proc->delim); proc->delim = strdup("\t"); // TODO: why default to tab here? break; case 'P': // poll file for events proc->poll_filename = strdup(optarg); proc->do_poll = 1; break; case 'p': proc->preload = 1; break; case 't': // poll file on this period proc->poll_duration = atoi(optarg); proc->do_poll = 1; // TODO: what happens if you give t but not P? break; case 'F': // use file as list of csv input files proc->in = sysutil_config_fopen(optarg,"r"); if (!proc->in) { // TODO: test this; proc->in initialized to stdin tool_print("unable to open file for reading %s", optarg); return 0; } else { tool_print("opened file for reading list of csv files %s", optarg); } break; case 'r': proc->in = sysutil_config_fopen(optarg, "r"); proc->straight_data = 1; if ( !proc->in ) { error_print("Unable to open file '%s' for input", optarg); return 0; } break; case 'i': // use stdin for data proc->straight_data = 1; break; case 's': case 'd': // use characters as delimiters free(proc->delim); if (strcmp(optarg, "\\t") == 0) { proc->delim = strdup("\t"); tool_print("using [tab] as input delimiter"); } else { proc->delim = strdup(optarg); tool_print("using [%s] as input delimiter", proc->delim); } break; case 'N': // use stdin for data proc->no_autodatatyping = 1; break; default: return 0; } } // store all remaining command line tokens as labels for members parsed // from the events received as input while (optind < argc) { // proc->lset is limited to 128 by WSMAX_LABEL_SET defined in waterslide.h wslabel_set_add_noindex(type_table, &proc->lset, argv[optind]); if ((WSMAX_LABEL_SET - label_cnt) > 0) { tool_print("searching for string with label %s", argv[optind]); } else { tool_print("too many labels: %s", argv[optind]); } optind++; label_cnt++; } return 1; }
void ruby_error_print(void) { error_print(GET_THREAD()); }
int gtkspell_start(char *path, char * args[]) { int fd_error[2]; char buf[BUFSIZE]; if (gtkspell_running()) { error_print("gtkspell_start called while already running.\n"); gtkspell_stop(); } if (!signal_set_up) { set_up_signal(); signal_set_up = 1; } pipe(fd_write); pipe(fd_read); pipe(fd_error); spell_pid = fork(); if (spell_pid < 0) { error_print("fork: %s\n", strerror(errno)); return -1; } else if (spell_pid == 0) { dup2(fd_write[0], 0); close(fd_write[0]); close(fd_write[1]); dup2(fd_read[1], 1); close(fd_read[0]); close(fd_read[1]); dup2(fd_error[1], 2); close(fd_error[0]); close(fd_error[1]); if (path == NULL) { if (execvp(args[0], args) < 0) error_print("execvp('%s'): %s\n", args[0], strerror(errno)); } else { if (execv(path, args) < 0) error_print("execv('%s'): %s\n", path, strerror(errno)); } /* if we get here, we failed. * send some text on the pipe to indicate status. */ write(0, "!", 1); /* stdout _is_ the pipe. */ _exit(0); } else { /* there are at least two ways to fail: * - the exec() can fail * - the exec() can succeed, but the program can dump the help screen * we must check for both. */ fd_set rfds; struct timeval tv; close(fd_write[0]); close(fd_read[1]); FD_ZERO(&rfds); FD_SET(fd_error[0], &rfds); FD_SET(fd_read[0], &rfds); tv.tv_sec = 2; tv.tv_usec = 0; if (select(MAX(fd_error[0], fd_read[0])+1, &rfds, NULL, NULL, &tv) < 0) { /* FIXME: is this needed? */ error_print("Timed out waiting for spell command.\n"); gtkspell_stop(); return -1; } if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */ error_print("Spell command printed on stderr -- probably failed.\n"); gtkspell_stop(); return -1; } /* we're done with stderr, now. */ close(fd_error[0]); close(fd_error[1]); /* otherwise, fd_read[0] is set. */ readline(buf); /* ispell should print something like this: * @(#) International Ispell Version 3.1.20 10/10/95 * if it doesn't, it's an error. */ if (buf[0] != '@') { gtkspell_stop(); return -1; } } /* put ispell into terse mode. * this makes it not respond on correctly spelled words. */ sprintf(buf, "!\n"); writetext(buf); return 0; }
void ruby_error_print(void) { error_print(); }
void main(int argc, char *argv[]){ void error_print(); int i,j,i2; double sx,sy,dx,x,y, x0,y0,x_shift, y_shift, angle,cc,ss; long ik1; /* Processing the command line argument */ if (argc<2 || argc >6){ error_print(argv[0]); exit(1); } /* reading the data from a command line */ sscanf(argv[1],"%le",&sy); sx=sy; x_shift=y_shift=angle=0.; if(argc == 3) sscanf(argv[2],"%le",&sx); if(argc == 4) { sscanf(argv[2],"%le",&sx); sscanf(argv[3],"%le",&y_shift); } if(argc == 5){ sscanf(argv[2],"%le",&sx); sscanf(argv[3],"%le",&y_shift); sscanf(argv[4],"%le",&x_shift); } if(argc == 6){ sscanf(argv[2],"%le",&sx); sscanf(argv[3],"%le",&y_shift); sscanf(argv[4],"%le",&x_shift); sscanf(argv[5],"%le",&angle); angle *= -Pi2/360.; } read_field(); dx =field.size/(field.number); i2=field.number/2+1; /* Cuttitng the aperture */ for (i=1;i<=field.number ;i++) for (j=1;j<=field.number ;j++){ ik1=(i-1)*field.number+j-1; x0=(i-i2)*dx-x_shift; y0=(j-i2)*dx-y_shift; cc=cos(angle); ss=sin(angle); x=x0*cc+y0*ss; y=-x0*ss+y0*cc; if(fabs(x) > sx/2. || fabs(y) > sy/2. ) { field.real[ik1]=0.; field.imaginary[ik1]=0.; } } write_field(); }
int init_driver() { union REGS ireg, oreg; struct SREGS sreg; unsigned short tmp, i; extern int kernel_int; struct TCB *tp; // Find Packet Driver TSR packet_int = find_signature("PKT DRVR", 8, 0x60, 0x7f); if (!packet_int) { error_print("No Packet Driver.\r$"); return(-1); } if ((packet_int == kernel_int) || (packet_int == (kernel_int + 1))) { error_print("Bad Interrupt Number.\r$"); return(-1); } //dos_print("Packet Driver is found at 0x$"); //printhex(packet_int); //dos_print(".\r\n$"); ireg.x.ax = 0x01FF; // Get Driver Info ireg.x.bx = 0xFFFF; int86(packet_int, &ireg, &oreg); driver_type = oreg.x.cflag ? ETHERNET_DRIVER : oreg.h.ch; // MTU_SIZE Adjustment be done for Specific Driver // MTU size includes TCP/IP header (excludes Datalink header) switch (driver_type) { // case BUFFER_DRIVER : case ETHERNET_DRIVER : MTU_SIZE = MAX_BUFSIZE + TCP_HLEN; break; // case SLIP_DRIVER : MTU_SIZE = 296; break; default : MTU_SIZE = 576; break; } ireg.h.ah = 0x02; sreg.es = _CS; if (driver_type == SLIP_DRIVER) { ireg.x.di = (unsigned)RING_BUFFER + MAX_RING_BUFFER / 2; } else { ireg.h.al = driver_type; ireg.x.cx = 0x2; ireg.h.dl = 0; ireg.x.di = (unsigned)pktisr; // RX Routine tmp = ETIP; sreg.ds = _SS; ireg.x.si = (unsigned)&tmp; // for IP } int86x(packet_int, &ireg, &oreg, &sreg); if (driver_type == SLIP_DRIVER) { packet_buffer = RING_BUFFER; return(0); } if (oreg.x.cflag) { goto usedbyother; } else { handle[0] = oreg.x.ax; } tmp = ETADR; sreg.es = _CS; // di still alive sreg.ds = _SS; ireg.x.si = (unsigned)&tmp; // for ARP int86x(packet_int, &ireg, &oreg, &sreg); if (oreg.x.cflag) { ireg.h.ah = 0x03; // release handle[0] ireg.x.bx = handle[0]; int86(packet_int, &ireg, &oreg); usedbyother: error_print("Packet Driver in USE.\r$"); return(-1); } handle[1] = oreg.x.ax; get_addr: // Read my Ethernet Address //dos_print("Read Ethernet Address\n\r$"); ireg.h.ah = 0x06; ireg.x.bx = handle[0]; ireg.x.cx = 6; // 6 byte address sreg.es = _DS; ireg.x.di = (unsigned)(ARP_STUB.my_hw_addr); int86x(packet_int, &ireg, &oreg, &sreg); if (oreg.x.cflag) { error_print("in Reading H/W Address.\r$"); close_driver(); return(-1); } copy_hw_addr(ARP_STUB.ether_pkt.source, ARP_STUB.my_hw_addr); for (tp = tcb, i = 0; i < num_socket; i++, tp++) { copy_hw_addr(ETH_STUB(tp)->source, ARP_STUB.my_hw_addr); } //dos_print("Packet Driver is initialized\n\r$"); //rprintf("H(%d,%d) ", handle[0], handle[1]); //rprintf("ADR:"); print_ether_addr(ARP_STUB.my_hw_addr); //rprintf("\n"); return(0); }
/* cpp_error */ static int _cpp_error(void) { return error_print("cpp"); }
int main(int argc, char **argv) { if(argc < 2) { printf("Usage: %s infile\n", argv[0]); exit(1); } MPI_Comm comm = MPI_COMM_WORLD; MPI_Info mpi_info = MPI_INFO_NULL; MPI_File fh, fw; MPI_Offset file_size, frag_size, read_size; MPI_Offset offset; MPI_Status status; int retval; double start, end; unsigned char *buf, *outbuf, *outProps; size_t destlen; size_t propsize = 5; MPI_Init(&argc, &argv); MPI_Comm_rank(comm, &mpi_rank); MPI_Comm_size(comm, &mpi_size); MPI_Barrier(comm); start = MPI_Wtime(); /* * read */ MPI_File_open(comm, argv[1], MPI_MODE_RDONLY, mpi_info, &fh); MPI_File_get_size(fh, &file_size); //printf("file size:%d\n", file_size); frag_size = file_size / mpi_size; offset = frag_size * mpi_rank; read_size = MIN(frag_size, file_size - offset); //printf("rank %d offset %d\n", mpi_rank, offset); buf = malloc(frag_size + 2); assert(buf != NULL); MPI_File_open(comm, argv[1], MPI_MODE_RDONLY, mpi_info, &fh); MPI_File_read_at(fh, offset, buf, read_size, MPI_CHAR, &status); MPI_File_close(&fh); /* * compress */ destlen = 1.2 * frag_size + 1024 * 1024; outbuf = (unsigned char *)malloc(destlen); assert(outbuf != NULL); destlen = destlen - DATA_OFFSET -propsize; outProps = outbuf + DATA_OFFSET; retval = LzmaCompress(outbuf + DATA_OFFSET + propsize, &destlen, buf, read_size, outProps, &propsize, -1, 0, -1, -1, -1, -1, 1); if(retval != SZ_OK) { error_print(retval); free(buf); free(outbuf); exit(1); } /* * write */ char *fwname; unsigned long long *len; fwname = get_fwname(argv[1]); len = (unsigned long long *)outbuf; *len = read_size; //printf("%s %d\n", fwname, destlen); MPI_File_open(MPI_COMM_SELF, fwname, MPI_MODE_WRONLY | MPI_MODE_CREATE, mpi_info, &fw); MPI_File_set_size(fw, destlen); MPI_File_write(fw, outbuf, destlen + DATA_OFFSET + propsize, MPI_CHAR, &status); MPI_File_close(&fw); MPI_Barrier(comm); end = MPI_Wtime(); size_t cmprs_len; double cmprs_ratio; MPI_Reduce(&destlen, &cmprs_len, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, comm); if(0 == mpi_rank) { cmprs_ratio = (double)cmprs_len / file_size; printf("file size: %lu\n", file_size); printf("after compressed: %lu\n", cmprs_len); printf("compress ratio: %f\n", cmprs_ratio); printf("number of processes: %d\n", mpi_size); printf("time used: %fs\n", end - start); } MPI_Finalize(); free(fwname); free(buf); free(outbuf); return 0; }
void bill(char *hotel_current, char *guest) { int i, service_id, bill_amount; char hotel_filename[NAME_MAXIMUM + 1], guest_name[NAME_MAXIMUM + 1]; FILE *hotel_file, *service_file; fpos_t write_position; hotel hotel_new; service service_new; room room_new; if(!*hotel_current){ error_print("No hotel selected! Use\n\tswitch <hotel name>"); return; } to_filename(strcpy(hotel_filename, hotel_current)); strcat(hotel_filename, NAME_EXTENSION); hotel_file = fopen(hotel_filename, "rb+"); if(!hotel_file){ error_print("File not opened!"); return; } service_file = fopen(SERVICE_FILENAME, "rb"); if(!service_file){ error_print("Services file unavailable!"); fclose(hotel_file); return; } if(!get_name("Guest Name", guest_name, guest)) goto cleanup; fread(&hotel_new, sizeof(hotel_new), 1, hotel_file); if(feof(hotel_file) || ferror(hotel_file)){ error_print("Data not read!"); goto cleanup; } for(i = 0; i < hotel_new.rooms; ++i){ fgetpos(hotel_file, &write_position); fread(&room_new, sizeof(room_new), 1, hotel_file); if(ferror(hotel_file)){ error_print("Data not read!"); goto cleanup; } if(feof(hotel_file)) break; if(!strcmp(room_new.guest, guest_name)) break; } if(i == hotel_new.rooms || feof(hotel_file)){ error_print("Guest not found!"); goto cleanup; } if(!room_new.number_of_services) goto cleanup; printf( "Bill for %s\n" "+----+------+------------------------------------------------------+\n" "| ID | Cost | Description |\n" "+----+------+------------------------------------------------------+\n" , to_name(room_new.guest) ); bill_amount = 0; for(i = 0; i < room_new.number_of_services; ++i){ for(service_id = 1; ; ++service_id){ fread(&service_new, sizeof(service_new), 1, service_file); if(feof(service_file) || ferror(service_file)){ error_print("Data not read!"); goto cleanup; } if(service_id != room_new.service_list[i]) continue; printf( "| %2d | %4d | %52.52s |\n", service_id, service_new.cost, to_name(service_new.description) ); bill_amount += service_new.cost; break; } rewind(service_file); } room_new.number_of_services = 0; fsetpos(hotel_file, &write_position); fwrite(&room_new, sizeof(room_new), 1, hotel_file); if(ferror(hotel_file)){ error_print("Data not written!"); goto cleanup; } printf( "+----+------+------------------------------------------------------+\n" "| | %4d | Total |\n" "+----+------+------------------------------------------------------+\n" , bill_amount ); cleanup: fclose(hotel_file); fclose(service_file); }
int load_png(char * file_name, int * w, int * h, int * depth, char ** data) { #if COMPILE_PNG_CODE FILE *fp; png_structp png_ptr; png_infop info_ptr; png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_type; int rowbytes, channels; unsigned int i; char * buff; char ** row_pointers; fp = fopen(file_name, "rb"); if (!fp){ error_print("Cannot load required png-file (%s). Terminating!",file_name); sys_exit(1); } png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp)NULL/*user_error_ptr*/, NULL/*user_error_fn*/, NULL/*user_warning_fn*/); if (!png_ptr) { error_print("Error png-ptr png-file (%s). Terminating!",file_name); sys_exit(1); } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); error_print("Error create info struct png-file (%s). Terminating!",file_name); sys_exit(1); } png_init_io(png_ptr, fp); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_type); channels = png_get_channels(png_ptr, info_ptr); rowbytes = png_get_rowbytes(png_ptr, info_ptr); buff = (char *) malloc(height*rowbytes); row_pointers = (char **) malloc(height*sizeof(char *)); for(i=0;i<height;i++){ row_pointers[i]=&buff[rowbytes*i]; } png_read_image(png_ptr, (png_bytepp)row_pointers); //fprintf(stderr,"load_png: rgstereo=%d\n",options_rgstereo_on); if( options_rgstereo_on ){ //fprintf(stderr,"load_png: graying out texture\n"); for(i=0;i<height;i++){ int j,k,d; for(j=0;j<rowbytes;j+=channels){ d=0; for(k=0;k<channels;k++) d+=(unsigned char)row_pointers[i][j+k]; d/=channels; for(k=0;k<channels;k++) row_pointers[i][j+k]=d; } } } free(row_pointers); free(info_ptr); free(png_ptr); fclose(fp); *data = buff; *w = width; *h = height; *depth = channels*bit_depth; return 1; #else *data = 0; *w = 0; *h = 0; *depth = 0; return 1; #endif }
void Snapshot(int width, int height) { int i; char file_name[1024]; char randomname[200]; #ifdef USE_WIN //on Windows we have to save a bmp-file (problems with png) SDL_Surface *temp; unsigned char *pixels; /* create file */ get_history(file_name); mkdir(file_name); // every time is not a problem sprintf(randomname,"/screen-%i.bmp",rand()); strcat(file_name,randomname); temp = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0); if (temp == NULL) return; pixels =(png_byte *)malloc(width * height * 3 * sizeof(png_byte)); if (pixels == NULL) { SDL_FreeSurface(temp); return; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)pixels); for (i=0; i<height; i++) memcpy(((char *) temp->pixels) + temp->pitch * i, pixels + 3*width * (height-i-1), width*3); free(pixels); SDL_SaveBMP(temp, file_name); SDL_FreeSurface(temp); return; #else #if COMPILE_PNG_CODE FILE *fp; png_structp png_ptr; png_infop info_ptr; png_colorp palette; png_byte *image; png_bytep *row_pointers; /* create file */ get_history(file_name); #ifdef USE_WIN mkdir(file_name); // every time is not a problem #else mkdir(file_name,0777); // every time is not a problem #endif sprintf(randomname,"/screen-%i.png",rand()); strcat(file_name,randomname); if((fp = fopen(file_name, "wb"))==NULL) { error_print("[write_png_file] File %s could not be opened for writing", file_name); return; } if((png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))==NULL) { error_print("[write_png_file] png_create_write_struct failed",NULL); fclose(fp); remove(file_name); return; } if((info_ptr = png_create_info_struct(png_ptr))==NULL) { error_print("[write_png_file] png_create_info_struct failed",NULL); fclose(fp); remove(file_name); #ifdef png_infopp_NULL png_destroy_write_struct(&png_ptr, png_infopp_NULL); #else png_destroy_write_struct(&png_ptr, (png_infopp)NULL); #endif } if (setjmp(png_jmpbuf(png_ptr))) { fclose(fp); remove(file_name); png_destroy_write_struct(&png_ptr, &info_ptr); return; } png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof (png_color)); png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); png_write_info(png_ptr, info_ptr); png_set_packing(png_ptr); if((image = (png_byte *)malloc(width * height * 3 * sizeof(png_byte)))==NULL) { fclose(fp); remove(file_name); png_destroy_write_struct(&png_ptr, &info_ptr); return; } if((row_pointers = (png_bytep *)malloc(height * sizeof(png_bytep)))==NULL) { fclose(fp); remove(file_name); png_destroy_write_struct(&png_ptr, &info_ptr); free(image); image = NULL; return; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)image); for (i = 0; i < height; i++) { row_pointers[i] = (png_bytep)image + (height - i) * width * 3; } png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, info_ptr); png_free(png_ptr, palette); png_destroy_write_struct(&png_ptr, &info_ptr); free(row_pointers); free(image); fclose(fp); return; #endif // COMPILE_PNG_CODE #endif // USE_WIN }
/****************************************************************************** * iq80310_fiq_handler - Interrupt dispatcher for IQ80310 FIQ Interrupts * * */ int iq80310_fiq_handler(void) { unsigned long nmi_status = *(volatile unsigned long *)NISR_ADDR; unsigned long status; int srcs_found = 0; if (nmi_status & MCU_ERROR) { status = *(volatile unsigned long *)MCISR_ADDR; *MSB_DISPLAY_REG = LETTER_E; if (status & 0x001) *LSB_DISPLAY_REG = ONE; if (status & 0x002) *LSB_DISPLAY_REG = TWO; if (status & 0x004) *LSB_DISPLAY_REG = FOUR; srcs_found++; #if 0 error_print ("**** 80312 Memory Controller Error ****\n",0,0,0,0); if (status & 0x001) error_print ("One ECC Error Detected and Recorded in ELOG0\n",0,0,0,0); if (status & 0x002) error_print ("Second ECC Error Detected and Recorded in ELOG1\n",0,0,0,0); if (status & 0x004) error_print ("Multiple ECC Errors Detected\n",0,0,0,0); #endif /* call ecc interrupt handler */ nmi_ecc_isr(); /* clear the interrupt condition*/ AND_WORD((volatile unsigned long *)MCISR_ADDR, 0x07); /* 02/02/01 jwf */ ecc_error_reported = TRUE; } if (nmi_status & PATU_ERROR) { srcs_found++; error_print ("**** Primary ATU Error ****\n",0,0,0,0); status = *(volatile unsigned long *)PATUISR_ADDR; if (status & 0x001) error_print ("PPCI Master Parity Error\n",0,0,0,0); if (status & 0x002) error_print ("PPCI Target Abort (target)\n",0,0,0,0); if (status & 0x004) error_print ("PPCI Target Abort (master)\n",0,0,0,0); if (status & 0x008) error_print ("PPCI Master Abort\n",0,0,0,0); if (status & 0x010) error_print ("Primary P_SERR# Detected\n",0,0,0,0); if (status & 0x080) error_print ("Internal Bus Master Abort\n",0,0,0,0); if (status & 0x100) error_print ("PATU BIST Interrupt\n",0,0,0,0); if (status & 0x200) error_print ("PPCI Parity Error Detected\n",0,0,0,0); if (status & 0x400) error_print ("Primary P_SERR# Asserted\n",0,0,0,0); /* clear the interrupt conditions */ AND_WORD((volatile unsigned long *)PATUISR_ADDR, 0x79f); CLEAR_PATU_STATUS(); /* tell the config cleanup code about error */ if (pci_config_cycle == 1) pci_config_error = TRUE; } if (nmi_status & SATU_ERROR) { srcs_found++; error_print ("**** Secondary ATU Error ****\n",0,0,0,0); status = *(volatile unsigned long *)SATUISR_ADDR; if (status & 0x001) error_print ("SPCI Master Parity Error\n",0,0,0,0); if (status & 0x002) error_print ("SPCI Target Abort (target)\n",0,0,0,0); if (status & 0x004) error_print ("SPCI Target Abort (master)\n",0,0,0,0); if (status & 0x008) error_print ("SPCI Master Abort\n",0,0,0,0); if (status & 0x010) error_print ("Secondary P_SERR# Detected\n",0,0,0,0); if (status & 0x080) error_print ("Internal Bus Master Abort\n",0,0,0,0); if (status & 0x200) error_print ("SPCI Parity Error Detected\n",0,0,0,0); if (status & 0x400) error_print ("Secondary S_SERR# Asserted\n",0,0,0,0); /* clear the interrupt conditions */ AND_WORD((volatile unsigned long *)SATUISR_ADDR, 0x69f); CLEAR_SATU_STATUS(); /* tell the config cleanup code about error */ if (pci_config_cycle == 1) pci_config_error = TRUE; } if (nmi_status & PBRIDGE_ERROR) { srcs_found++; error_print ("**** Primary Bridge Error ****\n",0,0,0,0); status = *(volatile unsigned long *)PBISR_ADDR; if (status & 0x001) error_print ("PPCI Master Parity Error\n",0,0,0,0); if (status & 0x002) error_print ("PPCI Target Abort (Target)\n",0,0,0,0); if (status & 0x004) error_print ("PPCI Target Abort (Master)\n",0,0,0,0); if (status & 0x008) error_print ("PPCI Master Abort\n",0,0,0,0); if (status & 0x010) error_print ("Primary P_SERR# Asserted\n",0,0,0,0); if (status & 0x020) error_print ("PPCI Parity Error Detected\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)PBISR_ADDR, 0x3f); CLEAR_PBRIDGE_STATUS(); /* tell the config cleanup code about error */ if (pci_config_cycle == 1) pci_config_error = TRUE; } if (nmi_status & SBRIDGE_ERROR) { srcs_found++; /* don't print configuration secondary bridge errors */ /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)SBISR_ADDR, 0x7f); CLEAR_SBRIDGE_STATUS(); /* tell the config cleanup code about error */ if (pci_config_cycle == 1) pci_config_error = TRUE; } if (nmi_status & DMA_0_ERROR) { srcs_found++; error_print ("**** DMA Channel 0 Error ****\n",0,0,0,0); status = *(volatile unsigned long *)CSR0_ADDR; if (status & 0x001) error_print ("DMA Channel 0 PCI Parity Error\n",0,0,0,0); if (status & 0x004) error_print ("DMA Channel 0 PCI Target Abort\n",0,0,0,0); if (status & 0x008) error_print ("DMA Channel 0 PCI Master Abort\n",0,0,0,0); if (status & 0x020) error_print ("Internal PCI Master Abort\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)CSR0_ADDR, 0x2D); } if (nmi_status & DMA_1_ERROR) { srcs_found++; error_print ("**** DMA Channel 1 Error ****\n",0,0,0,0); status = *(volatile unsigned long *)CSR1_ADDR; if (status & 0x001) error_print ("DMA Channel 1 PCI Parity Error\n",0,0,0,0); if (status & 0x004) error_print ("DMA Channel 1 PCI Target Abort\n",0,0,0,0); if (status & 0x008) error_print ("DMA Channel 1 PCI Master Abort\n",0,0,0,0); if (status & 0x020) error_print ("Internal PCI Master Abort\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)CSR1_ADDR, 0x2D); } if (nmi_status & DMA_2_ERROR) { srcs_found++; error_print ("**** DMA Channel 2 Error ****\n",0,0,0,0); status = *(volatile unsigned long *)CSR2_ADDR; if (status & 0x001) error_print ("DMA Channel 2 PCI Parity Error\n",0,0,0,0); if (status & 0x004) error_print ("DMA Channel 2 PCI Target Abort\n",0,0,0,0); if (status & 0x008) error_print ("DMA Channel 2 PCI Master Abort\n",0,0,0,0); if (status & 0x020) error_print ("Internal PCI Master Abort\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)CSR2_ADDR, 0x2D); } if (nmi_status & MU_ERROR) { status = *(volatile unsigned long *)IISR_ADDR; if (status & 0x20) { srcs_found++; error_print ("Messaging Unit Outbound Free Queue Overflow\n",0,0,0,0); /* clear the interrupt condition; note that the clearing of the NMI doorbell is handled by the PCI comms code */ } AND_WORD((volatile unsigned long *)IISR_ADDR, 0x20); } if (nmi_status & AAU_ERROR) { srcs_found++; error_print ("**** Application Accelerator Unit Error ****\n",0,0,0,0); status = *(volatile unsigned long *)ASR_ADDR; if (status & 0x020) error_print ("Internal PCI Master Abort\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)ASR_ADDR, 0x20); } if (nmi_status & BIU_ERROR) { srcs_found++; error_print ("**** Bus Interface Unit Error ****\n",0,0,0,0); status = *(volatile unsigned long *)BIUISR_ADDR; if (status & 0x004) error_print ("Internal PCI Master Abort\n",0,0,0,0); /* clear the interrupt condition */ AND_WORD((volatile unsigned long *)BIUISR_ADDR, 0x04); } return (srcs_found); }
void ruby_init(void) { static int initialized = 0; int state; //RHO const_cache_version++; rb_mKernel = 0; rb_mComparable = 0; rb_mEnumerable = 0; rb_mErrno = 0; rb_mFileTest = 0; rb_mGC = 0; rb_mMath = 0; rb_mProcess = 0; rb_mWaitReadable = 0; rb_mWaitWritable = 0; rb_cBasicObject = 0; rb_cObject = 0; rb_cArray = 0; rb_cBignum = 0; rb_cBinding = 0; rb_cClass = 0; //rb_cCont = 0; rb_cDir = 0; rb_cData = 0; rb_cFalseClass = 0; rb_cEncoding = 0; rb_cEnumerator = 0; rb_cFile = 0; rb_cFixnum = 0; rb_cFloat = 0; rb_cHash = 0; rb_cInteger = 0; rb_cIO = 0; rb_cMatch = 0; rb_cMethod = 0; rb_cModule = 0; rb_cNameErrorMesg = 0; rb_cNilClass = 0; rb_cNumeric = 0; rb_cProc = 0; rb_cRandom = 0; rb_cRange = 0; rb_cRational = 0; rb_cComplex = 0; rb_cRegexp = 0; rb_cStat = 0; rb_cString = 0; rb_cStruct = 0; rb_cSymbol = 0; rb_cThread = 0; rb_cTime = 0; rb_cTrueClass = 0; rb_cUnboundMethod = 0; rb_eException = 0; rb_eStandardError = 0; rb_eSystemExit = 0; rb_eInterrupt = 0; rb_eSignal = 0; rb_eFatal = 0; rb_eArgError = 0; rb_eEOFError = 0; rb_eIndexError = 0; rb_eStopIteration = 0; rb_eKeyError = 0; rb_eRangeError = 0; rb_eIOError = 0; rb_eRuntimeError = 0; rb_eSecurityError = 0; rb_eSystemCallError = 0; rb_eThreadError = 0; rb_eTypeError = 0; rb_eZeroDivError = 0; rb_eNotImpError = 0; rb_eNoMemError = 0; rb_eNoMethodError = 0; rb_eFloatDomainError = 0; rb_eLocalJumpError = 0; rb_eSysStackError = 0; rb_eRegexpError = 0; rb_eEncodingError = 0; rb_eEncCompatError = 0; rb_eScriptError = 0; rb_eNameError = 0; rb_eSyntaxError = 0; rb_eLoadError = 0; rb_eMathDomainError = 0; ruby_current_vm = 0; rb_cISeq = 0; rb_cRubyVM = 0; rb_cEnv = 0; rb_mRubyVMFrozenCore = 0; //RHO //RHO //if (initialized) //return; //RHO initialized = 1; ruby_init_stack((void *)&state); Init_BareVM(); Init_heap(); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { rb_call_inits(); ruby_prog_init(); } POP_TAG(); if (state) { error_print(); exit(EXIT_FAILURE); } GET_VM()->running = 1; }
/* cpp_error */ static int _cpp_error(void) { return error_print(PACKAGE); }
int init_wsperf_kid_name(uint32_t uid, char *name) { uint32_t i, cpsz = sizeof(*name); num_kids = uid; // NOTE: memory added by realloc is uninitialized by the system, so we // need to initialize it // Expand kidname if necessary if (uid >= max_kids) { kidname = (char **)realloc(kidname, (max_kids+10)*sizeof(char *)); if (!kidname) { error_print("failed init_wsperf_kid_name realloc of kidname"); return 0; } for (i = max_kids; i < max_kids+10; i++) { kidname[i] = (char *)calloc(MAX_CHARS, sizeof(char)); if (!kidname[i]) { error_print("failed init_wsperf_kid_name calloc of kidname[i]"); return 0; } } numcalls = (uint64_t *)realloc(numcalls, (max_kids+10)*sizeof(uint64_t)); if (!numcalls) { error_print("failed init_wsperf_kid_name realloc of numcalls"); return 0; } for (i = max_kids; i < max_kids+10; i++) { numcalls[i] = 0; } // Also expand kidcycle, kidcount and flushcount for (i = 0; i < work_size; i++) { kidcycle[i] = (uint64_t *)realloc(kidcycle[i], (max_kids+10)*sizeof(uint64_t)); if (!kidcycle[i]) { error_print("failed init_wsperf_kid_name realloc of kidcycle[i]"); return 0; } memset(&kidcycle[i][max_kids], 0, 10*sizeof(uint64_t)); kidcount[i] = (uint64_t *)realloc(kidcount[i], (max_kids+10)*sizeof(uint64_t)); if (!kidcount[i]) { error_print("failed init_wsperf_kid_name realloc of kidcount[i]"); return 0; } memset(&kidcount[i][max_kids], 0, 10*sizeof(uint64_t)); flushcount[i] = (uint64_t *)realloc(flushcount[i], (max_kids+10)*sizeof(uint64_t)); if (!flushcount[i]) { error_print("failed init_wsperf_kid_name realloc of flushcount[i]"); return 0; } memset(&flushcount[i][max_kids], 0, 10*sizeof(uint64_t)); } max_kids += 10; } if (cpsz <= MAX_CHARS) { strcpy(kidname[uid-1], name); } else { strncpy(kidname[uid-1], name, MAX_CHARS); } return 1; }
/* libvfs_init */ static void _libvfs_init(void) { static void * hdl = NULL; static char libc[] = "/lib/libc.so"; static char libc6[] = "/lib/libc.so.6"; #ifdef RLIMIT_NOFILE struct rlimit r; #endif if(hdl != NULL) return; if((hdl = dlopen(libc, RTLD_LAZY)) == NULL && (hdl = dlopen(libc6, RTLD_LAZY)) == NULL) { fprintf(stderr, "%s: %s\n", PROGNAME, dlerror()); exit(1); } if((old_access = dlsym(hdl, "access")) == NULL || (old_chmod = dlsym(hdl, "chmod")) == NULL || (old_chown = dlsym(hdl, "chown")) == NULL || (old_close = dlsym(hdl, "close")) == NULL || (old_closedir = dlsym(hdl, "closedir")) == NULL #ifndef dirfd || (old_dirfd = dlsym(hdl, "dirfd")) == NULL #endif #ifdef __NetBSD__ || (old_fstat = dlsym(hdl, "__fstat50")) == NULL #else || (old_fstat = dlsym(hdl, "fstat")) == NULL #endif || (old_lchown = dlsym(hdl, "lchown")) == NULL || (old_lseek = dlsym(hdl, "lseek")) == NULL #ifdef __NetBSD__ || (old_lstat = dlsym(hdl, "__lstat50")) == NULL #else || (old_lstat = dlsym(hdl, "lstat")) == NULL #endif || (old_mkdir = dlsym(hdl, "mkdir")) == NULL || (old_mmap = dlsym(hdl, "mmap")) == NULL || (old_open = dlsym(hdl, "open")) == NULL || (old_opendir = dlsym(hdl, "opendir")) == NULL || (old_read = dlsym(hdl, "read")) == NULL #ifdef __NetBSD__ || (old_readdir = dlsym(hdl, "__readdir30")) == NULL #elif 0 || (old_readdir = dlsym(hdl, NAME(readdir))) == NULL #else || (old_readdir = dlsym(hdl, "readdir")) == NULL #endif || (old_rewinddir = dlsym(hdl, "rewinddir")) == NULL || (old_rename = dlsym(hdl, "rename")) == NULL || (old_rmdir = dlsym(hdl, "rmdir")) == NULL #ifdef __NetBSD__ || (old_stat = dlsym(hdl, "__stat50")) == NULL #else || (old_stat = dlsym(hdl, "stat")) == NULL #endif || (old_symlink = dlsym(hdl, "symlink")) == NULL || (old_umask = dlsym(hdl, "umask")) == NULL || (old_unlink = dlsym(hdl, "unlink")) == NULL || (old_write = dlsym(hdl, "write")) == NULL) { fprintf(stderr, "%s: %s\n", PROGNAME, dlerror()); dlclose(hdl); exit(1); } dlclose(hdl); #ifdef DEBUG fprintf(stderr, "DEBUG: %s()\n", __func__); #endif if((_appclient = appclient_new(NULL, "VFS", NULL)) == NULL) { error_print(PROGNAME); exit(1); } #ifdef RLIMIT_NOFILE if(getrlimit(RLIMIT_NOFILE, &r) == 0 && r.rlim_max > _vfs_offset) _vfs_offset = r.rlim_max; # ifdef DEBUG fprintf(stderr, "DEBUG: %s() %u\n", __func__, _vfs_offset); # endif #endif }
int print_wsperf(mimo_t * mimo) { double finaltime, kidtime = 0., time0; uint64_t wstotal; int i; uint32_t * kidindx; double * kidtot; double max_pct = 0.0; int max_num_calls = 0; kidindx = (uint32_t *)calloc(num_kids, sizeof(uint32_t)); if (!kidindx) { error_print("failed print_wsperf calloc of kidindx"); return 0; } kidtot = (double *)calloc(num_kids, sizeof(double)); if (!kidtot) { error_print("failed print_wsperf calloc of kidtot"); return 0; } const int nrank = GETRANK(); uint64_t wsbase_loc = wsbase[nrank]; // set up the hertz rate hertz = NANOTICKS; // nanosecond timer // final ws timing wstotal = GET_CYCLE_COUNT() - wsbase_loc; wstot[nrank] = wstotal; WS_MUTEX_LOCK(&endgame_lock); fprintf(stderr,"\nWS Kid Profile (Sorted) for Rank %d:\n", nrank); for (i = 0; i < num_kids; i++) { time0 = ((double)kidcycle[nrank][i])/((double)hertz); kidtime += time0; kidtot[i] = time0; kidindx[i] = i; } // sort the kid run times InsertionSort(kidtot, kidindx, num_kids); mimo->parsed_graph->total_calls = 0; #if (WSPERF_INTERVAL == 1) // print the sorted times for (i = num_kids-1; i > -1; i--) { uint32_t j = kidindx[i]; if (kidcount[nrank][j] > 0 || flushcount[nrank][j]) { fprintf(stderr,"kid %4u is %-24s: proc_func calls = %12lu, time = %10.3f,\n", j+1, kidname[j], kidcount[nrank][j], kidtot[i]); if (flushcount[nrank][j]) { fprintf(stderr," proc_flush calls = %12lu\n", flushcount[nrank][j]); } } char * end = kidname[j]; for(;*end;++end) {} int kidname_len = end - kidname[j]; parse_node_proc_t * proc = listhash_find(mimo->parsed_graph->procs,kidname[j],kidname_len); proc->num_calls = kidcount[nrank][j]; if(proc->num_calls > max_num_calls) { max_num_calls = proc->num_calls; } mimo->parsed_graph->total_calls += proc->num_calls; proc->time = kidtot[i]; proc->rank = num_kids-i; } finaltime = ((double)wstotal)/((double)hertz); fprintf(stderr,"\nWS Total Kid Time: %10.3f\n", kidtime); fprintf(stderr,"\nWS Unaccounted Time: %10.3f\n", finaltime-kidtime); #else // (WSPERF_INTERVAL != 1) // print the sorted percentages for (i = num_kids-1; i > -1; i--) { uint32_t j = kidindx[i]; if (kidcount[nrank][j] > 0 || flushcount[nrank][j]) { fprintf(stderr,"kid %4u is %-24s: proc_func calls = %12"PRIu64", pct = %10.3f\n", j+1, kidname[j], kidcount[nrank][j], kidtot[i]/kidtime*100.); if (flushcount[nrank][j]) { fprintf(stderr," proc_flush calls = %12"PRIu64"\n", flushcount[nrank][j]); } } char * end = kidname[j]; for(;*end;++end) {} int kidname_len = end - kidname[j]; parse_node_proc_t * proc = listhash_find(mimo->parsed_graph->procs,kidname[j],kidname_len); proc->num_calls = kidcount[nrank][j]; if( proc->num_calls > max_num_calls) { max_num_calls = proc->num_calls; } mimo->parsed_graph->total_calls += proc->num_calls; proc->time = kidtot[i]; proc->rank = num_kids-i; proc->pct = kidtot[i]/kidtime*100.; if (proc->pct > max_pct) { max_pct = proc->pct; } } mimo->parsed_graph->max_pct = max_pct; mimo->parsed_graph->max_num_calls = max_num_calls; finaltime = ((double)wstotal)/((double)hertz); #endif // (WSPERF_INTERVAL == 1) fprintf(stderr,"\nWS Total Time: %10.3f\n\n", finaltime); WS_MUTEX_UNLOCK(&endgame_lock); free(kidindx); free(kidtot); return 1; }
/* probe_error */ static int _probe_error(int ret) { error_print(PROGNAME); return ret; }
int init_wsperf(void) { uint32_t i; // assert that WSPERF_INTERVAL is a positive integer assert(WSPERF_INTERVAL >= 1 && (WSPERF_INTERVAL - (int)WSPERF_INTERVAL) == 0); kidname = (char **)calloc(max_kids, sizeof(char *)); if (!kidname) { error_print("failed init_wsperf calloc of kidname"); return 0; } for (i = 0; i < max_kids; i++) { kidname[i] = (char *)calloc(MAX_CHARS, sizeof(char)); if (!kidname[i]) { error_print("failed init_wsperf calloc of kidname[i]"); return 0; } } numcalls = (uint64_t *)calloc(max_kids, sizeof(uint64_t)); if (!numcalls) { error_print("failed init_wsperf calloc of numcalls"); return 0; } kidcycle = (uint64_t **)calloc(work_size, sizeof(uint64_t *)); if (!kidcycle) { error_print("failed init_wsperf calloc of kidcycle"); return 0; } kidcount = (uint64_t **)calloc(work_size, sizeof(uint64_t *)); if (!kidcount) { error_print("failed init_wsperf calloc of kidcount"); return 0; } flushcount = (uint64_t **)calloc(work_size, sizeof(uint64_t *)); if (!flushcount) { error_print("failed init_wsperf calloc of flushcount"); return 0; } for (i = 0; i < work_size; i++) { kidcycle[i] = (uint64_t *)calloc(max_kids, sizeof(uint64_t)); if (!kidcycle[i]) { error_print("failed init_wsperf calloc of kidcycle[i]"); return 0; } kidcount[i] = (uint64_t *)calloc(max_kids, sizeof(uint64_t)); if (!kidcount[i]) { error_print("failed init_wsperf calloc of kidcount[i]"); return 0; } flushcount[i] = (uint64_t *)calloc(max_kids, sizeof(uint64_t)); if (!flushcount[i]) { error_print("failed init_wsperf calloc of flushcount[i]"); return 0; } } wsbase = (uint64_t *)calloc(work_size, sizeof(uint64_t)); if (!wsbase) { error_print("failed init_wsperf calloc of wsbase"); return 0; } wstot = (uint64_t *)calloc(work_size, sizeof(uint64_t)); if (!wstot) { error_print("failed init_wsperf calloc of wstot"); return 0; } return 1; }
static int error_handle(int ex) { int status = EXIT_FAILURE; rb_thread_t *th = GET_THREAD(); if (rb_threadptr_set_raised(th)) return EXIT_FAILURE; switch (ex & TAG_MASK) { case 0: status = EXIT_SUCCESS; break; case TAG_RETURN: error_pos(); warn_print(": unexpected return\n"); break; case TAG_NEXT: error_pos(); warn_print(": unexpected next\n"); break; case TAG_BREAK: error_pos(); warn_print(": unexpected break\n"); break; case TAG_REDO: error_pos(); warn_print(": unexpected redo\n"); break; case TAG_RETRY: error_pos(); warn_print(": retry outside of rescue clause\n"); break; case TAG_THROW: /* TODO: fix me */ error_pos(); warn_printf(": unexpected throw\n"); break; case TAG_RAISE: { VALUE errinfo = GET_THREAD()->errinfo; if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) { status = sysexit_status(errinfo); } else if (rb_obj_is_instance_of(errinfo, rb_eSignal) && rb_ivar_get(errinfo, id_signo) != INT2FIX(SIGSEGV)) { /* no message when exiting by signal */ } else { error_print(); } break; } case TAG_FATAL: error_print(); break; default: unknown_longjmp_status(ex); break; } rb_threadptr_reset_raised(th); return status; }
// creates the texture for the font // TODO (robertva#1#): Handle glyph sizes better. Each glyph has a unique width // + height... int _createFontTexture() { SDL_Surface *surface; SDL_Surface *surface_texture; SDL_Rect srcrect, dstrect; int start = 32; int count = 94; int x, y; float xval, yval; char c[2]; int tw, th; Glyph *first, *current, *row; int per_row; int width, height; SDL_Color color_fg, color_bg; // set vars memset(c, '\0', sizeof(c)); per_row = 0; width = 0; height = 0; debug_print("Getting glyph info."); first = font_getGlyphInfo(start, count); first->x = 0; first->y = 0; current = first; row = current; // todo: make colour settable color_fg.r = 255; color_fg.g = 255; color_fg.b = 255; color_bg.r = 0; color_bg.g = 0; color_bg.b = 0; if (!font) { error_print("_createFontTexture: Font not open."); return 0; } // determine the dimensions required to fit all glyphs and // number of characters in a row debug_print("Getting font texture dimensions."); per_row = round(sqrt(count)); // rounds up. remember to cater for fewer characters font_determineDimensions(start, count, &tw, &th, &per_row); // set texture width and height to nearest power of two tw = power_of_two(tw); th = power_of_two(th); printf("dims: %d %d\n", tw, th); // generate a place for the final surface debug_print("Creating new surface for font texture."); surface_texture = SDL_CreateRGBSurface(SDL_SWSURFACE, tw, th, 32, 0, 0, 0, 0); if (!surface_texture) { error_print("Failed to create new surface for font."); return 0; } for (y = 0; y < per_row; y++) { // store the glyph at the beginning of the row row = current; height = 0; // need to first get the max height out of the glyphs in this row for (x = 0; x < per_row; x++) { if (current) { if (current->h + (GLYPH_PADDING * 2) > height) { height = current->h + (GLYPH_PADDING * 2); } } current = current->next; } // go back to the beginning of the row current = row; // now do the actual rendering and applying to the finial surface for (x = 0; x < per_row; x++) { if (x + (y * per_row) < count) { // correction for rounding of per_row if (current) { // render next character c[0] = start + x + (y * per_row); surface = TTF_RenderText_Shaded(font, c, color_fg, color_bg); current->w = surface->w; current->h = surface->h; // set the src dimensions srcrect.x = 0; srcrect.y = 0; srcrect.w = surface->w; srcrect.h = surface->h; // set the destination location for the new char dstrect.x = current->x + GLYPH_PADDING; dstrect.y = current->y + GLYPH_PADDING; dstrect.w = surface->w; dstrect.h = current->h; // copy the row to the final surface SDL_BlitSurface(surface, &srcrect, surface_texture, &dstrect); SDL_FreeSurface(surface); // set the top left corner of the next glyph if (current->next) { if (x + 1 < per_row) { // if we're still on the same row ((Glyph*)current->next)->x = current->x + current->w + (GLYPH_PADDING * 2); ((Glyph*)current->next)->y = current->y; } else { // on the next row ((Glyph*)current->next)->x = 0; ((Glyph*)current->next)->y = current->y + current->h + (GLYPH_PADDING * 2); } } current = current->next; } } } } // create an opengl texture from the surface font_texture = graphics_createTextureFromSurface(surface_texture); //SDL_SaveBMP(surface_texture, "font.bmp"); // used for debugging SDL_FreeSurface(surface_texture); // reset the glyph info list current = first; debug_print("Generating font display lists..."); font_base = glGenLists(count); // create opengl display list for (y = 0; y < per_row; y++ ) { for (x = 0; x < per_row; x++ ) { if (x + (y * per_row) < count) { if (current) { glNewList(font_base + x + (y * per_row), GL_COMPILE); // new char glBegin(GL_QUADS); // texture 0, 0 xval = current->x / (float)tw; yval = current->y / (float)th; glTexCoord2f(xval, yval); glVertex2i(0, 0); // texture 1, 0 xval = ((current->x + current->w + (GLYPH_PADDING * 2)) / (float)tw); yval = current->y / (float)th; glTexCoord2f(xval, yval); glVertex2i(current->w + (GLYPH_PADDING * 2), 0); // texture 1, 1 xval = ((current->x + current->w + (GLYPH_PADDING * 2)) / (float)tw); yval = (current->y / (float)th) + (current->h / (float)th); glTexCoord2f(xval, yval); glVertex2i(current->w + (GLYPH_PADDING * 2), current->h); // texture 0, 1 xval = current->x / (float)tw; yval = (current->y / (float)th) + (current->h / (float)th); glTexCoord2f(xval, yval); glVertex2i(0, current->h); glEnd(); glTranslatef(current->w + (GLYPH_PADDING), 0, 0.0f); // move to next place glEndList(); current = current->next; } } } } font_destroyGlyphInfo(first); return 1; }