/* * Test for PARSER: parse "i1+i2" or "i1+i2+..." where "i-n" is an integer. */ FUNCTION main () { IMPORT TEXT vrsion[]; TEXT string[STRINGSIZ+1]; CODE parse(); struct SYNBLK sb; CODE code; COUNT dummy; /* define indexes for our list of pointers to states */ #define s0pt 0 #define s1pt 1 #define s2pt 2 #define s3pt 3 #define s4pt 4 #define EV_SUM PA_ACCEPT + 100 /* reference the action routines */ CODE doneact(), sumact(); /* define the state structures */ static struct SHFENT shift0[] = { EV_SUM, s1pt, /* to s1 on EV_SUM */ PA_NUM, s4pt, /* to s4 on a number */ PA_TABTERM}; static struct PSTATE s0 = {0, 0, NULL, NULL, shift0}; static PA_CODE red1[] = {EOS, PA_TABTERM}; /* reduce if EOS */ static struct SHFENT shift1[] = {'+', s2pt, PA_TABTERM}; static struct PSTATE s1 = {1, PA_ACCEPT, doneact, red1, shift1}; static struct SHFENT shift2[] = {PA_NUM, s3pt, PA_TABTERM}; static struct PSTATE s2 = {0, 0, NULL, NULL, shift2}; static PA_CODE red3[] = {EOS, '+', PA_TABTERM}; static struct PSTATE s3 = {3, EV_SUM, sumact, red3, NULL}; static PA_CODE red4[] = {EOS, '+', PA_TABTERM}; static struct PSTATE s4 = {1, EV_SUM, NULL, red4, NULL}; /* list of state pointers */ struct PSTATE *statelist[]= {&s0, &s1, &s2, &s3, &s4}; parser_init (statelist, sizeof(statelist)/sizeof(struct PSTATE *)); printf(" Parser test, version %s\n", vrsion); printf(" Enter a string "); t_init(&dummy, &dummy, &dummy); t_read(string, &dummy); for (; string[0]!='@';) /* exit on '@' */ { initok(&sb, string); code = parser(&sb, statelist, s0pt); /* call the parser */ printf("Parse complete. Success/fail: %d\n", code); printf(" Enter a string "); t_read(string, &dummy); } }
int main(int argc, char* argv[]) { std::thread t_read(data_reading); std::thread t_print(data_printing); t_print.join(); t_read.join(); }
int op_read(const int extra_flag) { // open int fd = t_open(tfs_name, ".jpg", T_READ|extra_flag, NULL); if (fd <= 0) { printf("get fd for read fail, ret: %d \n", fd); return TFS_ERROR; } // read int64_t len = 0; char buf[OP_SIZE]; if ((len = t_read(fd, buf, OP_SIZE/2)) < 0) { printf("read data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // lseek then read t_lseek(fd, OP_SIZE/3, T_SEEK_CUR); // read if ((len = t_read(fd, buf, OP_SIZE/2)) < 0) { printf("lseek and read data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // pread if ((len = t_pread(fd, buf, OP_SIZE/2, OP_SIZE/3)) < 0) { printf("pread data fail, ret: %" PRI64_PREFIX "d\n", len); return TFS_ERROR; } // close t_close(fd, NULL, 0); return TFS_SUCCESS; }
unsigned int main(register unsigned int argc, char* argv[]) { unsigned int fail = 0; /* success and golf are scored in the same way */ register unsigned int pos = 0; register unsigned int alloc_size; char ch[7]; char* edit_buffer; char* temp_buffer; t_getstate(&original); n_state = t_initstate(&original); t_setstate(&n_state); alloc_size = read_file(&edit_buffer, &fail); if (!fail) { temp_buffer = malloc(alloc_size); } while(!fail) { t_read(ch, 7); /* commands */ if (ch[0] == 27 && ch[1] == 'j' && ch[2] == 0) { /* alt+j - move backwards */ if(pos > 0) { pos -= 1; } } else if (ch[0] == 27 && ch[1] == 'k' && ch[2] == 0) { /* alt+k - move forwards */ if (pos < strlen(edit_buffer)) { pos += 1; } } else if (ch[0] == 27 && ch[1] == 'd' && ch[2] == 0) { /* alt+d - save file */ fputs(edit_buffer, stdout); } else if (ch[0] == 27 && ch[1] == 'f' && ch[2] == 0) { /* alt+f - quit program. Note: Don't hit this by accident. */ break; } else if (ch[0] == 127 && ch[1] == 0 && ch[2] == 0) { /* backspace - delete previous character */ if (pos > 0) { alloc_size = remove_char(pos, &edit_buffer, &temp_buffer, alloc_size, &fail); pos--; } } else if(ch[0] != 0 && ch[1] == 0 && ch[2] == 0) { /* add any other character pressed */ alloc_size = add_char(ch[0], pos, &edit_buffer, &temp_buffer, alloc_size, &fail); pos++; } } if (alloc_size > 0 && !fail) { free(edit_buffer); free(temp_buffer); } t_setstate(&original); fflush(stdout); return fail; };
int main(){ char ch[7]; /* the returns from the terminal are up to 6 chars long, 7th is for \0 */ i_setup(); while( 1 ){ t_read(ch, 7); printf("I got (%s)\n", ch); if( ch[0] == 27 && ch[1] == 0 ){ /* either escape or stray alt */ } if( ch[0] == 27 && ch[1] == 'q' && ch[2] == 0 ){ /* alt+q */ break; } } i_tidyup(); };
void initView() { if(glewInit() != GLEW_OK) { printf("Glew Init Error!"); return ; } glClearColor(0.0,0.0,0.0,1.0); glViewport(0,0,VIEW_W,VIEW_H); glGenBuffers(NumBuffers,buffers); glBindBuffer(GL_ARRAY_BUFFER,buffers[VERTEX]); glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_DYNAMIC_DRAW); glVertexAttribPointer(vPosition,2,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(0)); glEnableVertexAttribArray(vPosition); GLuint vShader = glCreateShader(GL_VERTEX_SHADER); GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER); const char* vSrc = t_read("tetris.vert"); const char* fSrc = t_read("tetris.frag"); glShaderSource(vShader,1,&vSrc,0); glShaderSource(fShader,1,&fSrc,0); glCompileShader(vShader); glCompileShader(fShader); GLint vStatus; GLint fStatus; glGetShaderiv(vShader,GL_COMPILE_STATUS,&vStatus); glGetShaderiv(fShader,GL_COMPILE_STATUS,&fStatus); if(!vStatus) { GLint infoLen; char* infoLog; glGetShaderiv(vShader,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*)malloc(infoLen); glGetShaderInfoLog(vShader,infoLen,NULL,infoLog); printf("vertex shader compile error:%s\n",infoLog); free(infoLog); } if(!fStatus) { GLint infoLen; char* infoLog; glGetShaderiv(fShader,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*) malloc(infoLen); glGetShaderInfoLog(fShader,infoLen,NULL,infoLog); printf("fragment shader compile error:%s\n",infoLog); free(infoLog); } if(!vStatus || !fStatus) return; GLuint program = glCreateProgram(); glAttachShader(program,vShader); glAttachShader(program,fShader); glLinkProgram(program); GLint pStatus; glGetProgramiv(program,GL_LINK_STATUS,&pStatus); if(!pStatus) { GLint infoLen; char* infoLog; glGetProgramiv(program,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*) malloc(infoLen); glGetProgramInfoLog(program,infoLen,NULL,infoLog); printf("program link error:%s\n",infoLog); free(infoLog); return; } glUseProgram(program); GLint mvpLoc = glGetUniformLocation(program,"mvp"); GLfloat mvp[] = { 2.0/WINDOW_WIDTH, 0.0, 0.0, 0.0, 0.0, -2.0/WINDOW_HEIGHT, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0 }; glUniformMatrix4fv(mvpLoc,1,GL_FALSE,mvp); vertices = (GLfloat*) calloc(MAX_SQUARES*8,sizeof(GLfloat)); }
GLuint LoadShaders(ShaderInfo* shaders) { printf("load shaders start\n"); GLuint vShader = glCreateShader(GL_VERTEX_SHADER); GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER); const char * vSrc; const char * fSrc; GLint *vLens = NULL; GLint *fLens = NULL; vSrc = t_read(shaders[0].filename); fSrc = t_read(shaders[1].filename); printf("read complete\n"); glShaderSource(vShader,1,&vSrc,0); glShaderSource(fShader,1,&fSrc,0); printf("start compile\n"); glCompileShader(fShader); glCompileShader(vShader); GLint vStatus; GLint fStatus; glGetShaderiv(vShader,GL_COMPILE_STATUS,&vStatus); glGetShaderiv(fShader,GL_COMPILE_STATUS,&fStatus); printf("vStatus:%d\n",vStatus); printf("fStatus:%d\n",fStatus); GLsizei vInfoLen; GLsizei fInfoLen; glGetShaderiv(vShader,GL_INFO_LOG_LENGTH,&vInfoLen); glGetShaderiv(fShader,GL_INFO_LOG_LENGTH,&fInfoLen); char *vInfoLog = (char*)malloc(vInfoLen); char *fInfoLog = (char*)malloc(fInfoLen); glGetShaderInfoLog(vShader,vInfoLen,&vInfoLen,vInfoLog); glGetShaderInfoLog(fShader,fInfoLen,&fInfoLen,fInfoLog); printf("Compile Vertex Shader:%s\n",vInfoLog); printf("Compile Fragment Shader:%s\n",fInfoLog); if(vStatus == GL_FALSE) { printf("vertex shader compile failed!\n"); return 0; } if(fStatus == GL_FALSE) { printf("fragment shader compile failed!\n"); return 0; } printf("compile complete\n"); printf("start create program\n"); GLuint program = glCreateProgram(); if(program == 0) { printf("Create Program Error!"); return 0; } glAttachShader(program,vShader); glAttachShader(program,fShader); printf("attach shader complete\n"); glLinkProgram(program); printf("link program complete\n"); GLint linked; glGetProgramiv(program,GL_LINK_STATUS,&linked); GLsizei infoLen; char infoLog[100]; glGetProgramInfoLog(program,100,&infoLen,infoLog); printf("Link program:%s\n",infoLog); printf("glGetProgramiv complete\n"); if(linked == GL_TRUE) { printf("Link success!"); return program; } else { printf("Link failed!"); return 0; } }
FUNCTION CODE tutohlp ( struct SFILE *pdf, /* in: PDF */ struct CONTXT *pctx, /* in: proc context */ struct TXTSTOR *title, /* out: block of .TITLE text (in dyn mem)*/ struct SFILE **ohf /* out: help file control block */ ) { TEXT field[STRINGSIZ+1]; CODE code; struct SFILE *hf; /* local version of ohf */ CODE terminat; TEXT libe[FLIBRSIZ+1]; struct CONTXT *ctx; BOOL sephelp; if ((*pctx).compiled || s_equal((*pctx).help_spec, "*")) /* if help info in PDF */ { sephelp = FALSE; hf = pdf; *ohf = hf; } else { sephelp = TRUE; if ((hf = (struct SFILE *) tae_alloc(1, sizeof(struct SFILE))) == NULL) goto over_err; *ohf = hf; if ((*pctx).intrinsic) code = f_open(hf, HELPLUN, HELPLIB, (*pctx).pdf.name, HLP_TYPE, F_READ); else { for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink); s_copy ((*ctx).pdf.libr, libe); code = f_opnspc(hf, HELPLUN, (*pctx).help_spec, libe, (*pctx).pdf.name, HLP_TYPE, F_READ); } if (code != SUCCESS) goto open_err; } code = tut_h_prep(pctx, hf, title); /* find & save posits at least thru .LEVEL1*/ if ((*pctx).compiled) tutctx.hlp_searched = TRUE; /* all searching done for compiled PDFs */ if (code != SUCCESS) goto prep_err; return(SUCCESS); over_err: tutmsg(msg_mmov, key_mmov, 0, 0, 0, 0, 0); /* dyn mem overflow */ tutctx.nohelpf = TRUE; goto prompt; open_err: tae_free((GENPTR)hf); *ohf = NULL; /* to keep cls_tutor from freeing */ tutctx.nohelpf = TRUE; return(SUCCESS); prep_err: tutctx.nohelpf = TRUE; if (sephelp) { f_close(hf, F_KEEP); tae_free((GENPTR)hf); sephelp = FALSE; *ohf = NULL; /* to keep cls_tutor from freeing */ } goto prompt; prompt: t_write("Do you wish to continue (Y/N)?", T_PROMPT); t_read(field, &terminat); if (s_lseq("Y", field)) return(SUCCESS); else return(FAIL); }
void initView() { glClearColor(0,0,0,1); glViewport(0,0,VIEW_W,VIEW_H); GLuint vbos[numVBOs]; glGenBuffers(numVBOs,vbos); glBindBuffer(GL_ARRAY_BUFFER,vbos[vertex]); int vSize = num_jewels * 16 * sizeof(GLfloat); vertices = (GLfloat*)malloc(vSize); memset(vertices,0,vSize); int iSize = num_jewels * 6 * sizeof(GLushort); indices = (GLushort*)malloc(iSize); memset(indices,0,iSize); dragXs = (float*) malloc(num_jewels * sizeof(float)); dragYs = (float*) malloc(num_jewels * sizeof(float)); // glBufferData(GL_ARRAY_BUFFER,4*4*sizeof(GLfloat),vertices,GL_STATIC_DRAW); memset(dragXs,0,num_jewels * sizeof(float)); memset(dragYs,0,num_jewels * sizeof(float)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,vbos[index]); // glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(GLushort),indices,GL_STATIC_DRAW); glVertexAttribPointer(a_postion,2,GL_FLOAT,GL_FALSE,4*sizeof(GLfloat),BUFFER_OFFSET(0)); glEnableVertexAttribArray(a_postion); glVertexAttribPointer(a_texCoord,2,GL_FLOAT,GL_FALSE,4*sizeof(GLfloat),BUFFER_OFFSET(2)); glEnableVertexAttribArray(a_texCoord); GLuint vShader = glCreateShader(GL_VERTEX_SHADER); GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER); const char* vSrc = t_read("jewel.vert"); const char* fSrc = t_read("jewel.frag"); glShaderSource(vShader,1,&vSrc,0); glShaderSource(fShader,1,&fSrc,0); glCompileShader(vShader); glCompileShader(fShader); GLint vStatus,fStatus; glGetShaderiv(vShader,GL_COMPILE_STATUS,&vStatus); glGetShaderiv(fShader,GL_COMPILE_STATUS,&fStatus); if(!vStatus) { GLint infoLen; char* infoLog; glGetShaderiv(vShader,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*) malloc(infoLen); glGetShaderInfoLog(vShader,infoLen,NULL,infoLog); printf("vertex shader compile error:%s\n",infoLog); free(infoLog); } if(!fStatus) { GLint infoLen; char* infoLog; glGetShaderiv(fShader,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*) malloc(infoLen); glGetShaderInfoLog(fShader,infoLen,NULL,infoLog); printf("fragment shader compile error:%s\n",infoLog); free(infoLog); } GLuint program = glCreateProgram(); glAttachShader(program,vShader); glAttachShader(program,fShader); glBindAttribLocation(program,a_postion,"a_position"); glBindAttribLocation(program,a_texCoord,"a_texCoord"); glLinkProgram(program); GLint pStatus; glGetProgramiv(program,GL_LINK_STATUS,&pStatus); if(!pStatus) { GLint infoLen; char* infoLog; glGetProgramiv(program,GL_INFO_LOG_LENGTH,&infoLen); infoLog = (char*) malloc(infoLen); glGetProgramInfoLog(program,infoLen,NULL,infoLog); printf("program link error:%s\n"); free(infoLog); } glUseProgram(program); GLint mvpLoc = glGetUniformLocation(program,"u_mvp"); GLfloat mvp[] = { 2.0/VIEW_W, 0.0, 0.0, 0.0, 0.0, -2.0/VIEW_H, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0 }; glUniformMatrix4fv(mvpLoc,1,GL_FALSE,mvp); GLuint textures[numTexs]; glGenTextures(numTexs,textures); glBindTexture(GL_TEXTURE_2D,textures[s_popo]); png_data_t png_data; if(!png_read("./Data/Jewels.png",&png_data)) { glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA, png_data.width,png_data.height,0, GL_RGBA,GL_UNSIGNED_BYTE,png_data.data); free(png_data.data); } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glPixelStorei(GL_PACK_ALIGNMENT, 1); GLint sampleLoc = glGetUniformLocation(program,"s_texture"); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,textures[s_popo]); glUniform1i(sampleLoc,0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); }
FUNCTION main () { struct SYNBLK sb; /* syntax block */ TEXT s[STRINGSIZ+1]; /* string buffer */ TEXT verb[TOKESIZ+1];/* verb */ TEXT key[TOKESIZ+1]; /* keyword */ TEXT *value[MAXVAL]; /* value pointers */ CODE code; COUNT count; COUNT tstnum; COUNT i; CODE dum; dumrout(&code, &tstnum); /* dummy - get addrs w/ debugger */ tstnum = 0; /* TEST 1 */ printf("\n TEST 1 \n"); s_copy("menu file=alpha a", s); initok(&sb, s); tstnum++; code = getvrb(&sb, verb); printf(" code: %d, verb: %s\n", code, verb); tstnum++; code = getkey(&sb, key); printf(" code: %d, key: %s\n", code, key); tstnum++; code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); tstnum++; code = chkend(&sb); tstnum++; /* TEST 2 */ printf("\n TEST 2 \n"); s_copy("menu (A, B, CDE) file = alpha", s); initok(&sb, s); code = getvrb(&sb, verb); printf(" code: %d, verb: %s\n", code, verb); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getkey(&sb, key); printf(" code: %d, key: %s\n", code, key); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = chkend(&sb); /* TEST 3 */ printf("\n TEST 3 \n"); s_copy("vrb ,(A,,C,) f,", s); initok(&sb, s); code = getvrb(&sb, verb); printf(" code: %d, verb: %s\n", code, verb); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); /* TEST 4 */ printf("\n TEST 4 \n"); s_copy("(\"aaa\", \"bbb\")", s); initok(&sb, s); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); /* TEST 5 */ printf("\n TEST 5 \n"); /* white space test */ s_copy("menu (A, B, CDE) file = alpha", s); initok(&sb, s); code = getvrb(&sb, verb); printf(" code: %d, verb: %s\n", code, verb); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getkey(&sb, key); printf(" code: %d, key: %s\n", code, key); code = getval(&sb, value, MAXVAL, &count); printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = chkend(&sb); /* USER TEST */ while (FOREVER) { printf("\n Enter a string of values:\n"); t_init(&dum, &dum, &dum); t_read(s, &dum); initok(&sb, s); code = getval(&sb, value, MAXVAL, &count); while (code !=EOS && code!=S_SYNERR) { printf(" code: %d, count: %d, values: \n", code, count); for (i=0; i<count; i++) printf(" %s\n", value[i]); code = getval(&sb, value, MAXVAL, &count); } } sb.errchr = sb.curchr - 1; synerr(&sb, "Test complete"); exit(TRUE); }