Example #1
0
/*
 *  Returns a null terminated formatted string.
 *  If error is encountered, such as malloc() failed, then return NULL.
 *  The caller of this function should beware that the return value is
 *  a static buffer declared within this function and the value of it may
 *  change.
 */
char *
cm_printf(double value, int decimal_pt)
{
	int sign = 0;
	int deci_pt = 0;
	int buf_cnt = 0;
	int formatted_cnt = 0;
	int buf_len = 0;
	char *buf = NULL;
	static char *formatted = NULL;

	if ( formatted != NULL ) {
		free(formatted);
		formatted = NULL;
	}
	if ( (value == (double)0) && (decimal_pt == 0) ) {
		formatted = (char *)cm_strdup("0");
		return formatted;
	}
	if ( (buf = (char *)malloc(DBL_SIZE + decimal_pt)) == NULL ) {
		return (char *)NULL;
	}
	if ( (formatted = (char *)calloc(1, DBL_SIZE + decimal_pt)) == NULL ) {
		free(buf);
		return (char *)NULL;
	}
#ifdef SunOS
	fconvert(value, decimal_pt, &deci_pt, &sign, buf);
#elif defined(CSRG_BASED)
	snprintf(buf, decimal_pt, "%f", value);
#else
	/* this version, available on the HP and AIX machine is not reentrant. */

	strcpy(buf, fcvt(value, decimal_pt, &deci_pt, &sign));
#endif
	if ( sign ) {
		strcpy(formatted, "-");
	}
	buf_len = deci_pt + decimal_pt;
	if ( deci_pt ) {
		strncat(formatted, buf, deci_pt);
	} else {    /* zero */
		strcat(formatted, "0");	
	}
	if ( deci_pt == buf_len ) {
		strcat(formatted, "\0");
		free(buf);
		return formatted;
	}
	strcat(formatted, ".");
	for ( formatted_cnt = strlen(formatted), buf_cnt = deci_pt;  buf_cnt < buf_len;  buf_cnt++, formatted_cnt++ ) {
		formatted[formatted_cnt] = buf[buf_cnt];
	}
	formatted[formatted_cnt] = '\0';
	free(buf);
	return formatted;	
}
Example #2
0
extern void
blist_init_names(Calendar *c) {
        char		*name, *namelist;
        Props		*p = (Props*)c->properties;
	Browselist	*bl = (Browselist *)c->browselist;
 
	if (!bl->blist_data)
		bl->blist_data = CmDataListCreate();

	/*
	 * Make sure the default calendar is in list
	 */
	name = get_user_calendar();
	blist_name_append(c, name, BLIST_ACTIVE);
	free(name);

	/*
	 * Make sure user's calendar is in list
	 */
	blist_name_append(c, c->calname, BLIST_ACTIVE);

	/* make sure the intiial view name is in the list. */

	blist_name_append(c, get_char_prop(p, CP_DEFAULTCAL), BLIST_ACTIVE);

        namelist = cm_strdup(get_char_prop(p, CP_DAYCALLIST));
        if (namelist == NULL || *namelist == NULL )
		return;

	name = strtok(namelist, " ");
	while (name) {
		blist_name_append(c, name, BLIST_ACTIVE);
		name = strtok(NULL, " ");
	}
	free(namelist);
}
Example #3
0
void
main(int argc, char **argv)
{
	int		cnt, status = 0;
	char		*date = NULL, *view = NULL, *target = NULL,
			*start = NULL, *end = NULL, *repeat = NULL,
			*numrepeat = NULL, *what = NULL, *uname, *loc;
	Props		*p = NULL;
	CSA_entry_handle	*list;
	CSA_session_handle	c_handle;
	CSA_return_code		stat;
	CSA_calendar_user	csa_user;
	DisplayType		dt;
	int			version;
	char			date_str[256];
#ifdef FNS
	char		buf[256];
#endif

	init_time();
        _DtEnvControl(DT_ENV_SET); /* set up environment variables */
	setlocale(LC_ALL, "");
	DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
	cm_tty_load_props(&p);
	dt = get_int_prop(p, CP_DEFAULTDISP);
#ifdef FNS
	dtfns_init();
#endif

	if (argc > 1)
	{
		cm_args(argc,argv);		/* parse command line */
		if (cm_strlen(cm_target)) 
			target = cm_target;
		else
			target = cm_get_credentials();
#ifdef FNS
		if (cmfns_use_fns(p)) {
			cmfns_lookup_calendar(target, buf, sizeof(buf));
			target = buf;
		}
#endif
		uname = cm_target2name(target);
		loc = cm_target2location(target);

		csa_user.user_name = target;
		csa_user.user_type = 0;
		csa_user.calendar_user_extensions = NULL;
		csa_user.calendar_address = target;
		stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
		if (stat != CSA_SUCCESS) {
		  	char *format = cm_strdup(catgets(DT_catd, 1, 206, 
					   "\nCould not open calendar %s\n"));
			fprintf(stderr, format,
				target ? target : 
				catgets(DT_catd, 1, 209, "UNKNOWN"));
			free(format);
			free(uname);
			free(loc);
			exit(1);
		}
		version = get_data_version(c_handle);
		if (!cm_date[0])
        		format_tick(now(), get_int_prop(p, CP_DATEORDERING),
		    		    get_int_prop(p, CP_DATESEPARATOR), cm_date);
		if (cm_strlen(cm_date)) date = cm_date;
		if (cm_strlen(cm_view)) view = cm_view;
		if (cm_strlen(cm_start)) start = cm_start;

		if (!cm_end[0] && cm_start[0]) {
			format_time((int)cm_getdate(cm_start, NULL) + hrsec,
				    dt, cm_end);
		}

		if (cm_strlen(cm_end)) end = cm_end;
		if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
		if (cm_strlen(cm_for)) numrepeat = cm_for;
		if (cm_strlen(cm_what)) what = cm_what;
		if (!cm_appt_file[0])
			status = cm_tty_insert(DT_catd, c_handle, version, 
				      date, start, end, repeat, numrepeat,
				      what, NULL, p);
		else
			status = cm_tty_insert(DT_catd, c_handle, version, date,
				      start, end, repeat, numrepeat,
				      what, cm_appt_file, p);
	} else {
		prompt_for_insert(p);
		if (cm_strlen(cm_target)) target = cm_target;
		uname = cm_target2name(target);
		loc = cm_target2location(target);

		csa_user.user_name = target;
		csa_user.user_type = 0;
		csa_user.calendar_user_extensions = NULL;
		csa_user.calendar_address = target;
		stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
		if (stat !=CSA_SUCCESS) {
		  	char *format = cm_strdup(catgets(DT_catd, 1, 206, 
					   "\nCould not open calendar %s\n"));
			fprintf(stderr, format, 
				target ? target : 
				catgets(DT_catd, 1, 209, "UNKNOWN"));
			free(format);
			free(uname);
			free(loc);
			exit(1);
		}
		version = get_data_version(c_handle);
		if (cm_strlen(cm_date)) date = cm_date;
		if (cm_strlen(cm_view)) view = cm_view;
		if (cm_strlen(cm_start)) start = cm_start;
		if (cm_strlen(cm_end)) end = cm_end;
		if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
		if (cm_strlen(cm_for)) numrepeat = cm_for;
		if (cm_strlen(cm_what)) what = cm_what;
		status = cm_tty_insert(DT_catd, c_handle, version, date, 
			      start, end, repeat, numrepeat, what, NULL, p);
	}
	if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, 
					&list, p)) > 0)
		csa_free(list);
	csa_logoff(c_handle, NULL);
	props_clean_up(p);
	free(p);
	free(uname);
	free(loc);
        exit(status);
}
Example #4
0
static void
prompt_for_insert(Props *p) {
	char		date_str[BUFSIZ], what_buffer[BUFSIZ], buf[BUFSIZ], *timecopy;
	int		index, next, valid = FALSE;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);

        format_tick(now(), get_int_prop(p, CP_DATEORDERING),
		    get_int_prop(p, CP_DATESEPARATOR), date_str);

	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"));
	prompt_for_line(catgets(DT_catd, 1, 194, 
		"Calendar (%s): "), cm_get_credentials(), cm_target);
	prompt_for_line(catgets(DT_catd, 1, 195, 
		"Date (%s): "), date_str, cm_date);
	while (valid != TRUE)
	{
		format_time(now(), dt, cm_start);
		prompt_for_line(catgets(DT_catd, 1, 196, 
			"Start (%s): "), cm_start, cm_start);
		if (cm_start && cm_start[0])
		{
			timecopy = (char *)cm_strdup(cm_start);
			if (valid_time(p, timecopy))
				valid = TRUE;
			else
				printf("%s", catgets(DT_catd, 1, 197, "You have entered an invalid time.  Please try again:\n"));
			free(timecopy);
		}
	}

	sprintf(buf, "%s %s", date_str, cm_start);
	next = (int) cm_getdate(buf, NULL);
        next = next + hrsec;

	format_time(next, dt, cm_end);
	if (cm_start && cm_start[0])
		prompt_for_line(
			catgets(DT_catd, 1, 198, "End (%s): "), cm_end, cm_end);
	else
		prompt_for_line(
			catgets(DT_catd, 1, 199, "End (%s): "), "None", cm_end);

	strcpy(cm_repeatstr, catgets(DT_catd, 1, 200, "One Time"));

	prompt_for_line(catgets(DT_catd, 1, 201, 
			"Repeat (%s): "), cm_repeatstr, cm_repeatstr);

	if (strcmp(cm_repeatstr, catgets(DT_catd, 1, 200, "One Time"))) {
		sprintf(buf, "%s", catgets(DT_catd, 1, 203, "no default"));
		prompt_for_line(
			catgets(DT_catd, 1, 204, "For (%s): "), buf, cm_for);
	}

	printf("%s", catgets(DT_catd, 1, 205, 
		"What (you may enter up to 5 lines, use ^D to finish):\n"));
	cm_what[0] = NULL;
	for (index = 0; index < 5; index++)
	{
        	*what_buffer = '\0';
        	fgets (what_buffer, sizeof(what_buffer), stdin);
        	if (strlen(what_buffer) &&
		    what_buffer[strlen(what_buffer)-1] == '\n')
          	  what_buffer[strlen(what_buffer)-1] = '\0';

		if (what_buffer[0] == '\000')
			break;
		else
		{
			strcat(cm_what, what_buffer);
			strcat(cm_what, "\\n");
		}
		memset(what_buffer, '\000', 256);
	}
	
}
Example #5
0
/*
**  This function will consume form values and stuff them into an appointment.
*/
extern Boolean
dssw_form_to_todo(DSSW *dssw, Dtcm_appointment *a, char *name, Tick t)
{
	time_t		start_tick, stop_tick;
	char		ampm_buf[BUFSIZ], buf[BUFSIZ];
	Props		*p = (Props *)dssw->cal->properties;
	Props_pu	*pu = (Props_pu *)dssw->cal->properties_pu;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);

	get_dssw_vals(dssw, t);
	/*
	 * Todo does not have end time.  So to distinguish between this
	 * and the editor, zero this out.
	 */
	sprintf(dssw->stop_val.val, "\0");
	if (blank_buf(dssw->date_val)) {
		editor_err_msg(dssw->parent, name, MISSING_DATE,
			       pu->xm_error_pixmap);
		return False;
	}

	if (!blank_buf(dssw->start_val.val)) {
		if (!valid_time(p, dssw->start_val.val)) {
			editor_err_msg(dssw->parent, name, INVALID_TIME,
				pu->xm_error_pixmap);
			return False;
		}

		if (dt == HOUR12) {
			if (dssw->start_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s",
			dssw->date_val, dssw->start_val.val, ampm_buf); 

		/* 
		 * No check here for stop time.
		 */
	} else {
		editor_err_msg(dssw->parent, name, MISSING_TIME,
			pu->xm_error_pixmap);
		return False;
	}

	start_tick = cm_getdate(buf, NULL);
	if(start_tick < 0) {
		editor_err_msg(dssw->parent, name, INVALID_DATE,
			pu->xm_error_pixmap);
		return False;
	}

	a->time->value->item.date_time_value = (char *) malloc(BUFSIZ);
	_csa_tick_to_iso8601(start_tick, a->time->value->item.date_time_value);
	a->what->value->item.string_value = (char *)cm_strdup(dssw->what_val);
	a->show_time->value->item.sint32_value = True;

	free(a->end_time->value);
	a->end_time->value = NULL;

	return True;
}
Example #6
0
extern Boolean
dssw_form_flags_to_appt(DSSW *dssw, Dtcm_appointment *a, char *name, Tick t, int *flagsP)
{
	time_t		start_tick, stop_tick;
	char		ampm_buf[BUFSIZ], buf[BUFSIZ];
	Props		*p = (Props *)dssw->cal->properties;
	Props_pu	*pu = (Props_pu *)dssw->cal->properties_pu;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);
	int		flags = 0;

	if (flagsP == (int *)NULL)
	  flagsP = &flags;

	/*
	**  If neither start nor end times exist, then the start time is set
	**  to 3:41am (magic time) and the end time to 3:41 plus one minute.
	*/
	get_dssw_vals(dssw, t);
	if (blank_buf(dssw->date_val)) {
		editor_err_msg(dssw->parent, name, MISSING_DATE,
			       pu->xm_error_pixmap);
		return False;
	}

	if (!blank_buf(dssw->start_val.val)) {
		if (!valid_time(p, dssw->start_val.val)) {
			if (a->type->value->item.sint32_value == CSA_TYPE_TODO)
				editor_err_msg(dssw->parent, name, 
					       INVALID_TIME_DUE,
					       pu->xm_error_pixmap);
			else
				editor_err_msg(dssw->parent, name, 
					       INVALID_START,
					       pu->xm_error_pixmap);
			return False;
		}

		if (dt == HOUR12) {
			/* am and pm should not be translated.  They are only
			 * used in the date parsing code and never shown to
			 * the user.
			 */
			if (dssw->start_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s",
			dssw->date_val, dssw->start_val.val, ampm_buf); 

		if (!blank_buf(dssw->stop_val.val)
			&& !valid_time(p, dssw->stop_val.val)) {
			editor_err_msg(dssw->parent, name, INVALID_STOP,
				pu->xm_error_pixmap);
               		return False;
		}
	} else if (!blank_buf(dssw->stop_val.val)) {
		editor_err_msg(dssw->parent, name, MISSING_START,
			pu->xm_error_pixmap);
		return False;
	} else
		sprintf(buf, "%s 3:41am", dssw->date_val);

	start_tick = cm_getdate(buf, NULL);
	if(start_tick < 0) {
		editor_err_msg(dssw->parent, name, INVALID_DATE,
			pu->xm_error_pixmap);
		return False;
	}

	if (blank_buf(dssw->what_val) && blank_buf(dssw->start_val.val)
		&& blank_buf(dssw->stop_val.val)) {
		editor_err_msg(dssw->parent, name, INVALID_NOTIME_APPT,
			pu->xm_error_pixmap);
		return False;
	}

	a->time->value->item.date_time_value = (char *) malloc(BUFSIZ);
	_csa_tick_to_iso8601(start_tick, a->time->value->item.date_time_value);
	a->what->value->item.string_value = (char *)cm_strdup(dssw->what_val);
	a->show_time->value->item.sint32_value = True;

	if (!blank_buf(dssw->stop_val.val)) {
		if (dt == HOUR12) {
			/* am and pm should not be translated.  They are only
			 * used in the date parsing code and never shown to
			 * the user.
			 */
			if (dssw->stop_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s", dssw->date_val,
			dssw->stop_val.val, ampm_buf); 
		if ((stop_tick = cm_getdate(buf, NULL)) <= 0) {
			editor_err_msg(dssw->parent, name, INVALID_DATE,
				       pu->xm_error_pixmap);
			return False;
		}
		if (stop_tick < start_tick) {
		    if (*flagsP == 0)
		    {
		  	char *title = XtNewString(catgets(calendar->DT_catd, 1, 248,
					"Calendar : Schedule Appointment"));
		  	char *ident1 = XtNewString(catgets(calendar->DT_catd, 1,
					923, "Cancel"));
		  	char *ident2 = XtNewString(catgets(calendar->DT_catd, 1,
					250, "Next Day"));
			sprintf(buf, "%s", catgets(calendar->DT_catd, 1, 247,
				"This appointment has an end time earlier than\nits begin time.  Do you want to\nschedule it into the next day?"));
			*flagsP = dialog_popup(dssw->parent,
				DIALOG_TITLE, title,
				DIALOG_TEXT, buf,
				BUTTON_IDENT, -1, ident1,
				BUTTON_IDENT, DSSW_NEXT_DAY, ident2,
				DIALOG_IMAGE, pu->xm_question_pixmap,
				NULL);
			XtFree(ident2);
			XtFree(ident1);
			XtFree(title);
		    }
		    switch (*flagsP) {
		    case DSSW_NEXT_DAY:
			stop_tick += daysec;
			break;

		    default:
			*flagsP = 0;
		        return False;
		    }
		}

		a->end_time->value->item.date_time_value = (char *) malloc(BUFSIZ);
		_csa_tick_to_iso8601(stop_tick, a->end_time->value->item.date_time_value);
	} else if (blank_buf(dssw->start_val.val)) {
		a->end_time->value->item.date_time_value = (char *) malloc(BUFSIZ);
		_csa_tick_to_iso8601(start_tick + minsec, a->end_time->value->item.date_time_value);
		a->show_time->value->item.sint32_value = False;
	} else {
		free(a->end_time->value);
		a->end_time->value = NULL;
	}

	return True;
}
Example #7
0
/*
 * Append the new name to the list and set the necessary tags.  Note this only
 * adds the name to the linked list - not to the UI.  Also, it won't add a
 * duplicate name.
 */
static int
blist_name_append(Calendar *c, char *name, BlistTag t) {
        int             i = 1;
	Boolean		marked = False;
        int             location = 2;
        BlistData       *bd;
        Browselist      *bl = (Browselist *)c->browselist;
	char		*defname;
 

	/* This while loop is doing double duty here.  The primary 
	   purpose of the list is to find out if the name we're 
	   inserting is already in the list.  While looping thru, 
	   the secondary purpose is to find the lexicographical 
	   position of the name relative to the current set of entries.  
	   The business about marked and location is related to that 
	   second purpose. */

        while ((bd = (BlistData *)CmDataListGetData(bl->blist_data, i)) &&
               strcmp(bd->name, name) != 0)
	{
                if ((marked == False) && (strcoll(name, bd->name) < 0) && 
		    (i != 1)) {
                        location = i;
			marked = True;
		}
                ++i;
	}

        if (bd) {
		/* Since the user may have hit the reset button, any items
		 * that had been marked for deletion need to be made active.
		 */
		if (bd->tag == BLIST_DELETE)
			bd->tag = BLIST_ACTIVE;

                return -1;
	}
	
	/* 2 special cases here.  If the name is that of the calendar 
	   owner, it should always be at the head of the list.  If the 
	   name wasn't maked against any of the people on the list, 
	   then it should be inserted at the end. */

	defname = get_user_calendar();
	if (strcmp(defname, name) == 0) {
		location = 1;
	} else if (marked == False) {
		location = i;
	}
	free(defname);
 
        bd = (BlistData *)ckalloc(sizeof(BlistData));
        bd->name = cm_strdup(name);
        bd->tag = t;
        bd->cal_handle = NULL;
        CmDataListAdd(bl->blist_data, (void *)bd, location);
 
        return location;

}
Example #8
0
int main(int argc, char **argv)
{
	int		cnt;
	char		*target = NULL, *date = NULL, *view = NULL,
			*uname, *loc;
	Props		*p = NULL;
	CSA_session_handle	c_handle;
	CSA_entry_handle	*list;
	CSA_return_code		stat;
	CSA_calendar_user	csa_user;
	int			version;
#ifdef FNS
	char		buf[256];
#endif

	init_time();
	_DtEnvControl(DT_ENV_SET); /* set up environment variables */
	setlocale(LC_ALL, "");
	DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
	cm_tty_load_props(&p);
	cm_args(argc,argv);		/* parse command line */

	target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials();
#ifdef FNS
	dtfns_init();
	if (cmfns_use_fns(p)) {
		cmfns_lookup_calendar(target, buf, sizeof(buf));
		target = buf;
	}
#endif
	uname = cm_target2name(target);
	loc = cm_target2location(target);

	csa_user.user_name = target;
	csa_user.user_type = 0;
	csa_user.calendar_user_extensions = NULL;
	csa_user.calendar_address = target;
	stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);

	if (stat != CSA_SUCCESS) {
		char *format = cm_strdup(catgets(DT_catd, 1, 208, 
				   "\nCould not open calendar \"%s\"\n"));
		fprintf(stderr, format, 
			target ? target : catgets(DT_catd, 1, 209, "UNKNOWN"));
		free(format);
		free(uname);
		free(loc);
		exit(1);
	}
	version = get_data_version(c_handle);
	if (cm_strlen(cm_date)) date = cm_date;
	if (cm_strlen(cm_view)) view = cm_view;

	if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, 
				 &list, p)) > 0)
		csa_free(list);
	csa_logoff(c_handle, NULL);
	props_clean_up(p);
	free(p);
	free(uname);
	free(loc);
	return 0;
}