////////////////////////////////////////////////////////////////////// // Sample functions ////////////////////////////////////////////////////////////////////// //================================================================ // Function : TexturesExt_Presentation::Texturize // display an AIS_TexturedShape based on a given shape with texture with given filename // filename can also be an integer value ("2", "5", etc.), in this case // a predefined texture from Graphic3d_NameOfTexture2D with number = this value // is loaded. //================================================================ Handle_AIS_TexturedShape TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName, Standard_Real toScaleU, Standard_Real toScaleV, Standard_Real toRepeatU, Standard_Real toRepeatV, Standard_Real originU, Standard_Real originV) { // create a textured presentation object for aShape Handle_AIS_TexturedShape aTShape = new AIS_TexturedShape(aShape); TCollection_AsciiString TFileName; // load texture from file if it is not an integer value // integer value indicates a number of texture in predefined TexturesExt enumeration CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initfile += "\\Data\\"; if (!aTFileName.IsIntegerValue()) { initfile += aTFileName.ToCString(); } aTShape->SetTextureFileName((Standard_CString)(LPCTSTR)initfile); // do other initialization of AIS_TexturedShape aTShape->SetTextureMapOn(); aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV); aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV); aTShape->SetTextureOrigin(Standard_True, originU, originV); aTShape->SetDisplayMode(3); // mode 3 is "textured" mode return aTShape; }
//================================================================ // Function : TexturesExt_Presentation::loadShape // loads a shape from a given brep file from data dir into a given TopoDS_Shape object //================================================================ Standard_Boolean TexturesExt_Presentation::loadShape(TopoDS_Shape& aShape, TCollection_AsciiString aFileName) { // create a TopoDS_Shape -> read from a brep file CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initfile += "\\Data\\"; initfile += aFileName.ToCString(); TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile); BRep_Builder aBld; //Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld); //if (!isRead) // isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld); Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld); if (!isRead) { Path += " was not found. The sample can not be shown."; getDocument()->UpdateResultMessageDlg("Textured Shape", Path.ToCString()); return Standard_False; } return Standard_True; }
int main(int argc, char **argv) { Optctx ctx; size_t i; FILE *f; localincpath = "."; optinit(&ctx, "sd:hmo:p:l:", argv, argc); while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'h': usage(argv[0]); exit(0); break; case 'p': pkgname = ctx.optarg; break; case 'o': outfile = ctx.optarg; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f] = 1; break; case 'l': lappend(&extralibs, &nextralibs, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } if (!outfile && !show) { fprintf(stderr, "output file needed when merging usefiles.\n"); exit(1); } if (!pkgname) { fprintf(stderr, "package needed when merging usefiles.\n"); exit(1); } /* read and parse the file */ initfile(&file, outfile); updatens(file.globls, pkgname); for (i = 0; i < ctx.nargs; i++) mergeuse(ctx.args[i]); loaduses(); infer(); tagexports(1); addextlibs(extralibs, nextralibs); /* generate the usefile */ f = fopen(outfile, "w"); writeuse(f); fclose(f); return 0; }
int main(int argc, char **argv) { extern int optind, opterr; int c; FINFO file1, file2; setlocale(LC_ALL, ""); opterr = 0; while ((c = getopt(argc, argv, "123")) != -1) switch (c) { case '1': opt1 = 1; break; case '2': opt2 = 1; break; case '3': opt3 = 1; break; default: fprintf(stderr, USAGE); exit(1); } argc -= optind; argv += optind; if (argc != 2) fatal(APPERR, USAGE); initfile(&file1, argv[0]); initfile(&file2, argv[1]); commfiles(&file1, &file2); cleanup(&file1); cleanup(&file2); return(0); }
void InitEditorWidget::read_files() { QFile initfile(DwarfFortress::instance().getInitPath()), dinitfile(DwarfFortress::instance().getDInitPath()); initfile.open(QFile::ReadOnly); dinitfile.open(QFile::ReadOnly); ui->initEdit->setPlainText(initfile.readAll()); ui->dinitEdit->setPlainText(dinitfile.readAll()); initfile.close(); dinitfile.close(); }
void Tesselate_Presentation::sample(const Standard_CString aFileName) { CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initfile += "\\..\\..\\Data\\"; initfile += aFileName; TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile); /* ResetView(); if (aFileName == "wedge_ok.brep"){ SetViewCenter(6.3639597574916, 4.4907309380832); SetViewScale(52.722555157077); } if (aFileName == "shell1.brep"){ SetViewCenter(60.457553053711, -20.351208944076); SetViewScale(26.857478563027); } if (aFileName == "Pump_Nut.brep"){ SetViewCenter(248.77723166710, 77.249633819945); SetViewScale(12.371719671833); } if (aFileName == "Pump_TopCover.brep"){ SetViewCenter(408.72474423160, 169.38361094986); SetViewScale(2.1932732873087); } */ TopoDS_Shape aShape; BRep_Builder aBld; //Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld); //if (!isRead) // isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld); Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld); if (!isRead) { Path += " was not found. The sample can not be shown."; GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", Path); // setResultText(Path.ToCString()); return; } tesselateShape (aShape); }
int sys_open(const char *filename, int flags, int *fd) { lock_acquire(curproc->opencloselock); struct vnode* filenode; int filedescriptor = -1; //vfs_open returns the vnode in filenode, and returns a integer value denoting it's success. char *temp = NULL; temp = kstrdup(filename); int result = vfs_open(temp, flags, 0, &(filenode)); if(result != 0) { lock_release(curproc->opencloselock); return result; } kfree(temp); KASSERT(filenode != NULL); //make our file, a wrapper for vnode. Stores vnode, lock, ect.. May be useful later. struct file* f; f = initfile(filenode, flags, filename); KASSERT(f != NULL); KASSERT(f->fvnode != NULL); //go through the file table, find an unused filedescriptor. for(int i = 0; i < 128; i++) { if(array_get(curproc->filetable, i) == NULL) { filedescriptor = i; break; } } //if fd>=0 then a file descriptor was found. Else file table is probably full. if(filedescriptor >= 0) { array_set(curproc->filetable, filedescriptor, f); *fd = filedescriptor; } else { //kprintf("RAN OUT OF FD FD %d \n", *fd); lock_release(curproc->opencloselock); cleanupfile(f); return EMFILE; } // kprintf("OPENED FD %d \n", *fd); lock_release(curproc->opencloselock); return 0; }
void InitEditorWidget::on_buttonBox_clicked(QAbstractButton *button) { const QDialogButtonBox::ButtonRole role = ui->buttonBox->buttonRole(button); if( role == QDialogButtonBox::ResetRole ) { //reset / reload read_files(); } else if( role == QDialogButtonBox::AcceptRole ) { QFile initfile(DwarfFortress::instance().getInitPath()), dinitfile(DwarfFortress::instance().getDInitPath()); initfile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text); initfile.write(ui->initEdit->toPlainText().toAscii()); dinitfile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text); dinitfile.write(ui->dinitEdit->toPlainText().toAscii()); dinitfile.close(); initfile.close(); } }
static File * getfile(char *fname) { File *f = allocfile(); if (f == nil) return nil; if (strcmp(fname, "/hello.txt") == 0) { initfile(f, hello, strlen(hello)); } else if (strcmp(fname, "/dev/cons") == 0) { consfile(f); } else { releasefile(f); f = nil; } return f; }
void fcompile( /* get definitions from a file */ char *fname ) { FILE *fp; if (fname == NULL) fp = stdin; else if ((fp = fopen(fname, "r")) == NULL) { eputs(fname); eputs(": cannot open\n"); quit(1); } initfile(fp, fname, 0); while (nextc != EOF) getstatement(); if (fname != NULL) fclose(fp); }
/* * Create a fresh proc for use by runprogram. * * It will have no address space and will inherit the current * process's (that is, the kernel menu's) current directory. */ struct proc * proc_create_runprogram(const char *name) { struct proc *proc; char *console_path; proc = proc_create(name); if (proc == NULL) { return NULL; } #ifdef UW /* open the console - this should always succeed */ console_path = kstrdup("con:"); if (console_path == NULL) { panic("unable to copy console path name during process creation\n"); } if (vfs_open(console_path,O_WRONLY,0,&(proc->console))) { panic("unable to open the console during process creation\n"); } #if OPT_A2 //first 3 file descriptors are always stdin, stdout, and stderr, which all point to the console int result; struct vnode* stdinvnode; console_path = kstrdup("con:"); result = vfs_open(console_path,O_RDWR,0,&(stdinvnode)); struct file* stdin; stdin = initfile(stdinvnode, O_RDWR, "stdin"); KASSERT(stdin != NULL); KASSERT(result == 0); struct vnode* stdoutvnode; console_path = kstrdup("con:"); result = vfs_open(console_path,O_RDWR,0,&(stdoutvnode)); struct file* stdout; stdout = initfile(stdoutvnode, O_RDWR, "stdout"); KASSERT(stdout != NULL); KASSERT(result == 0); struct vnode* stderrvnode; console_path = kstrdup("con:"); result = vfs_open(console_path,O_RDWR,0,&(stderrvnode)); struct file* stderr; stderr = initfile(stderrvnode, O_RDWR, "stderr"); KASSERT(stderr != NULL); KASSERT(result == 0); kfree(console_path); array_set(proc->filetable, 0, stdin); array_set(proc->filetable, 1, stdout); array_set(proc->filetable, 2, stderr); #endif #endif // UW /* VM fields */ proc->p_addrspace = NULL; /* VFS fields */ #ifdef UW /* we do not need to acquire the p_lock here, the running thread should have the only reference to this process */ /* also, acquiring the p_lock is problematic because VOP_INCREF may block */ if (curproc->p_cwd != NULL) { VOP_INCREF(curproc->p_cwd); proc->p_cwd = curproc->p_cwd; } #else // UW spinlock_acquire(&curproc->p_lock); if (curproc->p_cwd != NULL) { VOP_INCREF(curproc->p_cwd); proc->p_cwd = curproc->p_cwd; } spinlock_release(&curproc->p_lock); #endif // UW #ifdef UW /* increment the count of processes */ /* we are assuming that all procs, including those created by fork(), are created using a call to proc_create_runprogram */ P(proc_count_mutex); proc_count++; V(proc_count_mutex); #endif // UW return proc; }
void init( PDTV pDisk ) { int this_set; /*mark the file set (0..NSETS-1)*/ int bcount; /*counter to track #spacer files*/ int fcount; /*a counter to tell where to create*/ int i, j, k; /*files to flush buffer cache and*/ /*spread other files across disk*/ pDisk->bsize[ 0 ] = 256; pDisk->bfreq[ 0 ] = 128; pDisk->bsize[ 1 ] = 512; pDisk->bfreq[ 1 ] = 64; pDisk->bsize[ 2 ] = 1024; pDisk->bfreq[ 2 ] = 64; pDisk->bsize[ 3 ] = 2048; pDisk->bfreq[ 3 ] = 64; pDisk->bsize[ 4 ] = 4096; pDisk->bfreq[ 4 ] = 32; /*set file block sizes and*/ pDisk->bsize[ 5 ] = 8192; pDisk->bfreq[ 5 ] = 32; /*access frequencies*/ pDisk->bsize[ 6 ] = 16384; pDisk->bfreq[ 6 ] = 8; pDisk->bsize[ 7 ] = 32768; pDisk->bfreq[ 7 ] = 2; pDisk->bsize[ 8 ] = 65536; pDisk->bfreq[ 8 ] = 2; k = 0; /*set up files*/ bcount = 0; fcount = 0; for( i = 0; i < NBLOCKSIZES; i++ ) { for( j = 0; j < pDisk->bfreq[ i ]; j++ ) { if( i < NBLOCKSIZES - 1 ) this_set = j % NSETS; else this_set = ( j + 2 ) % NSETS; sprintf( pDisk->tmp, "%0d_%0d", i, j ); /*create filename*/ pDisk->files[ this_set ][ k ] = malloc( 1 + strlen( pDisk->tmp )); if( ! pDisk->files[ this_set ][ k ] ) { printf( "Could not allocate string for filename\n" ); EndItAll( 1, pDisk ); } strcpy( pDisk->files[ this_set ][ k ], pDisk->tmp ); initfile( pDisk->tmp, pDisk->bsize[ i ], pDisk ); if( i < NBLOCKSIZES - 1 && this_set == NSETS - 1 ) k++; if( bcount < NBFLUSH_FILES && fcount % 44 == 0 ) { sprintf( pDisk->tmp, "%bf_%0d", bcount ); /*create spacer file*/ pDisk->buf_flush_files[ bcount ] = malloc( 1 + strlen( pDisk->tmp )); if( ! pDisk->buf_flush_files[ bcount ] ) { printf( "Could not allocate string for filename\n" ); EndItAll( 1, pDisk ); } strcpy( pDisk->buf_flush_files[ bcount ], pDisk->tmp ); initfile( pDisk->tmp, BFLUSH_FILE_SIZE, pDisk ); bcount++; } fcount++; } } for( i = 0; i < NBFLUSH_FILES; i++ ) { /*read spacer files to flush buffers*/ if( ( pDisk->fd = open( pDisk->buf_flush_files[ i ], 2)) < 0 ) { printf( "error opening buffer flush file\n" ); EndItAll( 1, pDisk ); } lseek( pDisk->fd, 0L, 0 ); k = BFLUSH_FILE_SIZE / BUFFERSIZE; for( j = 0; j < k; j++ ) { if( ( pDisk->nbytes = read( pDisk->fd, pDisk->buffer, BUFFERSIZE )) < 0 ) { printf( "Error reading buffer flush file\n" ); EndItAll( 1, pDisk ); } } close( pDisk->fd ); } srand( SEED ); /*initialize random number generator*/ for( i = 0; i < NSETS; i++ ) { /*permutation for reading/writing*/ for( j = SET_SIZE; j > 0; j-- ) { k = my_rand( j ); strcpy( pDisk->tmp, pDisk->files[ i ][ j - 1 ] ); strcpy( pDisk->files[ i ][ j - 1 ], pDisk->files[ i ][ k ] ); strcpy( pDisk->files[ i ][ k ], pDisk->tmp ); } } }
int main(int argc, char* argv[]) { char c,d; unsigned long k; int i,j; FILE *fp; char buf[BUFLEN]; umask(0); if(mkfifo(FIFO,S_IFIFO|0660)<0) return -1; initfile(); if (!(ptr_auxMem = fopen(AUXILIARY_MEMORY, "r+"))) { do_error(ERROR_FILE_OPEN_FAILED); exit(1); } do_init(); do_print_info(); ptr_memAccReq = (Ptr_MemoryAccessRequest) malloc(sizeof(MemoryAccessRequest)); /* 在循环中模拟访存请求与处理过程 */ while(TRUE) { printf("请输入请求\n"); fp=fopen(FIFO,"r"); fgets(buf,sizeof(buf),fp); printf("Request is: %s\n",buf); fclose(fp); i=0; k=0; j=0; if(buf[i]=='r'||buf[i]=='w'||buf[i]=='x'){ c='a'; d=buf[i]; k=0; while(buf[i]<'0'||buf[i]>'9'){i++;} while(buf[i]>='0'&&buf[i]<='9'){ k=k*10+buf[i]-'0'; i++; } while(buf[i]<'0'||buf[i]>'9'){i++;} while(buf[i]>='0'&&buf[i]<='9'){ j=j*10+buf[i]-'0'; i++; } deal_request(d,k,j); do_response(); } else{ printf("无法识别命令"); } printf("按Y打印页表,按其他键不打印...\n"); fp=fopen(FIFO,"r"); fgets(buf,sizeof(buf),fp); fclose(fp); if (buf[0] == 'y' || buf[0] == 'Y') do_print_info(); printf("按X退出程序,按其他键继续...\n"); fp=fopen(FIFO,"r"); fgets(buf,sizeof(buf),fp); fclose(fp); if (buf[0] == 'e' || buf[0] == 'E') break; } /* while (TRUE) { do_request(); do_response(); printf("按Y打印页表,按其他键不打印...\n"); if ((c = getchar()) == 'y' || c == 'Y') do_print_info(); while (c != '\n') c = getchar(); printf("按X退出程序,按其他键继续...\n"); if ((c = getchar()) == 'x' || c == 'X') break; while (c != '\n') c = getchar(); //sleep(5000); }*/ if (fclose(ptr_auxMem) == EOF) { do_error(ERROR_FILE_CLOSE_FAILED); exit(1); } return (0); }