home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: month2ct.c,v 2.1 89/05/09 14:19:14 billr Exp $
- */
- /*
- * month2ct - convert month schedule files to calentool style files
- *
- * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Copyright (C) 1989 Tektronix, Inc. All Rights Reserved
- *
- * Permission is hereby granted to use and modify this code in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- */
-
- #include "month.h"
- #include "ct.h"
- #include <stdio.h>
-
- struct appt_entry appt;
- struct event_rec events;
- FILE *fp;
- char filename[128];
- char *dir, *getenv();
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- if (argc > 1)
- dir = argv[1];
- else {
- strcpy(filename, getenv("HOME"));
- dir = filename;
- }
-
- if (read_schedule(dir, READ_ONLY)) {
- fprintf(stderr, "no reminders read from %s/.month\n", dir);
- exit(1);
- }
- strcpy(filename, getenv("HOME"));
- strcat(filename, "/.appointments");
- if ((fp = fopen(filename, "w")) == NULL) {
- fprintf(stderr, "can't open .appointments file for writing\n");
- exit(1);
- }
- write_ct_file();
- }
-
- /*
- * write out the new .appointments file
- */
- write_ct_file()
- {
- struct event_rec *evt;
- int length, oflags, i;
-
- evt = &events;
- fputs(HEADER, fp);
- /* first event is empty */
- evt = evt->next_event;
- while (evt) {
- fprintf(stderr,"evt struct:\n mly=%d, yly=%d, evry=%d\n nth=%d, last=%d, nthon=%d\n str=%s\n",
- evt->monthly, evt->yearly, evt->every, evt->nth, evt->last, evt->nth_is_on, evt->event_string);
- appt.flags = appt.repeat = appt.lookahead = 0;
- appt.year = evt->start_date.year - 1900;
- appt.month = evt->start_date.month - 1;
- appt.day = evt->start_date.day;
- strcpy(appt.str, evt->event_string);
- if (evt->monthly)
- appt.flags |= ALL_MONTHS;
- if (evt->yearly)
- appt.flags |= ALL_YEARS;
- appt.hour = evt->start_time.hour;
- appt.minute = evt->start_time.minute;
- if (appt.hour > 23 || appt.hour < 0 || appt.minute > 59 || appt.minute < 0)
- appt.flags |= A_NOTE;
- if (appt.minute < 15)
- appt.minute = 0;
- else if (appt.minute < 45)
- appt.minute = 30;
- else {
- appt.minute = 0;
- appt.hour++;
- }
- length = evt->duration.hour * 60 + evt->duration.minute;
- appt.arrows = length / 30 - 1;
- if (appt.arrows < 0)
- appt.arrows = 0;
- if (evt->anti)
- appt.flags |= DELETED;
- if (evt->warning.hour >= 24)
- appt.lookahead = evt->warning.hour / 24;
- if (evt->every) {
- /* event occurs on an every something */
- appt.flags |= REPEAT;
- if (evt->last)
- appt.repeat = LAST_WEEK;
- else if (evt->nth_is_on)
- appt.repeat = 1<<(evt->nth_is_on-1);
- else
- appt.repeat = ALL_WEEKS;
- oflags = appt.flags;
- for (i=0; i<7; i++) {
- if (evt->smtwtfs[i]) {
- appt.flags = oflags | Setday(i);
- if (put_aentry(fp, &appt)) {
- fprintf(stderr, "error writing .appointments file\n");
- return;
- }
- }
- }
- } else
- if (put_aentry(fp, &appt)) {
- fprintf(stderr, "error writing .appointments file\n");
- return;
- }
- fputs("\n", fp);
- evt = evt->next_event;
- }
- }
-