Plan 9 from Bell Labs’s /usr/web/sources/contrib/tristan/root/sys/src/cmd/geo/proj/main.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>

#include "project.h"

void
initsystem(system *s) {
	if(!get_ell(&s->e, s->ename)) {
		list_ell();
		exits("argument");
	}
	if(!get_projection(&s->p, s->pname)) {
		list_projections();
		exits("argument");
	}
	(s->p.init)(&s->p, &s->e, s->parg);
}

void
main(int argc, char **argv){
	point pt;
	system isys, osys, *asys;
	Biobuf in, out;
	char *io;
	int verbose;

	verbose=0;
	asys=&isys;
	isys.ename=osys.ename="wgs84";
	isys.pname=osys.pname="λφ";
	isys.parg=osys.parg="";
	ARGBEGIN {
	case 'i':	asys=&isys;	break;
	case 'o':	asys=&osys;	break;
	case 'v':	verbose++;	break;
	case 'e':
		asys->ename = ARGF();
		break;
	case 'p':
		asys->pname=ARGF();
		if(!asys->pname) exits("argument");
		asys->parg=strchr(asys->pname, ',');
		if(asys->parg){
			*asys->parg='\0';
			asys->parg++;
		} else {
			asys->parg="";
		}
		break;
	default:
		print("usage: proj [-i] [-e ellipsis] [-p projection] [-o [-e ellipsis] [-p projection]]\n");
		exits("arguments");
		break;
	} ARGEND

	Binit(&in, 0, OREAD);
	Binit(&out, 1, OWRITE);

	setfcr(getfcr() & ~(FPINVAL|FPZDIV|FPOVFL));

	initsystem(&isys);
	initsystem(&osys);

	while(1) {
		if((io=Brdstr(&in, '\n', 1))==nil) break;
		pt=(isys.p.scan)(io);
		free(io);

		pt=(isys.p.λφ)(pt, &isys.e, &isys.p);
if(verbose)	printstd(pt);
		pt=(osys.p.xy)(pt, &osys.e, &osys.p);

		io=(osys.p.print)(pt);
		Bprint(&out, "%s\n", io);
		free(io);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.