Skip to content

A script that generates enums supplied from a file.

Notifications You must be signed in to change notification settings

fabtjar/generated-names

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generated Names

An exercise from the book The Pragmatic Programmer.

Write a script that generates a name.h and name.c file with enums supplied from within the names.txt file. This would be useful to be able to print out the state as a string (as opposed to a number) for debugging purposes.

Usage

python3 generate_names.py
clang main.c --include name.c -o generated_names
./generated_names

Files generates

// name.h

#ifndef NAME_H
#define NAME_H

extern const char* NAME_names[];

typedef enum {
    state_ace,
    state_act,
    ...
    state_zap,
    state_zip,
} NAME;

#endif  // NAME_H
// name.c

const char* NAME_names[] = {
    "state_ace",
    "state_act",
    ...
    "state_zap",
    "state_zip",
};

About

A script that generates enums supplied from a file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published