home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
MISC
/
TGARTS.ZIP
/
SAMPLE.ZIP
/
TGSHORT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-12-20
|
3KB
|
93 lines
Program TGshort;
Uses Crt, Dtime;
{$I telegard.inc}
Var Short_file : file of shortmsgrec;
Short_Rec : shortmsgrec;
Temp_File : File of shortmsgrec;
Temp_Rec : shortmsgrec; {Temporary files}
Key : Char;
Del_Count,Total_count : Integer;
TempS : String;
DateR : datetimerec;
Begin
Clrscr;
Del_Count := 0; { Delete entry counter }
Total_count := 0;
Writeln('Are you sure you wish to pack (remove deleted entries)');
Writeln('your shortmsg.dat file? Press Y to continue or any other');
Writeln('to abort the packing');
Repeat
Until (Keypressed) or (Key='Y');
Key := Readkey;Key:= Upcase(Key);
IF Key='Y' then {Pack}
Begin
Assign(Short_file, 'shortmsg.dat');
Reset(short_file);
Assign(temp_file, 'shortmsg.new');
Rewrite(temp_file);
Writeln('Processing data file to purge deleted entries..stand by');
While not eof(short_file) do
Begin
Read(short_file, short_rec);
If short_rec.userid<>0 then {if 0 then ignore entry mark for deletion}
Begin
Temp_rec := short_rec; {copy record to write record}
Write(temp_file,temp_rec);
end;
If short_rec.userid=0 then Inc(Del_count);
inc(Total_count);
end;
Close(short_file);
Close(Temp_file);
Writeln;textcolor(11);
Writeln('Purge complete.');
Str(total_count,TempS);
Writeln('Total records '+TempS);
str(del_count,TempS);
Textcolor(14);Writeln('Total removed '+TempS);
If del_count=total_count then
Begin
Textcolor(12); {all records gone}
Writeln('The complete file has been purged!');
end else
Begin
If del_count>0 then {=0 then no need to rename files}
Begin
Textcolor(15);
Writeln('Renaming shortmsg.dat to shortmsg.bak (just in case)');
Rename(short_file,'shortmsg.bak');
Writeln('Renaming temporary file to shortmsg.dat');
Rename(temp_file,'shortmsg.dat');
Writeln('Erasing temporary file');
end;
if del_count=0 then erase(temp_file);
end;
Writeln;
{Remove next 15 lines for a basic purge program}
Textcolor(13);
Writeln('Now adding note to the end of the data file');
Writeln('Adding note to Sysop (record number 1) about the purge');
Assign(short_file,'shortmsg.dat');
Reset(short_file);
Short_rec.userid := 1;
Short_rec.msg := 'Removed '+temps+' from shortmsg.dat!!!';
Short_rec.msgid := 0;
Getdatetime(dateR); {Gets current date/time}
Short_rec.written:= dt2unix(dater);; {function to convert to unix}
{see dtime.pas for dt2unix function}
Seek(short_file,filesize(short_file));
Write(short_file,short_rec);
Close(Short_file);
Writeln('Note added to file!');
end else Writeln('No packing will be done');
Writeln;
Writeln('Program execusion is done');
end.