84f4085838068ef9868e56bc1a393dfd838d3655
[platform/upstream/groff.git] / arch / mingw / grap2graph.cmd
1 @echo off\r
2 REM grap2graph -- compile graph description descriptions to bitmap images\r
3 REM\r
4 REM by Eli Zaretskii <eliz@gnu.org>, translation of a Unix shell\r
5 REM script written by Eric S. Raymond <esr@thyrsus.com>, May 2003\r
6 REM\r
7 REM In Unixland, the magic is in knowing what to string together...\r
8 REM\r
9 REM Take grap description on stdin, emit cropped bitmap on stdout.\r
10 REM The pic markup should *not* be wrapped in .G1/.G2, this script will do that.\r
11 REM A -U option on the command line enables gpic/groff "unsafe" mode.\r
12 REM A -format FOO option changes the image output format to any format\r
13 REM supported by convert(1).  All other options are passed to convert(1).\r
14 REM The default format is PNG.\r
15 REM\r
16 REM\r
17 REM Requires the groff suite and the ImageMagick tools.  Both are open source.\r
18 REM This code is released to the public domain.\r
19 REM\r
20 REM Here are the assumptions behind the option processing:\r
21 REM\r
22 REM 1. None of the options of grap(1) are relevant.\r
23 REM\r
24 REM 2. Only the -U option of groff(1) is relevant.\r
25 REM\r
26 REM 3. Many options of convert(1) are potentially relevant, (especially \r
27 REM -density, -interlace, -transparency, -border, and -comment).\r
28 REM\r
29 REM Thus, we pass -U to groff(1), and everything else to convert(1).\r
30 REM\r
31 setlocal\r
32 set groff_opts=\r
33 set convert_opts=\r
34 set format=png\r
35 \r
36 :loop\r
37 if "%1" == "" goto body\r
38 if "%1" == "-v" goto version\r
39 if "%1" == "--version" goto version\r
40 if "%1" == "--help" goto usage\r
41 if not "%1%" == "-unsafe" goto format\r
42 set groff_opts=-U\r
43 shift\r
44 goto loop\r
45 :format\r
46 if not "%1" == "-format" goto convert\r
47 set format=%2\r
48 shift\r
49 shift\r
50 goto loop\r
51 :convert\r
52 set convert_opts=%convert_opts% %1\r
53 shift\r
54 goto loop\r
55 \r
56 :body\r
57 REM echo %groff_opts% %convert_opts% %format%\r
58 \r
59 set rnd1=%RANDOM%\r
60 set rnd2=%RANDOM%\r
61 if "%GROFF_TMPDIR%" == "" goto deftmp\r
62 set tdir=%GROFF_TMPDIR%\grap2graph-%rnd1%\r
63 goto runpipe\r
64 :deftmp\r
65 sei tdir=%TEMP%\grap2graph-%rnd1%\r
66 \r
67 :runpipe\r
68 mkdir %tdir%\r
69 echo .G1 > %tdir%\wrap\r
70 cat >> %tdir%\wrap\r
71 echo .G2 >> %tdir%\wrap\r
72 grap %tdir%\wrap | groff -p %groff_opts% -Tps -P-pletter | convert -trim -crop 0x0 %convert_opts% - %tdir%/grap2graph.%format%\r
73 cat %tdir%/grap2graph.%format%\r
74 rm -rf %tdir%\r
75 goto end\r
76 \r
77 :version\r
78 echo GNU grap2graph (groff) version 1.22.3\r
79 goto end\r
80 \r
81 :usage\r
82 echo usage: grap2graph ^[ option ...^] ^< in ^> out\r
83 echo.\r
84 \r
85 :end\r
86 endlocal\r