/*---------------------------------------------------------------------------- str_casestr() Same as the strstr() library function except it ignores case. Adapted from the original strstr() routine (C)as above. ---------------------------------------------------------------------------*/ char *str_casestr(char *string, char *substring) { register char *a, *b; /* First scan quickly through the two strings looking for a * single-character match. When it's found, then compare the * rest of the substring. */ b = substring; if (*b == 0) { return string; } for ( ; *string != 0; string += 1) { if (locase(*string) != locase(*b)) { continue; } a = string; while (1) { if (*b == 0) { return string; } if (locase(*a) != locase(*b)) { a++; b++; break; } a++; b++; } b = substring; } return (char *) 0; }
static void pprogramdef (definition * def) { version_list *vers; proc_list *proc; #if 0 static int puttbl; if (!puttbl) { puttbl = 1; f_print (fout, "#ifndef _RPCGEN_TABLE_DEFINED_\n" "#define _RPCGEN_TABLE_DEFINED_ 1\n" "#ifndef RPCGEN_ACTION\n" "#define RPCGEN_ACTION(x) 0\n" "#endif /* !RPCGEN_ACTION */\n" "struct rpcgen_table {\n" " char *(*proc)();\n" " xdrproc_t xdr_arg;\n" " unsigned len_arg;\n" " xdrproc_t xdr_res;\n" " unsigned len_res;\n" "};\n" "\n" "struct rpc_program {\n" " u_int32_t progno;\n" " u_int32_t versno;\n" " const struct rpcgen_table *tbl;\n" " size_t nproc;\n" "};\n" "#endif /* !_RPCGEN_TABLE_DEFINED_ */\n\n"); } #endif pargdef (def); puldefine (def->def_name, def->def.pr.prog_num); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print (fout, "RPC_EXTERN const struct rpcgen_table %s_%s_table[];\n", locase (def->def_name), vers->vers_num); f_print (fout, "RPC_EXTERN const int %s_%s_nproc;\n", locase (def->def_name), vers->vers_num); f_print (fout, "RPC_EXTERN const struct rpc_program %s_%s;\n", locase (def->def_name), vers->vers_num); } puldefine (vers->vers_name, vers->vers_num); for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed (proc, def->def.pr.versions)) puldefine (proc->proc_name, proc->proc_num); #if 0 pprocdef (proc, vers, "CLIENT *", 0, 0); pprocdef (proc, vers, "struct svc_req *", 1, 0); #endif } } }
static void pprogramdef(definition *def) { version_list *vers; proc_list *proc; int i; const char *ext; pargdef(def); puldefine(def->def_name, def->def.pr.prog_num); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", locase(def->def_name), vers->vers_num); f_print(fout, "extern %s_%s_nproc;\n", locase(def->def_name), vers->vers_num); } puldefine(vers->vers_name, vers->vers_num); /* * Print out 3 definitions, one for ANSI-C, another for C++, * a third for old style C */ for (i=0;i<3;i++) { if (i==0) { f_print(fout,"\n#ifdef __cplusplus\n"); ext="extern \"C\" "; } else if (i==1) { f_print(fout,"\n#elif __STDC__\n"); ext="extern " ; } else { f_print(fout,"\n#else /* Old Style C */ \n"); ext="extern "; } for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { puldefine(proc->proc_name, proc->proc_num); } f_print(fout,"%s",ext); pprocdef(proc, vers, "CLIENT *", 0,i); f_print(fout,"%s",ext); pprocdef(proc, vers, "struct svc_req *", 1,i); } } f_print(fout,"#endif /* Old Style C */ \n"); } }
char *WUser::nam(int nUserNumber) const { static char s_szNamBuffer[255]; bool f = true; unsigned int p = 0; for (p = 0; p < strlen(this->GetName()); p++) { if (f) { unsigned char* ss = reinterpret_cast<unsigned char*>(strchr(reinterpret_cast<char*>(translate_letters[ 1 ]), data.name[ p ])); if (ss) { f = false; } s_szNamBuffer[ p ] = data.name[ p ]; } else { char* ss = strchr(reinterpret_cast<char*>(translate_letters[ 1 ]), data.name[ p ]); if (ss) { s_szNamBuffer[ p ] = locase(data.name[ p ]); } else { if ((data.name[ p ] >= ' ' && data.name[ p ] <= '/') && data.name[ p ] != 39) { f = true; } s_szNamBuffer[ p ] = data.name[ p ]; } } } s_szNamBuffer[ p++ ] = ' '; s_szNamBuffer[ p++ ] = '#'; snprintf(&s_szNamBuffer[p], sizeof(s_szNamBuffer) - p, "%d", nUserNumber); return s_szNamBuffer; }
tree evaluate_change_case (tree t, tree nc, bool evaluate_flag, bool first) { if (is_atomic (t)) { string s= t->label; tree r= copy (s); int i, n= N(s); bool all= true; bool up = false; bool lo = false; if (nc == "Upcase") { all= false; up= true; } else if (nc == "UPCASE") { up= true; } else if (nc == "locase") { lo= true; } for (i=0; i<n; tm_char_forwards (s, i)) if (is_iso_alpha (s[i]) && (all || (first && (i==0)))) { if (up && is_locase (s[i])) r->label[i]= upcase (s[i]); if (lo && is_upcase (s[i])) r->label[i]= locase (s[i]); } r->obs= list_observer (ip_observer (obtain_ip (t)), r->obs); return r; } else if (is_concat (t)) { int i, n= N(t); tree r (t, n); for (i=0; i<n; i++) r[i]= evaluate_change_case (t[i], nc, evaluate_flag, first && (i==0)); r->obs= list_observer (ip_observer (obtain_ip (t)), r->obs); return r; } else { if (evaluate_flag) return t; else return evaluate_change_case (evaluate (t), nc, true, first); } }
char * make_argname(const char *pname, const char *vname) { char *name; name = xmalloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); return (name); }
char * make_argname (char *pname, char *vname) { char *name; name = (char *) malloc (strlen (pname) + strlen (vname) + strlen (ARGEXT) + 3); if (!name) { fprintf (stderr, "failed in malloc"); exit (1); } sprintf (name, "%s_%s_%s", locase (pname), vname, ARGEXT); return (name); }
static void pprogramdef(definition *def, int headeronly) { version_list *vers; proc_list *proc; const char *ext; pargdef(def); puldefine(def->def_name, def->def.pr.prog_num); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", locase(def->def_name), vers->vers_num); f_print(fout, "extern %s_%s_nproc;\n", locase(def->def_name), vers->vers_num); } puldefine(vers->vers_name, vers->vers_num); f_print(fout, "\n"); ext = "extern "; if (headeronly) { f_print(fout, "%s", ext); pdispatch(def->def_name, vers->vers_num); } for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { puldefine(proc->proc_name, proc->proc_num); } f_print(fout, "%s", ext); pprocdef(proc, vers, "CLIENT *", 0); f_print(fout, "%s", ext); pprocdef(proc, vers, "struct svc_req *", 1); } pfreeprocdef(def->def_name, vers->vers_num); } }
static void pprogramdef(definition *def) { version_list *vers; proc_list *proc; pargdef(def); puldefine(def->def_name, def->def.pr.prog_num); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", locase(def->def_name), vers->vers_num); f_print(fout, "extern %s_%s_nproc;\n", locase(def->def_name), vers->vers_num); } puldefine(vers->vers_name, vers->vers_num); for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { puldefine(proc->proc_name, proc->proc_num); } } } /* * Print out 3 definitions, one for ANSI-C, another for C++, a * third for old style C */ f_print(fout, "\n"); cplusplusstart(); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { for (proc = vers->procs; proc != NULL; proc = proc->next) { pprocdef(proc, vers, "CLIENT *", 0); pprocdef(proc, vers, "struct svc_req *", 1); } } cplusplusend(); }
char * make_argname(const char *pname, const char *vname) { char *name; size_t len; len = strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3; name = malloc(len); if (!name) { fprintf(stderr, "failed in malloc"); exit(1); } snprintf(name, len, "%s_%s_%s", locase(pname), vname, ARGEXT); return (name); }
static void command (int cmd) { cmd = locase (cmd); if (cmd == ' ') { reset(); } else if (cmd == 'a') { tilt(); } else if (cmd == 't') { show_contacts = !show_contacts; } else if (cmd == '1') { write_world = true; } }
char *hpfs_translate_name(struct super_block *s, unsigned char *from, unsigned len, int lc, int lng) { char *to; int i; if (hpfs_sb(s)->sb_chk >= 2) if (hpfs_is_name_long(from, len) != lng) { printk("HPFS: Long name flag mismatch - name "); for (i=0; i<len; i++) printk("%c", from[i]); printk(" misidentified as %s.\n", lng ? "short" : "long"); printk("HPFS: It's nothing serious. It could happen because of bug in OS/2.\nHPFS: Set checks=normal to disable this message.\n"); } if (!lc) return from; if (!(to = kmalloc(len, GFP_KERNEL))) { printk("HPFS: can't allocate memory for name conversion buffer\n"); return from; } for (i = 0; i < len; i++) to[i] = locase(hpfs_sb(s)->sb_cp_table,from[i]); return to; }
static void write_table (definition * def) { version_list *vp; proc_list *proc; int current; int expected; char progvers[100]; int warning; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { warning = 0; s_print (progvers, "%s_%s", locase (def->def_name), vp->vers_num); /* print the table header */ f_print (fout, tbl_hdr, progvers); if (nullproc (vp->procs)) { expected = 0; } else { expected = 1; f_print (fout, "%s", null_entry); } for (proc = vp->procs; proc != NULL; proc = proc->next) { current = atoi (proc->proc_num); if (current != expected++) { f_print (fout, "\n/*\n * WARNING: table out of order\n */\n"); if (warning == 0) { f_print (stderr, "WARNING %s table is out of order\n", progvers); warning = 1; nonfatalerrors = 1; } expected = current + 1; } f_print (fout, " {\n\t(char *(*)())RPCGEN_ACTION("); /* routine to invoke */ if (!newstyle) pvname_svc (proc->proc_name, vp->vers_num); else { if (newstyle) f_print (fout, "_"); /* calls internal func */ pvname (proc->proc_name, vp->vers_num); } f_print (fout, "),\n"); /* argument info */ if (proc->arg_num > 1) printit ((char *) NULL, proc->args.argname); else /* do we have to do something special for newstyle */ printit (proc->args.decls->decl.prefix, proc->args.decls->decl.type); /* result info */ printit (proc->res_prefix, proc->res_type); f_print (fout, " },\n"); } /* print the table trailer */ f_print (fout, "%s", tbl_end); f_print (fout, tbl_nproc, progvers, progvers, progvers); f_print (fout, "const struct rpc_program_tc %s = {\n" "\t%s, %s, %s_table,\n" "\tsizeof (%s_table) / sizeof (%s_table[0])\n" "};\n\n", progvers, def->def_name, vp->vers_num, progvers, progvers, progvers); } }
static void command (int cmd) { size_t i; int k; dReal sides[3]; dMass m; int setBody; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'y') { setBody = 0; if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i if (obj[i].body) { dBodyDestroy (obj[i].body); } for (k=0; k < GPB; k++) { if (obj[i].geom[k]) { dGeomDestroy (obj[i].geom[k]); } } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1 + platpos[0], dRandReal()*2-1 + platpos[1], dRandReal()+2 + platpos[2]); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dBodySetPosition (obj[i].body, platpos[0], platpos[1], platpos[2]+2); dRSetIdentity (R); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*) i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } else if (cmd == 'y') { dMassSetCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } if (!setBody) for (k=0; k < GPB; k++) { if (obj[i].geom[k]) { dGeomSetBody (obj[i].geom[k],obj[i].body); } } dBodySetMass (obj[i].body,&m); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } else if (cmd == '1') { write_world = 1; } else if (cmd == ' ') { mov_time = 0; } else if (cmd == 'm') { mov_type = mov_type==1 ? 2 : 1; mov_time = 0; } }
static void command (int cmd) { size_t i; int j,k; dReal sides[3]; dMass m; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' /* || cmd == 'l' */) { if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+2); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*) i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCappedCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCCylinder (space,sides[0],sides[1]); } /* // cylinder option not yet implemented else if (cmd == 'l') { sides[1] *= 0.5; dMassSetCappedCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } */ else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'x') { dGeomID g2[GPB]; // encapsulated geometries dReal dpos[GPB][3]; // delta-positions for encapsulated geometries // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { obj[i].geom[k] = dCreateGeomTransform (space); dGeomTransformSetCleanup (obj[i].geom[k],1); if (k==0) { dReal radius = dRandReal()*0.25+0.05; g2[k] = dCreateSphere (0,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { g2[k] = dCreateBox (0,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; g2[k] = dCreateCCylinder (0,radius,length); dMassSetCappedCylinder (&m2,DENSITY,3,radius,length); } dGeomTransformSetGeom (obj[i].geom[k],g2[k]); // set the transformation (adjust the mass too) dGeomSetPosition (g2[k],dpos[k][0],dpos[k][1],dpos[k][2]); dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); dMatrix3 Rtx; dRFromAxisAndAngle (Rtx,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dGeomSetRotation (g2[k],Rtx); dMassRotate (&m2,Rtx); // add to the total mass dMassAdd (&m,&m2); } // move all encapsulated objects so that the center of mass is (0,0,0) for (k=0; k<2; k++) { dGeomSetPosition (g2[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); } for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomSetBody (obj[i].geom[k],obj[i].body); } dBodySetMass (obj[i].body,&m); } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } else if (cmd == '1') { write_world = 1; } }
void pvname(char *pname, char *vnum) { f_print(fout, "%s_%s", locase(pname), vnum); }
/*============================================================================= Function main Purpose: The main entry point of the program. This function contains the major server accept/process cycle for the program. Parameters: argc (IN) - number of command line arguments passed to program. *argv[] (IN) - array of char *'s to the arguments. Returns: Since this is a server it operates indefinitely and isn't expected to return. It will however, exit with an error code if an unrecoverable error condition results. =============================================================================*/ int main(int argc, char *argv[]) { int sd, /* server socket */ sd2, /* spawned socket */ addlen, /* length of sockaddr */ bytesRead, /* holds bytes read from a recv call */ buffLeft, /* used to keep track of space left in buffer */ useSelection = F; /* keeps track of whether or not we use selection */ long selection, /* the passed in selection parameter, if present */ port; /* port that server listens on */ struct sockaddr_in sad; /* server sockaddr */ struct sockaddr_in cad; /* client sockaddr */ struct protoent *ptrp; /* pointer to protocol table entry */ char inBuffer[WEB_BUFF_SIZE]; /* buffer for recv calls */ char request[WEB_BUFF_SIZE]; /* buffer to hold the request */ char command[MAX_CMD]; /* command from request */ char path[MAX_FILE_NAME]; /* path of requested page */ char version[MAX_VERS]; /* version of request */ char filename[MAX_FILE_NAME]; /* full path to requested file */ char filepath[MAX_FILE_NAME]; /* path to requested file */ char *p; /* char pointer used in string processing */ FILE *fp; /* used to open the requested file */ char urls[MAX_REFS][MAX_REF_LEN]; /* holds the references parsed from requested page */ char lo_url[MAX_REF_LEN]; /* used to hold a low case copy of a reference */ int numRefs; /* number of references parsed from the requested page */ /* ignoring the SIGPIPE signal for this program */ signal(SIGPIPE, SIG_IGN); /* set up the sad structure */ memset((char *)&sad,0,sizeof(sad)); /* clear the sockaddr structure */ sad.sin_family = AF_INET; /* family is internet */ sad.sin_addr.s_addr = INADDR_ANY; /* set the local IP address */ /* check for the passed in port number */ if (argc<2) { fprintf(stderr,"Proper usage is %s port [selection]\n"); exit(1); } /* need to check for non integer and out of range here */ port = strtol(argv[1],&p,0); if (p==argv[1]) { fprintf(stderr,"Port number must be numeric.\n"); exit(1); } else if (port<MIN_PORT || port>MAX_PORT) { fprintf(stderr,"Port out of range.\n"); exit(1); } sad.sin_port = htons((u_short)port); /* check for the passed in selection */ if (argc>2) { /* checking for non integer and out of range */ selection = strtol(argv[2],&p,0); if (p==argv[2]) { fprintf(stderr,"Selection must be numeric.\n"); exit(1); } else if (errno==ERANGE) { fprintf(stderr,"Selection is an invalid value.\n"); exit(1); } else { useSelection = T; selection-=1; /* our array is 0 based */ } } /* map the tcp transport protocol name to protocol number */ if (((int)(ptrp = getprotobyname("tcp"))) == 0) { /* unable to map tcp to protocol number report Internal server error */ fprintf(stderr,"Unable to map tcp to protocol number.\n"); exit(1); } /* attempt to create the socket */ if ((sd = socket(PF_INET, SOCK_STREAM, ptrp->p_proto)) < 0) { fprintf(stderr,"An error occured creating the socket.\n"); exit(1); } /* try to bind to a chosen port */ if (bind(sd, (struct sockaddr *)&sad, sizeof(sad)) < 0) { fprintf(stderr,"An error occured binding to a port.\n"); close(sd); exit(1); } /* sets the size of the queue */ if (listen(sd, QUEUE_SIZE) < 0) { fprintf(stderr,"An error occured on listen.\n"); close(sd); exit(1); } /* main loop */ while (1) { addlen = sizeof(cad); if ((sd2=accept(sd, (struct sockaddr *)&cad, &addlen)) < 0) { /* check for Solaris interrupted by signal failure */ /* or connection aborted,if this is the case continue loop */ if (sd2==-1 && (errno==EINTR || errno==ECONNABORTED)) continue; fprintf(stderr,"An error occured on accept: %d.\n",errno); close(sd); exit(1); } /* blank out the request buffer */ request[0] = 0; /* a while loop to read the request header of a size up to */ /* WEB_BUFF_SIZE */ while ((strstr(request,"\r\n\r\n")==NULL) && (strlen(request)<WEB_BUFF_SIZE-1) && (bytesRead=recv(sd2,inBuffer,sizeof(inBuffer),0))>0) { /* null terminate if room, makes the strncat below do less work */ if (bytesRead<WEB_BUFF_SIZE) inBuffer[bytesRead] = 0; /* leave one space for the null character */ buffLeft = WEB_BUFF_SIZE - strlen(request) - 1; strncat(request,inBuffer,buffLeft); } #ifdef DEBUG /* print the request header that has been received */ printf("request received:\n%s\n",request); #endif /* parse the command, filename, and version out of the request */ if ((sscanf(request, "%s %s %s", command, path, version))<3) { send(sd2,STATUS_400,strlen(STATUS_400),0); /* bad request */ close(sd2); continue; } #ifdef DEBUG printf("command: %s\n",command); printf("path: %s\n",path); printf("version: %s\n",version); #endif if (strcmp(command,"GET")!=0) { send(sd2,STATUS_501,strlen(STATUS_501),0); /* not implemented */ close(sd2); continue; } /* set up the filename with full path to file to load for parsing */ strcpy(filename,HOME); strncat(filename,path,sizeof(filename)-strlen(filename)-1); /* set up the filepath with the path to file to load for parsing */ strcpy(filepath,filename); p = strrchr(filepath,'/'); if (p==NULL) { /* this actually should never happen */ send(sd2,STATUS_400,strlen(STATUS_400),0); /* bad request */ close(sd2); continue; } *p = 0; /* chop off the string at that point */ #ifdef DEBUG /* print out the name of the file/path used on the inital read */ printf("requested file: %s\n",filename); printf("requested path: %s\n",filepath); #endif if (!extMatch(filename,".html") && !extMatch(filename,".htm")) { /* this is a fix to keep Netscape 4.7 happy by sending a "fake" */ /* .css or .js file */ if (extMatch(filename,".css")) send(sd2,CSS,strlen(CSS),0); else if (extMatch(filename,".js")) send(sd2,JS,strlen(JS),0); else send(sd2,STATUS_400,strlen(STATUS_400),0); /* bad request*/ } else { /* now try to open the requested file */ if ((fp = fopen(filename,"r"))==NULL) { if (errno==EACCES) send(sd2,STATUS_403,strlen(STATUS_403),0); /* forbidden */ else send(sd2,STATUS_404,strlen(STATUS_404),0); /* not found */ } else { /* parse the refs out of the file and return them in urls */ numRefs = parseRefs(fp,urls,MAX_REFS); fclose(fp); if (numRefs==0) send(sd2,STATUS_404,strlen(STATUS_404),0); /* not found */ else { if (useSelection) useSelection = F; /* only use select once! */ else selection = random() % numRefs; if (selection<0 || selection>numRefs-1) { /* select out of range */ send(sd2,STATUS_404,strlen(STATUS_404),0); /* ~ found*/ close(sd2); close(sd); #ifdef DEBUG printf("Closing - selection out of range.\n"); #endif exit(0); /* and then shutdown if out of range */ } else { /* make a lower case copy of the url so that we can */ /* do all lower case string comparisons */ strcpy(lo_url,urls[selection]); locase(lo_url); if (strncmp(lo_url,"http://",7)==0) { proxySend(sd2, urls[selection]); } else { /* if not http://, must be a path on the server */ /* find out if absolute or relative reference */ /* and then set up filename with the proper name */ if (urls[selection][0]=='/') strcpy(filename,urls[selection]); /* absolute*/ else { strcpy(filename,filepath); /* relative */ /* making sure not to overflow on these */ strncat(filename,"/", sizeof(filename)-strlen(filename)-1); strncat(filename, urls[selection], sizeof(filename)-strlen(filename)-1); } localSend(sd2, filename); } } } } } /* close the spawned socket */ #ifdef DEBUG printf("closing spawned socket.\n"); #endif close(sd2); } }
static void command (int cmd) { int i,j,k; dReal sides[3]; dMass m; bool setBody = false; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' || cmd == 'v' /* || cmd == 'l' */) { if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+1); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*)(size_t)i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } /* // cylinder option not yet implemented else if (cmd == 'l') { sides[1] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } */ else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'x') { setBody = true; // start accumulating masses for the composite geometries dMass m2; dMassSetZero (&m); dReal dpos[GPB][3]; // delta-positions for composite geometries dMatrix3 drot[GPB]; // set random delta positions for (j=0; j<GPB; j++) for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; for (k=0; k<GPB; k++) { if (k==0) { dReal radius = dRandReal()*0.25+0.05; obj[i].geom[k] = dCreateSphere (space,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { obj[i].geom[k] = dCreateBox(space,sides[0],sides[1],sides[2]); dMassSetBox(&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; obj[i].geom[k] = dCreateCapsule(space,radius,length); dMassSetCapsule(&m2,DENSITY,3,radius,length); } dRFromAxisAndAngle(drot[k],dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dMassRotate(&m2,drot[k]); dMassTranslate(&m2,dpos[k][0],dpos[k][1],dpos[k][2]); // add to the total mass dMassAdd(&m,&m2); } for (k=0; k<GPB; k++) { dGeomSetBody(obj[i].geom[k],obj[i].body); dGeomSetOffsetPosition(obj[i].geom[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); dGeomSetOffsetRotation(obj[i].geom[k], drot[k]); } dMassTranslate(&m,-m.c[0],-m.c[1],-m.c[2]); dBodySetMass(obj[i].body,&m); } else if (cmd == 'v') { dMassSetBox (&m,DENSITY,0.25,0.25,0.25); obj[i].geom[0] = dCreateConvex(space, planes, planecount, points, pointcount, polygons); } if (!setBody) { // avoid calling for composite geometries for (k=0; k < GPB; k++) if (obj[i].geom[k]) dGeomSetBody(obj[i].geom[k],obj[i].body); dBodySetMass(obj[i].body,&m); } } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } }
static void command (int cmd) { int i,j,k; dReal sides[3]; dMass m; bool setBody = false; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' || cmd == 'm' || cmd == 'y' || cmd == 'v') { if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+3); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*)(size_t)i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } else if (cmd == 'v') { dMassSetBox (&m,DENSITY,0.25,0.25,0.25); obj[i].geom[0] = dCreateConvex(space, planes, planecount, points, pointcount, polygons); } else if (cmd == 'y') { sides[1] *= 0.5; dMassSetCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'm') { dTriMeshDataID new_tmdata = dGeomTriMeshDataCreate(); dGeomTriMeshDataBuildSingle(new_tmdata, &Vertices[0], 3 * sizeof(float), VertexCount, (dTriIndex*)&Indices[0], IndexCount, 3 * sizeof(dTriIndex)); dGeomTriMeshDataPreprocess2(new_tmdata, (1U << dTRIDATAPREPROCESS_BUILD_FACE_ANGLES), NULL); obj[i].geom[0] = dCreateTriMesh(space, new_tmdata, 0, 0, 0); // remember the mesh's dTriMeshDataID on its userdata for convenience. dGeomSetData(obj[i].geom[0], new_tmdata); dMassSetTrimesh( &m, DENSITY, obj[i].geom[0] ); printf("mass at %f %f %f\n", m.c[0], m.c[1], m.c[2]); dGeomSetPosition(obj[i].geom[0], -m.c[0], -m.c[1], -m.c[2]); dMassTranslate(&m, -m.c[0], -m.c[1], -m.c[2]); } else if (cmd == 'x') { setBody = true; // start accumulating masses for the composite geometries dMass m2; dMassSetZero (&m); dReal dpos[GPB][3]; // delta-positions for composite geometries dMatrix3 drot[GPB]; // set random delta positions for (j=0; j<GPB; j++) for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; for (k=0; k<GPB; k++) { if (k==0) { dReal radius = dRandReal()*0.25+0.05; obj[i].geom[k] = dCreateSphere (space,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { obj[i].geom[k] = dCreateBox(space,sides[0],sides[1],sides[2]); dMassSetBox(&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; obj[i].geom[k] = dCreateCapsule(space,radius,length); dMassSetCapsule(&m2,DENSITY,3,radius,length); } dRFromAxisAndAngle(drot[k],dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dMassRotate(&m2,drot[k]); dMassTranslate(&m2,dpos[k][0],dpos[k][1],dpos[k][2]); // add to the total mass dMassAdd(&m,&m2); } for (k=0; k<GPB; k++) { dGeomSetBody(obj[i].geom[k],obj[i].body); dGeomSetOffsetPosition(obj[i].geom[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); dGeomSetOffsetRotation(obj[i].geom[k], drot[k]); } dMassTranslate(&m,-m.c[0],-m.c[1],-m.c[2]); dBodySetMass(obj[i].body,&m); } if (!setBody) { // avoid calling for composite geometries for (k=0; k < GPB; k++) if (obj[i].geom[k]) dGeomSetBody(obj[i].geom[k],obj[i].body); dBodySetMass(obj[i].body,&m); } } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } }
void pvname_svc (const char *pname, const char *vnum) { f_print (fout, "%s_%s_svc", locase (pname), vnum); }
static void command (int cmd) { size_t i; int j,k; dReal sides[3]; dMass m; int setBody; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' || cmd == 'y' || cmd == 'v') { setBody = 0; if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+2); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRSetIdentity (R); //dRFromAxisAndAngle (R,0,0,1,/*dRandReal()*10.0-5.0*/0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*) i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } //<---- Convex Object else if (cmd == 'v') { dMassSetBox (&m,DENSITY,0.25,0.25,0.25); #if 0 obj[i].geom[0] = dCreateConvex (space, planes, planecount, points, pointcount, polygons); #else obj[i].geom[0] = dCreateConvex (space, Sphere_planes, Sphere_planecount, Sphere_points, Sphere_pointcount, Sphere_polygons); #endif } //----> Convex Object else if (cmd == 'y') { dMassSetCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'x' && USE_GEOM_OFFSET) { setBody = 1; // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); dReal dpos[GPB][3]; // delta-positions for encapsulated geometries dMatrix3 drot[GPB]; // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { if (k==0) { dReal radius = dRandReal()*0.25+0.05; obj[i].geom[k] = dCreateSphere (space,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { obj[i].geom[k] = dCreateBox (space,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; obj[i].geom[k] = dCreateCapsule (space,radius,length); dMassSetCapsule (&m2,DENSITY,3,radius,length); } dRFromAxisAndAngle (drot[k],dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dMassRotate (&m2,drot[k]); dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); // add to the total mass dMassAdd (&m,&m2); } for (k=0; k<GPB; k++) { dGeomSetBody (obj[i].geom[k],obj[i].body); dGeomSetOffsetPosition (obj[i].geom[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); dGeomSetOffsetRotation(obj[i].geom[k], drot[k]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); dBodySetMass (obj[i].body,&m); } else if (cmd == 'x') { dGeomID g2[GPB]; // encapsulated geometries dReal dpos[GPB][3]; // delta-positions for encapsulated geometries // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { obj[i].geom[k] = dCreateGeomTransform (space); dGeomTransformSetCleanup (obj[i].geom[k],1); if (k==0) { dReal radius = dRandReal()*0.25+0.05; g2[k] = dCreateSphere (0,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { g2[k] = dCreateBox (0,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; g2[k] = dCreateCapsule (0,radius,length); dMassSetCapsule (&m2,DENSITY,3,radius,length); } dGeomTransformSetGeom (obj[i].geom[k],g2[k]); // set the transformation (adjust the mass too) dGeomSetPosition (g2[k],dpos[k][0],dpos[k][1],dpos[k][2]); dMatrix3 Rtx; dRFromAxisAndAngle (Rtx,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dGeomSetRotation (g2[k],Rtx); dMassRotate (&m2,Rtx); // Translation *after* rotation dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); // add to the total mass dMassAdd (&m,&m2); } // move all encapsulated objects so that the center of mass is (0,0,0) for (k=0; k<GPB; k++) { dGeomSetPosition (g2[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); } if (!setBody) for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomSetBody (obj[i].geom[k],obj[i].body); } dBodySetMass (obj[i].body,&m); } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } else if (cmd == '1') { write_world = 1; } else if (cmd == 'p'&& selected >= 0) { const dReal* pos = dGeomGetPosition(obj[selected].geom[0]); const dReal* rot = dGeomGetRotation(obj[selected].geom[0]); printf("POSITION:\n\t[%f,%f,%f]\n\n",pos[0],pos[1],pos[2]); printf("ROTATION:\n\t[%f,%f,%f,%f]\n\t[%f,%f,%f,%f]\n\t[%f,%f,%f,%f]\n\n", rot[0],rot[1],rot[2],rot[3], rot[4],rot[5],rot[6],rot[7], rot[8],rot[9],rot[10],rot[11]); } else if (cmd == 'f' && selected >= 0 && selected < num) { if (dBodyIsEnabled(obj[selected].body)) doFeedback = 1; } }
static void pprogramdef (definition *def) { version_list *vers; proc_list *proc; int i; const char *ext; pargdef (def); pdefine (def->def_name, def->def.pr.prog_num); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print (fout, "extern struct rpcgen_table %s_%s_table[];\n", locase (def->def_name), vers->vers_num); f_print (fout, "extern %s_%s_nproc;\n", locase (def->def_name), vers->vers_num); } pdefine (vers->vers_name, vers->vers_num); /* * Print out 2 definitions, one for ANSI-C, another for * old K & R C */ if(!Cflag) { ext = "extern "; for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { pdefine (proc->proc_name, proc->proc_num); } f_print (fout, "%s", ext); pprocdef (proc, vers, NULL, 0, 2); if (mtflag) { f_print(fout, "%s", ext); pprocdef (proc, vers, NULL, 1, 2); } } pfreeprocdef (def->def_name, vers->vers_num, 2); } else { for (i = 1; i < 3; i++) { if (i == 1) { f_print (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); ext = "extern "; } else { f_print (fout, "\n#else /* K&R C */\n"); ext = "extern "; } for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { pdefine(proc->proc_name, proc->proc_num); } f_print (fout, "%s", ext); pprocdef (proc, vers, "CLIENT *", 0, i); f_print (fout, "%s", ext); pprocdef (proc, vers, "struct svc_req *", 1, i); } pfreeprocdef (def->def_name, vers->vers_num, i); } f_print (fout, "#endif /* K&R C */\n"); } } }
static void command (int cmd) { int i,j,k; dReal sides[3]; dMass m; cmd = locase (cmd); if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' || cmd == 'm' || cmd == 'y' ) { if (num < NUM) { i = num; num++; } else { i = nextobj; nextobj++; if (nextobj >= num) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy (obj[i].body); for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]); } memset (&obj[i],0,sizeof(obj[i])); } obj[i].body = dBodyCreate (world); for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if (random_pos) { dBodySetPosition (obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+3); dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); } else { dReal maxheight = 0; for (k=0; k<num; k++) { const dReal *pos = dBodyGetPosition (obj[k].body); if (pos[2] > maxheight) maxheight = pos[2]; } dBodySetPosition (obj[i].body, 0,0,maxheight+1); dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0); } dBodySetRotation (obj[i].body,R); dBodySetData (obj[i].body,(void*)(size_t)i); if (cmd == 'b') { dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]); obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]); } else if (cmd == 'c') { sides[0] *= 0.5; dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]); } else if (cmd == 'y') { sides[1] *= 0.5; dMassSetCylinder (&m,DENSITY,3,sides[0],sides[1]); obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]); } else if (cmd == 's') { sides[0] *= 0.5; dMassSetSphere (&m,DENSITY,sides[0]); obj[i].geom[0] = dCreateSphere (space,sides[0]); } else if (cmd == 'm') { dTriMeshDataID new_tmdata = dGeomTriMeshDataCreate(); dGeomTriMeshDataBuildSingle(new_tmdata, &Vertices[0], 3 * sizeof(float), VertexCount, (dTriIndex*)&Indices[0], IndexCount, 3 * sizeof(dTriIndex)); obj[i].geom[0] = dCreateTriMesh(space, new_tmdata, 0, 0, 0); // remember the mesh's dTriMeshDataID on its userdata for convenience. dGeomSetData(obj[i].geom[0], new_tmdata); dMassSetTrimesh( &m, DENSITY, obj[i].geom[0] ); printf("mass at %f %f %f\n", m.c[0], m.c[1], m.c[2]); dGeomSetPosition(obj[i].geom[0], -m.c[0], -m.c[1], -m.c[2]); dMassTranslate(&m, -m.c[0], -m.c[1], -m.c[2]); } else if (cmd == 'x') { dGeomID g2[GPB]; // encapsulated geometries dReal dpos[GPB][3]; // delta-positions for encapsulated geometries // start accumulating masses for the encapsulated geometries dMass m2; dMassSetZero (&m); // set random delta positions for (j=0; j<GPB; j++) { for (k=0; k<3; k++) dpos[j][k] = dRandReal()*0.3-0.15; } for (k=0; k<GPB; k++) { obj[i].geom[k] = dCreateGeomTransform (space); dGeomTransformSetCleanup (obj[i].geom[k],1); if (k==0) { dReal radius = dRandReal()*0.25+0.05; g2[k] = dCreateSphere (0,radius); dMassSetSphere (&m2,DENSITY,radius); } else if (k==1) { g2[k] = dCreateBox (0,sides[0],sides[1],sides[2]); dMassSetBox (&m2,DENSITY,sides[0],sides[1],sides[2]); } else { dReal radius = dRandReal()*0.1+0.05; dReal length = dRandReal()*1.0+0.1; g2[k] = dCreateCapsule (0,radius,length); dMassSetCapsule (&m2,DENSITY,3,radius,length); } dGeomTransformSetGeom (obj[i].geom[k],g2[k]); // set the transformation (adjust the mass too) dGeomSetPosition (g2[k],dpos[k][0],dpos[k][1],dpos[k][2]); dMassTranslate (&m2,dpos[k][0],dpos[k][1],dpos[k][2]); dMatrix3 Rtx; dRFromAxisAndAngle (Rtx,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0); dGeomSetRotation (g2[k],Rtx); dMassRotate (&m2,Rtx); // add to the total mass dMassAdd (&m,&m2); } // move all encapsulated objects so that the center of mass is (0,0,0) for (k=0; k<2; k++) { dGeomSetPosition (g2[k], dpos[k][0]-m.c[0], dpos[k][1]-m.c[1], dpos[k][2]-m.c[2]); } dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]); } for (k=0; k < GPB; k++) { if (obj[i].geom[k]) dGeomSetBody (obj[i].geom[k],obj[i].body); } dBodySetMass (obj[i].body,&m); } if (cmd == ' ') { selected++; if (selected >= num) selected = 0; if (selected < 0) selected = 0; } else if (cmd == 'd' && selected >= 0 && selected < num) { dBodyDisable (obj[selected].body); } else if (cmd == 'e' && selected >= 0 && selected < num) { dBodyEnable (obj[selected].body); } else if (cmd == 'a') { show_aabb ^= 1; } else if (cmd == 't') { show_contacts ^= 1; } else if (cmd == 'r') { random_pos ^= 1; } }
// called when a key pressed static void command( int cmd ) { int i,k; dReal sides[3]; dMass m; cmd = locase( cmd ); if ( cmd == 'v' || cmd == 'b' || cmd == 'c' || cmd == 's' ) { if ( num < NUM ) { i = num; num++; } else { i = nextobj; nextobj++; if ( nextobj >= num ) nextobj = 0; // destroy the body and geoms for slot i dBodyDestroy( obj[i].body ); for ( k=0; k < GPB; k++ ) { if ( obj[i].geom[k] ) dGeomDestroy( obj[i].geom[k] ); } memset( &obj[i],0,sizeof( obj[i] ) ); } obj[i].body = dBodyCreate( world ); for ( k=0; k<3; k++ ) sides[k] = dRandReal()*0.5+0.1; dMatrix3 R; if ( random_pos ) { dBodySetPosition( obj[i].body, dRandReal()*2-1,dRandReal()*2-1,dRandReal()+3 ); dRFromAxisAndAngle( R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0, dRandReal()*2.0-1.0,dRandReal()*10.0-5.0 ); } else { dReal maxheight = 0; for ( k=0; k<num; k++ ) { const dReal *pos = dBodyGetPosition( obj[k].body ); if ( pos[2] > maxheight ) maxheight = pos[2]; } dBodySetPosition( obj[i].body, 0,0,maxheight+1 ); dRFromAxisAndAngle( R,0,0,1,dRandReal()*10.0-5.0 ); } dBodySetRotation( obj[i].body,R ); dBodySetData( obj[i].body,( void* )( size_t )i ); if ( cmd == 'b' ) { dMassSetBox( &m,DENSITY,sides[0],sides[1],sides[2] ); obj[i].geom[0] = dCreateBox( space,sides[0],sides[1],sides[2] ); } else if ( cmd == 'c' ) { sides[0] *= 0.5; dMassSetCapsule( &m,DENSITY,3,sides[0],sides[1] ); obj[i].geom[0] = dCreateCapsule( space,sides[0],sides[1] ); } else if ( cmd == 's' ) { sides[0] *= 0.5; dMassSetSphere( &m,DENSITY,sides[0] ); obj[i].geom[0] = dCreateSphere( space,sides[0] ); } else if ( cmd == 'v' ) { obj[i].geom[0] = dCreateConvex( space, convexBunnyPlanes, convexBunnyPlaneCount, convexBunnyPoints, convexBunnyPointCount, convexBunnyPolygons ); /// Use equivalent TriMesh to set mass dTriMeshDataID new_tmdata = dGeomTriMeshDataCreate(); dGeomTriMeshDataBuildSingle( new_tmdata, &Vertices[0], 3 * sizeof( float ), VertexCount, ( dTriIndex* )&Indices[0], IndexCount, 3 * sizeof( dTriIndex ) ); dGeomID triMesh = dCreateTriMesh( 0, new_tmdata, 0, 0, 0 ); dMassSetTrimesh( &m, DENSITY, triMesh ); dGeomDestroy( triMesh ); dGeomTriMeshDataDestroy( new_tmdata ); printf( "mass at %f %f %f\n", m.c[0], m.c[1], m.c[2] ); dGeomSetPosition( obj[i].geom[0], -m.c[0], -m.c[1], -m.c[2] ); dMassTranslate( &m, -m.c[0], -m.c[1], -m.c[2] ); } for ( k=0; k < GPB; k++ ) { if ( obj[i].geom[k] ) dGeomSetBody( obj[i].geom[k],obj[i].body ); } dBodySetMass( obj[i].body,&m ); } if ( cmd == ' ' ) { selected++; if ( selected >= num ) selected = 0; if ( selected < 0 ) selected = 0; } else if ( cmd == 'd' && selected >= 0 && selected < num ) { dBodyDisable( obj[selected].body ); } else if ( cmd == 'e' && selected >= 0 && selected < num ) { dBodyEnable( obj[selected].body ); } else if ( cmd == 'a' ) { show_aabb ^= 1; } else if ( cmd == 't' ) { show_contacts ^= 1; } else if ( cmd == 'r' ) { random_pos ^= 1; } }