home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / tm211_1.zip / TOOLBOX3.SCR < prev    next >
Text File  |  1990-05-25  |  10KB  |  328 lines

  1. ;
  2. ; TOOLBOX3.SCR (c) Copyright 1990 by Tsung Hu.  All right reserved.
  3. ; Date written: 10 May 1990
  4. ;
  5. ;
  6. ; This toolbox defines several procedures to access the phone
  7. ; directory and two procedures to calcuate the difference between
  8. ; two date/time strings.
  9. ;
  10. ; To use this toolbox, you should add the line
  11. ;    #include "toolbox3.scr"
  12. ; at the beginning of your script file.  This will increase the file
  13. ; size of the compiled script file .TMS by about 6K.  To minimum the
  14. ; overhead, you should cut and paste the procedures that you used into
  15. ; your script file.  For example, the <DiffTime> and <DiffDate>
  16. ; procedures may be excluded.
  17. ;
  18. ; The <PhoneDirectory> variable tells the Phone's procedures which
  19. ; phone directory is to be access.  Default is the TM.FON.
  20. ;
  21. ; Summary:
  22. ;
  23. ;   PhoneSize size
  24. ;   ; return the number of entries in the phone directory
  25. ;
  26. ;   PhoneFind name,number,startPoint
  27. ;   ; find an entry by <name> and return the entry number in <number>
  28. ;   ; starting from <startPoint>
  29. ;
  30. ;   PhoneRead number,name,password,linkscript,logfile,phone,total,last
  31. ;   ; read the <number>-th entry of <PhoneDirectory>
  32. ;   ; <total> is an integer variable
  33. ;
  34. ;   PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  35. ;   ; write the <number>-th entry of <PhoneDirectory>
  36. ;   ; <total> is an integer
  37. ;
  38. ;   DiffDate date1,date2,days      ; <days> = <date2> - <date1>
  39. ;   DiffTime time1,time2,seconds   ; <seconds> = <time2> - <time1>
  40. ;
  41.  
  42. string PhoneDirectory
  43.  
  44. PhoneDirectory = "TM.FON"     ; phone directory to be accessed by
  45.                               ; the following procedures
  46.  
  47.  
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. ;
  50. ; PhoneSize size
  51. ; function: calcuate the number of entires in the phone directory
  52. ;           <PhoneDirectory>
  53. ;
  54. Procedure PhoneSize integer size
  55. filesize PhoneDirectory,size
  56. size = size / 131             ; each entry is 131 bytes
  57. EndProc
  58.  
  59.  
  60. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;
  62. ; PhoneFind name,number,startPoint
  63. ; function: find an entry by <name> and return the entry number in <number>
  64. ;           starting from <startPoint>
  65. ; remark:   <number> is set to 0 if <name> is not found
  66. ;           <success> is FALSE if the phone directory cannot be open
  67. ;           To find from the beginning of the phone directory, use
  68. ;               PhoneFind name,number,1
  69. ;           To continue the search, use
  70. ;               PhoneFind name,number,number+1
  71. ; caution:  this function will close the formly opened file since the
  72. ;           OPEN command is used.  You should close the file before
  73. ;           issuing this command and reopen the file after this command
  74. ;
  75. Procedure PhoneFind string name,integer number,startPoint
  76. string entry
  77. integer pos,size
  78. PhoneSize size
  79. if startPoint>size            ; no more entries
  80.    number = 0                 ; report as not found
  81.    return
  82. endif
  83. number = startPoint-1
  84. if number<0
  85.    number = 0
  86. endif
  87. pos = 0
  88. open PhoneDirectory
  89. if success
  90.    seek number*131
  91.    While success and pos=0 and number<size
  92.       number = number+1
  93.       read entry                 ; read a phone entry
  94.       if success
  95.          strpos entry,name,pos   ; search for <name>
  96.          if pos>30
  97.             pos = 0              ; not in name field
  98.          endif
  99.       endif
  100.    EndWhile
  101.    close
  102. endif
  103. if pos=0
  104.    number = 0                 ; set <number> to 0 if not found
  105. endif
  106. EndProc
  107.  
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;
  111. ; PhoneRead number,name,password,linkscript,logfile,phone,total,last
  112. ; function: read the <number>-th entry of <PhoneDirectory>
  113. ; remark:   <success> is FALSE if the phone directory cannot be open
  114. ;           tailing spaces in each field are discarded
  115. ;           <total> is an integer variable, the others are string
  116. ;           variables
  117. ; caution:  this function will close the formly opened file since the
  118. ;           OPEN command is used.  You should close the file before
  119. ;           issuing this command and reopen the file after this command
  120. ;
  121. Procedure PhoneRead integer number,string name,password,linkscript,logfile,phone,integer total,string last
  122. string entry,totalstr
  123. integer size
  124.  
  125.    Procedure GetField string field,integer FieldLength,FieldOffset
  126.    integer len,orglen
  127.    string ch
  128.    substr entry,FieldOffset+1,FieldLength,field ; get the field
  129.    len = FieldLength
  130.    orglen = FieldLength       ; delete tailing space
  131.    ch = " "
  132.    While len>0 and ch=" "
  133.       substr field,len,1,ch
  134.       if ch=" "
  135.          len = len-1
  136.       endif
  137.    EndWhile
  138.    if orglen>len
  139.       strdel field,len+1,orglen-len
  140.    endif
  141.    EndProc
  142.  
  143. PhoneSize size
  144. open PhoneDirectory
  145. if success
  146.    if number<1
  147.       seek 0
  148.    elseif number>size
  149.       seek (size-1)*131
  150.    else
  151.       seek (number-1)*131     ; each entry is 131 bytes
  152.    endif
  153.    read entry
  154.    GetField name,30,0
  155.    GetField password,15,30
  156.    GetField linkscript,8,46
  157.    GetField logfile,8,55
  158.    GetField phone,20,64
  159.    GetField totalstr,5,96
  160.    atoi  totalstr,total
  161.    GetField last,8,103
  162.    close
  163. endif
  164. EndProc
  165.  
  166.  
  167. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  168. ;
  169. ; PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  170. ; function: write the <number>-th entry of <PhoneDirectory>
  171. ; remark:   <success> is FALSE if the phone directory cannot be open
  172. ;           <total> is an integer, the others are strings
  173. ;           To change only a field of the entry, you should use the
  174. ;           PhoneRead procedure to read the other fields of the entry,
  175. ;           otherwise, the other fields will be erased.
  176. ; caution:  this function will close the formly opened file since the
  177. ;           OPEN command is used.  You should close the file before
  178. ;           issuing this command and reopen the file after this command
  179. ;
  180. Procedure PhoneWrite integer number,string name,password,linkscript,logfile,phone,integer total,string last
  181. integer EntryPos,size
  182.  
  183.    Procedure WriteField string field,integer FieldLength,FieldOffset,LeftJustify
  184.    integer len
  185.    string space
  186.    seek EntryPos+FieldOffset
  187.    length field,len
  188.    if len>FieldLength
  189.       strdel field,len+1,FieldLength-len
  190.    endif
  191.    if not LeftJustify and len<FieldLength
  192.       strset space," ",1,FieldLength-len
  193.       write space,
  194.    endif
  195.    write field,
  196.    if LeftJustfiy and len<FieldLength
  197.       strset space," ",1,FieldLength-len
  198.       write space,
  199.    endif
  200.    EndProc
  201.  
  202. PhoneSize size
  203. if number<1
  204.    EntryPos = 0
  205. elseif number>size
  206.    EntryPos = (size-1)*131
  207. else
  208.    EntryPos = (number-1)*131
  209. endif
  210. open PhoneDirectory
  211. if success
  212.    WriteField name,30,0,1
  213.    WriteField password,15,30,1
  214.    WriteField linkscript,8,46,1
  215.    WriteField logfile,8,55,1
  216.    WriteField phone,20,64,1
  217.    itoa  total,totalstr
  218.    WriteField totalstr,5,96,0
  219.    WriteField last,8,103,1
  220. endif
  221. close
  222. EndProc
  223.  
  224.  
  225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  226. ;
  227. ; DiffDate date1,date2,days
  228. ; function: calcuate the number of days between <date1> and <date2>
  229. ;           as if <days>=<date2>-<date1>
  230. ; remark:   <date1> and <date2> in MM-DD-YY format
  231. ;           if <date2> is less then <date1>, it is assumed that <date2>
  232. ;           pass a century
  233. ;           <days> is always a non-negative integer
  234. ;
  235. Procedure DiffDate string date1,date2,integer days
  236.  
  237.    ; calcuate the elapsed days from 1st Jan 1800
  238.    Procedure CalcDays string dateStr,integer days
  239.    string yy,mm,dd
  240.    integer y,m,d
  241.    substr dateStr,7,2,yy      ; <dateStr> in MM-DD-YY format
  242.    substr dateStr,1,2,mm
  243.    substr dateStr,4,2,dd
  244.    atoi yy,y
  245.    atoi mm,m
  246.    atoi dd,d
  247.    days = (y+100)*365 + (y+99)/4
  248.    if m>1                     ; January
  249.       days = days + 31
  250.    endif                      ; Febrary
  251.    if m>2
  252.       if y = y/4*4
  253.          days = days + 29
  254.       else
  255.          days = days + 28
  256.       endif
  257.    endif
  258.    if m>3                     ; March
  259.       days = days + 31
  260.    endif
  261.    if m>4                     ; April
  262.       days = days + 30
  263.    endif
  264.    if m>5                     ; May
  265.       days = days + 31
  266.    endif
  267.    if m>6                     ; June
  268.       days = days + 30
  269.    endif
  270.    if m>7                     ; July
  271.       days = days + 31
  272.    endif
  273.    if m>8                     ; August
  274.       days = days + 31
  275.    endif
  276.    if m>9                     ; September
  277.       days = days + 30
  278.    endif
  279.    if m>10                    ; October
  280.       days = days + 31
  281.    endif
  282.    if m>11                    ; November
  283.       days = days + 30
  284.    endif
  285.    days = days + d
  286.    EndProc
  287.  
  288. CalcDays date1,z1             ; calculate elapsed days from 1st Jan 1800
  289. CalcDays date2,z2
  290. days = z2 - z1
  291. if days<0
  292.    days = days + 36500 + 25   ; pass a century
  293. endif
  294. EndProc
  295.  
  296.  
  297. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  298. ;
  299. ; DiffTime time1,time2,seconds
  300. ; function: calcuate the number of seconds between <time1> and <time2>
  301. ;           as if <seconds>=<time2>-<time1>
  302. ; remark:   <time1> and <time2> in HH:MM:SS format
  303. ;           if <time2> is less then <time1>, it is assumed that <time2>
  304. ;           pass mid-night
  305. ;           <seconds> is always a non-negative integer
  306. ;
  307. Procedure DiffTime string time1,time2,integer seconds
  308. integer h1,m1,s1,h2,m2,s2     ; <time1> and <time2> in "HH:MM:SS" format
  309. string hh,mm,ss
  310. substr time1,1,2,hh           ; get hour part
  311. substr time1,4,2,mm           ; get minuate part
  312. substr time1,7,2,ss           ; get second part
  313. atoi hh,h1                    ; convert to integer
  314. atoi mm,m1
  315. atoi ss,s1
  316. substr time2,1,2,hh           ; get hour,minuate and second from <time2>
  317. substr time2,4,2,mm
  318. substr time2,7,2,ss
  319. atoi hh,h2
  320. atoi mm,m2
  321. atoi ss,s2
  322. if h2<h1                      ; <time2> pass mid-night
  323.    h2 = h2 + 24
  324. endif
  325. seconds = (h2-h1)*3600 + (m2-m1)*60 + (s2-s1)
  326. EndProc
  327.  
  328.