/* ResizeHistory
**
** Author: Glenn J. Schworak
**   Date: 11/10/96
**
** This script will allow you to change the size of your history review
** buffer without losing any data that may be in the buffer.
**
** Of course, if you are making the buffer smaller, some data may be lost
** if it simply won't fit.
**
** The only side effect is that all the calls show up as if they came in
** at the time/date you run this script.
**
** It simply isn't practical to be writing the time/date back to the history
** as test data. And we are using what was intended as a testing function to
** pull this stunt off. And since this is not a script that will really be
** much, there was no point to support this in any other way.
*/

options results

address CID

GetVal 3; HistCount = Result    /* Get the current size of the History buffer */


say 'There are currently 'HistCount
say 'records in the history buffer.'
say ''
say ''
say 'What would you like the new size to be?'
pull NewSize

if datatype(NewSize,'Numeric') then do
 if NewSize>3 then do
 
  if NewSize<HistCount then do            /* Trim the buffer if we need room */
   Trim
   GetVal 3; HistCount = Result
  end

  BuildScratch ; Scratch = Result         /* Build a scratch pad in memory   */

  say ''
  say ''
  say 'Reading the existing history file...'
  do x=1 to HistCount
   GetHist x Scratch                      /* Read the history record         */
   GetVal 10 Scratch; Phone.x = Result
	GetVal 11 Scratch; Name.x  = Result
	if strip(Phone.x)='' then Phone.x='Out Of Area'
   say right(x,4)'.  'left(Phone.x,20)'  'Name.x
  end
  
  say ''
  say ''
  say 'Changing the history size...'
  shell command 'echo >>s:CallerID.cfg "HISTORY = 'NewSize'"'
  shell command 'echo >>s:CallerID.cfg "AutoSave"'
  LoadCFG

  say ''
  say ''
  say 'Building the new list...'
  if NewSize<HistCount then HistCount=NewSize   /* Toss any overflow entries */
  do x=HistCount to 1 by -1
   SimCall NoActions '"'Phone.x'"' Name.x
  end
  
  say ''
  say ''
  say 'All Done!'

 end; else do
  say "Don't be a dork. You can't have a history of less than 3."
 end
end


exit



ERROR:
say 'OOPS! Error...'
exit