Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!seismo!hao!hplabs!hpda!fortune!amd70!decwrl!flairvax!turtleva!ken From: ken@turtleva.UUCP (Ken Turkowski) Newsgroups: net.sources Subject: Graphics source in C: hsalgs/update_obj.c Message-ID: <299@turtleva.UUCP> Date: Thu, 22-Dec-83 02:13:01 EST Article-I.D.: turtleva.299 Posted: Thu Dec 22 02:13:01 1983 Date-Received: Sun, 18-Dec-83 09:05:18 EST Lines: 95 echo x - hsalgs/update_obj.c cat >hsalgs/update_obj.c <<'!Funky!Stuff!' /* update_obj.c - change entries in a .obj file */ #include #define LINE_LENGTH 160 #define TRUE 1 #define FALSE 0 #define NULLCHAR '\0' main(argc,argv) int argc; char **argv; { char *keywd,line[LINE_LENGTH],remainder[LINE_LENGTH]; char term[LINE_LENGTH],fields[LINE_LENGTH],*filename; double atof(),red,grn,blu,shininess,transmittance,trns_pwr; short i,shin_done,trans_done,keywd_fnd,shin_fnd,trans_fnd; FILE *input,*output; if (argc < 4) error("usage: update_obj filename keyword [n fields]"); filename = argv[1]; keywd = argv[2]; if (strcmp(keywd,"color") == 0) { red = atof(argv[3]); grn = atof(argv[4]); blu = atof(argv[5]); if (argc > 6) { shininess = atof(argv[6]); shin_done = TRUE; } if (argc > 7) { transmittance = atof(argv[7]); trans_done = TRUE; } if (argc > 8) trns_pwr = atof(argv[8]); } else for (i=3; i 2) fprintf(output,"%s",line); } if (strcmp(keywd,"color") == 0) { if (!keywd_fnd) fprintf(output,"color\t\t%g %g %g\n",red,grn,blu); if ((!shin_fnd ) && (shin_done)) fprintf(output,"shininess\t%g\n",shininess); if ((!trans_fnd) && (trans_done)) fprintf(output,"transmittance\t%g %g\n",transmittance,trns_pwr); } else if (!keywd_fnd) fprintf(output,"%s\t\t%s\n",keywd,fields); close(input); close(output); system(sprintf(line,"mv update_obj.tmp %s",filename)); } /* +++++++++++++++++++++ GET_TERM +++++++++++++++++++++++++++++++++ */ get_term(instrg,term,remainder) /* remove first term from string */ char *instrg,*term,*remainder; /* blanks, tabs, nulls, commas are separators */ { short i,index1,index2; index1 = 0; /* find first non-separator */ while ((instrg[index1] == ' ') || (instrg[index1] == '\t') || (instrg[index1] == NULLCHAR) || (instrg[index1] == ',' )) index1++; index2 = index1; /* find next separator */ while ((instrg[index2] != ' ') && (instrg[index2] != '\t') && (instrg[index2] != NULLCHAR) && (instrg[index2] != ',' ) && (instrg[index2] != '\n')) index2++; for (i=index1; i