Exemplo n.º 1
0
static GnomePilotRecord
local_record_to_pilot_record (EAddrLocalRecord *local,
			      EAddrConduitContext *ctxt)
{
	GnomePilotRecord p;
#ifdef PILOT_LINK_0_12
	pi_buffer_t * buffer;
#else
	static char record[0xffff];
#endif

	g_assert (local->addr != NULL );

	LOG (g_message ( "local_record_to_pilot_record\n" ));

	memset (&p, 0, sizeof (GnomePilotRecord));

	p.ID = local->local.ID;
	p.category = local->local.category;
	p.attr = local->local.attr;
	p.archived = local->local.archived;
	p.secret = local->local.secret;

	/* Generate pilot record structure */

#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 p;
	}

	pack_Address (local->addr, buffer, address_v1);

	p.record = g_new0(unsigned char, buffer->used);
	p.length = buffer->used;
	memcpy(p.record, buffer->data, buffer->used);

	pi_buffer_free(buffer);
#else
	p.record = (unsigned char *)record;
	p.length = pack_Address (local->addr, p.record, 0xffff);
#endif
	return p;
}
Exemplo n.º 2
0
/***********************************************************************
 *
 * Function:    read_file
 *
 * Summary:    	Open specified file and read into address records
 *
 * Parameters:  filehandle
 *
 * Returns:
 *
 ***********************************************************************/
int read_file(FILE *f, int sd, int db, struct AddressAppInfo *aai) {
	int 	i	= -1,
		l,
		attribute,
		category;
	char 	buf[0xffff];
	int showPhone = -1;

	pi_buffer_t *record;

	struct 	Address addr;

	int fields = 0; /* Number of fields in this entry */
	int count = 0; /* Number of entries read */
	const char *progress = "   Reading CSV entries, writing to Palm Address Book... ";

	if (!plu_quiet) {
		printf("%s",progress);
		fflush(stdout);
	}

	while (!feof(f)) {
		fields = 0;
		l = getc(f);
		if (feof(f) || (l<0)) {
			break;
		}
		if ('#' == l) {
			/* skip remainder of line */
			while (!feof(f) && (l!='\n') && (l>=0)) {
				l = getc(f);
			}
			continue;
		} else {
			ungetc(l,f);
		}
		i = read_field(buf, f, sizeof(buf));
		/* fprintf(stderr,"* Field=%s\n",buf); */

		memset(&addr, 0, sizeof(addr));
		addr.showPhone = 0;
		showPhone = -1; /* None specified this record */

		if ((i == term_semi) && (tabledelim != term_semi)) {
			/* This is an augmented entry */
			category = plu_findcategory(&aai->category,buf,
				PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);
			i = read_field(buf, f, sizeof(buf));
			if (i == term_semi) {
				showPhone = match_phone(buf, aai);
				i = read_field(buf, f, sizeof(buf));
			}
		} else {
			category = defaultcategory;
		}

		if (i < 0)
			break;

		attribute = 0;

		for (l = 0; (i >= 0) && (l < 21); l++) {
			int l2 = realentry[l];

			if ((l2 >= 3) && (l2 <= 7)) {
				if ((i != term_semi) || (tabledelim == term_semi)) {
					addr.phoneLabel[l2 - 3] = l2 - 3;
				}
				else {
					addr.phoneLabel[l2 - 3] = match_phone(buf, aai);
					i = read_field(buf, f, sizeof(buf));
				}
				if (buf[0]) {
					addr.entry[l2] = strdup(buf);
					++fields;
				} else {
					addr.entry[l2] = NULL;
				}
			} else if (19 <= l2) {
				if (19 == l2) {
					attribute = (atoi(buf) ? dlpRecAttrSecret : 0);
				}
				if (20 == l2) {
					category = plu_findcategory(&aai->category,buf,
						PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);
				}
			} else {
				if (buf[0]) {
					addr.entry[l2] = strdup(buf);
					++fields;
				} else {
					addr.entry[l2] = NULL;
				}

			}

			if (i == 0)
				break;

			i = read_field(buf, f, sizeof(buf));
		}


		while (i > 0) {	/* Too many fields in record */
			i = read_field(buf, f, sizeof(buf));
		}

		if (showPhone >= 0) {
			/* Find which label matches the category to display */
			addr.showPhone = 0;
			for (i=0; i<5; ++i) {
				if (showPhone == addr.phoneLabel[i]) {
					addr.showPhone = i;
					break;
				}
			}
		}

		if (fields>0) {
		        record = pi_buffer_new(0);
			pack_Address(&addr, record, address_v1);
			dlp_WriteRecord(sd, db, attribute, 0, category,
					(unsigned char *) record->data, record->used, 0);
			pi_buffer_free(record);
			++count;
		}
		free_Address(&addr);

		if (!plu_quiet) {
			printf("\r%s%d",progress,count);
			fflush(stdout);
		}

	}

	if (!plu_quiet) {
		printf("\r%s%d\n   Done.\n",progress,count);
		fflush(stdout);
	}
	return 0;
}