Alexander Neundorf wrote:
>
> On Thursday 21 June 2007 13:27, Andrew Barton-Sweeney wrote:
> > Maybe the xargs program can help?
>
> That's not available under Windows by default.
> One workaround would be to ship a batch file for Windows and a shell 
> script
> for all other systems, but this feels like a hack to get something working
> which would be fit perfectly in sdcclib (and all other 
> linkers/librarians I
> know of work this way).
>
I've rewritten the librarian in python, at the moment it just takes a 
list of .rel files and produces the library on stdout, but it could 
easily be adapted to behave more like the existing librarian. It's also 
incredibly faster.

Feel free to incorporate and do with what you want.

Dan.

#!/usr/bin/python

from sys import argv
import os.path

files=argv[1:]

sizes={}
lib=['<FILES>\n\n']
offset=len(lib[0])
for f in files:
    (path,base)=os.path.split(f)
    (name,ext)=os.path.splitext(base)
    relfile=f
    adbfile=path+os.path.sep+name+'.adb'
    try:
        reldata=file(relfile).read()
    except:
        reldata=''
    try:
        adbdata=file(adbfile).read()
    except:
        adbdata=''
   
    l=[]

    l+=['<FILE>\n',name,'\n']
    l+=['<REL>\n',reldata,'</REL>\n']
    l+=['<ADB>\n',adbdata,'</ADB>\n']
   
    l+=['</FILE>\n\n']
   
    ls=''.join(l)
    sizes[name]=offset
    offset+=len(ls)
    lib.append(ls)

lib.append('</FILES>\n\n')

syms=['<SDCCLIB>\n\n<INDEX>\n',11*' ']
for f in files:
    (path,base)=os.path.split(f)
    (name,ext)=os.path.splitext(base)

    syms+=['<MODULE>\n',name+' %d\n' % sizes[name]]

    for l in file(f).readlines():
        s=l.split()
        if s[0] == 'S' and s[2][0] == 'D':
            syms.append(s[1]+'\n')
    syms.append('</MODULE>\n\n')

syms.append('</INDEX>\n\n')
syms[1]="%10d\n" % sum([len(s) for s in syms])

print ''.join(syms+lib)
print "</SDCCLIB>"


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to