Index: Makefile.in
===================================================================
RCS file: /usr/local/cvsroot/pilot-link/Makefile.in,v
retrieving revision 1.1.1.1
diff -c -b -B -w -p -r1.1.1.1 Makefile.in
*** Makefile.in	2002/03/28 09:53:01	1.1.1.1
--- Makefile.in	2002/03/28 13:23:01
*************** CEXECS = addresses$(EXT) debugsh$(EXT) d
*** 91,97 ****
           pilot-clip$(EXT) pilot-dedupe$(EXT) pilot-file$(EXT) \
           pilot-mail$(EXT) pilot-prc$(EXT) pilot-schlep$(EXT) \
           pilot-xfer$(EXT) read-expenses$(EXT) read-ical$(EXT) \
!          read-todos$(EXT) reminders$(EXT) @ccexecs@
  
  CXXEXECS = ccexample$(EXT) iambicexample$(EXT)
  
--- 91,97 ----
           pilot-clip$(EXT) pilot-dedupe$(EXT) pilot-file$(EXT) \
           pilot-mail$(EXT) pilot-prc$(EXT) pilot-schlep$(EXT) \
           pilot-xfer$(EXT) read-expenses$(EXT) read-ical$(EXT) \
!          read-todos$(EXT) reminders$(EXT) pilot-pocketjournal$(EXT) @ccexecs@
  
  CXXEXECS = ccexample$(EXT) iambicexample$(EXT)
  
*************** pilot-debug$(EXT): $(PILIB) $(GETOPT) pi
*** 212,217 ****
--- 212,220 ----
  reminders$(EXT): $(PILIB) $(GETOPT) reminders.o
  	$(CCLINK) reminders.o $(PILIB) $(GETOPT) -o $@ $(LIBS)
  
+ pilot-pocketjournal$(EXT): $(PILIB) $(GETOPT) pilot-pocketjournal.o
+ 	$(CCLINK) pilot-pocketjournal.o $(PILIB) $(GETOPT) -o $@ $(LIBS)
+ 
  memos$(EXT): $(PILIB) $(GETOPT) memos.o
  	$(CCLINK) memos.o $(PILIB) $(GETOPT) -o $@ $(LIBS)
  
*************** pilot-mail.o: pilot-mail.c include/pi-so
*** 425,430 ****
--- 428,438 ----
   include/pi-socket.h include/pi-args.h include/pi-version.h \
   include/pi-sockaddr.h include/pi-macros.h include/pi-mail.h \
   include/pi-appinfo.h include/pi-dlp.h include/pi-header.h
+ pilot-pocketjournal.o: pilot-pocketjournal.c include/pi-source.h \
+  include/pi-config.h include/pi-socket.h include/pi-args.h \
+  include/pi-version.h include/pi-sockaddr.h include/pi-macros.h \
+  include/pi-dlp.h include/pi-pocketjournal.h include/pi-appinfo.h \
+  include/pi-header.h
  pilot-prc.o: pilot-prc.c include/pi-source.h include/pi-config.h \
   include/pi-socket.h include/pi-args.h include/pi-version.h \
   include/pi-sockaddr.h include/pi-macros.h include/pi-dlp.h \
Index: pilot-pocketjournal.c
===================================================================
RCS file: pilot-pocketjournal.c
diff -N pilot-pocketjournal.c
*** /dev/null	Tue Feb 23 03:41:16 1999
--- pilot-pocketjournal.c	Thu Mar 28 13:24:14 2002
***************
*** 0 ****
--- 1,648 ----
+ /*
+  * pilot-addresses.c:  Palm address transfer utility
+  *
+  * This program is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU General Public License as published by the
+  * Free Software Foundation; either version 2 of the License, or (at your
+  * option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+  * Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License along
+  * with this program; if not, write to the Free Software Foundation, Inc.,
+  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+  *
+  */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ #include "pi-source.h"
+ #include "pi-socket.h"
+ #include "pi-dlp.h"
+ #include "pi-pocketjournal.h"
+ #include "pi-header.h"
+ 
+ #define PILOTPORT "/dev/pilot"
+ 
+ /* Define prototypes */
+ int inchar(FILE * in);
+ int read_field(char *dest, FILE * in);
+ void outchar(char c, FILE * out);
+ int write_field(FILE * out, char *source, int more);
+ int match_category(char *buf, struct PocketJournalAppInfo *aai);
+ int read_file(FILE * in, int sd, int db, struct PocketJournalAppInfo *aai);
+ int write_file(FILE * out, int sd, int db, struct PocketJournalAppInfo *aai);
+ void Help(char *progname);
+ void Version(void);
+ 
+ char *tableheads[11] =
+   {       
+     "Flag",
+     "Date",
+     "Time",
+     "Duration",
+     "Type",
+     "Firstname",
+     "Lastname",
+     "Company",
+     "Number",
+     "Subject",
+     "Note"
+ };
+ 
+ int tableformat = 0;
+ int tabledelim = 1;
+ char tabledelims[5] = { '\n', ',', ';', '\t' };
+ int encodechars = 0;
+ 
+ int inchar(FILE * in)
+ {
+ 	int c;
+ 
+ 	c = getc(in);
+ 	if (encodechars && c == '\\') {
+ 		c = getc(in);
+ 		switch (c) {
+ 		case 'b':
+ 			c = '\b';
+ 			break;
+ 		case 'f':
+ 			c = '\f';
+ 			break;
+ 		case 'n':
+ 			c = '\n';
+ 			break;
+ 		case 't':
+ 			c = '\t';
+ 			break;
+ 		case 'r':
+ 			c = '\r';
+ 			break;
+ 		case 'v':
+ 			c = '\v';
+ 			break;
+ 		case '\\':
+ 			c = '\\';
+ 			break;
+ 		default:
+ 			ungetc(c, in);
+ 			c = '\\';
+ 			break;
+ 		}
+ 	}
+ 	return c;
+ }
+ 
+ 
+ int read_field(char *dest, FILE * in)
+ {
+ 	int c;
+ 
+ 	do {			/* Absorb whitespace */
+ 		c = getc(in);
+ 	} while ((c != EOF)
+ 		 && ((c == ' ') || (c == '\t') || (c == '\n')
+ 		     || (c == '\r')));
+ 
+ 	if (c == '"') {
+ 		c = inchar(in);
+ 
+ 		while (c != EOF) {
+ 			if (c == ',' || c == '\n') {
+ //			if (c == '"') {
+ 				c = inchar(in);
+ 				if (c != '"')
+ 					break;
+ 			}
+ 			*dest++ = c;
+ 			c = inchar(in);
+ 		}
+ 	} else {
+ 		while (c != EOF) {
+ 			if (c == ','
+ 			    || (tableformat
+ 				&& c == tabledelims[tabledelim])) {
+ 				break;
+ 			}
+ 			*dest++ = c;
+ 			c = inchar(in);
+ 		}
+ 	}
+ 	*dest++ = '\0';
+ 
+ 	while ((c != EOF) && ((c == ' ') || (c == '\t')))	/* Absorb whitespace */
+ 		c = getc(in);
+ 
+ 	if (c == ',')
+ 		return 1;
+ 	else if (c == ';')
+ 		return 2;
+ 	else if (c == '\t')
+ 		return 3;
+ 	else if (c == EOF)
+ 		return -1;	/* No more */
+ 	else
+ 		return 0;
+ }
+ 
+ void outchar(char c, FILE * out)
+ {
+ 
+ 	if (encodechars) {
+ 		switch (c) {
+ 		case '"':
+ 			putc('\\', out);
+ 			putc('"', out);
+ 			break;
+ 		case '\b':
+ 			putc('\\', out);
+ 			putc('b', out);
+ 			break;
+ 		case '\f':
+ 			putc('\\', out);
+ 			putc('f', out);
+ 			break;
+ 		case '\n':
+ 			putc('\\', out);
+ 			putc('n', out);
+ 			break;
+ 		case '\t':
+ 			putc('\\', out);
+ 			putc('t', out);
+ 			break;
+ 		case '\r':
+ 			putc('\\', out);
+ 			putc('r', out);
+ 			break;
+ 		case '\v':
+ 			putc('\\', out);
+ 			putc('v', out);
+ 			break;
+ 		case '\\':
+ 			putc('\\', out);
+ 			putc('\\', out);
+ 			break;
+ 		default:
+ 			putc(c, out);
+ 			break;
+ 		}
+ 	} else {
+ 		putc(c, out);
+ 		if (c == '"')
+ 			putc('"', out);
+ 	}
+ }
+ 
+ int write_field(FILE * out, char *source, int more)
+ {
+ 
+ 	putc('"', out);
+ 	while (*source) {
+ 		outchar(*source, out);
+ 		source++;
+ 	}
+ 	putc('"', out);
+ 
+ 	putc(tabledelims[more], out);
+ #if 0
+ 	if (more == 1)
+ 		putc(',', out);
+ 	else if (more == 2)
+ 		putc(';', out);
+ 	else if (more == 3)
+ 		putc('\t', out);
+ 	else if (more == 0)
+ 		putc('\n', out);
+ #endif
+ 	return 0;
+ }
+ 
+ int match_category(char *buf, struct PocketJournalAppInfo *aai)
+ {
+ 	int i;
+ 
+ 	for (i = 0; i < 16; i++)
+ 		if (strcasecmp(buf, aai->category.name[i]) == 0)
+ 			return i;
+ 	return atoi(buf);	/* 0 is default */
+ }
+ 
+ 
+ int defaultcategory = 0;
+ 
+ int read_file(FILE * in, int sd, int db, struct PocketJournalAppInfo *aai)
+ {
+ 	struct PocketJournal a;
+ 	int i, l;
+ 	char buf[0xffff];
+ 	int category, attribute;
+ 
+ 	do {
+ 		i = read_field(buf, in);
+ 
+ 		memset(&a, 0, sizeof(a));
+ 
+ 		if (tableformat) {
+ 			category = match_category(buf, aai);
+ 			i = read_field(buf, in);
+ 		} else {
+ 			if (i == 2) {
+ 				category = match_category(buf, aai);
+ 				i = read_field(buf, in);
+ 				if (i == 2) {
+ 				  /* a.showPhone = match_phone(buf, aai); */
+ 				  i = read_field(buf, in);
+ 				}
+ 			} else
+ 				category = defaultcategory;
+ 		}
+ 		if (i < 0)
+ 			break;
+ 
+ 		attribute = 0;
+ 
+ 		/* example 
+ 		for (l = 0; (i >= 0) && (l < 19); l++) {
+ 			int l2 = realentry[l];
+ 
+ 			if ((l2 >= 3) && (l2 <= 7)) {
+ 				if (i != 2 || tableformat)
+ 					a.phoneLabel[l2 - 3] = l2 - 3;
+ 				else {
+ 					a.phoneLabel[l2 - 3] =
+ 					    match_phone(buf, aai);
+ 					i = read_field(buf, in);
+ 				}
+ 			}
+ 
+ 			a.entry[l2] = strdup(buf);
+ 
+ 			if (i == 0)
+ 				break;
+ 
+ 			i = read_field(buf, in);
+ 		}
+ 		*/
+ 		attribute = (atoi(buf) ? dlpRecAttrSecret : 0);
+ 
+ 		while (i > 0) {	/* Too many fields in record */
+ 			i = read_field(buf, in);
+ 		}
+ 
+ #ifdef DEBUG
+ //      printf("Category %s (%d)\n", aai->CategoryName[category], category);
+ 		printf("Category %s (%d)\n", aai->category.name[category],
+ 		       category);
+ 		for (l = 0; l < 19; l++) {
+ 			if ((l >= 3) && (l <= 7))
+ 				printf(" %s (%d): %s\n",
+ 				       aai->phoneLabels[a.
+ 							phoneLabel[l - 3]],
+ 				       a.phoneLabel[l - 3], a.entry[l]);
+ 			else
+ 				printf(" %s: %s\n", aai->labels[l],
+ 				       a.entry[l]);
+ 		}
+ #endif
+ 
+ 		l = pack_PocketJournal(&a, (unsigned char *) buf, sizeof(buf));
+ #ifdef DEBUG
+ 		dumpdata(buf, l);
+ #endif
+ 		dlp_WriteRecord(sd, db, attribute, 0, category,
+ 				(unsigned char *) buf, l, 0);
+ 
+ 	} while (i >= 0);
+ 
+ 	return 0;
+ }
+ 
+ int augment = 0;
+ int tablehead = 0;
+ 
+ int write_file(FILE * out, int sd, int db, struct PocketJournalAppInfo *aai)
+ {
+   	struct PocketJournal a;
+ 	int i, j, l;
+ 	char buf[0xffff];
+ 	int category, attribute;
+ 	char timestamp[255];
+ 	
+ 	if (tablehead) {
+ 		write_field(out, "Category", tabledelim);
+ 		for (j = 0; j < 11; j++) {
+ 			write_field(out, tableheads[j],
+ 				    tabledelim);
+ 		}
+ 		//write_field(out, "Private-Flag", 0);
+ 		putc('\n', out);		
+ 	}
+ 
+ 	for (i = 0;
+ 	     (j =
+ 	      dlp_ReadRecordByIndex(sd, db, i, (unsigned char *) buf, 0,
+ 				    &l, &attribute, &category)) >= 0;
+ 	     i++) {
+ 
+ 
+ 		if (attribute & dlpRecAttrDeleted)
+ 			continue;
+ 
+ 
+ 		unpack_PocketJournal(&a, (unsigned char *) buf, l);
+ 		dlp_AddSyncLogEntry(sd, ".");
+ 
+ 		write_field(out, aai->category.name[category], -1);
+ 
+ 		putc(',', out);
+ 		if (a.flag) {
+ 		  write_field(out, "Marked", tabledelim);
+ 		} else {
+ 		  write_field(out, "Unmarked", tabledelim);
+ 		}
+ 
+ 		strftime(timestamp, 255, "%Y-%m-%d", &a.date);
+ 		write_field(out, timestamp, tabledelim);
+ 
+ 		if (a.time_set) {
+ 		  strftime(timestamp, 255, "%X", &a.date);
+ 		  write_field(out, timestamp, -1);
+ 		}
+ 		putc(',', out);
+ 
+ 		sprintf(timestamp, "%d:%d:%d",a.hours,a.minutes,a.seconds);
+ 		write_field(out, timestamp, tabledelim);
+ 
+ 		if (a.entryType)
+ 		  write_field(out, a.entryType, tabledelim);
+ 		if (a.entryFirst)
+ 		  write_field(out, a.entryFirst, tabledelim);
+ 		if (a.entryLast)
+ 		  write_field(out, a.entryLast, tabledelim);
+ 		if (a.entryCompany)
+ 		  write_field(out, a.entryCompany, tabledelim);
+ 		if (a.entryNumber)
+ 		  write_field(out, a.entryNumber, tabledelim);
+ 		if (a.entrySubject)
+ 		  write_field(out, a.entrySubject, tabledelim);
+ 		if (a.entryNote)
+ 		  write_field(out, a.entryNote, -1);
+ 
+ 		putc('\n', out);
+ 	}
+ 
+ 	return 0;
+ }
+ 
+ char *progname;
+ 
+ void Help(char *progname)
+ {
+ 	PalmHeader(progname);
+ 
+ 	fprintf(stderr, "   Usage: %s [-eqDT] [-p port]\n",
+ 		progname);
+ 	fprintf(stderr, "             [-d category] | -w [<file>]\n\n");
+ 	/* fprintf(stderr, "     -t delim    = include category, use delimiter (3=tab, 2=;, 1=,)\n"); */
+ 	fprintf(stderr, "     -T          = write header with titles\n");
+ 	fprintf(stderr, "     -q          = do not prompt for HotSync button press\n");
+ 	/* fprintf(stderr, "     -a          = augment records with additional information\n"); */
+ 	fprintf(stderr, "     -e          = escape special characters with backslash\n");
+ 	fprintf(stderr, "     -p port     = use device file <port> to communicate with Palm\n");
+ 	/* fprintf(stderr, "     -c category = install to category <category> by default\n"); */
+ 	fprintf(stderr, "     -d category = delete old Palm records in <category>\n");
+ 	fprintf(stderr, "     -D          = delete all Palm records in all categories\n");
+ 	/* fprintf(stderr, "     -r file     = read records from <file> and install them to Palm\n"); */
+ 	fprintf(stderr, "     -w file     = get records from Palm and write them to <file>\n\n");
+ 	exit(2);
+ }
+ 
+ void Version(void)
+ {
+ 	PalmHeader(progname);
+ 	fprintf(stderr,
+ 		"   Type 'man 7 %s' at your shell for more information.\n\n",
+ 		progname);
+ 	exit(0);
+ }
+ 
+ int main(int argc, char *argv[])
+ {
+ 	struct pi_sockaddr addr;
+ 	int db;
+ 	int sd;
+ 	int l;
+ 	struct PilotUser U;
+ 	int ret;
+ 	char buf[0xffff];
+ 	struct PocketJournalAppInfo aai;
+ 	char *defaultcategoryname = 0;
+ 	char *deletecategory = 0;
+ 	char *progname = argv[0];
+ 
+ /*   char *device = argv[1]; */
+ 	int deleteallcategories = 0;
+ 	int quiet = 0;
+ 	int mode = 0;
+ 	int c;
+ 	extern char *optarg;
+ 	extern int optind;
+ 
+ 	if (argc < 3)
+ 		Help(progname);
+ 
+ 	if (getenv("PILOTPORT")) {
+ 		strcpy(addr.pi_device, getenv("PILOTPORT"));
+ 	} else {
+ 		strcpy(addr.pi_device, PILOTPORT);
+ 	}
+ 
+ 	while (((c = getopt(argc, argv, "DTeqp:t:d:c:arw")) != -1)
+ 	       && (mode == 0)) {
+ 		switch (c) {
+ 
+ /* 		case 't': */
+ /* 			tableformat = 1; */
+ /* 			tabledelim = atoi(optarg); */
+ /* 			break; */
+ 		case 'D':
+ 			deleteallcategories = 1;
+ 			break;
+ 		case 'T':
+ 			tablehead = 1;
+ 			break;
+ /* 		case 'a': */
+ /* 			augment = 1; */
+ /* 			break; */
+ 		case 'q':
+ 			quiet = 1;
+ 			break;
+ 		case 'p':
+ 			/* optarg is name of port to use instead of
+ 			   $PILOTPORT or /dev/pilot */
+ 
+ 			strcpy(addr.pi_device, optarg);
+ 			break;
+ 		case 'd':
+ 			deletecategory = optarg;
+ 			break;
+ 		case 'e':
+ 			encodechars = 1;
+ 			break;
+ /* 		case 'c': */
+ /* 			defaultcategoryname = optarg; */
+ /* 			break; */
+ /* 		case 'r': */
+ /* 			mode = 1; */
+ /* 			break; */
+ 		case 'w':
+ 			mode = 2;
+ 			break;
+ 		case 'h':
+ 		case '?':
+ 			Help(progname);
+ 		}
+ 	}
+ 
+ 	if (mode == 0)
+ 		Help(progname);
+ 
+ 	if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
+ 		perror("pi_socket");
+ 		exit(1);
+ 	}
+ 
+ 	addr.pi_family = PI_AF_SLP;
+ /*   strcpy(addr.pi_device, device); */
+ 
+ 	ret = pi_bind(sd, (struct sockaddr *) &addr, sizeof(addr));
+ 	if (ret == -1) {
+ 		fprintf(stderr, "\n   Unable to bind to port %s\n",
+ 			addr.pi_device);
+ 		perror("   pi_bind");
+ 		fprintf(stderr, "\n");
+ 		exit(1);
+ 	}
+ 
+ 	if (!quiet) {
+ 		printf
+ 		    ("   Port: %s\n\n   Please press the HotSync button now...\n",
+ 		     addr.pi_device);
+ 	}
+ 
+ 	ret = pi_listen(sd, 1);
+ 	if (ret == -1) {
+ 		fprintf(stderr, "\n   Error listening on %s\n",
+ 			addr.pi_device);
+ 		perror("   pi_listen");
+ 		fprintf(stderr, "\n");
+ 		exit(1);
+ 	}
+ 
+ 	sd = pi_accept(sd, 0, 0);
+ 	if (sd == -1) {
+ 		fprintf(stderr, "\n   Error accepting data on %s\n",
+ 			addr.pi_device);
+ 		perror("   pi_accept");
+ 		fprintf(stderr, "\n");
+ 		exit(1);
+ 	}
+ 
+ 	if (!quiet) {
+ 		fprintf(stderr, "Connected...\n");
+ 	}
+ 
+ 	/* Ask the pilot who it is. */
+ 	dlp_ReadUserInfo(sd, &U);
+ 
+ 	/* Tell user (via the Palm) that we are starting things up */
+ 	dlp_OpenConduit(sd);
+ 
+ 	/* Open the CPJnlDB.pdb database, store access handle in db */
+ 	if (dlp_OpenDB(sd, 0, 0x80 | 0x40, "CPJnlDB", &db) < 0) {
+ 		puts("Unable to open CPJnlDB");
+ 		dlp_AddSyncLogEntry(sd, "Unable to open CPJnlDB.\n");
+ 		exit(1);
+ 	}
+ 
+ 	l = dlp_ReadAppBlock(sd, db, 0, (unsigned char *) buf, 0xffff);
+ 	unpack_PocketJournalAppInfo(&aai, (unsigned char *) buf, l);
+ 
+ 	if (defaultcategoryname)
+ 		defaultcategory =
+ 		    match_category(defaultcategoryname, &aai);
+ 	else
+ 		defaultcategory = 0;	/* Unfiled */
+ 
+ 	if (mode == 2) {	/* Write */
+ 		FILE *f = fopen(argv[optind], "w");
+ 
+ 		if (f == NULL) {
+ 			sprintf(buf, "%s: %s", argv[0], argv[optind]);
+ 			perror(buf);
+ 			exit(1);
+ 		}
+ 		write_file(f, sd, db, &aai);
+ 		if (deletecategory)
+ 			dlp_DeleteCategory(sd, db,
+ 					   match_category(deletecategory,
+ 							  &aai));
+ 		fclose(f);
+ 	} else if (mode == 1) {
+ 		FILE *f;
+ 
+ 		while (optind < argc) {
+ 			f = fopen(argv[optind], "r");
+ 			if (f == NULL) {
+ 				sprintf(buf, "%s: %s", argv[0],
+ 					argv[optind]);
+ 				perror(buf);
+ 				continue;
+ 			}
+ 			if (deletecategory)
+ 				dlp_DeleteCategory(sd, db,
+ 						   match_category
+ 						   (deletecategory, &aai));
+ 
+ 			if (deleteallcategories) {
+ 				int i;
+ 
+ 				for (i = 0; i < 16; i++)
+ 					if (strlen(aai.category.name[i]) >
+ 					    0)
+ 						dlp_DeleteCategory(sd, db,
+ 								   i);
+ 			}
+ 
+ 			read_file(f, sd, db, &aai);
+ 			fclose(f);
+ 			optind++;
+ 		}
+ 	}
+ 
+ 	/* Close the database */
+ 	dlp_CloseDB(sd, db);
+ 
+ 	/* Tell the user who it is, with a different PC id. */
+ 	U.lastSyncPC = 0xDEADBEEF;
+ 	U.successfulSyncDate = time(NULL);
+ 	U.lastSyncDate = U.successfulSyncDate;
+ 	dlp_WriteUserInfo(sd, &U);
+ 
+ 	if (mode == 1) {
+ 		dlp_AddSyncLogEntry(sd, "Wrote pocket journal to Palm.\n");
+ 	} else if (mode == 2) {
+ 		dlp_AddSyncLogEntry(sd, "Read pocket journal from Palm.\n");
+ 	}
+ 
+ 	/* All of the following code is now unnecessary, but harmless */
+ 
+ 	dlp_EndOfSync(sd, 0);
+ 	pi_close(sd);
+ 
+ 	return 0;
+ }
Index: include/pi-pocketjournal.h
===================================================================
RCS file: pi-pocketjournal.h
diff -N pi-pocketjournal.h
*** /dev/null	Tue Feb 23 03:41:16 1999
--- include/pi-pocketjournal.h	Thu Mar 28 13:24:14 2002
***************
*** 0 ****
--- 1,48 ----
+ #ifndef _PILOT_POCKETJOURNAL_H_
+ #define _PILOT_POCKETJOURNAL_H_
+ 
+ #include "pi-args.h"
+ #include "pi-appinfo.h"
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
+   
+ 
+ 	struct PocketJournal {
+ 	  signed char flag;
+ 	  struct tm date;
+ 	  int time_set; /* 1=time is set, 0=notime */
+ 	  int hours, minutes, seconds; /* duration of event */
+ 	  char *entryType;
+ 	  char *entryFirst;
+ 	  char *entryLast;
+ 	  char *entryCompany;
+ 	  char *entryNumber;
+ 	  char *entrySubject;
+ 	  char *entryNote;
+ 	};
+ 
+ 	struct PocketJournalAppInfo {
+ 	  struct CategoryAppInfo category;
+ 	  /* More that I don't know about ! */
+ 	};
+ 
+ 	extern void free_PocketJournal PI_ARGS((struct PocketJournal *));
+ 	extern int unpack_PocketJournal
+             PI_ARGS((struct PocketJournal *,
+ 		     unsigned char *record, int len));
+ 	extern int pack_PocketJournal
+ 	    PI_ARGS((struct PocketJournal *, unsigned char *record, int len));
+ 	extern int unpack_PocketJournalAppInfo
+ 	    PI_ARGS((struct PocketJournalAppInfo *, unsigned char *AppInfo,
+ 		     int len));
+ 	extern int pack_PocketJournalAppInfo
+ 	    PI_ARGS((struct PocketJournalAppInfo *, unsigned char *AppInfo,
+ 		     int len));
+ 
+ #ifdef __cplusplus
+ }
+ #endif
+ #endif				/* _PILOT_ADDRESS_H_ */
Index: libsock/Makefile.in
===================================================================
RCS file: /usr/local/cvsroot/pilot-link/libsock/Makefile.in,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.2
diff -c -b -B -w -p -r1.1.1.1 -r1.1.1.1.2.2
*** libsock/Makefile.in	2002/03/28 09:53:02	1.1.1.1
--- libsock/Makefile.in	2002/03/28 13:23:41	1.1.1.1.2.2
*************** FILEOBJS = pi-file.$(O)
*** 8,14 ****
  
  PIHEADER = pi-header.$(O)
  
! APPOBJS = datebook.$(O) memo.$(O) address.$(O) todo.$(O) expense.$(O) mail.$(O) sync.$(O) appinfo.$(O) hinote.$(O)
  
  UTILOBJS = utils.$(O) util.$(O)
  
--- 8,14 ----
  
  PIHEADER = pi-header.$(O)
  
! APPOBJS = datebook.$(O) memo.$(O) address.$(O) todo.$(O) expense.$(O) mail.$(O) sync.$(O) appinfo.$(O) hinote.$(O) pocketjournal.$(O)
  
  UTILOBJS = utils.$(O) util.$(O)
  
*************** pi-file.o pi-file.lo: pi-file.c ../inclu
*** 154,159 ****
--- 154,164 ----
   ../include/pi-sockaddr.h ../include/pi-macros.h ../include/pi-file.h \
   ../include/pi-dlp.h
  pi-header.o pi-header.lo: pi-header.c ../include/pi-version.h
+ pocketjournal.o pocketjournal.lo: pocketjournal.c ../include/pi-source.h \
+  ../include/pi-config.h ../include/pi-socket.h ../include/pi-args.h \
+  ../include/pi-version.h ../include/pi-sockaddr.h \
+  ../include/pi-macros.h ../include/pi-dlp.h \
+  ../include/pi-pocketjournal.h ../include/pi-appinfo.h
  serial.o serial.lo: serial.c ../include/pi-source.h ../include/pi-config.h \
   ../include/pi-socket.h ../include/pi-args.h ../include/pi-version.h \
   ../include/pi-sockaddr.h ../include/pi-macros.h \
Index: libsock/pocketjournal.c
===================================================================
RCS file: pocketjournal.c
diff -N pocketjournal.c
*** /dev/null	Tue Feb 23 03:41:16 1999
--- libsock/pocketjournal.c	Thu Mar 28 13:24:15 2002
***************
*** 0 ****
--- 1,241 ----
+ /*
+  * pocketjournal.c:  Translate pocket journal data formats
+  *
+  * Copyright (c) 2002, Nick Piper
+  *
+  *
+  * This library is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Library General Public License as published by
+  * the Free Software Foundation; either version 2 of the License, or (at
+  * your option) any later version.
+  * 
+  * This library is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
+  * General Public License for more details.
+  *
+  * You should have received a copy of the GNU Library General Public License
+  * along with this library; if not, write to the Free Software Foundation,
+  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+  */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "pi-source.h"
+ #include "pi-socket.h"
+ #include "pi-dlp.h"
+ #include "pi-pocketjournal.h"
+ 
+ /***********************************************************************
+  *
+  * Function:    free_PocketJournal
+  *
+  * Summary:	Free the members of an pocketjournal structure
+  *
+  * Parmeters:   None
+  *
+  * Returns:     Nothing
+  *
+  ***********************************************************************/
+ void free_PocketJournal(struct PocketJournal *a)
+ {
+ 	if (a->entryType) free(a->entryType);
+ 	if (a->entryFirst) free(a->entryFirst);
+ 	if (a->entryLast) free(a->entryLast);
+ 	if (a->entryCompany) free(a->entryCompany);
+ 	if (a->entryNumber) free(a->entryNumber);
+ 	if (a->entrySubject) free(a->entrySubject);
+ 	if (a->entryNote) free(a->entryNote);
+ }
+ 
+ /***********************************************************************
+  *
+  * Function:    unpack_PocketJournal
+  *
+  * Summary:     Fill in the pocketjournal structure based on the raw record 
+  *		data
+  *
+  * Parmeters:   None
+  *
+  * Returns:     0 on error, the length of the data used from the
+  *		buffer otherwise
+  *
+  ***********************************************************************/
+ int unpack_PocketJournal(struct PocketJournal *a, unsigned char *buffer, int len)
+ {
+ 	unsigned long d;
+ 	unsigned char *start = buffer;
+ 
+ 	if (len < 9)
+ 		return 0;
+ 
+ 	a->flag    =   get_byte(buffer);
+ 
+ 	d = (unsigned short int) get_short(buffer + 2);
+ 	a->date.tm_year = ((d & 0xfe00)>> 9) + 4;
+ 	a->date.tm_mon  = ((d & 0x01ef)>> 5) - 1;
+ 	a->date.tm_mday =   d & 0x001f;
+ 	a->date.tm_sec  =    0;
+ 	a->date.tm_isdst=    -1;
+ 
+ 	if ((get_byte (buffer + 4) == 255) || (get_byte (buffer + 5) == 255)) {
+ 	  a->date.tm_hour = 12;
+ 	  a->date.tm_min  = 0;
+ 	  a->time_set = 0;
+ 	} else {
+ 	  a->time_set = 1;
+ 	  a->date.tm_hour = get_byte (buffer + 4);
+ 	  a->date.tm_min  = get_byte (buffer + 5);
+ 	}
+ 
+ 	mktime(&a->date);
+ 
+ 	a->hours   =   get_short(buffer + 6) & 0x000f;
+ 	a->minutes =  (get_short(buffer + 6) & 0x03f0) >> 4;
+ 	a->seconds =  (get_short(buffer + 6) & 0xfc00) >> 10;
+ 	
+ 	buffer += 12;
+ 	len -= 12;
+ 
+ 	a->entryType = strdup(buffer); buffer += strlen(a->entryType) + 1;
+ 	a->entryFirst = strdup(buffer); buffer += strlen(a->entryFirst) + 1;
+ 	a->entryLast = strdup(buffer); buffer += strlen(a->entryLast) + 1;
+ 	a->entryCompany = strdup(buffer); buffer += strlen(a->entryCompany) + 1;
+ 	a->entryNumber = strdup(buffer); buffer += strlen(a->entryNumber) + 1;
+ 	a->entrySubject = strdup(buffer); buffer += strlen(a->entrySubject) + 1;
+ 	a->entryNote   = strdup(buffer); buffer += strlen(a->entryNote) + 1;
+ 
+ 	return (buffer - start);
+ }
+ 
+ /***********************************************************************
+  *
+  * Function:    pack_PocketJournal
+  *
+  * Summary:     Fill in the raw pocketjournal record data based on the 
+  *		pocketjournal structure
+  *
+  * Parmeters:   None
+  *
+  * Returns:     The length of the buffer required if record is NULL,
+  *		or 0 on error, the length of the data used from the 
+  *		buffer otherwise
+  *
+  ***********************************************************************/
+ int pack_PocketJournal(struct PocketJournal *a, unsigned char *record, int len)
+ {
+   unsigned char *buf = record;
+   int destlen = 12 + 7;
+   int v = 0;
+ 
+   /* the space for nulls is already counted in the + 7 above */
+ 
+   destlen += strlen(a->entryType);
+   destlen += strlen(a->entryFirst);
+   destlen += strlen(a->entryLast);
+   destlen += strlen(a->entryCompany);
+   destlen += strlen(a->entryNumber);
+   destlen += strlen(a->entrySubject);
+   destlen += strlen(a->entryNote);
+ 
+   if (!record)
+     return destlen;
+   if (len < destlen)
+     return 0;
+   
+   set_byte(buf, a->flag);
+   set_byte(buf + 1, 0); /* padding */
+ 
+   set_short(buf + 2,
+ 	    ((a->date.tm_year - 4) << 9) | ((a->date.tm_mon + 1) << 5) | a->date.tm_mday);
+ 
+   if (a->time_set) {
+     set_byte(buf + 4, a->date.tm_hour);
+     set_byte(buf + 5, a->date.tm_min);
+   } else {
+     set_byte(buf + 4, -1);
+     set_byte(buf + 5, -1);
+   }
+ 
+ 
+   set_short(buf + 6,
+ 	    (a->hours) | (a->minutes << 4) | (a->seconds << 10));
+ 
+   for (v = 8; v < 12; v++)
+     set_byte(buf + v, 0); /* padding ?! */
+ 
+   buf += 12;
+   len -= 12;
+   
+   strcpy(buf, a->entryType); buf+=strlen(buf)+1;
+   strcpy(buf, a->entryFirst); buf+=strlen(buf)+1;
+   strcpy(buf, a->entryLast); buf+=strlen(buf)+1;
+   strcpy(buf, a->entryCompany); buf+=strlen(buf)+1;
+   strcpy(buf, a->entryNumber); buf+=strlen(buf)+1;
+   strcpy(buf, a->entrySubject); buf+=strlen(buf)+1;
+   strcpy(buf, a->entryNote); buf+=strlen(buf)+1;
+   
+   return (buf - record);
+ }
+ 
+ /***********************************************************************
+  *
+  * Function:    unpack_PocketJournalAppInfo
+  *
+  * Summary:     Fill in the app info structure based on the raw app 
+  *		info data
+  *
+  * Parmeters:   None
+  *
+  * Returns:     The necessary length of the buffer if record is NULL,
+  *		or 0 on error, the length of the data used from the 
+  *		buffer otherwise
+  *
+  ***********************************************************************/
+ int
+ unpack_PocketJournalAppInfo(struct PocketJournalAppInfo *ai, unsigned char *record,
+ 		      int len)
+ {
+ 	int i;
+ 	unsigned char *start = record;
+ 	int destlen = 0;
+ 
+ 	i = unpack_CategoryAppInfo(&ai->category, record, len);
+ 	
+ 	if (!record)
+ 		return i + destlen;
+ 	if (!i)
+ 		return i;
+ 	record += i;
+ 	len -= i;
+ 
+ 	if (len < destlen)
+ 		return 0;
+ 
+ 	/* read any extra stuff now (fix destlen) */
+ 
+ 	return (record - start);
+ }
+ 
+ /***********************************************************************
+  *
+  * Function:    pack_PocketJournalAppInfo
+  *
+  * Summary:     Fill in the raw app info record data based on the app
+  *		info structure
+  *
+  * Parmeters:   None
+  *
+  * Returns:     The length of the buffer required if record is NULL,
+  *		or 0 on error, the length of the data used from the
+  *		buffer otherwise
+  *
+  ***********************************************************************/
+ int
+ pack_PocketJournalAppInfo(struct PocketJournalAppInfo *ai, unsigned char *record,
+ 		    int len)
+ {
+ 
+ }
