2. Sending your notes out the Serial Port                January 20, 1996
(with the paragraphs in the correct order)
----------------------------------------------------------------------------


(Contributed by John Schettino js12© gte.com)

You can use NS BASIC to send the text of your notes out the serial port. 
This
is a simple way to capture note text on your PC or Mac, using a terminal
emulator to capture the text and save it to a file.

There are some cases where the note text seems to be sent in the wrong 
order.
This happens when you have edited a note on the Newton, rearranging the
paragraphs, or when you add new paragraphs in the middle of a note.

Each note in the notepad is stored in a record of the notes file. The notes
record includes a field named "data" that has an array of paragraphs for 
the
current note.

Let's say you wrote 3 different paragraps on your newton (tapped to set the
cursor in 3 places):


One

Two

Three

This gets you 3 frames in the data[] array of the entry for this note:

[{viewStationery:para,viewBounds:{left:12,top:10,right:232,bottom:48},text:
"One",viewFont:12291},

{viewStationery:para,viewBounds:{left:9,top:80,right:207,bottom:99},text:"T
wo",viewFont:12291},

{viewStationery:para,viewBounds:{left:7,top:122,right:230,bottom:179},text:
"Three",viewFont:12291}]


Note that the viewBounds.top numbers are in a nice acending order...
Dumping these in a loop like

rem no error checking
for i = 0 to length(n.data) -1
print n.data[i]
next i

would get you

One
Two
Three

Great, but what if you drag the middle line ("Two") below the third. Now 
on-
screen you see

One

Three

Two

but the data[] looks like this:

[{viewStationery:para,viewBounds:{left:12,top:10,right:232,bottom:48},text:
"One",viewFont:12291},

{viewStationery:para,viewBounds:{left:9,top:200,right:207,bottom:219},text:
"Two",viewFont:12291},

{viewStationery:para,viewBounds:{left:7,top:122,right:230,bottom:179},text:
"Three",viewFont:12291}]


Only the viewBounds.top/bottom has changed. You'll want to sort these
(using your favorite sort routine... how about the built-in sort()?)

First, copy the data array

mydata := clone(n.data) // copy the array pointers, but not the frames

Next, use sort() to sort the array based on viewbounds.top:

Sort( mydata,'|<|, 'viewbounds.top )

Now dump them out:

rem no error checking
for i = 0 to length(mydata) -1
print mydata[i]
next i

One
Two
Three


Here is a complete program that sends the text of all notes out the
serial port, with the text in the correct order:

0010 rem dump all notes to serial port
0020 open ch,"notes",timestamp
0030 environ io="s0"
0040 get ch,n
0050 if fstat=1 then goto 0130
0060 print datentime(n.timestamp)
0070 if not n.data or length(n.data)=0 then goto 40
0073 mydata := clone(n.data) // copy the array pointers, but not the
frames
0076 sort( mydata,'|<|, 'viewbounds.top )
0080 for i=0 to length(n.data)-1
0090   if n.data.text then print n.data[i].text // skip ink-only
paragraphs
0100 next i
0110 print " "
0120 GOTO 0040
0130 rem fin
0140 environ io="screen"