Help!

m4: tool to auto-correct the indentation of m4 scripts

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> App Development RSS
Next:  Statistics for alt.os.linux.mandriva  
Author Message
Mark Hobley
External


Since: Jan 14, 2009
Posts: 28



PostPosted: Fri Apr 17, 2009 6:10 pm    Post subject: m4: tool to auto-correct the indentation of m4 scripts
Archived from groups: comp>os>linux>development>apps (more info?)

Is there any tools that will autocorrect the indentations in m4 scripts?

I am trying to make some changes to some m4 scripts, and the indentation does
not appear to be sane, so I am having difficulty in matching up the if and
ifelse statements with their closing parenthesis.

These scripts are big, messy, and deeply nested.

Look at this:

[
dnl Argument checking.
ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool],
, [ifelse([$1], [use-libtool], ,
[errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
])])])])])
ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-forma$
[errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
])])])])
define(gt_included_intl, ifelse([$1], [external], [no], [yes]))
define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], []))

AC_REQUIRE([AM_PO_SUBDIRS])dnl
ifelse(gt_included_intl, yes, [
AC_REQUIRE([AM_INTL_SUBDIR])dnl
])


It gets worse. I want to know which is block associated with USE_NLS in the
following example:

if test "$USE_NLS" = "yes"; then
gt_use_preinstalled_gnugettext=no

dnl Add a version number to the cache macros.
define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, if$
define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_vers$
define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_v$

AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
[AC_TRY_LINK([#include <libintl.h>
]ifelse([$2], [need-formatstring-macros],
[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
#endif
changequote(,)dnl
typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
changequote([,])dnl
], [])[extern int _nl_msg_cat_cntr;
extern int *_nl_domain_bindings;],
[bindtextdomain ("", "");
return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
gt_cv_func_gnugettext_libc=yes,
gt_cv_func_gnugettext_libc=no)])

if test "$gt_cv_func_gnugettext_libc" != "yes"; then
dnl Sometimes libintl requires libiconv, so first search for libiconv.
ifelse(gt_included_intl, yes, , [
AM_ICONV_LINK
])
dnl reduced comments.
AC_LIB_LINKFLAGS_BODY([intl])
AC_CACHE_CHECK([for GNU gettext in libintl],
gt_cv_func_gnugettext_libintl,
[gt_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $INCINTL"
gt_save_LIBS="$LIBS"
LIBS="$LIBS $LIBINTL"
dnl Now see whether libintl exists and does not depend on libiconv.
AC_TRY_LINK([#include <libintl.h>
]ifelse([$2], [need-formatstring-macros],
[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
#endif
changequote(,)dnl
typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
changequote([,])dnl
], [])[extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias ();],
[bindtextdomain ("", "");
return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
gt_cv_func_gnugettext_libintl=yes,
gt_cv_func_gnugettext_libintl=no)
dnl Now see whether libintl exists and depends on libiconv.
if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICO$
LIBS="$LIBS $LIBICONV"
AC_TRY_LINK([#include <libintl.h>

]ifelse([$2], [need-formatstring-macros],
[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
#endif
changequote(,)dnl
typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
changequote([,])dnl
], [])[extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias ();],
[bindtextdomain ("", "");
return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
[LIBINTL="$LIBINTL $LIBICONV"
LTLIBINTL="$LTLIBINTL $LTLIBICONV"
gt_cv_func_gnugettext_libintl=yes
gt_cv_func_gnugettext_libc=no)])

if test "$gt_cv_func_gnugettext_libc" != "yes"; then
dnl Sometimes libintl requires libiconv, so first search for libiconv.
ifelse(gt_included_intl, yes, , [
AM_ICONV_LINK
])
dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
dnl even if libiconv doesn't exist.
AC_LIB_LINKFLAGS_BODY([intl])
AC_CACHE_CHECK([for GNU gettext in libintl],
gt_cv_func_gnugettext_libintl,


Maybe it is further down ... but how the hell can I tell? I could really do
with a magic tool that will properly indent this lot.

Maybe to give something like this ...

if foo [
if bar [
blah blah rhubarb
])
])

Mark.

--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
Back to top
Erik Max Francis
External


Since: Jun 06, 2006
Posts: 12



PostPosted: Fri Apr 17, 2009 6:10 pm    Post subject: Re: m4: tool to auto-correct the indentation of m4 scripts [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mark Hobley wrote:
> Is there any tools that will autocorrect the indentations in m4 scripts?
>
> I am trying to make some changes to some m4 scripts, and the indentation does
> not appear to be sane, so I am having difficulty in matching up the if and
> ifelse statements with their closing parenthesis.
>
> These scripts are big, messy, and deeply nested.
>
> Look at this:
>
> [
> dnl Argument checking.
> ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool],
> , [ifelse([$1], [use-libtool], ,
> [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
> ])])])])])
> ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-forma$
> [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
> ])])])])
> define(gt_included_intl, ifelse([$1], [external], [no], [yes]))
> define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], []))
>
> AC_REQUIRE([AM_PO_SUBDIRS])dnl
> ifelse(gt_included_intl, yes, [
> AC_REQUIRE([AM_INTL_SUBDIR])dnl
> ])
>
>
> It gets worse. I want to know which is block associated with USE_NLS in the
> following example:
>
> if test "$USE_NLS" = "yes"; then
> gt_use_preinstalled_gnugettext=no
>
> dnl Add a version number to the cache macros.
> define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, if$
> define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_vers$
> define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_v$
>
> AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
> [AC_TRY_LINK([#include <libintl.h>
> ]ifelse([$2], [need-formatstring-macros],
> [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
> #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
> #endif
> changequote(,)dnl
> typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
> changequote([,])dnl
> ], [])[extern int _nl_msg_cat_cntr;
> extern int *_nl_domain_bindings;],
> [bindtextdomain ("", "");
> return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
> gt_cv_func_gnugettext_libc=yes,
> gt_cv_func_gnugettext_libc=no)])
>
> if test "$gt_cv_func_gnugettext_libc" != "yes"; then
> dnl Sometimes libintl requires libiconv, so first search for libiconv.
> ifelse(gt_included_intl, yes, , [
> AM_ICONV_LINK
> ])
> dnl reduced comments.
> AC_LIB_LINKFLAGS_BODY([intl])
> AC_CACHE_CHECK([for GNU gettext in libintl],
> gt_cv_func_gnugettext_libintl,
> [gt_save_CPPFLAGS="$CPPFLAGS"
> CPPFLAGS="$CPPFLAGS $INCINTL"
> gt_save_LIBS="$LIBS"
> LIBS="$LIBS $LIBINTL"
> dnl Now see whether libintl exists and does not depend on libiconv.
> AC_TRY_LINK([#include <libintl.h>
> ]ifelse([$2], [need-formatstring-macros],
> [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
> #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
> #endif
> changequote(,)dnl
> typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
> changequote([,])dnl
> ], [])[extern int _nl_msg_cat_cntr;
> extern
> #ifdef __cplusplus
> "C"
> #endif
> const char *_nl_expand_alias ();],
> [bindtextdomain ("", "");
> return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
> gt_cv_func_gnugettext_libintl=yes,
> gt_cv_func_gnugettext_libintl=no)
> dnl Now see whether libintl exists and depends on libiconv.
> if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICO$
> LIBS="$LIBS $LIBICONV"
> AC_TRY_LINK([#include <libintl.h>
>
> ]ifelse([$2], [need-formatstring-macros],
> [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
> #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
> #endif
> changequote(,)dnl
> typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
> changequote([,])dnl
> ], [])[extern int _nl_msg_cat_cntr;
> extern
> #ifdef __cplusplus
> "C"
> #endif
> const char *_nl_expand_alias ();],
> [bindtextdomain ("", "");
> return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("",$
> [LIBINTL="$LIBINTL $LIBICONV"
> LTLIBINTL="$LTLIBINTL $LTLIBICONV"
> gt_cv_func_gnugettext_libintl=yes
> gt_cv_func_gnugettext_libc=no)])
>
> if test "$gt_cv_func_gnugettext_libc" != "yes"; then
> dnl Sometimes libintl requires libiconv, so first search for libiconv.
> ifelse(gt_included_intl, yes, , [
> AM_ICONV_LINK
> ])
> dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
> dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
> dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
> dnl even if libiconv doesn't exist.
> AC_LIB_LINKFLAGS_BODY([intl])
> AC_CACHE_CHECK([for GNU gettext in libintl],
> gt_cv_func_gnugettext_libintl,
>
>
> Maybe it is further down ... but how the hell can I tell? I could really do
> with a magic tool that will properly indent this lot.

I doubt there exists such a thing. A big problem with even the concept
is that m4 is a preprocessor, but it's unspecified what it's being
processed to. That is to say, the target of the preprocessed m4 may
well be something that is indentation or whitespace sensitive, so
arbitrary re-indentation or the preprocessed m4 could break things.

If you're preprocessing to a target that _isn't_ indentation sensitive,
then it wouldn't be hard to put a quick tool together that will do the
re-indentation for you. Just count the number of open and close
delimiters (and remember that in m4 they're changeable so you'll have to
specify this as an option), and adjust the indentation on each line
depending on the current state of the open/close delimiters, with one
indentation level for each open delimiter that has not yet been closed.

--
Erik Max Francis && max.DeleteThis@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M, Skype erikmaxfrancis
Maybe I could see you / When this is over
-- Scritti Politti
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> App Development All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum