home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum23.lzh
/
f23b
/
SOFTWARE
/
PDRAW
/
IOread.c
< prev
next >
Wrap
Text File
|
1992-01-15
|
8KB
|
302 lines
/*** IOread.c ***/
#include <stdio.h>
#include <strings.h>
#include <math.h>
#include "header.h"
#ifndef OSK
#include "Xdefs.h"
#endif
/* Read the command line */
fileopen(argc,argv)
int argc;
char **argv;
{
FILE *optionfile, *fopen();
char *strcpy();
double atof();
pfileptr insert_pfile();
extern char printer[MAXCHAR];
extern double scale;
extern int hiddenline, nosort, equalscale, postscript;
int i,FILEFOUND;
#ifdef OSK
char *progname; /* program name */
char *geometry; /* window geometry */
progname = argv[0];
#endif
#ifndef OSK
/* initialize general X arguments */
progname = argv[0];
font_name = NULL;
geometry = NULL;
display_name = NULL;
border_color = NULL;
fore_color = NULL;
back_color = NULL;
mouse_color = NULL;
icon_color = NULL;
reverse = 0;
border_width = 0;
#endif
FILEFOUND = FALSE;
for (i=1; i < argc; i++) { /* Parse Line */
if (argv[i][0] == '=') {
geometry = argv[i];
continue;
}
#ifdef X
if (!strncmp(argv[i],"-g",2)) { /* new geometry */
if (++i >= argc) usage(progname);
geometry = argv[i];
continue;
}
if (index(argv[i],':')!=NULL) { /* host:display */
strncpy(display_name,argv[i],sizeof(display_name));
continue;
}
if (!strncmp(argv[i],"-d",2)) { /* new display */
if (++i >= argc) usage(progname);
display_name = argv[i];
continue;
}
if (strcmp(argv[i],"-rv") == 0) { /* reverse display */
reverse = 1;
continue;
}
if (strcmp(argv[i],"-bw") == 0) { /* border width */
if (++i >= argc) usage(progname);
border_width = atoi(argv[i]);
continue;
}
if (strcmp(argv[i],"-bd") == 0) { /* border color */
if (++i >= argc) usage(progname);
border_color = argv[i];
continue;
}
if (strcmp(argv[i],"-fg") == 0) { /* foreground color */
if (++i >= argc) usage(progname);
fore_color = argv[i];
continue;
}
if (strcmp(argv[i],"-bg") == 0) { /* background color */
if (++i >= argc) usage(progname);
back_color = argv[i];
continue;
}
if (strcmp(argv[i],"-fn") == 0) { /* font type */
if (++i >= argc) usage(progname);
font_name = argv[i];
continue;
}
#endif
if (strcmp(argv[i],"-h") == 0) { /* hiddenline */
hiddenline = ON;
fprintf(stdout," Commands: hiddenline = ON\n");
continue;
}
if (strcmp(argv[i],"-nosort") == 0) { /* sorting */
nosort = ON;
fprintf(stdout," Commands: nosort = ON\n");
continue;
}
if (strcmp(argv[i],"-e") == 0) { /* equalscale */
equalscale = OFF;
fprintf(stdout," Commands: equalscale = OFF\n");
continue;
}
if (strncmp(argv[i],"-pr",3) == 0) { /* printplot */
printplot = ON;
fprintf(stdout," Commands: printplot = ON\n");
continue;
}
if (strcmp(argv[i],"-noplot") == 0) { /* noplot */
noplot = ON;
fprintf(stdout," Commands: noplot = ON\n");
continue;
}
if (strcmp(argv[i],"-ps") == 0) { /* postscript */
postscript = OFF;
fprintf(stdout," Commands: postscript = OFF\n");
continue;
}
if (strcmp(argv[i],"-s") == 0) { /* scale factor */
if (++i >= argc) usage(progname);
scale = atof(argv[i]);
if (scale < 0.1 || scale > 1) {
scale = 1.0;
fprintf(stdout," Warning : Invalid scale -");
fprintf(stdout," scale reset to %f\n",scale);
}
fprintf(stdout," Commands: scale = %f\n",scale);
continue;
}
if (strcmp(argv[i],"-v") == 0) { /* view */
if (++i >= argc) usage(progname);
eyepos.x = atof(argv[i]);
if (++i >= argc) usage(progname);
eyepos.y = atof(argv[i]);
if (++i >= argc) usage(progname);
eyepos.z = atof(argv[i]);
fprintf(stdout," Commands: eye-view = %f %f %f\n",
eyepos.x,eyepos.y,eyepos.z);
continue;
}
if (strcmp(argv[i],"-o") == 0) { /* options file */
if (++i >= argc) usage(progname);
if ((optionfile = fopen(argv[i],"r")) == NULL) {
fprintf(stderr,"cat: can't open %s\n", argv[i]);
usage(progname);
}
else {
fprintf(stdout," Commands: options-file = \"%s\"\n",argv[i]);
parse(optionfile);
fclose(optionfile);
}
continue;
}
if (argv[i][0] == '-' && argv[i][1] == 'P') { /* Printer */
strcpy(printer,argv[i]);
fprintf(stdout," Commands: Printer = %s\n",printer);
continue;
}
if (argv[i][0] == '-') usage(progname);
if (argv[i][0] != '-' && argv[i][0] != '=') {
FILEFOUND = TRUE;
insert_pfile(argv[i]);
}
}
if (FILEFOUND == FALSE) usage(progname);
/* exit(0); */
}
fileread(fp,format)
FILE *fp;
int format;
{
if (format == CONV) {
fileread_conv(fp);
} else if (format == PIF) {
fileread_pif(fp);
} else {
fprintf(stderr,"Error! Cant read format %d\n",format);
exit(-1);
}
}
fileread_conv(fp)
FILE *fp;
{
float rdfloat();
nodeptr insert_node();
segmptr insert_segm();
extern double xmax,xmin,ymax,ymin,zmax,zmin;
segmptr S;
nodeptr Nd;
double x, y, z;
int ncurves, npts, i, m;
xmin = rdfloat(fp);
xmax = rdfloat(fp);
ymin = rdfloat(fp);
ymax = rdfloat(fp);
zmin = rdfloat(fp);
zmax = rdfloat(fp);
ncurves = (int)rdfloat(fp);
if (ncurves <= 0) pltexit(1);
for (m=0; m<ncurves; m++) {
S = insert_segm();
npts = (int)rdfloat(fp);
if (npts<=0) pltexit(2);
for (i=0; i<npts; i++) {
x = rdfloat(fp);
y = rdfloat(fp);
z = rdfloat(fp);
Nd= insert_node(x,y,z,S);
}
}
}
float rdfloat(fp) /* Read a float; skip the whole line if failed */
FILE *fp;
{
int n;
char c;
float x;
/* try to read a floating variable */
/* if fail, then skip the whole line */
while ( (n=fscanf(fp,"%f",&x)) != EOF && n!=1) {
if (n!=1)
while ( (c=getc(fp)) != EOF && c != '\n');
}
if (n==EOF) pltexit(0);
return(x);
}
pltexit(mesg)
int mesg;
{
switch (mesg) {
case 0 : fprintf(stderr,"Error: Incorrect Format!\n");
exit(1); break;
case 1 : fprintf(stderr,"Error: Plot Curves <= 0\n");
exit(1); break;
case 2 : fprintf(stderr,"Error: Plot Points <= 0\n");
exit(1); break;
default: fprintf(stderr,"Error: Incorrect Format!\n");
exit(1); break;
}
}
usage (program)
char *program;
{
/* -s for single curve format */
fprintf(stderr,"usage: %s [-v vx vy vz] [-o options-file] [-Pprinter] \
[-s scale] [-e] [-h] [-nosort] [-noplot] [-print] [-ps] infile1 infile2 ...\n", program);
exit(1);
}
/* try to open a file for reading - this could be a compressed file */
open_file(fname,fp,format)
char *fname;
FILE **fp;
int *format;
{
char cmd[MAXCHAR];
char *sprintf();
/* try to open a file for reading */
if ((strlen(fname) > 2) && (!strcmp(fname + strlen(fname) - 2,".Z"))) {
#ifdef OSK
sprintf(cmd,"compr -d %s >>>/nil",fname);
#else
sprintf(cmd,"uncompress -c %s",fname);
#endif
*fp = popen(cmd,"r");
} else {
*fp = fopen(fname,"r");
}
if (*fp==NULL) {
fprintf(stderr,"cat : couldn't open file %s\n",fname);
exit(-1);
}
/* try to determine IO format */
*format = CONV;
if ((strlen(fname) > 4) && (!strcmp(fname + strlen(fname) - 4,".pif")))
*format = PIF;
if ((strlen(fname) > 6) && (!strcmp(fname + strlen(fname) - 6,".pif.Z")))
*format = PIF;
}