Source File Organization

Richard Caley rjc at uk.ac.ed.cstr
Sat Mar 2 10:37:07 AEST 1991


In article <1991Feb26.045242.23453 at rfengr.com>, Rick Farris (rf) writes:

rf> My problem is: How do I keep the darn things in sync?

I had to do this for six or seven sets of things in a library. I
decided to write a short shell script to write all the code for me. I
created a file containing the names and any data to be associated with
them and the shell script creats a header and a c file

a file called people with...

	char *name	int age
fred	fred		24
mary	mary		30

would give a header person.h containing

enum person
	{
	pe_NIL= -1,
	pe_fred=0,
	pe_mary=1,
	pe_number=2,
	};

struct person_rec
	{
	char *name;
	int age;
	};

struct person_rec person_data;

enum person person_with_name(char *name);
enum person person_with_age(int age);

and a c file person.c contining the definition of person_data and the
code for the search routines (left as an exercise for the reader).

The Makefile takes care of recreating the files when needed and
nothing can get out of step. Also saves lots of tedious coding of
access routines which are isomorphic for all the tables.

(the reson for having a separate "name" field is that often things
 have names which are not legal c tokens).

--
rjc at cstr.ed.ac.uk



More information about the Comp.lang.c mailing list