Makefile proveído tiene objetivos para crear versiones
estática y dinámica de la librería:
lhp@nereida:~/Lperl/src/XSUB/h2xsexample/coordlib/lib$ cat -n Makefile 1 CFLAGS= -I../include -g 2 INCLUDE=../include 3 4 shared:libpl.so 5 6 static:libpl.a 7 8 libpl.a:pl2rc.o rc2pl.o 9 ar r libpl.a pl2rc.o rc2pl.o 10 11 libpl.so:pl2rc.o rc2pl.o 12 cc -shared $(CFLAGS) pl2rc.o rc2pl.o -o libpl.so 13 14 pl2rc.o:pl2rc.c $(INCLUDE)/coord.h 15 16 rc2pl.o:rc2pl.c $(INCLUDE)/coord.h 17 18 clean: 19 rm -f *.o core 20 21 veryclean: 22 make clean; 23 rm -f libpl.a libpl.so
El fuente pl2rc.c guarda las funciones relacionadas
con el manejo de las coordenadas polares:
24
lhp@nereida:~/Lperl/src/XSUB/h2xsexample/coordlib/lib$ cat -n pl2rc.c
1 #include <math.h>
2 #include <coord.h>
3 #include <stdio.h>
4
5 rectangular pl2rc(polar p) {
6 rectangular aux;
7
8 aux.x = p.mod*cos(p.arg);
9 aux.y = p.mod*sin(p.arg);
10 return (aux);
11 }
12
13 polar getpolar() {
14 polar aux;
15
16 printf("mod: "); scanf("%lf",&aux.mod);
17 printf("arg: "); scanf("%lf",&aux.arg);
18
19 return aux;
20 }
21
22 char * polar2str(const char *format, polar p) {
23 static char s[256];
24 sprintf(s, format, p.mod,p.arg);
25 return s;
26 }
El fuente rc2pl.c guarda las funciones relacionadas
con el manejo de las coordenadas rectangulares:
lhp@nereida:~/Lperl/src/XSUB/h2xsexample/coordlib/lib$ cat -n rc2pl.c
1 #include <math.h>
2 #include <coord.h>
3 #include <stdio.h>
4
5 polar rc2pl(rectangular r) {
6 polar aux;
7
8 aux.mod = sqrt(r.x*r.x+r.y*r.y);
9 if (r.x != 0.0)
10 aux.arg = atan(r.y/r.x);
11 else if (r.y != 0.0)
12 aux.arg = PI;
13 else {
14 fprintf(stderr,"Error passing from rectangular to polar coordinates\n");
15 aux.arg = -1.0;
16 }
17 return (aux);
18 }
19
20 char * rectangular2str(const char *format, rectangular r) {
21 static char s[256];
22 sprintf(s, format, r.x, r.y);
23 return s;
24 }
25
26 rectangular getrectangular() {
27 rectangular aux;
28
29 printf("x: "); scanf("%lf",&aux.x);
30 printf("y: "); scanf("%lf",&aux.y);
31
32 return aux;
33 }
Casiano Rodríguez León
