home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / crsh-010.zip / readme.txt < prev   
Text File  |  1998-12-07  |  20KB  |  395 lines

  1. Make Shadow Objects of recently used documents
  2.  
  3.  
  4. Jan Stozek
  5. jasio@polbox.pl
  6.  
  7.  
  8. Have you ever envied the glassworkers (as Windows users are often called in
  9. Poland), that they have direct access to the 15 most recently used
  10. documents in the Start/Documents menu?  Well, I have.  So I wrote a set of
  11. scripts to provide me with simillar functionality.  Please note, this is
  12. _not_ a fully blown, automagic, GUI, self configuring, blinking and shining
  13. solution.  Actually, it's not even a program.  It is rather an idea
  14. accompanied by a tool and a few examples of its usage.  I made it as a
  15. quick and dirty hack.  Since there is a non-zero probability that it might
  16. be useful to someone else as well, I decided to distribute it.  So it's
  17. definitely not fool-proof, actually it does not even check if all
  18. parametres are correct.  Additionally, it will require some additional work
  19. from you to adapt it to your particular configuration.  So, please, read
  20. this readme thoroughly before running anything.  I know it's difficult and
  21. boring.  I don't do it myself most of the time, unless something does not
  22. work.  But please do, since most probably it _won't_ (WON'T!!!!  WON'T!!!!
  23. WON'T!!!!)  work with your configuration right away.
  24.  
  25.  
  26. 0. Language Disclaimer
  27.  
  28. Although I made some efforts, that this readme file is written correctly,
  29. and understandable, it's more than probable I made some - possibly many -
  30. mistakes.  Please, excuse me if so.  English is not my native language and
  31. it may happen, that the way I use it is disgusting for native speakers.
  32.  
  33.  
  34. 1. Legal stuff
  35.  
  36. Unless stated otherwise in specific cases, all pieces of code included in
  37. the archive, wheather signed or not, have been written by me (Jan Stozek)
  38. and are distributed under GNU Licence version 2, cited in a file named
  39. "License".  The scripts are free for personal (home) and educational
  40. (schools and universities of all types, _excluding_ commercial services
  41. provided by them for third parties, such as industry) use, yet copyrighted.
  42. All other users should contact with author before using on a regular basis.
  43.  
  44. The scripts are provided "as is", without any warranty, expressed or
  45. implied.  I explicitly refuse to take any responsibilities for any results
  46. - weather direct or indirect - resulting from executing them.  To make long
  47. thing short:  whatever you do with those scripts - execute, rewrite or
  48. trash - you and only you are responsible for the results.
  49.  
  50.  
  51. 2. Contents:
  52.  
  53.     fileid.diz    - obvious; short program description
  54.     License        - obvious; GNU License version 2
  55.     FindLatest.cmd    - 4OS2 script finding 15 latest files in directory trees given as parametres
  56.     MakeLast20.cmd    - usage example: make shadows of 20 recently created files
  57.     MakeShadow.cmd    - main workhorse in REXX
  58.     MakeTodays.cmd    - usage example: make shadows of up to 50 files created
  59.                           today (and, actually, yesterday)
  60.     readme.txt      - this file
  61.  
  62.  
  63. 3. Prerequisits
  64.  
  65. MakeShadow requires OS/2 with Rexx support enabled.  I use it
  66. with Warp 4 PL, but it should work with any other version as well,
  67. unless there have been changes in Rexx influencing functions or structures
  68. used in the script.
  69.  
  70. FindLatest, MakeLast20 and MakeTodays require 4OS2 command processor by JP
  71. Software.  If you don't and don't want to use 4OS2, you can treat them as a
  72. brief, demonstration of its capabilities and a source of inspiration. Since
  73. their job is to feed MakeShadow, you can replace them with any other
  74. scripting tools of your choice, such as Rexx or Perl, or even a high level
  75. language program.  Actually, if someone makes a working Rexx replacement
  76. for those files, I will be happy to include them in the archive.
  77.  
  78. Finally, FindLatest.cmd currently uses qsort, plain old DOS sorting
  79. program.  This is because OS/2 SORT.EXE has a completely idiotic and
  80. anachronic size limit of 64K per sorted file.  I noticed two OS/2 native
  81. programs of this kind on Hobbes (bigsrt44.zip and jsort13.zip), but since I
  82. have not used them yet, I didn't want to make dummy calls to them.  This
  83. should not be a problem, though, since most probably you will have to write
  84. your own control scripts anyway.
  85.  
  86.  
  87. 4. Installation
  88.  
  89. There is no specific installation automation routine. Installation consists
  90. of four steps.
  91.  
  92.         a) copy all necessary files to a directory located in the path
  93.         b) tailor the scripts (FindLatest, MakeLatest20 and MakeTodays) to
  94.            your needs
  95.         c) create necessary target directories
  96.         d) create objects for running batch files, if needed
  97.  
  98.  
  99. 5. How does it work
  100.  
  101. The main powerhorse is MakeShadow.cmd.  It accepts three parameters:  fully
  102. qualified name of the file you want to make shadow of (and /B or /S, which
  103. is explained in detailes later on), the fully qualified name of the
  104. directory you want the shadow object to be put in and the shadow object ID.
  105. Theory says, you should be able to supply the respective object IDs instead
  106. of their names, but this has not been tested.  One thing is for sure -
  107. if you try, you have to quote angle brackets in the object IDs, since
  108. they are interpreted as redirectors by the shell.  The script returns exit
  109. code equal to the number of objects succesfully created (or 0 if for any
  110. reason no objects have been created, which seems to be quite logical).  Be
  111. aware, that shadow object IDs - as object IDs - are system wide, not
  112. directory wide.  This means, it may happen, by creating shadows in one
  113. folder, you can actually delete something - not necessarily a shadow - in
  114. another folder.  So please, be _very_ _very_ _very_ careful in selecting
  115. object names and make sure they are unique.
  116.  
  117. The script has three main modes of operation:  regular, batch and script,
  118. distinguished by the first parameter. If it is a filename, script is run in
  119. regular mode, /B means the batch mode and /S - the script processing mode.
  120.  
  121.  
  122. Regular mode
  123.  
  124. In the regular mode the script creates a shadow of a single file, given by
  125. the first parameter, in a directory given as the second parameter, using an
  126. object ID provided as optional third parameter.  Both file name and
  127. directory name should be fully qualified.  Watch out, the shadow object ID
  128. passed as the third parameter MUST NOT contain angle brackets.  They are
  129. appended internally, within the script.
  130.  
  131. The script tries to process two special cases, regarding file and directory
  132. names:  filename without a path is treated as located in the current
  133. directory and a target directory name beginning with a dot (including the
  134. dot alone) is treated as a relative to the current directory.  This is
  135. regular system convention.  No further name processing is done though -
  136. MakeShadow was meant to be called from other scripts or programs rather
  137. than from the command line, and then it's pretty easy to provide fully
  138. qualified file names.
  139.  
  140. If no object ID is given, the default value is used, equal to the fully
  141. qualified file name.  MakeShadow never makes an object with a random ID,
  142. which is the system default.  This way you can easily delete the shadow
  143. with another script or identify it with object managers, although - as a
  144. side effect - you cannot create two shadows of the same file without
  145. specifying object ID (you can do it in batch and script modes, when object
  146. ID is processed differently).  Please note, object ID is an internal
  147. object name, used by the Presentation Manager for managing objects.  This
  148. is _not_ the name you see on the desktop.  In case of shadows, the latter
  149. is _always_ the same as the title (equal to filename in case of files) of
  150. the object pointed to by the shadow.
  151.  
  152. So:
  153.  
  154. MakeShadow C:\Autoexec.bat C:\Desktop Test
  155.  
  156. will create a shadow of the C:\Autoexec.bat in the directory C:\Desktop
  157. (which in English OS/2 versions is a desktop directory) with the internal
  158. object ID 'Test'.  While:
  159.  
  160. MakeShadow C:\Autoexec.bat C:\Desktop
  161.  
  162. will do the same, but the internal object ID will be 'C:\Autoexec.bat'.
  163.  
  164.  
  165. Batch mode
  166.  
  167. Batch mode is recognised by the /B switch used as the first parameter, in
  168. place of the file name.  In this mode names of files you want to make
  169. shadows of are read from standard input, one in a row.  There is also a
  170. significant change in a way object ID is interpreted.  It does not mean
  171. actual object ID any more, but a "root" ID instead.  The actual ID for each
  172. object is computed by appending an object number within the batch to the
  173. "root" name.  The second change is that the default "root" object ID equals
  174. to the target directory name (just the name, no path) rather than the path.
  175. So:
  176.  
  177. dir /f C:\ | MakeShadow /B C:\Desktop Root
  178.  
  179. will make shadows of all non-hidden files and directories placed in the
  180. root directory of C:  drive (usually autoexec.bat, config.sys, readme.os2,
  181. several config.sys backups, popuplog) in the C:\Temp folder.  Newly created
  182. objects will have the names of Root1, Root2, Root3 etc.  While:
  183.  
  184. dir /f C:\ | MakeShadow /B C:\Desktop
  185.  
  186. does the same, but shadows will have IDs Desktop1, Desktop2, Desktop3 etc.
  187. Please note, whole C:  drive will not be scanned.  Rather whole directories
  188. (with C:\Desktop included) will have their shadows created on desktop.  If
  189. you want to make shadows of all the files on the C:  drive you should feed
  190. MakeShadow with "dir /f /s".  This would end up with a big mess though,
  191. since all the files on the C:  drive would have their shadows placed flat
  192. on desktop, along with the shadows of all directories and subdirectories.
  193. Also, since Presentation Manager has not been optimised for batch object
  194. creation, you may have to wait until the Judgment Day until the command has
  195. completed.
  196.  
  197.  
  198. Script processing mode
  199.  
  200. Script processing mode is recognised by the /S switch as the first
  201. parameter.  It is similar to the batch mode, but the data read from stdin
  202. are treated as a sequence of commands rather than file names by themselves.
  203. Both target directory and object ID should be defined by the script
  204. commands.  Please note, although object ID still defaults to something
  205. usable, target directory name must be defined explicitly.
  206.  
  207. MakeShadow recognises following script commands:
  208.  
  209. #               - every line with # as the first character is treated as a
  210.                   comment
  211.  
  212. CD dirname      - defines the target directory name.  Please note, this
  213. does not change the process current directory (in the OS terms), just
  214. defines the name for the target directory.  This is exact equivalent of the
  215. second MakeShadow command line parameter in other modes.  It can be
  216. redefined multiple times - each name is valid until another CD command.
  217.  
  218. Please note, target directory is mandatory for DATA command, while it's not
  219. required at all by the DEL command.
  220.  
  221. ROOTNAME name   - defines the root shadow object ID.  This is exact
  222. equivalent of the third MakeShadow command line parameter in other modes.
  223. It can be redefined multiple times within the script.  Each name is valid
  224. until redefined.
  225.  
  226. DEL param       - deletes objects.  Please note, this is potentially
  227. dangerous command, since you can delete _any_ object in the system.
  228. Please, do it with care.  Please also note, DEL deletes objects by their
  229. objects IDs, not by the file names.  This means, neither current nor target
  230. directory influence this command.  Param defines object(s) to be deleted,
  231. in the following way:
  232.  
  233. * <object_name>                 - named object is deleted
  234. (including angle brackets!)
  235.  
  236. * number (for example 10)       - ROOTNAMEnumber (ROOTNAME10 in this case)
  237.                                   object is deleted
  238.  
  239. * number+ (f.e. 10+)            - ROOTNAMEnumber (f.e. ROOTNAME10) is
  240.                                   deleted, then the number is incremented
  241.                                   in a loop and consecutive objects are
  242.                                   deleted (ROOTNAME11, ROOTNAME12...),
  243.                                   until failure.  So, if you have
  244.                                   objects 1,2,3,4,5,10 and issue DEL 3+,
  245.                                   objects 3, 4 and 5 will be deleted.
  246.                                   Object 10 will be preserved, because DEL
  247.                                   6 fails.
  248.  
  249. * number + (f.e. 10 +)          - same as the above
  250.  
  251. * ALL                           - ROOTNAME object is deleted, followed by
  252.                                   DEL 1+. This may end up with the target
  253.                                   directory deletion (if its object ID is
  254.                                   equal to the ROOTNAME), so use it with
  255.                                   care.
  256.  
  257. * number1 number2               - all objects with numbers between
  258. (f.e.  5 1000000)                 number1 and number2 inclusive are deleted
  259.                                   (ROOTNAME5, ROOTNAME6 ...
  260.                                   ROOTNAME1000000).  No error codes are
  261.                                   checked, so it won't stop on
  262.                                   nonexistant objects. This way you
  263.                                   can remove remainings after failed tests
  264.                                   or make sure no spare objects are left.
  265.  
  266. DATA            - triggers object creation. This command is potentially
  267. dangerous, since objects with conflicting names are silently replaced. This
  268. should not mess up any system objects, since they usually do not contain
  269. trailing digits, but may clear up shadows created earlier, even in
  270. different directories.
  271.  
  272. All the following lines in the script contain names of the files you want
  273. to have shadows of, one at a time.  Actually, this is equivalent to the
  274. batch mode (and is even processed by the same code), with some values
  275. predefined by the preciding script commands. File names are read until the
  276. end of the file or a single dot character is encountered. In the latter
  277. case MakeShadow returns to command processing, so that you can define new
  278. target and rootname and create or delete some more objects.
  279.  
  280. After every DATA command, object counter is always reset to 1, with two
  281. side effects:  if you define a ROOTNAME already used, you may replace some
  282. shadows just created with new ones - even, if they have been created in
  283. another folder - probably with different logic in mind.  Also, exit code
  284. informs only about the number of the shadow objects resulting from the
  285. last DATA command only.  This may be changed in future versions though.
  286.  
  287. . (dot)         - end of DATA and return to command processing
  288.  
  289. QUIT            - terminate MakeShadow immediately.  Since there is no
  290. conditional logic implemented, this simply means, the following part of the
  291. script will not be processed.  I included it purely to ease debugging.
  292. Please note, QUIT is only recognised in the command state.  If you want to
  293. terminate object creation (DATA command) prematurely, you should issue a
  294. dot (.)  command to return to command processing state first.
  295.  
  296. That's all. As you see - no real magic.
  297.  
  298.  
  299. 6. What does it work for
  300.  
  301. As you might see from the above, MakeShadow is not especially clever by
  302. itself.  It does not make much more than creating shadows of the files
  303. given as parametres or piped to its stdin.  The real inteligence and
  304. usefulness is included in a way MakeShadow data is created.  Using
  305. MakeShadow I mimicked Start/Documents functionality in two ways:  finding
  306. 15 documents most recently updated and finding up to 50 documents updated
  307. today or yesterday.  You can mimic some functionality of the Toronto
  308. Virtual File System, creating shadows of selected directory trees on
  309. different drives in a common directory (will work pretty well, unless you
  310. need virtuality on a file system level rather than on WPS level).  You can
  311. write a better file finder.  You can...  eh!  you can write almost
  312. anything, as long as you can output a list of fully qualified file names,
  313. matching certain conditions.
  314.  
  315. I included a couple of scripts as a kind of demonstration.  They require JP
  316. Software's 4OS2 command processor to run (this is an enhancement and
  317. replacement of CMD, compatible with 4DOS and 4NT command processors for
  318. other OS-es).  You can implement those same ideas in a scripting language
  319. of your choice.  I decided not to do it for you for two reasons:  CMD is
  320. too poor for these tasks, I cannot bet, everybody is using Perl, while I
  321. don't feel good enough in Rexx to use it for the file system tasks.
  322. Besides, these scripts work for me, with my particular set of directories,
  323. while you would have to modify them heavily anyway, to accomodate to your
  324. configuration and needs.
  325.  
  326. a) FindLatest.  This is a simple script printing %FileLimit% (default = 15)
  327. recently used files in directories (actually - filemasks) given as
  328. parametres.  %Filelimit% variable should have already been defined in the
  329. environment, if you need value other than default.  This script is actually
  330. used by the following two, to make a dirty job of traversing through the
  331. file systems.
  332.  
  333. All parametres (up to 127 in case of 4OS2) are passed in the original order
  334. directly to the DIR command.  In my example DIR makes a list of fully
  335. qualified filenames (/F) excluding dot and double dot directories (/B), and
  336. backups (/[!*.ba?]) in whole trees (/S).  It will include regular
  337. directories though.  Then, every entry is added a date and time of its
  338. last modification (%@FileAge) in front of the file name and the whole list
  339. is saved in a temp file.  The latter is only because I used DOS sorting
  340. program - otherwise I could simply extend the pipe.  From the first
  341. %FileLimit% lines of the sorted temporary file (meaning %FileLimit%
  342. recently updated files) file names are extracted and echoed to the stdout.
  343. Finally, empty lines are removed (I could do the same implementing some
  344. conditional logic, but I'm rather lazy).  All error messages which would
  345. possibly spoil the resulting list are sent to hell.
  346.  
  347. b) MakeLast20.  This one is pretty simple.  It uses FindLatest to create
  348. the list of 20 most recently modified files in my primary working
  349. directories, and feeds it to MakeShadow.  Before that, objects exceeding
  350. the file limit are removed - just in case you have recently played with the
  351. file limit, since normally it's not needed at all.
  352.  
  353. c) MakeTodays.  This one is simple as well and pretty simillar to the
  354. above, but uses an additional trick.  The script lists up to 50 files
  355. modified today or yesterday (/[d-1]) on disks D:\ and E:\ (they are my data
  356. drives), _except_ for E:\Mail directory, where my email, news and a web
  357. cache reside.  The trick with backquotes inserts and additional FIND
  358. pipe right after the DIR statement in FindLatest, effectively making the
  359. whole subtree remove, before any further processing is made, including time
  360. stamping and sorting.  Since the number of modified files may be different
  361. every day (ranging from 0 to 50 in this case), all existing shadows are
  362. removed before new are created.
  363.  
  364.  
  365. 7. Sample installation (mine, actually)
  366.  
  367. On my system all of these scripts are placed in a directory listed in the
  368. PATH environment variable.  Folders for shadow files have been created
  369. somewhere in my data directories and their shadows are placed on desktop,
  370. so that they are listed in the warpcenter menu.  Actually, since they do
  371. not contain regular files, they could have been placed on the desktop right
  372. away.  Directory names begin with the exclamation mark (!), so that they
  373. are sorted out at the very beginning of the menu.  In both directories
  374. there is a program object created, effectively calling respective
  375. batchfile.  This way I can always easily recreate objects on demand.  Also,
  376. the shadows of these objects are placed in the Autostart folder, so that
  377. they are recreated during every system start.  I examined the need to call
  378. any of the scripts in CRON or another task scheduler, but finally decided
  379. it would be an overkill.  In my environment there is no need for that.
  380.  
  381.  
  382. 8. Known bugs, problems etc.
  383.  
  384. Due to the way Rexx parses the command line, MakeShadow parametres must not
  385. contain spaces, even if the respective parameter is double quoted.  Piped
  386. file names can contain spaces, since no Rexx parsing is ever done on them.
  387.  
  388.  
  389. 9. Contacting the Author
  390.  
  391. If you have any suggestions, comments or bug reports, please let me know.
  392.  
  393. Name:  Jan Stozek
  394. Email: jasio@polbox.pl
  395.