Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d9991c

Browse files
committed
psql: add asciidoc output format
Patch by Szymon Guz, adjustments by meTesting by Michael Paquier, Pavel Stehule
1 parent0cf16b4 commit9d9991c

File tree

8 files changed

+470
-6
lines changed

8 files changed

+470
-6
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ lo_import 152801
20902090
<para>
20912091
Sets the output format to one of <literal>unaligned</literal>,
20922092
<literal>aligned</literal>, <literal>wrapped</literal>,
2093-
<literal>html</literal>,
2093+
<literal>html</literal>, <literal>asciidoc</literal>,
20942094
<literal>latex</literal> (uses <literal>tabular</literal>),
20952095
<literal>latex-longtable</literal>, or
20962096
<literal>troff-ms</literal>.
@@ -2119,7 +2119,7 @@ lo_import 152801
21192119
</para>
21202120

21212121
<para>
2122-
The <literal>html</>, <literal>latex</>,
2122+
The <literal>html</>, <literal>asciidoc</>, <literal>latex</>,
21232123
<literal>latex-longtable</literal>, and <literal>troff-ms</>
21242124
formats put out tables that are intended to
21252125
be included in documents using the respective mark-up

‎src/bin/psql/command.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,9 @@ _align2string(enum printFormat in)
22492249
casePRINT_HTML:
22502250
return"html";
22512251
break;
2252+
casePRINT_ASCIIDOC:
2253+
return"asciidoc";
2254+
break;
22522255
casePRINT_LATEX:
22532256
return"latex";
22542257
break;
@@ -2325,6 +2328,8 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
23252328
popt->topt.format=PRINT_WRAPPED;
23262329
elseif (pg_strncasecmp("html",value,vallen)==0)
23272330
popt->topt.format=PRINT_HTML;
2331+
elseif (pg_strncasecmp("asciidoc",value,vallen)==0)
2332+
popt->topt.format=PRINT_ASCIIDOC;
23282333
elseif (pg_strncasecmp("latex",value,vallen)==0)
23292334
popt->topt.format=PRINT_LATEX;
23302335
elseif (pg_strncasecmp("latex-longtable",value,vallen)==0)
@@ -2333,7 +2338,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
23332338
popt->topt.format=PRINT_TROFF_MS;
23342339
else
23352340
{
2336-
psql_error("\\pset: allowed formats are unaligned, aligned, wrapped, html, latex, troff-ms\n");
2341+
psql_error("\\pset: allowed formats are unaligned, aligned, wrapped, html,asciidoc,latex, troff-ms\n");
23372342
return false;
23382343
}
23392344

‎src/bin/psql/help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ helpVariables(unsigned short int pager)
351351
fprintf(output,_(" expanded (or x) toggle expanded output\n"));
352352
fprintf(output,_(" fieldsep field separator for unaligned output (default '|')\n"));
353353
fprintf(output,_(" fieldsep_zero set field separator in unaligned mode to zero\n"));
354-
fprintf(output,_(" format set output format [unaligned, aligned, wrapped, html,latex,..]\n"));
354+
fprintf(output,_(" format set output format [unaligned, aligned, wrapped, html,asciidoc, ...]\n"));
355355
fprintf(output,_(" footer enable or disable display of the table footer [on, off]\n"));
356356
fprintf(output,_(" linestyle set the border line drawing style [ascii, old-ascii, unicode]\n"));
357357
fprintf(output,_(" null set the string to be printed in place of a null value\n"));

‎src/bin/psql/print.c

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,227 @@ print_html_vertical(const printTableContent *cont, FILE *fout)
18781878
}
18791879

18801880

1881+
/*************************/
1882+
/* ASCIIDOC */
1883+
/*************************/
1884+
1885+
staticvoid
1886+
asciidoc_escaped_print(constchar*in,FILE*fout)
1887+
{
1888+
constchar*p;
1889+
for (p=in;*p;p++)
1890+
{
1891+
switch(*p)
1892+
{
1893+
case'|':
1894+
fputs("\\|",fout);
1895+
break;
1896+
default:
1897+
fputc(*p,fout);
1898+
}
1899+
}
1900+
}
1901+
1902+
staticvoid
1903+
print_asciidoc_text(constprintTableContent*cont,FILE*fout)
1904+
{
1905+
boolopt_tuples_only=cont->opt->tuples_only;
1906+
unsigned shortopt_border=cont->opt->border;
1907+
unsignedinti;
1908+
constchar*const*ptr;
1909+
1910+
if (cancel_pressed)
1911+
return;
1912+
1913+
if (cont->opt->start_table)
1914+
{
1915+
/* print table in new paragraph - enforce preliminary new line */
1916+
fputs("\n",fout);
1917+
1918+
/* print title */
1919+
if (!opt_tuples_only&&cont->title)
1920+
{
1921+
fputs(".",fout);
1922+
fputs(cont->title,fout);
1923+
fputs("\n",fout);
1924+
}
1925+
1926+
/* print table [] header definition */
1927+
fprintf(fout,"[%scols=\"", !opt_tuples_only ?"options=\"header\"," :"");
1928+
for(i=0;i<cont->ncolumns;i++)
1929+
{
1930+
if (i!=0)
1931+
fputs(",",fout);
1932+
fprintf(fout,"%s",cont->aligns[(i) %cont->ncolumns]=='r' ?">l" :"<l");
1933+
}
1934+
fputs("\"",fout);
1935+
switch (opt_border)
1936+
{
1937+
case0:
1938+
fputs(",frame=\"none\",grid=\"none\"",fout);
1939+
break;
1940+
case1:
1941+
fputs(",frame=\"none\"",fout);
1942+
break;
1943+
case2:
1944+
fputs(",frame=\"all\",grid=\"all\"",fout);
1945+
break;
1946+
}
1947+
fputs("]\n",fout);
1948+
fputs("|====\n",fout);
1949+
1950+
/* print headers */
1951+
if (!opt_tuples_only)
1952+
{
1953+
for (ptr=cont->headers;*ptr;ptr++)
1954+
{
1955+
if (ptr!=cont->headers)
1956+
fputs(" ",fout);
1957+
fputs("^l|",fout);
1958+
asciidoc_escaped_print(*ptr,fout);
1959+
}
1960+
fputs("\n",fout);
1961+
}
1962+
}
1963+
1964+
/* print cells */
1965+
for (i=0,ptr=cont->cells;*ptr;i++,ptr++)
1966+
{
1967+
if (i %cont->ncolumns==0)
1968+
{
1969+
if (cancel_pressed)
1970+
break;
1971+
}
1972+
1973+
if (i %cont->ncolumns!=0)
1974+
fputs(" ",fout);
1975+
fputs("|",fout);
1976+
1977+
/* protect against needless spaces */
1978+
if ((*ptr)[strspn(*ptr," \t")]=='\0')
1979+
{
1980+
if ((i+1) %cont->ncolumns!=0)
1981+
fputs(" ",fout);
1982+
}
1983+
else
1984+
asciidoc_escaped_print(*ptr,fout);
1985+
1986+
if ((i+1) %cont->ncolumns==0)
1987+
fputs("\n",fout);
1988+
}
1989+
1990+
fputs("|====\n",fout);
1991+
1992+
if (cont->opt->stop_table)
1993+
{
1994+
printTableFooter*footers=footers_with_default(cont);
1995+
1996+
/* print footers */
1997+
if (!opt_tuples_only&&footers!=NULL&& !cancel_pressed)
1998+
{
1999+
printTableFooter*f;
2000+
2001+
fputs("\n....\n",fout);
2002+
for (f=footers;f;f=f->next)
2003+
{
2004+
fputs(f->data,fout);
2005+
fputs("\n",fout);
2006+
}
2007+
fputs("....\n",fout);
2008+
}
2009+
}
2010+
}
2011+
2012+
staticvoid
2013+
print_asciidoc_vertical(constprintTableContent*cont,FILE*fout)
2014+
{
2015+
boolopt_tuples_only=cont->opt->tuples_only;
2016+
unsigned shortopt_border=cont->opt->border;
2017+
unsigned longrecord=cont->opt->prior_records+1;
2018+
unsignedinti;
2019+
constchar*const*ptr;
2020+
2021+
if (cancel_pressed)
2022+
return;
2023+
2024+
if (cont->opt->start_table)
2025+
{
2026+
/* print table in new paragraph - enforce preliminary new line */
2027+
fputs("\n",fout);
2028+
2029+
/* print title */
2030+
if (!opt_tuples_only&&cont->title)
2031+
{
2032+
fputs(".",fout);
2033+
fputs(cont->title,fout);
2034+
fputs("\n",fout);
2035+
}
2036+
2037+
/* print table [] header definition */
2038+
fputs("[cols=\"h,l\"",fout);
2039+
switch (opt_border)
2040+
{
2041+
case0:
2042+
fputs(",frame=\"none\",grid=\"none\"",fout);
2043+
break;
2044+
case1:
2045+
fputs(",frame=\"none\"",fout);
2046+
break;
2047+
case2:
2048+
fputs(",frame=\"all\",grid=\"all\"",fout);
2049+
break;
2050+
}
2051+
fputs("]\n",fout);
2052+
fputs("|====\n",fout);
2053+
}
2054+
2055+
/* print records */
2056+
for (i=0,ptr=cont->cells;*ptr;i++,ptr++)
2057+
{
2058+
if (i %cont->ncolumns==0)
2059+
{
2060+
if (cancel_pressed)
2061+
break;
2062+
if (!opt_tuples_only)
2063+
fprintf(fout,
2064+
"2+^|Record %lu\n",
2065+
record++);
2066+
else
2067+
fputs("2+|\n",fout);
2068+
}
2069+
2070+
fputs("<l|",fout);
2071+
asciidoc_escaped_print(cont->headers[i %cont->ncolumns],fout);
2072+
2073+
fprintf(fout," %s|",cont->aligns[i %cont->ncolumns]=='r' ?">l" :"<l");
2074+
/* is string only whitespace? */
2075+
if ((*ptr)[strspn(*ptr," \t")]=='\0')
2076+
fputs(" ",fout);
2077+
else
2078+
asciidoc_escaped_print(*ptr,fout);
2079+
fputs("\n",fout);
2080+
}
2081+
2082+
fputs("|====\n",fout);
2083+
2084+
if (cont->opt->stop_table)
2085+
{
2086+
/* print footers */
2087+
if (!opt_tuples_only&&cont->footers!=NULL&& !cancel_pressed)
2088+
{
2089+
printTableFooter*f;
2090+
2091+
fputs("\n....\n",fout);
2092+
for (f=cont->footers;f;f=f->next)
2093+
{
2094+
fputs(f->data,fout);
2095+
fputs("\n",fout);
2096+
}
2097+
fputs("....\n",fout);
2098+
}
2099+
}
2100+
}
2101+
18812102
/*************************/
18822103
/* LaTeX */
18832104
/*************************/
@@ -2872,6 +3093,12 @@ printTable(const printTableContent *cont, FILE *fout, FILE *flog)
28723093
else
28733094
print_html_text(cont,fout);
28743095
break;
3096+
casePRINT_ASCIIDOC:
3097+
if (cont->opt->expanded==1)
3098+
print_asciidoc_vertical(cont,fout);
3099+
else
3100+
print_asciidoc_text(cont,fout);
3101+
break;
28753102
casePRINT_LATEX:
28763103
if (cont->opt->expanded==1)
28773104
print_latex_vertical(cont,fout);

‎src/bin/psql/print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum printFormat
1818
PRINT_ALIGNED,
1919
PRINT_WRAPPED,
2020
PRINT_HTML,
21+
PRINT_ASCIIDOC,
2122
PRINT_LATEX,
2223
PRINT_LATEX_LONGTABLE,
2324
PRINT_TROFF_MS

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,8 +3790,8 @@ psql_completion(const char *text, int start, int end)
37903790
if (strcmp(prev_wd,"format")==0)
37913791
{
37923792
staticconstchar*constmy_list[]=
3793-
{"unaligned","aligned","wrapped","html","latex",
3794-
"troff-ms",NULL};
3793+
{"unaligned","aligned","wrapped","html","asciidoc",
3794+
"latex","latex-longtable","troff-ms",NULL};
37953795

37963796
COMPLETE_WITH_LIST_CS(my_list);
37973797
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp