home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Gnuplot 3.5 / source / term_prep.c < prev    next >
Encoding:
Text File  |  1993-11-11  |  56.9 KB  |  2,259 lines  |  [TEXT/KAHL]

  1. char global_merde[80];
  2. static char *RCSid = "$Id: term.c%v 3.50.1.17 1993/08/27 05:21:33 woo Exp woo $";
  3. char * alloc(size_t size, char *message);
  4. extern short __F_MIN[], __F_MAX[], __F_EPSILON[];
  5. extern short __D_MIN[], __D_MAX[], __D_EPSILON[];
  6. extern short __X_MIN[], __X_MAX[], __X_EPSILON[];
  7. typedef int TBOOLEAN;
  8. typedef int (*FUNC_PTR)();
  9. enum operators {
  10. PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD, CALL, CALLN, LNOT, BNOT, UMINUS,
  11. LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
  12. DIV, MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  13. };
  14. enum DATA_TYPES {
  15. INTGR, CMPLX
  16. };
  17. enum PLOT_TYPE {
  18. FUNC, DATA, FUNC3D, DATA3D
  19. };
  20. enum PLOT_STYLE {
  21. LINES, POINTSTYLE, IMPULSES, LINESPOINTS, DOTS, ERRORBARS, BOXES, BOXERROR, STEPS
  22. };
  23. enum JUSTIFY {
  24. LEFT, CENTRE, RIGHT
  25. };
  26. struct cmplx {
  27. double real, imag;
  28. };
  29. struct value {
  30. enum DATA_TYPES type;
  31. union {
  32. int int_val;
  33. struct cmplx cmplx_val;
  34. } v;
  35. };
  36. struct lexical_unit {
  37. TBOOLEAN is_token;
  38. struct value l_val;
  39. int start_index;
  40. int length;
  41. };
  42. struct ft_entry {
  43. char *f_name;
  44. FUNC_PTR func;
  45. };
  46. struct udft_entry {
  47. struct udft_entry *next_udf;
  48. char udf_name[50+1];
  49. struct at_type *at;
  50. char *definition;
  51. struct value dummy_values[5];
  52. };
  53. struct udvt_entry {
  54. struct udvt_entry *next_udv;
  55. char udv_name[50+1];
  56. TBOOLEAN udv_undef;
  57. struct value udv_value;
  58. };
  59. union argument {
  60. int j_arg;
  61. struct value v_arg;
  62. struct udvt_entry *udv_arg;
  63. struct udft_entry *udf_arg;
  64. };
  65. struct at_entry {
  66. enum operators index;
  67. union argument arg;
  68. };
  69. struct at_type {
  70. int a_count;
  71. struct at_entry actions[150];
  72. };
  73. enum coord_type {
  74. INRANGE,
  75. OUTRANGE,
  76. UNDEFINED
  77. };
  78. typedef double coordval;
  79. struct coordinate {
  80. enum coord_type type;
  81. coordval x, y, z;
  82. coordval ylow, yhigh;
  83. };
  84. struct curve_points {
  85. struct curve_points *next_cp;
  86. enum PLOT_TYPE plot_type;
  87. enum PLOT_STYLE plot_style;
  88. char *title;
  89. int line_type;
  90. int point_type;
  91. int p_max;
  92. int p_count;
  93. struct coordinate *points;
  94. };
  95. struct gnuplot_contours {
  96. struct gnuplot_contours *next;
  97. struct coordinate *coords;
  98. char isNewLevel;
  99. char label[12];
  100. int num_pts;
  101. };
  102. struct iso_curve {
  103. struct iso_curve *next;
  104. int p_max;
  105. int p_count;
  106. struct coordinate *points;
  107. };
  108. struct surface_points {
  109. struct surface_points *next_sp;
  110. enum PLOT_TYPE plot_type;
  111. enum PLOT_STYLE plot_style;
  112. char *title;
  113. int line_type;
  114. int point_type;
  115. int has_grid_topology;
  116. int num_iso_read;
  117. struct gnuplot_contours *contours;
  118. struct iso_curve *iso_crvs;
  119. };
  120. struct TERMENTRY {
  121. char *name;
  122. char *description;
  123. unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  124.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype;
  125.     int (*put_text)(unsigned int, unsigned int, char *);
  126.     FUNC_PTR text_angle,justify_text,point,arrow;
  127. };
  128. struct text_label {
  129. struct text_label *next;
  130. int tag;
  131. double x,y,z;
  132. enum JUSTIFY pos;
  133. char text[1024+1];
  134. };
  135. struct arrow_def {
  136. struct arrow_def *next;
  137. int tag;
  138. double sx,sy,sz;
  139. double ex,ey,ez;
  140. TBOOLEAN head;
  141. };
  142. struct ticdef {
  143. int type;
  144. union {
  145. struct {
  146. double start, incr;
  147. double end;
  148. } series;
  149. struct ticmark *user;
  150. } def;
  151. };
  152. struct ticmark {
  153. double position;
  154. char *label;
  155. struct ticmark *next;
  156. };
  157. extern TBOOLEAN screen_ok;
  158. extern TBOOLEAN term_init;
  159. extern TBOOLEAN undefined;
  160. extern struct TERMENTRY term_tbl[];
  161. extern struct curve_points *cp_alloc();
  162. extern int cp_extend();
  163. extern int cp_free();
  164. extern struct surface_points *sp_alloc();
  165. extern int sp_replace();
  166. extern int sp_free();
  167. extern struct iso_curve *iso_alloc();
  168. extern int iso_extend();
  169. extern int iso_free();
  170. typedef double transform_matrix[4][4];
  171. struct gnuplot_contours *contour(int, struct iso_curve *, int, int, int, int, int, double *);
  172. int add_cntr_point(double, double);
  173. int end_crnt_cntr(void);
  174. struct udvt_entry *add_udv(int);
  175. struct udft_entry *add_udf(int);
  176. union argument *add_action(enum operators);
  177. int standard(int);
  178. int execute_at(struct at_type *);
  179. int scanner(char[]);
  180. int get_num(char[]);
  181. int substitute(char *, int);
  182. int f_real(void);
  183. int f_imag(void);
  184. int f_arg(void);
  185. int f_conjg(void);
  186. int f_sin(void);
  187. int f_cos(void);
  188. int f_tan(void);
  189. int f_asin(void);
  190. int f_acos(void);
  191. int f_atan(void);
  192. int f_sinh(void);
  193. int f_cosh(void);
  194. int f_tanh(void);
  195. int f_int(void);
  196. int f_abs(void);
  197. int f_sgn(void);
  198. int f_sqrt(void);
  199. int f_exp(void);
  200. int f_log10(void);
  201. int f_log(void);
  202. int f_floor(void);
  203. int f_ceil(void);
  204. double jzero(double);
  205. double pzero(double);
  206. double qzero(double);
  207. double yzero(double);
  208. double rj0(double);
  209. double ry0(double);
  210. double jone(double);
  211. double pone(double);
  212. double qone(double);
  213. double yone(double);
  214. double rj1(double);
  215. double ry1(double);
  216. int f_besj0(void);
  217. int f_besj1(void);
  218. int f_besy0(void);
  219. int f_besy1(void);
  220. int chr_in_str(int, char);
  221. int equals(int, char *);
  222. int almost_equals(int, char *);
  223. int isstring(int);
  224. int isnumber(int);
  225. int isletter(int);
  226. int is_definition(int);
  227. int copy_str(char[], int);
  228. int quote_str(char[], int);
  229. int quotel_str(char[], int);
  230. int capture(char[], int, int);
  231. int m_capture(char **, int, int);
  232. int m_quote_capture(char **, int, int);
  233. int convert(struct value *, int);
  234. int disp_value(FILE *, struct value *);
  235. double real(struct value *);
  236. double imag(struct value *);
  237. double magnitude(struct value *);
  238. double angle(struct value *);
  239. struct value *Gcomplex(struct value *, double, double);
  240. struct value *Ginteger(struct value *, int);
  241. int os_error(char[], int);
  242. int int_error(char[], int);
  243. void lower_case(char *);
  244. void squash_spaces(char *);
  245. void b_setpixel(unsigned int, unsigned int, unsigned int);
  246. void b_makebitmap(unsigned int, unsigned int, unsigned int);
  247. void b_freebitmap(void);
  248. void b_setmaskpixel(unsigned int, unsigned int, unsigned int);
  249. void b_line(unsigned int, unsigned int, unsigned int, unsigned int);
  250. void b_charsize(unsigned int);
  251. void b_putc(unsigned int, unsigned int, char, unsigned int);
  252. int b_setlinetype(int);
  253. void b_setvalue(unsigned int);
  254. int b_move(unsigned int, unsigned int);
  255. int b_vector(unsigned int, unsigned int);
  256. int b_put_text(unsigned int, unsigned int, char *);
  257. int b_text_angle(int);
  258. unsigned int b_getpixel(unsigned int, unsigned int);
  259. int help(char *, char *, TBOOLEAN *);
  260. void FreeHelp(void);
  261. char *alloc(unsigned long, char *);
  262. struct curve_points *cp_alloc(int);
  263. int cp_extend(struct curve_points *, int);
  264. int cp_free(struct curve_points *);
  265. struct iso_curve *iso_alloc(int);
  266. int iso_extend(struct iso_curve *, int);
  267. int iso_free(struct iso_curve *);
  268. struct surface_points *sp_alloc(int, int, int, int);
  269. int sp_replace(struct surface_points *, int, int, int, int);
  270. int sp_free(struct surface_points *);
  271. int save_functions(FILE *);
  272. int save_variables(FILE *);
  273. int save_all(FILE *);
  274. int save_set(FILE *);
  275. int save_set_all(FILE *);
  276. int save_tics(FILE *, TBOOLEAN, char, struct ticdef *);
  277. int load_file(FILE *, char *);
  278. FILE *lf_top(void);
  279. int load_file_error(void);
  280. int instring(char *, char);
  281. int show_functions(void);
  282. int show_at(void);
  283. int disp_at(struct at_type *, int);
  284. void fpe(void);
  285. int evaluate_at(struct at_type *, struct value *);
  286. struct value *const_express(struct value *);
  287. struct at_type *temp_at(void);
  288. struct at_type *perm_at(void);
  289. int express(void);
  290. int xterm(void);
  291. int aterm(void);
  292. int bterm(void);
  293. int cterm(void);
  294. int dterm(void);
  295. int eterm(void);
  296. int fterm(void);
  297. int gterm(void);
  298. int hterm(void);
  299. int factor(void);
  300. int xterms(void);
  301. int aterms(void);
  302. int bterms(void);
  303. int cterms(void);
  304. int dterms(void);
  305. int eterms(void);
  306. int fterms(void);
  307. int gterms(void);
  308. int hterms(void);
  309. int iterms(void);
  310. int unary(void);
  311. void tc_interrupt(void);
  312. int gnu_main(int, int);
  313. int unix_main(int, char **);
  314. int purec_matherr(struct exception *);
  315. int interrupt_setup(void);
  316. char *gpfaralloc(unsigned long, char *);
  317. char *gpfarrealloc(char *, unsigned long);
  318. void gpfarfree(char *);
  319. int is_binary_file(FILE *);
  320. int fread_matrix(FILE *, float * * *, int *, int *, float * *, float * *);
  321. int fwrite_matrix(FILE *, float * *, int, int, int, int, float *, float *);
  322. float *vector(int, int);
  323. void free_vector(float *, int, int);
  324. float *extend_vector(float *, int, int, int);
  325. float *retract_vector(float *, int, int, int);
  326. float * *matrix(int, int, int, int);
  327. void free_matrix(float * *, unsigned, unsigned, unsigned, unsigned);
  328. float * *extend_matrix(float * *, int, int, int, int, int, int);
  329. float * *retract_matrix(float * *, int, int, int, int, int, int);
  330. float * *convert_matrix(float *, int, int, int, int);
  331. void free_convert_matrix(float * *, int, int, int, int);
  332. int get_binary_data(struct surface_points *, FILE *, struct iso_curve **);
  333. int matherr(void);
  334. int reset_stack(void);
  335. int check_stack(void);
  336. struct value *pop(struct value *);
  337. int push(struct value *);
  338. int f_push(union argument *);
  339. int f_pushc(union argument *);
  340. int f_pushd1(union argument *);
  341. int f_pushd2(union argument *);
  342. int f_pushd(union argument *);
  343. int f_call(union argument *);
  344. int f_calln(union argument *);
  345. int f_lnot(void);
  346. int f_bnot(void);
  347. int f_bool(void);
  348. int f_lor(void);
  349. int f_land(void);
  350. int f_bor(void);
  351. int f_xor(void);
  352. int f_band(void);
  353. int f_uminus(void);
  354. int f_eq(void);
  355. int f_ne(void);
  356. int f_gt(void);
  357. int f_lt(void);
  358. int f_ge(void);
  359. int f_le(void);
  360. int f_plus(void);
  361. int f_minus(void);
  362. int f_mult(void);
  363. int f_div(void);
  364. int f_mod(void);
  365. int f_power(void);
  366. int f_factorial(void);
  367. int f_jump(union argument *);
  368. int f_jumpz(union argument *);
  369. int f_jumpnz(union argument *);
  370. int f_jtern(union argument *);
  371. int user_putc(int);
  372. int user_puts(char *);
  373. int backspace(void);
  374. char *readline(char *);
  375. void add_history(char *);
  376. int f_erf(void);
  377. int f_erfc(void);
  378. int f_ibeta(void);
  379. int f_igamma(void);
  380. int f_gamma(void);
  381. int f_lgamma(void);
  382. int f_rand(void);
  383. int f_rand(void);
  384. int f_normal(void);
  385. int f_inverse_normal(void);
  386. int f_inverse_erf(void);
  387. double inverse_normal_func(double);
  388. double inverse_error_func(double);
  389. int chdir(char *);
  390. char *getcwd(char *, int);
  391. int do_point(int, int, int);
  392. int line_and_point(int, int, int);
  393. int do_arrow(int, int, int, int, TBOOLEAN);
  394. int options_null(void);
  395. int list_terms(void);
  396. int set_term(int);
  397. int change_term(char *, int);
  398. int init_terminal(void);
  399. char *turboc_init(void);
  400. char *ztc_init(void);
  401. int UP_redirect(int);
  402. int UP_redirect(int);
  403. int test_term(void);
  404. void reopen_binary(void);
  405. char *vms_init(void);
  406. void vms_reset(void);
  407. void term_mode_tek(void);
  408. void term_mode_native(void);
  409. void term_pasthru(void);
  410. void term_nopasthru(void);
  411. void reopen_binary(void);
  412. void fflush_binary(void);
  413. void set_command(void);
  414. enum PLOT_STYLE get_style(void);
  415. TBOOLEAN load_range(double *, double *);
  416. void show_command(void);
  417. void show_version(void);
  418. void set_command(void);
  419. enum PLOT_STYLE get_style(void);
  420. TBOOLEAN load_range(double *, double *);
  421. void show_command(void);
  422. void show_version(void);
  423. void mat_mult(transform_matrix, transform_matrix, transform_matrix);
  424. int setlinestyle(int);
  425. void clip_move(int, int);
  426. void clip_vector(int, int);
  427. void clip_put_text(int, int, char *);
  428. double make_3dtics(double, double, int, TBOOLEAN, double);
  429. int do_3dplot(struct surface_points *, int, double, double, double, double, double, double);
  430. int update_extrema_pts(int, int, int *, int *, int *, int *, double , double );
  431. int draw_bottom_grid(struct surface_points *, double, double);
  432. int draw_month_3dxtics(double);
  433. int draw_month_3dytics(double);
  434. int draw_month_3dztics(double, double, double, double);
  435. int draw_day_3dxtics(double);
  436. int draw_day_3dytics(double);
  437. int draw_day_3dztics(double, double, double, double);
  438. int xtick3d(double place, char *text, double spacing, double ticscale, double ypos);
  439. int ytick3d(double place, char *text, double spacing, double ticscale, double xpos);
  440. int ztick3d(double place, char *text, double spacing, double ticscale, double xpos, double ypos);
  441. int mat_scale(double, double, double, transform_matrix);
  442. int mat_rot_x(double, transform_matrix);
  443. int mat_rot_z(double, transform_matrix);
  444. void mat_mult(transform_matrix, transform_matrix, transform_matrix);
  445. int map3d_xy(double, double, double, int *, int *);
  446. int map3d_z(double, double, double);
  447. int do_3dplot(struct surface_points *, int, double, double, double, double, double, double);
  448. int draw_bottom_grid(struct surface_points *, double , double);
  449. int draw_month_3dxtics(double);
  450. int draw_month_3dytics(double);
  451. int draw_month_3dztics(double, double, double, double);
  452. int draw_day_3dxtics(double);
  453. int draw_day_3dytics(double);
  454. int draw_day_3dztics(double, double, double, double);
  455. int xtick3d(double place, char *text, double spacing, double ticscale, double ypos);
  456. int ytick3d(double place, char *text, double spacing, double ticscale, double xpos);
  457. int ztick3d(double place, char *text, double spacing, double ticscale, double xpos, double ypos);
  458. int purec_sscanf(const char *, const char *, ...);
  459. int com_line(void);
  460. int do_line(void);
  461. int command(void);
  462. int replotrequest(void);
  463. int plotrequest(void);
  464. int plot3drequest(void);
  465. int define(void);
  466. int get_data(struct curve_points *);
  467. int store2d_point(struct curve_points *, int, double, double, double, double, double);
  468. int adjust_yrange(struct curve_points *);
  469. int grid_nongrid_data(struct surface_points *);
  470. int get_3ddata(struct surface_points *);
  471. int print_points(int);
  472. int print_table(void);
  473. int print_3dtable(int);
  474. int eval_plots(void);
  475. int eval_3dplots(void);
  476. int done(int);
  477. void parametric_fixup(struct curve_points *, int *, double *, double *);
  478. void parametric_3dfixup(struct surface_points *, int *, double *, double *, double *, double *, double *, double *);
  479. int read_line(char *);
  480. int do_help(void);
  481. int do_shell(void);
  482. int do_system(void);
  483. int purec_sscanf(const char *, const char *, ...);
  484. int com_line(void);
  485. int do_line(void);
  486. int command(void);
  487. int replotrequest(void);
  488. int plotrequest(void);
  489. int plot3drequest(void);
  490. int define(void);
  491. int get_data(struct curve_points *);
  492. int store2d_point(struct curve_points *, int, double, double, double, double, double);
  493. int adjust_yrange(struct curve_points *);
  494. int grid_nongrid_data(struct surface_points *);
  495. int get_3ddata(struct surface_points *);
  496. int print_points(int);
  497. int print_table(void);
  498. int print_3dtable(int);
  499. int eval_plots(void);
  500. int eval_3dplots(void);
  501. int done(int);
  502. void parametric_fixup(struct curve_points *, int *, double *, double *);
  503. void parametric_3dfixup(struct surface_points *, int *, double *, double *, double *, double *, double *, double *);
  504. int read_line(char *);
  505. int do_help(void);
  506. int do_shell(void);
  507. int do_system(void);
  508. int do_help(void);
  509. double LogScale(double, TBOOLEAN, double, char *, char *);
  510. int boundary(TBOOLEAN);
  511. double dbl_raise(double, int);
  512. double make_tics(double, double, TBOOLEAN, double);
  513. int do_plot(struct curve_points *, int, double, double, double, double);
  514. void plot_impulses(struct curve_points *, int, int);
  515. void plot_lines(struct curve_points *);
  516. void plot_steps(struct curve_points *);
  517. void plot_bars(struct curve_points *);
  518. void plot_boxes(struct curve_points *, int);
  519. void plot_points(struct curve_points *);
  520. void plot_dots(struct curve_points *);
  521. void edge_intersect(struct coordinate *, int, double *, double *);
  522. void edge_intersect_steps(struct coordinate *, int, double *, double *);
  523. TBOOLEAN two_edge_intersect_steps(struct coordinate *, int, double *, double *);
  524. TBOOLEAN two_edge_intersect(struct coordinate *, int, double *, double *);
  525. int polar_xform(struct curve_points *, int);
  526. int draw_ytics(double, double, double);
  527. int draw_xtics(double, double, double);
  528. int draw_series_ytics(double, double, double);
  529. int draw_series_xtics(double, double, double);
  530. int draw_month_ytics(void);
  531. int draw_month_xtics(void);
  532. int draw_day_ytics(void);
  533. int draw_day_xtics(void);
  534. int draw_set_ytics(struct ticmark *);
  535. int draw_set_xtics(struct ticmark *);
  536. int ytick(double, char *, double, double);
  537. int xtick(double, char *, double, double);
  538. double LogScale(double, TBOOLEAN, double, char *, char *);
  539. int boundary(TBOOLEAN);
  540. double dbl_raise(double, int);
  541. double make_tics(double, double, TBOOLEAN, double);
  542. int do_plot(struct curve_points *, int, double, double, double, double);
  543. void plot_impulses(struct curve_points *, int, int);
  544. void plot_lines(struct curve_points *);
  545. void plot_steps(struct curve_points *);
  546. void plot_bars(struct curve_points *);
  547. void plot_boxes(struct curve_points *, int);
  548. void plot_points(struct curve_points *);
  549. void plot_dots(struct curve_points *);
  550. void edge_intersect(struct coordinate *, int, double *, double *);
  551. void edge_intersect_steps(struct coordinate *, int, double *, double *);
  552. TBOOLEAN two_edge_intersect_steps(struct coordinate *, int, double *, double *);
  553. TBOOLEAN two_edge_intersect(struct coordinate *, int, double *, double *);
  554. int polar_xform(struct curve_points *, int);
  555. int draw_ytics(double, double, double);
  556. int draw_xtics(double, double, double);
  557. int draw_series_ytics(double, double, double);
  558. int draw_series_xtics(double, double, double);
  559. int draw_month_ytics(void);
  560. int draw_month_xtics(void);
  561. int draw_day_ytics(void);
  562. int draw_day_xtics(void);
  563. int draw_set_ytics(struct ticmark *);
  564. int draw_set_xtics(struct ticmark *);
  565. int ytick(double, char *, double, double);
  566. int xtick(double, char *, double, double);
  567. extern TBOOLEAN autoscale_r;
  568. extern TBOOLEAN autoscale_t;
  569. extern TBOOLEAN autoscale_u;
  570. extern TBOOLEAN autoscale_v;
  571. extern TBOOLEAN autoscale_x;
  572. extern TBOOLEAN autoscale_y;
  573. extern TBOOLEAN autoscale_z;
  574. extern TBOOLEAN autoscale_lt;
  575. extern TBOOLEAN autoscale_lu;
  576. extern TBOOLEAN autoscale_lv;
  577. extern TBOOLEAN autoscale_lx;
  578. extern TBOOLEAN autoscale_ly;
  579. extern TBOOLEAN autoscale_lz;
  580. extern double boxwidth;
  581. extern TBOOLEAN clip_points;
  582. extern TBOOLEAN clip_lines1;
  583. extern TBOOLEAN clip_lines2;
  584. extern TBOOLEAN draw_border;
  585. extern TBOOLEAN draw_surface;
  586. extern TBOOLEAN timedate;
  587. extern char dummy_var[5][50+1];
  588. extern char xformat[];
  589. extern char yformat[];
  590. extern char zformat[];
  591. extern enum PLOT_STYLE data_style, func_style;
  592. extern TBOOLEAN grid;
  593. extern int key;
  594. extern double key_x, key_y, key_z;
  595. extern TBOOLEAN is_log_x, is_log_y, is_log_z;
  596. extern double base_log_x, base_log_y, base_log_z;
  597. extern double log_base_log_x, log_base_log_y, log_base_log_z;
  598. extern FILE* outfile;
  599. extern char outstr[];
  600. extern TBOOLEAN parametric;
  601. extern TBOOLEAN polar;
  602. extern TBOOLEAN hidden3d;
  603. extern int angles_format;
  604. extern int mapping3d;
  605. extern int samples;
  606. extern int samples_1;
  607. extern int samples_2;
  608. extern int iso_samples_1;
  609. extern int iso_samples_2;
  610. extern float xsize;
  611. extern float ysize;
  612. extern float zsize;
  613. extern float surface_rot_z;
  614. extern float surface_rot_x;
  615. extern float surface_scale;
  616. extern float surface_zscale;
  617. extern int term;
  618. extern char term_options[];
  619. extern char title[];
  620. extern char xlabel[];
  621. extern char ylabel[];
  622. extern char zlabel[];
  623. extern int time_xoffset;
  624. extern int time_yoffset;
  625. extern int title_xoffset;
  626. extern int title_yoffset;
  627. extern int xlabel_xoffset;
  628. extern int xlabel_yoffset;
  629. extern int ylabel_xoffset;
  630. extern int ylabel_yoffset;
  631. extern int zlabel_xoffset;
  632. extern int zlabel_yoffset;
  633. extern double rmin, rmax;
  634. extern double tmin, tmax, umin, umax, vmin, vmax;
  635. extern double xmin, xmax, ymin, ymax, zmin, zmax;
  636. extern double loff, roff, toff, boff;
  637. extern int draw_contour;
  638. extern TBOOLEAN label_contours;
  639. extern int contour_pts;
  640. extern int contour_kind;
  641. extern int contour_order;
  642. extern int contour_levels;
  643. extern double zero;
  644. extern int levels_kind;
  645. extern double levels_list[30];
  646. extern int dgrid3d_row_fineness;
  647. extern int dgrid3d_col_fineness;
  648. extern int dgrid3d_norm_value;
  649. extern TBOOLEAN dgrid3d;
  650. extern TBOOLEAN xzeroaxis;
  651. extern TBOOLEAN yzeroaxis;
  652. extern TBOOLEAN xtics;
  653. extern TBOOLEAN ytics;
  654. extern TBOOLEAN ztics;
  655. extern float ticslevel;
  656. extern struct ticdef xticdef;
  657. extern struct ticdef yticdef;
  658. extern struct ticdef zticdef;
  659. extern TBOOLEAN tic_in;
  660. extern struct text_label *first_label;
  661. extern struct arrow_def *first_arrow;
  662. extern void set_command();
  663. extern void show_command();
  664. extern enum PLOT_STYLE get_style();
  665. extern TBOOLEAN load_range();
  666. extern void show_version();
  667. typedef unsigned int char_row;
  668. typedef char_row * char_box;
  669. extern char_row fnt5x9[96][9];
  670. extern char_row fnt9x17[96][17];
  671. extern char_row fnt13x25[96][25];
  672. typedef unsigned char pixels;
  673. typedef pixels **bitmap;
  674. extern bitmap *b_p;
  675. extern unsigned int b_currx, b_curry;
  676. extern unsigned int b_xsize, b_ysize;
  677. extern unsigned int b_planes;
  678. extern unsigned int b_psize;
  679. extern unsigned int b_rastermode;
  680. extern unsigned int b_linemask;
  681. extern unsigned int b_value;
  682. extern unsigned int b_hchar;
  683. extern unsigned int b_hbits;
  684. extern unsigned int b_vchar;
  685. extern unsigned int b_vbits;
  686. extern unsigned int b_angle;
  687. extern char_box b_font[96];
  688. extern unsigned int b_pattern[];
  689. extern int b_maskcount;
  690. extern unsigned int b_lastx, b_lasty;
  691. TBOOLEAN term_init;
  692. extern FILE *outfile;
  693. extern char outstr[];
  694. extern TBOOLEAN term_init;
  695. extern int term;
  696. extern float xsize, ysize;
  697. extern char input_line[];
  698. extern struct lexical_unit token[];
  699. extern int num_tokens, c_token;
  700. extern struct value *const_express();
  701. extern TBOOLEAN interactive;
  702. extern double sqrt();
  703. char *getenv();
  704. int unixplot=0;
  705. do_point(x,y,number)
  706. int x,y;
  707. int number;
  708. {
  709. register int htic,vtic;
  710. register struct TERMENTRY *t = &term_tbl[term];
  711. if (number < 0) {
  712. (*t->move)(x,y);
  713. (*t->vector)(x,y);
  714. return(0);
  715. }
  716. number %= 6;
  717. htic = (t->h_tic/2);
  718. vtic = (t->v_tic/2);
  719. switch(number) {
  720. case 0:
  721. (*t->move)(x-htic,y);
  722. (*t->vector)(x,y-vtic);
  723. (*t->vector)(x+htic,y);
  724. (*t->vector)(x,y+vtic);
  725. (*t->vector)(x-htic,y);
  726. (*t->move)(x,y);
  727. (*t->vector)(x,y);
  728. break;
  729. case 1:
  730. (*t->move)(x-htic,y);
  731. (*t->vector)(x-htic,y);
  732. (*t->vector)(x+htic,y);
  733. (*t->move)(x,y-vtic);
  734. (*t->vector)(x,y-vtic);
  735. (*t->vector)(x,y+vtic);
  736. break;
  737. case 2:
  738. (*t->move)(x-htic,y-vtic);
  739. (*t->vector)(x-htic,y-vtic);
  740. (*t->vector)(x+htic,y-vtic);
  741. (*t->vector)(x+htic,y+vtic);
  742. (*t->vector)(x-htic,y+vtic);
  743. (*t->vector)(x-htic,y-vtic);
  744. (*t->move)(x,y);
  745. (*t->vector)(x,y);
  746. break;
  747. case 3:
  748. (*t->move)(x-htic,y-vtic);
  749. (*t->vector)(x-htic,y-vtic);
  750. (*t->vector)(x+htic,y+vtic);
  751. (*t->move)(x-htic,y+vtic);
  752. (*t->vector)(x-htic,y+vtic);
  753. (*t->vector)(x+htic,y-vtic);
  754. break;
  755. case 4:
  756. (*t->move)(x,y+(4*vtic/3));
  757. (*t->vector)(x-(4*htic/3),y-(2*vtic/3));
  758. (*t->vector)(x+(4*htic/3),y-(2*vtic/3));
  759. (*t->vector)(x,y+(4*vtic/3));
  760. (*t->move)(x,y);
  761. (*t->vector)(x,y);
  762. break;
  763. case 5:
  764. (*t->move)(x-htic,y);
  765. (*t->vector)(x-htic,y);
  766. (*t->vector)(x+htic,y);
  767. (*t->move)(x,y-vtic);
  768. (*t->vector)(x,y-vtic);
  769. (*t->vector)(x,y+vtic);
  770. (*t->move)(x-htic,y-vtic);
  771. (*t->vector)(x-htic,y-vtic);
  772. (*t->vector)(x+htic,y+vtic);
  773. (*t->move)(x-htic,y+vtic);
  774. (*t->vector)(x-htic,y+vtic);
  775. (*t->vector)(x+htic,y-vtic);
  776. break;
  777. }
  778. }
  779. line_and_point(x,y,number)
  780. int x,y,number;
  781. {
  782. (*term_tbl[term].linetype)(0);
  783. do_point(x,y,number);
  784. }
  785. do_arrow(sx, sy, ex, ey, head)
  786. int sx,sy;
  787. int ex, ey;
  788. TBOOLEAN head;
  789. {
  790. register struct TERMENTRY *t = &term_tbl[term];
  791. int len = (t->h_tic + t->v_tic)/2;
  792. (*t->move)(sx, sy);
  793. (*t->vector)(ex, ey);
  794. if (head) {
  795. if (sx == ex) {
  796. int delta = ((float)len / (1.41421) + 0.5);
  797. if (sy < ey)
  798. delta = -delta;
  799. (*t->move)(ex - delta, ey + delta);
  800. (*t->vector)(ex,ey);
  801. (*t->vector)(ex + delta, ey + delta);
  802. } else {
  803. int dx = sx - ex;
  804. int dy = sy - ey;
  805. double coeff = len / sqrt(2.0*((double)dx*(double)dx
  806. + (double)dy*(double)dy));
  807. int x,y;
  808. x = (int)( ex + (dx + dy) * coeff );
  809. y = (int)( ey + (dy - dx) * coeff );
  810. (*t->move)(x,y);
  811. (*t->vector)(ex,ey);
  812. x = (int)( ex + (dx - dy) * coeff );
  813. y = (int)( ey + (dy + dx) * coeff );
  814. (*t->vector)(x,y);
  815. }
  816. }
  817. }
  818. static struct mif_line {
  819. float fpos_x;
  820. float fpos_y;
  821. struct mif_line *next;
  822. struct mif_line *prev;
  823. } mif_line = {
  824. (((float) (0)) / 1000.0),
  825. (((float) ((10000 - 1))) / 1000.0),
  826. &mif_line,
  827. &mif_line
  828. };
  829. static char mif_justify[64];
  830. static char mif_pen[64], mif_pen_width[64], mif_separation[64];
  831. static int mif_text_ang = 0;
  832. static int mif_pentype = 0;
  833. static int mif_pattern_table[16] = {
  834. 0,
  835. 1,
  836. 2, 3, 4, 8, 12, 13,
  837. 5,
  838. 9, 10, 11, 12, 13, 14, 15
  839. };
  840. static struct mif_group_id {
  841. int group_existance;
  842. int group_id;
  843. } mif_group_id[20];
  844. static int mif_initialized = 0;
  845. static int mif_in_frame = 0;
  846. static int mif_frameno = -1;
  847. static int mif_colour = 1;
  848. static int mif_polyline = 1;
  849. static int insert_mif_line(), proc_group_id();
  850. MIF_options()
  851. {
  852. extern char term_options[];
  853. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  854. if (!(c_token >= num_tokens || equals(c_token,";")) && almost_equals(c_token, "m$onochrome")) {
  855. mif_colour = 0;
  856. c_token++;
  857. }
  858. if (!(c_token >= num_tokens || equals(c_token,";")) && almost_equals(c_token, "c$olour")) {
  859. mif_colour = 1;
  860. c_token++;
  861. }
  862. if (!(c_token >= num_tokens || equals(c_token,";")) && almost_equals(c_token, "v$ectors")) {
  863. mif_polyline = 0;
  864. c_token++;
  865. }
  866. if (!(c_token >= num_tokens || equals(c_token,";")) && almost_equals(c_token, "p$olyline")) {
  867. mif_polyline = 1;
  868. c_token++;
  869. }
  870. if ( !(c_token >= num_tokens || equals(c_token,";")) &&
  871. (almost_equals(c_token, "h$elp") ||
  872. almost_equals(c_token, "?$")) ) {
  873. fprintf((&__file[2]), "Usage: set terminal mif [options]\n");
  874. fprintf((&__file[2]), "\toptions:\n");
  875. fprintf((&__file[2]), "\t\tcolour /        Draw primitives with line types >= 0 in colour (sep. 2-7)\n");
  876. fprintf((&__file[2]), "\t\tmonochrome      Draw primitives in black (sep. 0)                        \n");
  877. fprintf((&__file[2]), "\n");
  878. fprintf((&__file[2]), "\t\tpolyline /      Draw lines as continous curves                           \n");
  879. fprintf((&__file[2]), "\t\tvectors         Draw lines as collections of vectors                     \n");
  880. fprintf((&__file[2]), "\n");
  881. fprintf((&__file[2]), "\t\thelp / ?        Print short usage description on stderr                  \n");
  882. c_token++;
  883. }
  884. }
  885. sprintf(term_options, "%s %s", (mif_colour == 1)? "colour": "monochrome",
  886. (mif_polyline == 1)? "polyline": "vectors");
  887. }
  888. static int free_mif_line()
  889. {
  890. struct mif_line *tline;
  891. while (mif_line.prev != &mif_line) {
  892. tline = mif_line.prev;
  893. mif_line.prev = mif_line.prev->prev;
  894. mif_line.prev->next = &mif_line;
  895. free(tline);
  896. }
  897. mif_line.prev = &mif_line;
  898. mif_line.next = &mif_line;
  899. }
  900. static int put_mif_line()
  901. {
  902. int np, i;
  903. struct mif_line *tline;
  904. if (mif_initialized != 0 && mif_in_frame != 0) {
  905. for (tline = mif_line.next, np = 1; tline != &mif_line; tline = tline->next, np++)
  906. ;
  907. if (np >= 2) {
  908. fprintf(outfile, "\t<PolyLine <GroupID %d> %s %s %s\n",
  909. ( 1 + (mif_pentype) ), mif_pen, mif_pen_width, mif_separation);
  910. fprintf(outfile, "\t\t<NumPoints %d> ", np);
  911. for (i = 0, tline = &mif_line; i < np; i++, tline = tline->next) {
  912. if (i%4 == 0)
  913. fprintf(outfile, "\n\t\t");
  914. fprintf(outfile, "<Point  %.3f %.3f> ", tline->fpos_x, tline->fpos_y);
  915. }
  916. fprintf(outfile, "\n\t>\n");
  917. proc_group_id(( 1 + (mif_pentype) ));
  918. mif_pen[0] = '\0';
  919. mif_pen_width[0] = '\0';
  920. mif_separation[0] = '\0';
  921. mif_line.fpos_x = mif_line.prev->fpos_x;
  922. mif_line.fpos_y = mif_line.prev->fpos_y;
  923. free_mif_line();
  924. }
  925. }
  926. }
  927. MIF_init()
  928. {
  929. int i;
  930. extern char version[];
  931. extern char patchlevel[];
  932. if (mif_initialized == 0 && mif_in_frame == 0) {
  933. mif_initialized = 1;
  934. mif_in_frame = 0;
  935. free_mif_line();
  936. mif_line.fpos_x = (((float) (0)) / 1000.0);
  937. mif_line.fpos_y = (((float) ((10000 - 1))) / 1000.0);
  938. mif_pen[0] = '\0';
  939. mif_pen_width[0] = '\0';
  940. mif_separation[0] = '\0';
  941. sprintf(mif_justify, " <TLAlignment Left> ");
  942. for (i = 0; i < 20; i++) {
  943. mif_group_id[i].group_id = 0;
  944. mif_group_id[i].group_existance = 0;
  945. }
  946. fprintf(outfile, "<MIFFile 3.00> # Generated by gnuplot version %s patchlevel %s; identifies this as a MIF file\n", version, patchlevel);
  947. fprintf(outfile, "#\n");
  948. fprintf(outfile, "# Set a default pen pattern, pen width, unit and font for subsequent objects\n");
  949. fprintf(outfile, "<Pen 0>\n");
  950. fprintf(outfile, "<Fill 15>\n");
  951. fprintf(outfile, "<PenWidth 0.5 pt>\n");
  952. fprintf(outfile, "<Separation 0>\n");
  953. fprintf(outfile, "<Units Ucm>\n");
  954. fprintf(outfile, "<Font <FFamily `Times'> <FSize %d> <FPlain Yes>>\n", 9);
  955. fprintf(outfile, "#\n");
  956. }
  957. }
  958. MIF_reset()
  959. {
  960. if (mif_initialized != 0 && mif_in_frame == 0) {
  961. fprintf(outfile, "#\n");
  962. fprintf(outfile, "# End of MIFFile\n");
  963. mif_initialized = 0;
  964. }
  965. }
  966. MIF_graphics()
  967. {
  968. int i;
  969. if (mif_initialized != 0 && mif_in_frame == 0) {
  970. mif_in_frame = 1;
  971. mif_frameno++;
  972. free_mif_line();
  973. mif_line.fpos_x = (((float) (0)) / 1000.0);
  974. mif_line.fpos_y = (((float) ((10000 - 1))) / 1000.0);
  975. mif_pen[0] = '\0';
  976. mif_pen_width[0] = '\0';
  977. mif_separation[0] = '\0';
  978. sprintf(mif_justify, " <TLAlignment Left> ");
  979. for (i = 0; i < 20; i++) {
  980. mif_group_id[i].group_id = 0;
  981. mif_group_id[i].group_existance = 0;
  982. }
  983. fprintf(outfile, "#\n");
  984. fprintf(outfile, "# Frame number %d with plot of graphics\n", mif_frameno);
  985. fprintf(outfile, "<Frame\n");
  986. fprintf(outfile, "\t<Pen 15>\n");
  987. fprintf(outfile, "\t<Fill 15>\n");
  988. fprintf(outfile, "\t<PenWidth  0.5 pt>\n");
  989. fprintf(outfile, "\t<Separation 0>\n");
  990. fprintf(outfile, "\t<BRect 0.000 %.3f %.3f %.3f>\n",
  991. ((float) mif_frameno)*(((float) (10000+100)) / 1000.0), (((float) (15000)) / 1000.0), (((float) (10000)) / 1000.0));
  992. fprintf(outfile, "\t<NSOffset  0.000>\n");
  993. fprintf(outfile, "\t<BLOffset  0.000>\n");
  994. }
  995. }
  996. MIF_text()
  997. {
  998. int i;
  999. if (mif_initialized != 0 && mif_in_frame != 0) {
  1000. if (mif_polyline == 1)
  1001. put_mif_line();
  1002. fprintf(outfile, "\t#\n");
  1003. fprintf(outfile, "\t# Group the the objects in groups to make the chart easier to manipulate\n");
  1004. fprintf(outfile, "\t# after it's imported into FrameMaker.\n");
  1005. for (i = 0; i < 20; i++) {
  1006. if (mif_group_id[i].group_id != 0 &&
  1007. mif_group_id[i].group_existance == 1) {
  1008. fprintf(outfile, "\t<Group\n");
  1009. fprintf(outfile, "\t\t<ID %d>\n", mif_group_id[i].group_id);
  1010. fprintf(outfile, "\t>\n");
  1011. }
  1012. }
  1013. fprintf(outfile, ">\n");
  1014. fprintf(outfile, "# End of Frame number %d\n", mif_frameno);
  1015. fprintf(outfile, "#\n");
  1016. mif_in_frame = 0;
  1017. }
  1018. }
  1019. MIF_linetype(linetype)
  1020. int linetype;
  1021. {
  1022. if (mif_initialized != 0 && mif_in_frame != 0) {
  1023. if (mif_polyline == 1)
  1024. put_mif_line();
  1025. if (linetype < 0) {
  1026. if (linetype == -1) {
  1027. mif_pentype = 8+16;
  1028. if (mif_colour == 1)
  1029. sprintf(mif_separation, " <Separation 0> ");
  1030. }
  1031. else {
  1032. mif_pentype = 0+16;
  1033. if (mif_colour == 1)
  1034. sprintf(mif_separation, " <Separation 0> ");
  1035. }
  1036. sprintf(mif_pen_width, " <PenWidth 1.0 pt> ");
  1037. }
  1038. else {
  1039. mif_pentype = (linetype)%16;
  1040. sprintf(mif_pen_width, " <PenWidth 0.5 pt> ");
  1041. if (mif_colour == 1)
  1042. sprintf(mif_separation, " <Separation %d> ", 2+(mif_pentype%6));
  1043. }
  1044. sprintf(mif_pen, " <Pen %d> ", mif_pattern_table[mif_pentype%16]);
  1045. }
  1046. }
  1047. int MIF_text_angle(ang)
  1048. int ang;
  1049. {
  1050. if (ang != 0)
  1051. mif_text_ang = 1;
  1052. else
  1053. mif_text_ang = 0;
  1054. return(1);
  1055. }
  1056. MIF_justify_text(mode)
  1057. enum JUSTIFY mode;
  1058. {
  1059. int rval = 1;
  1060. if (mif_initialized != 0 && mif_in_frame != 0) {
  1061. switch (mode) {
  1062. case LEFT:
  1063. sprintf(mif_justify, " <TLAlignment Left> ");
  1064. break;
  1065. case CENTRE:
  1066. sprintf(mif_justify, " <TLAlignment Center> ");
  1067. break;
  1068. case RIGHT:
  1069. sprintf(mif_justify, " <TLAlignment Right> ");
  1070. break;
  1071. default:
  1072. rval = 0;
  1073. break;
  1074. }
  1075. }
  1076. else {
  1077. rval = 0;
  1078. }
  1079. return(rval);
  1080. }
  1081. MIF_vector(x, y)
  1082. unsigned int x, y;
  1083. {
  1084. if (mif_initialized != 0 && mif_in_frame != 0) {
  1085. insert_mif_line((((float) (x)) / 1000.0), (((float) ((10000 - 1)-(int)y)) / 1000.0));
  1086. if (mif_polyline == 0)
  1087. put_mif_line();
  1088. }
  1089. }
  1090. MIF_move(x, y)
  1091. unsigned int x, y;
  1092. {
  1093. if (mif_initialized != 0 && mif_in_frame != 0) {
  1094. if (mif_polyline == 1)
  1095. put_mif_line();
  1096. mif_line.fpos_x = (((float) (x)) / 1000.0);
  1097. mif_line.fpos_y = (((float) ((10000 - 1)-(int)y)) / 1000.0);
  1098. }
  1099. }
  1100. MIF_put_text(x, y, str)
  1101. unsigned int x, y;
  1102. char str[];
  1103. {
  1104. if (mif_initialized != 0 && mif_in_frame != 0) {
  1105. if (mif_polyline == 1)
  1106. put_mif_line();
  1107. MIF_move(x, y-(10000/31)/5);
  1108. if (strlen(str) > 0) {
  1109. fprintf(outfile, "\t<TextLine <GroupID %d> %s %s %s\n",
  1110. ( 1 + (mif_pentype) ), mif_pen, mif_pen_width, mif_separation);
  1111. fprintf(outfile, "\t\t<TLOrigin  %.3f %.3f> %s %s <String `%s'>\n",
  1112. mif_line.fpos_x, mif_line.fpos_y, mif_justify,
  1113. (mif_text_ang == 1)? "<Angle 90>": "",
  1114. str);
  1115. fprintf(outfile, "\t>\n");
  1116. proc_group_id(( 1 + (mif_pentype) ));
  1117. mif_pen[0] = '\0';
  1118. mif_pen_width[0] = '\0';
  1119. mif_separation[0] = '\0';
  1120. mif_justify[0] = '\0';
  1121. }
  1122. }
  1123. }
  1124. static int insert_mif_line(fx, fy)
  1125. float fx, fy;
  1126. {
  1127. int rval = 1;
  1128. if ((mif_line.prev->next = (struct mif_line *) alloc(sizeof(struct mif_line),"MIF driver")) != (struct mif_line *) ((void *) 0)) {
  1129. mif_line.prev->next->next = &mif_line;
  1130. mif_line.prev->next->prev = mif_line.prev;
  1131. mif_line.prev = mif_line.prev->next;
  1132. mif_line.prev->fpos_x = fx;
  1133. mif_line.prev->fpos_y = fy;
  1134. rval = 1;
  1135. }
  1136. else {
  1137. mif_line.prev->next = &mif_line;
  1138. rval = 0;
  1139. }
  1140. return(rval);
  1141. }
  1142. static int proc_group_id(group_id)
  1143. int group_id;
  1144. {
  1145. int i, rval = 0;
  1146. if (mif_initialized != 0 && mif_in_frame != 0) {
  1147. for (i = 0; i < 20 &&
  1148. mif_group_id[i].group_id != 0 &&
  1149. mif_group_id[i].group_id != group_id;
  1150. i++) {
  1151. }
  1152. if (i < 20) {
  1153. if (mif_group_id[i].group_id == 0) {
  1154. mif_group_id[i].group_id = group_id;
  1155. mif_group_id[i].group_existance = 0;
  1156. }
  1157. else {
  1158. if (mif_group_id[i].group_id == group_id) {
  1159. mif_group_id[i].group_existance = 1;
  1160. rval = 1;
  1161. }
  1162. }
  1163. }
  1164. else {
  1165. rval = -2;
  1166. }
  1167. }
  1168. else {
  1169. rval = -1;
  1170. }
  1171. return(rval);
  1172. }
  1173. extern struct __copt {
  1174. short top;
  1175. short left;
  1176. unsigned char *title;
  1177. short procID;
  1178. short txFont;
  1179. short txSize;
  1180. short txFace;
  1181. short nrows;
  1182. short ncols;
  1183. short pause_atexit;
  1184. } __console_options;
  1185. enum { C_RAW, C_CBREAK, C_NOECHO, C_ECHO };
  1186. FILE *__fopenc(void);
  1187. FILE *__freopenc(FILE *, FILE *);
  1188. void __cgotoxy(int, int, FILE *);
  1189. void __cgetxy(int *, int *, FILE *);
  1190. void __ccleos(FILE *);
  1191. void __ccleol(FILE *);
  1192. void __csettabs(int, FILE *);
  1193. void __csetmode(int, FILE *);
  1194. void __cinverse(int, FILE *);
  1195. void __cshow(FILE *);
  1196. void __chide(FILE *);
  1197. void __cecho2file(char *, int, FILE *);
  1198. void __cecho2printer(FILE *);
  1199. int __ccommand(char ***);
  1200. static WindowPtr itsWindow =((void *) 0);
  1201. static GrafPtr savePort =((void *) 0);
  1202. static PicHandle itsPicture =((void *) 0);
  1203. static Handle saveMBar, myMBar;
  1204. static Boolean MAC_event(void);
  1205. static void SetUpMenu(void);
  1206. static void AdjustMenu(void);
  1207. static void RestoreMenu(void);
  1208. MAC_init()
  1209. {
  1210. Rect boundsRect = {50, 10, 200, 200};
  1211. itsWindow = NewWindow(((void *) 0), &boundsRect,"\pMac Graphic Window", 0,
  1212. noGrowDocProc, (void *)-1L, 0, 0L);
  1213. SizeWindow (itsWindow,448+40,271+20,0);
  1214. GetPort(&savePort);
  1215. SetPort(itsWindow);
  1216. TextFont(monaco);
  1217. TextSize(9);
  1218. TextFace(normal);
  1219. PenNormal();
  1220. SetUpMenu();
  1221. SetPort(savePort);
  1222. }
  1223. MAC_graphics()
  1224. {
  1225. GetPort(&savePort);
  1226. SetPort(itsWindow);
  1227. EraseRect(&(((GrafPtr) itsWindow)->portRect));
  1228. ShowWindow (itsWindow);
  1229. BringToFront (itsWindow);
  1230. HiliteWindow (itsWindow,1);
  1231. if(itsPicture != ((void *) 0)){
  1232. KillPicture(itsPicture);
  1233. itsPicture=((void *) 0);
  1234. }
  1235. itsPicture=OpenPicture (&(((GrafPtr) itsWindow)->portRect));
  1236. TextFont(monaco);
  1237. TextSize(9);
  1238. TextFace(normal);
  1239. PenNormal();
  1240. }
  1241. MAC_text()
  1242. {
  1243. Rect myRect;
  1244. ClosePicture();
  1245. if(itsPicture != ((void *) 0)){
  1246. myRect=itsWindow->portRect;
  1247. DrawPicture(itsPicture,&myRect);
  1248. }
  1249. if(itsWindow !=((void *) 0)){
  1250. SetWTitle(itsWindow, "\pHit any key to continue.");
  1251. while(!MAC_event());
  1252. SetWTitle(itsWindow, "\pMac Graphic Window");
  1253. }
  1254. SetPort(savePort);
  1255. __cshow((&__file[1]));
  1256. }
  1257. MAC_linetype(linetype)
  1258. int linetype;
  1259. {
  1260. int lt;
  1261. lt=(linetype > 1?linetype:1);
  1262. PenSize(lt,lt);
  1263. }
  1264. MAC_move(x,y)
  1265. unsigned int x,y;
  1266. {
  1267. MoveTo(x+(468-448),271-y);
  1268. }
  1269. MAC_vector(x,y)
  1270. unsigned int x,y;
  1271. {
  1272. LineTo(x+(468-448),271-y);
  1273. }
  1274. MAC_put_text(x,y,str)
  1275. unsigned int x,y;
  1276. char str[];
  1277. {
  1278. char test[80];
  1279. /*
  1280.  * Laval : bug 
  1281.  */
  1282. strcpy(test,global_merde);
  1283. MoveTo(x+(468-448),271-y+11/2);
  1284. PenNormal();
  1285. /*
  1286.  * DrawString(CtoPstr(str));
  1287.  */
  1288. DrawString(CtoPstr(test));
  1289. PtoCstr(test);
  1290. }
  1291. MAC_reset()
  1292. {
  1293. }
  1294. static Boolean MAC_event(){
  1295. EventRecord theEvent;
  1296. WindowPtr whichWindow;
  1297. SystemTask ();
  1298. if (GetNextEvent (everyEvent, &theEvent))
  1299. switch (theEvent.what){
  1300. case mouseDown:
  1301. switch(FindWindow(theEvent.where,&whichWindow)){
  1302. case inSysWindow:
  1303. SystemClick(&theEvent,whichWindow);
  1304. break;
  1305. case inDrag:{
  1306. Rect dragRect;
  1307. SetRect(&dragRect,4,24,
  1308. screenBits.bounds.right-4,screenBits.bounds.bottom-4);
  1309. DragWindow (whichWindow,theEvent.where, &dragRect);
  1310. }
  1311. break;
  1312. case inMenuBar:
  1313. AdjustMenu();
  1314. doMenuCommand(MenuSelect(theEvent.where));
  1315. RestoreMenu();
  1316. break;
  1317. };
  1318. break;
  1319. case keyDown:
  1320. case autoKey:
  1321. if ((theEvent.modifiers & cmdKey) != 0){
  1322. AdjustMenu();
  1323. doMenuCommand(MenuKey(theEvent.message & charCodeMask));
  1324. RestoreMenu();
  1325. }
  1326. else
  1327. return 1;
  1328. break;
  1329. case updateEvt:
  1330. BeginUpdate(itsWindow);
  1331. if(itsPicture != ((void *) 0)) DrawPicture(itsPicture,&(itsWindow->portRect));
  1332. EndUpdate(itsWindow);
  1333. break;
  1334. case activateEvt:
  1335. InvalRect(&itsWindow->portRect);
  1336. break;
  1337. }
  1338. return 0;
  1339. }
  1340. static doMenuCommand(long mCmd){
  1341. int item,menu;
  1342. Str255 daName;
  1343. short daRefNum;
  1344. item=LoWord(mCmd);
  1345. menu=HiWord(mCmd);
  1346. switch(menu){
  1347. case 1:
  1348. switch ( item ) {
  1349. default:
  1350. GetItem(GetMHandle(1), item, daName);
  1351. daRefNum = OpenDeskAcc(daName);
  1352. break;
  1353. }
  1354. break;
  1355. case 2:
  1356. switch(item){
  1357. case 5:
  1358. doSave();
  1359. break;
  1360. }
  1361. break;
  1362. case 3:
  1363. switch(item){
  1364. case 4:
  1365. doCopy();
  1366. break;
  1367. }
  1368. break;
  1369. }
  1370. HiliteMenu(0);
  1371. }
  1372. static doCopy(){
  1373. if( ZeroScrap() != 0) {
  1374. fprintf((&__file[2]), "Cann't initialize Clippboard\n");
  1375. exit(0);
  1376. }
  1377. else{
  1378. HLock(itsPicture);
  1379. PutScrap(GetHandleSize(itsPicture),'PICT', *itsPicture);
  1380. HUnlock(itsPicture);
  1381. }
  1382. }
  1383. long PICTCount;
  1384. int globalRef;
  1385. PicHandle newPICTHand;
  1386. pascal void PutPICTData(Ptr dataPtr, int byteCount){
  1387. long longCount;
  1388. int err;
  1389. longCount=byteCount;
  1390. PICTCount+=byteCount;
  1391. err=FSWrite(globalRef, &longCount, dataPtr);
  1392. if(newPICTHand != ((void *) 0)) (**newPICTHand).picSize=PICTCount;
  1393. }
  1394. static doSave(){
  1395. Point where={97,103};
  1396. SFReply reply;
  1397. OSErr err;
  1398. int i;
  1399. long longCount,longZero;
  1400. Rect pFrame;
  1401. QDProcs myProcs;
  1402. SFPutFile(where,"\pSave picture into", "\pUntitled", ((void *) 0), &reply);
  1403. if(reply.good) {
  1404. err=Create(reply.fName,reply.vRefNum,'????','PICT');
  1405. if( err == 0 || err == dupFNErr) {
  1406. FSOpen(reply.fName,reply.vRefNum,&globalRef);
  1407. SetStdProcs(&myProcs);
  1408. itsWindow->grafProcs=&myProcs;
  1409. myProcs.putPicProc=(Ptr) PutPICTData;
  1410. longZero=0L;
  1411. longCount=4;
  1412. PICTCount=sizeof(Picture);
  1413. for(i=1;i<=(512/4+sizeof(Picture));i++){
  1414. FSWrite(globalRef,&longCount,&longZero);
  1415. }
  1416. pFrame=(**itsPicture).picFrame;
  1417. newPICTHand=((void *) 0);
  1418. newPICTHand=OpenPicture(&pFrame);
  1419. DrawPicture(itsPicture,&pFrame);
  1420. ClosePicture();
  1421. SetFPos(globalRef, fsFromStart,512);
  1422. longCount=sizeof(Picture);
  1423. FSWrite(globalRef,&longCount,(Ptr) (*newPICTHand));
  1424. FSClose(globalRef);
  1425. itsWindow->grafProcs=((void *) 0);
  1426. KillPicture(newPICTHand);
  1427. }
  1428. else{
  1429. }
  1430. }
  1431. }
  1432. static void SetUpMenu(void){
  1433. MenuHandle mh;
  1434. saveMBar=GetMenuBar();
  1435. ClearMenuBar();
  1436. mh=NewMenu(1,"\p\024");
  1437. InsertMenu(mh,0);
  1438. AddResMenu(GetMHandle(1), 'DRVR');
  1439. mh=NewMenu(2,"\pFile");
  1440. AppendMenu(mh, "\p(New/N;(Open/O;(-;(Close/W;Save/S");
  1441. InsertMenu(mh,0);
  1442. mh=NewMenu(3,"\pEdit");
  1443. AppendMenu(mh, "\p(Undo/Z;(-;(Cut/X;Copy/C");
  1444. InsertMenu(mh,0);
  1445. DrawMenuBar();
  1446. myMBar=GetMenuBar();
  1447. }
  1448. static void AdjustMenu(void){
  1449. SetMenuBar(myMBar);
  1450. DrawMenuBar();
  1451. }
  1452. static void RestoreMenu(void){
  1453. SetMenuBar(saveMBar);
  1454. DrawMenuBar();
  1455. }
  1456. char ps_font[50+1] = "Helvetica" ;
  1457. int ps_fontsize = 14;
  1458. TBOOLEAN ps_portrait = 0;
  1459. TBOOLEAN ps_color = 0;
  1460. TBOOLEAN ps_solid = 0;
  1461. TBOOLEAN ps_eps = 0;
  1462. int ps_page=0;
  1463. int ps_path_count=0;
  1464. int ps_ang=0;
  1465. enum JUSTIFY ps_justify=LEFT;
  1466. char * PS_header[] = {
  1467. "/M {moveto} bind def\n",
  1468. "/L {lineto} bind def\n",
  1469. "/R {rmoveto} bind def\n",
  1470. "/V {rlineto} bind def\n",
  1471. "/vpt2 vpt 2 mul def\n",
  1472. "/hpt2 hpt 2 mul def\n",
  1473. "/Lshow { currentpoint stroke M\n",
  1474. "  0 vshift R show } def\n",
  1475. "/Rshow { currentpoint stroke M\n",
  1476. "  dup stringwidth pop neg vshift R show } def\n",
  1477. "/Cshow { currentpoint stroke M\n",
  1478. "  dup stringwidth pop -2 div vshift R show } def\n",
  1479. "/DL { Color {setrgbcolor Solid {pop []} if 0 setdash }\n",
  1480. " {pop pop pop Solid {pop []} if 0 setdash} ifelse } def\n",
  1481. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  1482. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  1483. "/PL { stroke gnulinewidth setlinewidth } def\n",
  1484. "/LTb { BL [] 0 0 0 DL } def\n",
  1485. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n",
  1486. "/LT0 { PL [] 0 1 0 DL } def\n",
  1487. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  1488. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  1489. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  1490. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  1491. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  1492. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  1493. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  1494. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  1495. "/P { stroke [] 0 setdash\n",
  1496. "  currentlinewidth 2 div sub M\n",
  1497. "  0 currentlinewidth V stroke } def\n",
  1498. "/D { stroke [] 0 setdash 2 copy vpt add M\n",
  1499. "  hpt neg vpt neg V hpt vpt neg V\n",
  1500. "  hpt vpt V hpt neg vpt V closepath stroke\n",
  1501. "  P } def\n",
  1502. "/A { stroke [] 0 setdash vpt sub M 0 vpt2 V\n",
  1503. "  currentpoint stroke M\n",
  1504. "  hpt neg vpt neg R hpt2 0 V stroke\n",
  1505. "  } def\n",
  1506. "/B { stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M\n",
  1507. "  0 vpt2 neg V hpt2 0 V 0 vpt2 V\n",
  1508. "  hpt2 neg 0 V closepath stroke\n",
  1509. "  P } def\n",
  1510. "/C { stroke [] 0 setdash exch hpt sub exch vpt add M\n",
  1511. "  hpt2 vpt2 neg V currentpoint stroke M\n",
  1512. "  hpt2 neg 0 R hpt2 vpt2 V stroke } def\n",
  1513. "/T { stroke [] 0 setdash 2 copy vpt 1.12 mul add M\n",
  1514. "  hpt neg vpt -1.62 mul V\n",
  1515. "  hpt 2 mul 0 V\n",
  1516. "  hpt neg vpt 1.62 mul V closepath stroke\n",
  1517. "  P  } def\n",
  1518. "/S { 2 copy A C} def\n",
  1519. ((void *) 0)
  1520. };
  1521. int PS_pen_x, PS_pen_y;
  1522. int PS_taken;
  1523. int PS_linetype_last;
  1524. TBOOLEAN PS_relative_ok;
  1525. PS_options()
  1526. {
  1527. extern struct value *const_express();
  1528. extern double real();
  1529. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1530. if (almost_equals(c_token,"p$ortrait")) {
  1531. ps_portrait=1;
  1532. ps_eps=0;
  1533. c_token++;
  1534. }
  1535. else if (almost_equals(c_token,"l$andscape")) {
  1536. ps_portrait=0;
  1537. ps_eps=0;
  1538. c_token++;
  1539. }
  1540. else if (almost_equals(c_token,"e$psf")) {
  1541. ps_portrait=1;
  1542. ps_eps = 1;
  1543. c_token++;
  1544. }
  1545. else if (almost_equals(c_token,"d$efault")) {
  1546. ps_portrait=0;
  1547. ps_eps=0;
  1548. ps_color=0;
  1549. strcpy(ps_font,"Helvetica");
  1550. ps_fontsize = 14;
  1551. term_tbl[term].v_char = (unsigned int)(ps_fontsize*(10));
  1552. term_tbl[term].h_char = (unsigned int)(ps_fontsize*(10)*6/10);
  1553. c_token++;
  1554. }
  1555. }
  1556. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1557. if (almost_equals(c_token,"m$onochrome")) {
  1558. ps_color=0;
  1559. c_token++;
  1560. }
  1561. else if (almost_equals(c_token,"c$olor")) {
  1562. ps_color=1;
  1563. c_token++;
  1564. }
  1565. }
  1566. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1567. if (almost_equals(c_token,"s$olid")) {
  1568. ps_solid=1;
  1569. c_token++;
  1570. }
  1571. else if (almost_equals(c_token,"d$ashed")) {
  1572. ps_solid=0;
  1573. c_token++;
  1574. }
  1575. }
  1576. if (!(c_token >= num_tokens || equals(c_token,";")) && isstring(c_token)) {
  1577. quote_str(ps_font,c_token);
  1578. c_token++;
  1579. }
  1580. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1581. struct value a;
  1582. ps_fontsize = (int)real(const_express(&a));
  1583. term_tbl[term].v_char = (unsigned int)(ps_fontsize*(10));
  1584. term_tbl[term].h_char = (unsigned int)(ps_fontsize*(10)*6/10);
  1585. }
  1586. sprintf(term_options,"%s %s %s \"%s\" %d",
  1587. ps_eps ? "eps" : (ps_portrait ? "portrait" : "landscape"),
  1588. ps_color ? "color" : "monochrome",
  1589. ps_solid ? "solid" : "dashed",
  1590. ps_font,ps_fontsize);
  1591. }
  1592. PS_init()
  1593. {
  1594. static char psi1[] = "%%%%Creator: gnuplot\n%%%%DocumentFonts: %s\n%%%%BoundingBox: %d %d ";
  1595. static char psi2[] = "%%%%EndComments\n/gnudict 40 dict def\ngnudict begin\n/Color %s def\n/Solid %s def\n/gnulinewidth %.3f def\n/vshift %d def\n/dl {%d mul} def\n/hpt %.1f def\n/vpt %.1f def\n";
  1596. struct TERMENTRY *t = &term_tbl[term];
  1597. int i;
  1598. ps_page = 0;
  1599. if (!ps_eps)
  1600. fprintf(outfile,"%%!PS-Adobe-2.0\n");
  1601. else
  1602. fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  1603. fprintf(outfile, psi1, ps_font, 50, 50);
  1604. if (ps_portrait)
  1605. fprintf(outfile,"%d %d\n",
  1606. (int)(xsize*(ps_eps ? 0.5 : 1.0)*(7200)/(10)+0.5+50),
  1607. (int)(ysize*(ps_eps ? 0.5 : 1.0)*(5040)/(10)+0.5+50) );
  1608. else
  1609. fprintf(outfile,"%d %d\n",
  1610. (int)(ysize*(ps_eps ? 0.5 : 1.0)*(5040)/(10)+0.5+50),
  1611. (int)(xsize*(ps_eps ? 0.5 : 1.0)*(7200)/(10)+0.5+50) );
  1612. if (!ps_eps)
  1613. fprintf(outfile,"%%%%Pages: (atend)\n");
  1614. fprintf(outfile, psi2,
  1615. ps_color ? "true" : "false",
  1616. ps_solid ? "true" : "false",
  1617. (0.5*(10)),
  1618. (int)(t->v_char)/(-3),
  1619. (10),
  1620. (5040/80)/2.0,
  1621. (5040/80)/2.0);
  1622. for ( i=0; PS_header[i] != ((void *) 0); i++)
  1623. fprintf(outfile,"%s",PS_header[i]);
  1624. fprintf(outfile,"end\n%%%%EndProlog\n");
  1625. }
  1626. PS_graphics()
  1627. {
  1628. static char psg1[] = "0 setgray\n/%s findfont %d scalefont setfont\nnewpath\n";
  1629. struct TERMENTRY *t = &term_tbl[term];
  1630. ps_page++;
  1631. if (!ps_eps)
  1632. fprintf(outfile,"%%%%Page: %d %d\n",ps_page,ps_page);
  1633. fprintf(outfile,"gnudict begin\ngsave\n");
  1634. fprintf(outfile,"%d %d translate\n",50,50);
  1635. fprintf(outfile,"%.3f %.3f scale\n", (ps_eps ? 0.5 : 1.0)/(10),
  1636. (ps_eps ? 0.5 : 1.0)/(10));
  1637. if (!ps_portrait) {
  1638. fprintf(outfile,"90 rotate\n0 %d translate\n", (int)(-5040*ysize));
  1639. }
  1640. fprintf(outfile, psg1, ps_font, (t->v_char) );
  1641. ps_path_count = 0;
  1642. PS_relative_ok = 0;
  1643. PS_pen_x = PS_pen_y = -4000;
  1644. PS_taken = 0;
  1645. PS_linetype_last = -1;
  1646. }
  1647. PS_text()
  1648. {
  1649. ps_path_count = 0;
  1650. fprintf(outfile,"stroke\ngrestore\nend\nshowpage\n");
  1651. }
  1652. PS_reset()
  1653. {
  1654. fprintf(outfile,"%%%%Trailer\n");
  1655. if (!ps_eps)
  1656. fprintf(outfile,"%%%%Pages: %d\n",ps_page);
  1657. }
  1658. PS_linetype(linetype)
  1659. int linetype;
  1660. {
  1661. char *line = "ba012345678";
  1662. linetype = (linetype % 9) + 2;
  1663. PS_relative_ok = 0;
  1664. if (PS_linetype_last == linetype) return(0);
  1665. PS_linetype_last = linetype;
  1666. fprintf(outfile,"LT%c\n", line[linetype]);
  1667. ps_path_count = 0;
  1668. }
  1669. PS_move(x,y)
  1670. unsigned int x,y;
  1671. {
  1672. int dx, dy;
  1673. char abso[20],rel[20];
  1674. dx = x - PS_pen_x;
  1675. dy = y - PS_pen_y;
  1676. if (dx==0 && dy==0 && PS_relative_ok)
  1677. return(0);
  1678. sprintf(abso, "%d %d M\n", x, y);
  1679. sprintf(rel, "%d %d R\n", dx, dy);
  1680. if (strlen(rel) < strlen(abso) && PS_relative_ok){
  1681. fputs(rel, outfile);
  1682. PS_taken++;
  1683. }else
  1684. fputs(abso, outfile);
  1685. PS_relative_ok = 1;
  1686. ps_path_count += 1;
  1687. PS_pen_x = x;
  1688. PS_pen_y = y;
  1689. }
  1690. PS_vector(x,y)
  1691. unsigned int x,y;
  1692. {
  1693. int dx, dy;
  1694. char abso[20],rel[20];
  1695. dx = x - PS_pen_x;
  1696. dy = y - PS_pen_y;
  1697. if (dx==0 && dy==0) return(0);
  1698. sprintf(abso, "%d %d L\n", x, y);
  1699. sprintf(rel, "%d %d V\n", dx, dy);
  1700. if (strlen(rel) < strlen(abso) && PS_relative_ok){
  1701. fputs(rel, outfile);
  1702. PS_taken++;
  1703. }else
  1704. fputs(abso, outfile);
  1705. PS_relative_ok = 1;
  1706. ps_path_count += 1;
  1707. PS_pen_x = x;
  1708. PS_pen_y = y;
  1709. if (ps_path_count >= 400) {
  1710. fprintf(outfile,"currentpoint stroke M\n");
  1711. ps_path_count = 0;
  1712. }
  1713. }
  1714. PS_put_text(x,y,str)
  1715. unsigned int x, y;
  1716. char *str;
  1717. {
  1718. char ch;
  1719. if (!strlen(str)) return(0);
  1720. PS_move(x,y);
  1721. if (ps_ang != 0)
  1722. fprintf(outfile,"currentpoint gsave translate %d rotate 0 0 M\n"
  1723. ,ps_ang*90);
  1724. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = ('(')) : __putc('(', outfile));
  1725. ch = *str++;
  1726. while(ch!='\0') {
  1727. if ( (ch=='(') || (ch==')') || (ch=='\\') )
  1728. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = ('\\')) : __putc('\\', outfile));
  1729. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = (ch)) : __putc(ch, outfile));
  1730. ch = *str++;
  1731. }
  1732. switch(ps_justify) {
  1733. case LEFT : fprintf(outfile,") Lshow\n");
  1734. break;
  1735. case CENTRE : fprintf(outfile,") Cshow\n");
  1736. break;
  1737. case RIGHT : fprintf(outfile,") Rshow\n");
  1738. break;
  1739. }
  1740. if (ps_ang != 0)
  1741. fprintf(outfile,"grestore\n");
  1742. ps_path_count = 0;
  1743. PS_relative_ok = 0;
  1744. }
  1745. int PS_text_angle(ang)
  1746. int ang;
  1747. {
  1748. ps_ang=ang;
  1749. return 1;
  1750. }
  1751. int PS_justify_text(mode)
  1752. enum JUSTIFY mode;
  1753. {
  1754. ps_justify=mode;
  1755. return 1;
  1756. }
  1757. PS_point(x,y,number)
  1758. int x,y;
  1759. int number;
  1760. {
  1761. char *point = "PDABCTS";
  1762. number %= 6;
  1763. if (number < -1)
  1764. number = -1;
  1765. fprintf(outfile,"%d %d %c\n", x, y, point[number+1]);
  1766. PS_relative_ok = 0;
  1767. ps_path_count = 0;
  1768. PS_linetype_last = -1;
  1769. }
  1770. char ai_font[50+1] = "Times-Roman" ;
  1771. int ai_fontsize = 14;
  1772. TBOOLEAN ai_color = 0;
  1773. TBOOLEAN ai_stroke = 0;
  1774. int ai_page=0;
  1775. int ai_path_count=0;
  1776. int ai_ang=0;
  1777. enum JUSTIFY ai_justify=LEFT;
  1778. AI_options()
  1779. {
  1780. extern struct value *const_express();
  1781. extern double real();
  1782. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1783. if (almost_equals(c_token,"d$efault")) {
  1784. ai_color=0;
  1785. strcpy(ai_font,"Times-Roman");
  1786. ai_fontsize = 14;
  1787. c_token++;
  1788. }
  1789. }
  1790. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1791. if (almost_equals(c_token,"m$onochrome")) {
  1792. ai_color=0;
  1793. c_token++;
  1794. }
  1795. else if (almost_equals(c_token,"c$olor")) {
  1796. ai_color=1;
  1797. c_token++;
  1798. }
  1799. }
  1800. if (!(c_token >= num_tokens || equals(c_token,";")) && isstring(c_token)) {
  1801. quote_str(ai_font,c_token);
  1802. c_token++;
  1803. }
  1804. if (!(c_token >= num_tokens || equals(c_token,";"))) {
  1805. struct value a;
  1806. ai_fontsize = (int)real(const_express(&a));
  1807. c_token++;
  1808. term_tbl[term].v_char = (unsigned int)(ai_fontsize*(10.0));
  1809. term_tbl[term].h_char = (unsigned int)(ai_fontsize*(10.0)*6/10);
  1810. }
  1811. sprintf(term_options,"%s \"%s\" %d",
  1812. ai_color ? "color" : "monochrome",ai_font,ai_fontsize);
  1813. }
  1814. AI_init()
  1815. {
  1816. ai_page = 0;
  1817. fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  1818. fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", 50,50,
  1819. (int)((5000)/(10.0)+0.5+50),
  1820. (int)((3500)/(10.0)+0.5+50) );
  1821. fprintf(outfile,"%%%%Template:\n");
  1822. fprintf(outfile,"%%%%EndComments\n");
  1823. fprintf(outfile,"%%%%EndProlog\n");
  1824. }
  1825. AI_graphics()
  1826. {
  1827. ai_page++;
  1828. fprintf(outfile,"0 G\n");
  1829. fprintf(outfile,"1 j\n");
  1830. fprintf(outfile,"1 J\n");
  1831. fprintf(outfile,"u\n");
  1832. ai_path_count = 0;
  1833. ai_stroke = 0;
  1834. }
  1835. AI_text()
  1836. {
  1837. if (ai_stroke) {
  1838. fprintf(outfile,"S\n");
  1839. ai_stroke = 0;
  1840. }
  1841. fprintf(outfile,"U\n");
  1842. ai_path_count = 0;
  1843. }
  1844. AI_reset()
  1845. {
  1846. fprintf(outfile,"%%%%Trailer\n");
  1847. }
  1848. AI_linetype(linetype)
  1849. int linetype;
  1850. {
  1851. if (ai_stroke) {
  1852. fprintf(outfile,"S\n");
  1853. ai_stroke = 0;
  1854. }
  1855. switch(linetype) {
  1856. case -2 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0)*2.0);
  1857. if (ai_color) {
  1858. fprintf(outfile,"0 0 0 1 K\n");
  1859. }
  1860. else {
  1861. fprintf(outfile,"[] 0 d\n");
  1862. }
  1863. break;
  1864. case -1 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0)/2.0);
  1865. if (ai_color) {
  1866. fprintf(outfile,"0 0 0 1 K\n");
  1867. }
  1868. else {
  1869. fprintf(outfile,"[1 2] 0 d\n");
  1870. }
  1871. break;
  1872. case 0 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1873. if (ai_color) {
  1874. fprintf(outfile,"1 0 1 0 K\n");
  1875. }
  1876. else {
  1877. fprintf(outfile,"[] 0 d\n");
  1878. }
  1879. break;
  1880. case 1 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1881. if (ai_color) {
  1882. fprintf(outfile,"1 1 0 0 K\n");
  1883. }
  1884. else {
  1885. fprintf(outfile,"[4 2] 0 d\n");
  1886. }
  1887. break;
  1888. case 2 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1889. if (ai_color) {
  1890. fprintf(outfile,"0 1 1 0 K\n");
  1891. }
  1892. else {
  1893. fprintf(outfile,"[2 3] 0 d\n");
  1894. }
  1895. break;
  1896. case 3 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1897. if (ai_color) {
  1898. fprintf(outfile,"0 1 0 0 K\n");
  1899. }
  1900. else {
  1901. fprintf(outfile,"[1 1.5] 0 d\n");
  1902. }
  1903. break;
  1904. case 4 : fprintf(outfile,"%f w\n",(0.5*(10.0))/(10.0));
  1905. if (ai_color) {
  1906. fprintf(outfile,"1 0 0 0 K\n");
  1907. }
  1908. else {
  1909. fprintf(outfile,"[5 2 1 2] 0 d\n");
  1910. }
  1911. break;
  1912. case 5 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1913. if (ai_color) {
  1914. fprintf(outfile,"0 0 1 0 K\n");
  1915. }
  1916. else {
  1917. fprintf(outfile,"[4 3 1 3] 0 d\n");
  1918. }
  1919. break;
  1920. case 6 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1921. if (ai_color) {
  1922. fprintf(outfile,"0 0 0 1 K\n");
  1923. }
  1924. else {
  1925. fprintf(outfile,"[2 2 2 4] 0 d\n");
  1926. }
  1927. break;
  1928. case 7 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1929. if (ai_color) {
  1930. fprintf(outfile,"0 0.7 1 0 K\n");
  1931. }
  1932. else {
  1933. fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  1934. }
  1935. break;
  1936. case 8 : fprintf(outfile,"%.2f w\n",(0.5*(10.0))/(10.0));
  1937. if (ai_color) {
  1938. fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  1939. }
  1940. else {
  1941. fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  1942. }
  1943. break;
  1944. }
  1945. ai_path_count = 0;
  1946. }
  1947. AI_move(x,y)
  1948. unsigned int x,y;
  1949. {
  1950. if (ai_stroke) fprintf(outfile,"S\n");
  1951. fprintf(outfile,"%.2f %.2f m\n", x/(10.0), y/(10.0));
  1952. ai_path_count += 1;
  1953. ai_stroke = 1;
  1954. }
  1955. AI_vector(x,y)
  1956. unsigned int x,y;
  1957. {
  1958. fprintf(outfile,"%.2f %.2f l\n", x/(10.0), y/(10.0));
  1959. ai_path_count += 1;
  1960. ai_stroke = 1;
  1961. if (ai_path_count >= 400) {
  1962. fprintf(outfile,"S\n%.2f %.2f m\n",x/(10.0),y/(10.0));
  1963. ai_path_count = 0;
  1964. }
  1965. }
  1966. AI_put_text(x,y,str)
  1967. unsigned int x, y;
  1968. char *str;
  1969. {
  1970. char ch;
  1971. if (ai_stroke) {
  1972. fprintf(outfile,"S\n");
  1973. ai_stroke = 0;
  1974. }
  1975. switch(ai_justify) {
  1976. case LEFT : fprintf(outfile,"/_%s %d 0 0 0 z\n",ai_font,ai_fontsize);
  1977. break;
  1978. case CENTRE : fprintf(outfile,"/_%s %d 0 0 1 z\n",ai_font,ai_fontsize);
  1979. break;
  1980. case RIGHT : fprintf(outfile,"/_%s %d 0 0 2 z\n",ai_font,ai_fontsize);
  1981. break;
  1982. }
  1983. if (ai_ang==0) {
  1984. fprintf(outfile,"[ 1 0 0 1 %.2f %.2f] e\n",
  1985. x/(10.0),y/(10.0) - ai_fontsize/3.0);
  1986. }
  1987. else {
  1988. fprintf(outfile,"[ 0 1 -1 0 %.2f %.2f] e\n",
  1989. x/(10.0) - ai_fontsize/3.0,y/(10.0));
  1990. }
  1991. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = ('(')) : __putc('(', outfile));
  1992. ch = *str++;
  1993. while(ch!='\0') {
  1994. if ( (ch=='(') || (ch==')') || (ch=='\\') )
  1995. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = ('\\')) : __putc('\\', outfile));
  1996. ((outfile)->cnt-- > 1 ? (int) (*(outfile)->ptr++ = (ch)) : __putc(ch, outfile));
  1997. ch = *str++;
  1998. }
  1999. fprintf(outfile,") t\nT\n");
  2000. ai_path_count = 0;
  2001. }
  2002. int AI_text_angle(ang)
  2003. int ang;
  2004. {
  2005. ai_ang=ang;
  2006. return 1;
  2007. }
  2008. int AI_justify_text(mode)
  2009. enum JUSTIFY mode;
  2010. {
  2011. ai_justify=mode;
  2012. return 1;
  2013. }
  2014. static int null_text_angle()
  2015. {
  2016. return 0 ;
  2017. }
  2018. static int null_justify_text()
  2019. {
  2020. return 0 ;
  2021. }
  2022. static int null_scale()
  2023. {
  2024. return 0 ;
  2025. }
  2026. static int do_scale()
  2027. {
  2028. return 1 ;
  2029. }
  2030. options_null()
  2031. {
  2032. term_options[0] = '\0';
  2033. }
  2034. static UNKNOWN_null()
  2035. {
  2036. }
  2037. struct TERMENTRY term_tbl[] = {
  2038. {"unknown", "Unknown terminal type - not a plotting device",
  2039. 100, 100, 1, 1,
  2040. 1, 1, options_null, UNKNOWN_null, UNKNOWN_null,
  2041. UNKNOWN_null, null_scale, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  2042. UNKNOWN_null, UNKNOWN_null, null_text_angle,
  2043. null_justify_text, UNKNOWN_null, UNKNOWN_null}
  2044. ,{"table", "Dump ASCII table of X Y [Z] values to output",
  2045. 100, 100, 1, 1,
  2046. 1, 1, options_null, UNKNOWN_null, UNKNOWN_null,
  2047. UNKNOWN_null, null_scale, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  2048. UNKNOWN_null, UNKNOWN_null, null_text_angle,
  2049. null_justify_text, UNKNOWN_null, UNKNOWN_null}
  2050. ,{"aifm", "Adobe Illustrator 3.0 Format",
  2051. 5000, 3500, (14*(10.0)), (14*(10.0)*6/10),
  2052. (3500/80), (3500/80), AI_options, AI_init, AI_reset,
  2053. AI_text, null_scale, AI_graphics, AI_move, AI_vector,
  2054. AI_linetype, AI_put_text, AI_text_angle,
  2055. AI_justify_text, do_point, do_arrow}
  2056. ,{"mif", "Frame maker MIF 3.00 format",
  2057. 15000, 10000, (10000/31), (15000/95),
  2058. (10000/150), (15000/225), MIF_options, MIF_init, MIF_reset,
  2059. MIF_text, null_scale, MIF_graphics, MIF_move, MIF_vector,
  2060. MIF_linetype, MIF_put_text, MIF_text_angle,
  2061. MIF_justify_text, line_and_point, do_arrow}
  2062. ,{"postscript", "PostScript graphics language [mode \042fontname\042 font_size]",
  2063. 7200, 5040, (14*(10)), (14*(10)*6/10),
  2064. (5040/80), (5040/80), PS_options, PS_init, PS_reset,
  2065. PS_text, null_scale, PS_graphics, PS_move, PS_vector,
  2066. PS_linetype, PS_put_text, PS_text_angle,
  2067. PS_justify_text, PS_point, do_arrow}
  2068. ,{"Mac", "Macintosh Graphic Window",
  2069. 448, 271, 11, 6,
  2070. (271/80), (448/80), options_null,MAC_init, MAC_reset,
  2071. MAC_text, null_scale, MAC_graphics, MAC_move, MAC_vector,
  2072. MAC_linetype, MAC_put_text, null_text_angle,
  2073. null_justify_text, line_and_point, do_arrow}
  2074. };
  2075. list_terms()
  2076. {
  2077. register int i;
  2078. fprintf((&__file[2]),"\nAvailable terminal types:\n");
  2079. for (i = 0; i < (sizeof(term_tbl)/sizeof(struct TERMENTRY)); i++)
  2080. fprintf((&__file[2]),"  %15s  %s\n",
  2081. term_tbl[i].name, term_tbl[i].description);
  2082. (void) (((&__file[2]))->cnt-- > 1 ? (int) (*((&__file[2]))->ptr++ = ('\n')) : __putc('\n', (&__file[2])));
  2083. }
  2084. int
  2085. set_term(c_token)
  2086. int c_token;
  2087. {
  2088. register int t;
  2089. char *input_name;
  2090. if (!token[c_token].is_token)
  2091. int_error("terminal name expected",c_token);
  2092. t = -1;
  2093. input_name = input_line + token[c_token].start_index;
  2094. t = change_term(input_name, token[c_token].length);
  2095. if (t == -1)
  2096. int_error("unknown terminal type; type just 'set terminal' for a list",
  2097. c_token);
  2098. if (t == -2)
  2099. int_error("ambiguous terminal name; type just 'set terminal' for a list",
  2100. c_token);
  2101. return(t);
  2102. }
  2103. int
  2104. change_term(name, length)
  2105. char *name;
  2106. int length;
  2107. {
  2108. int i, t = -1;
  2109. for (i = 0; i < (sizeof(term_tbl)/sizeof(struct TERMENTRY)); i++) {
  2110. if (!strncmp(name,term_tbl[i].name,length)) {
  2111. if (t != -1)
  2112. return(-2);
  2113. t = i;
  2114. }
  2115. }
  2116. if (t == -1)
  2117. return(t);
  2118. term = t;
  2119. term_init = 0;
  2120. name = term_tbl[term].name;
  2121. if (!strncmp("unixplot",name,8)) {
  2122. UP_redirect (2);
  2123. } else if (unixplot) {
  2124. UP_redirect (3);
  2125. }
  2126. if (interactive)
  2127. fprintf((&__file[2]), "Terminal type set to '%s'\n", name);
  2128. return(t);
  2129. }
  2130. init_terminal()
  2131. {
  2132. int t;
  2133. char *term_name = ((void *) 0);
  2134. char *gnuterm = ((void *) 0);
  2135. gnuterm = getenv("GNUTERM");
  2136. if (gnuterm != (char *)((void *) 0)) {
  2137. term_name = gnuterm;
  2138. }
  2139. else {
  2140. }
  2141. if (term_name != ((void *) 0) && *term_name != '\0') {
  2142. t = change_term(term_name, (int)strlen(term_name));
  2143. if (t == -1)
  2144. fprintf((&__file[2]), "Unknown terminal name '%s'\n", term_name);
  2145. else if (t == -2)
  2146. fprintf((&__file[2]), "Ambiguous terminal name '%s'\n", term_name);
  2147. else
  2148. ;
  2149. }
  2150. }
  2151. UP_redirect(caller) int caller;
  2152. {
  2153. caller = caller;
  2154. }
  2155. test_term()
  2156. {
  2157. register struct TERMENTRY *t = &term_tbl[term];
  2158. char *str;
  2159. int x,y, xl,yl, i;
  2160. unsigned int xmax, ymax;
  2161. char label[50];
  2162. int scaling;
  2163. if (!term_init) {
  2164. (*t->init)();
  2165. term_init = 1;
  2166. }
  2167. screen_ok = 0;
  2168. scaling = (*t->scale)(xsize, ysize);
  2169. xmax = (unsigned int)(t->xmax * (scaling ? 1 : xsize));
  2170. ymax = (unsigned int)(t->ymax * (scaling ? 1 : ysize));
  2171. (*t->graphics)();
  2172. (*t->linetype)(-2);
  2173. (*t->move)(0,0);
  2174. (*t->vector)(xmax-1,0);
  2175. (*t->vector)(xmax-1,ymax-1);
  2176. (*t->vector)(0,ymax-1);
  2177. (*t->vector)(0,0);
  2178. (void) (*t->justify_text)(LEFT);
  2179. (*t->put_text)(t->h_char*5,ymax-t->v_char*3,"Terminal Test");
  2180. (*t->linetype)(-1);
  2181. (*t->move)(xmax/2,0);
  2182. (*t->vector)(xmax/2,ymax-1);
  2183. (*t->move)(0,ymax/2);
  2184. (*t->vector)(xmax-1,ymax/2);
  2185. (*t->linetype)(-2);
  2186. (*t->move)( xmax/2-t->h_char*10,ymax/2+t->v_char/2);
  2187. (*t->vector)(xmax/2+t->h_char*10,ymax/2+t->v_char/2);
  2188. (*t->vector)(xmax/2+t->h_char*10,ymax/2-t->v_char/2);
  2189. (*t->vector)(xmax/2-t->h_char*10,ymax/2-t->v_char/2);
  2190. (*t->vector)(xmax/2-t->h_char*10,ymax/2+t->v_char/2);
  2191. (*t->put_text)(xmax/2-t->h_char*10,ymax/2,
  2192. "12345678901234567890");
  2193. (void) (*t->justify_text)(LEFT);
  2194. (*t->put_text)(xmax/2,ymax/2+t->v_char*6,"left justified");
  2195. str = "centre+d text";
  2196. if ((*t->justify_text)(CENTRE))
  2197. (*t->put_text)(xmax/2,
  2198. ymax/2+t->v_char*5,str);
  2199. else
  2200. (*t->put_text)(xmax/2-strlen(str)*t->h_char/2,
  2201. ymax/2+t->v_char*5,str);
  2202. str = "right justified";
  2203. if ((*t->justify_text)(RIGHT))
  2204. (*t->put_text)(xmax/2,
  2205. ymax/2+t->v_char*4,str);
  2206. else
  2207. (*t->put_text)(xmax/2-strlen(str)*t->h_char,
  2208. ymax/2+t->v_char*4,str);
  2209. str = "rotated ce+ntred text";
  2210. if ((*t->text_angle)(1)) {
  2211. if ((*t->justify_text)(CENTRE))
  2212. (*t->put_text)(t->v_char,
  2213. ymax/2,str);
  2214. else
  2215. (*t->put_text)(t->v_char,
  2216. ymax/2-strlen(str)*t->h_char/2,str);
  2217. }
  2218. else {
  2219. (void) (*t->justify_text)(LEFT);
  2220. (*t->put_text)(t->h_char*2,ymax/2-t->v_char*2,"Can't rotate text");
  2221. }
  2222. (void) (*t->justify_text)(LEFT);
  2223. (void) (*t->text_angle)(0);
  2224. (*t->move)(xmax/2+t->h_tic*2,0);
  2225. (*t->vector)(xmax/2+t->h_tic*2,t->v_tic);
  2226. (*t->move)(xmax/2,t->v_tic*2);
  2227. (*t->vector)(xmax/2+t->h_tic,t->v_tic*2);
  2228. (*t->put_text)(xmax/2+t->h_tic*2,t->v_tic*2+t->v_char/2,"test tics");
  2229. x = xmax - t->h_char*4 - t->h_tic*4;
  2230. y = ymax - t->v_char;
  2231. for ( i = -2; y > t->v_char; i++ ) {
  2232. (*t->linetype)(i);
  2233. (void) sprintf(label,"%d",i+1);
  2234. if ((*t->justify_text)(RIGHT))
  2235. (*t->put_text)(x,y,label);
  2236. else
  2237. (*t->put_text)(x-strlen(label)*t->h_char,y,label);
  2238. (*t->move)(x+t->h_char,y);
  2239. (*t->vector)(x+t->h_char*4,y);
  2240. if ( i >= -1 )
  2241. (*t->point)(x+t->h_char*4+t->h_tic*2,y,i);
  2242. y -= t->v_char;
  2243. }
  2244. (*t->linetype)(0);
  2245. x = xmax/4;
  2246. y = ymax/4;
  2247. xl = t->h_tic*5;
  2248. yl = t->v_tic*5;
  2249. (*t->arrow)(x,y,x+xl,y,1);
  2250. (*t->arrow)(x,y,x+xl/2,y+yl,1);
  2251. (*t->arrow)(x,y,x,y+yl,1);
  2252. (*t->arrow)(x,y,x-xl/2,y+yl,0);
  2253. (*t->arrow)(x,y,x-xl,y,1);
  2254. (*t->arrow)(x,y,x-xl,y-yl,1);
  2255. (*t->arrow)(x,y,x,y-yl,1);
  2256. (*t->arrow)(x,y,x+xl,y-yl,1);
  2257. (*t->text)();
  2258. }
  2259.