You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, September 24th 2004, 4:05am

Documents To Go : pdb2doc converter script (included)

I wrote a script to convert DocumentsToGo pdb files into .doc files. I thought someone might find it useful, or might be able to include it in a kdepim plugin or something, so I'm posting it here:

[code:1]
#!/bin/sh

# This program is released under the GPL, except that I don't know how
# to do it. If anyone wants to include the proper GPL block here, be
# my guest.

# Author: Erich Enke
# twilit77@fastmail.fm
#
# suggested program name and usage : pdb2doc infile [outfile]
#
# This program takes in a pdb filename, parses the record list, and
# extracts the file from it. The file doesn't necessarily have to be
# a DocumentsToGo file, but that is all I have tested it with. pdb2doc
# doesn't even care if its a MSWD type of pdb file.
#
# Anyway, it seems no one out there had written anything like this, and
# my wife needed her doc files, so I wrote one up. I hope it does someone
# some good. Who knows? Maybe someone will include it in a kdepim plugin
# or something...
#
# There are several things that could be improved with it:
# 1. a.pdb should have an automatic output filename of a.doc, not a.pdb.doc
# 2. I don't know if the different "sections" of a pdb file should be
# different Word docs. I haven't even tried it yet. (By "sections" I
# mean contiguous lists of all about 4K in length, then it jumps id
# right after a <4K record, and on to a new section...&#41;
# 3. Usage string
# 4. Options parsing

pdb=$1
outfile=$&#123;2&#58;-"$pdb.doc"&#125;

function read_addr &#40;&#41; &#123;
hexdump -e '12/1 "%02x"' -s $1 -n 3 $pdb | sed 's/^/0x/' | xargs printf "%d"
&#125;

function extract_portion &#40;&#41; &#123;
byteskip=$1
bytecount=$2

dd if=$pdb of=.pdb2doc.tmp bs=1 skip=$&#40;&#40;byteskip+8&#41;&#41; count=$&#40;&#40;bytecount-8&#41;&#41; 2>/dev/null 1>&2
cat .pdb2doc.tmp >> $outfile
rm .pdb2doc.tmp
&#125;

next_addr_bytes=79
skip=`read_addr $next_addr_bytes`
while &#91; $skip -ne 382 &#93;; do
echo -n "Doing Record at $skip bytes..."
next_addr_bytes=$&#40;&#40;next_addr_bytes + 8&#41;&#41;
lastskip=$skip
skip=`read_addr $next_addr_bytes`
if &#91; $skip -eq 382 &#93;; then
size=$&#40;&#40;`wc -c $pdb | awk '&#123;print $1&#125;'` - lastskip&#41;&#41;
else
size=$&#40;&#40;skip-lastskip&#41;&#41;
fi
extract_portion $lastskip $size
echo " $size bytes processed"

done
[/code:1]

Hope it helps someone,
Erich