home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dongrovs.zip / tz1file.CMD < prev    next >
OS/2 REXX Batch file  |  1996-10-16  |  7KB  |  202 lines

  1. /* ********************************** */
  2. /* OS/2 Rexx Script for MR/2 ICE      */
  3. /* ********************************** */
  4. /*   By: Jetnick Enterprise           */
  5. /*       Don E. Groves, Jr.           */
  6. /*   Contact Information:             */
  7. /*     E-mail: jetnick@erols.com      */
  8. /*        CIS: 71310,3702             */
  9. /* Date: 22 Sep 1996                  */
  10. /* ********************************** */
  11. /* Based very losely on the script    */
  12. /* TZ1.CMD and/or TZ1FIX.CMD          */
  13. /* by William H. Geiger III 07 Apr 96 */
  14. /* Geiger Consulting                  */
  15. /* whgiii@amaranth.com                */
  16. /* this script will convert the Date: stamp in the header of messages */
  17. /* ********************************** */
  18.  
  19. parse source . invhow .
  20. if invhow == 'COMMAND'
  21. THEN DO
  22.    /* elsp_counter = .Elasp_Time~NEW */
  23.    Argv = .ARRAY_CLI~of(ARG(1), .false, .false) /* parse the arguments */
  24.    if Argv~items > 0
  25.    THEN DO
  26.       file_name = Argv[1]     /* get filename */
  27.       if Argv~items > 1
  28.       THEN fix = Argv[2]
  29.       else fix = ''
  30.       if fix=='fix'
  31.       then worker = .FixTimeZone~new
  32.       else worker = .DoTimeZone~new
  33.       hDate = worker~work(file_name)
  34.       /* say 'hDate=' hDate */
  35.       /* IF hDate \= .nil */
  36.       /* THEN say 'record str=['~''(hDate~DATE('O')~' '(hDate~TIME('N')~SUBSTR(1,5)))~''(']') */
  37.    end
  38.    else DO
  39.       /* future message concerning Commandline arguments goes here */
  40.    END
  41.    /* say elsp_counter */
  42. end
  43. return 0
  44.  
  45. ::requires Array_Cli
  46. ::requires MyTimeZone
  47. ::requires TextStream
  48.  
  49. ::class AdjustTimeStamp
  50. ::method init
  51. return self
  52.   /* field names we are interested in the header of RCV file */
  53. ::method OldTimeField private
  54. return 'Old-TimeStamp:'
  55. ::method DateField private
  56. return 'Date:'
  57. ::method work
  58.   use arg filename
  59.   IF FileName~RIGHT(4)~TRANSLATE \== '.OUT'
  60.   THEN DO
  61.      msg_file = .RcvTextStream~new(filename)
  62.      IF msg_file~exist
  63.      THEN do
  64.         fileSize = msg_file~SIZE         /* this is line 59. */
  65.         IF fileSize \= .nil              /* Whatever limit in bytes your */
  66.         THEN IF fileSize <= 65536        /* break off point is. */
  67.         THEN forward message 'work_org' ARRAY (msg_file)
  68.      END
  69.   END
  70.   /* skip .OUT files there correct already */
  71. return .nil                        /* returns a DateTime object or .nil */
  72. ::method work_org private   /* This isn't required but complete */
  73.   use arg msg_file          /* the documentation of the class. */
  74.   NOP  /* this is required to be OverRidden */
  75.   /* returns a DateTime object or .nil */
  76.  
  77. ::CLASS DoTimeZone subclass AdjustTimeStamp public
  78. ::method work_org private
  79.   use arg msg_file
  80.   /* Convert date field of *.RCV file to Local Time */
  81.   /* returns DateTime object equal to new adjusted DateTime on success. */
  82.  
  83.   /* say 'DoTimeZone for=' msg_file~Qualify */
  84.  
  85.   /* Load the file into a list. */
  86.   msg_File~OPEN('READ')
  87.   msg_list = msg_file~MakeList
  88.   msg_File~Close
  89.  
  90.   NewDate    = .nil  /* new data for 'Date:' field */
  91.   dt_no      = .nil  /* location of 'Date:' information */ 
  92.   hDate      = .nil  /* DateTime object to return to user */
  93.   oTimeStamp = .nil  /* non .nil if 'Old-TimeStamp:' was found */
  94.   OldDate    = .nil  /* save Date to place in 'Old-TimeStamp:' field */
  95.   su         = msg_list~supplier
  96.   do while su~available      /* find field(s) from file header */
  97.      select
  98.        when su~item~strip~length = 0
  99.        then LEAVE  /* Leave the loop when the end of header area is reached */
  100.        when su~item~pos(self~DateField,1) = 1
  101.        THEN DO
  102.           IF hdate = .nil
  103.           THEN if su~item~words > 5
  104.           THEN DO
  105.              dt    = su~item~SUBSTR(self~DateField~length + 1)~strip('L')
  106.              hDate = ParseDateStr( dt )
  107.              if hdate \= .nil
  108.              THEN DO
  109.                 dt_no   = su~index
  110.                 OldDate = self~OldTimeField~' '(dt)
  111.                 hDate   = hDate~MakeLocalTimeStamp /* convert to local ref. */
  112.                 NewDate = self~DateField~' '(hDate)
  113.              END
  114.           END
  115.        END
  116.        when su~item~pos(self~OldTimeField,1) = 1
  117.        THEN DO
  118.           oTimeStamp = su~index
  119.           IF hDate \= .nil
  120.           THEN leave /* leave search loop early if all information is found */
  121.        END
  122.        OTHERWISE nop  /* other header fields I don't care about */
  123.      END
  124.      su~next
  125.   end
  126.   drop su
  127.   /* Was the required Date field found and Old-TimeStamp not found */
  128.   if dt_no \= .nil & oTimeStamp = .nil & hDate \= .nil
  129.   THEN DO
  130.      msg_list[dt_no] = NewDate       /* Replace 'Date:' with new data */
  131.      msg_list~insert(oldDate,dt_no)  /* add the 'Old-Timestamp:' field */
  132.      msg_file~OPEN('WRITE REPLACE')
  133.      msg_file~WriteList(msg_list)    /* Write out the new information */
  134.      msg_File~Close
  135.   END
  136. return hDate     /* Tell caller new adjusted dateTime. */
  137.  
  138. ::CLASS FixTimeZone subclass AdjustTimeStamp public
  139. ::method work_org private
  140.   use arg msg_file
  141.   /* Restore date field of *.RCV file to Old-TimeStamp */
  142.   /* returns DateTime object equal to Old-Time on sucess. */
  143.  
  144.   msg_File~OPEN('READ')
  145.   msg_list = msg_file~MakeList
  146.   msg_File~Close
  147.   yyfix     = 'Fixed:'
  148.   xxfix1    = .nil  /* line to remove if yyfix is found */
  149.   old_dt_no = .nil  /* location of 'Old-TimeStamp:' information */
  150.   dt_no     = .nil  /* location of 'Date:' information */ 
  151.   NewDate   = .nil  /* new data for 'Date:' field */
  152.   hDate     = .nil  /* DateTime object to return to user */
  153.   su        = msg_list~supplier
  154.   do while su~available      /* find info from file header */
  155.      select
  156.        when su~item~length = 0
  157.        then LEAVE  /* Leave when end of header area is reached */
  158.        When su~item~pos(yyfix,1) = 1
  159.        then xxfix1= su~index
  160.        When su~item~pos(self~OldTimeField,1) = 1
  161.        then do
  162.           IF hdate = .nil
  163.           THEN if su~item~words > 5
  164.           THEN DO
  165.              dt    = su~item~SUBSTR(self~OldTimeField~length + 1)~strip('L')
  166.              hDate = ParseDateStr( dt )  /* Parse the Date String */
  167.              NewDate   = self~DateField~' '(dt)
  168.              old_dt_no = su~index
  169.              if dt_no \= .nil
  170.              THEN LEAVE  /* Leave when all the information is found */
  171.           END
  172.        end
  173.        when su~item~pos(self~DateField,1) = 1
  174.        THEN do
  175.           IF dt_no = .nil
  176.           then dt_no = su~index
  177.        end
  178.        OTHERWISE nop  /* other header fields I don't care about */
  179.      end
  180.      su~next
  181.   end
  182.   drop su
  183.   /* Where all the required fields found. */
  184.   if old_dt_no \= .nil & dt_no \= .nil
  185.   THEN DO
  186.      IF xxfix1 \= .nil
  187.      THEN msg_list~REMOVE(xxfix1) /* remove 'Fixed:' line */
  188.      msg_list~REMOVE(old_dt_no)   /* remove 'Old-TimeStamp:' line */
  189.      msg_list[dt_no] = NewDate    /* restore the old date */
  190.      msg_file~OPEN('WRITE REPLACE')
  191.      msg_file~WriteList(msg_list) /* Write out the new information */
  192.      msg_File~Close
  193.   END
  194. return hDate     /* Tell caller new dateTime if Old-TimeStamp was found. */
  195.  
  196. /* ********************************* */
  197. /* ********************************* */
  198. ::ROUTINE Dummy
  199. RETURN
  200. /* ********************************* */
  201. /* ********************************* */
  202.