home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / cdrom / optycdplayer / extras / utils / disknote.rexx next >
OS/2 REXX Batch file  |  1977-12-31  |  2KB  |  112 lines

  1. /* $VER: DiskNote.rexx 1.1 (21.7.96)
  2.  
  3.    Puts a filenote on a file, consisting of the two first lines
  4.    in the file, separated by ": ". This has the effect - for
  5.    Disk Files for e.g. OptyCDPlayer - of making the author and
  6.    title visible in a directory listing or utility.
  7.  
  8.    © Niels Bache (nbache@diku.dk), 14/7-96. Freely distributable.
  9.    Specifically, Stéphane 'Opty' Barbaray is welcome to include
  10.    this with future releases of his great OptyCDPlayer program.
  11.  
  12.    History:
  13.    Version 1.1, 21/7-96:
  14.      ·  Now handles authors/titles with double quotes and/or asterisks
  15.         in them, by escaping them with asterisks.
  16.      ·  If author or title is empty, now just gives a warning and uses
  17.         the other one alone, with no colon.
  18.      ·  If both are missing, it still quits, since there is nothing to
  19.         put in the filenote.
  20.      ·  Also now just gives a warning if no track titles are found.
  21. */
  22.  
  23. parse arg File .
  24. File = strip(File, 'B', '"')
  25.  
  26. NoAuth = 0
  27. NoTitl = 0
  28.  
  29. if length(File) <= 0 then do
  30.    say "No file name given!"
  31.    exit 10
  32. end
  33.  
  34. if ~open('In', File, 'R') then do
  35.    say "File not found!"
  36.    exit 10
  37. end
  38.  
  39. if eof('In') then do
  40.    say "File empty!"
  41.    exit 10
  42. end
  43.  
  44. Line1 = readln('In')
  45. if length(Line1) <= 0 then do
  46.    say "WARNING: No author found in file!"
  47.    NoAuth = 1
  48. end
  49.  
  50. if eof('In') then do
  51.    say "File too short!"
  52.    exit 10
  53. end
  54.  
  55. Line2 = readln('In')
  56. if length(Line2) <= 0 then do
  57.    say "WARNING: No CD title found in file!"
  58.    NoTitl = 1
  59. end
  60.  
  61. if eof('In') then do
  62.    say "WARNING: No track titles found in file!"
  63. end
  64.  
  65. call close('In')
  66.  
  67. if NoAuth & NoTitl then do
  68.    say "Neither author nor CD title found!"
  69.    exit 10
  70. end
  71.  
  72. Sep = ": "
  73. if NoAuth | NoTitl then Sep = ""
  74. Note = Line1 || Sep || Line2
  75. if Length(Note) > 79 then do
  76.    Note = left(Note, 78) || "»"
  77. end
  78.  
  79. Done = 0
  80. Start = 1
  81. do while ~Done
  82.    APos = pos('*', Note, Start)
  83.    if APos > 0 then do
  84.       Note = left(Note, APos - 1) || '*' || substr(Note, APos)
  85.       Start = APos + 2
  86.       if Start > length(Note) then Done = 1
  87.    end
  88.    else Done = 1
  89. end
  90.  
  91. Done = 0
  92. Start = 1
  93. do while ~Done
  94.    QPos = pos('"', Note, Start)
  95.    if QPos > 0 then do
  96.       Note = left(Note, QPos - 1) || '*' || substr(Note, QPos)
  97.       Start = QPos + 2
  98.       if Start > length(Note) then Done = 1
  99.    end
  100.    else Done = 1
  101. end
  102.  
  103. Note = '"' || Note || '"'
  104. MyCmd = "filenote " || File || " " || Note
  105. address command MyCmd
  106. if RC ~= 0 then do
  107.    say "Error (RC = " || RC || ") while setting file note!"
  108.    exit 10
  109. end
  110.  
  111. exit 0
  112.