WSTester updated to work plus hopefully all the other changes that need to go into...
[jabaws.git] / binaries / src / ViennaRNA / RNAforester / g2-0.70 / g2_perl / G2.xs
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7
8 #ifdef __cplusplus
9 }
10 #endif
11
12 #include <stdlib.h>
13 #include <g2.h>
14
15 #ifdef DO_PS
16 #include <g2_PS.h>
17 #endif /* DO_PS */
18
19 #ifdef DO_FIG
20 #include <g2_FIG.h>
21 #endif /* DO_FIG */
22
23 #ifdef DO_X11
24 #include <g2_X11.h>
25 #endif /* DO_X11 */
26
27 #ifdef DO_GD
28 #include <g2_gd.h>
29 #endif /* DO_GD */
30
31 #ifdef DO_WIN32
32 #include <g2_Win32.h>
33 #endif /* DO_WIN32 */
34
35
36 static int
37 not_here(s)
38 char *s;
39 {
40     croak("%s not implemented on this architecture", s);
41     return -1;
42 }
43
44 static double
45 constant(name, arg)
46 char *name;
47 int arg;
48 {
49     errno = 0;
50     switch (*name) {
51     case 'A':
52         break;
53     case 'B':
54         break;
55     case 'C':
56         break;
57     case 'D':
58         break;
59     case 'E':
60         break;
61     case 'F':
62         break;
63     case 'G':
64         if (strEQ(name, "G2LD"))
65 #ifdef G2LD
66             return G2LD;
67 #else
68             goto not_there;
69 #endif
70         if (strEQ(name, "G2_H"))
71 #ifdef G2_H
72             return G2_H;
73 #else
74             goto not_there;
75 #endif
76         if (strEQ(name, "G2_VERSION"))
77 #ifdef G2_VERSION
78             return atof(G2_VERSION);
79 #else
80             goto not_there;
81 #endif
82         break;
83     case 'H':
84         break;
85     case 'I':
86         break;
87     case 'J':
88         break;
89     case 'K':
90         break;
91     case 'L':
92         break;
93     case 'M':
94         break;
95     case 'N':
96         break;
97     case 'O':
98         break;
99     case 'P':
100         break;
101     case 'Q':
102         break;
103     case 'R':
104         break;
105     case 'S':
106         break;
107     case 'T':
108         break;
109     case 'U':
110         break;
111     case 'V':
112         break;
113     case 'W':
114         break;
115     case 'X':
116         break;
117     case 'Y':
118         break;
119     case 'Z':
120         break;
121     }
122     errno = EINVAL;
123     return 0;
124
125 not_there:
126     errno = ENOENT;
127     return 0;
128 }
129
130 typedef int* DevType;
131 typedef DevType G2__Device;
132
133
134 MODULE = G2             PACKAGE = G2                    
135
136
137 double
138 constant(name,arg)
139         char *          name
140         int             arg
141
142 MODULE = G2             PACKAGE = G2::Device            PREFIX = g2_
143
144 #ifdef DO_X11
145
146 G2::Device
147 g2_newX11(packname="G2::Device", width=100,height=100)
148         char * packname
149         int width
150         int height
151         PROTOTYPE: $;$$
152         CODE:
153         {
154                 DevType theDevice;
155                 theDevice = (int *)malloc(sizeof(int));
156                 *theDevice = g2_open_X11(width, height);
157                 RETVAL = theDevice;
158         }
159         OUTPUT:
160         RETVAL
161
162 #endif /* DO_X11 */
163         
164
165 #ifdef DO_WIN32
166
167 G2::Device
168 g2_newWin32(packname="G2::Device", width=100,height=100,filename="Win32 window",type=0)
169         char * packname
170         int width
171         int height
172         char * filename 
173         int type
174         PROTOTYPE: $;$$
175         CODE:
176         {
177                 DevType theDevice;
178                 theDevice = (int *)malloc(sizeof(int));
179                 *theDevice = g2_open_win32(width, height, filename, type);
180                 RETVAL = theDevice;
181         }
182         OUTPUT:
183         RETVAL
184
185 #endif /* DO_WIN32 */
186
187 #ifdef DO_GD
188
189 G2::Device
190 g2_newGD(packname="G2::Device", filename="g2.png", width=100, height=100, type=1)
191         char * packname
192         char * filename
193         int width
194         int height
195         int type
196         PROTOTYPE: $;$$$
197         CODE:
198         {
199                 DevType theDevice;
200                 theDevice = (int *)malloc(sizeof(int));
201                 *theDevice = g2_open_gd(filename, width, height, type);
202                 RETVAL = theDevice;
203         }
204         OUTPUT:
205         RETVAL
206
207 #endif /* DO_GD */
208
209 #ifdef DO_PS
210
211 G2::Device
212 g2_newPS(packname="G2::Device", filename="g2.ps", paper=1,orientation=1)
213         char * packname
214         char * filename
215         int paper
216         int orientation
217         PROTOTYPE: $;$$$
218         CODE:
219         {
220                 DevType theDevice;
221                 theDevice = (int *)malloc(sizeof(int));
222                 *theDevice = g2_open_PS(filename, paper, orientation);
223                 RETVAL = theDevice;
224         }
225         OUTPUT:
226         RETVAL
227         
228 G2::Device
229 g2_newEPSF(packname="G2::Device", filename="g2.eps")
230         char * packname
231         char * filename
232         PROTOTYPE: $;$$$
233         CODE:
234         {
235                 DevType theDevice;
236                 theDevice = (int *)malloc(sizeof(int));
237                 *theDevice = g2_open_EPSF(filename);
238                 RETVAL = theDevice;
239         }
240         OUTPUT:
241         RETVAL
242         
243 G2::Device
244 g2_newEPSF_CLIP(packname="G2::Device", filename="g2.eps",width=100,height=100)
245         char * packname
246         char * filename
247         long width
248         long height
249         PROTOTYPE: $;$$$
250         CODE:
251         {
252                 DevType theDevice;
253                 theDevice = (int *)malloc(sizeof(int));
254                 *theDevice = g2_open_EPSF_CLIP(filename,width,height);
255                 RETVAL = theDevice;
256         }
257         OUTPUT:
258         RETVAL
259         
260 #endif /* DO_PS */
261
262 #ifdef DO_FIG
263
264 G2::Device
265 g2_newFIG(packname="G2::Device", filename="g2.fig")
266         char * packname
267         char * filename
268         PROTOTYPE: $;$$$
269         CODE:
270         {
271                 DevType theDevice;
272                 theDevice = (int *)malloc(sizeof(int));
273                 *theDevice = g2_open_FIG(filename);
274                 RETVAL = theDevice;
275         }
276         OUTPUT:
277         RETVAL
278         
279 #endif /* DO_FIG */
280
281         
282 G2::Device
283 g2_newvd(packname="G2::Device")
284         char * packname
285         PROTOTYPE: $;
286         CODE:
287         {
288                 DevType theDevice;
289                 theDevice = (int *)malloc(sizeof(int));
290                 *theDevice = g2_open_vd();
291                 RETVAL = theDevice;
292         }
293         OUTPUT:
294         RETVAL
295
296
297 void
298 g2_DESTROY(dev)
299         G2::Device      dev
300         PROTOTYPE: $
301         CODE:
302         {
303                 if(g2_device_exist(*dev)) {
304                         g2_close(*dev);
305                 }
306                 free(dev);
307         }
308
309
310 void
311 g2_attach(vd_dev, dev)
312         G2::Device      vd_dev
313         G2::Device      dev
314         PROTOTYPE: $
315         CODE:
316         {
317         g2_attach(*vd_dev, *dev);
318         }
319
320 void
321 g2_detach(vd_dev, dev)
322         G2::Device      vd_dev
323         G2::Device      dev
324         PROTOTYPE: $
325         CODE:
326         {
327         g2_detach(*vd_dev, *dev);
328         }
329
330 void
331 g2_close(dev)
332         G2::Device      dev
333         PROTOTYPE: 
334         CODE:
335         {
336         g2_close(*dev);
337         }
338
339 void
340 g2_set_auto_flush(dev, on_off)
341         G2::Device      dev
342         int     on_off
343         PROTOTYPE: $
344         CODE:
345         {
346                 g2_set_auto_flush(*dev, on_off);
347         }
348
349 void
350 g2_flush(dev)
351         G2::Device      dev
352         PROTOTYPE: 
353         CODE:
354         {
355                 g2_flush(*dev);
356         }
357
358 void
359 g2_save(dev)
360         G2::Device      dev
361         PROTOTYPE: 
362         CODE:
363         {
364                 g2_save(*dev);
365         }
366
367 void
368 g2_set_coordinate_system(dev, x_origin, y_origin, x_mul, y_mul)
369         G2::Device      dev
370         double  x_origin
371         double  y_origin
372         double  x_mul
373         double  y_mul
374         PROTOTYPE: $$$$
375         CODE:
376         {
377                 g2_set_coordinate_system(*dev, x_origin, y_origin, x_mul, y_mul);
378         }
379
380
381 int
382 g2_ink(pd_dev, red, green, blue)
383         G2::Device      pd_dev
384         double  red
385         double  green
386         double  blue
387         PROTOTYPE: $$$
388         CODE:
389         {
390                 RETVAL = g2_ink(*pd_dev, red, green, blue);
391         }
392         OUTPUT:
393         RETVAL
394
395 void
396 g2_pen(dev, color)
397         G2::Device      dev
398         int     color
399         PROTOTYPE: $
400         CODE:
401         {
402                 g2_pen(*dev, color);
403         }
404
405
406 void
407 g2_set_dash(dev, N, dashes=NULL)
408         G2::Device      dev
409         int     N
410         double *        dashes
411         PROTOTYPE: $
412         CODE:
413         {
414                 g2_set_dash(*dev, N, dashes);
415                 free(dashes);
416         }
417
418 void
419 g2_set_font_size(dev, size)
420         G2::Device      dev
421         double  size
422         PROTOTYPE: $
423         CODE:
424         {
425                 g2_set_font_size(*dev, size);
426         }
427
428 void
429 g2_set_line_width(dev, w)
430         G2::Device      dev
431         double  w
432         PROTOTYPE: $
433         CODE:
434         {
435                 g2_set_line_width(*dev, w);
436         }
437
438 void
439 g2_clear_palette(dev)
440         G2::Device      dev
441         PROTOTYPE: 
442         CODE:
443         {
444                 g2_clear_palette(*dev);
445         }
446
447 void
448 g2_reset_palette(dev)
449         G2::Device      dev
450         PROTOTYPE: 
451         CODE:
452         {
453                 g2_reset_palette(*dev);
454         }
455
456 void
457 g2_allocate_basic_colors(dev)
458         G2::Device      dev
459         PROTOTYPE: 
460         CODE:
461         {
462                 g2_allocate_basic_colors(*dev);
463         }
464
465 void
466 g2_clear(dev)
467         G2::Device      dev
468         PROTOTYPE:
469         CODE:
470         {
471                 g2_clear(*dev);
472         }
473
474 void
475 g2_set_background(dev, color)
476         G2::Device      dev
477         int     color
478         PROTOTYPE: $
479         CODE:
480         {
481                 g2_set_background(*dev, color);
482         }
483
484 void
485 g2_move(dev, x, y)
486         G2::Device      dev
487         double  x
488         double  y
489         PROTOTYPE: $$
490         CODE:
491         {
492                 g2_move(*dev, x, y);
493         }
494
495 void
496 g2_move_r(dev, dx, dy)
497         G2::Device      dev
498         double  dx
499         double  dy
500         PROTOTYPE: $$
501         CODE:
502         {
503                 g2_move_r(*dev, dx, dy);
504         }
505
506 void
507 g2_plot(dev, x, y)
508         G2::Device      dev
509         double  x
510         double  y
511         PROTOTYPE: $$
512         CODE:
513         {
514                 g2_plot(*dev, x, y);
515         }
516
517 void
518 g2_plot_r(dev, dx, dy)
519         G2::Device      dev
520         double  dx
521         double  dy
522         PROTOTYPE: $$
523         CODE:
524         {
525                 g2_plot_r(*dev, dx, dy);
526         }
527
528
529
530 void
531 g2_line(dev, x1, y1, x2, y2)
532         G2::Device      dev
533         double  x1
534         double  y1
535         double  x2
536         double  y2
537
538         PROTOTYPE: $$$$
539         CODE:
540         {
541                 g2_line(*dev, x1, y1, x2, y2);
542         }
543
544 void
545 g2_line_r(dev, dx, dy)
546         G2::Device      dev
547         double  dx
548         double  dy
549         PROTOTYPE: $$
550         CODE:
551         {
552                 g2_line_r(*dev, dx, dy);
553         }
554
555 void
556 g2_line_to(dev, x, y)
557         G2::Device      dev
558         double  x
559         double  y
560         PROTOTYPE: $$
561         CODE:
562         {
563                 g2_line_to(*dev, x, y);
564         }
565
566 void
567 g2_poly_line(dev, N_pt, points)
568         G2::Device      dev
569         int     N_pt
570         double * points
571         PROTOTYPE: $$
572         CODE:
573         {
574                 g2_poly_line(*dev, N_pt, points);
575                 free(points);
576         }
577
578 void
579 g2_triangle(dev, x1, y1, x2, y2, x3, y3)
580         G2::Device      dev
581         double  x1
582         double  y1
583         double  x2
584         double  y2
585         double  x3
586         double  y3
587         PROTOTYPE: $$$$$$$
588         CODE:
589         {
590                 g2_triangle(*dev, x1, y1, x2, y2, x3, y3);
591         }
592
593
594 void
595 g2_filled_triangle(dev, x1, y1, x2, y2, x3, y3)
596         G2::Device      dev
597         double  x1
598         double  y1
599         double  x2
600         double  y2
601         double  x3
602         double  y3
603         PROTOTYPE: $$$$$$$
604         CODE:
605         {
606                 g2_filled_triangle(*dev, x1, y1, x2, y2, x3, y3);
607         }
608
609 void
610 g2_rectangle(dev, x1, y1, x2, y2)
611         G2::Device      dev
612         double  x1
613         double  y1
614         double  x2
615         double  y2
616         PROTOTYPE: $$$$
617         CODE:
618         {
619                 g2_rectangle(*dev, x1, y1, x2, y2);
620         }
621
622
623 void
624 g2_filled_rectangle(dev, x1, y1, x2, y2)
625         G2::Device      dev
626         double  x1
627         double  y1
628         double  x2
629         double  y2
630         PROTOTYPE: $$$$
631         CODE:
632         {
633                 g2_filled_rectangle(*dev, x1, y1, x2, y2);
634         }
635
636 void
637 g2_polygon(dev, N_pt, points)
638         G2::Device      dev
639         int     N_pt
640         double * points
641         PROTOTYPE: $$
642         CODE:
643         {
644                 g2_polygon(*dev, N_pt, points);
645                 free(points);
646         }
647
648 void
649 g2_filled_polygon(dev, N_pt, points)
650         G2::Device      dev
651         int     N_pt
652         double * points
653         PROTOTYPE: $$
654         CODE:
655         {
656                 g2_filled_polygon(*dev, N_pt, points);
657                 free(points);
658         }
659
660 void
661 g2_circle(dev, x, y, r)
662         G2::Device      dev
663         double  x
664         double  y
665         double  r
666         PROTOTYPE: $$$
667         CODE:
668         {
669                 g2_circle(*dev, x, y, r);
670         }
671
672 void
673 g2_filled_circle(dev, x, y, r)
674         G2::Device      dev
675         double  x
676         double  y
677         double  r
678         PROTOTYPE: $$$
679         CODE:
680         {
681                 g2_filled_circle(*dev, x, y, r);
682         }
683
684 void
685 g2_ellipse(dev, x, y, r1, r2)
686         G2::Device      dev
687         double  x
688         double  y
689         double  r1
690         double  r2
691         PROTOTYPE: $$$$
692         CODE:
693         {
694                 g2_ellipse(*dev, x, y, r1, r2);
695         }
696
697 void
698 g2_filled_ellipse(dev, x, y, r1, r2)
699         G2::Device      dev
700         double  x
701         double  y
702         double  r1
703         double  r2
704         PROTOTYPE: $$$$
705         CODE:
706         {
707                 g2_filled_ellipse(*dev, x, y, r1, r2);
708         }
709
710 void
711 g2_arc(dev, x, y, r1, r2, a1, a2)
712         G2::Device      dev
713         double  x
714         double  y
715         double  r1
716         double  r2
717         double  a1
718         double  a2
719         PROTOTYPE: $$$$$$
720         CODE:
721         {
722                 g2_arc(*dev, x, y, r1, r2, a1, a2);
723         }
724
725 void
726 g2_filled_arc(dev, x, y, r1, r2, a1, a2)
727         G2::Device      dev
728         double  x
729         double  y
730         double  r1
731         double  r2
732         double  a1
733         double  a2
734         PROTOTYPE: $$$$$$
735         CODE:
736         {
737                 g2_filled_arc(*dev, x, y, r1, r2, a1, a2);
738         }
739
740 void
741 g2_string(dev, x, y, text)
742         G2::Device      dev
743         double  x
744         double  y
745         char *  text
746         PROTOTYPE: $$$
747         CODE:
748         {
749                 g2_string(*dev, x, y, text);
750         }
751
752 void
753 g2_set_QP(dev, d, shape)
754         G2::Device      dev
755         double  d
756         enum QPshape    shape
757         PROTOTYPE: $$
758         CODE:
759         {
760                 g2_set_QP(*dev, d, shape);
761         }
762
763 void
764 g2_plot_QP(dev, x, y)
765         G2::Device      dev
766         double  x
767         double  y
768         PROTOTYPE: $$
769         CODE:
770         {
771                 g2_plot_QP(*dev, x, y);
772         }
773
774 void
775 g2_query_pointer(dev)
776         G2::Device      dev
777         PROTOTYPE: $$
778         CODE:
779         {
780                 double x, y;
781                 unsigned int button;
782                 g2_query_pointer(*dev, &x, &y, &button);
783         }
784
785
786
787
788
789 void
790 g2_spline(dev, N_pt, points, o)
791         G2::Device      dev
792         int     N_pt
793         double * points
794         int o
795         PROTOTYPE: $$
796         CODE:
797         {
798                 g2_spline(*dev, N_pt, points, o);
799                 free(points);
800         }
801
802
803 void
804 g2_b_spline(dev, N_pt, points, o)
805         G2::Device      dev
806         int     N_pt
807         double * points
808         int o
809         PROTOTYPE: $$
810         CODE:
811         {
812                 g2_b_spline(*dev, N_pt, points, o);
813                 free(points);
814         }
815
816
817 void
818 g2_raspln(dev, N_pt, points, tn)
819         G2::Device      dev
820         int     N_pt
821         double * points
822         double tn
823         PROTOTYPE: $$
824         CODE:
825         {
826                 g2_raspln(*dev, N_pt, points, tn);
827                 free(points);
828         }
829
830
831 void
832 g2_para_3(dev, N_pt, points)
833         G2::Device      dev
834         int     N_pt
835         double * points
836         PROTOTYPE: $$
837         CODE:
838         {
839                 g2_para_3(*dev, N_pt, points);
840                 free(points);
841         }
842
843
844 void
845 g2_para_5(dev, N_pt, points)
846         G2::Device      dev
847         int     N_pt
848         double * points
849         PROTOTYPE: $$
850         CODE:
851         {
852                 g2_para_5(*dev, N_pt, points);
853                 free(points);
854         }
855
856
857 void
858 g2_filled_spline(dev, N_pt, points, o)
859         G2::Device      dev
860         int     N_pt
861         double * points
862         int o
863         PROTOTYPE: $$
864         CODE:
865         {
866                 g2_filled_spline(*dev, N_pt, points, o);
867                 free(points);
868         }
869
870
871 void
872 g2_filled_b_spline(dev, N_pt, points, o)
873         G2::Device      dev
874         int     N_pt
875         double * points
876         int o
877         PROTOTYPE: $$
878         CODE:
879         {
880                 g2_filled_b_spline(*dev, N_pt, points, o);
881                 free(points);
882         }
883
884
885 void
886 g2_filled_raspln(dev, N_pt, points, tn)
887         G2::Device      dev
888         int     N_pt
889         double * points
890         double tn
891         PROTOTYPE: $$
892         CODE:
893         {
894                 g2_filled_raspln(*dev, N_pt, points, tn);
895                 free(points);
896         }
897
898
899 void
900 g2_filled_para_3(dev, N_pt, points)
901         G2::Device      dev
902         int     N_pt
903         double * points
904         PROTOTYPE: $$
905         CODE:
906         {
907                 g2_filled_para_3(*dev, N_pt, points);
908                 free(points);
909         }
910
911
912 void
913 g2_filled_para_5(dev, N_pt, points)
914         G2::Device      dev
915         int     N_pt
916         double * points
917         PROTOTYPE: $$
918         CODE:
919         {
920                 g2_filled_para_5(*dev, N_pt, points);
921                 free(points);
922         }