int main(int argc, char *argv[]) { float a = doMath(add, 10, 2); printf ("add test : %f\n", a); float b = doMath(subtract, 10, 2); printf ("subtract test : %f\n",b); return 0; }
void render() { static RECT rc = {0, 0, 320, 100}; // rectangular region.. used for text drawing static DWORD frameCount = 0; static DWORD startTime = clock(); char str[16]; doMath(); // do the math.. :-P frameCount++; // increment frame count // Clear the back buffer to a black... values r g b are 0-256 lpD3DDevice8->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER ,D3DCOLOR_XRGB(256, 256, 256), 1.0f, 0); // render the cubes myRect1->render(clock()); myRect2->render(clock()); // this function writes a formatted string to a character string // in this case.. it will write "Avg fps" followed by the // frames per second.. with 2 decimal places sprintf(str, "Avg fps %.2f", (float) frameCount / ((clock() - startTime) / 1000.0f)); // draw the text string.. lpD3DXFont->Begin(); lpD3DXFont->DrawText(str, -1, &rc, DT_LEFT, 0xFFFFFFFF); lpD3DXFont->End(); // present the back buffer.. or "flip" the page lpD3DDevice8->Present( NULL, NULL, NULL, NULL ); // these options are for using rectangular // regions for rendering/drawing... // 3rd is which target window.. NULL makes it use the currently set one (default) // last one is NEVER used.. that happens with DirectX often }
int Mission::doIMath(missionNode *node,int mode){ // debug(0,node,mode,"deprecated Imath"); varInst *math_vi=doMath(node,mode); if(math_vi->type!=VAR_INT){ fatalError(node,mode,"fmath expected int"); assert(0); } int res=math_vi->int_val; deleteVarInst(math_vi); return res; #if 0 // if(mode==SCRIPT_PARSE){ string mathname=node->attr_value("math"); int len=node->subnodes.size(); if(len<2){ fatalError(node,mode,"imath needs at least 2 arguments"); assert(0); } int res=checkIntExpr((missionNode *)node->subnodes[0],mode); char buffer[200]; sprintf(buffer,"imath: 1st expr returns %d",res); debug(4,node,mode,buffer); for(int i=1;i<len;i++){ int res2=checkIntExpr((missionNode *)node->subnodes[i],mode); if(mode==SCRIPT_RUN){ if(mathname=="+"){ res=res+res2; } else if(mathname=="-"){ res=res-res2; } else if(mathname=="*"){ res=res*res2; } else if(mathname=="/"){ res=res/res2; } else{ fatalError(node,mode,"no such imath expression"); assert(0); } } } if(mode==SCRIPT_RUN){ return res; } return 0; #endif }
varInst *Mission::checkExpression(missionNode *node,int mode){ varInst *ret=NULL; debug(3,node,mode,"checking expression"); // printRuntime(); switch(node->tag){ case DTAG_AND_EXPR: case DTAG_OR_EXPR: case DTAG_NOT_EXPR: case DTAG_TEST_EXPR: { bool res=checkBoolExpr(node,mode); ret=newVarInst(VI_TEMP); ret->type=VAR_BOOL; ret->bool_val=res; return ret; } break; case DTAG_CONST: { ret=doConst(node,mode); return ret; } break; case DTAG_VAR_EXPR: { ret=doVariable(node,mode); return ret; } break; case DTAG_FMATH: { ret=doMath(node,mode); return ret; } break; case DTAG_CALL: { ret=doCall(node,mode); return ret; } break; case DTAG_EXEC: { ret=doExec(node,mode); return ret; } break; default: fatalError(node,mode,"no such expression"); assert(0); break; } return ret; }
static int test_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { printf("test_Read\n"); size_t len; (void) fi; int i = 0; int found = 0; for(i=1;i<8;i++){ //meant for docs if (strcmp(path,docNames[i])==0){ found = 1; break; } } if(found==1){ len = strlen(documents[i]); if (offset < len) { if (offset + size > len) size = len - offset; memcpy(buf, documents[i] + offset, size); //storing the string into buf. } else size = 0; return size; } double ans; char* myBuffer; char** ptr = parse(path); int choice = getFunction(ptr); printf("CHOICE_read: %d\n",choice); printf("LINE: %d\n", __LINE__); printf("ptr_read: %s\n",ptr[0]); printf("LINE: %d\n", __LINE__); if(choice == -1){ return -ENOENT; } else{ if(choice == 4 && strcmp(ptr[2],"0")==0){ myBuffer = malloc(sizeof(char)*100); myBuffer = strcpy(myBuffer,"Divide by zero error"); len = strlen(myBuffer); myBuffer[len] = '\n'; myBuffer[len+1] = '\0'; len = len+1; } else if((choice == 5 || choice == 7) && isDouble(ptr[1])){ myBuffer = malloc(sizeof(char)*100); myBuffer = strcpy(myBuffer, "number to factor must be integer"); len = strlen(myBuffer); myBuffer[len] = '\n'; myBuffer[len+1] = '\0'; len = len+1; } else if((choice == 5 || choice == 7) && isNumber(ptr[1]) && ptr[2] == NULL){ myBuffer = malloc(sizeof(char)*1000); char * ff_ans = doMoreMath(choice, ptr[1]); printf("ff_ans is %s\n",ff_ans); myBuffer = strcpy(myBuffer,ff_ans); len = strlen(myBuffer); myBuffer[len] = '\0'; printf("mybuffer is %s\n",myBuffer); len = len + 1; } else{ myBuffer = malloc(sizeof(char)*100); ans = doMath(choice,ptr[1],ptr[2]); len = sprintf(myBuffer,"%f",ans); myBuffer[len]='\n'; myBuffer[len+1]='\0'; len = len+1; } printf("LINE: %d\n", __LINE__); printf("ANSWER_read: %f\n",ans); if(offset < len){ if(offset + size > len) size = len - offset; printf("LINE: %d\n", __LINE__); memcpy(buf, myBuffer+offset, size); } else size = 0; printf("LINE: %d\n", __LINE__); return size; } }
// Sets the size of our files in preparation for test_read // filters directories and files static int test_getattr(const char *path, struct stat *stbuf) { int i =0; int res = 0; char** ptr = parse(path); int choice = getFunction(ptr); double ans; int length; char* myBuffer; memset(stbuf, 0, sizeof(struct stat)); for(i=0;i<8;i++){ //path = mountpoint "/" if (strcmp(path, functions[i]) == 0) { stbuf->st_mode = S_IFDIR | 0755; //0755 = Admin can do all. Rest can read+exec stbuf->st_nlink = 3; return res; } else if(strcmp(path, docNames[i])==0){ //0444 = Read only //Call math functions through here. Example: /add/3/3 stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = strlen(documents[i]); return res; } } printf("THE CHOICE_getattr: %d\n",choice); printf("THE ptr_getattr: %s\n",ptr[0]); if(choice!=-1){ if((((choice>=1 && choice<=4) || choice==6) && isNumber(ptr[1])!=0 && ptr[2]==NULL) || ((choice ==7 || choice == 5) && ptr[1]==NULL && ptr[2]==NULL)) { stbuf->st_mode = S_IFDIR | 0755; //0755 = Admin can do all. Rest can read+exec stbuf->st_nlink = 3; return res; } else if((((choice>=1 && choice<=4) || choice==6) && isNumber(ptr[1])!=0 && isNumber(ptr[2])!=0) || ((choice ==7 || choice == 5) && isNumber(ptr[1])!=0 && ptr[2]==NULL)){ printf("WE GOT MATH\n"); stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; if(choice == 4 && strcmp(ptr[2],"0")==0){ myBuffer = malloc(sizeof(char)*100); myBuffer = strcpy(myBuffer, "Divide by zero error"); length = strlen(myBuffer); printf("LENGTH: %d\n",length); stbuf->st_size = length+1; } else if(choice == 6 && doMath(6,ptr[1],ptr[2])==HUGE_VAL){ myBuffer = malloc(sizeof(char)*100); myBuffer = strcpy(myBuffer, "Exponential overflow"); length = strlen(myBuffer); printf("LENGTH: %d\n",length); stbuf->st_size = length+1; } else if((choice == 5 || choice == 7) && isDouble(ptr[1])){ myBuffer = malloc(sizeof(char)*100); myBuffer = strcpy(myBuffer, "number to factor must be integer"); length = strlen(myBuffer); stbuf->st_size = length+1; } else if((choice == 5 || choice == 7) && isNumber(ptr[1])!=0 && ptr[2]==NULL){ myBuffer = malloc(sizeof(char)*1000); printf("LINE: %d\n", __LINE__); char * ff_ans = doMoreMath(choice, ptr[1]); myBuffer = strcpy(myBuffer, ff_ans); length = strlen(myBuffer); stbuf->st_size = length; } else{ myBuffer = malloc(sizeof(char)*100); ans = doMath(choice,ptr[1],ptr[2]); length = sprintf(myBuffer,"%f",ans); stbuf->st_size = length+1; } free(myBuffer); return res; } } res = -ENOENT; return res; }
void render() { static RECT rc = {0, 0, 320, 100}; // rectangular region.. used for text drawing static DWORD frameCount = 0; static DWORD startTime = clock(); char str[16]; DWORD val; doMath(); // do the math.. :-P frameCount++; // increment frame count // Clear the back buffer to a black... values r g b are 0-256 lpD3DDevice8->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(256, 256, 256), 1.0f, 0); lpD3DDevice8->GetRenderState(D3DRS_LIGHTING, &val); if (val) { D3DLIGHT8 light; // structure for light data ZeroMemory( &light, sizeof(D3DLIGHT8) ); // zero the mem light.Type = D3DLIGHT_POINT; // set type, either SPOT, DIRECTIONAL, or POINT // light being put onto objects.. light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; // ambient light of the light source.. only on when light is on light.Ambient.r = 0.25f; light.Ambient.g = 0.25f; light.Ambient.b = 0.25f; // attenuation = Atten0 + Atten1 * d + Atten2 * d * d; // where d is distance // attenuation is decreasing brightness as // a vertex is further away from the light source light.Attenuation0 = .5f; light.Attenuation1 = 0.10f; light.Attenuation2 = 0.01f; // spot lights and directional lights also have a direction // but a POINT light shines in all directions.. kinda like a light bulb light.Position = D3DXVECTOR3(0, 0, -2); light.Range = 15; // after this range the light doesn't affect vertices lpD3DDevice8->SetLight( 0, &light ); // set the light as index 0 lpD3DDevice8->LightEnable( 0, true ); // enable light at index 0 // ambient light.. for everything.. not attached to // this light, just lighting in general lpD3DDevice8->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); } // render the cubes myRect1->render(clock()); myRect2->render(clock()); myRect3->render(clock()); myRect4->render(clock()); myRect5->render(clock()); // this function writes a formatted string to a character string // in this case.. it will write "Avg fps" followed by the // frames per second.. with 2 decimal places sprintf(str, "Avg fps %.2f", (float) frameCount / ((clock() - startTime) / 1000.0f)); // draw the text string.. lpD3DXFont->Begin(); lpD3DXFont->DrawText(str, -1, &rc, DT_LEFT, 0xFFFFFFFF); lpD3DXFont->End(); // present the back buffer.. or "flip" the page lpD3DDevice8->Present( NULL, NULL, NULL, NULL ); // these options are for using rectangular // regions for rendering/drawing... // 3rd is which target window.. NULL makes it use the currently set one (default) // last one is NEVER used.. that happens with DirectX often }