On Fri, Aug 10, 2001 at 04:56:12PM +0200, Steinar Hamre wrote:
> On Fri, Aug 10, 2001 at 07:37:11PM +0530, Nikunj A. Dadhania wrote:

> all_fstypes
> ===========
> UFS
> NFS
> GFS
> LFS
> ...
> 
> a script to convert to C:
> 
> gen_printf_all_fstypes
> ======================
> #! /bin/sh
> sed 's/.*/#ifdef FSTYPE_&\
>       case FSTYPE_&:\
>               printf("&\\n");\
>               break;\
> #endif/' <$1 >$2
> 
> and then in the Makefile:
> 
> printf_all_fstypes.h: all_fstypes gen_printf_all_fstypes
>       ./gen_printf_all_fstypes $< $@

May I suggest a code generating macro instead:

#define PRINT_FS(pref, fs, suf) \
        case pref##fs##suf: \
                printf (#fs "\n"); \
                break;

And in the code:

        switch (statfsbuf.f_type) {
#ifdef FSTYPE_EXT2
                PRINT_FS(FSTYPE_,EXT2,)
#endif
#ifdef EXT2_SUPER_MAGIC
                PRINT_FS(,EXT2,SUER_MAGIC);
#endif
                ...
        }

Simpler cleaner and no need to maintain a separate list of supported
filesystems.

Igor


Reply via email to