home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Extra 1997 #5
/
AmigaPlus_Extra-CD_5-97.iso
/
online-tools
/
mail
/
ems
/
rexx
/
dmreply.ems
< prev
next >
Wrap
Text File
|
1993-08-30
|
45KB
|
1,591 lines
/***************/
/* DMreply.ems */
/**********************/
/* Commands: */
/* */
/* EDIT 1 */
/* EDIT_FILE 2 */
/* WRITE 3 */
/* WRITE_FILE 4 */
/* REPLY 5 */
/* REPLY_FORWARD 6 */
/* REPLY_MULTISEND 7 */
/* FORWARD 8 */
/* MULTISEND 9 */
/* RESEND 10 */
/* ARCHIVE 11 */
/* CONFIG 12 */
/* */
/* ASK */
/**********************/
/* Arguments */
/* */
/* NO_REQS */
/* CARBON_COPY */
/* REPLY_KLUDGES */
/* CHOOSE_OPENING */
/* CHOOSE_COD */
/* CHOOSE_SIGNATURE */
/* CHOOSE_ORIGIN */
/**************************************/
/* $VER: DMreply.ems 1.0 (29.08.93) */
/**************************************/
script_name = 'DMreply'
script_version = 'v1.0'
options results
signal on error
signal on syntax
parse arg session_number src_area msg_num cmd_name cmd_args
cmd_args = strip( cmd_args, 'B' )
if( ~show( 'l', "rexxsupport.library" ) ) then
do
if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then
do
say "Could not open rexxsupport.library"
exit 10
end
end
if( ~show( 'l', "ems_rexx.library" ) ) then
do
if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
do
say "Could not open ems_rexx.library"
exit 10
end
end
if datatype( session_number, 'N' ) ~= 1 then signal Usage
if datatype( msg_num , 'N' ) ~= 1 then signal Usage
if src_area = '' then signal Usage
reply_cfg. = ''
dst_areas.0 = 0
carbon_copy_name.0 = 0
carbon_copy_addr.0 = 0
/*
** Search for areas of type MAIL
*/
call EMS_Areas_Mail( 'areas_mail' )
cmd_num = ParseCommand( src_area, cmd_name, cmd_args )
if cmd_num = 0 then signal ScriptExit
mask = Local_Cfg_Get( 'Cmd_AskAreas' )
if mask = 0 then
do
call EMS_Add_To_Stem( 'dst_areas', src_area )
end
if mask = 1 then
do
if EMS_Area_Select( 'area' ) = 'OK' then call EMS_Add_To_Stem( 'dst_areas', area )
end
if mask = 2 then
do
area = ''
do while EMS_Area_Select( 'area' ) = 'OK'
call EMS_Add_To_Stem( 'dst_areas', area ); area = ''
end
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Carbon_Copy' ) = 'TRUE' then
do
addr = ''
do while EMS_User_Select( 'name', 'addr' ) = 'OK'
call EMS_Add_To_Stem( 'carbon_copy_name', name )
call EMS_Add_To_Stem( 'carbon_copy_addr', addr )
addr = ''
end
end
/* No areas where to write. */
if dst_areas.0 = 0 then signal ScriptExit
if cmd_num = 12 then /* CONFIG */
do
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'TRUE' then
do
call ChooseOpening( src_area, 'TRUE' )
if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'TRUE' then
do
call ChooseSignature( src_area, 'TRUE' )
if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD' ) = 'TRUE' then
do
call ChooseCOD( src_area, 'TRUE' )
if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
end
call Global_Cfg_Set( src_area, 'ReplyKludges' , Local_Cfg_Get( 'Cfg_ReplyKludges' ) )
call Global_Cfg_Set( src_area, 'Opening' , Local_Cfg_Get( 'Cfg_Opening' ) )
call Global_Cfg_Set( src_area, 'Signature' , Local_Cfg_Get( 'Cfg_Signature' ) )
call Global_Cfg_Set( src_area, 'COD' , Local_Cfg_Get( 'Cfg_COD' ) )
call Global_Cfg_Set( src_area, 'ChooseOpening' , Local_Cfg_Get( 'Cfg_ChooseOpening' ) )
call Global_Cfg_Set( src_area, 'ChooseSignature' , Local_Cfg_Get( 'Cfg_ChooseSignature' ) )
call Global_Cfg_Set( src_area, 'ChooseCOD' , Local_Cfg_Get( 'Cfg_ChooseCOD' ) )
call Global_Cfg_Set( src_area, 'ChooseOrigin' , Local_Cfg_Get( 'Cfg_ChooseOrigin' ) )
call Global_Cfg_Set( src_area, 'NoDomainInOrigin', Local_Cfg_Get( 'Cfg_NoDomainInOrigin' ) )
signal ScriptExit
end
file = EMS_Var_Local( 'SCRIPT_MSG_FILE' )
if session_number ~= 0 then file = file || session_number
call Local_Cfg_Set( 'Msg_File' , file )
call Local_Cfg_Set( 'Sysop_Name', EMS_Var_Local( 'SYSOP_NAME' ) )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Read_Old_Msg' ) = 'FALSE' then msg_num = 0
/*
** Read the message to act on.
*/
sel = ''
if cmd_num = 2 | cmd_num = 4 then
do
if EMS_Area_File_DBname( src_area ) ~= '' then sel = 'FILE'
end
else
do
if EMS_Area_Msg_DBname( src_area ) ~= '' then sel = 'MSG'
end
if sel = '' then
do
call EMS_Do_Request( "Can't exec requested command (wrong database)!" )
signal ScriptExit
end
if msg_num ~= 0 then call EMS_Item_Alloc( 'reply_msg', src_area, sel, msg_num )
else call EMS_Item_Alloc( 'reply_msg', src_area, sel )
call Local_Cfg_Set( 'Header_From' , EMS_Item_Header_From( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_To' , EMS_Item_Header_To( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Subject' , EMS_Item_Header_Subject( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Date' , EMS_Item_Header_Date_Created( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Addr_From', EMS_Item_Header_Address_From( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Addr_To' , EMS_Item_Header_Address_To( 'reply_msg' ) )
area_name = dst_areas.1
call DeleteMsgFile( file )
if cmd_num = 11 then /* ARCHIVE */
do
mode.0 = 4
mode.1 = 'Default'
mode.2 = 'File (APPEND)'
mode.3 = 'File (OVERWRITE)'
mode.4 = 'Printer'
sel = 1
res = EMS_Do_Choice_Single( 'Archive Message As', 'mode', 'sel' )
if res ~= 'OK' then signal ScriptExit
textDir = EMS_Var_Local( 'SCRIPT_TEXT_DIR' ); if textDir = '' then textDir = 'EMS:'
arcfile = ''
if sel = 4 then arcfile = 'prt:'
if sel = 2 | sel = 3 then
do
arcfile = textDir
saved_CD = PRAGMA( 'D' )
call PRAGMA( 'D', textDir )
res = EMS_File_Select( 'Select Archive File', 'arcfile' )
call PRAGMA( 'D', saved_CD )
if res ~= 'OK' then signal ScriptExit
if arcfile = '' then sel = 1
end
if arcfile = '' then arcfile = textDir || src_area || '.txt'
if sel = 3 | sel = 4 then file_mode = 'WRITE'
else file_mode = 'APPEND'
if file_mode = 'APPEND' & exists( arcfile ) ~= 1 then file_mode = 'WRITE'
if open( 'tempname', arcfile, file_mode ) ~= 1 then
do
say "| Can't open '" || arcfile || "' file for output."
call ScriptExit
end
from = overlay( EMS_Item_Header_From( 'reply_msg' ), ' ' )
addfrom = EMS_Item_Header_Address_From( 'reply_msg' )
to = overlay( EMS_Item_Header_To( 'reply_msg' ), ' ' )
addto = EMS_Item_Header_Address_To( 'reply_msg' )
subject = EMS_Item_Header_Subject( 'reply_msg' )
date = overlay( EMS_Item_Header_Date_Created( 'reply_msg' ), ' ' )
call writeln( 'tempname', " " )
call writeln( 'tempname', "-------------------------- Archived Message ---------------------------" )
call writeln( 'tempname', "From :" || from || ' at ' || addfrom )
call writeln( 'tempname', "To :" || to || ' at ' || addto )
call writeln( 'tempname', "Subject:" || subject )
call writeln( 'tempname', "Date :" || date || ' Area : ' || src_area )
call writeln( 'tempname', "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" )
call close( 'tempname' )
call EMS_Item_File_Write( 'reply_msg', 'text', arcfile, 'APPEND' )
signal ScriptExit
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'TRUE' then call InsertOpening( file, area_name )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Quote_Text' ) = 'TRUE' then
do
/*
** Get first letter of name and firstname.
*/
from = Local_Cfg_Get( 'Header_From' )
Quoting = substr( from, 1, 1 )
if word( from, 2 ) = '' then Quoting = Quoting || substr( from, 2 , 1 )
else Quoting = Quoting || substr( word( from, 2 ), 1, 1 )
if Local_Cfg_Get( 'Cfg_ReplyKludges' ) = 'TRUE' then format_mode = 'TEARORIGIN SEENBYPATH OTHERKLUDGES'
else format_mode = ''
call EMS_Item_Lines_Format( 'reply_msg', Quoting || '>', 75, format_mode )
end
call EMS_Item_File_Write( 'reply_msg', 'text', file, 'APPEND' )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'TRUE' then call InsertSignature( file, area_name )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD' ) = 'TRUE' then call InsertCOD( file, area_name )
mode = Local_Cfg_Get( 'Cmd_Header' )
if mode = 2 then
do
call BuildREPLY( 'reply_msg' )
end
else
do
res = Local_Cfg_GetBit( 'Cmd_Actions', 'Reduce_Kludges' )
if res = 'TRUE' then call ReduceKludges( 'reply_msg' )
else call EMS_Item_Lines_Delete( 'reply_msg', 'header' )
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Reset_FATT' ) = 'TRUE' then
do
call EMS_Item_Header_Flag( 'reply_msg', 'FATT', 'OFF' )
end
do i=1 to dst_areas.0
area_name = dst_areas.i
call EMS_Item_Area( 'reply_msg', area_name )
/*
** Get infos about the message area.
*/
call Local_Cfg_Set( 'Area_Name', area_name )
call Local_Cfg_Set( 'Area_Type', upper( EMS_Area_Type( area_name ) ) )
call Local_Cfg_Set( 'Area_Addr', EMS_Area_Address( area_name ) )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Reset_Msg_Number' ) = 'TRUE' then call EMS_Item_Number( 'reply_msg', 0 )
header = Local_Cfg_Get( 'Cmd_Header' )
if header = 1 then
do
call EMS_Item_Header_From( 'reply_msg', Local_Cfg_Get( 'Sysop_Name' ) )
call EMS_Item_Header_Address_From( 'reply_msg', Local_Cfg_Get( 'Area_Addr' ) )
call EMS_Item_Header_Address_To( 'reply_msg', '' )
end
if header = 2 then
do
subject = Local_Cfg_Get( 'Header_Subject' )
if upper( left( subject, 3 ) ) ~= 'RE:' then subject = 'Re:' subject
addr_to = Local_Cfg_Get( 'Header_Addr_From' )
addr_area = Local_Cfg_Get( 'Area_Addr' )
if Local_Cfg_Get( 'Area_Type' ) ~= 'MAIL' & EMS_Address_IsFIDO( addr_area ) = 'TRUE' then addr_from = addr_area
else addr_from = EMS_Aka_Nearer( addr_to )
call EMS_Item_Header_From( 'reply_msg', Local_Cfg_Get( 'Sysop_Name' ) )
call EMS_Item_Header_To( 'reply_msg', Local_Cfg_Get( 'Header_From' ) )
call EMS_Item_Header_Subject( 'reply_msg', subject )
call EMS_Item_Header_Address_From( 'reply_msg', addr_from )
call EMS_Item_Header_Address_To( 'reply_msg', addr_to )
end
dump.0 = 0
call EMS_Item_SeenBy_Set( 'reply_msg', 'dump' )
call EMS_Item_Path_Set( 'reply_msg', 'dump' )
call EMS_Item_Header_Flag( 'reply_msg', 'SENT', 'OFF' )
if Local_Cfg_Get( 'Area_Type' ) = 'MAIL' then
do
call EMS_Item_Header_Flag( 'reply_msg', 'PVT', 'ON' )
end
else
do
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Origin' ) = 'TRUE' then call InsertOrigin( 'reply_msg', area_name )
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Call_Editor' ) = 'TRUE' then
do
cmd_pre = EMS_Var_Local( 'SCRIPT_EDITOR_NAME' )
cmd_post = EMS_Var_Local( 'SCRIPT_EDITOR_ARGS' )
select
when cmd_num = 1 then do; title = "Edit a Message" ; mode = "" ; end
when cmd_num = 2 then do; title = "Edit a File" ; mode = "" ; end
when cmd_num = 3 then do; title = "Write a Message" ; mode = "" ; end
when cmd_num = 4 then do; title = "Upload a File" ; mode = "" ; end
when cmd_num = 5 then do; title = "Reply to a Message" ; mode = "NOACTIVE" ; end
when cmd_num = 6 then do; title = "Reply&Forward a Message" ; mode = "NOACTIVE" ; end
when cmd_num = 7 then do; title = "Reply&MultiSend a Message"; mode = "NOACTIVE" ; end
when cmd_num = 8 then do; title = "Forward a Message" ; mode = "NOACTIVE NOEDIT"; end
when cmd_num = 9 then do; title = "Multisend a Message" ; mode = "" ; end
otherwise do; title = "" ; mode = "" ; end
end
if title ~= '' then
do
req_res = EMS_Item_Header_Edit( 'reply_msg', title, mode, cmd_pre file cmd_post )
if req_res ~= 'OK' then call ScriptExit
end
call Local_Cfg_SetBit( 'Cmd_Actions', 'Call_Editor', 'FALSE' )
end
if Local_Cfg_Get( 'Cfg_NoDomainInOrigin' ) = 'TRUE' then call AdjustOrigin( 'reply_msg' )
if exists( file ) then call EMS_Item_File_Read( 'reply_msg', 'text', file )
else call EMS_Item_Lines_Delete( 'reply_msg', 'text' )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Forward_Banner' ) = 'TRUE' then
do
line.1 = ' * Forwarded by' Local_Cfg_Get( 'Sysop_Name' ) 'on' Local_Cfg_Get( 'Area_Addr' )
line.2 = ' * Subj :' Local_Cfg_Set( 'Header_Subject' )
line.3 = ' * To :' Local_Cfg_Set( 'Header_To' ) || ',' Local_Cfg_Get( 'Header_Addr_To' )
line.4 = ' * From :' Local_Cfg_Set( 'Header_From' ) || ',' Local_Cfg_Get( 'Header_Addr_From' )
line.5 = ' * Area :' src_area
line.6 = ''
line.0 = 6
do j=line.0 to 1 by -1
call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line.j )
end
end
/*
** Make sure there's an origin for an ECHO message.
*/
if upper( EMS_Area_Type( area_name ) ) ~= 'MAIL' then
do
call EMS_Item_Lines_Get( 'reply_msg', 'header', 'lines' )
if EMS_Search_In_Stem( 'lines', ' * Origin: #?' ) = 0 then call InsertOrigin( 'reply_msg', area_name )
end
/*
** and no origin nor tearline for a MAIL message.
*/
else
do
call EMS_Item_Lines_Get( 'reply_msg', 'header', 'lines' )
orig_pos = EMS_Search_In_Stem( 'lines', ' * Origin: #?' )
tear_pos = EMS_Search_In_Stem( 'lines', '--- #?' )
if orig_pos ~= 0 | tear_pos ~= 0 then
do
new_lines.0 = 0
do j=1 to lines.0
if j = orig_pos then iterate
if j = tear_pos then iterate
call EMS_Add_To_Stem( 'new_lines', lines.j )
end
call EMS_Item_Lines_Set( 'reply_msg', 'header', 'new_lines' )
drop new_lines.
end
drop lines.
end
call EMS_Item_Write( 'reply_msg' )
if Local_Cfg_GetBit( 'Cmd_Actions', 'Move_Down_HWM' ) = 'TRUE' then
do
old_hwm = EMS_Area_HiMark( area_name )
new_hwm = EMS_Item_Number( 'reply_msg' ) - 1
if old_hwm > new_hwm then call EMS_Area_HiMark( area_name, new_hwm )
end
end
call Local_Cfg_Set( 'Header_From' , EMS_Item_Header_From( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_To' , EMS_Item_Header_To( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Subject' , EMS_Item_Header_Subject( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Date' , EMS_Item_Header_Date_Created( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Addr_From', EMS_Item_Header_Address_From( 'reply_msg' ) )
call Local_Cfg_Set( 'Header_Addr_To' , EMS_Item_Header_Address_To( 'reply_msg' ) )
/***************************************************/
/* Build CC: lines (originally from Bernd Ernesti) */
/***************************************************/
line_pre = ''
line_cc.0 = 0
do i=1 to carbon_copy_name.0
if i == carbon_copy_name.0 then line_end = ''
else line_end = ','
line_post = line_pre || carbon_copy_name.i || line_end
if LENGTH( line_post ) > 70 then
do
call EMS_Add_To_Stem( 'line_cc', ' CC:' line_pre )
line_post = carbon_copy_name.i || line_end
end
line_pre = line_post
end
if line_pre ~= '' then call EMS_Add_To_Stem( 'line_cc', ' CC:' line_pre )
/*
** Do CARBON COPY only if there's at least one MAIL area.
*/
if areas_mail.0 > 0 then
do
do i=1 to carbon_copy_name.0
cc_name = carbon_copy_name.i
cc_addr = carbon_copy_addr.i
/*
** Search nearer MAIL area.
*/
cc_aka_nearer = EMS_Aka_Nearer( cc_addr )
cc_area = areas_mail.1
do j=1 to areas_mail.0
if EMS_Address_Compare( cc_aka_nearer, EMS_Area_Address( areas_mail.j ) ) = 'TRUE' then
do
cc_area = areas_mail.j
leave
end
end
/*
** Get infos about the message area.
*/
call Local_Cfg_Set( 'Area_Name', cc_area )
call Local_Cfg_Set( 'Area_Type', 'MAIL' )
call Local_Cfg_Set( 'Area_Addr', EMS_Area_Address( cc_area ) )
dump.0 = 0
call EMS_Item_Area( 'reply_msg', cc_area )
call EMS_Item_Header_From( 'reply_msg', Local_Cfg_Get( 'Sysop_Name' ) )
call EMS_Item_Header_To( 'reply_msg', cc_name )
call EMS_Item_Header_Address_From( 'reply_msg', EMS_Aka_Nearer( cc_addr ) )
call EMS_Item_Header_Address_To( 'reply_msg', cc_addr )
call EMS_Item_SeenBy_Set( 'reply_msg', 'dump' )
call EMS_Item_Path_Set( 'reply_msg', 'dump' )
call EMS_Item_Header_Flag( 'reply_msg', 'SENT', 'OFF' )
call EMS_Item_Header_Flag( 'reply_msg', 'PVT' , 'ON' )
if exists( file ) then call EMS_Item_File_Read( 'reply_msg', 'text', file )
else call EMS_Item_Lines_Delete( 'reply_msg', 'text' )
if upper( EMS_Area_Type( area_name ) ) ~= 'MAIL' then
do
line.1 = ' * Carbon Copy by' Local_Cfg_Get( 'Sysop_Name' ) 'on' Local_Cfg_Get( 'Area_Addr' )
line.2 = ' * Subj :' Local_Cfg_Get( 'Header_Subject' )
line.3 = ' * To :' Local_Cfg_Get( 'Header_To' ) || ',' Local_Cfg_Get( 'Header_Addr_To' )
line.4 = ' * From :' Local_Cfg_Get( 'Header_From' ) || ',' Local_Cfg_Get( 'Header_Addr_From' )
line.5 = ' * Area :' dst_areas.1
line.6 = ''
line.0 = 6
do j=line.0 to 1 by -1
call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line.j )
end
end
if line_cc.0 > 0 then
do
call EMS_Item_Line_Add_Head( 'reply_msg', 'text', '' )
/* CC: lines */
do j=line_cc.0 to 1 by -1
call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line_cc.j )
end
end
call EMS_Item_Number( 'reply_msg', 0 )
call EMS_Item_Write( 'reply_msg' )
end
end
call DeleteMsgFile( file )
call EMS_Item_Free( 'reply_msg' )
/*************************************************************/
ScriptExit:
call EMS_FreeScriptData()
exit 0
/*************************************************************/
Usage:
say 'Usage:' script_name'.ems <session number> <source area name> <message num> [HELP|<command name>] [option ...]'
signal ScriptExit
/*************************************************************/
error:
syntax:
error_text = EMS_LastError()
if error_text = '' then error_text = rc ErrorText( rc )
say '| ***BREAK: error at' sigl error_text
call EMS_FreeScriptData()
exit rc
InsertOpening: procedure EXPOSE reply_cfg.
parse arg file_name , area_name
language = ChooseOpening( area_name, Local_Cfg_Get( 'Cfg_ChooseOpening' ) )
if language = '' then return 0
call EMS_CustomCfg_Get( 'DMreply_Openings', language, 'Lines', 'a' )
from = Local_Cfg_Get( 'Header_From' )
from_first = strip( word( from, 1 ), 'B' )
modifiers.1 = 'from_first'; data.1 = from_first
modifiers.2 = 'from' ; data.2 = from
modifiers.3 = 'to' ; data.3 = Local_Cfg_Get( 'Header_To' )
modifiers.4 = 'subject' ; data.4 = Local_Cfg_Get( 'Header_Subject' )
modifiers.5 = 'date' ; data.5 = Local_Cfg_Get( 'Header_Date' )
modifiers.6 = 'addr_from' ; data.6 = Local_Cfg_Get( 'Header_Addr_From' )
modifiers.7 = 'addr_to' ; data.7 = Local_Cfg_Get( 'Header_Addr_To' )
modifiers.0 = 7 ; data.0 = 7
if open( 'tempfile', file_name, 'W' ) ~= 1 then
do
say "| Can't open '" || file_name || "' file for output."
call ScriptExit
end
do i=1 to a.0
line = EMS_Translate_Stem( a.i, 'modifiers', 'data' )
call writeln( 'tempfile', line )
end
call writeln( 'tempfile', '' )
call close( 'tempfile' )
return 0
ChooseOpening: procedure EXPOSE reply_cfg.
parse arg area_name , choose
language = Local_Cfg_Get( 'Cfg_Opening' )
if language = '' & area_name ~= 'GENERAL' then language = EMS_Area_Language( area_name )
call EMS_CustomCfg_Get( 'DMreply_Openings', '', '', 'a' )
sel = EMS_Search_In_Stem( 'a', language )
if sel ~= 0 then language = a.sel
if choose = 'TRUE' then
do
call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
res = EMS_Do_Choice_Single( 'Choose Opening For Area' area_name, 'a', 'sel' )
if res = 'OK' then language = a.sel
else call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
end
call Local_Cfg_Set( 'Cfg_Opening', language )
return language
InsertSignature: procedure EXPOSE reply_cfg.
parse arg file_name , area_name
which = ChooseSignature( area_name, Local_Cfg_Get( 'Cfg_ChooseSignature' ) )
call EMS_CustomCfg_Get( 'DMreply_Signs', which, 'Lines', 'a' )
if open( 'tempfile', file_name, 'A' ) ~= 1 then
do
if open( 'tempfile', file_name, 'W' ) ~= 1 then
do
say "| Can't open '" || file_name || "' file for output."; call ScriptExit
end
end
do i=1 to a.0
call writeln( 'tempfile', a.i )
end
call close( 'tempfile' )
return 0
ChooseSignature: procedure EXPOSE reply_cfg.
parse arg area_name , choose
which = Local_Cfg_Get( 'Cfg_Signature' )
if which = '' then which = 'Normal'
if choose = 'TRUE' then
do
call EMS_CustomCfg_Get( 'DMreply_Signs', '', '', 'a' )
sel = EMS_Search_In_Stem( 'a', which )
call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
res = EMS_Do_Choice_Single( 'Choose Signature For Area' area_name, 'a', 'sel' )
if res = 'OK' then which = a.sel
else call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
drop a.
end
call Local_Cfg_Set( 'Cfg_Signature', which )
return which
InsertCOD: procedure EXPOSE reply_cfg.
parse arg file_name , area_name
which = ChooseCOD( area_name, Local_Cfg_Get( 'Cfg_ChooseCOD' ) )
if which = '' then return 0
call EMS_CustomCfg_Search( 'DMreply_COD', which'_#?', 'cods' )
if cods.0 = 0 then return 0
res = CalcRandom( cods.0 )
which = cods.res
if which = '' then return 0
call EMS_CustomCfg_Get( 'DMreply_COD', which, 'Lines', 'a' )
if a.0 = 0 then return 0
if open( 'tempfile', file_name, 'A' ) ~= 1 then
do
if open( 'tempfile', file_name, 'W' ) ~= 1 then
do
say "| Can't open '" || file_name || "' file for output."; call ScriptExit
end
end
call writeln( 'tempfile', '' )
do i=1 to a.0
call writeln( 'tempfile', a.i )
end
call writeln( 'tempfile', '' )
call close( 'tempfile' )
return 0
ChooseCOD: procedure EXPOSE reply_cfg.
parse arg area_name , choose
which = Local_Cfg_Get( 'Cfg_COD' )
call EMS_CustomCfg_Get( 'DMreply_COD', '', '', 'a' )
cods.0 = 0
do i=1 to a.0
parse var a.i name '_'
call EMS_Add_To_Stem( 'cods', name, 'UNIQUE' )
end
sel = EMS_Search_In_Stem( 'cods', which )
call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
if choose = 'TRUE' then
do
res = EMS_Do_Choice_Single( 'Choose COD For Area' area_name, 'cods', 'sel' )
if res ~= 'OK' then call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
end
if sel ~= 0 then which = cods.sel
else which = ''
call Local_Cfg_Set( 'Cfg_COD', which )
return which
InsertOrigin: procedure EXPOSE reply_cfg. script_name script_version
parse arg msg_name , area_name
a.0 = 0
sel = -1
call EMS_CustomCfg_Get( 'Origins', area_name, 'Origin', 'a' )
if a.0 = 0 then
do
call EMS_CustomCfg_Get( 'Origins', 'GENERAL', 'Origin', 'a' )
if a.0 = 0 then call EMS_Add_To_Stem( 'a', EMS_Var_Local( 'ORIGIN_NAME' ) )
end
call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
if Local_Cfg_Get( 'Cfg_ChooseOrigin' ) = 'TRUE' then
do
res = EMS_Do_Choice_Single( 'Choose Origin For Area' area_name, 'a', 'sel' )
if res ~= 'OK' then
do
sel = -1
call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
end
end
if sel = -1 then sel = CalcRandom( a.0 )
call EMS_Item_Line_Unique( msg_name, 'header', '--- ' , '---' script_name script_version )
call EMS_Item_Line_Unique( msg_name, 'header', ' * Origin: ', ' * Origin: ' || a.sel || ' (' || Local_Cfg_Get( 'Area_Addr' ) || ')' )
call Local_Cfg_Set( 'Cfg_Origin', a.sel )
return 0
AdjustOrigin: procedure EXPOSE reply_cfg.
parse arg msg_name
call EMS_Item_Lines_Get( msg_name, 'header', 'lines' )
orig_pos = EMS_Search_In_Stem( 'lines', ' * Origin: #?' )
if orig_pos = 0 then return 0
orig = lines.orig_pos; drop lines.
last_pos = lastpos( '(', orig ); if last_pos = 0 then return 0
orig_addr = substr( orig, last_pos ); parse var orig_addr '(' orig_addr ')'
orig = left( orig, last_pos - 1 )
if EMS_Address_IsFIDO( orig_addr ) ~= 'TRUE' then return 0
parse var orig_addr orig_addr '@'
call EMS_Item_Line_Unique( msg_name, 'header', ' * Origin: ', orig || '(' || orig_addr || ')' )
return 0
BuildREPLY: procedure EXPOSE reply_cfg.
parse arg msg_name
call EMS_Item_Lines_Get( msg_name, 'header', 'header_lines' )
msgid_line = EMS_Search_In_Stem( 'header_lines', '1'X || 'MSGID:#?' )
call EMS_Item_Lines_Delete( msg_name, 'header' )
if msgid_line ~= 0 then
do
id = substr( header_lines.msgid_line, 8 )
call EMS_Item_Line_Unique( msg_name, 'header', '1'X || 'REPLY:', '1'X || 'REPLY:' || id )
end
drop msgid_line
drop header_lines.
return 0
ReduceKludges: procedure EXPOSE reply_cfg.
parse arg msg_name
call EMS_Item_Lines_Get( msg_name, 'header', 'old_lines' )
new_lines.0 = 0
do i=1 to old_lines.0
line = upper( old_lines.i )
if left( line, 7 ) = '1'X || 'MSGID:' then iterate
if left( line, 5 ) = '1'X || 'EID:' then iterate
if left( line, 5 ) = '1'X || 'VIA:' then iterate
if left( line, 9 ) = '1'X || 'VIA NODE' then iterate
if left( line, 5 ) = '1'X || 'PID:' then iterate
call EMS_Add_To_Stem( 'new_lines', old_lines.i )
end
call EMS_Item_Lines_Set( msg_name, 'header', 'new_lines' )
return 0
DeleteMsgFile: procedure
parse arg file
if exists( file ) then
do
cmd_delete = EMS_Var_Local( 'SCRIPT_DELETE_NAME' )
address command cmd_delete file
end
return 0
ParseCommand: procedure EXPOSE reply_cfg. script_name script_version
parse arg area_name , cmd_name , cmd_args
cmd_name = upper( cmd_name )
/**************************************************************/
/* Command definitions: */
/* */
/* cmds.x Cmd_Name */
/* */
/* cmds_opt.x.0 Cmd_Header 0=OLD 1=NEW 2=REPLY */
/* */
/* cmds_opt.x.1 Cmd_AskAreas 0=NO 1=ONE 2=MANY */
/* */
/* cmds_opt.x.2 Cmd_Actions bit 0=Read Old Msg */
/* bit 1=Call Editor */
/* bit 2=Insert Opening */
/* bit 3=Insert Origin */
/* bit 4=Insert Signature */
/* bit 5=Insert COD */
/* bit 6=Quote Text */
/* bit 7=Forward Banner */
/* bit 8=Move Down HWM */
/* bit 9=Carbon Copy */
/* bit 10=Reply Kludges */
/* bit 11=Reduce Kludges */
/* bit 12=Reset FATT */
/* bit 13=Reset Msg Number */
/* */
/* cmds_opt.x.3 Cmd_AskFor bit 0=Do Carbon Copy */
/* bit 1=Reply Kludges */
/* bit 2=Insert Opening */
/* bit 3=Choose Opening */
/* bit 4=Insert Signature */
/* bit 5=Choose Signature */
/* bit 6=Insert COD */
/* bit 7=Choose COD */
/* bit 8=Choose Origin */
/* bit 9=No Domain In Origin */
/* */
/**************************************************************/
cmds.1 = 'EDIT'
cmds_help.1 = 'Edit an existing message.'
cmds_opt.1.0 = 0
cmds_opt.1.1 = 0
cmds_opt.1.2 = '00000000100100000011'b
cmds_opt.1.3 = '00000000001100000000'b
cmds.2 = 'EDIT_FILE'
cmds_help.2 = 'Edit an existing file.'
cmds_opt.2.0 = 0
cmds_opt.2.1 = 0
cmds_opt.2.2 = '00000000000000000011'b
cmds_opt.2.3 = '00000000000000000000'b
cmds.3 = 'WRITE'
cmds_help.3 = 'Write a new message.'
cmds_opt.3.0 = 1
cmds_opt.3.1 = 0
cmds_opt.3.2 = '00000010000000111010'b
cmds_opt.3.3 = '00000000001111110001'b
cmds.4 = 'WRITE_FILE'
cmds_help.4 = 'Upload a file.'
cmds_opt.4.0 = 1
cmds_opt.4.1 = 0
cmds_opt.4.2 = '00000010000000000010'b
cmds_opt.4.3 = '00000000000000000000'b
cmds.5 = 'REPLY'
cmds_help.5 = 'Reply to a message.'
cmds_opt.5.0 = 2
cmds_opt.5.1 = 0
cmds_opt.5.2 = '00000011000001111111'b
cmds_opt.5.3 = '00000000001111111111'b
cmds.6 = 'REPLY_FORWARD'
cmds_help.6 = 'Reply to a message, but in another area.'
cmds_opt.6.0 = 2
cmds_opt.6.1 = 1
cmds_opt.6.2 = '00000011000011111111'b
cmds_opt.6.3 = '00000000001111111111'b
cmds.7 = 'REPLY_MULTISEND'
cmds_help.7 = 'Reply to a message and send it in many areas.'
cmds_opt.7.0 = 2
cmds_opt.7.1 = 2
cmds_opt.7.2 = '00000011000001111111'b
cmds_opt.7.3 = '00000000001111111111'b
cmds.8 = 'FORWARD'
cmds_help.8 = 'Forward a message without editing.'
cmds_opt.8.0 = 0
cmds_opt.8.1 = 1
cmds_opt.8.2 = '00000010100010000011'b
cmds_opt.8.3 = '00000000001000000001'b
cmds.9 = 'MULTISEND'
cmds_help.9 = 'Write a new message and send it in many areas.'
cmds_opt.9.0 = 1
cmds_opt.9.1 = 2
cmds_opt.9.2 = '00000010000000111010'b
cmds_opt.9.3 = '00000000001111110001'b
cmds.10 = 'RESEND'
cmds_help.10 = 'Resend an old message.'
cmds_opt.10.0 = 0
cmds_opt.10.1 = 0
cmds_opt.10.2 = '00000000100100000001'b
cmds_opt.10.3 = '00000000000000000000'b
cmds.11 = 'ARCHIVE'
cmds_help.11 = 'Archive a message'
cmds_opt.11.0 = 0
cmds_opt.11.1 = 0
cmds_opt.11.2 = '00000000000000000001'b
cmds_opt.11.3 = '00000000000000000000'b
cmds.12 = 'CONFIG'
cmds_help.12 = 'Change the configuration of source area.'
cmds_opt.12.0 = 0
cmds_opt.12.1 = 0
cmds_opt.12.2 = '00000000000000111100'b
cmds_opt.12.3 = '00000000001111111110'b
cmds.0 = 12
opts.1 = 'NO_REQS'
opts_help.1 = "Don't ask anything."
opts.2 = 'CARBON_COPY'
opts_help.2 = 'Do carbon copy.'
opts.3 = 'REPLY_KLUDGES'
opts_help.3 = 'Reply kludges.'
opts.4 = 'INSERT_OPENING'
opts_help.4 = 'Insert an automatic opening on reply.'
opts.5 = 'CHOOSE_OPENING'
opts_help.5 = 'Choose the automatic opening.'
opts.6 = 'INSERT_SIGNATURE'
opts_help.6 = 'Insert a signature.'
opts.7 = 'CHOOSE_SIGNATURE'
opts_help.7 = 'Choose the signature.'
opts.8 = 'INSERT_COD'
opts_help.8 = 'Insert a random Quote Of The Day.'
opts.9 = 'CHOOSE_COD'
opts_help.9 = 'Choose the Quote Of The Day family.'
opts.10 = 'CHOOSE_ORIGIN'
opts_help.10 = 'Choose origin.'
opts.11 = 'NO_DOMAIN_IN_ORIGIN'
opts_help.11 = "Don't put domain in fidonet origins."
opts.0 = 11
if cmd_name = 'HELP' then
do
say 'List of commands supported by' script_name script_version || ':'
say
work_cmds.0 = cmds.0
do i=1 to cmds.0
work_cmds.i = cmds.i
end
call EMS_Calc_Stem_Width( 'work_cmds', 'ADAPT' )
do i=1 to work_cmds.0
say ' ' work_cmds.i '-' cmds_help.i
end
say
drop work_cmds.
say
say 'List of options:'
say
work_opts.0 = opts.0
do i=1 to opts.0
work_opts.i = opts.i
end
call EMS_Calc_Stem_Width( 'work_opts', 'ADAPT' )
do i=1 to work_opts.0
say ' ' work_opts.i '-' opts_help.i
end
drop work_opts.
return 0
end
if cmd_name = 'ASK' | cmd_name = '' then
do
sel = -1
res = EMS_Do_Choice_Single( 'Choose Operation', 'cmds', 'sel' )
if res = 'OK' then cmd_name = cmds.sel
else cmd_name = ''
end
if cmd_name ~= '' then sel = EMS_Search_In_Stem( 'cmds', cmd_name )
else sel = 0
if sel ~= 0 then
do
call Local_Cfg_Set( 'Cmd_Name' , cmds.sel )
call Local_Cfg_Set( 'Cmd_Header' , cmds_opt.sel.0 )
call Local_Cfg_Set( 'Cmd_AskAreas', cmds_opt.sel.1 )
call Local_Cfg_Set( 'Cmd_Actions' , cmds_opt.sel.2 )
work_area_name = area_name
call EMS_CustomCfg_Get( 'DMreply_Cfg', work_area_name, 'AreaName', 'a' )
if a.0 = 0 & cmd_name ~= 'CONFIG' then
do
call EMS_CustomCfg_Get( 'DMreply_Cfg', 'GENERAL', 'AreaName', 'a' )
if a.0 = 0 then work_area_name = ''
else work_area_name = 'GENERAL'
end
status.0 = 'FALSE'
choice.1 = 'Do Carbon Copy' ; status.1 = 'FALSE'
choice.2 = 'Reply Kludges' ; status.2 = 'FALSE'
choice.3 = 'Insert Opening' ; status.3 = 'FALSE'
choice.4 = 'Choose Opening' ; status.4 = 'FALSE'
choice.5 = 'Insert Signature' ; status.5 = 'FALSE'
choice.6 = 'Choose Signature' ; status.6 = 'FALSE'
choice.7 = 'Insert COD' ; status.7 = 'FALSE'
choice.8 = 'Choose COD' ; status.8 = 'FALSE'
choice.9 = 'Choose Origin' ; status.9 = 'FALSE'
choice.10 = 'No Domain In Origin'; status.10 = 'FALSE'
choice.0 = 10
cfg_ReplyKludges = Global_Cfg_Get( work_area_name, 'ReplyKludges' ); if cfg_ReplyKludges = '' then cfg_ReplyKludges = 'FALSE'
cfg_Opening = Global_Cfg_Get( work_area_name, 'Opening' )
cfg_Signature = Global_Cfg_Get( work_area_name, 'Signature' )
cfg_COD = Global_Cfg_Get( work_area_name, 'COD' )
cfg_ChooseOpening = Global_Cfg_Get( work_area_name, 'ChooseOpening' ); if cfg_ChooseOpening = '' then cfg_ChooseOpening = 'FALSE'
cfg_ChooseSignature = Global_Cfg_Get( work_area_name, 'ChooseSignature' ); if cfg_ChooseSignature = '' then cfg_ChooseSignature = 'FALSE'
cfg_ChooseCOD = Global_Cfg_Get( work_area_name, 'ChooseCOD' ); if cfg_ChooseCOD = '' then cfg_ChooseCOD = 'FALSE'
cfg_ChooseOrigin = Global_Cfg_Get( work_area_name, 'ChooseOrigin' ); if cfg_ChooseOrigin = '' then cfg_ChooseOrigin = 'FALSE'
cfg_NoDomainInOrigin = Global_Cfg_Get( work_area_name, 'NoDomainInOrigin' ); if cfg_NoDomainInOrigin = '' then cfg_NoDomainInOrigin = 'FALSE'
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'FALSE' then
do
cfg_Opening = ''
cfg_ChooseOpening = 'FALSE'
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'FALSE' then
do
cfg_Signature = ''
cfg_ChooseSignature = 'FALSE'
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD' ) = 'FALSE' then
do
cfg_COD = ''
cfg_ChooseCOD = 'FALSE'
end
if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Origin' ) = 'FALSE' then
do
cfg_ChooseOrigin = 'FALSE'
end
if cfg_ReplyKludges ~= 'FALSE' then status.2 = 'TRUE'
if cfg_Opening ~= '' then status.3 = 'TRUE'
if cfg_ChooseOpening ~= 'FALSE' then status.4 = 'TRUE'
if cfg_Signature ~= '' then status.5 = 'TRUE'
if cfg_ChooseSignature ~= 'FALSE' then status.6 = 'TRUE'
if cfg_COD ~= '' then status.7 = 'TRUE'
if cfg_ChooseCOD ~= 'FALSE' then status.8 = 'TRUE'
if cfg_ChooseOrigin ~= 'FALSE' then status.9 = 'TRUE'
if cfg_NoDomainInOrigin ~= 'FALSE' then status.10 = 'TRUE'
do while length( cmd_args ) ~= 0
parse var cmd_args cmd_arg cmd_args
cmd_arg = upper( cmd_arg )
if left( cmd_arg, 1 ) = '~' then do; val = 'FALSE'; cmd_arg = delstr( cmd_arg, 1, 1 ); end
else do; val = 'TRUE' ; end
do i=1 to opts.0
if cmd_arg = opts.i then do; j = i - 1; status.j = val; end
end
end
if status.0 = 'FALSE' then
do
j = 0
do i=1 to choice.0
if bittst( cmds_opt.sel.3, i - 1 ) then
do
j = j + 1
req_choice.j = choice.i; req_status.j = status.i
end
end
if j ~= 0 then
do
req_choice.0 = j
req_status.0 = j
res = EMS_Do_Choice_Multi( 'Options for area' area_name, 'req_choice', 'req_status' )
if res ~= 'OK' then return 0
j = 0
do i=1 to choice.0
if bittst( cmds_opt.sel.3, i - 1 ) then
do
j = j + 1;
status.i = req_status.j
end
end
end
end
cfg_ReplyKludges = status.2
cfg_ChooseOpening = status.4
cfg_ChooseSignature = status.6
cfg_ChooseCOD = status.8
cfg_ChooseOrigin = status.9
cfg_NoDomainInOrigin = status.10
call Local_Cfg_SetBit( 'Cmd_Actions', 'Carbon_Copy' , status.1 )
call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_Opening' , status.3 )
call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_Signature', status.5 )
call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_COD' , status.7 )
if status.3 = 'FALSE' then cfg_Opening = ''
if status.5 = 'FALSE' then cfg_Signature = ''
if status.7 = 'FALSE' then cfg_COD = ''
call Local_Cfg_Set( 'Cfg_ReplyKludges' , cfg_ReplyKludges )
call Local_Cfg_Set( 'Cfg_Opening' , cfg_Opening )
call Local_Cfg_Set( 'Cfg_Signature' , cfg_Signature )
call Local_Cfg_Set( 'Cfg_COD' , cfg_COD )
call Local_Cfg_Set( 'Cfg_ChooseOpening' , cfg_ChooseOpening )
call Local_Cfg_Set( 'Cfg_ChooseSignature' , cfg_ChooseSignature )
call Local_Cfg_Set( 'Cfg_ChooseCOD' , cfg_ChooseCOD )
call Local_Cfg_Set( 'Cfg_ChooseOrigin' , cfg_ChooseOrigin )
call Local_Cfg_Set( 'Cfg_NoDomainInOrigin', cfg_NoDomainInOrigin )
end
return sel
Local_Cfg_Set: procedure EXPOSE reply_cfg.
parse arg name , value
old_value = reply_cfg.name
reply_cfg.name = value
return old_value
Local_Cfg_Get: procedure EXPOSE reply_cfg.
parse arg name
return reply_cfg.name
Local_Cfg_SetBit: procedure EXPOSE reply_cfg.
parse arg name , mask , status
if status = 'TRUE' then status = 1
if status = 'FALSE' then status = 0
select
when mask = 'Read_Old_Msg' then bit = 0
when mask = 'Call_Editor' then bit = 1
when mask = 'Insert_Opening' then bit = 2
when mask = 'Insert_Origin' then bit = 3
when mask = 'Insert_Signature' then bit = 4
when mask = 'Insert_COD' then bit = 5
when mask = 'Quote_Text' then bit = 6
when mask = 'Forward_Banner' then bit = 7
when mask = 'Move_Down_HWM' then bit = 8
when mask = 'Carbon_Copy' then bit = 9
when mask = 'Reply_Kludges' then bit = 10
when mask = 'Reduce_Kludges' then bit = 11
when mask = 'Reset_FATT' then bit = 12
when mask = 'Reset_Msg_Number' then bit = 13
otherwise return 0
end
if status = 0 then reply_cfg.name = bitclr( reply_cfg.name, bit )
else reply_cfg.name = bitset( reply_cfg.name, bit )
return 0
Local_Cfg_GetBit: procedure EXPOSE reply_cfg.
parse arg name , mask
select
when mask = 'Read_Old_Msg' then bit = 0
when mask = 'Call_Editor' then bit = 1
when mask = 'Insert_Opening' then bit = 2
when mask = 'Insert_Origin' then bit = 3
when mask = 'Insert_Signature' then bit = 4
when mask = 'Insert_COD' then bit = 5
when mask = 'Quote_Text' then bit = 6
when mask = 'Forward_Banner' then bit = 7
when mask = 'Move_Down_HWM' then bit = 8
when mask = 'Carbon_Copy' then bit = 9
when mask = 'Reply_Kludges' then bit = 10
when mask = 'Reduce_Kludges' then bit = 11
when mask = 'Reset_FATT' then bit = 12
when mask = 'Reset_Msg_Number' then bit = 13
otherwise return 0
end
status = bittst( reply_cfg.name, bit )
if status = 1 then return 'TRUE'
return 'FALSE'
Global_Cfg_Set: procedure
parse arg area_name , field , value
if area_name = '' then return 0
a.0 = 1
a.1 = value
call EMS_CustomCfg_Set( 'DMreply_Cfg', area_name, field, 'a' )
return 0
Global_Cfg_Get: procedure
parse arg area_name , field
if area_name = '' then return ''
call EMS_CustomCfg_Get( 'DMreply_Cfg', area_name, field, 'a' )
if a.0 >= 1 then return a.1
return ''
CalcRandom: procedure
parse arg limit
seed = getclip( 'LAST_RANDOM_SEED' )
last = getclip( 'LAST_RANDOM_VALUE' )
if seed = '' | seed = 0 then seed = Time( 'S' )
if last = '' then last = 0
parse var seed seed '.'
seed = randu( seed )
num = ((seed * limit * 2) // (limit * 2)) % 2
num = ((num + last ) // limit ) + 1
call setclip( 'LAST_RANDOM_SEED' , seed * num / limit * 86400 )
call setclip( 'LAST_RANDOM_VALUE', num )
return num