home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ii_98158.zip / ImgInfo.CMD next >
OS/2 REXX Batch file  |  1998-06-07  |  13KB  |  460 lines

  1. /*
  2.  * Pgm Name    : E:\DB\BATCH\CMD\PPWIZARD.CMD
  3.  * Pgm Version : 98.150
  4.  * Time        : Sunday, 7 Jun 1998  6:04:12pm
  5.  * Input File  : E:\DB\PROJECTS\OS2\imginfo\IMGINFO.x
  6.  * Output File : .\OUT\ImgInfo.CMD
  7.  */
  8.  
  9. call RxFuncAdd  'SysFileTree',     'RexxUtil', 'SysFileTree'
  10. call RxFuncAdd  'RxMessageBox',    'RexxUtil', 'RxMessageBox'
  11. call RxFuncAdd  'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  12. call SayGarbage '[]-----------------------------------------------------------[]'
  13. call SayGarbage '| GifInfo: Version 98.158, Reports GIF & JPG file information |'
  14. call SayGarbage '|          http://www.ozemail.com.au/~dbareis (db0@anz.com)   |'
  15. call SayGarbage '[]-----------------------------------------------------------[]'
  16. call SayGarbage ''
  17. Parameters = arg(1)
  18. if Parameters = '' then
  19. SyntaxError("No parameters supplied by caller")
  20. parse var Parameters ImgMask ExtraParms
  21. /*
  22. * QSORT.XH Version 98.158 by Dennis Bareis
  23. *            The base code was not written by me (not sure where it came from
  24. *            http://www.ozemail.com.au/~dbareis (db0@anz.com)
  25. */
  26. signal EndQsortXh_1
  27. _ForwardsSort: PROCEDURE EXPOSE ImgFile.
  28. parse arg top, down
  29. if ( ( down-top ) < 2 ) then
  30. do
  31. if ( ( down - top ) > 0 ) then
  32. /* if ( ImgFile.top > ImgFile.down ) then */
  33. if ( FileNameSortRoutine( ImgFile.top, ImgFile.down ) > 0 ) then
  34. do
  35. tmpval      = ImgFile.top
  36. ImgFile.top    = ImgFile.down
  37. ImgFile.down   = tmpval
  38. end
  39. end
  40. else
  41. do
  42. l = top
  43. r = down
  44. m = top + trunc( ( down-top )/2 )
  45. do while ( l<r )
  46. m_val = ImgFile.m
  47. /* do while ( ImgFile.l < m_val ) */
  48. do while ( FileNameSortRoutine( ImgFile.l, m_val ) < 0 )
  49. if  ( l < m ) then
  50. l=l+1
  51. else
  52. leave
  53. end
  54. /* do while ( ImgFile.r > m_val ) */
  55. do while ( FileNameSortRoutine( ImgFile.r, m_val ) > 0 )
  56. if  ( m < r ) then
  57. r=r-1
  58. else
  59. leave
  60. end
  61. if ( l < r ) then
  62. do
  63. tmpval = ImgFile.l
  64. ImgFile.l = ImgFile.r
  65. ImgFile.r = tmpval
  66. select
  67. when ( m=r ) then
  68. do
  69. r = r-1
  70. m = l
  71. end
  72. when ( m=l ) then
  73. do
  74. l = l+1
  75. m = r
  76. end
  77. otherwise
  78. do
  79. l = l+1
  80. r = r-1
  81. end
  82. end
  83. end
  84. end
  85. if ( ( r-top ) < ( down-l ) ) then
  86. do
  87. call _ForwardsSort top, m-1
  88. call _ForwardsSort m+1, down
  89. end
  90. else
  91. do
  92. call _ForwardsSort m+1, down
  93. call _ForwardsSort top, m-1
  94. end
  95. end
  96. return
  97. ForwardsSort: PROCEDURE EXPOSE ImgFile.
  98. call _ForwardsSort 1, ImgFile.0
  99. return
  100. EndQSORTXh_1:
  101. DoSubdirs                    = ''
  102. IgnoreUnknownImageExtensions = 'N'
  103. Global.TagImgFiles           = 'N'
  104. Global.ExtendedTags          = 'N'
  105. Global.Dropped               = 'N'
  106. Global.ImportantOutput       = stderr
  107. if ImgMask = "*OBJECT_DROPPED*" then
  108. exit( ObjectDropped(Parameters) )
  109. do while  ExtraParms <> ''
  110. parse var ExtraParms ThisParm ExtraParms
  111. ThisParm = translate(ThisParm)
  112. select
  113. when ThisParm = '/S' then
  114. DoSubdirs = 'S'
  115. when ThisParm = '/I' then
  116. IgnoreUnknownImageExtensions = 'Y'
  117. when ThisParm = '/T' then
  118. do
  119. Global.TagImgFiles  = 'Y'
  120. Global.ExtendedTags = 'Y'
  121. end
  122. otherwise
  123. SyntaxError('Unknown command of "' || ThisParm || '" specified')
  124. end
  125. end
  126. SearchRc = SysFileTree(ImgMask, 'ImgFile', 'FO' || DoSubdirs)
  127. if SearchRc <> 0 | ImgFile.0 = 0 then
  128. do
  129. call SayGarbage 'ERROR: No files match "' || ImgMask || '"'
  130. exit(900 + SearchRc)
  131. end
  132. call ForwardsSort
  133. RoutineRc = 0
  134. GifCount  = 0
  135. JpgCount  = 0
  136. call OutputHtmlHeader
  137. do Index=1 to ImgFile.0
  138. ThisFile = ImgFile.Index
  139. LastDot = lastpos('.', ThisFile)
  140. if  LastPos = 0 then
  141. ThisExtn = ''
  142. else
  143. ThisExtn = translate( substr(ThisFile, LastDot+1) )
  144. select
  145. when ThisExtn = 'GIF' then
  146. do
  147. GifCount  = GifCount + 1
  148. ImgRc     = ReportGifInfo(ThisFile)
  149. end
  150. when ThisExtn = 'JPG' then
  151. do
  152. JpgCount  = JpgCount + 1
  153. ImgRc     = ReportJpgInfo(ThisFile)
  154. end
  155. otherwise
  156. do
  157. if  IgnoreUnknownImageExtensions = 'Y' then
  158. ImgRc     = 0
  159. else
  160. ImgRc     = MyLineNumber()
  161. end
  162. end
  163. if  ImgRc <> 0 then
  164. RoutineRc = ImgRc
  165. end
  166. call OutputHtmlTrailer
  167. TotalImages = GifCount  + JpgCount
  168. Extras      = ImgFile.0 - TotalImages
  169. if Extras = 0 then
  170. say 'Processed ' || GifCount || ' GIF file(s) & ' || JpgCount || ' JPEG file(s).'
  171. else
  172. say 'Processed ' || GifCount || ' GIF file(s) & ' || JpgCount || ' JPEG file(s) with ' || Extras || ' file(s) ignored.'
  173. exit(RoutineRc)
  174. HtmlFileName: procedure expose Global Global.
  175. InFileName     = arg(1)
  176. ReasonableSize = arg(2)
  177. OutFileName = ''
  178. do  while length(InFileName) > ReasonableSize
  179. OutFileName = OutFileName || left(InFileName, ReasonableSize)
  180. InFileName  = substr(InFileName, ReasonableSize+1)
  181. SlashPos = pos('\', InFileName)
  182. if  SlashPos <> 0 then
  183. do
  184. OutFileName = OutFileName || left(InFileName, SlashPos) || '<BR>'
  185. InFileName  = substr(InFileName, SlashPos+1)
  186. end
  187. end
  188. return( OutFileName || InFileName )
  189. OutputHtmlHeader: procedure expose Global Global.
  190. if Global.ExtendedTags = 'Y' then
  191. do
  192. Title = arg(1)
  193. if  Title = '' then
  194. Title = 'ImgInfo Output (' || date('Normal') || ' ' || time() || ')'
  195. call SayImgInformation '<HTML><HEAD>'
  196. call SayImgInformation '<TITLE>' || Title || '</TITLE></HEAD><BODY>'
  197. call SayImgInformation ''
  198. call SayImgInformation '<CENTER><TABLE COLS=2 BORDER=5 CELLSPACING=5>'
  199. call SayImgInformation '<TR><TH ALIGN=CENTER>Details<TH ALIGN=CENTER>Image</B></TR>'
  200. end
  201. return
  202. TagIt: procedure expose Global Global.
  203. FileName    = arg(1)
  204. ImageWidth  = arg(2)
  205. ImageHeight = arg(3)
  206. if  Global.ExtendedTags = 'Y' then
  207. do
  208. ImageSize = AddCommasToDecimalNumber( stream(FileName, 'c', 'query size') )
  209. call SayImgInformation '<TR><TD ALIGN=CENTER>' || HtmlFileName(FileName,20) || '<HR><B>' || ImageWidth || ' x ' || ImageHeight || '</B><BR>' || ImageSize || ' bytes<TD ALIGN=LEFT>'
  210. end
  211. call SayImgInformation '<IMG SRC="' || FileName || '" BORDER=0 WIDTH=' || ImageWidth || ' HEIGHT=' || ImageHeight || '>'
  212. if  Global.ExtendedTags = 'Y' then
  213. call SayImgInformation '</TR>'
  214. return
  215. ImageInfoFailure: procedure expose Global Global.
  216. ImgFile   = arg(1)
  217. ErrorText = arg(2)
  218. call SayGarbage left(ErrorText, 23) || ImageFileName(ImgFile)
  219. if  Global.TagImgFiles = 'Y' then
  220. do
  221. if  Global.ExtendedTags = 'Y' then
  222. do
  223. ImageSize = AddCommasToDecimalNumber( stream(ImgFile, 'c', 'query size') )
  224. call SayImgInformation '<TR><TD ALIGN=CENTER>' || HtmlFileName(ImgFile,20) || '<HR>' || ImageSize || ' bytes<TD ALIGN=LEFT>'
  225. call SayImgInformation ErrorText
  226. call SayImgInformation '</TR>'
  227. end
  228. end
  229. return
  230. OutputHtmlTrailer: procedure expose Global Global.
  231. if Global.ExtendedTags = 'Y' then
  232. do
  233. call SayImgInformation ''
  234. call SayImgInformation '</TABLE></CENTER>'
  235. call SayImgInformation ''
  236. call SayImgInformation '</BODY></HTML>'
  237. end
  238. return
  239. SyntaxError:
  240. Reason   = arg(1)
  241. Location = SIGL
  242. call SayGarbage 'CORRECT SYNTAX'
  243. call SayGarbage '~~~~~~~~~~~~~~'
  244. call SayGarbage '    ImgInfo[.CMD]  [drive:][path][FileMask]  [/s] [/t] [/i] [ 2 > Output]'
  245. call SayGarbage ''
  246. call SayGarbage 'WHERE'
  247. call SayGarbage '~~~~~'
  248. call SayGarbage '    /s = scan subdirectories.'
  249. call SayGarbage '    /t = HTML tag the image references (sent to stderr).  View generated HTML'
  250. call SayGarbage '         in a browser to see image along with its details.  Use from root dir'
  251. call SayGarbage '         with /s to see all images on drive!'
  252. call SayGarbage "    /i = Don't set non-zero return code if unknown extensions found."
  253. call SayGarbage ''
  254. call SayGarbage 'THE PROBLEM'
  255. call SayGarbage '~~~~~~~~~~~'
  256. call SayGarbage '    ' || Reason || '.'
  257. call SayGarbage ''
  258. exit(Location)
  259. MyLineNumber:
  260. return(SIGL)
  261. SayGarbage: procedure
  262. say arg(1)
  263. return
  264. SayImgInformation: procedure expose Global Global.
  265. call charout Global.ImportantOutput, arg(1) || d2c(13) || d2c(10)
  266. CloseRc = stream(Global.ImportantOutput, 'c', 'close')
  267. return
  268. ImageFileName: procedure
  269. FullFileName      = arg(1)
  270. FullFileNameUpper = translate( FullFileName )
  271. ThisDir           = translate( directory()  )
  272. if  right(ThisDir, 1) <> '\' then
  273. ThisDir = ThisDir || '\'
  274. ThisDirLength     = length( ThisDir )
  275. if  left(FullFileNameUpper, ThisDirLength) <> ThisDir then
  276. return(FullFileName)
  277. else
  278. do
  279. return( substr(FullFileName, ThisDirLength+1) )
  280. end
  281. ReportGifInfo: procedure expose Global Global.
  282. GifFile     = arg(1)
  283. GifFormatId = charin(GifFile, 1, 6)
  284. if left(GifFormatId,3) <> "GIF" then
  285. do
  286. call ImageInfoFailure GifFile, "Not a GIF file"
  287. CloseRc = stream(GifFile, 'c', 'close')
  288. return(MyLineNumber())
  289. end
  290. WidthLow    = charin(GifFile,, 1)
  291. WidthHigh   = charin(GifFile,, 1)
  292. ImageWidth  = c2d(WidthHigh || WidthLow)
  293. HeightLow   = charin(GifFile,, 1)
  294. HeightHigh  = charin(GifFile,, 1)
  295. ImageHeight = c2d(HeightHigh || HeightLow)
  296. CloseRc = stream(GifFile, 'c', 'close')
  297. if  Global.TagImgFiles = 'N' then
  298. call SayImgInformation right(ImageWidth, 4) || '*' || left(ImageHeight, 4) || ' | ' || GifFormatId || '   | ' || ImageFileName(GifFile)
  299. else
  300. call TagIt ImageFileName(GifFile), ImageWidth, ImageHeight
  301. return(0)
  302. ReportJpgInfo: procedure expose Global Global.
  303. JpgFile     = arg(1)
  304. FileType    = c2x(Charin(JpgFile, 1, 2))
  305. if FileType <> "FFD8" then
  306. do
  307. call ImageInfoFailure JpgFile, "Not a JPEG file"
  308. CloseRc = stream(GifFile, 'c', 'close')
  309. return(MyLineNumber())
  310. end
  311. NxtSeg      = 3
  312. ImageHeight = "IMAGEHEIGHT"
  313. do  while (Type <> "D9") & (NxtSeg <> -1) & (Imageheight = "IMAGEHEIGHT")
  314. NxtSeg = ReadJpgSegment(NxtSeg)
  315. end
  316. CloseRc = stream(JpgFile, 'c', 'close')
  317. BitsMsg = ImageBPS || ' bits'
  318. if  Global.TagImgFiles = 'N' then
  319. call SayImgInformation right(ImageWidth, 4) || '*' || left(ImageHeight, 4) || ' | ' || left(BitsMsg , 8) || ' | ' || ImageFileName(JpgFile)
  320. else
  321. call TagIt ImageFileName(JpgFile), ImageWidth, ImageHeight
  322. return(0)
  323. ReadJpgSegment:
  324. SegPos = arg(1)
  325. Marker = c2x( charIn(JpgFile, SegPos) )
  326. if  Marker <> "FF" then
  327. return(-1)
  328. Type = c2x( charIn(JpgFile) )
  329. Res  = SegPos + 2
  330. select
  331. when Type = "01" | Type >= "D0" & Type <= "D9" then
  332. SegmentLength = 0
  333. otherwise
  334. SegmentLength = c2d( CharIn(JpgFile, , 2) )
  335. End
  336. Res = Res + SegmentLength
  337. if Type = "C0" | Type = "C2" then
  338. do
  339. Imagebps    = c2d( CharIn(JpgFile) )
  340. Imageheight = c2d( CharIn(JpgFile, , 2) )
  341. Imagewidth  = c2d( CharIn(JpgFile, , 2) )
  342. end
  343. return(Res)
  344. AddCommasToDecimalNumber: procedure
  345. NoComma = strip( arg(1) )
  346. if  pos(',', NoComma) <> 0 then
  347. return(NoComma)
  348. DotPos = pos('.', NoComma)
  349. if  DotPos = 0 then
  350. AfterDecimal = ''
  351. else
  352. do
  353. if  DotPos = 1 then
  354. return("0" || NoComma)
  355. AfterDecimal = substr(NoComma, DotPos+1)
  356. NoComma      = left(NoComma, DotPos-1)
  357. end
  358. NoComma = reverse(NoComma)
  359. ResultWithCommas = ""
  360. do  while length(NoComma) > 3
  361. ResultWithCommas = ResultWithCommas || left(NoComma, 3) || ','
  362. NoComma          = substr(NoComma, 4)
  363. end
  364. ResultWithCommas = ResultWithCommas || NoComma
  365. ResultWithCommas = reverse(ResultWithCommas)
  366. if  AfterDecimal <> '' then
  367. ResultWithCommas = ResultWithCommas || '.' || AfterDecimal
  368. return(ResultWithCommas)
  369. PmDebug:
  370. Action = RxMessageBox(arg(1), "DEBUG: " || "At Line #" || SIGL, 'OK', 'INFORMATION')
  371. return
  372. ObjectDropped: procedure expose Global Global.
  373. Global.Dropped = 'Y'
  374. call Beep 2000,100
  375. Parameters = arg(1)
  376. parse var Parameters IgnoreCmd '"'ImgRootDir'"' ExtraParms
  377. ExtraParms = strip(ExtraParms)
  378. DoSubdirs = ''
  379. TreeCmt   = 'single directory'
  380. do while  ExtraParms <> ''
  381. parse var ExtraParms ThisParm ExtraParms
  382. ThisParm = translate(ThisParm)
  383. select
  384. when ThisParm = '/S' then
  385. do
  386. DoSubdirs = 'S'
  387. TreeCmt   = '+ subdirectories'
  388. end
  389. otherwise
  390. SyntaxError('Unknown command of "' || ThisParm || '" specified')
  391. end
  392. end
  393. NewDir = directory(ImgRootDir)
  394. if  translate(NewDir) <> translate(ImgRootDir) then
  395. do
  396. LastSlash = lastpos('\', ImgRootDir)
  397. if  LastSlash <> 0 then
  398. ImgRootDir = left(ImgRootDir, LastSlash-1)
  399. if  length(ImgRootDir) = 2 then
  400. ChangeDirName = ImgRootDir || '\'
  401. else
  402. ChangeDirName = ImgRootDir
  403. NewDir = directory(ChangeDirName)
  404. end
  405. DropAmount = length(ImgRootDir) + 1 + 1
  406. Global.ImportantOutput = SysTempFileName(ImgRootDir || '\' || 'ImgInfo.???')
  407. Global.ExtendedTags    = 'Y'
  408. Global.TagImgFiles     = 'Y'
  409. ImgMask = ImgRootDir || '\*.*'
  410. SearchRc = SysFileTree(ImgMask, 'ImgFile', 'FO' || DoSubdirs)
  411. if SearchRc <> 0 | ImgFile.0 = 0 then
  412. do
  413. Action = RxMessageBox('No Files match "' || ImgMask || '".',, 'OK', 'ERROR')
  414. exit(900 + SearchRc)
  415. end
  416. call ForwardsSort
  417. call OutputHtmlHeader ImgRootDir || '\*.* (' || TreeCmt || ') - ' || AddCommasToDecimalNumber(ImgFile.0) || ' files found'
  418. do Index=1 to ImgFile.0
  419. ThisFile = ImgFile.Index
  420. ThisFile = substr(ThisFile, DropAmount)
  421. LastDot = lastpos('.', ThisFile)
  422. if  LastPos = 0 then
  423. ThisExtn = ''
  424. else
  425. ThisExtn = translate( substr(ThisFile, LastDot+1) )
  426. select
  427. when ThisExtn = 'GIF' then
  428. ImgRc     = ReportGifInfo(ThisFile)
  429. when ThisExtn = 'JPG' then
  430. ImgRc     = ReportJpgInfo(ThisFile)
  431. otherwise
  432. end
  433. end
  434. call OutputHtmlTrailer
  435. call Beep 2200,100
  436. NetscapeCmd = 'start /WIN /MIN "Netscape DB$" "cmd.exe /c netscape.exe "' || Global.ImportantOutput || '" & del "' || Global.ImportantOutput || '" & exit"'
  437. address cmd NetscapeCmd
  438. return
  439. FileNameSortRoutine: PROCEDURE
  440. parse arg p1, p2
  441. p1Dir = filespec('drive', p1) || filespec('path', p1)
  442. p2Dir = filespec('drive', p2) || filespec('path', p2)
  443. if  p1Dir < p2Dir then
  444. return(-1)
  445. else
  446. do
  447. if  p1Dir > p2Dir then
  448. return(1)
  449. end
  450. p1File = filespec('name', p1)
  451. p2File = filespec('name', p2)
  452. if  p1File < p2File then
  453. return(-1)
  454. else
  455. do
  456. if  p1File > p2File then
  457. return(1)
  458. end
  459. return(0)
  460.