home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
beehive
/
bbs
/
rover12a.arc
/
EXPORT.INC
< prev
next >
Wrap
Text File
|
1991-08-11
|
10KB
|
397 lines
{** EXPORT.INC **}
procedure export_menu;
label continue, nextstep;
var
ch: char;
st: string[6];
value, code, I: integer;
textflag: boolean;
begin
folder:= 0;
deleted:= 0;
public:= 0;
start_number:= 0;
textflag:= false;
writeln('EXPORT MENU:');
writeln('(control C aborts)');
writeln;
if existstext('MESSAGES.ASC') then
begin
textflag:= true;
write('MESSAGES.ASC exists, and will be overwritten if you proceed.');
end
else
begin
if not opennewtext('MESSAGES.ASC') then finis(2);
writeln('Messages will be exported to MESSAGES.ASC on the default drive.');
end;
writeln;
writeln;
write('Do you want to select specific message(s) (y,[N])? ');
by_number:= (upcase(readKeyETX) = 'Y');
if by_number then
begin
for I:= 1 to 10 do msg[I]:= 0;
writeln;
writeln(' Enter up to 10 message numbers to select.');
writeln(' Enter 0 to end.');
for I:= 1 to 10 do
begin
write(I, '. ');
readln(msg[I]);
if msg[I] < 1 then goto continue;
end;
end;
CONTINUE:
if by_number then goto nextstep;
writeln;
write('Is there a starting number (y,[N])? ');
if (upcase(readKeyETX) = 'Y') then
begin
writeln;
write(' Enter the starting message number: ');
readln(st);
if (length(st) > 0) then
begin
val(st, start_number, code);
if (code > 0) then start_number:= 0;
end;
end
else writeln;
write('Select folder number (1-9) or [A] LL: ');
ch:= readKeyETX;
if ch in ['1'..'9'] then folder:= ord(ch) - $30
else folder:= 0;
writeln;
write('Select <D>eleted, <U>ndeleted, <R>ead, or [A] LL: ');
case upcase(readKeyETX) of
'D': deleted:= 2;
'U': deleted:= 1;
'R': deleted:= 3;
else deleted:= 0;
end;
writeln;
write('Select <P>ublic, p<R>ivate, or [A} LL: ');
case upcase(readKeyETX) of
'P': public:= 1;
'R': public:= 2;
else public:= 0;
end;
writeln;
NEXTSTEP:
writeln;
set_pick:= ((folder + deleted + public) > 0) or by_number;
if textflag then if not opennewtext('MESSAGES.ASC') then finis(2);
end; {export_menu}
function pad(PadStr: Str30; Len: integer): Str30;
var
I: integer;
begin
if length(PadStr) < Len then
begin
for I := length(PadStr) to Len do PadStr := PadStr + ' ';
Pad := PadStr
end
end; {pad}
function trim(st: Str80): Str80;
{remove trailing blanks}
label exitloop;
var
I: integer;
len: integer;
begin
len:= length(st);
for I := len downto 1 do
if st[I] = ' ' then delete(st,I,1) else goto exitloop;
EXITLOOP:
trim:= st;
end; {trim}
function convert(bt: byte): str1;
var
ch: str1;
begin
if (bt and $80 = $80) then ch:= ^@
else ch:= chr(bt);
{ch:= chr(bt and $7F);}
if ch in [^A..^_, char($7F)] then ch:= ' ';
convert:= ch;
end; {convert}
procedure transfer(start, count: integer);
var
I: integer;
begin
for I:= 1 to count do
selectbuffer[I]:= msgindexbuffer[I + start - 1];
end; {transfer}
function buffer_to_string: str30;
label stop;
var
I: integer;
st: str30;
begin
st:= '';
for I:= 1 to 30 do
begin
if selectbuffer[I] = 0 then goto stop;
st:= st + convert(selectbuffer[I]);
end;
STOP:
buffer_to_string:= st;
end; {buffer_to_string}
function buffer_to_integer: integer;
var
bt,bt1: byte;
numb: integer;
begin
bt:= selectbuffer[1];
bt1:= selectbuffer[2];
numb:= bt + (256 * bt1);
buffer_to_integer:= numb;
end; {buffer_to_integer}
procedure display;
begin
transfer(1,30);
writeln(buffer_to_string);
end; {display}
function pick: boolean;
label exitloop;
var
I: integer;
test: boolean;
OK: boolean;
begin
pick:= true;
test:= true;
OK:= true;
if not (set_pick or (start_number > 0)) then exit;
if (start_number > 0) then
test:= (msgindex.msg_no >= start_number);
if folder> 0 then test:= test and (folder = msgindex.folder);
if deleted> 0 then
case deleted of
1: test:= test and (msgindex.deleted < 2); {undeleted = 0, read = 1}
2: test:= test and (msgindex.deleted > 127); {deleted}
3: test:= test and (msgindex.deleted = 1); {read}
end; {case}
if public> 0 then
case public of
1: test:= test and (msgindex.public = 0); {public}
2: test:= test and (msgindex.public > 0); {private}
end; {case}
if by_number and test then
for I:= 1 to 10 do
begin
OK:= false;
if msg[I] = 0 then goto exitloop;
OK:= (msg[I] = msgindex.msg_no);
if OK then goto exitloop;
end;
EXITLOOP:
test:= test and OK;
pick:= test;
end; {pick}
procedure move_buffer;
var
I, count, destination: integer;
skip: boolean;
begin
skip:= msgindex_pointer >= 100;
count:= 100 - msgindex_pointer;
if skip then msgindex_pointer:= 100;
if msgindex_pointer > 0 then
for I:= 1 to msgindex_pointer do {move stored data}
msgindexbuffer[I]:= store[I];
if not skip then
begin
destination:= msgindex_pointer + 1;
msgindex_pointer:= 128 - count;
for I:= 0 to count - 1 do {move read data}
msgindexbuffer[I + destination]:= buffer[I + 1];
for I:= 1 to msgindex_pointer do {store extra data}
store[I]:= buffer[I + count];
end
else
begin
msgindex_pointer:= abs(count);
for I:= 1 to msgindex_pointer do
store[I]:= store[I + 100];
end;
end; {move_buffer}
procedure set_msgindex_record;
var
m,d,y: byte;
begin
msgindex.date:= byte_to_string(msgindexbuffer[33]) + '/'
+ byte_to_string(msgindexbuffer[34]) + '/'
+ byte_to_string(msgindexbuffer[35]);
{msgindex.time:= time;}
with msgindex do
begin
receiver:= buffertostring(msgindexbuffer, 1, 30); {str30}
msg_no:= msgindexbuffer[31] + msgindexbuffer[32]*256; {integer}
num_of_recs:= msgindexbuffer[36]; {byte}
start_rec_no:= msgindexbuffer[37] + msgindexbuffer[38]*256; {integer}
msgindex_rec_no:= mirecord; {integer}
subject:= buffertostring(msgindexbuffer, 41, 26); {string[26]}
sender:= buffertostring(msgindexbuffer, 67, 30); {str30}
public:= msgindexbuffer[97]; {byte}
folder:= msgindexbuffer[98]; {byte}
deleted:= msgindexbuffer[99]; {byte}
null:= 0; {byte}
end; {with}
end; {set_msgindex_record}
function readmsgindex: boolean;
var
buffer: bufftype;
mioffset: byte;
physicalrecord: integer;
name: string[30];
N: integer;
begin
begin
if (msgindexrec > index.last_msgindex_rec) then
begin
readmsgindex:= false;
exit;
end;
physicalrecord:= trunc((100/128) * msgindexrec);
mioffset:= round(frac((100/128) * msgindexrec) * 128) + 1;
seek(msgndxfil, physicalrecord);
blockread(msgndxfil, msgindexbuffer, 1);
buffer:= msgindexbuffer;
if (mioffset > 29) then {overflow to next physical rec.}
blockread(msgndxfil, buffer, 1);
if (mioffset > 1) and (mioffset < 30) then
for N:= mioffset to (100 + mioffset -1) do
msgindexbuffer[n - mioffset + 1] := msgindexbuffer[n];
if (mioffset > 29) then {overflow to next physical rec}
begin
for N:= mioffset to 128 do
msgindexbuffer[n - mioffset + 1] := msgindexbuffer[n];
for N:= 1 to (100 - 128 + mioffset -1) do
msgindexbuffer[n + 128 - mioffset + 1] := buffer[n];
end;
nextrecord:= msgindexbuffer[37]
+ msgindexbuffer[38]*256
+ msgindexbuffer[36];
end;
set_msgindex_record;
msgindexbuffer:= buffer;
readmsgindex:= true;
end; {readmsgindex}
function nextmsgindex: boolean;
var
OK: boolean;
begin
OK:= readmsgindex;
nextmsgindex:= OK;
if not OK then exit;
msgindexrec:= msgindexrec + 1;
end; {nextmsgindex}
function chek0(st: str64): str64;
{delete end of line after null}
var
p: byte;
st1: str64;
begin
st1:= st;
p:= 0;
if (length(st) > 0) then
p:= pos(NUL, st);
if (p > 0) then
st1:= copy(st, 1, p - 1 );
chek0:= st1;
end; {chek0}
procedure header;
begin
writeln(textfil,'Folder: ', folders[msgindex.folder]);
write(textfil,'Msg. # ', msgindex.msg_no:4, ' ');
write(textfil,'Dated: ' + msgindex.date);
write(textfil,' ':10);
writeln(textfil,'Subj: ' + msgindex.subject);
write(textfil,'To: ' + fixcaps(msgindex.receiver));
writeln(textfil,' From: ' + fixcaps(msgindex.sender));
writeln(textfil);
end; {header}
function readmessageline(numb: integer): str64;
var
I: integer;
OD: boolean;
st: string[128];
st1: str64;
begin
st:= '';
OD:= odd(numb);
numb:= trunc(numb / 2);
seek(messagesfil,numb);
blockread(messagesfil, buffer, 1);
begin
for I:= 1 to 128 do
st:= st + convert(buffer[I]);
if not od then st1:= copy(st,1,64)
else st1:= copy(st,65,64);
end;
readmessageline:= st1;
end; {readmessageline}
procedure get_message;
var
I: integer;
OK: boolean;
st: str64;
begin
st:= '';
begin
header;
for I:= 0 to msgindex.num_of_recs - 1 do
begin
st:= chek0(readmessageline(msgindex.start_rec_no + I));
writeln(textfil,st);
end;
writeln(textfil);
end;
end; {get_message}
procedure do_export;
begin
if not openfiles then finis(2);
readindex;
if not export then exit;
writeln('EXPORT FILES:');
writeln;
writeln('working...');
writeln;
if (index.next_message_number < start_number + 1) then finis(1);
msgindexrec:= 0;
while nextmsgindex do
if pick then
begin
write(msgindex.msg_no, ' ');
get_message; {if readmessages then;}
{ transfer_message;}
end;
writeln;
end; {do_export}