Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

%Touch.r and Touch Dialect

 [1/2] from: Al:Bri:xtra at: 10-Jun-2003 21:30

Here's my %Touch.r along with an example of it's Touch dialect: Note that it's set for my prefered method of indenting blocks (it doesn't work well on Rebol HQ headers). Just call me prejudiced. :) If people want to, feel free to make this user adjustable and better. And feel free to expland the dialect as well. [ Rebol [ Name: 'Touch Title: "Touch" File: %Touch.r Author: "A J Martin" Owner: "Aztecnology" Rights: "Copyright 2003 A J Martin, Aztecnology." eMail: [Al--Bri--xtra--co--nz] Web: Tabs: 4 Purpose: "Implements a Rebol script specific Touch program." Language: 'English Date: 10/June/2003 Version: 1.0.4 Example: { foreach File recursive-read Folder: %/C/Rebol/ [ Touch Folder/:File compose [ [ Name Title File Author Owner Rights eMail Web ] Version + 0.0.1 Author: "A J Martin" eMail: (Rebol/script/header/eMail) Web: (Rebol/script/header/Web) Owner: "Aztecnology" Tabs: 4 Rights: "Copyright 2003 A J Martin, Aztecnology." Language: 'English Date: (now/date) Language: 'English [ Date Version ] ] ] } ] Touch: function [ File [file!] Dialect [block!] ] [Script Header Firsts Word Value Increment Lasts New_Header Header_Value] [ if all [ %.r = extension? File attempt [ Script: load/header File ] Header: first Script object? Header ] [ Header: make Rebol/script/header Header if word? Header/Name [ Header/Name: to lit-word! Header/Name ] parse Dialect [ opt [set Firsts into [any word!]] any [ [ set Word set-word! set Value any-type! ( Word: to word! :Word either found? find first Header Word [ set in Header Word :Value ] [ Header: make Header compose [ (to set-word! Word) (:Value) ] ] ) ] | [ 'Version '+ set Increment tuple! ( Header/Version: Increment + any [Header/Version 1.0.0] ) ] ] opt [set Lasts into [any word!]] end ] Script: read File New_Header: make string! 1000 Header_Value: [ if Value: get in Header Word [ switch/default type?/word Value [ string! [ Value: mold Value replace/all Value "^^-" tab ] word! [ Value: mold :Value ] date! [ Value: rejoin [ Value/3 #"/" pick Rebol/Locale/Months Value/2 #"/" Value/1 ] ] ] [ Value: mold :Value ] insert tail New_Header rejoin [ tab mold to set-word! Word #" " Value newline ] ] ] foreach Word Firsts Header_Value foreach Word exclude exclude next first Header Firsts Lasts Header_Value foreach Word Lasts Header_Value change/part find/tail Script "Rebol [^/" New_Header next find Script ^/^-]^/ write File Script ] ] ] Note that %Touch.r uses a common block value for the three 'foreach near the end. It's a cheaper way of doing Map! :) This took three hours to write, including this email! :) Andrew J Martin ICQ: 26227169

 [2/2] from: greggirwin::mindspring::com at: 10-Jun-2003 11:15

Hi Andrew, Neat idea! Here's a litle TOUCH function I wrote some time ago that could be used in conjunction with your dialect. touch: func [ {Set the modification timestamp of the file.} files [file! block!] "The file, or files, you want to stamp" /with "Use a specified time rather than the current time." time [date!] "The date and time to stamp them with" /local rd-only ][ if not with [time: now] ; We have to turn off the read-only attribute if it's on. foreach item compose [(files)] [ rd-only: not get-modes item 'owner-write set-modes to-file item [owner-write: true modification-date: time] if rd-only [set-modes item [owner-write: false]] ] ; Should we return the time, even though it may not match the actual ; stamp on the files due to OS differences? ;time ] -- Gregg