int main(int argc, char **argv) { printf("Microlink test (%s %s)\n", __DATE__, __TIME__); buffer = (unsigned char *)Malloc(MAXMSGSIZE); if (buffer == 0) { printf("failed to get buffer\n"); exit(1); } BuildCommandTable(); /* Start a separate process to announce when a message handler */ /* a message. */ InitSemaphore(&handlerArg.sem, 0); /* Process sleeps on this */ if (Fork(5000, HandlerProcess, 0, 0) < 0) { printf("failed to start child process\n"); exit(1); } /* Main command loop */ while (!finished) { char com[256], a1[256], a2[256], a3[256], a4[256], a5[256], a6[256]; char line[256]; int nwords; printf("> "); fflush(stdout); gets(line); com[0] = 0; a1[0] = 0; a2[0] = 0; a3[0] = 0; a4[0] = 0; a5[0] = 0; a6[0] = 0; nwords = sscanf(line, "%s %s %s %s %s %s %s", com, a1, a2, a3, a4, a5, a6); if (nwords > 0) { void (*proc)() = LookupCommand(com); if ((int)proc) (*proc)(com, a1, a2, a3, a4, a5, a6); else printf("Unknown command '%s'\n", com); } } Free(buffer); return 0; }
int main(int argc, char **argv) { Object *obj; printf("Serialtest 1.18 (%s)\n", __DATE__); argc = argc; argv = argv; buffer = (unsigned char *)Malloc(BUFSIZE); if (buffer == 0) { printf("failed to get buffer\n"); exit(1); } /* Open() doesn't seem to work with a NULL context, so we have to do */ /* a Locate() first. */ obj = Locate(CurrentDir, DEVNAME); if (obj == NULL) { printf("can't locate %s\n", DEVNAME); exit(1); } stream = Open(obj, NULL, O_ReadWrite); if (stream == 0) { printf("open of %s failed\n", DEVNAME); exit(1); } BuildCommandTable(); while (!finished) { char com[256], a1[256], a2[256], a3[256]; char line[256]; int nwords; printf("> "); fflush(stdout); gets(line); com[0] = 0; a1[0] = 0; a2[0] = 0; a3[0] = 0; nwords = sscanf(line, "%s %s %s %s", com, a1, a2, a3); if (nwords > 0) { void (*proc)() = LookupCommand(com); if ((int)proc) (*proc)(com, a1, a2, a3); else printf("Unknown command '%s'\n", com); } } Free(buffer); Close(stream); return 0; }
VOID ReadEnvFile(CHAR *EnvFileName) { INT i, j; /* Indices. */ INT stat; /* Input var status counter. */ INT dummy; CHAR opcode; /* Environment spec opcode. */ CHAR command[30]; /* Environment spec command. */ CHAR opparam[30]; /* Command parameter. */ CHAR dummy_char[60]; CHAR datafile[10]; BOOL lights_set; /* Lights set? */ FILE *pf; /* Input file pointer. */ LIGHT *lptr, *lastlight; /* Light node pointers. */ /* Open command file. */ pf = fopen(EnvFileName, "r"); if (!pf) { printf("Unable to open environment file %s.\n", EnvFileName); exit(-1); } InitEnv(); /* Set defaults. */ nlights = 0; lights_set = FALSE; /* Process command file according to opcodes. */ while (fscanf(pf, "%s", command) != EOF) { opcode = LookupCommand(command); switch (opcode) { /* Eye position. */ case OP_EYE: stat = fscanf(pf, "%lf %lf %lf", &(View.eye[0]), &(View.eye[1]), &(View.eye[2])); if (stat != 3) { printf("error: eye position.\n"); exit(-1); } break; /* Center of interest position. */ case OP_COI: stat = fscanf(pf, "%lf %lf %lf", &(View.coi[0]), &(View.coi[1]), &(View.coi[2])); if (stat != 3) { printf("error: coi position.\n"); exit(-1); } break; /* Background color. */ case OP_BKGCOL: stat = fscanf(pf, "%lf %lf %lf", &(View.bkg[0]), &(View.bkg[1]), &(View.bkg[2])); if (stat != 3) { printf("error: background color.\n"); exit(-1); } if (!VerifyColorRange(View.bkg)) exit(-1); break; /* Viewing angle in degrees. */ case OP_VANG: stat = fscanf(pf, "%lf", &(View.vang)); if (stat != 1) { printf("error: viewing angle.\n"); exit(-1); } if (View.vang < 0.0 || View.vang > 100.0) { printf("Invalid angle %f.\n", View.vang); exit(-1); } break; /* Ambient. */ case OP_AMBIENT: stat = fscanf(pf, "%lf %lf %lf", &(View.ambient[0]), &(View.ambient[1]), &(View.ambient[2])); if (stat != 3) { printf("error: ambient.\n"); exit(-1); } if (!VerifyColorRange(View.ambient)) exit(-1); break; /* Anti-aliasing level. */ case OP_ANTILEVEL: stat = fscanf(pf, "%ld", &(Display.maxAAsubdiv)); if (stat != 1) { printf("View error: antialias level.\n"); exit(-1); } if (Display.maxAAsubdiv < 0 || Display.maxAAsubdiv > 3) { printf("error: antialias level %ld.\n", Display.maxAAsubdiv); exit(-1); } break; /* Recursion level. */ case OP_MAXLEVEL: stat = fscanf(pf, "%ld", &(Display.maxlevel)); printf("maxlevel of ray recursion = %ld\n",Display.maxlevel); fflush(stdout); if (stat != 1) { printf("error: recursion level.\n"); exit(-1); } if (Display.maxlevel > 5 || Display.maxlevel < 0) { printf("error: recursion level %ld.\n", Display.maxlevel); exit(-1); } break; /* Mininum ray weight. */ case OP_MINWEIGHT: stat = fscanf(pf, "%lf", &(Display.minweight)); if (stat != 1) { printf("error: miniumum ray weight.\n"); exit(-1); } if (Display.minweight < 0.0 || Display.minweight > 1.0) { printf("error: invalid ray weight %f.\n", Display.minweight); exit(-1); } break; /* Anti tolerance weight. */ case OP_ANTITOL: stat = fscanf(pf, "%lf", &(Display.aatolerance)); if (stat != 1) { printf("error: anti tolerance weight.\n"); exit(-1); } if (Display.aatolerance < 0.0 || Display.aatolerance > 1.0) { printf("error: invalid anti tolerance weight %f.\n", Display.aatolerance); exit(-1); } break; /* Resolution. */ case OP_RES: stat = fscanf(pf, "%ld %ld", &(Display.xres), &(Display.yres)); if (stat != 2) { printf("error: resolution.\n"); exit(-1); } break; /* Light positions and colors. */ case OP_LIGHT: lights_set = TRUE; if (nlights > 0) lptr = GlobalMalloc(sizeof(LIGHT), "env.c"); else lptr = lights; stat = fscanf(pf, "%lf %lf %lf %lf %lf %lf", &(lptr->pos[0]), &(lptr->pos[1]), &(lptr->pos[2]), &(lptr->col[0]), &(lptr->col[1]), &(lptr->col[2])); if (stat != 6) { printf("error: Lights.\n"); exit(-1); } if (!VerifyColorRange(lptr->col)) exit(-1); lptr->pos[3] = 1.0; stat = fscanf(pf, "%ld", &(lptr->shadow)); if (stat != 1) { printf("error: Lights shadow indicator.\n"); exit(-1); } lptr->next = NULL; if (nlights > 0) lastlight->next = lptr; nlights++; lastlight = lptr; break; /* Model transformation matrix. */ case OP_MODELMAT: for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { stat = fscanf(pf, "%lf", &(View.model[i][j])); if (stat != 1) { printf("Error in matrix.\n"); exit(-1); } } ModelTransform = TRUE; break; /* Shadow info. */ case OP_SHAD: stat = fscanf(pf, "%s", opparam); if (stat != 1) { printf("error: shadow.\n"); exit(-1); } if (strcmp(opparam, "on") == 0) View.shad = TRUE; else View.shad = FALSE; break; /* Shading info. */ case OP_SHADING: stat = fscanf(pf, "%s", opparam); if (stat != 1) { printf("error: shading %s.\n", opparam); exit(-1); } if (strcmp(opparam, "on") == 0) View.shading = TRUE; else View.shading = FALSE; break; /* Projection type. */ case OP_PROJECT: stat = fscanf(pf, "%s", opparam); if (stat != 1) { printf("error: projection %s.\n", opparam); exit(-1); } if (strcmp(opparam, "perspective") == 0) View.projection = PT_PERSP; else if (strcmp(opparam, "orthographic") == 0) View.projection = PT_ORTHO; else { printf("Invalid projection %s.\n", opparam); exit(-1); } break; /* Database traversal info. */ case OP_TRAVERSAL: stat = fscanf(pf, "%s", opparam); if (stat != 1) { printf("error: traversal %s.\n", opparam); exit(-1); } if (strcmp(opparam, "list") == 0) TraversalType = TT_LIST; else if (strcmp(opparam, "huniform") == 0) TraversalType = TT_HUG; else { printf("Invalid traversal code %s.\n", opparam); exit(-1); } break; /* Geometry file. */ case OP_GEOM_FILE: stat = fscanf(pf, " %s", GeoFileName); if (stat != 1) { printf("error: geometry file.\n"); exit(-1); } GeoFile = TRUE; break; /* Runlength file. */ case OP_RL_FILE: stat = fscanf(pf, " %s", PicFileName); if (stat != 1) { printf("error: runlength file.\n"); exit(-1); } PicFile = TRUE; break; case OP_PREVIEW_BKCULL: stat = fscanf(pf, "%ld", &dummy); if (stat != 1) { printf("error: Preview bkcull.\n"); exit(-1); } break; case OP_PREVIEW_FILL: stat = fscanf(pf, "%ld", &dummy); if (stat != 1) { printf("error: Preview fill.\n"); exit(-1); } break; case OP_PREVIEW_SPHTESS: stat = fscanf(pf, "%s", dummy_char); if (stat != 1) { printf("error: sphere tess.\n"); exit(-1); } break; case OP_NORM_DB: stat = fscanf(pf, "%s", opparam); if (stat != 1) { printf("error: norm database.\n"); exit(-1); } if (strcmp(opparam, "no") == 0) ModelNorm = FALSE; break; case OP_DATA_TYPE: stat = fscanf(pf, "%s", datafile); if (stat != 1) { printf("error: datatype.\n"); exit(-1); } if (strcmp(datafile, "binary") == 0) DataType = DT_BINARY; break; case OP_HU_MAX_PRIMS_CELL: stat = fscanf(pf, "%ld", &hu_max_prims_cell); if (stat != 1) { printf("error: Huniform prims per cell.\n"); exit(-1); } break; case OP_HU_GRIDSIZE: stat = fscanf(pf, "%ld", &hu_gridsize); if (stat != 1) { printf("error: Huniform gridsize.\n"); exit(-1); } break; case OP_HU_NUMBUCKETS: stat = fscanf(pf, "%ld", &hu_numbuckets); if (stat != 1) { printf("error: Huniform numbuckets.\n"); exit(-1); } break; case OP_HU_MAX_SUBDIV: stat = fscanf(pf, "%ld", &hu_max_subdiv_level); if (stat != 1 || hu_max_subdiv_level > 3) { printf("error: Huniform max subdiv level.\n"); exit(-1); } break; case OP_HU_LAZY: stat = fscanf(pf, "%ld", &hu_lazy); if (stat != 1) { printf("error: Huniform lazy.\n"); exit(-1); } break; case OP_BUNDLE: stat = fscanf(pf, "%ld %ld", &bundlex, &bundley); if (stat != 2 ) { printf("error: bundle.\n"); exit(-1); } break; case OP_BLOCK: stat = fscanf(pf, "%ld %ld", &blockx, &blocky); if (stat != 2 ) { printf("error: block.\n"); exit(-1); } break; default: printf("Warning: unrecognized env command: %s.\n", command); break; } } fclose(pf); /* Display parameters reset. */ Display.numpixels = Display.xres*Display.yres; Display.vWscale = Display.scrWidth/Display.xres; Display.vHscale = Display.scrHeight/Display.yres; /* If no light information given, set default. */ if (!lights_set) InitLights(); /* Set up screen parameters. */ InitDisplay(); /* Parameter check; think about lifting this restriction. */ if ((TraversalType != TT_LIST) && ModelNorm == FALSE) { printf("Data must be normalized with this traversal method!.\n"); ModelNorm = TRUE; } }