diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2022-03-07 14:43:44 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2022-03-07 14:43:44 +0100 |
commit | cbcab8684e06379c9f5c51cfc9cac68d8684fe0c (patch) | |
tree | d03b04e9a7f8e3aae70e590953408f90deed077c /skeletons/main.c.erb | |
parent | 721a7ea65d23e7b149ba73968a1d75727a55b390 (diff) | |
download | vim-cbcab8684e06379c9f5c51cfc9cac68d8684fe0c.zip vim-cbcab8684e06379c9f5c51cfc9cac68d8684fe0c.tar.gz |
move to old
Diffstat (limited to 'skeletons/main.c.erb')
-rw-r--r-- | skeletons/main.c.erb | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/skeletons/main.c.erb b/skeletons/main.c.erb deleted file mode 100644 index 1767fbf..0000000 --- a/skeletons/main.c.erb +++ /dev/null @@ -1,134 +0,0 @@ -<%= header 'c.hdr' %> - -#include "main.h" - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <stdarg.h> -#include <string.h> -#include <getopt.h> - - -static int verbose = 0; - -/** - * my_error - print an error message on stderr then : if(code) exit(code) - */ -static void my_error( int code, const char *fmt, ... ) -{ - va_list ap; - - if ( *fmt ) { - va_start( ap, fmt ); - (void)vfprintf( stderr, fmt, ap ); - va_end( ap ); - fmt += strlen( fmt ); - if ( fmt[-1] != '\n' ) - (void) fputc( '\n', stderr ); - } - if( code ) exit( code ); - /* NOTREACHED */ -} - - -/** - * usage - print usage on stderr - */ -static void usage( const char *program_name, const char* optstring ) -{ - fprintf( stderr, "usage : %s [-%s]\n", program_name, optstring ); - fprintf( stderr, "\t --verbose (-v) : verbose mode.\n" - "\t --version (-V) : print version number.\n" - "\t --help (-h) : print this screen.\n" - "\t --arg (-a) <arg> : a numeric argument.\n" - "\n" ); -} - - -/** - * MAIN - */ -int main( int argc, char **argv ) -{ - int optch; /* returned by getopts_long */ - int index; /* index of longopts[] */ - - int a; - - /** - * name - has_arg (bool) - flag (int *) - val (int) - * - * if(!longopts[x].flag) - * return longopts[x].val; - * else - * *(longopts[x].flag) = longopts[x].val; - * return 0; - * - */ - static struct option longopts[] = { - { "help", 0, 0, 'h' }, - { "version", 0, 0, 'V' }, - { "verbose", 0, &verbose, 1 }, - { "arg", 1, 0, 'a' }, - { 0, 0, 0, 0, } - }; - - static char *optstring = "hvVa:"; - - static const char *program_name = PACKAGE_NAME; - /* - const char *program_name = file_name( argv[0] ); - */ - - opterr=0; /* no default advise for bad options */ - optind=0; - - a=0; - -#ifdef DEBUG - printf( "DEBUG mode is set.\n" ); -#endif - - /* process options */ - while( ( optch = getopt_long( argc, argv, optstring, longopts, &index ) ) !=-1 ) { - switch( optch ){ - case 'h': - usage( program_name, optstring ); - return EXIT_FAILURE; - case 'V': - fprintf( stdout, " %s version : %s\n", program_name, VERSION ); - return EXIT_FAILURE; - case 'v': - verbose = 1; - break; - case 'a': - a = atoi( optarg ); - break; - case 0: - /* longopt used flag */ - break; - default: - my_error(EXIT_FAILURE,"invalid option %s\n\ttype : %s --help\n",argv[optind-1],program_name); - } - } - - printf("a : %d\n",a); - - /* process other arguments */ - while(optind<argc){ - printf("argv[%d]='%s'\n",optind,argv[optind]); - optind++; - } - - if(verbose)printf("verbose mode is set.\n"); - - /** - * insert some fucking code here. - */ - - /* end reached */ - return EXIT_SUCCESS; -} - - |