home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calentool / part05 / init.c next >
Encoding:
C/C++ Source or Header  |  1989-05-27  |  16.0 KB  |  477 lines

  1. /*
  2.  * $Header: init.c,v 2.1 89/05/09 14:23:19 billr Exp $
  3.  */
  4. /*
  5.  * init.c
  6.  *
  7.  * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
  8.  *
  9.  * Original source Copyright (C) 1987, Sun Microsystems, Inc.
  10.  *    All Rights Reserved
  11.  * Permission is hereby granted to use and modify this program in source
  12.  * or binary form as long as it is not sold for profit and this copyright
  13.  * notice remains intact.
  14.  *
  15.  *
  16.  * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  17.  *
  18.  * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
  19.  *    All Rights Reserved
  20.  * Permission is hereby granted to use and modify the modifications in source
  21.  * or binary form as long as they are not sold for profit and this copyright
  22.  * notice remains intact.
  23.  */
  24.  
  25. /***************************************************
  26.  *                           *
  27.  *   Initialization routines, for memory pixrects  *
  28.  *   and files.                       *
  29.  *                           *
  30.  ***************************************************/
  31.  
  32.  
  33. #include <stdio.h>
  34. #include <suntool/sunview.h>
  35. #include <suntool/menu.h>
  36. #include <sunwindow/defaults.h>
  37. #include <sys/file.h>
  38. #include <pwd.h>
  39. #include "ct.h"
  40.  
  41.  
  42. extern int dayslot_width, dayslot_height;
  43. extern int weekslot_width, weekslot_height;
  44. extern int ybox_width, ybox_height;
  45. extern Pixrect *daybox_pr, *timeslot_pr, *gray_pr;
  46. extern Pixrect *weekslot_pr, *weekarrow_pr, *smallarrow_pr;
  47. extern Pixrect *arrowshaft_pr, *arrowhead_pr;
  48. extern Pixrect *weekarrowshaft_pr, *weekarrowhead_pr;
  49. extern Pixrect *triangle_pr;
  50. extern Pixrect *ydaybox_pr, *ymonthbox_pr;
  51. extern Frame frame;
  52. extern Frame prompt_frame;
  53. extern int otherfile, mailto, one_based, read_only, version2;
  54. extern char *othername;
  55. extern char version[];
  56. Pixrect *daybox_td_pr, *weekslot_td_pr, *weekarrowshaft_td_pr;
  57. Pixrect *weekarrowhead_td_pr, *ydaybox_td_pr, *timeslot_td_pr;
  58. Pixrect *leftarrow, *rightarrow;
  59. char t_title[160];
  60. char apts_pathname[160], tmpapts_pathname[160];
  61. char apts_dir[128], lib_dir[128];
  62. char printer[64];
  63.  
  64. struct passwd *getpwnam();
  65.  
  66. init_pixrects()
  67. {
  68.     init_daybox_pr();
  69.     init_timeslot_pr();
  70.     init_weekslot_pr();
  71.         init_weekarrow_pr();
  72.     init_arrow_prs();
  73.     init_triangle_pr();
  74.     init_ydaybox_pr();
  75.     init_ymonthbox_pr();
  76. }
  77.  
  78. /* Concentric squares for drawing days of month calendar. */
  79. init_daybox_pr()
  80. {
  81.     Pixrect *pattern;
  82.     int i;
  83.  
  84.     daybox_pr = mem_create(64,64,1);
  85.         pr_vector(daybox_pr,0,0,63,0,PIX_SET,1);
  86.         pr_vector(daybox_pr,63,0,63,63,PIX_SET,1);
  87.         pr_vector(daybox_pr,63,63,0,63,PIX_SET,1);
  88.         pr_vector(daybox_pr,0,63,0,0,PIX_SET,1);
  89.         pr_vector(daybox_pr,2,2,61,2,PIX_SET,1);
  90.         pr_vector(daybox_pr,61,2,61,61,PIX_SET,1);
  91.         pr_vector(daybox_pr,61,61,2,61,PIX_SET,1);
  92.         pr_vector(daybox_pr,2,61,2,2,PIX_SET,1);
  93.     pattern = mem_create(64,2,1);
  94.     for (i=3; i<60; i+=8)
  95.         pr_put(pattern, i, 0, 1);
  96.     for (i=7; i<60; i+=8)
  97.         pr_put(pattern, i, 1, 1);
  98.     daybox_td_pr = mem_create(64,64,1);
  99.         pr_vector(daybox_td_pr,0,0,63,0,PIX_SET,1);
  100.         pr_vector(daybox_td_pr,63,0,63,63,PIX_SET,1);
  101.         pr_vector(daybox_td_pr,63,63,0,63,PIX_SET,1);
  102.         pr_vector(daybox_td_pr,0,63,0,0,PIX_SET,1);
  103.         pr_vector(daybox_td_pr,2,2,61,2,PIX_SET,1);
  104.         pr_vector(daybox_td_pr,61,2,61,61,PIX_SET,1);
  105.         pr_vector(daybox_td_pr,61,61,2,61,PIX_SET,1);
  106.         pr_vector(daybox_td_pr,2,61,2,2,PIX_SET,1);
  107.     pr_replrop(daybox_td_pr, 0, 2, 60, 60, PIX_SRC|PIX_DST, pattern, 0, 0);
  108.     pr_destroy(pattern);
  109.  
  110. }
  111.  
  112. /* Box for 30-minute slot in picture of day. */
  113. init_timeslot_pr()
  114. {
  115.     int i;
  116.     Pixrect *pattern;
  117.  
  118.         timeslot_pr = mem_create(dayslot_width, dayslot_height, 1);
  119.         timeslot_td_pr = mem_create(dayslot_width, dayslot_height, 1);
  120.     pattern = mem_create(dayslot_width, 2, 1);
  121.     for (i=1; i<dayslot_width; i+=8)
  122.         pr_put(pattern, i, 0, 1);
  123.     for (i=5; i<dayslot_width; i+=8)
  124.         pr_put(pattern, i, 1, 1);
  125.         pr_vector(timeslot_pr,0,0,0,dayslot_height-1,PIX_SET,1);
  126.         pr_vector(timeslot_pr,dayslot_width-1,0,
  127.       dayslot_width-1,dayslot_height-1,PIX_SET,1);
  128.         pr_vector(timeslot_td_pr,0,0,0,dayslot_height-1,PIX_SET,1);
  129.         pr_vector(timeslot_td_pr,dayslot_width-1,0,
  130.       dayslot_width-1,dayslot_height-1,PIX_SET,1);
  131.         for (i=0; i<dayslot_width-1; i=i+2) {
  132.                 pr_put(timeslot_pr, i, 0, 1);
  133.                 pr_put(timeslot_pr, i, dayslot_height-1, 1);
  134.                 pr_put(timeslot_td_pr, i, 0, 1);
  135.                 pr_put(timeslot_td_pr, i, dayslot_height-1, 1);
  136.         }
  137.     pr_replrop(timeslot_td_pr, 1, 2, dayslot_width-1, dayslot_height-3, PIX_SRC|PIX_DST, pattern, 0, 0);
  138.     pr_destroy(pattern);
  139. }
  140.  
  141.  
  142. /* Box for 30-minute slot in picture of week. */
  143. init_weekslot_pr()
  144. {
  145.     int i;
  146.     Pixrect *pattern;
  147.  
  148.     weekslot_pr = mem_create(weekslot_width,weekslot_height,1);
  149.     weekslot_td_pr = mem_create(weekslot_width,weekslot_height,1);
  150.     pattern = mem_create(weekslot_width, 2, 1);
  151.     for (i=1; i<weekslot_width; i+=8)
  152.         pr_put(pattern, i, 0, 1);
  153.     for (i=5; i<weekslot_width; i+=8)
  154.         pr_put(pattern, i, 1, 1);
  155.         pr_vector(weekslot_pr,0,0,0,weekslot_width-1,PIX_SET,1);
  156.         pr_vector(weekslot_pr,weekslot_width-1,0,weekslot_width-1,weekslot_height-1,PIX_SET,1);
  157.         pr_vector(weekslot_td_pr,0,0,0,weekslot_height-1,PIX_SET,1);
  158.         pr_vector(weekslot_td_pr,weekslot_width-1,0,weekslot_width-1,weekslot_height-1,PIX_SET,1);
  159.         for (i=0; i<weekslot_width-1; i=i+2) {
  160.                 pr_put(weekslot_pr,i,0,1);
  161.                 pr_put(weekslot_pr,i,weekslot_height-1,1);
  162.                 pr_put(weekslot_td_pr,i,0,1);
  163.                 pr_put(weekslot_td_pr,i,weekslot_height-1,1);
  164.     }
  165.     pr_replrop(weekslot_td_pr, 1, 2, weekslot_width-1, weekslot_height-3, PIX_SRC|PIX_DST, pattern, 0, 0);
  166.     pr_destroy(pattern);
  167. }
  168.  
  169. /* Arrow pointing to a week in picture of month. */
  170. init_weekarrow_pr()
  171. {
  172.     int i;
  173.  
  174.     weekarrow_pr = mem_create(42,29,1);
  175.         pr_vector(weekarrow_pr,0,0,27,0,PIX_SET,1);
  176.         pr_vector(weekarrow_pr,27,0,41,14,PIX_SET,1);
  177.         pr_vector(weekarrow_pr,41,14,27,28,PIX_SET,1);
  178.         pr_vector(weekarrow_pr,27,28,0,28,PIX_SET,1);
  179.         pr_vector(weekarrow_pr,0,28,0,0,PIX_SET,1);
  180.         pr_vector(weekarrow_pr,2,2,26,2,PIX_SET,1);
  181.         pr_vector(weekarrow_pr,26,2,38,14,PIX_SET,1);
  182.         pr_vector(weekarrow_pr,38,14,26,26,PIX_SET,1);
  183.         pr_vector(weekarrow_pr,26,26,2,26,PIX_SET,1);
  184.         pr_vector(weekarrow_pr,2,26,2,2,PIX_SET,1);
  185.         smallarrow_pr = mem_create(42,29,1);
  186.         pr_rop(smallarrow_pr, 3, 3, 25, 23, PIX_SET, 0, 0, 0);
  187.         for (i=0; i<14; i++) {
  188.                 pr_vector(smallarrow_pr, 27, i+3, 27+i, i+3, PIX_SET,1);
  189.                 pr_vector(smallarrow_pr, 27, 25-i, 27+i, 25-i, PIX_SET,1);
  190.         }
  191. }
  192.  
  193.  
  194. init_arrow_prs()
  195. {
  196.     int lmid, rmid;
  197.  
  198.     arrowshaft_pr = mem_create(dayslot_width-2, dayslot_height-2, 1);
  199.     arrowhead_pr = mem_create(dayslot_width-2, dayslot_height-2, 1);
  200.     weekarrowshaft_pr = mem_create(weekslot_width-2, weekslot_height-2, 1);
  201.     weekarrowhead_pr = mem_create(weekslot_width-2, weekslot_height-2, 1);
  202.  
  203.     lmid = (dayslot_width-2) / 2;
  204.     rmid = lmid + 1;
  205.     pr_vector(arrowshaft_pr, lmid-4, 0, lmid-4, dayslot_height-3, PIX_SET, 1);
  206.     pr_vector(arrowshaft_pr, lmid-3, 0, lmid-3, dayslot_height-3, PIX_SET, 1);
  207.     pr_vector(arrowshaft_pr, rmid+3, 0, rmid+3, dayslot_height-3, PIX_SET, 1);
  208.     pr_vector(arrowshaft_pr, rmid+4, 0, rmid+4, dayslot_height-3, PIX_SET, 1);
  209.  
  210.     pr_vector(arrowhead_pr, lmid, dayslot_height-3, lmid-7, dayslot_height-10,
  211.           PIX_SET, 1);
  212.     pr_vector(arrowhead_pr, lmid, dayslot_height-4, lmid-7, dayslot_height-11, 
  213.                   PIX_SET, 1);
  214.     pr_vector(arrowhead_pr, rmid, dayslot_height-3, rmid+7, dayslot_height-10, 
  215.                   PIX_SET, 1); 
  216.         pr_vector(arrowhead_pr, rmid, dayslot_height-4, rmid+7, dayslot_height-11, 
  217.                   PIX_SET, 1);
  218.     pr_vector(arrowhead_pr, lmid-4, dayslot_height-8, lmid-4, 0, PIX_SET, 1);
  219.     pr_vector(arrowhead_pr, lmid-3, dayslot_height-7, lmid-3, 0, PIX_SET, 1); 
  220.         pr_vector(arrowhead_pr, rmid+3, dayslot_height-7, rmid+3, 0, PIX_SET, 1);
  221.         pr_vector(arrowhead_pr, rmid+4, dayslot_height-8, rmid+4, 0, PIX_SET, 1);
  222.  
  223.     lmid = (weekslot_width-2) / 2;
  224.         rmid = lmid + 1;
  225.  
  226.     pr_vector(weekarrowshaft_pr, lmid-4, 0, lmid-4, weekslot_height-3, PIX_SET, 1);
  227.         pr_vector(weekarrowshaft_pr, lmid-3, 0, lmid-3, weekslot_height-3, PIX_SET, 1);
  228.         pr_vector(weekarrowshaft_pr, rmid+3, 0, rmid+3, weekslot_height-3, PIX_SET, 1);
  229.         pr_vector(weekarrowshaft_pr, rmid+4, 0, rmid+4, weekslot_height-3, PIX_SET, 1);
  230.  
  231.     pr_vector(weekarrowhead_pr, lmid, weekslot_height-3, lmid-7, weekslot_height-10,
  232.                   PIX_SET, 1);
  233.         pr_vector(weekarrowhead_pr, lmid, weekslot_height-4, lmid-7, weekslot_height-11,
  234.                   PIX_SET, 1);
  235.         pr_vector(weekarrowhead_pr, rmid, weekslot_height-3, rmid+7, weekslot_height-10,
  236.                   PIX_SET, 1);
  237.         pr_vector(weekarrowhead_pr, rmid, weekslot_height-4, rmid+7, weekslot_height-11,
  238.                   PIX_SET, 1);
  239.         pr_vector(weekarrowhead_pr, lmid-4, weekslot_height-8, lmid-4, 0, PIX_SET, 1);
  240.         pr_vector(weekarrowhead_pr, lmid-3, weekslot_height-7, lmid-3, 0, PIX_SET, 1);
  241.         pr_vector(weekarrowhead_pr, rmid+3, weekslot_height-7, rmid+3, 0, PIX_SET, 1);
  242.         pr_vector(weekarrowhead_pr, rmid+4, weekslot_height-8, rmid+4, 0, PIX_SET, 1);
  243.  
  244.     leftarrow = mem_create(19, 14, 1);
  245.     rightarrow = mem_create(19, 14, 1);
  246.     pr_vector(leftarrow, 3, 5, 16, 5, PIX_SET, 1);
  247.     pr_vector(leftarrow, 2, 6, 16, 6, PIX_SET, 1);
  248.     pr_vector(leftarrow, 3, 7, 16, 7, PIX_SET, 1);
  249.     pr_vector(leftarrow, 4, 4, 4, 8, PIX_SET, 1);
  250.     pr_vector(leftarrow, 5, 3, 5, 9, PIX_SET, 1);
  251.     pr_vector(leftarrow, 6, 2, 6, 10, PIX_SET, 1);
  252.     pr_vector(leftarrow, 0, 0, 18, 0, PIX_SET, 1);
  253.     pr_vector(leftarrow, 18, 0, 18, 13, PIX_SET, 1);
  254.     pr_vector(leftarrow, 18, 13, 0, 13, PIX_SET, 1);
  255.     pr_vector(leftarrow, 0, 13, 0, 0, PIX_SET, 1);
  256.  
  257.     pr_vector(rightarrow, 2, 5, 15, 5, PIX_SET, 1);
  258.     pr_vector(rightarrow, 2, 6, 16, 6, PIX_SET, 1);
  259.     pr_vector(rightarrow, 2, 7, 15, 7, PIX_SET, 1);
  260.     pr_vector(rightarrow, 14, 4, 14, 8, PIX_SET, 1);
  261.     pr_vector(rightarrow, 13, 3, 13, 9, PIX_SET, 1);
  262.     pr_vector(rightarrow, 12, 2, 12, 10, PIX_SET, 1);
  263.     pr_vector(rightarrow, 0, 0, 18, 0, PIX_SET, 1);
  264.     pr_vector(rightarrow, 18, 0, 18, 13, PIX_SET, 1);
  265.     pr_vector(rightarrow, 18, 13, 0, 13, PIX_SET, 1);
  266.     pr_vector(rightarrow, 0, 13, 0, 0, PIX_SET, 1);
  267. }
  268.  
  269.  
  270. init_triangle_pr()
  271. {
  272.     int i;
  273.  
  274.     triangle_pr = mem_create(32, 32, 1);
  275.     for (i=0; i<32; i++)
  276.         pr_vector(triangle_pr, i, i, 31, i, PIX_SET, 1);
  277. }
  278.  
  279. /* squares for drawing days of month on the year calendar */
  280. init_ydaybox_pr()
  281. {
  282.     Pixrect *pattern;
  283.     int i;
  284.  
  285.     ydaybox_pr = mem_create(ybox_width,ybox_height,1);
  286.         pr_vector(ydaybox_pr,0,0,ybox_width-1,0,PIX_SET,1);
  287.         pr_vector(ydaybox_pr,ybox_width-1,0,ybox_width-1,ybox_height-1,PIX_SET,1);
  288.         pr_vector(ydaybox_pr,ybox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1);
  289.         pr_vector(ydaybox_pr,0,ybox_height-1,0,0,PIX_SET,1);
  290.     pattern = mem_create(ybox_width,2,1);
  291.     for (i=1; i<ybox_width; i+=4)
  292.         pr_put(pattern, i, 0, 1);
  293.     for (i=3; i<ybox_width; i+=4)
  294.         pr_put(pattern, i, 1, 1);
  295.     ydaybox_td_pr = mem_create(ybox_width,ybox_height,1);
  296.         pr_vector(ydaybox_td_pr,0,0,ybox_width-1,0,PIX_SET,1);
  297.         pr_vector(ydaybox_td_pr,ybox_width-1,0,ybox_width-1,ybox_height-1,PIX_SET,1);
  298.         pr_vector(ydaybox_td_pr,ybox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1);
  299.         pr_vector(ydaybox_td_pr,0,ybox_height-1,0,0,PIX_SET,1);
  300.     pr_replrop(ydaybox_td_pr, 1, 1, ybox_width-3, ybox_height-2, PIX_SRC|PIX_DST, pattern, 0, 0);
  301.     pr_destroy(pattern);
  302. }
  303.  
  304. /* label box for each month on the year calendar */
  305. init_ymonthbox_pr()
  306. {
  307.     int ymbox_width;
  308.  
  309.     ymbox_width = 7 * ybox_width;
  310.     ymonthbox_pr = mem_create(ymbox_width,ybox_height,1);
  311.         pr_vector(ymonthbox_pr,0,0,ymbox_width-1,0,PIX_SET,1);
  312.         pr_vector(ymonthbox_pr,ymbox_width-1,0,ymbox_width-1,ybox_height-1,PIX_SET,1);
  313.         pr_vector(ymonthbox_pr,ymbox_width-1,ybox_height-1,0,ybox_height-1,PIX_SET,1);
  314.         pr_vector(ymonthbox_pr,0,ybox_height-1,0,0,PIX_SET,1);
  315.         pr_vector(ymonthbox_pr,0,1,ymbox_width-1,1,PIX_SET,1);
  316. }
  317.  
  318. do_files(window_prompt)
  319. int window_prompt;
  320. {
  321.     char *strcpy(), *rindex(), *getenv();
  322.     char *slash, *default_ptr, *envptr;
  323.     char buff[80];
  324.     int to_slash, getpid(), fd, errflag;
  325.     struct passwd *pw;
  326.     FILE *appts;
  327.  
  328.     /* the tmp file */
  329.     sprintf(tmpapts_pathname, "/tmp/appts%d", getpid());
  330.     if (otherfile) {
  331.         strcpy(apts_pathname, othername);
  332.         if ((slash = rindex(apts_pathname, '/')) != NULL) {
  333.             to_slash = slash - apts_pathname;
  334.             strncpy(apts_dir, apts_pathname, to_slash);
  335.             apts_dir[to_slash] = '\0';
  336.         } else {
  337.             strcpy(apts_dir, ".");
  338.         }
  339.     } else {
  340.         if ((default_ptr = defaults_get_string("/CalenTool/Appts", NULL, 0)) != NULL) {
  341.             if ((slash = rindex(default_ptr, '/')) != NULL) {
  342.                 to_slash = slash - default_ptr;
  343.                 strncpy(apts_dir, default_ptr, to_slash);
  344.                 apts_dir[to_slash] = '\0';
  345.             } else {
  346.                 strcpy(apts_dir, ".");
  347.             }
  348.         } else if ((envptr = getenv("CALENTOOL_DIR")) != NULL) {   
  349.             strcpy(apts_dir, envptr);
  350.         } else if (mailto) {
  351.             if ((pw = getpwnam(mailto)) == NULL)
  352.                 /* no entry */
  353.                 exit(1);
  354.             envptr = pw->pw_dir; /* home directory */
  355.             strcpy(apts_dir, envptr);
  356.         } else if ((envptr = getenv("HOME")) != NULL) {   
  357.             strcpy(apts_dir, envptr);
  358.         } else {   
  359.             apts_dir[0] = '\0';
  360.         }
  361.         if (*apts_dir) {
  362.             /* prepend directory on pathnames */
  363.             sprintf(apts_pathname, "%s/.appointments", apts_dir);
  364.         } else {
  365.             /* use current directory */
  366.             strcpy(apts_pathname, ".appointments");
  367.         }
  368.     }
  369.     
  370.     /* directory for date/event data files */
  371.     if ((default_ptr = defaults_get_string("/CalenTool/LibDir", NULL, 0)) != NULL)
  372.         strcpy(lib_dir, default_ptr);
  373.     else
  374.         strcpy(lib_dir, DATELIB_DIR);
  375.  
  376.     errflag = 0;
  377.     if (access(apts_pathname, R_OK) == -1) {
  378.         if (window_prompt) {
  379.             fprintf(stderr, "nonexistant file\n");
  380.             sprintf(buff, "Cannot access calendar file %s - create?", apts_pathname);
  381.             create_prompt_frame(buff, TRUE);
  382.             if ((int)window_loop(prompt_frame) == 0) {
  383.                 /* try to create the file */
  384.                 fprintf(stderr, "creating file\n");
  385.                 if ((fd=open(apts_pathname, O_CREAT|O_RDWR, 0664)) <= 0) {
  386.                     perror(apts_pathname);
  387.                     errflag = 1;
  388.                     fprintf(stderr, "..error\n");
  389.                 } else {
  390.                     if (write(fd, HEADER, sizeof(HEADER)) != sizeof(HEADER)) {
  391.                         perror("writing header");
  392.                         errflag = 1;
  393.                     }
  394.                     close(fd);
  395.                     fprintf(stderr, "..wrote header\n");
  396.                     one_based = 1;
  397.                 }
  398.             } else {
  399.                 fprintf(stderr, "window_ret != 0\n");
  400.                 errflag = 1;
  401.             }
  402.             window_set(prompt_frame, WIN_SHOW, FALSE, 0);
  403.             if (errflag)
  404.                 return(1);
  405.         } else {
  406.             fprintf(stderr, "Cannot access calendar file %s - create? ", apts_pathname);
  407.             fgets(buff, 80, stdin);
  408.             if (buff[0] == 'y' || buff[0] == 'Y') {
  409.                 if ((fd=open(apts_pathname, O_CREAT|O_RDWR, 0664)) <= 0) {
  410.                     perror(apts_pathname);
  411.                     return(1);
  412.                 } else {
  413.                     if (write(fd, HEADER, sizeof(HEADER)) != sizeof(HEADER)) {
  414.                         perror("writing header");
  415.                         close(fd);
  416.                         return(1);
  417.                     }
  418.                     close(fd);
  419.                     one_based = 1;
  420.                 }
  421.             } else
  422.                 return(1);
  423.         }
  424.     }
  425.     if (access(apts_pathname, W_OK) == -1)
  426.         read_only = 1;
  427.  
  428.     /* update base frame label, if the tool is running */
  429.     if (frame) {
  430.         strcpy(t_title, version);
  431.         if (read_only)
  432.             strcat(t_title, " [Read Only]");
  433.         strcat(t_title, "  -  ");
  434.         strcat(t_title, apts_pathname);
  435.         window_set(frame, FRAME_LABEL, t_title, 0);
  436.     }
  437.  
  438.     /* check first line of appts file to see if it is the new style */
  439.     if ((appts = fopen(apts_pathname, "r")) != NULL) {
  440.         fgets(buff, 80, appts);
  441.         if (!strcmp(buff, HEADER)) {
  442.             version2 = 1;
  443.             one_based = 1;
  444.         }
  445.         fclose(appts);
  446.     }
  447.  
  448.     /* Convert from old format to new. There may some appts files
  449.      * that are one-based, but are still old style. These are
  450.      * also handled. (Note: for old-style one-based appts files
  451.      * the user MUST start calentool with the -z flag.)
  452.      */
  453.      if (!version2)
  454.         ver1to2();
  455.     
  456.     return(0);
  457. }
  458.  
  459. /*
  460.  * get/set printer variable to correspond to the command to print
  461.  * a raster or Postscript file
  462.  */
  463. get_printer()
  464. {
  465. #ifndef NO_PRINTER
  466.     char *ptr, *getenv();
  467.  
  468.     strcpy(printer, "lpr -P");
  469.     if ((ptr = defaults_get_string("/CalenTool/Printer", NULL, 0)) != NULL)
  470.         strcat(printer, ptr);
  471.     else if ((ptr = getenv("PRINTER")) != NULL)
  472.         strcat(printer, ptr);
  473.     else
  474.         strcpy(printer, PRINT_CMD);
  475. #endif
  476. }
  477.