Пример #1
0
/*
** Returns the command
*/
char			*get_next_command(const int fd)
{
  char			buffer[10];
  struct termios	backup_st;
  void			(*func_op)();
  int			r;

  cursor(0);
  command_line(malloc(sizeof(*(command_line(NULL))) * 10));
  command_line(NULL)[0] = 0;
  backup_st = get_next_init(retrieve_vars(NULL));
  display_line(retrieve_vars(NULL));
  func_op = NULL;
  while (func_op != key_enter && (r = read(fd, buffer, 9)))
    {
      buffer[r] = 0;
      func_op = get_input_modif(buffer);
      func_op ? func_op() :
	command_line(insert_string(command_line(NULL), buffer));
      display_line(retrieve_vars(NULL));
    }
  set_conf(backup_st, 0);
  signal(SIGWINCH, SIG_DFL);
  signal(SIGTSTP, SIG_DFL);
  my_putchar('\n');
  test_and_add_bindkey(command_line(NULL));
  return (command_line(NULL));
}
Пример #2
0
static gboolean
is_syncable (EAddrConduitContext *ctxt, EAddrLocalRecord *local)
{
	EContactField next_mail, next_home, next_work, next_fax;
	EContactField next_other, next_main, next_pager, next_mobile;
	gboolean syncable = TRUE;
	int i, l = 0;

	/* See if there are fields we can't sync or not in priority order */
	get_next_init (&next_mail, &next_home, &next_work, &next_fax,
		       &next_other, &next_main, &next_pager, &next_mobile);

	for (i = entryPhone1; i <= entryPhone5 && syncable; i++) {
		int phonelabel = local->addr->phoneLabel[i - entryPhone1];
		const char *phone_str = local->addr->entry[i];
		gboolean empty = !(phone_str && *phone_str);

		if (empty)
			continue;

		for ( ; priority_label[l] != -1; l++)
			if (phonelabel == priority_label[l])
				break;

		if (priority_label[l] == -1) {
			syncable = FALSE;
			continue;
		}

		if (phonelabel == LABEL_EMAIL) {
			if (is_next_done (next_mail) || next_mail != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_mail = get_next_mail (&next_mail);
		} else if (phonelabel == LABEL_HOME) {
			if (is_next_done (next_home) || next_home != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_home = get_next_home (&next_home);
		} else if (phonelabel == LABEL_WORK) {
			if (is_next_done (next_work) || next_work != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_work = get_next_work (&next_work);
		} else if (phonelabel == LABEL_FAX) {
			if (is_next_done (next_fax) || next_fax != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_fax = get_next_fax (&next_fax);
		} else if (phonelabel == LABEL_OTHER) {
			if (is_next_done (next_other) || next_other != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_other = get_next_other (&next_other);
		} else if (phonelabel == LABEL_MAIN) {
			if (is_next_done (next_main) || next_main != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_main = get_next_main (&next_main);
		} else if (phonelabel == LABEL_PAGER) {
			if (is_next_done (next_pager) || next_pager != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_pager = get_next_pager (&next_pager);
		} else if (phonelabel == LABEL_MOBILE) {
			if (is_next_done (next_mobile) || next_mobile != priority[l]) {
				syncable = FALSE;
				break;
			}
			next_mobile = get_next_mobile (&next_mobile);
		}
	}

	return syncable;
}
Пример #3
0
static void
local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrConduitContext *ctxt)
{
	EContactAddress *address = NULL;
	int phone = entryPhone1;
	EContactField field;
	gboolean syncable;
	int i;

	g_return_if_fail (local != NULL);
	g_return_if_fail (contact != NULL);

	local->contact = g_object_ref (contact);
	local->local.ID = e_pilot_map_lookup_pid (ctxt->map, e_contact_get_const (contact, E_CONTACT_UID), TRUE);

	compute_status (ctxt, local, e_contact_get_const (contact, E_CONTACT_UID));

	local->addr = g_new0 (struct Address, 1);

	/* Handle the fields and category we don't sync by making sure
         * we don't overwrite them
	 */
	if (local->local.ID != 0) {
		struct Address addr;
		int cat = 0;
#ifdef PILOT_LINK_0_12
		pi_buffer_t * record;
		record = pi_buffer_new(DLP_BUF_SIZE);
		if(record == NULL){
			pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
			return;
		}
#else
		char record[0xffff];
#endif

		if (dlp_ReadRecordById (ctxt->dbi->pilot_socket,
					ctxt->dbi->db_handle,
#ifdef PILOT_LINK_0_12
					local->local.ID, record,
					NULL, NULL, &cat) > 0) {
#else
					local->local.ID, &record,
					NULL, NULL, NULL, &cat) > 0) {
#endif
			local->local.category = cat;
			memset (&addr, 0, sizeof (struct Address));
#ifdef PILOT_LINK_0_12
			unpack_Address (&addr, record, address_v1);
#else
			unpack_Address (&addr, (unsigned char *)record, 0xffff);
#endif
			for (i = 0; i < 5; i++) {
				if (addr.entry[entryPhone1 + i])
					local->addr->entry[entryPhone1 + i] =
						strdup (addr.entry[entryPhone1 + i]);
				local->addr->phoneLabel[i] = addr.phoneLabel[i];
			}
			local->addr->showPhone = addr.showPhone;
			for (i = 0; i < 4; i++) {
				if (addr.entry[entryCustom1 + i])
					local->addr->entry[entryCustom1 + i] =
						strdup (addr.entry[entryCustom1 + i]);
			}
			free_Address (&addr);
		}
#ifdef PILOT_LINK_0_12
		pi_buffer_free (record);
#endif
	}

	local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
	local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
	local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG));
	local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE));

	/* See if the default has something in it */
	if ((address = e_contact_get (contact, ctxt->cfg->default_address))) {
		field = ctxt->cfg->default_address;
	} else {
		/* Try to find a non-empty address field */
		for (field = E_CONTACT_FIRST_ADDRESS_ID; field <= E_CONTACT_LAST_ADDRESS_ID; field++) {
			if ((address = e_contact_get (contact, field)))
				break;
		}
	}

	if (address) {
		char *add;

		/* If the address has 2 lines, make sure both get added */
		if (address->ext != NULL &&
		    strlen (address->ext) > 0) {
			add = g_strconcat (address->street, "\n", address->ext, NULL);
			LOG (g_warning ("Address has two lines: [%s]\n", add));
		}
		else {
			add = g_strdup (address->street);
			LOG (g_warning ("Address has only one line: [%s]\n", add));
		}
		local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add);
		g_free (add);

		local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality);
		local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region);
		local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code);
		local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country);

		e_contact_address_free (address);
	}

	/* Phone numbers */

	/* See if everything is syncable */
	syncable = is_syncable (ctxt, local);

	if (syncable) {
		INFO ("Syncable");

		/* Sync by priority */
		for (i = 0, phone = entryPhone1;
		     priority[i] != E_CONTACT_FIELD_LAST && phone <= entryPhone5; i++) {
			const char *phone_str;

			phone_str = e_contact_get_const (contact, priority[i]);
			if (phone_str && *phone_str) {
				clear_entry_text (*local->addr, phone);
				local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str);
				local->addr->phoneLabel[phone - entryPhone1] = priority_label[i];
				phone++;
			}
		}
		for ( ; phone <= entryPhone5; phone++)
			local->addr->phoneLabel[phone - entryPhone1] = phone - entryPhone1;
		local->addr->showPhone = 0;
	} else {
		EContactField next_mail, next_home, next_work, next_fax;
		EContactField next_other, next_main, next_pager, next_mobile;

		INFO ("Not Syncable");
		get_next_init (&next_mail, &next_home, &next_work, &next_fax,
			       &next_other, &next_main, &next_pager, &next_mobile);

		/* Not completely syncable, so do the best we can */
		for (i = entryPhone1; i <= entryPhone5; i++) {
			int phonelabel = local->addr->phoneLabel[i - entryPhone1];
			const char *phone_str = NULL;

			if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
				phone_str = e_contact_get_const (contact, next_mail);
				next_mail = get_next_mail (&next_mail);
			} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
  				phone_str = e_contact_get_const (contact, next_home);
				next_home = get_next_home (&next_home);
			} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
				phone_str = e_contact_get_const (contact, next_work);
				next_work = get_next_work (&next_work);
			} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
				phone_str = e_contact_get_const (contact, next_fax);
				next_fax = get_next_fax (&next_fax);
			} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
				phone_str = e_contact_get_const (contact, next_other);
				next_other = get_next_other (&next_other);
			} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
				phone_str = e_contact_get_const (contact, next_main);
				next_main = get_next_main (&next_main);
			} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
				phone_str = e_contact_get_const (contact, next_pager);
				next_pager = get_next_pager (&next_pager);
			} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
				phone_str = e_contact_get_const (contact, next_mobile);
				next_mobile = get_next_mobile (&next_mobile);
			}

			if (phone_str && *phone_str) {
				clear_entry_text (*local->addr, i);
				local->addr->entry[i] = e_pilot_utf8_to_pchar (phone_str);
			}
		}
	}

	/* Note */
	local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE));
}
Пример #4
0
static EContact *
ecard_from_remote_record(EAddrConduitContext *ctxt,
			 GnomePilotRecord *remote,
			 EContact *in_contact)
{
	struct Address address;
	EContact *contact;
	EContactName *name;
	EContactAddress *eaddress;
	EContactField mailing_address;
	char *txt, *find, *full_name;
	EContactField next_mail, next_home, next_work, next_fax;
	EContactField next_other, next_main, next_pager, next_mobile;
	int i;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#endif
	g_return_val_if_fail(remote!=NULL,NULL);
	memset (&address, 0, sizeof (struct Address));
#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return NULL;
	}

	if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){
		pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
		return NULL;
	}
	unpack_Address (&address, buffer, address_v1);
	pi_buffer_free(buffer);
#else
	unpack_Address (&address, remote->record, remote->length);
#endif
	if (in_contact == NULL)
		contact = e_contact_new ();
	else
		contact = e_contact_duplicate (in_contact);

	/* Name */
	name = e_contact_name_new ();
	name->given = get_entry_text (address, entryFirstname);
	name->family = get_entry_text (address, entryLastname);

	full_name = e_contact_name_to_string (name);
	e_contact_set (contact, E_CONTACT_FULL_NAME, full_name);
	e_contact_name_free (name);

	/* File As */
	if (!full_name || !*full_name)
		set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany);

	g_free (full_name);

	/* Title and Company */
	set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle);
	set_contact_text (contact, E_CONTACT_ORG, address, entryCompany);

	/* Address */
	mailing_address = -1;
	if ((eaddress = e_contact_get (contact, ctxt->cfg->default_address))) {
		mailing_address = ctxt->cfg->default_address;
		e_contact_address_free (eaddress);
	} else {
		for (i = E_CONTACT_FIRST_ADDRESS_ID; i <= E_CONTACT_LAST_ADDRESS_ID; i++) {
			if ((eaddress = e_contact_get (contact, i))) {
				e_contact_address_free (eaddress);
				mailing_address = i;
				break;
			}
		}
	}

	if (mailing_address == -1)
		mailing_address = ctxt->cfg->default_address;

	eaddress = g_new0 (EContactAddress, 1);

	txt = get_entry_text (address, entryAddress);
	if (txt && (find = strchr (txt, '\n')) != NULL) {
		*find = '\0';
		find++;
	} else {
		find = NULL;
	}

	eaddress->street = txt;
	eaddress->ext = find != NULL ? g_strdup (find) : g_strdup ("");
	eaddress->locality = get_entry_text (address, entryCity);
	eaddress->region = get_entry_text (address, entryState);
	eaddress->country = get_entry_text (address, entryCountry);
	eaddress->code = get_entry_text (address, entryZip);

	e_contact_set (contact, mailing_address, eaddress);
	e_contact_address_free (eaddress);

	/* Phone numbers */
	get_next_init (&next_mail, &next_home, &next_work, &next_fax,
		       &next_other, &next_main, &next_pager, &next_mobile);

	for (i = entryPhone1; i <= entryPhone5; i++) {
		int phonelabel = address.phoneLabel[i - entryPhone1];
		char *phonenum = get_entry_text (address, i);

		if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
			e_contact_set (contact, next_mail, phonenum);
			next_mail = get_next_mail (&next_mail);
		} else if (phonelabel == LABEL_HOME && !is_next_done (next_home)) {
			e_contact_set (contact, next_home, phonenum);
			next_home = get_next_home (&next_home);
		} else if (phonelabel == LABEL_WORK && !is_next_done (next_work)) {
			e_contact_set (contact, next_work, phonenum);
			next_work = get_next_work (&next_work);
		} else if (phonelabel == LABEL_FAX && !is_next_done (next_fax)) {
			e_contact_set (contact, next_fax, phonenum);
			next_fax = get_next_fax (&next_fax);
		} else if (phonelabel == LABEL_OTHER && !is_next_done (next_other)) {
			e_contact_set (contact, next_other, phonenum);
			next_other = get_next_other (&next_other);
		} else if (phonelabel == LABEL_MAIN && !is_next_done (next_main)) {
			e_contact_set (contact, next_main, phonenum);
			next_main = get_next_main (&next_main);
		} else if (phonelabel == LABEL_PAGER && !is_next_done (next_pager)) {
			e_contact_set (contact, next_pager, phonenum);
			next_pager = get_next_pager (&next_pager);
		} else if (phonelabel == LABEL_MOBILE && !is_next_done (next_mobile)) {
			e_contact_set (contact, next_mobile, phonenum);
			next_mobile = get_next_mobile (&next_mobile);
		}

		g_free (phonenum);
	}

	/* Note */
	set_contact_text (contact, E_CONTACT_NOTE, address, entryNote);

	free_Address(&address);

	return contact;
}