[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Parsing package filenames (was: Re: New ftp method for dselect)



>Yup.  Thanks for pointing that out.  EXT should disallow dashes.
>
>The following seems to (slowly) parse all packages in a fairly old 
>"available" file which I have handy as is apparently intended by the 
>debian package maintainer, with the exception of
>
>  elisp-manual-19-2.4-1.tar.gz     (is "-19" part of Name or Veraion?)

19 is (I believe) part of the package name.

>  lrzsz-0.11.tar.gz                (Revision? Should be lrzsz-0-11.tar.gz?)
>  ?bind-4.9.3-BETA24-1.tar.gz       (change to bind-4.9.3_BETA24-1.tar.gz?)

There is also "dpkg-1.0.5.deb" which has no revision.  It isn't strictly
neccessary and so has been left out.  In order to use this scheme, such
packages would have to include a dummy revision of "-0" or something.

>for FILE in $*
>do
>    TOKENS=`echo $FILE | \
>        sed -e 's/\(.*\)-\([^-]*\)-\([^.]*\)\.\([^-]*\)$/\1 \2 \3 \4/'`

You might want "[^.-]" here-----------^^^^

>    PKG=`echo $TOKENS | cut -d' ' -f1`
>    VER=`echo $TOKENS | cut -d' ' -f2`
>    REV=`echo $TOKENS | cut -d' ' -f3`
>    EXT=`echo $TOKENS | cut -d' ' -f4`
>    echo "$PKG  $VER    $REV    $EXT"
>done

I don't see how to accelerate your regex, but you can accelerate the
loop by forking as few external process as possible.  eg:

Run sed only once:
    for FILE in `sed -e '.....' FileOfPackagesOnePerLine`
(be sure to put something besides spaces (like ",") between the different
pieces or each piece will pass through the loop)

Break the tokens up in one shot and use shell operators:
    set pkg = ( `echo $file | sed -e 's|,| |g'` )
    if ($#pkg != 3) then
        echo "Error: bad file $file"
        continue
    endif
    set nam = $pkg[1]
    set ver = $pkg[2]
    set rev = $pkg[3]
(the above is csh code...  sorry!)

                                        Brian
                                 ( bcwhite@bnr.ca )

-------------------------------------------------------------------------------
    In theory, theory and practice are the same.  In practice, they're not.


Reply to: