#!/usr/bin/perl
# EL 2005 09 03
# Convert a CSV-exported export of all memos from Palm Desktop software
#  into a set of files meant for dropping into the A780 MyNotes directory
while (<STDIN>) {
	$templine = $_;
	# note that after this operation the first field starts with a junk
	#  doublequote and the last field ends with one
	@fields = split(/\"\t\"/, $templine);
	# take the first of these fields, then nuke the doublequote and 
	#  use the first line for a filename
	$memo = substr($fields[0], 1, length($fields[0])-1);
	@memolines = split(/\r/, $memo);
	$firstline = $memolines[0];
	# replace some characters that are annoying in filenames (TODO: add more)
	$firstline =~ s/\//(slash)/g;
	$firstline =~ s/\@/(at)/g;
	$firstline =~ s/\$/(dollar)/g;
	$firstline =~ s/\#/number/g;
	$firstline =~ s/\:/(colon)/g;
	$firstline =~ s/ /_/g;

	# fix newlines
	$memo =~ s/\r/\n/g;
	
	open(MEMOFILE, ">$firstline".".txt");		# Open a file named $firstline
	print MEMOFILE $memo;
	close(MEMOFILE);			# Close the file
}
