home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part03 / e_copy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  4.5 KB  |  187 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "resources.h"
  15. #include "mode.h"
  16. #include "object.h"
  17. #include "paintop.h"
  18. #include "u_elastic.h"
  19. #include "u_search.h"
  20. #include "u_create.h"
  21. #include "w_canvas.h"
  22. #include "w_mousefun.h"
  23. #include "w_setup.h"
  24.  
  25. /* local routine declarations */
  26. static        init_copy(), init_arb_copy(), init_constrained_copy();
  27. static        init_copy_to_scrap();
  28.  
  29. copy_selected()
  30. {
  31.     canvas_kbd_proc = null_proc;
  32.     canvas_locmove_proc = null_proc;
  33.     init_searchproc_left(init_arb_copy);
  34.     init_searchproc_middle(init_constrained_copy);
  35.     init_searchproc_right(init_copy_to_scrap);
  36.     canvas_leftbut_proc = object_search_left;
  37.     canvas_middlebut_proc = object_search_middle;
  38.     canvas_rightbut_proc = object_search_right;
  39.     return_proc = copy_selected;
  40.     set_cursor(pick15_cursor);
  41.     set_mousefun("copy object", "horiz/vert copy", "copy to cut buf");
  42.     reset_action_on();
  43. }
  44.  
  45. static
  46. init_arb_copy(p, type, x, y, px, py)
  47.     char       *p;
  48.     int            type;
  49.     int            x, y, px, py;
  50. {
  51.     constrained = MOVE_ARB;
  52.     init_copy(p, type, x, y, px, py);
  53.     canvas_middlebut_proc = null_proc;
  54.     set_mousefun("place object", "", "cancel");
  55.     draw_mousefun_canvas();
  56. }
  57.  
  58. static
  59. init_constrained_copy(p, type, x, y, px, py)
  60.     char       *p;
  61.     int            type;
  62.     int            x, y, px, py;
  63. {
  64.     constrained = MOVE_HORIZ_VERT;
  65.     init_copy(p, type, x, y, px, py);
  66.     canvas_middlebut_proc = canvas_leftbut_proc;
  67.     canvas_leftbut_proc = null_proc;
  68.     set_mousefun("", "place object", "cancel");
  69.     draw_mousefun_canvas();
  70. }
  71.  
  72. static
  73. init_copy(p, type, x, y, px, py)
  74.     char       *p;
  75.     int            type;
  76.     int            x, y, px, py;
  77. {
  78.     switch (type) {
  79.     case O_COMPOUND:
  80.     set_temp_cursor(null_cursor);
  81.     cur_c = (F_compound *) p;
  82.     new_c = copy_compound(cur_c);
  83.     init_compounddragging(new_c, px, py);
  84.     break;
  85.     case O_POLYLINE:
  86.     set_temp_cursor(null_cursor);
  87.     cur_l = (F_line *) p;
  88.     new_l = copy_line(cur_l);
  89.     init_linedragging(new_l, px, py);
  90.     break;
  91.     case O_TEXT:
  92.     set_temp_cursor(null_cursor);
  93.     cur_t = (F_text *) p;
  94.     new_t = copy_text(cur_t);
  95.     init_textdragging(new_t, x, y);
  96.     break;
  97.     case O_ELLIPSE:
  98.     set_temp_cursor(null_cursor);
  99.     cur_e = (F_ellipse *) p;
  100.     new_e = copy_ellipse(cur_e);
  101.     init_ellipsedragging(new_e, px, py);
  102.     break;
  103.     case O_ARC:
  104.     set_temp_cursor(null_cursor);
  105.     cur_a = (F_arc *) p;
  106.     new_a = copy_arc(cur_a);
  107.     init_arcdragging(new_a, px, py);
  108.     break;
  109.     case O_SPLINE:
  110.     set_temp_cursor(null_cursor);
  111.     cur_s = (F_spline *) p;
  112.     new_s = copy_spline(cur_s);
  113.     init_splinedragging(new_s, px, py);
  114.     break;
  115.     default:
  116.     return;
  117.     }
  118. }
  119.  
  120. static
  121. init_copy_to_scrap(p, type, x, y, px, py)
  122.     char       *p;
  123.     int            type;
  124.     int            x, y;
  125.     int            px, py;
  126. {
  127.     FILE       *fp;
  128.     struct stat        file_status;
  129.  
  130.     if (stat(cut_buf_name, &file_status) == 0) {    /* file exists */
  131.     if (file_status.st_mode & S_IFDIR) {
  132.         put_msg("\"%s\" is a directory", cut_buf_name);
  133.         return;
  134.     }
  135.     if (file_status.st_mode & S_IWRITE) {    /* writing is permitted */
  136.         if (file_status.st_uid != geteuid()) {
  137.         put_msg("Error: access denied to cut file");
  138.         return;
  139.         }
  140.     } else {
  141.         put_msg("Error: cut file is read only");
  142.         return;
  143.     }
  144.     } else if (errno != ENOENT)
  145.     return;            /* file does exist but stat fails */
  146.  
  147.     if ((fp = fopen(cut_buf_name, "w")) == NULL) {
  148.     put_msg("Couldn't open cut file %s", sys_errlist[errno]);
  149.     return;
  150.     } else {
  151.     (void) fprintf(fp, "%s\n", file_header);
  152.     (void) fprintf(fp, "%d %d\n", PIX_PER_INCH, 2);
  153.     }
  154.  
  155.     switch (type) {
  156.     case O_COMPOUND:
  157.     cur_c = (F_compound *) p;
  158.     write_compound(fp, cur_c);
  159.     break;
  160.     case O_ARC:
  161.     cur_a = (F_arc *) p;
  162.     write_arc(fp, cur_a);
  163.     break;
  164.     case O_ELLIPSE:
  165.     cur_e = (F_ellipse *) p;
  166.     write_ellipse(fp, cur_e);
  167.     break;
  168.     case O_POLYLINE:
  169.     cur_l = (F_line *) p;
  170.     write_line(fp, cur_l);
  171.     break;
  172.     case O_TEXT:
  173.     cur_t = (F_text *) p;
  174.     write_text(fp, cur_t);
  175.     break;
  176.     case O_SPLINE:
  177.     cur_s = (F_spline *) p;
  178.     write_spline(fp, cur_s);
  179.     break;
  180.     default:
  181.     fclose(fp);
  182.     return;
  183.     }
  184.     put_msg("Object copied to scrap");
  185.     fclose(fp);
  186. }
  187.