📄 cdbfile.ps
字号:
(conversions)h(would)f(be)g(useful,)g(particularly)h(for)165494 y(dates)d(or)g(memo)g(block)g(numbers,)h(but)f(I)h(did)g(not)f(need)h(those)e(functionalities)h(for)g(my)h(own)165544 y(application.)j(It's)6 b(up)h(to)g(you)g(to)g(add)h(mor)o(e)f(conversions,)i(in)e(r)o(espect)h(of)f(the)g(GPL,)h(of)f(course.)227594 y(In)12 b(all)g(cases,)g(the)f(r)o(esult)g(of)h(the)f(conversion)h(will)g(be)f(put)h(in)g(a)f(dynamically)h(allocated)165643 y(pointer)7 b(of)g(the)h(corr)o(esponding)g(type,)g(and)g(that)f(pointer)g(will)h(be)f(r)o(eturned)i(as)e(a)g Fn(void)gFq(poin-)165 693 y(ter)m(.)13 b(This)7 b(is)g(the)g(inelegant)f(aspect)h(of)f(the)h(function:)12 b(the)7 b(pr)o(ogrammer)g(has)g(to)f(know)h(exactly)165 743 y(what)h(kind)h(of)f(data)g(he)g(is)h(r)o(eceiving)h(in)f(that)e Fn(void)h Fq(pointer)m(,)h(and)g(he)f(also)g(has)g(to)g(delete)g(that)165 793 y(pointer)k(\(it)g(has)g(to)g(be)g(deleted,)h(since)g(it)f(has)g(been)h(allocated)f(dynamically\).)21b(If)12 b(he)g(is)h(us-)165 843 y(ing)d(a)f(\256xed)h(type)f(of)g(r)o(ecor)o(ds)i(\(for)e(a)h(speci\256c)g(application,)f(an)h(addr)o(ess)f(book)g(for)h(example\))165 892 y(this)f(will)h(not)g(be)g(a)g(pr)o(oblem.)k(But)c(if)g(the)g(type)f(of)h(r)o(ecor)o(ds)h(can)g(vary)f(in)h(that)e(application)g(\(a)165 942 y(generic)h(spr)o(eadsheet)e(application,)i(for)f(example\),)g(the)f(pr)o(ogrammer)i(will)f(pr)o(obably)g(have)165 992 y(to)e(verify)i(the)f(type)g(of)f(the)h(data,)h(using)f(public)g(functions)g(such)h(as)e Fn(GetFieldType\(\))pFq(\(see)165 1042 y(below\).)227 1092 y(The)14 b(same)e(canvas)h(applies)f(to)g Fn(SetFieldValue\(\))p Fq(,)h(the)g(other)f(way)h(r)o(ound:)20 b(when)165 1142 y(calling)10 b(that)f(function,)h(a)fFn(void)g Fq(pointer)g(containing)h(the)f(value)h(to)f(be)g(set)g(is)g(passed,)g(along)165 1191 y(with)f(a)g(pointer)g(to)g(the)g(\256eld)h(descriptor)m(.)14 b(The)9 b(function)f(then)g(converts)h(the)f(contents)f(of)h(the)165 1241 y Fn(void)i Fq(pointer)g(to)g(the)g(right)g(substring,)g(and)h(copies)f(it)g(to)g(the)g(contents)f(of)h(the)g(r)o(ecor)o(d.)227 1291 y(The)h(other)e(two)g(functions,)gFn(IsBigger\(\))g Fq(and)h Fn(IsSmaller\(\))p Fq(,)g(use)fFn(GetFieldVa-)165 1341 y(lue\(\))j Fq(to)g(compar)o(e)g(two)g(r)o(ecor)o(ds)i(on)e(the)g(basis)g(of)g(their)g(r)o(espective)h(values)g(for)f(a)g(given)165 1391 y(\256eld.)j(They)c(ar)o(e)f(called)h(by)gFn(SortAllRecords\(\))e Fq(only)h(so)g(far)m(.)227 1437y(The)h(public)g(functions)f(that)f(can)i(be)f(used)g(by)h(the)f(pr)o(ogrammer)g(ar)o(e)h(the)f(following:)165 1549 y Fg(class)20b(CDBFile)165 1588 y({)165 1628 y(...)165 1667 y(public:)2051707 y(void)f(SetFieldValue\(char*)g(Field,)g(void*)h(Value\);)2051746 y(void)f(SetFieldValue\(unsigned)g(short)g(FieldNum,)h(void*)f(Value\);)205 1785 y(void*)g(GetFieldValue\(char*)g(Field\);)2051825 y(void*)g(GetFieldValue\(unsigned)g(short)g(FieldNum\);)2051864 y(char)g(GetFieldType\(unsigned)g(short)g(NumField\))2651904 y({)g(return)h(\(FirstField->GetField\(NumField\)\)->GetType\(\);)d(})205 1943 y(void)i(DeleteVoidPointer\(void*)g(Pointer,)g(unsigned)g(short)h(Field\);)205 1983 y(void)f(DeleteVoidPointer\(void*)g(Pointer,)g(char*)h(Field\);)165 2022 y(...)165 2061y(};)227 2184 y Fq(The)9 b(overloaded)g(and)f(public)h(versions)f(of)gFn(SetFieldValue\(\))f Fq(and)h Fn(GetFieldVa-)165 2234y(lue\(\))i Fq(ar)o(e)g(the)g(equivalent)g(of)f(their)h(private)h(versions,)f(but)f(they)h(use)g(either)g(the)f(name)h(or)1652284 y(the)i(number)g(of)f(the)h(\256eld)g(to)f(r)o(efer)i(to)e(it.)18b Fn(GetFieldType\(\))11 b Fq(enables)g(the)h(pr)o(ogrammer)1652333 y(to)f(know)h(the)f(type)h(of)f(the)h(\256eld)g(r)o(efer)o(enced)i(by)e Fn(NumField)p Fq(.)18 b(I)12 b(also)f(chose)h(to)f(cr)o(eate)hFn(De-)165 2383 y(leteVoidPointer\(\))7 b Fq(so)h(that)f(the)i(pr)o(ogrammer)f(can)h(delete)f(easily)g(the)h Fn(void)f Fq(pointers)1652433 y(he)i(r)o(eceives)i(fr)o(om)e(calls)g(to)g Fn(GetFieldValue\(\))pFq(.)227 2483 y(That's)i(all)h(about)e(handling)j(the)e(contents)g(of)g(the)g(r)o(ecor)o(ds,)j(let's)c(have)i(a)f(look)h(now)f(at)1652533 y(how)e(the)g(\256les)g(ar)o(e)g(handled.)165 2646y Fr(3.4.3)42 b(Handling)10 b(the)g(\256les)165 2725y Fq(As)j(I)g(said)g(earlier)g(on,)h(I)f(did)h(not)e(implement)g(the)h(possibility)e(to)i(cr)o(eate)g(a)g(DBF)g(\256le)g(fr)o(om)1652775 y(scratch,)c(adding)g(\256elds)f(in)h(the)e(\256eld)i(descriptor)f(ring)h(and)f(the)g(r)o(ecor)o(ds)h(or)g(r)o(emoving)f(them.)1652824 y(Ther)o(efor)o(e,)15 b(one)e(has)g(to)f(open)h(an)g(existing)g(DBF)h(\256le)f(\256rst,)h(then)f(one)g(can)g(only)g(add,)i(edit)9052960 y(8)p eop%%Page: 9 99 8 bop 165 195 a Fq(or)12 b(r)o(emove)g(r)o(ecor)o(ds)h(fr)o(om)e(that)g(\256le,)i(and)f(save)f(it)h(or)g(save)f(it)g(as)h(a)f(new)h(\256le)f(\(with)g(another)165 245 y(pathname\).)227291 y(When)d(r)o(eferring)i(to)e(Section)g(2,)h(the)f(header)h(of)f(the)g(\256le)h(contains)f(a)g(few)g(speci\256c)h(param-)165337 y(eters)g(that)g(describe)i(the)f(characteristics)g(of)g(the)f(\256le.)14 b(They)d(ar)o(e)f(implemented)g(in)g(CDBFile)165383 y(as)g(private)g(member)g(variables:)165 440 y Fg(class)20b(CDBFile)165 480 y({)165 519 y(...)165 559 y(private:)205598 y(char)f(PathName[256];)219 b(//)19 b(Path)h(name)g(for)f(the)h(dBase)g(III)f(file)205 638 y(FILE)g(*FileHandle;)259b(//)19 b(Handler)h(for)f(the)h(dBase)g(III)f(file)205677 y(unsigned)g(short)h(HeaderSize;)79 b(//)19 b(Length)h(of)g(header)f(structure)205 717 y(unsigned)g(short)h(FieldCount;)79b(//)19 b(Number)h(of)g(fields)f(in)h(each)g(record)205756 y(unsigned)f(long)h(RecordCount;)79 b(//)19 b(Number)h(of)g(records)f(in)h(the)g(file)205 795 y(BOOL)f(ModifiedFlag;)239b(//)19 b(TRUE)h(if)g(the)f(data)h(has)g(been)f(modified)205835 y(BOOL)g(FullFileInMemory;)159 b(//)19 b(TRUE)h(if)g(the)f(entire)h(file)g(is)f(loaded)205 874 y(unsigned)g(short)h(RecordLength;)39b(//)19 b(Length)h(of)g(the)f(record)h(strings)205 953y(Record*)f(RecordList;)g(//)h(Head)g(of)g(the)f(list)h(of)g(records)205 993 y(Record*)f(CurrentRec;)g(//)h(Current)g(record)f(pointed)g(in)h(the)g(list)205 1032 y(CField*)f(FirstField;)g(//)h(Head)g(of)g(the)f(list)h(of)g(fields)165 1071 y(...)165 1111 y(};)2271208 y Fq(Some)13 b(of)g(them)g(can)h(be)f(accessed)h(and)g(modi\256ed)f(dir)o(ectly)i(by)f(the)f(pr)o(ogrammer)m(,)i(us-)1651254 y(ing)10 b(dedicated)h(public)f(functions;)g(most)e(of)i(them,)f(however)m(,)i(ar)o(e)f(only)g(accessed)g(and)g(pr)o(o-)1651300 y(cessed)i(internally)h(by)f(the)g(member)g(functions)g(of)g(the)g(package,)h(since)g(the)f(pr)o(ogrammer)165 1346 y(should)h(not)g(need)g(to)f(r)o(ead)i(or)f(modify)g(them)g(in)g(any)g(way)-5b(.)23 b(Her)o(e)13 b(ar)o(e)g(the)g(few)g(functions)1651392 y(that)c(enable)h(the)g(pr)o(ogrammer)h(to)e(do)i(so:)1651449 y Fg(class)20 b(CDBFile)165 1489 y({)165 1528 y(...)1651568 y(public:)205 1607 y(BOOL)f(IsOpen\(\))265 1646y({)g(return)h(\(BOOL\)\(FileHandle!=NULL\);)e(})2051686 y(unsigned)h(long)h(GetRecordCount\(\))265 1725y({)f(return)h(RecordCount;)f(})205 1765 y(unsigned)g(short)h(GetFieldCount\(\))265 1804 y({)f(return)h(FieldCount;)f(})1651844 y(...)165 1883 y(};)227 1980 y Fq(The)11 b(other)f(functions)g(perform)g(bigger)h(tasks,)e(of)h(a)g(higher)h(level.)k(Her)o(e)10b(they)g(ar)o(e:)165 2037 y Fg(class)20 b(CDBFile)1652076 y({)165 2116 y(...)165 2155 y(public:)205 2195 y(CDBFile\(\);)2052234 y(CDBFile\(char*)f(Path\);)205 2274 y(\304CDBFile\(\);)2052313 y(BOOL)g(Clean\(\);)205 2352 y(BOOL)g(OpenFile\(char*)g(Path\);)205 2392 y(BOOL)g(CloseFile\(\);)205 2431 y(unsigned)g(long)h(WriteAllToFile\(char)e(*Path=NULL\);)165 2510 y(private:)2052550 y(BOOL)h(WriteHeader\(char*)g(Path=NULL\);)165 2589y(...)165 2628 y(};)227 2736 y Fq(The)12 b(only)f(private)h(function)f(her)o(e)h(is)f(used)g(to)g(r)o(ewrite)g(the)g(\256le)g(header)h(when)f(some)g(of)165 2785 y(its)f(information)g(has)g(changed.)16b(It)11 b(is)f(also)g(used)h(to)f(write)g(the)g(modi\256ed)h(\256le)g(under)h(a)e(new)165 2835 y(pathname.)905 2960 y(9)peop%%Page: 10 1010 9 bop 227 195 a Fq(The)13 b(public)f(function)g(that)e(uses)hFn(WriteHeader\(\))g Fq(is)g Fn(WriteAllToFile\(\))pFq(.)17 b(That)165 245 y(function)10 b(is)g(used)g(only)g(when)g(the)f(entir)o(e)i(\256le)f(has)g(been)g(loaded)g(into)f(memory)h(and)g(has)g(to)165 295 y(be)i(r)o(ewritten)g(or)h(saved)f(under)i(a)e(new)g(pathname.)19 b(Note)12 b(that)f(it)h(contains)g(non-portable)165345 y(time-encoding)d(functions,)g(which)g(ar)o(e)g(speci\256cally)g(DOS-oriented,)g(and)g(will)g(cause)f(tr)o(ou-)165 394y(ble)j(when)g(ported)g(to)f(UNIX)h(/)g(Linux.)18 b(See)10b(the)h(code)g(in)g Fn("cdbfile.cpp")f Fq(for)h(mor)o(e)g(de-)165444 y(tails.)227 494 y(The)g(other)f(public)h(functions)f(perform)g(the)g(following)g(tasks:)227 577 y Ff(\017)21 b Fn(CDBFile\(\))6b Fq(is)g(the)h(default)f(constructor)m(,)i(wher)o(eas)eFn(CDBFile\(char*)24 b(Path\))6 b Fq(cr)o(e-)269 627y(ates)j(the)h(object)f(and)i(opens)f(the)g(\256le)g(known)g(as)gFn(Path)p Fq(;)227 710 y Ff(\017)21 b Fn(\304CDBFile\(\))9b Fq(is)h(the)g(default)g(destructor;)227 793 y Ff(\017)21b Fn(Clean\(\))8 b Fq(r)o(esets)h(\(or)g(initializes\))f(the)h(contents)f(of)h(the)g Fn(CDBFile)f Fq(object,)h(and)h(is)f(cal-)269843 y(led)h(both)g(by)h(the)f(constructors)f(and)i(the)f(destructor;)227 926 y Ff(\017)21 b Fn(OpenFile\(char*)i(Path\))14b Fq(\256rst)f(r)o(esets)g(the)h(object)f(and)h(then)g(opens)f(a)g(new)h(\256le)269 976 y(under)f Fn(Path)p Fq(;)g(that)e(function)h(also)g(sets)f(most)f(of)i(the)g(data)g(members)f(to)g(the)h(values)2691025 y(mentioned)e(in)g(the)g(\256le,)h(and)g(particularly)-5b(,)11 b(it)f(builds)h(the)f(\256eld)h(descriptor)f(ring.)2271108 y Ff(\017)21 b Fn(CloseFile\(\))9 b Fq(simply)h(closes)g(the)g(\256le)g(and)h(r)o(esets)e(all)h(the)g(data.)227 1191y(That's)c(all)h(for)g(the)f(description)h(of)g(the)f(code.)14b(Again,)8 b(if)f(you)g(need)g(mor)o(e)g(details,)g(R)n(TFC)16361176 y Fo(2)1656 1191 y Fq(.)165 1334 y Fs(4)60 b(An)14b(example:)19 b(the)14 b(T)-7 b(estDBF)14 b(\256le)h(editor)1651429 y Fq(This)8 b(is)g(an)g(elementary)f(C-style)g(console)g(application,)i(pr)o(oposing)e(a)h(few)f(tools)g(to)g(edit)g(DBF)1651479 y(\256les.)16 b(It)11 b(does)g(not)g(demonstrate)eFe(all)i Fq(of)g(the)f(possibilities)g(of)h Fn(CDBFile)pFq(,)g(but)g(it)f(shows)g(you)165 1528 y(most)f(of)h(them.)k(Also,)d(note)e(that)h(not)g(all)g(the)g(shortkeys)g(ar)o(e)h(displayed)g(on)f(the)g(top)g(line)h(of)165 1578 y(the)f(console)f(when)h(you)g(launch)h(the)f(pr)o(ogram.)k(This)c(is)g(a)g(typically)g(user)o(-unfriendly)i(\(but)165 1628 y(hopefully)e(hacker/pr)o(ogrammer)o(-friendly\))i(application.)227 1678 y(If)e(you)h(take)e(a)h(look)g(at)g(the)f(sour)o(ce)i(code)g(\()p Fn("testdbf.cpp")p Fq(\),)e(you)h(will)g(have)h(a)f(better)165 1728 y(idea)e(of)e(how)h(the)g Fn(CDBFile)gFq(objects)f(and)i(its)f(methods)f(should)i(be)f(used)g(within)g(a)g(pr)o(ogram.)165 1778 y(The)j Fn("case)24 b('e')h(:")8b Fq(part)h(of)g(the)f Fn(main\(\))h Fq(function)f(particularly)i(deserves)f(your)g(atten-)165 1827 y(tion:)k(it)c(shows)f(how)g(to)h(implement)f(a)g(generic)j(r)o(ecor)o(d)f(editor)f(using)h(that)e(package)h(\(which)165 1877 y(is)h(non-trivial\).)2271927 y(I)f(will)h(not)e(comment)g(mor)o(e)h(on)g(that)g(application:)k(the)8 b(best)h(thing)g(for)g(you)g(is)g(de\256nitely)1651977 y(to)h(have)g(a)g(look)g(at)g(the)g(sour)o(ce)g(code.)15b Fc(Hmmm...)f(Didn')o(t)9 b(I)h(say)e(that)i(earlier)e(on?)j(I'm)f(not)g(sur)o(e...)i Fd(:-\))165 2120 y Fs(5)60 b(Conclusion)1652214 y Fq(W)l(ell,)9 b(that's)f(all)h(for)g(the)g(time)f(being.)14b(I'm)8 b(not)h(quite)f(sur)o(e)i(that)e(I)h(will)g(have)g(time)g(enough)g(to)165 2264 y(support)e(that)f(package)i(in)g(the)f(next)g(few)g(months,)h(but)f(I)g(will)h(do)f(my)h(best.)k(However)m(,)c(if)f(you)165 2314 y(have)h(some)e(questions)g(\(in)h(spite)f(of)h(all)g(the)g(ef)o(forts)f(I)h(did)i(to)d(make)h(that)f(pr)o(oject)h(understand-)165 2364 y(able)14 b(:-\),)i(comments)d(or)i(bug)f(r)o(eports,)i(just)d(e-mail)h(me)g(at:)22 b Fn(herve.gourmelon@ens-)1652413 y(sat.fr)10 b Fq(\(until)g(April)h(98\).)227 2463y(As)c(far)g(as)g(the)f(portability)g(is)h(concerned,)j(I)d(only)g(tried)g(that)f(package)h(under)h(Micr)o(o$oft's)1652513 y(V)n(isual)f(C++.)14 b(Porting)7 b(it)g(to)g(Borland's)h(or)f(W)l(atcom's)f(should)h(be)h(no)f(tr)o(ouble,)h(but)f(bewar)o(e)h(of)1652563 y(the)i(de\256nition)h(of)f(the)g Fn(BOOL)g Fq(type)g(in)hFn(cdbfile.h)p Fq(:)j(you)c(might)g(have)h(to)f(modify)g(it)g(using)1652613 y(pr)o(e-compilation)h(dir)o(ectives.)19 b(If)11b(you)g(want)g(ot)g(use)g(it)g(under)h(UNIX/Linux)h(\(using)fFn(cc)f Fq(or)165 2663 y Fn(gcc)p Fq(\),)e(you)f(should)h(be)f(able)h(to)e(\256nd)j(a)e(special)g(GNU/Linux)j(version)e(that)e(I)i(r)o(eleased)g(lately)165 2712 y(in)i(the)f(Linux)i(part)e(of)g(the)h(Sunsite)f(ar)o(chive)i(\(that)d(version)i(is)f(easier)h(to)f(port,)g(by)h(the)f(way\),)p 165 2751 600 2 v 207 2777 a Fl(2)2252789 y Fk(Read)e(The)h(F***ing)g(Code\256les!)894 2960y Fq(10)p eop%%Page: 11 1111 10 bop 165 195 a Fq(as)10 b(follows:)165 245 y Fb(ftp://sunsite.unc.)o(edu/pub/Linux/devel/)o(db/cdb\256le.t)o(ar)n(.)o(gz)227 295 y Fq(If)h(you)f(decide)i(to)e(impr)o(ove)h(signi\256cantly)f(the)h(code)g(and)f(to)g(add)h(new)g(functionalities,)165345 y(please)c(contact)h(me:)13 b(I)8 b(will)g(pr)o(ovide)i(you)e(with)f(the)h(L)1009 336 y Fa(A)1025 345 y Fq(T)1043 354 y(E)1065345 y(X)g(sour)o(ce)g(of)g(the)g(postscript)f(\256le)h(you)165394 y(ar)o(e)13 b(r)o(eading,)h(so)d(that)g(you)h(can)h(add)g(the)f(description)g(of)g(your)g(new)g(functions)g(or)g(objects)165444 y(and)h(your)g(name)f(will)g(be)h(added)g(to)f(the)g(contributor)s('s)g(\256le)h(of)f(the)g(package,)i(and)f(to)f(this)165494 y(page.)802 585 y Fj(Have)h(fun!)165 728 y Fs(6)60b(Contributors)165 823 y Fr(Herv)s(\302)-17 b(e)10 b(GOURMELON)165873 y Fn(herve.gourmelon@enssat.fr)165 972 y Fr(Erik)h(Bachmann)gFq(\(for)f(the)g(GNU/Linux)i(version\))165 1022 y Fn(ebp@dde.dk)1751072 y Fb(http://www)n(.geocities.com)o(/S)o(iliconV)m(alley/Pines/2563/)227 1240 y Fq(I)f(hope)f(that)f(several)h(other)g(people)g(will)g(add)h(their)g(names)e(to)h(that)f(list...)8952960 y(1)n(1)p eop%%Trailerenduserdict /end-hook known{end-hook}if%%EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -