dnl This file is part of grecs dnl Copyright (C) 2007, 2009-2011 Sergey Poznyakoff dnl dnl Grecs is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by dnl the Free Software Foundation; either version 3, or (at your option) dnl any later version. dnl dnl Grecs is distributed in the hope that it will be useful, dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the dnl GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with Grecs. If not, see . divert(-1) changequote([<,>]) changecom(/*,*/) dnl _getopt_mangle_option(NAME) dnl --------------------------- dnl Convert NAME to a valid m4 identifier, by replacing invalid characters dnl with underscores, and prepend the _GETOPT_OPTION_ suffix to it. define([<_getopt_mangle_option>], [<[<_GETOPT_OPTION_>]patsubst($1, [<[^a-zA-Z0-9_]>], [<_>])>]) dnl _getopt_set_option(NAME[=VAL]) dnl ------------------------------ dnl Set option NAME. define([<_getopt_set_option>], [],=),-1,[], [],\([^=]+\)=\(.*\), [<_getopt_mangle_option(\1),[<\2>]>]))>])>]) dnl _getopt_get_option(NAME[,DEFAULT]) dnl ------------------------------ define([<_getopt_get_option>], [<_getopt_if_option_set($1,[],[<$2>])>]) dnl _getopt_if_option_set(NAME,IF-SET,IF-NOT-SET) dnl --------------------------------------------- dnl Check if option NAME is set. define([<_getopt_if_option_set>], []),[<$2>],[<$3>])>]) dnl _getopt_option_switch(NAME1,IF-SET1,[NAME2,IF-SET2,[...]],[IF-NOT-SET]) dnl ------------------------------------------------------------------------ dnl If NAME1 is set, run IF-SET1. Otherwise, if NAME2 is set, run IF-SET2. dnl Continue the process for all name-if-set pairs within [...]. If none dnl of the options is set, run IF-NOT-SET. define([<_getopt_option_switch>], [],,[<_getopt_if_option_set($@)>], [<$3>],,[<_getopt_if_option_set($@)>], [<_getopt_if_option_set([<$1>],[<$2>], [<_getopt_option_switch(shift(shift($@)))>])>])>]) dnl _getopt_if_option_val(NAME,val,IF-TRUE,IF-FALSE) dnl --------------------------------------------- dnl Check if option NAME is set. define([<_getopt_if_option_val>], []),[<$2>],[<$3>],[<$4>])>]) define([<__getopt_switch_option_val>], [],2,[<$2>],dnl [<$#>],3,[],[<$2>],[<$3>])>],dnl [],[<$2>],[<$3>],dnl [<__getopt_switch_option_val([<$1>],shift(shift(shift($@))))>])>])>]) dnl _getopt_switch_option_val(NAME,val1,IF-VAL1,val2,IF-VAL2...,ELSE) dnl ----------------------------------------------------------------- dnl Check if option NAME is set. define([<_getopt_switch_option_val>], [],[<_getopt_get_option($1)>])dnl __getopt_switch_option_val(val, shift($@))[<>]dnl popdef([])>]) dnl _getopt_set_options(OPTION[,OPTION...]) dnl --------------------------------------- dnl Set options given as arguments. define([<_getopt_set_options>], [],,, [<_getopt_set_option([<$1>]) _getopt_set_options(shift($@))>])>]) dnl format_authors(name[,name...]) dnl ------------------------------ define([],dnl [],,NULL,[<"$1", format_authors(shift($@))>])>]) dnl upcase(ARGS...) dnl Concatenate and convert ARGS to upper case. dnl define([], [], [], [])>]) dnl concat(ARGS...) dnl Concatenate arguments, inserting ", " between each of pair of them. dnl define([],[],1,[<$1>],[<$1, concat(shift($@))>])>]) dnl flushleft(ARGS...) dnl Concatenate ARGS and remove any leading whitespace dnl define([], [], [<^[ ]+>])>]) dnl chop(ARGS...) dnl Concatenate ARGS and remove any trailing whitespace dnl define([], [], [<[ ]+$>])>]) dnl escape(ARGS...) dnl Concatenate ARGS and escape any occurrences of double-quotes with dnl backslashes. dnl define([], [],[<[\"]>],[<\\\&>])>]) dnl prep(ARG) dnl Prepare ARG for including in C strings: replace newlines with any amount dnl of preceding and following whitespace by a single space character, remove dnl leading whitespace, and escape double-quotes. dnl define([], [],[<[ ]* +[ ]*>],[< >])))>]) dnl SHORT_OPTS dnl Accumulator for the 3rd argument of getopt_long dnl define([],[<>]) dnl GROUP(STRING) dnl Begin a named group of options dnl define([],[])") }, divert(-1)>]) define([<__GATHER_OPTIONS>],[< define([],ifelse([<$2>],,[]upcase(patsubst($1,-,_)),'$2')) ifelse([<$2>],,[< divert(1) KEY, divert(-1) >]) define([],ifdef([],SELECTOR) case KEY:) ifelse([<$1>],,,[< divert(2) { "$1", ARGTYPE, 0, KEY }, divert(-1)>]) dnl define([],SHORT_OPTS[<>]dnl ifelse([<$2>],,,$2[<>]ifelse(ARGTYPE,[],,ARGTYPE,[],:,ARGTYPE,[],::))) dnl ifelse([<$1>],,,dnl [],ifelse(LONG_TAG,,[<--$1>],[]))>]) ifelse([<$2>],,,dnl [],ifelse(SHORT_TAG,,[<-$2>],[]))>]) >]) dnl OPTION(long-opt, short-opt, [arg], [descr]) dnl Introduce a command line option. Arguments: dnl long-opt Long option. dnl short-opt Short option (a single char) dnl (At least one of long-opt or short-opt must be present) dnl dnl Optional arguments: dnl arg Option argument. dnl descr Option description dnl dnl If arg is absent, the option does not take any arguments. If arg is dnl enclosed in square brackets, the option takes an optional argument. dnl Otherwise, the argument is required. dnl dnl If descr is not given the option will not appear in the --help and dnl --usage outputs. dnl define([