Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sdd.hp.com!decwrl!elroy.jpl.nasa.gov!peregrine!dmi From: dmi@peregrine.peregrine.com (Dean Inada) Newsgroups: comp.lang.c Subject: Keeping tables in step (Was: Re: How to force cpp to abort?) Message-ID: <106848@peregrine.peregrine.com> Date: 19 Aug 90 04:44:22 GMT References: <9679@ganymede.inmos.co.uk> <3579@goanna.cs.rmit.oz.au> Reply-To: dmi@peregrine.UUCP (Dean Inada) Distribution: comp Organization: Peregrine Systems, Inc. Lines: 68 #if 0 In article <3579@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > #File: mktable.demo > > EntryCt; int whence; int whither; char *name > > Butcher; 1; 2; "Butcher" > Baker; 1; 3; "Baker" > Bellman; 2; 3; "Bellman" > Boojum; 0; 0; NULL > #End: mktable.demo > >Running the command > > awk -F";" -f mkheader.awk mktable.demo > >produces > > /* From mktable.demo */ > #define Butcher 0 > #define Baker 1 > #define Bellman 2 > #define Boojum 3 > #define EntryCt 4 > extern int whence[4]; > extern int whither[4]; > extern char *name[4]; > /* End mktable.demo */ #endif #include #define table \ x(Butcher, 1, 2, "Butcher")\ x(Baker, 1, 3, "Baker")\ x(Bellman, 2, 3, "Bellman")\ x(Boojum, 0, 0, NULL)\ /*enddefine*/ enum EntryCt { #define x(entry,whence,whither,name) entry, table EntryCt #undef x }; int whence[]={ #define x(entry,whence,whither,name) whence, table #undef x }; int whither[]={ #define x(entry,whence,whither,name) whither, table #undef x }; char *name[]={ #define x(entry,whence,whither,name) name, table #undef x }; main() { #define x(en,wn,wr,nm) \ printf("entry=%d, whence=%d, whither=%d, name=%s\r\n",\ en, whence[en], wr, name[en]); table #undef x }