home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
AUTODESC.SRF
< prev
next >
Wrap
Text File
|
1997-01-01
|
5KB
|
190 lines
/* Construct a description of a file.
Requires the unzipapi.dll
Note that a maximum of about 1000 characters (or 15 lines)
is returned in a string:
header_string=sref_auto_describe(filename.ext,candozip)
Candozip is optional: if 1, then UNZIPAPI.DLL is available
If 0, it's not (so .ZIP files will NOT be auto-described).
If missing, SREF_AUTO_DESCRIBE will look for it).
Note: if a badly formatted html file is investigated (no
<HEAD>, or no <TITLE>, then it will be treated as a plain
text file.
----------- */
SREF_AUTO_DESCRIBE:
/* construct a description from html, text, or .zip files */
auto_describe:
crlf='0d0a'x
parse arg thefile,candozip
if candozip="" then do /* check for unzipapi.dll */
foo=rxfuncquery('UZLoadFuncs')
if foo=1 then do
call RxFuncAdd 'UZLoadFuncs', 'UNZIPAPI', 'UZLoadFuncs'
call UZLoadFuncs
end
foo=rxfuncquery('UZLoadFuncs')
candozip=1
if foo=1 then candozip=0
end
thefile=strip(thefile)
/* is it a .zip file? */
if right(upper(thefile),4)='.ZIP' then do
if candozip=0 then return ' ' /* no dll -- give up */
zipcmts.0=0 /* try using a file_id.diz file */
rc=uzfiletree(thefile,getem)
do km=1 to getem.0
if upper(getem.km)='FILE_ID.DIZ' then do
rc=uzunziptovar(thefile,getem.km,zipcmts)
if rc<>0 then zipcmts.0=0
leave
end
end
if zipcmts.0>0 then do /* use first 15 lines of file_id.diz */
oof=zipcmts.1
do te=2 to min(15,zipcmts.0)
oof=oof||' '||zipcmts.te
end /* do */
return oof
end
zipcmts.0=0 /* no .diz, then get -z comments */
rc=uzunzip(' -z '||thefile,'zipcmts.')
if rc<>0 then zipcmts.0=0
if zipcmts.0>1 then do /* use -z comments if available, skip generic line */
oof=zipcmts.2
do te=3 to zipcmts.0
oof=oof||' '||zipcmts.te
end /* do */
return oof
end
return ' ' /* no -z, and no file_id.diz */
end /* .ZIP file */
atype=upper(sref_mediatype(thefile))
if atype='TEXT/PLAIN' then do /*grab first 15 lines */
oof=""
if lines(thefile)=1 then
oof=linein(tempfile)
do mm=1 to 14 /* read first 15 lines */
if lines(thefile)=0 then leave
tt=linein(thefile)
oof=oof||' '||tt
end
foo=stream(thefile,'c','close')
return oof
end /* Do */
if atype='TEXT/HTML' then do /* parse html, look for title or description */
oof=get_html_descript(thefile)
if oof="" then do /* must be badly formatted, treat as text file */
oof=""
aa=stream(thefile,'c','close')
if lines(thefile)=1 then
oof=linein(tempfile)
do mm=1 to 14 /* read first 15 lines */
if lines(thefile)=0 then leave
tt=linein(thefile)
oof=oof||' '||tt
end
foo=stream(thefile,'c','close')
end
return oof
end
return ' ' /* other type, give up */
/**************************************/
/* Extract description from text/html file */
get_html_descript:procedure
parse arg filename
crlf='0d0a'x
alen=min(chars(filename),2000)
stuff=charin(filename,1,alen)
stuff=space(translate(stuff,' ','00090a0d1a1b'x))
wow=look_header(filename)
astring=""
if url_title<>' ' then
astring=strip(strip(url_title),'t','.')||'. '
if url_content<>' ' then
astring=astring||url_content
return astring
/* ----------------------------------------------------------------------- */
/* Look for "desc" field in header */
/* ----------------------------------------------------------------------- */
look_header: procedure expose stuff url_title url_content
parse arg afile
url_title=""
url_content=""
dowrite=0
do until stuff=""
parse var stuff p1 '<' tag '>' stuff
if translate(word(tag,1))="HEAD" then do /* now in head !*/
dowrite=1
iterate
end
if dowrite=0 then iterate /* wait till we get into head .. */
if translate(word(tag,1))="/HEAD" then /* out of head, all done ! */
leave
/* IT IS A TITLE TAG? */
if translate(word(tag,1))="TITLE" then do
parse var stuff url_title '<' footag '>' stuff
if url_content<>' ' then return 0
end
/* is it a META HTTP-EQUIV or a META NAME ? */
if translate(word(tag,1))="META" then do
parse var tag ameta atype '=' rest
tatype=translate(atype)
if tatype="HTTP-EQUIV" | tatype="NAME" then do
parse var rest aval1 rest
REST=STRIP(REST)
aval1=strip(aval1) ;
aval1=strip(aval1,,'"')
if abbrev(translate(aval1),'DESC')<>1 then iterate
aval2=" "
foo1=ABBREV(translate(rest),'CONTENT')
if foo1>0 then do
PARSE VAR REST FOO '=' AVAL2
aval2=strip(aval2)
aval2=strip(aval2,'b','"')
url_content=LEFT(AVAL2,1000)
if url_title<>' ' then return 0
iterate
end
end /* name or http-equiv */
end /* meta */
end /* stuff */
return 0