From 9c6a1e47aee7e8b1d07b5d6009a3b614867bab46 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Sun, 1 Oct 2017 19:49:44 -0400 Subject: [PATCH] Added -export-config and -export-default-config so that users can generate a starting config style with every option, suitable for rc files. --- console/tidy.c | 174 ++++++++++++++++++++++++--------- include/tidyenum.h | 2 + localize/translations/tidy.pot | 10 +- src/language_en.h | 2 + 4 files changed, 143 insertions(+), 45 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index 015b211..4e2fdc3 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -345,58 +345,60 @@ typedef struct { ** specified by the subKey field. */ static const CmdOptDesc cmdopt_defs[] = { - { CmdOptFileManip, "-output <%s>", TC_OPT_OUTPUT, TC_LABEL_FILE, "output-file: <%s>", "-o <%s>" }, - { CmdOptFileManip, "-config <%s>", TC_OPT_CONFIG, TC_LABEL_FILE, NULL }, - { CmdOptFileManip, "-file <%s>", TC_OPT_FILE, TC_LABEL_FILE, "error-file: <%s>", "-f <%s>" }, - { CmdOptFileManip, "-modify", TC_OPT_MODIFY, 0, "write-back: yes", "-m" }, - { CmdOptProcDir, "-indent", TC_OPT_INDENT, 0, "indent: auto", "-i" }, - { CmdOptProcDir, "-wrap <%s>", TC_OPT_WRAP, TC_LABEL_COL, "wrap: <%s>", "-w <%s>" }, - { CmdOptProcDir, "-upper", TC_OPT_UPPER, 0, "uppercase-tags: yes", "-u" }, - { CmdOptProcDir, "-clean", TC_OPT_CLEAN, 0, "clean: yes", "-c" }, - { CmdOptProcDir, "-bare", TC_OPT_BARE, 0, "bare: yes", "-b" }, - { CmdOptProcDir, "-gdoc", TC_OPT_GDOC, 0, "gdoc: yes", "-g" }, - { CmdOptProcDir, "-numeric", TC_OPT_NUMERIC, 0, "numeric-entities: yes", "-n" }, - { CmdOptProcDir, "-errors", TC_OPT_ERRORS, 0, "markup: no", "-e" }, - { CmdOptProcDir, "-quiet", TC_OPT_QUIET, 0, "quiet: yes", "-q" }, - { CmdOptProcDir, "-omit", TC_OPT_OMIT, 0, "omit-optional-tags: yes" }, - { CmdOptProcDir, "-xml", TC_OPT_XML, 0, "input-xml: yes" }, - { CmdOptProcDir, "-asxml", TC_OPT_ASXML, 0, "output-xhtml: yes", "-asxhtml" }, - { CmdOptProcDir, "-ashtml", TC_OPT_ASHTML, 0, "output-html: yes" }, + { CmdOptFileManip, "-output <%s>", TC_OPT_OUTPUT, TC_LABEL_FILE, "output-file: <%s>", "-o <%s>" }, + { CmdOptFileManip, "-config <%s>", TC_OPT_CONFIG, TC_LABEL_FILE, NULL }, + { CmdOptFileManip, "-file <%s>", TC_OPT_FILE, TC_LABEL_FILE, "error-file: <%s>", "-f <%s>" }, + { CmdOptFileManip, "-modify", TC_OPT_MODIFY, 0, "write-back: yes", "-m" }, + { CmdOptProcDir, "-indent", TC_OPT_INDENT, 0, "indent: auto", "-i" }, + { CmdOptProcDir, "-wrap <%s>", TC_OPT_WRAP, TC_LABEL_COL, "wrap: <%s>", "-w <%s>" }, + { CmdOptProcDir, "-upper", TC_OPT_UPPER, 0, "uppercase-tags: yes", "-u" }, + { CmdOptProcDir, "-clean", TC_OPT_CLEAN, 0, "clean: yes", "-c" }, + { CmdOptProcDir, "-bare", TC_OPT_BARE, 0, "bare: yes", "-b" }, + { CmdOptProcDir, "-gdoc", TC_OPT_GDOC, 0, "gdoc: yes", "-g" }, + { CmdOptProcDir, "-numeric", TC_OPT_NUMERIC, 0, "numeric-entities: yes", "-n" }, + { CmdOptProcDir, "-errors", TC_OPT_ERRORS, 0, "markup: no", "-e" }, + { CmdOptProcDir, "-quiet", TC_OPT_QUIET, 0, "quiet: yes", "-q" }, + { CmdOptProcDir, "-omit", TC_OPT_OMIT, 0, "omit-optional-tags: yes" }, + { CmdOptProcDir, "-xml", TC_OPT_XML, 0, "input-xml: yes" }, + { CmdOptProcDir, "-asxml", TC_OPT_ASXML, 0, "output-xhtml: yes", "-asxhtml" }, + { CmdOptProcDir, "-ashtml", TC_OPT_ASHTML, 0, "output-html: yes" }, #if SUPPORT_ACCESSIBILITY_CHECKS - { CmdOptProcDir, "-access <%s>", TC_OPT_ACCESS, TC_LABEL_LEVL, "accessibility-check: <%s>" }, + { CmdOptProcDir, "-access <%s>", TC_OPT_ACCESS, TC_LABEL_LEVL, "accessibility-check: <%s>" }, #endif - { CmdOptCharEnc, "-raw", TC_OPT_RAW, 0, NULL }, - { CmdOptCharEnc, "-ascii", TC_OPT_ASCII, 0, NULL }, - { CmdOptCharEnc, "-latin0", TC_OPT_LATIN0, 0, NULL }, - { CmdOptCharEnc, "-latin1", TC_OPT_LATIN1, 0, NULL }, + { CmdOptCharEnc, "-raw", TC_OPT_RAW, 0, NULL }, + { CmdOptCharEnc, "-ascii", TC_OPT_ASCII, 0, NULL }, + { CmdOptCharEnc, "-latin0", TC_OPT_LATIN0, 0, NULL }, + { CmdOptCharEnc, "-latin1", TC_OPT_LATIN1, 0, NULL }, #ifndef NO_NATIVE_ISO2022_SUPPORT - { CmdOptCharEnc, "-iso2022", TC_OPT_ISO2022, 0, NULL }, + { CmdOptCharEnc, "-iso2022", TC_OPT_ISO2022, 0, NULL }, #endif - { CmdOptCharEnc, "-utf8", TC_OPT_UTF8, 0, NULL }, - { CmdOptCharEnc, "-mac", TC_OPT_MAC, 0, NULL }, - { CmdOptCharEnc, "-win1252", TC_OPT_WIN1252, 0, NULL }, - { CmdOptCharEnc, "-ibm858", TC_OPT_IBM858, 0, NULL }, + { CmdOptCharEnc, "-utf8", TC_OPT_UTF8, 0, NULL }, + { CmdOptCharEnc, "-mac", TC_OPT_MAC, 0, NULL }, + { CmdOptCharEnc, "-win1252", TC_OPT_WIN1252, 0, NULL }, + { CmdOptCharEnc, "-ibm858", TC_OPT_IBM858, 0, NULL }, #if SUPPORT_UTF16_ENCODINGS - { CmdOptCharEnc, "-utf16le", TC_OPT_UTF16LE, 0, NULL }, - { CmdOptCharEnc, "-utf16be", TC_OPT_UTF16BE, 0, NULL }, - { CmdOptCharEnc, "-utf16", TC_OPT_UTF16, 0, NULL }, + { CmdOptCharEnc, "-utf16le", TC_OPT_UTF16LE, 0, NULL }, + { CmdOptCharEnc, "-utf16be", TC_OPT_UTF16BE, 0, NULL }, + { CmdOptCharEnc, "-utf16", TC_OPT_UTF16, 0, NULL }, #endif #if SUPPORT_ASIAN_ENCODINGS /* #431953 - RJ */ - { CmdOptCharEnc, "-big5", TC_OPT_BIG5, 0, NULL }, - { CmdOptCharEnc, "-shiftjis", TC_OPT_SHIFTJIS, 0, NULL }, + { CmdOptCharEnc, "-big5", TC_OPT_BIG5, 0, NULL }, + { CmdOptCharEnc, "-shiftjis", TC_OPT_SHIFTJIS, 0, NULL }, #endif - { CmdOptMisc, "-version", TC_OPT_VERSION, 0, NULL, "-v" }, - { CmdOptMisc, "-help", TC_OPT_HELP, 0, NULL, "-h", "-?" }, - { CmdOptMisc, "-help-config", TC_OPT_HELPCFG, 0, NULL }, - { CmdOptMisc, "-help-env", TC_OPT_HELPENV, 0, NULL }, - { CmdOptMisc, "-show-config", TC_OPT_SHOWCFG, 0, NULL }, - { CmdOptMisc, "-help-option <%s>", TC_OPT_HELPOPT, TC_LABEL_OPT, NULL }, - { CmdOptMisc, "-language <%s>", TC_OPT_LANGUAGE, TC_LABEL_LANG, "language: <%s>" }, - { CmdOptXML, "-xml-help", TC_OPT_XMLHELP, 0, NULL }, - { CmdOptXML, "-xml-config", TC_OPT_XMLCFG, 0, NULL }, - { CmdOptXML, "-xml-strings", TC_OPT_XMLSTRG, 0, NULL }, - { CmdOptXML, "-xml-error-strings", TC_OPT_XMLERRS, 0, NULL }, - { CmdOptXML, "-xml-options-strings", TC_OPT_XMLOPTS, 0, NULL }, + { CmdOptMisc, "-version", TC_OPT_VERSION, 0, NULL, "-v" }, + { CmdOptMisc, "-help", TC_OPT_HELP, 0, NULL, "-h", "-?" }, + { CmdOptMisc, "-help-config", TC_OPT_HELPCFG, 0, NULL }, + { CmdOptMisc, "-help-env", TC_OPT_HELPENV, 0, NULL }, + { CmdOptMisc, "-show-config", TC_OPT_SHOWCFG, 0, NULL }, + { CmdOptMisc, "-export-config", TC_OPT_EXP_CFG, 0, NULL }, + { CmdOptMisc, "-export-default-config", TC_OPT_EXP_DEF, 0, NULL }, + { CmdOptMisc, "-help-option <%s>", TC_OPT_HELPOPT, TC_LABEL_OPT, NULL }, + { CmdOptMisc, "-language <%s>", TC_OPT_LANGUAGE, TC_LABEL_LANG, "language: <%s>" }, + { CmdOptXML, "-xml-help", TC_OPT_XMLHELP, 0, NULL }, + { CmdOptXML, "-xml-config", TC_OPT_XMLCFG, 0, NULL }, + { CmdOptXML, "-xml-strings", TC_OPT_XMLSTRG, 0, NULL }, + { CmdOptXML, "-xml-error-strings", TC_OPT_XMLERRS, 0, NULL }, + { CmdOptXML, "-xml-options-strings", TC_OPT_XMLOPTS, 0, NULL }, { CmdOptMisc, NULL, 0, 0, NULL } }; @@ -1498,6 +1500,78 @@ static void optionvalues( TidyDoc tdoc ) /** @} end service_show_config group */ +/* MARK: - Provide the -export-config Services */ +/***************************************************************************//** + ** @defgroup service_export_config Provide the -export-config Services + ******************************************************************************* + ** @{ + */ + + +/** Prints the option value for a given option. + */ +static void printOptionExportValues(TidyDoc ARG_UNUSED(tdoc), /**< The Tidy document. */ + TidyOption topt, /**< The option for which to show values. */ + OptionDesc *d /**< The OptionDesc array. */ + ) +{ + TidyOptionId optId = tidyOptGetId( topt ); + + if ( tidyOptGetCategory(topt) == TidyInternalCategory ) + return; + + switch ( optId ) + { + case TidyInlineTags: + case TidyBlockTags: + case TidyEmptyTags: + case TidyPreTags: + { + TidyIterator pos = tidyOptGetDeclTagList( tdoc ); + while ( pos ) + { + d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos); + if ( pos ) + { + printf( "%s: %s\n", d->name, d->def ); + d->name = ""; + d->type = ""; + } + } + } + break; + default: + break; + } + + /* fix for http://tidy.sf.net/bug/873921 */ + if ( *d->name || *d->type || (d->def && *d->def) ) + { + if ( ! d->def ) + d->def = ""; + printf( "%s: %s\n", d->name, d->def ); + } +} + +/** Handles the -export-config service. + ** @param tdoc The Tidy Document. + */ +static void exportOptionValues( TidyDoc tdoc ) +{ + ForEachSortedOption( tdoc, printOptionExportValues ); +} + +/** Handles the -export-default-config service. + ** @param tdoc The Tidy Document. + */ +static void exportDefaultOptionValues( TidyDoc tdoc ) +{ + tidyOptResetAllToDefault( tdoc ); + ForEachSortedOption( tdoc, printOptionExportValues ); +} + + +/** @} end service_export_config group */ /* MARK: - Provide the -version Service */ /***************************************************************************//** ** @defgroup service_version Provide the -version Service @@ -2194,6 +2268,18 @@ int main( int argc, char** argv ) tidyRelease( tdoc ); return 0; /* success */ } + else if ( strcasecmp(arg, "export-config") == 0 ) + { + exportOptionValues( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } + else if ( strcasecmp(arg, "export-default-config") == 0 ) + { + exportDefaultOptionValues( tdoc ); + tidyRelease( tdoc ); + return 0; /* success */ + } else if ( strcasecmp(arg, "config") == 0 ) { if ( argc >= 3 ) diff --git a/include/tidyenum.h b/include/tidyenum.h index 1357bdb..5dcac4e 100644 --- a/include/tidyenum.h +++ b/include/tidyenum.h @@ -449,6 +449,8 @@ extern "C" { FN(TC_OPT_RAW) \ FN(TC_OPT_SHIFTJIS) \ FN(TC_OPT_SHOWCFG) \ + FN(TC_OPT_EXP_CFG) \ + FN(TC_OPT_EXP_DEF) \ FN(TC_OPT_UPPER) \ FN(TC_OPT_UTF16) \ FN(TC_OPT_UTF16BE) \ diff --git a/localize/translations/tidy.pot b/localize/translations/tidy.pot index 8fce546..0f123bf 100644 --- a/localize/translations/tidy.pot +++ b/localize/translations/tidy.pot @@ -5,7 +5,7 @@ msgstr "" "Plural-Forms: nplurals=2; plural=n != 1;\n" "X-Generator: HTML Tidy poconvert.rb\n" "Project-Id-Version: \n" -"POT-Creation-Date: 2017-10-01 19:19:32\n" +"POT-Creation-Date: 2017-10-01 19:49:27\n" "Last-Translator: jderry\n" "Language-Team: \n" @@ -3213,6 +3213,14 @@ msgctxt "TC_OPT_SHOWCFG" msgid "list the current configuration settings" msgstr "" +msgctxt "TC_OPT_EXP_CFG" +msgid "list the current configuration settings, suitable for a config file" +msgstr "" + +msgctxt "TC_OPT_EXP_DEF" +msgid "list the default configuration settings, suitable for a config file" +msgstr "" + msgctxt "TC_OPT_UPPER" msgid "force tags to upper case" msgstr "" diff --git a/src/language_en.h b/src/language_en.h index 52c04f7..a3570ba 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -2132,6 +2132,8 @@ static languageDefinition language_en = { whichPluralForm_en, { { TC_OPT_RAW, 0, "output values above 127 without conversion to entities" }, { TC_OPT_SHIFTJIS, 0, "use Shift_JIS for both input and output" }, { TC_OPT_SHOWCFG, 0, "list the current configuration settings" }, + { TC_OPT_EXP_CFG, 0, "list the current configuration settings, suitable for a config file" }, + { TC_OPT_EXP_DEF, 0, "list the default configuration settings, suitable for a config file" }, { TC_OPT_UPPER, 0, "force tags to upper case" }, { TC_OPT_UTF16, 0, "use UTF-16 for both input and output" }, { TC_OPT_UTF16BE, 0, "use UTF-16BE for both input and output" },