2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $TOG: cm_insert.c /main/8 1998/04/20 13:08:52 mgreess $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)cm_insert.c 1.31 95/05/19 Copyr 1993 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
61 #include <sys/resource.h>
75 #include <Dt/EnvControlP.h>
77 #if !defined(NL_CAT_LOCALE)
78 #define NL_CAT_LOCALE 0
82 static nl_catd DT_catd;
83 static char cm_target[256] = ""; /* target for table (user@host) */
84 static int cm_today = 0; /* today's date (in epoch time) */
85 static char cm_date[256] = ""; /* appointment date */
86 static char cm_view[16] = "day"; /* view span (day,week,month) */
87 static char cm_start[16] = ""; /* start time for appointment list*/
88 static char cm_end[16] = ""; /* end time for appointment list */
89 static char cm_repeatstr[256] = "One Time";/* repeat period */
90 static char cm_for[256] = ""; /* number of repeats */
91 static char cm_what[1024] = "Appointment";
92 /* what appointment is about */
93 static char cm_appt_file[1024] = "";
94 /* file to find an appointment template in */
95 static int cm_repeat = 0; /* how often to repeat this */
96 static int cm_flash = 0; /* flash reminder */
97 static int cm_beep = 0; /* beep reminder */
98 static int cm_open = 0; /* open reminder */
99 static int cm_mail = 0; /* mail reminder */
101 static void cm_args(); /* parse command line */
104 grab(char **argv, /* command line arguments */
105 char *buf, /* buffer for keyed data */
108 if (!argv || !*argv) return(argv);
109 cm_strcpy (buf,*argv++);
110 while(argv && *argv) {
111 if (*(*argv) == stop_key) break;
113 cm_strcat(buf,*argv++);
120 cm_args(int argc, char **argv)
123 while (++argv && *argv) {
127 argv = grab(++argv,cm_target,'-');
130 argv = grab(++argv,cm_date,'-');
133 argv = grab(++argv,cm_view,'-');
136 argv = grab(++argv,cm_start,'-');
139 argv = grab(++argv,cm_end,'-');
142 argv = grab(++argv,cm_what,'-');
145 argv = grab(++argv,cm_appt_file,'-');
148 fprintf(stderr, "%s", catgets(DT_catd, 1, 191, "Usage:\n\tdtcm_insert [ -c calendar ] [-d <mm/dd/yy>] [ -v view ]\n"));
149 fprintf(stderr, "%s", catgets(DT_catd, 1, 192, " [-w what string] [-s <HH:MMam/pm>] [-e <HH:MMam/pm>]\n"));
156 prompt_for_line(char *prompt, char *defval, char *buffer)
158 char input_buf[1024];
160 printf(prompt, defval);
163 fgets (input_buf, sizeof(input_buf), stdin);
164 if (strlen(input_buf) && input_buf[strlen(input_buf)-1] == '\n')
165 input_buf[strlen(input_buf)-1] = '\0';
167 if (input_buf[0] && (input_buf[0] != '\n'))
168 cm_strcpy(buffer, input_buf);
170 cm_strcpy(buffer, defval);
174 prompt_for_insert(Props *p) {
175 char date_str[BUFSIZ], what_buffer[BUFSIZ], buf[BUFSIZ], *timecopy;
176 int index, next, valid = FALSE;
177 DisplayType dt = get_int_prop(p, CP_DEFAULTDISP);
179 format_tick(now(), get_int_prop(p, CP_DATEORDERING),
180 get_int_prop(p, CP_DATESEPARATOR), date_str);
182 printf("%s", catgets(DT_catd, 1, 193, "Please enter the information for the appointment you wish to add.\nDefaults will be shown in parentheses.\n"));
183 prompt_for_line(catgets(DT_catd, 1, 194,
184 "Calendar (%s): "), cm_get_credentials(), cm_target);
185 prompt_for_line(catgets(DT_catd, 1, 195,
186 "Date (%s): "), date_str, cm_date);
187 while (valid != TRUE)
189 format_time(now(), dt, cm_start);
190 prompt_for_line(catgets(DT_catd, 1, 196,
191 "Start (%s): "), cm_start, cm_start);
194 timecopy = (char *)cm_strdup(cm_start);
195 if (valid_time(p, timecopy))
198 printf("%s", catgets(DT_catd, 1, 197, "You have entered an invalid time. Please try again:\n"));
203 sprintf(buf, "%s %s", date_str, cm_start);
204 next = (int) cm_getdate(buf, NULL);
207 format_time(next, dt, cm_end);
210 catgets(DT_catd, 1, 198, "End (%s): "), cm_end, cm_end);
213 catgets(DT_catd, 1, 199, "End (%s): "), "None", cm_end);
215 snprintf(cm_repeatstr, sizeof(cm_repeatstr), "%s", catgets(DT_catd, 1, 200, "One Time"));
217 prompt_for_line(catgets(DT_catd, 1, 201,
218 "Repeat (%s): "), cm_repeatstr, cm_repeatstr);
220 if (strcmp(cm_repeatstr, catgets(DT_catd, 1, 200, "One Time"))) {
221 sprintf(buf, "%s", catgets(DT_catd, 1, 203, "no default"));
223 catgets(DT_catd, 1, 204, "For (%s): "), buf, cm_for);
226 printf("%s", catgets(DT_catd, 1, 205,
227 "What (you may enter up to 5 lines, use ^D to finish):\n"));
229 for (index = 0; index < 5; index++)
232 fgets (what_buffer, sizeof(what_buffer), stdin);
233 if (strlen(what_buffer) &&
234 what_buffer[strlen(what_buffer)-1] == '\n')
235 what_buffer[strlen(what_buffer)-1] = '\0';
237 if (what_buffer[0] == '\000')
241 strcat(cm_what, what_buffer);
242 strcat(cm_what, "\\n");
244 memset(what_buffer, '\000', 256);
250 main(int argc, char **argv)
253 char *date = NULL, *view = NULL, *target = NULL,
254 *start = NULL, *end = NULL, *repeat = NULL,
255 *numrepeat = NULL, *what = NULL, *uname, *loc;
257 CSA_entry_handle *list;
258 CSA_session_handle c_handle;
259 CSA_return_code stat;
260 CSA_calendar_user csa_user;
269 _DtEnvControl(DT_ENV_SET); /* set up environment variables */
270 setlocale(LC_ALL, "");
271 DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
272 cm_tty_load_props(&p);
273 dt = get_int_prop(p, CP_DEFAULTDISP);
280 cm_args(argc,argv); /* parse command line */
281 if (cm_strlen(cm_target))
284 target = cm_get_credentials();
286 if (cmfns_use_fns(p)) {
287 cmfns_lookup_calendar(target, buf, sizeof(buf));
291 uname = cm_target2name(target);
292 loc = cm_target2location(target);
294 csa_user.user_name = target;
295 csa_user.user_type = 0;
296 csa_user.calendar_user_extensions = NULL;
297 csa_user.calendar_address = target;
298 stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
299 if (stat != CSA_SUCCESS) {
300 char *format = cm_strdup(catgets(DT_catd, 1, 206,
301 "\nCould not open calendar %s\n"));
302 fprintf(stderr, format,
304 catgets(DT_catd, 1, 209, "UNKNOWN"));
310 version = get_data_version(c_handle);
312 format_tick(now(), get_int_prop(p, CP_DATEORDERING),
313 get_int_prop(p, CP_DATESEPARATOR), cm_date);
314 if (cm_strlen(cm_date)) date = cm_date;
315 if (cm_strlen(cm_view)) view = cm_view;
316 if (cm_strlen(cm_start)) start = cm_start;
318 if (!cm_end[0] && cm_start[0]) {
319 format_time((int)cm_getdate(cm_start, NULL) + hrsec,
323 if (cm_strlen(cm_end)) end = cm_end;
324 if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
325 if (cm_strlen(cm_for)) numrepeat = cm_for;
326 if (cm_strlen(cm_what)) what = cm_what;
327 if (!cm_appt_file[0])
328 status = cm_tty_insert(DT_catd, c_handle, version,
329 date, start, end, repeat, numrepeat,
332 status = cm_tty_insert(DT_catd, c_handle, version, date,
333 start, end, repeat, numrepeat,
334 what, cm_appt_file, p);
336 prompt_for_insert(p);
337 if (cm_strlen(cm_target)) target = cm_target;
338 uname = cm_target2name(target);
339 loc = cm_target2location(target);
341 csa_user.user_name = target;
342 csa_user.user_type = 0;
343 csa_user.calendar_user_extensions = NULL;
344 csa_user.calendar_address = target;
345 stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
346 if (stat !=CSA_SUCCESS) {
347 char *format = cm_strdup(catgets(DT_catd, 1, 206,
348 "\nCould not open calendar %s\n"));
349 fprintf(stderr, format,
351 catgets(DT_catd, 1, 209, "UNKNOWN"));
357 version = get_data_version(c_handle);
358 if (cm_strlen(cm_date)) date = cm_date;
359 if (cm_strlen(cm_view)) view = cm_view;
360 if (cm_strlen(cm_start)) start = cm_start;
361 if (cm_strlen(cm_end)) end = cm_end;
362 if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
363 if (cm_strlen(cm_for)) numrepeat = cm_for;
364 if (cm_strlen(cm_what)) what = cm_what;
365 status = cm_tty_insert(DT_catd, c_handle, version, date,
366 start, end, repeat, numrepeat, what, NULL, p);
368 if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view,
371 csa_logoff(c_handle, NULL);