Skip to content

Commit

Permalink
Add multiple templates generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrus-and committed Jul 27, 2012
1 parent 004b6bf commit 6973180
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/generator.h

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions src/generators.def
@@ -0,0 +1,2 @@
_( php )
#undef _
7 changes: 7 additions & 0 deletions src/generators.h
@@ -0,0 +1,7 @@
#ifndef _HTTPFS_GENERATORS_H
#define _HTTPFS_GENERATORS_H

#define _( x ) void httpfs_generate_##x();
#include "generators.def"

#endif
37 changes: 32 additions & 5 deletions src/main.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
#include "generator.h"
#include "generators.h"
#include "httpfs.h"
#include "fuse_api/fuse_api.h"

Expand All @@ -9,7 +9,8 @@ static void usage()
{
fprintf( stderr ,
"Usage:\n\n"
" httpfs generate\n"
" httpfs generators\n"
" httpfs generate <generator>\n"
" httpfs mount <url> <mount_point> [<remote_chroot>]\n" );
exit( EXIT_FAILURE );
}
Expand Down Expand Up @@ -45,12 +46,38 @@ int main( int argc , char *argv[] )
{
if ( argc == 1 ) usage();

if ( strcmp( argv[ 1 ] , "generate" ) == 0 )
if ( strcmp( argv[ 1 ] , "generators" ) == 0 )
{
if ( argc != 2 ) usage();
httpfs_generate_php();
#define _( x ) printf( #x "\n" );
#include "generators.def"
return EXIT_SUCCESS;
}
if ( strcmp( argv[ 1 ] , "generate" ) == 0 )
{
int i;
struct generator
{
const char *name;
void ( *function )();
}
generators[] = {
#define _( x ) { #x , httpfs_generate_##x } ,
#include "generators.def"
};

if ( argc != 3 ) usage();

for ( i = 0 ; i < sizeof( generators ) / sizeof( struct generator ) ; i++ )
{
if ( strcmp( generators[ i ].name , argv[ 2 ] ) == 0 )
{
generators[ i ].function();
return EXIT_SUCCESS;
}
}

usage();
}
else if ( strcmp( argv[ 1 ] , "mount" ) == 0 )
{
if ( argc != 4 && argc != 5 ) usage();
Expand Down

0 comments on commit 6973180

Please sign in to comment.