home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / icetag26.zip / icetag26.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-22  |  6KB  |  197 lines

  1. /* REXX script to read icequote files */
  2. /* and attach them to PMMail e-mails  */
  3. /* (c) 1997 Ahmad Al-Nusif            */
  4. /*          morpheus@moc.kw           */
  5. /*               ___        _____              ______           */
  6. /*              |_ _|___ __|_   _|_ _  __ _   / /___ \          */
  7. /*               | |/ __/ _ \| |/ _` |/ _` | / /  __) |         */
  8. /*               | | (_|  __/| | (_| | (_| |/ /  / __/          */
  9. /*              |___\___\___||_|\__,_|\__, /_/  |_____|         */
  10. /*                                    |___/                     */
  11. /*                                                      V 2.6   */
  12. /*--------------------------------------------------------------*/
  13.  
  14. /*               _   _               ___      _                 */
  15. /*              | | | |___ ___ _ _  / __| ___| |_ _  _ _ __     */
  16. /*              | |_| (_-</ -_) '_| \__ \/ -_)  _| || | '_ \    */
  17. /*               \___//__/\___|_|   |___/\___|\__|\_,_| .__/    */
  18. /*                                                    |_|       */
  19.  
  20.  
  21. /* Do you want to confirm each quote before it is applied to an
  22.    outgoing e-mail? (0=NO - 1=Yes)                              */
  23.  
  24. Confirm=0
  25.  
  26. /* Do you want a string inserted before each quote?             */
  27. /* (0=NO - 1=Yes)                                               */
  28.  
  29. insert_prefix=0
  30.  
  31. /* If you want a prefix other than the one below, change the
  32.    value between the quotes.                                    */
  33.  
  34. prefix="... "
  35.  
  36. /* Do you want a newline inserted before the quote?             */
  37. /* (0=NO - 1=Yes)                                               */
  38.  
  39. insert_newline=0
  40.  
  41. /* Do you want to replace the X-Mailer line in your header?     */
  42. /* (0=NO - 1=Yes)                                               */
  43.  
  44. replace_xmailer=0
  45.  
  46. /* If answered YES to the above question then you can change the
  47.    change the value below to something you prefer to replace the
  48.    X-Mailer line with. Leaving nothing between the quotes removes
  49.    the X-Mailer line completely.                                */
  50.  
  51. new_XMailer=""
  52.  
  53. /*--------------------------------------------------------------*/
  54. /* End of User Setup section                                    */
  55. /* Please don't change anything below this line                 */
  56.  
  57. Parse Arg destfile
  58.  
  59.  
  60. tempfile = left( destfile, length( destfile ) - 4)
  61.  
  62.  
  63. i=1
  64.  
  65. do while lines( destfile ) > 0
  66.    line = linein( destfile )
  67.    if word( line, 1 ) = 'X-Mailer:' then
  68.      do
  69.         if \ replace_xmailer then
  70.            do
  71.                 rc=lineout(tempfile, line);
  72.                 if i then do
  73.                   rc=lineout(tempfile, 'X-Tag: <| IceTag/2 v2.6 |> by Ahmad Al-Nusif (morpheus@moc.kw)')
  74.                   end /* if i */
  75.                 i=0
  76.            end /* if \ replace */
  77.         if replace_xmailer then
  78.            do
  79.                 if new_xmailer\= "" then rc=lineout(tempfile,new_XMailer)
  80.                 if i then do
  81.                    rc=lineout(tempfile, 'X-Tag: <| IceTag/2 v2.6 |> by Ahmad Al-Nusif (morpheus@moc.kw)')
  82.                    end /* if i */
  83.                 i=0
  84.            end /* if replace */
  85.         end /* if word */
  86.    else rc=lineout(tempfile,line)
  87. end
  88.  
  89. rc=stream(destfile, 'c', 'close')
  90. rc=stream(tempfile, 'c', 'close')
  91.  
  92. '@copy' tempfile destfile '>nul'
  93. '@del' tempfile '>nul'
  94.  
  95. /* if the file you're using is different, change the name below */
  96. File='pqf4.quo'
  97. Index="pqf4.idx"
  98.  
  99. call rxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  100. call sysloadfuncs
  101.  
  102.  
  103. call ReadIndex
  104.  
  105. Main:
  106. pick = RANDOM(1, nq2)   /* choose a random quote */
  107. pick2=(pick*2)-1        /* calc stem index of starting line */
  108. mark=quotes.pick2 +1    /* get line number in the quote file */
  109. pick3=pick*2            /* calc stem index of the length (in lines) of the quote */
  110. count=quotes.pick3      /* get the number of lines of the quote */
  111.  
  112. /* advance to the desired position in a file by reading all the rest */
  113. /* which was my intention to do without from the start */
  114. /* but I couldn't find a REXX function that takes as an argument */
  115. /* a line number and number of lines to return them in a stem */
  116.  
  117.  
  118. rc=stream(destfile,'c','open write')
  119. rc=stream(file,'c','open read')
  120. rc=stream(file,'c','seek ='mark)
  121.  
  122. dummy="             "
  123.  
  124. if insert_newline then rc=lineout(destfile,dummy);
  125.  
  126.  
  127. i=0
  128. do while count\='0'
  129.    tmp=linein(file)
  130.    count=count-1
  131.    i=i+1        /* i is the index of the stem that holds the quote lines */
  132.    if count='0' then do
  133.       test=pos('#',tmp)
  134.       tmpline2=left(tmp,test-1)
  135.       tmp=tmpline2
  136.       end
  137.    quotelines.0=i
  138.    quotelines.i=tmp
  139. end
  140.  
  141. rc=stream(file,'c','close')
  142.  
  143. i=0
  144.  
  145.  
  146.  
  147. if \ confirm then do
  148.         if insert_prefix then rc=charout(destfile,prefix);
  149.         do quotelines.0
  150.                 i=i+1
  151.                 rc=lineout(destfile,quotelines.i)
  152.                 end
  153. end /* if */
  154.  
  155. if confirm then do
  156. say ""
  157. i=0
  158. if insert_prefix then rc=charout(,prefix)
  159. do quotelines.0
  160.         i=i+1
  161.         say quotelines.i
  162.         end
  163. say ""
  164. Say "Do you feel that this quote is appropriate (Y/N) ?"
  165. parse upper pull response
  166.  
  167. select
  168.         when (response='Y' | response='YES') then do
  169.                 i=0
  170.                 if insert_prefix then rc=charout(destfile,prefix);
  171.                 do quotelines.0
  172.                         i=i+1
  173.                         rc=lineout(destfile,quotelines.i)
  174.                         end
  175.                 end
  176.         when (response='N' | response='NO') then do
  177.                 say
  178.                 say "Choosing another quote..."
  179.                 say
  180.                 call Main
  181.                 leave
  182.                 end
  183. end /* select */
  184. end /* if confirm */
  185.  
  186. exit
  187.  
  188. ReadIndex:
  189.           nq=0  /* The number of quotes x2 */
  190.           do while lines(index)>0
  191.              nq=nq+1
  192.              quotes.0=nq
  193.              quotes.nq=linein(index)
  194.            end
  195.            nq2=(nq)/2
  196. return
  197.