home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part02 / f_load.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  2.5 KB  |  105 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 "u_undo.h"
  18. #include "w_setup.h"
  19.  
  20. extern int    num_object;
  21.  
  22. int
  23. load_file(file)
  24.     char       *file;
  25. {
  26.     int            s;
  27.     F_compound        c;
  28.  
  29.     c.arcs = NULL;
  30.     c.compounds = NULL;
  31.     c.ellipses = NULL;
  32.     c.lines = NULL;
  33.     c.splines = NULL;
  34.     c.texts = NULL;
  35.     c.next = NULL;
  36.     set_temp_cursor(wait_cursor);
  37.     s = read_fig(file, &c);
  38.     if (s == 0) {        /* Successful read */
  39.     clean_up();
  40.     (void) strcpy(save_filename, cur_filename);
  41.     update_cur_filename(file);
  42.     saved_objects = objects;
  43.     objects = c;
  44.     redisplay_canvas();
  45.     put_msg("Current figure \"%s\" (%d objects)", file, num_object);
  46.     set_action(F_LOAD);
  47.     reset_cursor();
  48.     reset_modifiedflag();
  49.     return (0);
  50.     } else if (s == ENOENT) {
  51.     clean_up();
  52.     saved_objects = objects;
  53.     objects = c;
  54.     redisplay_canvas();
  55.     put_msg("Current figure \"%s\" (new file)", file);
  56.     (void) strcpy(save_filename, cur_filename);
  57.     update_cur_filename(file);
  58.     set_action(F_LOAD);
  59.     reset_cursor();
  60.     reset_modifiedflag();
  61.     return (0);
  62.     }
  63.     read_fail_message(file, s);
  64.     reset_modifiedflag();
  65.     reset_cursor();
  66.     return (1);
  67. }
  68.  
  69. int
  70. merge_file(file)
  71.     char       *file;
  72. {
  73.     F_compound        c;
  74.     int            s;
  75.  
  76.     c.arcs = NULL;
  77.     c.compounds = NULL;
  78.     c.ellipses = NULL;
  79.     c.lines = NULL;
  80.     c.splines = NULL;
  81.     c.texts = NULL;
  82.     c.next = NULL;
  83.     set_temp_cursor(wait_cursor);
  84.  
  85.     s = read_fig(file, &c);
  86.     if (s == 0) {        /* Successful read */
  87.     int        xmin, ymin, xmax, ymax;
  88.  
  89.     compound_bound(&c, &xmin, &ymin, &xmax, &ymax);
  90.     clean_up();
  91.     saved_objects = c;
  92.     tail(&objects, &object_tails);
  93.     append_objects(&objects, &saved_objects, &object_tails);
  94.     redisplay_zoomed_region(xmin, ymin, xmax, ymax);
  95.     put_msg("%d object(s) read from \"%s\"", num_object, file);
  96.     set_action_object(F_ADD, O_ALL_OBJECT);
  97.     reset_cursor();
  98.     set_modifiedflag();
  99.     return (0);
  100.     }
  101.     read_fail_message(file, s);
  102.     reset_cursor();
  103.     return (1);
  104. }
  105.