Article 13721 of alt.sources:
Path: nntpd.lkg.dec.com!crl.dec.com!news-ext.crl.dec.com!bloom-beacon.mit.edu!news-peer.gsl.net!news.gsl.net!news.mathworks.com!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!uunet!in1.uu.net!news.iij.ad.jp!wnoc-tyo-news!waseda.ac.jp!cfi.waseda!wsdnws.cfi.waseda.ac.jp!seiichi
From: seiichi@muraoka.info.waseda.ac.jp (YOSHIDA Seiichi)
Newsgroups: alt.sources
Subject: pad2ps-3.1 (9/11)
Followup-To: alt.sources
Date: 03 Nov 1996 10:33:02 GMT
Organization: Centre for Infomatics, Waseda University
Lines: 3667
Distribution: world
Message-ID: <SEIICHI.96Nov3193302@muras5.muraoka.info.waseda.ac.jp>
NNTP-Posting-Host: unknown@muras5.muraoka.info.waseda.ac.jp
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Xref: nntpd.lkg.dec.com alt.sources:13721

#!/bin/sh
# This is `pad2ps-3.1.09' (part 9 of a multipart archive).
# Do not concatenate these parts, unpack them in order with `/bin/sh'.
# File `pad2ps-3.1/src/main/main.c' is being continued...
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if test ! -r _sh23946/seq; then
  $echo 'Please unpack part 1 first!'
  exit 1
fi
shar_sequence=`cat _sh23946/seq`
if test "$shar_sequence" != 9; then
  $echo 'Please unpack part' "$shar_sequence" 'next!'
  exit 1
fi
if test ! -f _sh23946/new; then
  $echo 'x -' 'STILL SKIPPING' 'pad2ps-3.1/src/main/main.c'
else
  $echo 'x -' 'continuing file' 'pad2ps-3.1/src/main/main.c'
  sed 's/^X//' << 'SHAR_EOF' >> pad2ps-3.1/src/main/main.c &&
X		case 'n':
X		    if(strcmp(argv[i],"-noopt") == 0){
X			if(src_type == C  ||  src_type == Java)
X			    strcat(args," -noopt");
#ifdef JAPANESE
X		    }else if(strcmp(argv[i],"-noconv") == 0){
X			strcat(args," -noconv");
#endif
X		    }
X		    break;
X		case 'O':
X		    if(strcmp(argv[i],"-O") == 0){
X			if(src_type == C  ||  src_type == Java)
X			    strcat(args," -O");
X		    }
X		    break;
X		case 'P':
X		    if(strcmp(argv[i],"-P") == 0){
X			if(src_type == Pad  ||  src_type == Default)
X			    strcat(args," -P");
X			i++;
X			while(i < argc  &&  argv[i][0] != '-'){
X			    if(src_type == Pad  ||  src_type == Default){
X				strcat(args," ");
X				strcat(args,argv[i]);
X			    }
X			    i++;
X			}
X			if(src_type == Pad  ||  src_type == Default)
X			    strcat(args," -dummy");
X			i--;
X		    }
X		    break;
X		case 'q':
X		    if(strcmp(argv[i],"-quiet") == 0){
X			strcat(args," -quiet");
X		    }
X		    break;
X		case 's':
X		    if(strcmp(argv[i],"-semicolon") == 0){
X			if(src_type == C  ||  src_type == Java)
X			    strcat(args," -semicolon");
X		    }else if(strcmp(argv[i],"-stdin") == 0){
X			strcat(args," -stdin");
X		    }
X		    break;
X		case 't':
X		    if(strcmp(argv[i],"-tab") == 0){
X			i++;
X			strcat(args," -tab ");
X			strcat(args,argv[i]);
X		    }
X		    break;
X		case 'w':
X		    if(strcmp(argv[i],"-warn") == 0){
X			strcat(args," -warn");
X		    }
X		    break;
X	    }
X	}
X    }
}
X
void print_help(void)
{
X    fprintf(stderr,"\n%s %s  by %s\n\n",thiscmd,VERSION,AUTHOR);
X    fprintf(stderr,"usage: %s [inputfile [outputfile]] [options]\n",thiscmd);
X    fputs("-awk                    Draw PAD of AWK program directly.\n",stderr);
X    fputs("-c                      Draw PAD of C program directly.\n",stderr);
X    fputs("-c++                    Draw PAD of C++ program directly.\n",stderr);
X    fputs("-csh                    Draw PAD of C shell program directly.\n",stderr);
X    fputs("-D symbols ...          Define symbols. Ex: -D DEBUG __linux__  <C,C++>\n",stderr);
#ifdef DEBUG
X    fputs("-debug                  Print parser debug message.\n",stderr);
#endif
X    fputs("-dir directory          Directory to output files.\n",stderr);
X    fputs("-help                   Print help message.\n",stderr);
X    fputs("-ifdef                  Print defined symbols.  <C,C++>\n",stderr);
X    fputs("-inline                 Draw PAD of inline functions too.  <C++>\n",stderr);
X    fputs("-java                   Draw PAD of Java program directly.\n",stderr);
#ifdef JAPANESE
X    fputs("-kconv converter        Kanji code converter [default: \"nkf -e\"].\n",stderr);
X    fputs("-noconv                 Do not convert kanji code.\n",stderr);
#endif
X    fputs("-nohelp                 Do not print help message.\n",stderr);
X    fputs("-noopt                  No optimizing.  <C,C++,Java>\n",stderr);
X    fputs("-O                      Optimizing.  <C,C++,Java>\n",stderr);
X    fputs("-P parameters ...       Set parameters. Ex: -P page=1 figure=1\n",stderr);
X    fputs("-pad                    Draw PAD of PAD source (PADEL).\n",stderr);
X    fputs("-quiet                  Do not print messages.\n",stderr);
X    fputs("-semicolon              Print ';' at EOL.  <C,C++,Java>\n",stderr);
X    fputs("-sh                     Draw PAD of Bourne shell program directly.\n",stderr);
X    fputs("-stdin                  Input from stdin.\n",stderr);
X    fputs("-tab width              Set TAB width [default: 4].\n",stderr);
X    fputs("-warn                   Print warnings.\n",stderr);
}
X
#if defined(HAVE_ATEXIT) || defined(HAVE_ON_EXIT)
#if defined(HAVE_ATEXIT)
void at_exit(void)
#elif defined(HAVE_ON_EXIT)
void at_exit(int val, void *p)
#endif
/* hadle termination process */
{
X    remove(foo2padfile);
}
#endif
SHAR_EOF
  $echo 'File' 'pad2ps-3.1/src/main/main.c' 'is complete' &&
  $shar_touch -am 0820130496 'pad2ps-3.1/src/main/main.c' &&
  chmod 0644 'pad2ps-3.1/src/main/main.c' ||
  $echo 'restore of' 'pad2ps-3.1/src/main/main.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/main/main.c:' 'MD5 check failed'
3c3c74b36d3b2f93a2f84c672afddafc  pad2ps-3.1/src/main/main.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/main/main.c'`"
    test 14479 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/main/main.c:' 'original size' '14479,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/main/main.h ==============
if test -f 'pad2ps-3.1/src/main/main.h' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/main/main.h' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/main/main.h' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/main/main.h' &&
/*                         */
/*  main.h                 */
/*                         */
/*  pad2ps  by S. Yoshida  */
/*                         */
X
#ifndef _MAIN_H
#define _MAIN_H
X
#include "config.h"
X
#ifndef JAPANESE
#ifndef ENGLISH
#define ENGLISH		/* output in English by default */
#endif
#endif
X
#include <stdio.h>
#include "lib.h"
#include "version.h"
X
typedef enum {
X    Default, Pad,
X    Awk, C, Csh, Java, Sh
} SRC;
X
#endif  /* ! _MAIN_H */
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/main/main.h' &&
  chmod 0644 'pad2ps-3.1/src/main/main.h' ||
  $echo 'restore of' 'pad2ps-3.1/src/main/main.h' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/main/main.h:' 'MD5 check failed'
498696229f59a6d14c2d706745613f78  pad2ps-3.1/src/main/main.h
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/main/main.h'`"
    test 454 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/main/main.h:' 'original size' '454,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/main/Makefile.in ==============
if test -f 'pad2ps-3.1/src/main/Makefile.in' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/main/Makefile.in' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/main/Makefile.in' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/main/Makefile.in' &&
### Makefile of pad2ps  by S. Yoshida
X
### configuration by configure
X
prefix = @prefix@
exec_prefix = @exec_prefix@
BINDIR = @bindir@
X
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
LN_S = @LN_S@
X
CC = @CC@
X
LIBS = @LIBS@ -L../lib -lpublic
X
### make commands
X
CFLAGS = -O2
LDFLAGS =
MFLAGS =
X
INCLUDES = -I.. -I../lib
X
HDRS = main.h
SRCS = main.c
OBJS = main.o
X
TARGS = pad2ps
X
LNFILE = pad2tex pad2eps
X
all: ${TARGS}
X
pad2ps: ${OBJS} ${HDRS}
X	$(CC) $(LDFLAGS) ${OBJS} -o $@ $(LIBS)
X
%.o: %.c
X	$(CC) $(CFLAGS) $(INCLUDES) -c $<
X
install: ${TARGS}
X	$(INSTALL) -d $(BINDIR)
X	if [ -f $(BINDIR)/pad2ps ]; then rm -f $(BINDIR)/pad2ps; fi
X	$(INSTALL_PROGRAM) pad2ps $(BINDIR)
X	for i in $(LNFILE); do \
X		if [ -f $(BINDIR)/$$i ]; then rm -f $(BINDIR)/$$i; fi; \
X		$(LN_S) pad2ps $(BINDIR)/$$i; \
X	done
X
clean:
X	rm -f ${OBJS} ${TARGS} a.out core *~ *.bak
X
distclean:
X	rm -f ${OBJS} ${TARGS} a.out core *~ *.bak
X	rm -f Makefile
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/main/Makefile.in' &&
  chmod 0644 'pad2ps-3.1/src/main/Makefile.in' ||
  $echo 'restore of' 'pad2ps-3.1/src/main/Makefile.in' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/main/Makefile.in:' 'MD5 check failed'
9f1e532fe7fdf3a2adc9e1f9ecbc20ff  pad2ps-3.1/src/main/Makefile.in
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/main/Makefile.in'`"
    test 959 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/main/Makefile.in:' 'original size' '959,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/mkpad/Makefile.in ==============
if test ! -d 'pad2ps-3.1/src/mkpad'; then
  $echo 'x -' 'creating directory' 'pad2ps-3.1/src/mkpad'
  mkdir 'pad2ps-3.1/src/mkpad'
fi
if test -f 'pad2ps-3.1/src/mkpad/Makefile.in' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/mkpad/Makefile.in' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/mkpad/Makefile.in' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/mkpad/Makefile.in' &&
### Makefile of mkpad  by S. Yoshida
X
### configuration by configure
X
prefix = @prefix@
exec_prefix = @exec_prefix@
BINDIR = @bindir@
LIBDIR = @libdir@/pad2ps
X
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
SH = @SH@
X
### make commands
X
MFLAGS =
X
SRCS = mkpad.in
X
TARGS = mkpad
X
all: ${TARGS}
X
mkpad: ${SRCS} ../version.h
X	cat ../version.h | grep "#define\ VERSION" | sed -e "s/.*\"\(.*\)\"/\1/" > .version
X	cat ../version.h | grep "#define\ AUTHOR" | sed -e "s/.*\"\(.*\)\"/\1/" > .author
X	if test "$(SH)" = no; then \
X		cat mkpad.in | sed -e "s/^\(.*\)\@SH\@\(.*\)/\1%bin%sh\2/" > .mkpad.tmp.1; \
X	else \
X		cat mkpad.in | sed -e "s/^\(.*\)\@SH\@\(.*\)/\1`echo $(SH) | tr / %`\2/" > .mkpad.tmp.1; \
X	fi
X	cat .mkpad.tmp.1 | sed -e "s/^\(.*\)\@LIBDIR\@\(.*\)/\1`echo $(LIBDIR) | tr / %`\2/" > .mkpad.tmp.2
X	cat .mkpad.tmp.2 | sed -e "s/^\(.*\)\@VERSION\@\(.*\)/\1`cat .version | tr / %`\2/" > .mkpad.tmp.3
X	cat .mkpad.tmp.3 | sed -e "s/^\(.*\)\@AUTHOR\@\(.*\)/\1`cat .author | tr / %`\2/" > .mkpad.tmp.4
X	cat .mkpad.tmp.4 | tr % / > mkpad
X
install: ${TARGS}
X	$(INSTALL) -d $(BINDIR)
X	if [ -f $(BINDIR)/mkpad ]; then rm -f $(BINDIR)/mkpad; fi
X	$(INSTALL_PROGRAM) mkpad $(BINDIR)
X
clean:
X	rm -f ${TARGS} .version .author .mkpad.tmp.* core *~ *.bak
X
distclean:
X	rm -f ${TARGS} .version .author .mkpad.tmp.* core *~ *.bak
X	rm -f Makefile
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/mkpad/Makefile.in' &&
  chmod 0644 'pad2ps-3.1/src/mkpad/Makefile.in' ||
  $echo 'restore of' 'pad2ps-3.1/src/mkpad/Makefile.in' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/mkpad/Makefile.in:' 'MD5 check failed'
f5b7268eaa2997b961279d3ad424449a  pad2ps-3.1/src/mkpad/Makefile.in
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/mkpad/Makefile.in'`"
    test 1372 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/mkpad/Makefile.in:' 'original size' '1372,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/mkpad/mkpad.in ==============
if test -f 'pad2ps-3.1/src/mkpad/mkpad.in' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/mkpad/mkpad.in' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/mkpad/mkpad.in' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/mkpad/mkpad.in' &&
#!@SH@
# mkpad -- translate a program source into PADEL
#
# The original version is made by Daisuke Fujii (fujii@rins.ryukoku.ac.jp).
# --------------------------------------------------------------------
#!/bin/csh -f
# title:mkpad -- Make .pad file for pad2ps and generate .ps by pad2ps
# $Header: /tmp_mnt/auto2e00068/fujii/bin/RCS/mkpad,v 1.112 1995/06/29 01:49:09 fujii Exp fujii $
# --------------------------------------------------------------------
#
X
libdir=@LIBDIR@
if test -n "$PAD2PSLIB"; then
X	libdir=$PAD2PSLIB
fi
X
if test $# = 0; then
X	echo "mkpad @VERSION@  by @AUTHOR@"
X	echo ""
X	echo "usage: mkpad -[awk|c|c++|csh|java|sh] [arguments]"
X	echo "       mkpad -[awk|c|c++|csh|java|sh] -help"
X	exit 1
else
X	opt="$1"
X	shift
X	args=
X	for i do
X		args="$args $1"
X		shift
X	done
fi
X
case $opt in
X    -awk )
X	$libdir/awk2pad $args ;;
X    -c | -c++ )
X	$libdir/c2pad $args ;;
X    -csh )
X	$libdir/csh2pad $args ;;
X    -java )
X	$libdir/java2pad $args ;;
X    -sh )
X	$libdir/sh2pad $args ;;
X    * )
X	echo "mkpad @VERSION@  by @AUTHOR@"
X	echo ""
X	echo "usage: mkpad -[awk|c|c++|csh|java|sh] [arguments]"
X	echo "       mkpad -[awk|c|c++|csh|java|sh] -help"
X	exit 1 ;;
esac
X
# end of mkpad
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/mkpad/mkpad.in' &&
  chmod 0644 'pad2ps-3.1/src/mkpad/mkpad.in' ||
  $echo 'restore of' 'pad2ps-3.1/src/mkpad/mkpad.in' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/mkpad/mkpad.in:' 'MD5 check failed'
563d390c6e0862ae149e82a8a7e24bdd  pad2ps-3.1/src/mkpad/mkpad.in
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/mkpad/mkpad.in'`"
    test 1187 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/mkpad/mkpad.in:' 'original size' '1187,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/parser.y ==============
if test ! -d 'pad2ps-3.1/src/pad2ps'; then
  $echo 'x -' 'creating directory' 'pad2ps-3.1/src/pad2ps'
  mkdir 'pad2ps-3.1/src/pad2ps'
fi
if test -f 'pad2ps-3.1/src/pad2ps/parser.y' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/parser.y' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/parser.y' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/parser.y' &&
%{
/*                                        */
/*  parser.y -- parser (syntax analysis)  */
/*                                        */
/*  pad2ps  by S. Yoshida                 */
/*                                        */
X
#include "config.h"
X
#include <stdarg.h>
#include <string.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#include <ctype.h>
#include "pad2ps.h"
#include "lib.h"
X
#ifdef YACC_NO_VOID_PTR
#define YYSTYPE int
#else
#define YYSTYPE void *
#endif
X
#ifdef DEBUG
#undef YYDEBUG
#define YYDEBUG	1
#endif
X
static STACK *sw = NULL;
static PAD *tmp_pad = NULL;
X
static PAD *make_pad(TYPE,char *,PAD *,PAD *);
static void link_pad(PAD *);
static void dup_pad(PAD *);
X
static char *get_termstr(char *);
static char *get_until(char *,char,int);
static char *get_headsp(char *);
static char *rm_headsp(char *);
static char *rm_tailsp(char *);
X
static char *complete_label(char *);
static void push_sw(void *);
static void *pop_sw(void);
%}
X
%token FOR
%token WHILE
%token DO
%token IF
%token ELSE
%token SWITCH
%token CASE
%token DEFAULT_LABEL
%token DEFAULT
%token LABEL
%token REFER
%token SHORT_LABEL
%token TRY
%token CATCH
%token LB_END
%token RB_END
%token RP_END
%token RPLB_END
%token COLON_END
%token RB_ELSE
%token RB_WHILE
%token RB_CATCH
%token LP
%token RP
%token LB
%token RB
%token SP
%token RET
%token CHAR
%token MESSAGE
%token MESSAGE_END
%token COMMENT
%token NP
%token VSP
X
%%
X
program
X		: 
X		| program RET
X		{ link_pad(make_pad(Empty,NULL,NULL,NULL)); }
X		| program control_code
X		{ link_pad($2); }
X		| program body
X		{ link_pad($2); }
X		;
control_code
X		: NP
X		{ $$ = make_pad(Newpage,NULL,NULL,NULL); }
X		| VSP
X		{ tmp_pad = make_pad(Vsp,NULL,NULL,NULL);
X		  tmp_pad->value = (int)$1; $$ = tmp_pad; }
X		;
body
X		: LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Padtitle,NULL,$2,NULL); }
X		| string end LB_END commands RB_END
X		{ current = pop();
X		  $$ = make_pad(Padtitle,joint(2,$1,$2),$4,NULL); }
X		| one_symbol_line LB_END commands RB_END
X		{ current = pop();
X		  $$ = make_pad(Padtitle,$1,$3,NULL); }
X		;
commands
X		:
X		{ push(current); $$ = NULL; }
X		| real_commands
X		{ $$ = $1; }
X		;
real_commands
X		: command
X		{ push(current); current = $1; $$ = $1; }
X		| real_commands command
X		{ link_pad($2); $$ = $1; }
X		;
oneline
X		: oneline_command
X		{ $$ = $1; }
X		;
oneline_command
X		: for_statement			{ $$ = $1; }
X		| while_statement		{ $$ = $1; }
X		| do_statement			{ $$ = $1; }
X		| ifelse_statement		{ $$ = $1; }
X		| trycatch_statement		{ $$ = $1; }
X		| switch_statement		{ $$ = $1; }
X		| label_statement		{ $$ = $1; }
X		| refer_statement		{ $$ = $1; }
X		| oneline_block			{ $$ = $1; }
X		| normal_line			{ $$ = $1; }
X		;
command
X		: oneline_command		{ $$ = $1; }
X		| block				{ $$ = $1; }
X		| RET
X		{ $$ = make_pad(Empty,NULL,NULL,NULL); }
X		| message
X		{ $$ = make_pad(Message,$1,NULL,NULL); }
X		| control_code			{ $$ = $1; }
X		;
for_statement
X		: FOR sp LP string RP_END LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(For,$4,$7,NULL); }
X		| FOR sp LP string RPLB_END commands RB_END
X		{ current = pop(); $$ = make_pad(For,$4,$6,NULL); }
X		| FOR sp LP string RP_END oneline
X		{ $$ = make_pad(For,$4,$6,NULL); }
X		;
while_statement
X		: WHILE sp LP string RP_END LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(While,$4,$7,NULL); }
X		| WHILE sp LP string RPLB_END commands RB_END
X		{ current = pop(); $$ = make_pad(While,$4,$6,NULL); }
X		| WHILE sp LP string RP_END oneline
X		{ $$ = make_pad(While,$4,$6,NULL); }
X		;
do_statement
X		: DO LB_END commands RB_WHILE sp WHILE sp LP string RP_END
X		{ current = pop(); $$ = make_pad(Do,$9,$3,NULL); }
X		| DO LB_END commands RB_END WHILE sp LP string RP_END
X		{ current = pop(); $$ = make_pad(Do,$8,$3,NULL); }
X		| DO RET LB_END commands RB_WHILE sp WHILE sp LP string RP_END
X		{ current = pop(); $$ = make_pad(Do,$10,$4,NULL); }
X		| DO RET LB_END commands RB_END WHILE sp LP string RP_END
X		{ current = pop(); $$ = make_pad(Do,$9,$4,NULL); }
X		| DO RET oneline WHILE sp LP string RP_END
X		{ $$ = make_pad(Do,$7,$3,NULL); }
X		;
ifelse_statement
X		: if_statement
X		{ $$ = make_pad(If,NULL,$1,NULL); }
X		;
if_statement
X		: if_head commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$1,$2,NULL); }
X		| if_head commands RB_END else_statement
X		{ current = make_pad(Cond,$1,$2,NULL); push(current);
X		  link_pad($4); tmp_pad = pop(); current = pop(); $$ = tmp_pad; }
X		| if_head commands RB_ELSE sp else_statement
X		{ current = make_pad(Cond,$1,$2,NULL); push(current);
X		  link_pad($5); tmp_pad = pop(); current = pop(); $$ = tmp_pad; }
X		| IF sp LP string RP_END oneline
X		{ $$ = make_pad(Cond,$4,$6,NULL); }
X		| IF sp LP string RP_END oneline else_statement
X		{ push(current); current = make_pad(Cond,$4,$6,NULL);
X		  push(current); link_pad($7); tmp_pad = pop(); current = pop();
X		  $$ = tmp_pad; }
X		;
if_head
X		: IF sp LP string RP_END LB_END
X		{ $$ = $4; }
X		| IF sp LP string RPLB_END
X		{ $$ = $4; }
X		;
else_statement
X		: ELSE SP if_statement
X		{ $$ = $3; }
X		| ELSE RET LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,NULL,$4,NULL); }
X		| ELSE LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,NULL,$3,NULL); }
X		| ELSE RET oneline
X		{ $$ = make_pad(Cond,NULL,$3,NULL); }
X		;
trycatch_statement
X		: try_statement catch_statement
X		{ $$ = make_pad(If,NULL,$2,NULL); }
X		;
try_statement
X		: TRY LB_END commands
X		{ tmp_pad = current; current = pop();
X		  link_pad($3); current = tmp_pad; $$ = NULL; }
X		| TRY RET LB_END commands
X		{ tmp_pad = current; current = pop();
X		  link_pad($4); current = tmp_pad; $$ = NULL; }
X		| TRY RET oneline
X		{ link_pad($3); $$ = NULL; }
X		;
catch_statement
X		: RB_END CATCH sp LP string RP_END LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$5,$8,NULL); }
X		| RB_CATCH sp CATCH sp LP string RP_END LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$6,$9,NULL); }
X		| CATCH sp LP string RP_END LB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$4,$7,NULL); }
X		| RB_END CATCH sp LP string RPLB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$5,$7,NULL); }
X		| RB_CATCH sp CATCH sp LP string RPLB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$6,$8,NULL); }
X		| CATCH sp LP string RPLB_END commands RB_END
X		{ current = pop(); $$ = make_pad(Cond,$4,$6,NULL); }
X		| RB_END CATCH sp LP string RP_END oneline
X		{ $$ = make_pad(Cond,$5,$7,NULL); }
X		| RB_CATCH sp CATCH sp LP string RP_END oneline
X		{ $$ = make_pad(Cond,$6,$8,NULL); }
X		| CATCH sp LP string RP_END oneline
X		{ $$ = make_pad(Cond,$4,$6,NULL); }
X		;
switch_statement
X		: switch_head switch_blocks RB_END
X		{ pop_sw(); current = pop();
X		  $$ = make_pad(Switch,NULL,$2,NULL); }
X		;
switch_head
X		: SWITCH sp LP string RP_END LB_END
X		{ push_sw($4); }
X		| SWITCH sp LP string RPLB_END
X		{ push_sw($4); }
X		| SWITCH LB_END
X		{ push_sw(NULL); }
X		| SWITCH RET LB_END
X		{ push_sw(NULL); }
X		;
switch_blocks
X		:
X		{ push(current); $$ = NULL; }
X		| switch_label
X		{ push(current); $$ = make_pad(Cond,$1,NULL,NULL); }
X		| switch_label switch_labels
X		{ push(current); $$ = make_pad(Cond,$1,NULL,$2); }
X		| real_switch_blocks
X		{ $$ = $1; }
X		| real_switch_blocks switch_label
X		{ link_pad(make_pad(Cond,$2,NULL,NULL)); $$ = $1; }
X		| real_switch_blocks switch_label switch_labels
X		{ current = pop(); link_pad(make_pad(Cond,$2,NULL,$3)); $$ = $1; }
X		;
real_switch_blocks
X		: switch_block
X		{ push(current); current = $1; $$ = $1; }
X		| real_switch_blocks switch_block
X		{ link_pad($2); $$ = $1; }
X		;
switch_block
X		: switch_label real_commands
X		{ current = pop(); $$ = make_pad(Cond,$1,$2,NULL); }
X		| switch_label switch_labels real_commands
X		{ pop(); current = pop(); $$ = make_pad(Cond,$1,$3,$2); }
X		;
switch_labels
X		: switch_label
X		{ push(current); current = make_pad(Cond,$1,NULL,NULL);
X		  $$ = current; }
X		| switch_labels switch_label
X		{ dup_pad(make_pad(Cond,$2,NULL,NULL)); $$ = $1; }
X		;
switch_label
X		: case_statement
X		{ $$ = $1; }
X		| default_statement
X		{ $$ = $1; }
X		;
case_statement
X		: CASE string COLON_END
X		{ $$ = complete_label($2); }
X		;
default_statement
X		: DEFAULT_LABEL
X		{ free($1); $$ = NULL; }
X		;
label_statement
X		: LABEL string end
X		{ $$ = make_pad(Label,joint(2,$2,$3),NULL,NULL); }
X		| LABEL string end comment
X		{ $$ = make_pad(Label,joint(2,$2,$3),make_pad(Comment,$4,NULL,NULL),NULL); }
X		| LABEL sp one_symbol_line
X		{ $$ = make_pad(Label,$3,NULL,NULL); }
X		| LABEL sp one_symbol_line comment
X		{ $$ = make_pad(Label,$3,make_pad(Comment,$4,NULL,NULL),NULL); }
X		| SHORT_LABEL
X		{ $$ = make_pad(Label,rm_headsp(rm_tailsp(get_until($1,':',0))),NULL,NULL); }
X		| SHORT_LABEL comment
X		{ $$ = make_pad(Label,rm_headsp(rm_tailsp(get_until($1,':',0))),make_pad(Comment,$2,NULL,NULL),NULL); }
X		;
refer_statement
X		: REFER sp LP string RP_END LB_END block_strings RB_END
X		{ current = pop(); $$ = make_pad(Refer,$4,$7,NULL); }
X		| REFER sp LP string RP_END LB_END block_strings RB_END comment
X		{ current = pop(); $$ = make_pad(Refer,$4,$7,make_pad(Comment,$9,NULL,NULL)); }
X		| REFER sp LP string RPLB_END block_strings RB_END
X		{ current = pop(); $$ = make_pad(Refer,$4,$6,NULL); }
X		| REFER sp LP string RPLB_END block_strings RB_END comment
X		{ current = pop(); $$ = make_pad(Refer,$4,$6,make_pad(Comment,$8,NULL,NULL)); }
X		| REFER sp LP string RP_END block_string
X		{ $$ = make_pad(Refer,$4,$6,NULL); }
X		| REFER sp LP string RP_END block_string comment
X		{ $$ = make_pad(Refer,$4,$6,make_pad(Comment,$7,NULL,NULL)); }
X		;
oneline_block
X		: LB RB_END
X		{ $$ = make_pad(Box,get_headsp($2),NULL,NULL); }
X		| LB RB_END comment
X		{ $$ = make_pad(Box,get_headsp($2),make_pad(Comment,$3,NULL,NULL),NULL); }
X		| LB string RB_END
X		{ $$ = make_pad(Box,$2,NULL,NULL); }
X		| LB string RB_END comment
X		{ $$ = make_pad(Box,$2,make_pad(Comment,$4,NULL,NULL),NULL); }
X		;
block
X		: LB_END block_strings RB_END
X		{ current = pop(); $$ = make_pad(Block,NULL,$2,NULL); }
X		| LB_END block_strings RB_END comment
X		{ current = pop();
X		  $$ = make_pad(Block,NULL,$2,make_pad(Comment,$4,NULL,NULL)); }
X		;
block_strings
X		:
X		{ push(current); $$ = NULL; }
X		| real_block_strings
X		{ $$ = $1; }
X		;
real_block_strings
X		: block_string
X		{ push(current); current = $1; $$ = current; }
X		| real_block_strings block_string
X		{ link_pad($2); $$ = $1; }
X		;
block_string
X		: RET
X		{ $$ = make_pad(Empty,NULL,NULL,NULL); }
X		| string end
X		{ $$ = make_pad(Str,joint(2,$1,$2),NULL,NULL); }
X		| one_symbol_line
X		{ $$ = make_pad(Str,$1,NULL,NULL); }
X		| SHORT_LABEL
X		{ $$ = make_pad(Str,rm_headsp(rm_tailsp(get_termstr($1))),NULL,NULL); }
X		| DEFAULT_LABEL
X		{ $$ = make_pad(Str,rm_headsp(rm_tailsp(get_termstr($1))),NULL,NULL); }
X		;
normal_line
X		: real_normal_line end
X		{ $$ = make_pad(Box,joint(2,$1,$2),NULL,NULL); }
X		| real_normal_line end comment
X		{ $$ = make_pad(Box,joint(2,$1,$2),make_pad(Comment,$3,NULL,NULL),NULL); }
X		| one_symbol_line
X		{ $$ = make_pad(Box,$1,NULL,NULL); }
X		| one_symbol_line comment
X		{ $$ = make_pad(Box,$1,make_pad(Comment,$2,NULL,NULL),NULL); }
X		;
real_normal_line
X		: command_char
X		{ $$ = $1; }
X		| real_normal_line all_char
X		{ $$ = joint(2,$1,$2); }
X		| real_normal_line SP all_char
X		{ $$ = joint(3,$1,$2,$3); }
X		;
message
X		: message_chars MESSAGE_END
X		{ $$ = joint(2,$1,$2); }
X		;
message_chars
X		:				{ $$ = NULL; }
X		| message_chars MESSAGE		{ $$ = joint(2,$1,$2); }
X		;
comment
X		: COMMENT
X		{ $$ = $1; }
X		| comment COMMENT
X		{ $$ = joint(2,$1,$2); }
X		;
string
X		: real_string
X		{ $$ = $1; }
X		| SP string
X		{ $$ = $2; }
X		;
real_string
X		: all_char
X		{ $$ = $1; }
X		| real_string all_char
X		{ $$ = joint(2,$1,$2); }
X		| real_string SP all_char
X		{ $$ = joint(3,$1,$2,$3); }
X		;
one_symbol_line
X		: one_symbol_end
X		{ $$ = rm_headsp($1); }
X		;
command_char
X		: CHAR			{ $$ = $1; }
X		| LP			{ $$ = $1; }
X		| RP			{ $$ = $1; }
X		| RB			{ $$ = $1; }
X		;
char
X		: command_char		{ $$ = $1; }
X		| FOR			{ $$ = $1; }
X		| WHILE			{ $$ = $1; }
X		| DO			{ $$ = $1; }
X		| IF			{ $$ = $1; }
X		| ELSE			{ $$ = $1; }
X		| SWITCH		{ $$ = $1; }
X		| CASE			{ $$ = $1; }
X		| DEFAULT		{ $$ = $1; }
X		| LABEL			{ $$ = $1; }
X		| REFER			{ $$ = $1; }
X		| TRY			{ $$ = $1; }
X		| CATCH			{ $$ = $1; }
X		;
all_char
X		: char			{ $$ = $1; }
X		| LB			{ $$ = $1; }
X		| RB_ELSE		{ $$ = $1; }
X		| RB_WHILE		{ $$ = $1; }
X		;
sp
X		: 
X		| SP			{ free($1); }
X		;
end
X		: RET			{ $$ = NULL; }
X		| RB_END		{ $$ = get_termstr($1); }
X		| LB_END		{ $$ = get_termstr($1); }
X		| one_symbol_end	{ $$ = $1; }
X		;
one_symbol_end
X		: RP_END		{ $$ = get_termstr($1); }
X		| RPLB_END		{ $$ = get_termstr($1); }
X		| COLON_END		{ $$ = get_termstr($1); }
X		;
%%
X
#include "lex.yy.c"
X
PAD *make_pad(TYPE type,char *str,PAD *child,PAD *depth)
/* create a node on a tree structure */
{
X    PAD *p;
X
X    p = (PAD *)malloc(sizeof(PAD));
X    p->type = type;
X    p->str = str;
X    p->child = child;
X    p->depth = depth;
X    p->next = NULL;
X
X    return p;
}
X
void link_pad(PAD *p)
/* create link to below */
{
X    current->next = p;
X    current = p;
}
X
void dup_pad(PAD *p)
/* duplicate a node */
{
X    current->depth = p;
X    current = p;
}
X
char *get_termstr(char *s)
/* get string from terminator ("---\n") */
{
X    int i,l;
X    char *p;
X
X    if(s == NULL)
X	return NULL;
X
X    l = strlen(s);
X    for(i = l - 2 ; *(s+i) == ' '  ||  *(s+i) == '\t' ; i++)
X	;
X
X    l = i + 1;
X    p = (char *)malloc((l+2)*sizeof(char));
X    for(i = 0 ; i < l ; i++)
X	*(p+i) = *(s+i);
X    *(p+l) = '\0';
X
X    free(s);
X    return p;
}
X
char *get_until(char *s,char c,int flag)
/* get string that is before designated character */
{
X    int i,l;
X    char *p;
X
X    if(s == NULL)
X	return NULL;
X
X    for(l = 0 ; *(s+l) != c ; l++)
X	;
X    if(flag == 1)
X	l++;
X
X    p = (char *)malloc((l+2)*sizeof(char));
X    for(i = 0 ; i < l ; i++)
X	*(p+i) = *(s+i);
X    *(p+l) = '\0';
X
X    free(s);
X    return p;
}
X
char *get_headsp(char *s)
/* get spaces at head */
{
X    int i,l;
X    char *p;
X
X    if(s == NULL)
X	return NULL;
X
X    for(l = 0 ; isspace(*(s+l)) ; l++)
X	;
X
X    p = (char *)malloc((l+2)*sizeof(char));
X    for(i = 0 ; i < l ; i++)
X	*(p+i) = ' ';
X    *(p+l) = '\0';
X
X    free(s);
X    return p;
}
X
char *rm_headsp(char *s)
/* remove spaces at head */
{
X    int i,l;
X    char *p;
X
X    if(s == NULL)
X	return NULL;
X
X    for(i = 0 ; isspace(*(s+i)) ; i++)
X	;
X
X    l = strlen(&s[i]);
X    p = (char *)malloc((l+2)*sizeof(char));
X    strcpy(p,&s[i]);
X
X    free(s);
X    return p;
}
X
char *rm_tailsp(char *s)
/* remove spaces at tail */
{
X    int i;
X
X    if(s == NULL)
X	return NULL;
X
X    for(i = strlen(s) - 1 ; i >= 0 && isspace(*(s+i)) ; i--)
X	;
X    s[i+1] = '\0';
X    return s;
}
X
char *complete_label(char *str)
/* complete branch label in switch statement */
{
X    char *p,*s;
X    int l;
X
X    p = pop_sw();
X
X    if(p == NULL)
X	s = str;
X    else{
X	l = strlen(p)+1;
X	s = (char *)malloc((l+2)*sizeof(char));
X	strcpy(s,p);
X	strcat(s,"=");
X	s = joint(2,s,str);
X    }
X
X    push_sw(p);
X    return s;
}
X
void push_sw(void *ptr)
{
X    STACK *tmp;
X
X    tmp = (STACK *)malloc(sizeof(STACK));
X    tmp->ptr = ptr;
X    tmp->prev = sw;
X    sw = tmp;
}
X
void *pop_sw(void)
{
X    void *ptr;
X    STACK *s;
X
X    ptr = sw->ptr;
X    s = sw;
X    sw = sw->prev;
X    free(s);
X    return ptr;
}
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/parser.y' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/parser.y' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/parser.y' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/parser.y:' 'MD5 check failed'
a73903b603878ce7e5a59956115b8c7d  pad2ps-3.1/src/pad2ps/parser.y
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/parser.y'`"
    test 15165 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/parser.y:' 'original size' '15165,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/pad2ps.h ==============
if test -f 'pad2ps-3.1/src/pad2ps/pad2ps.h' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/pad2ps.h' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/pad2ps.h' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/pad2ps.h' &&
/*                         */
/*  pad2ps.h               */
/*                         */
/*  pad2ps  by S. Yoshida  */
/*                         */
X
#ifndef _PAD2PS_H
#define _PAD2PS_H
X
#include "config.h"
X
#ifndef JAPANESE
#ifndef ENGLISH
#define ENGLISH		/* output in English by default */
#endif
#endif
X
#include <stdio.h>
#include "lib.h"
#include "version.h"
X
#define SCALE		0.06	/* PostScript scale */
#define SQRT2		1.42	/* used for labeling and calculating radius for handling references */
X
#define X_MAX		9000	/* right boundary of the paper */
#define Y_MAX		10000	/* upper boundary of the paper */
#define X_CENTER	4500	/* x-coordinate of the center of the paper */
#define PAGE_TOP	9800	/* page top */
#define PAGE_BOTTOM	0	/* page bottom */
#define PAGE_LEFT	500	/* page left */
#define PAGE_RIGHT	8500	/* page right */
#define PAGENUMBER_Y	-1000	/* position where page number is to be printed */
#define INVALID		-50000	/* invalid coordinate */
#define INFINITY	50000	/* infinity */
X
#define VSPACE		120	/* vertical spacing between boxes */
#define HSPACE		200	/* horizontal spacing between boxes */
#define BOX_VSPACE	25	/* vertical space of normal box */
#define IF_VSPACE	50	/* vertical space of "if" box */
#define BOX_HSPACE	125	/* space in normal box */
#define IF_RIGHTSPACE	200	/* space of "if" box at right side */
#define SIDELINE_SPACE	50	/* spacing between sidelines (used in for statement and others) */
#define PAD_VSPACE	400	/* vertical spacing between PADs */
#define PADFRAME_VSPACE	180	/* vertical spacing between PAD and its frame */
#define PADFRAME_HSPACE	300	/* horizontal spacing between PAD and its frame */
X
#define LINEWIDTH	16	/* thickness of line */
#define PADLINEWIDTH	16	/* thickness of PAD */
#define FRAMELINEWIDTH	8	/* thickness of frame line */
X
#define FONTSIZE	200	/* font size (height of characters) */
#define FONTWIDTH	100	/* width of font (alphabets) */
#define JFONTWIDTH	200	/* width of font (japanese characters) */
#define TITLE_RATE	2.0	/* magnification rate of title */
#define PADTITLE_RATE	1.5	/* magnification rate of PAD title */
#define FIGURE_RATE	1.5	/* magnification rate of PAD figure */
#define CHAR_BASEUP	40	/* shift up characters a little */
#define JCHAR_BASEUP	20	/* shift up Japnese characters a little */
X
X
typedef struct _PAD PAD;
typedef struct _BOX BOX;
typedef struct _STRING STRING;
typedef struct _INT2 INT2;
X
typedef enum {
X    Root, Title,
X    Message, Comment,
X    Newpage, Vsp,
X    Empty, Str, Box, Figure,
X    Padtitle, For, While, Do,
X    Block, If, Switch, Cond,
X    Label, Refer,
X    Line, Padframe,
X    Topdown, Middle, Bottomup,
X    Top, Bottom
} TYPE;
X
struct _PAD {
X    TYPE type;
X    char *str;
X    int value;
X    int lines;
X    int space_width;
X    int whole_width;
X    int child_number;
X    int depth_number;
X    int amount;
X    bool enable_fold;
X    PAD *child;
X    PAD *depth;
X    PAD *next;
};
X
struct _BOX {
X    TYPE type;
X    STRING *str;
X    int x;
X    int y;
X    int w;
X    int h;
X    bool flag1;
X    bool flag2;
X    BOX *prev;
X    BOX *next;
};
X
struct _STRING {
X    char *str;
X    int x;
X    int y;
#ifdef JAPANESE
X    bool jflag;
#endif
X    STRING *next;
};
X
struct _INT2 {
X    int count;
X    int amount;
};
X
X
extern bool quiet;		/* -quiet option */
#ifdef DEBUG
extern bool debug;		/* -debug option */
#endif
X
extern bool eps_flag;		/* pad2eps? */
extern bool latex_command_flag;	/* treat string as LaTeX command? */
X
extern char *title;		/* overall title */
extern bool titlebox;		/* whether to draw each PAD title in box */
extern bool page_print;		/* whether to print page number */
extern int page;		/* <starting page>-1 */
extern int figure;		/* figure number */
extern TYPE figure_locate;	/* figure position */
extern bool figure_locate_flag;	/* whether figure_locate is being set */
extern bool centering;		/* whether to centerize */
extern bool poster;		/* poster */
extern bool slice;		/* whether to draw each PAD from the head of page */
X
extern int tab_width;		/* tab width */
X
extern TYPE locate_type;	/* PAD location format */
X
extern bool pageframe;		/* whether to draw page frame */
extern bool padframe;		/* whether to draw PAD frame */
X
extern int page_top;		/* page top */
extern int page_bottom;		/* page bottom */
extern int page_left;		/* page left */
extern int page_right;		/* page right */
extern int page_width;		/* page width */
extern int x_center;		/* page center (when centering is 0n, this value is 0) */
extern int right_limit;		/* right limit */
extern int left_limit;		/* left limit */
X
extern int max_length;		/* maximum length of PAD string */
extern int min_length;		/* minumum length of PAD string */
X
extern int vspace;		/* vertical spacing between boxes */
extern int hspace;		/* horizontal spacing between boxes */
extern int box_vspace;		/* vertical space of normal box */
extern int if_vspace;		/* vertical sapce of "if" box */
extern int box_hspace;		/* horizontal space of normal box */
extern int if_rightspace;	/* space of "if" box at right side */
extern int sideline_space;	/* spacing between horizontal sidelines (used in for statement and others) */
extern int box_height;		/* box height */
extern int if_height;		/* "if" box height */
extern int pad_vspace;		/* vertical spacing between PADs */
extern int padframe_vspace;	/* vertical spacing between PAD and its frame */
extern int padframe_hspace;	/* horizontal spacing between PAD and it frame */
X
extern int linewidth;		/* thickness of line */
extern int padlinewidth;	/* thickness of PAD figure */
extern int framelinewidth;	/* thickness of PAD frame */
X
extern int fontsize;		/* font size (height of characters) */
extern int fontwidth;		/* width of font (alphabets) */
extern int jfontwidth;		/* width of font (japanese characters) */
extern double title_rate;	/* magnification rate of title */
extern double padtitle_rate;	/* magnification rate of PAD title */
extern double figure_rate;	/* magnification rate of PAD figure */
X
extern char font[];		/* font */
extern char title_font[];	/* title font */
#ifdef JAPANESE
extern char jfont[];		/* Japanese font */
extern char title_jfont[];	/* Japanese font for title */
#endif
X
extern double vrate;		/* magnification rate (vertical) */
extern double hrate;		/* magnification rate (horizontal) */
X
extern double proper_hrate;	/* appropriate hrate value */
X
extern int first_x;		/* the starting x-coordinate */
extern int next_y;		/* the following PAD's y-coordinate */
X
extern int most_right;		/* the rightmost PAD's x-coordinate */
extern int most_left;		/* the leftmost PAD's x-coordinate */
X
extern PAD *root;		/* root of the tree structure */
extern PAD *current;		/* current position of the tree structure */
extern BOX *first;		/* beginning of the list */
extern BOX *lp;			/* current position oof the list */
X
extern bool print_warning;	/* whether to print warning */
extern int line_count;		/* line in process */
X
extern FILE *input_stream;	/* input file */
extern FILE *fp;		/* output file */
extern char outfile[];		/* output file name */
extern char outdir[];		/* directory to put output file */
X
X
/* fold.c */
extern void fold(void);			/* auto-fold PAD figure */
extern void refold_pad(PAD *,int);	/* refold PAD */
extern int is_box(PAD *);		/* PAD box? */
X
/* font.c */
extern void change_font(double);	/* change font */
extern void restore_font(void);		/* resume font */
X
/* locate.c */
extern void locate(void);	/* locate PAD */
X
/* parser.l */
extern void parser(void);	/* lexical & syntax analysis */
X
/* ps.c */
extern void ps(void);		/* create PostScript */
X
/* sort.c */
extern void sort(void);		/* sort box-typed data */
X
/* string.c */
extern STRING *string(char *,int,int,int);	/* create STRING-type data */
extern int get_str_ww(char *);			/* return string width */
extern int get_str_width(PAD *);		/* return string width after folding */
extern int get_str_height(PAD *);		/* return string height after folding */
extern int get_str_lines(PAD *,int);		/* return line number after folding with given width */
X
/* tex.c */
extern void tex(void);		/* create LaTeX code */
X
#endif  /* ! _PAD2PS_H */
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/pad2ps.h' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/pad2ps.h' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/pad2ps.h' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/pad2ps.h:' 'MD5 check failed'
2d5b67200fd8f8e8dc8a236df1194ec7  pad2ps-3.1/src/pad2ps/pad2ps.h
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/pad2ps.h'`"
    test 8090 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/pad2ps.h:' 'original size' '8090,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/parser.l.in ==============
if test -f 'pad2ps-3.1/src/pad2ps/parser.l.in' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/parser.l.in' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/parser.l.in' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/parser.l.in' &&
%{
/*                                         */
/*  parser.l -- parser (lexical analysis)  */
/*                                         */
/*  pad2ps  by S. Yoshida                  */
/*                                         */
X
#include "config.h"
X
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#include <ctype.h>
#include "pad2ps.h"
#include "lib.h"
X
#define COMM_C		1
#define COMM_CPP	2
X
static int comm_type = 0;
static char *str = NULL;
X
static void init_tree(void);
static char *keep_token(void);
X
static void set_string(void);
static int get_integer(void);
static double get_double(void);
%}
%start COMM PARAM TITLE MESG MESGC CMNT CMNTC
%e 5000
%p 5000
%n 2000
%a 5000
X
CH			[A-Za-z_]
NUM			[0-9]
SP			[ \t]
X
%%
X
<INITIAL>"for"				{ yylval = keep_token(); return FOR; }
<INITIAL>"while"			{ yylval = keep_token(); return WHILE; }
<INITIAL>"do"				{ yylval = keep_token(); return DO; }
<INITIAL>"if"				{ yylval = keep_token(); return IF; }
<INITIAL>"else"				{ yylval = keep_token(); return ELSE; }
<INITIAL>"switch"			{ yylval = keep_token(); return SWITCH; }
<INITIAL>"case"				{ yylval = keep_token(); return CASE; }
<INITIAL>^{SP}*"default"{SP}*":"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return DEFAULT_LABEL; }
<INITIAL>"default"			{ yylval = keep_token(); return DEFAULT; }
<INITIAL>"label"			{ yylval = keep_token(); return LABEL; }
<INITIAL>"refer"			{ yylval = keep_token(); return REFER; }
<INITIAL>^{SP}*{CH}({CH}|{NUM})*{SP}*":"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return SHORT_LABEL; }
<INITIAL>"try"				{ yylval = keep_token(); return TRY; }
<INITIAL>"catch"			{ yylval = keep_token(); return CATCH; }
<INITIAL>^{SP}*"/*"			{ comm_type = COMM_C; BEGIN COMM; }
<INITIAL>^{SP}*"//"			{ comm_type = COMM_CPP; BEGIN COMM; }
<INITIAL>{SP}*"{"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return LB_END; }
<INITIAL>{SP}*"}"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return RB_END; }
<INITIAL>{SP}*")"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return RP_END; }
<INITIAL>{SP}*")"{SP}*"{"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return RPLB_END; }
<INITIAL>{SP}*":"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); line_count++; return COLON_END; }
<INITIAL>"}"/{SP}*"else"		{ yylval = keep_token(); return RB_ELSE; }
<INITIAL>"}"/{SP}*"while"		{ yylval = keep_token(); return RB_WHILE; }
<INITIAL>"}"/{SP}*"catch"		{ yylval = keep_token(); return RB_CATCH; }
<INITIAL>"("				{ yylval = keep_token(); return LP; }
<INITIAL>")"				{ yylval = keep_token(); return RP; }
<INITIAL>"{"				{ yylval = keep_token(); return LB; }
<INITIAL>"}"				{ yylval = keep_token(); return RB; }
<INITIAL>^{SP}+				{ ; }
<INITIAL>{SP}+				{ yylval = keep_token(); return SP; }
<INITIAL>{SP}*("\n"|"\r\n")		{ line_count++; return RET; }
<INITIAL>{CH}({CH}|{NUM})*		{ yylval = keep_token(); return CHAR; }
<INITIAL>{NUM}+				{ yylval = keep_token(); return CHAR; }
<INITIAL>.				{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      yylval = keep_token(); return CHAR; \
X					  } \
X					}
X
<COMM>"pad2ps"{SP}*":"{SP}*		{ BEGIN PARAM; }
<COMM>{SP}*"*/"{SP}*("\n"|"\r\n")	{ line_count++; BEGIN INITIAL; }
<COMM>("\n"|"\r\n")			{ line_count++; \
X					  if(comm_type == COMM_CPP) \
X					      BEGIN INITIAL; }
<COMM>.					{ ; }
X
<TITLE>{SP}*"*/"{SP}*("\n"|"\r\n")	{ line_count++; \
X					  if(comm_type == COMM_CPP) \
X					      set_string(); \
X					  title = str; BEGIN INITIAL; }
<TITLE>{SP}*("\n"|"\r\n")		{ line_count++; title = str; \
X					  if(comm_type == COMM_C) \
X					      BEGIN COMM; \
X					  else \
X					      BEGIN INITIAL; }
<TITLE>({CH}|{NUM}|{SP})		{ set_string(); }
<TITLE>.				{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      set_string(); } \
X					}
X
<MESG>{SP}*("\n"|"\r\n")		{ line_count++; BEGIN INITIAL; }
<MESG>./{SP}*("\n"|"\r\n")		{ yylval = keep_token(); return MESSAGE_END; }
<MESG>({CH}|{NUM}|{SP})			{ yylval = keep_token(); return MESSAGE; }
<MESG>.					{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      yylval = keep_token(); return MESSAGE; } \
X					}
X
<MESGC>{SP}*"*/"{SP}*("\n"|"\r\n")	{ line_count++; BEGIN INITIAL; }
<MESGC>{SP}*("\n"|"\r\n")		{ line_count++; BEGIN COMM; }
<MESGC>./{SP}*"*/"{SP}*("\n"|"\r\n")	{ yylval = keep_token(); return MESSAGE_END; }
<MESGC>./{SP}*("\n"|"\r\n")		{ yylval = keep_token(); return MESSAGE_END; }
<MESGC>({CH}|{NUM}|{SP})		{ yylval = keep_token(); return MESSAGE; }
<MESGC>.				{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      yylval = keep_token(); return MESSAGE; } \
X					}
X
<CMNT>{SP}*("\n"|"\r\n")		{ line_count++; BEGIN INITIAL; }
<CMNT>({CH}|{NUM}|{SP})			{ yylval = keep_token(); return COMMENT; }
<CMNT>.					{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      yylval = keep_token(); return COMMENT; } \
X					}
X
<CMNTC>{SP}*"*/"{SP}*("\n"|"\r\n")	{ line_count++; BEGIN INITIAL; }
<CMNTC>{SP}*("\n"|"\r\n")		{ line_count++; BEGIN COMM; }
<CMNTC>({CH}|{NUM}|{SP})		{ yylval = keep_token(); return COMMENT; }
<CMNTC>.				{ if (isprint(*yytext)  ||  is_euc(*yytext)) { \
X					      yylval = keep_token(); return COMMENT; } \
X					}
X
<PARAM>"title"{SP}*"="{SP}*		{ str = NULL; BEGIN TITLE; }
<PARAM>"message"{SP}*"="{SP}*		{ str = NULL; \
X					  if(comm_type == COMM_C) \
X					      BEGIN MESGC; \
X					  else \
X					      BEGIN MESG; }
<PARAM>"comment"{SP}*"="{SP}*		{ str = NULL; \
X					  if(comm_type == COMM_C) \
X					      BEGIN CMNTC; \
X					  else \
X					      BEGIN CMNT; }
<PARAM>"texmode"{SP}*"="{SP}*"latex"	{ latex_command_flag = On; BEGIN COMM; }
<PARAM>"texmode"{SP}*"="{SP}*"verbatim"	{ latex_command_flag = Off; BEGIN COMM; }
<PARAM>"centering"{SP}*"="{SP}*"on"	{ centering = On; BEGIN COMM; }
<PARAM>"centering"{SP}*"="{SP}*"off"	{ centering = Off; BEGIN COMM; }
<PARAM>"locate"{SP}*"="{SP}*"topdown"	{ locate_type = Topdown; BEGIN COMM; }
<PARAM>"locate"{SP}*"="{SP}*"bottomup"	{ locate_type = Bottomup; BEGIN COMM; }
<PARAM>"locate"{SP}*"="{SP}*"middle"	{ locate_type = Middle; BEGIN COMM; }
<PARAM>"page"{SP}*"="{SP}*"-"?{NUM}+	{ page = get_integer() - 1; page_print = On; BEGIN COMM; }
<PARAM>"figure"{SP}*"="{SP}*"-"?{NUM}+	{ figure = get_integer(); BEGIN COMM; }
<PARAM>"figure_locate"{SP}*"="{SP}*"top"	{ figure_locate_flag = On; figure_locate = Top; BEGIN COMM; }
<PARAM>"figure_locate"{SP}*"="{SP}*"bottom"	{ figure_locate_flag = On; figure_locate = Bottom; BEGIN COMM; }
<PARAM>"titlebox"{SP}*"="{SP}*"on"	{ titlebox = On; BEGIN COMM; }
<PARAM>"titlebox"{SP}*"="{SP}*"off"	{ titlebox = Off; BEGIN COMM; }
<PARAM>"pageframe"{SP}*"="{SP}*"on"	{ pageframe = On; BEGIN COMM; }
<PARAM>"pageframe"{SP}*"="{SP}*"off"	{ pageframe = Off; BEGIN COMM; }
<PARAM>"padframe"{SP}*"="{SP}*"on"	{ padframe = On; BEGIN COMM; }
<PARAM>"padframe"{SP}*"="{SP}*"off"	{ padframe = Off; BEGIN COMM; }
<PARAM>"slice"{SP}*"="{SP}*"on"		{ slice = On; BEGIN COMM; }
<PARAM>"slice"{SP}*"="{SP}*"off"	{ slice = Off; BEGIN COMM; }
<PARAM>"hrate"{SP}*"="{SP}*({NUM}+)?"."{NUM}+	{ hrate = get_double(); BEGIN COMM; }
<PARAM>"vrate"{SP}*"="{SP}*({NUM}+)?"."{NUM}+	{ vrate = get_double(); BEGIN COMM; }
<PARAM>"poster"{SP}*"="{SP}*"on"	{ poster = On; BEGIN COMM; }
<PARAM>"poster"{SP}*"="{SP}*"off"	{ poster = Off; BEGIN COMM; }
<PARAM>"max_length"{SP}*"="{SP}*{NUM}+	{ max_length = get_integer(); BEGIN COMM; }
<PARAM>"min_length"{SP}*"="{SP}*{NUM}+	{ min_length = get_integer(); BEGIN COMM; }
<PARAM>"newpage"			{ return NP; }
<PARAM>"vsp"{SP}*"="{SP}*"-"?{NUM}+	{ yylval = (void *)get_integer(); return VSP; }
<PARAM>"page_top"{SP}*"="{SP}*"-"?{NUM}+	{ page_top = get_integer(); BEGIN COMM; }
<PARAM>"page_bottom"{SP}*"="{SP}*"-"?{NUM}+	{ page_bottom = get_integer(); BEGIN COMM; }
<PARAM>"page_left"{SP}*"="{SP}*"-"?{NUM}+	{ page_left = get_integer(); BEGIN COMM; }
<PARAM>"page_right"{SP}*"="{SP}*"-"?{NUM}+	{ page_right = get_integer(); BEGIN COMM; }
<PARAM>"fontsize"{SP}*"="{SP}*{NUM}+		{ fontsize = get_integer(); BEGIN COMM; }
<PARAM>"fontwidth"{SP}*"="{SP}*{NUM}+		{ fontwidth = get_integer(); BEGIN COMM; }
<PARAM>"jfontwidth"{SP}*"="{SP}*{NUM}+		{ jfontwidth = get_integer(); BEGIN COMM; }
<PARAM>"title_rate"{SP}*"="{SP}*({NUM}+)?"."{NUM}+	{ title_rate = get_double(); BEGIN COMM; }
<PARAM>"padtitle_rate"{SP}*"="{SP}*({NUM}+)?"."{NUM}+	{ padtitle_rate = get_double(); BEGIN COMM; }
<PARAM>"figure_rate"{SP}*"="{SP}*({NUM}+)?"."{NUM}+	{ figure_rate = get_double(); BEGIN COMM; }
<PARAM>"pad_vspace"{SP}*"="{SP}*{NUM}+		{ pad_vspace = get_integer(); BEGIN COMM; }
<PARAM>"vspace"{SP}*"="{SP}*{NUM}+		{ vspace = get_integer(); BEGIN COMM; }
<PARAM>"hspace"{SP}*"="{SP}*{NUM}+		{ hspace = get_integer(); BEGIN COMM; }
<PARAM>"box_vspace"{SP}*"="{SP}*{NUM}+		{ box_vspace = get_integer(); BEGIN COMM; }
<PARAM>"if_vspace"{SP}*"="{SP}*{NUM}+		{ if_vspace = get_integer(); BEGIN COMM; }
<PARAM>"box_hspace"{SP}*"="{SP}*{NUM}+		{ box_hspace = get_integer(); BEGIN COMM; }
<PARAM>"if_rightspace"{SP}*"="{SP}*{NUM}+	{ if_rightspace = get_integer(); BEGIN COMM; }
<PARAM>"sideline_space"{SP}*"="{SP}*{NUM}+	{ sideline_space = get_integer(); BEGIN COMM; }
<PARAM>"padframe_vspace"{SP}*"="{SP}*{NUM}+	{ padframe_vspace = get_integer(); BEGIN COMM; }
<PARAM>"padframe_hspace"{SP}*"="{SP}*{NUM}+	{ padframe_hspace = get_integer(); BEGIN COMM; }
<PARAM>"linewidth"{SP}*"="{SP}*{NUM}+		{ linewidth = get_integer(); BEGIN COMM; }
<PARAM>"padlinewidth"{SP}*"="{SP}*{NUM}+	{ padlinewidth = get_integer(); BEGIN COMM; }
<PARAM>"framelinewidth"{SP}*"="{SP}*{NUM}+	{ framelinewidth = get_integer(); BEGIN COMM; }
<PARAM>("\n"|"\r\n")			{ line_count++; \
X					  if(comm_type == COMM_C) \
X					      BEGIN COMM; \
X					  else \
X					      BEGIN INITIAL; }
<PARAM>.				{ BEGIN COMM; }
X
%%
X
int yyerror(char *message)
{
X    char tmp[BUFSIZ];
X    sprintf(tmp,"%s in line: %d",message,line_count);
X    error(tmp);
}
X
void parser(void)
/* lexical & syntax analysis */
{
X    init_tree();
X
#ifdef DEBUG
X    if(debug == On)
X	yydebug = 1;
#endif
X
#ifdef DEBUG
X    if(quiet == Off)
X	fprintf(stderr,"Lexical and syntactical analysis starts...");
#endif
X
X    yyin = input_stream;
X    yyparse();
X
#ifdef DEBUG
X    if(quiet == Off)
X	fprintf(stderr,"done\n");
#endif
}
X
void init_tree(void)
{
X    if(root == NULL){
X	root = (PAD *)malloc(sizeof(PAD));
X	root->type = Root;
X	root->str = NULL;
X	root->child = NULL;
X	root->depth = NULL;
X	root->next = NULL;
X	current = root;
X    }
}
X
char *keep_token(void)
{
X    int l;
X    char *p;
X
X    l = strlen(yytext);
X    p = (char *)malloc((l+2)*sizeof(char));
X    strcpy(p,yytext);
X    return p;
}
X
void set_string(void)
/* overall title and others */
{
X    char *p;
X    int l;
X
X    l = strlen(yytext);
X
X    if(*(yytext + l - 1) == '\n'){	/* when return code is included */
X	*(yytext + l - 1) = '\0';
X	l--;
X	while(*(yytext + l - 1) == ' '  ||  *(yytext + l - 1) == '\t'  || *(yytext + l - 1) == '\r'){
X	    *(yytext + l - 1) = '\0';
X	    l--;
X	}
X    }
X
X    p = (char *)malloc((l+2)*sizeof(char));
X    strcpy(p,yytext);
X
X    if(str == NULL)
X	str = p;
X    else
X	str = joint(2,str,p);
}
X
int get_integer(void)
{
X    char *p;
X
X    for(p = yytext ; *p != '=' ; p++)
X	;
X    return atoi(p+1);
}
X
double get_double(void)
{
X    char *p;
X
X    for(p = yytext ; *p != '=' ; p++)
X	;
X    return atof(p+1);
}
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/parser.l.in' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/parser.l.in' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/parser.l.in' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/parser.l.in:' 'MD5 check failed'
d0501f65b9ca8867bd3723509575ca38  pad2ps-3.1/src/pad2ps/parser.l.in
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/parser.l.in'`"
    test 11248 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/parser.l.in:' 'original size' '11248,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/pad2ps.c ==============
if test -f 'pad2ps-3.1/src/pad2ps/pad2ps.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/pad2ps.c' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/pad2ps.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/pad2ps.c' &&
/*                              */
/*  pad2ps.c -- main routine    */
/*                              */
/*  pad2ps  by S. Yoshida       */
/*                              */
X
#include "config.h"
X
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "pad2ps.h"
X
bool quiet = Off;		/* -quiet option */
#ifdef DEBUG
bool debug = Off;		/* -debug option */
#endif
X
bool eps_flag = Off;		/* pad2eps? */
bool latex_command_flag = Off;	/* treat string as LaTeX command? */
X
char *title = NULL;		/* overall title */
bool titlebox = Off;		/* whether to draw each PAD title in box */
bool page_print = Off;		/* whether to print page number */
int page = 0;			/* <starting page>-1 */
int figure = EOF;		/* figure number */
TYPE figure_locate = Top;	/* figure position */
bool figure_locate_flag = Off;	/* whether figure_locate is being set */
bool centering = On;		/* whether to centerize */
bool poster = Off;		/* poster */
bool slice = Off;		/* whether to draw each PAD from the head of page */
X
int tab_width = 4;		/* tab width */
X
TYPE locate_type = Middle;	/* PAD location format */
X
bool pageframe = Off;		/* whether to draw page frame */
bool padframe = On;		/* whether to draw PAD frame */
X
int page_top = PAGE_TOP;		/* page top */
int page_bottom = PAGE_BOTTOM;		/* page bottom */
int page_left = PAGE_LEFT;		/* page left */
int page_right = PAGE_RIGHT;		/* page right */
int page_width = PAGE_RIGHT-PAGE_LEFT;	/* page width */
int x_center = 0;		/* page center (when centering is 0n, this value is 0) */
int right_limit = PAGE_RIGHT;		/* right limit */
int left_limit = PAGE_LEFT;		/* left limit */
X
int max_length = INFINITY;		/* maximum length of PAD string */
int min_length = 0;			/* minumum length of PAD string */
X
int vspace = VSPACE;			/* vertical spacing between boxes */
int hspace = HSPACE;			/* horizontal spacing between boxes */
int box_vspace = BOX_VSPACE;		/* vertical space of normal box */
int if_vspace = IF_VSPACE;		/* vertical sapce of "if" box*/
int box_hspace = BOX_HSPACE;		/* horizontal space of normal box */
int if_rightspace = IF_RIGHTSPACE;	/* space of "if" box at right side */
int sideline_space = SIDELINE_SPACE;	/* spacing between horizontal sidelines (used in for statements and others) */
int box_height = BOX_VSPACE*2+FONTSIZE;	/* box height */
int if_height = IF_VSPACE*2+FONTSIZE;	/* "if" box height */
int pad_vspace = PAD_VSPACE;		/* vertical spacing between PADs */
int padframe_vspace = PADFRAME_VSPACE;	/* vertical spacing between PAD and its frame */
int padframe_hspace = PADFRAME_HSPACE;	/* horizontal spacing between PAD and its frame */
X
int linewidth = LINEWIDTH;		/* thickness of line */
int padlinewidth = PADLINEWIDTH;	/* thickness of PAD figure */
int framelinewidth = FRAMELINEWIDTH;	/* thickness of PAD frame */
X
int fontsize = FONTSIZE;		/* font size (height of characters) */
int fontwidth = FONTWIDTH;		/* width of font (alphabets) */
int jfontwidth = JFONTWIDTH;		/* width of font (japanese characters) */
double title_rate = TITLE_RATE;		/* magnification rate of title */
double padtitle_rate = PADTITLE_RATE;	/* magnification rate of PAD title */
double figure_rate = FIGURE_RATE;	/* magnification rate of PAD figure */
X
char font[] = "Courier";			/* font */
char title_font[] = "Courier-Bold";		/* title font */
#ifdef JAPANESE
char jfont[] = "Ryumin-Light-EUC-H";		/* Japanese font */
char title_jfont[] = "GothicBBB-Medium-EUC-H";	/* Japanese font for title */
#endif
X
double vrate = 1.0;		/* magnification rate (vertical) */
double hrate = 1.0;		/* magnification rate (horizontal) */
X
double proper_hrate = 99999.9;	/* appropriate hrate value */
X
int first_x = 0;		/* the starting x-coordinate */
int next_y = 10;		/* the following PAD's y-coordinate */
X
int most_right = 0;		/* the rightmost PAD's x-coordinate */
int most_left = PAGE_RIGHT;	/* the leftmost PAD's x-coordinate */
X
PAD *root = NULL;		/* root of the tree structure */
PAD *current = NULL;		/* current position of the tree structure */
BOX *first = NULL;		/* beginning of the list */
BOX *lp = NULL;			/* current position of the list */
X
bool print_warning = Off;	/* whether to print warning */
int line_count = 1;		/* line in process */
X
FILE *input_stream;		/* input file */
FILE *fp = stdout;		/* output file */
char outfile[BUFSIZ] = {'\0'};	/* output file name */
char outdir[BUFSIZ] = {'\0'};	/* directory to put output file */
X
X
#ifdef JAPANESE
static char kconv[BUFSIZ] = "nkf -e";	/* KANJI converter */
static bool noconv = Off;		/* -noconv */
#endif
static bool nohelp = Off;		/* -nohelp */
static bool parameter_flag = Off;	/* -P */
static bool stdin_flag = Off;		/* -stdin */
X
static char thiscmd[BUFSIZ] = {'\0'};	/* executed command name */
static char filename[BUFSIZ] = {'\0'};	/* input file name */
static char command[BUFSIZ];		/* command */
static char paramfile[BUFSIZ];		/* file name for handling parameters */
X
X
static void pad_parser(void);		/* call PAD parser */
static void parameter(void);		/* parameter set in -P */
X
static void option(int,char **);	/* handle options */
static void print_help(void);		/* print help messages */
X
#if defined(HAVE_ATEXIT)
static void at_exit(void);		/* handle termination process */
#elif defined(HAVE_ON_EXIT)
static void at_exit(int,void *);	/* handle termination process */
#endif
X
int main(int argc,char **argv)
{
X    char *env;
X
X    /* handle exit() */
#if defined(HAVE_ATEXIT)
X    atexit(at_exit);
#elif defined(HAVE_ON_EXIT)
X    on_exit(at_exit,NULL);
#endif
X
X    /* file name for handling parameters */
#ifdef TMP
X    strcpy(paramfile,TMP);
X    strcat(paramfile,"/");
#else
X    strcpy(paramfile,"/tmp/");
#endif
X    if((env = getenv("TMP")) != NULL  &&  strlen(env) > 0){
X	/* get the environment variable TMP */
X	strcpy(paramfile,env);
X	strcat(paramfile,"/");
X    }
X    strcat(paramfile,"pad2ps-XXXXXX");
X
X    option(argc,argv);			/* handle options */
X
X    if(quiet == Off)
X	fprintf(stderr,"\n%s %s  by %s\n\n",thiscmd,VERSION,AUTHOR);
X
X    pad_parser();			/* call PAD parser */
X    parameter();			/* parameter set in -P */
X
X    if(outfile[0] != '\0'  &&  outdir[0] != '\0'){	/* directory for output file */
X	char tmp[BUFSIZ];
X	strcpy(tmp,outfile);
X	sprintf(outfile,"%s/%s",outdir,tmp);
X    }
X
X    if(strcmp(thiscmd,"pad2tex") == 0)
X	tex();
X    else{
X	fold();
X	locate();
X	sort();
X	if(strcmp(thiscmd,"pad2eps") == 0)
X	    eps_flag = On;
X	ps();
X    }
X
X    if(quiet == Off)
X	fprintf(stderr,"\n%d errors, %d warnings.\n",error_count,warning_count);
X
X    return 0;
}
X
void pad_parser(void)
/* call PAD parser */
{
X    if(stdin_flag == On)
X	filename[0] = '\0';
X
#ifdef JAPANESE
X    if(noconv == Off)
X	sprintf(command,"cat %s | %s",filename,kconv);
X    else
#endif
X	sprintf(command,"cat %s",filename);
X
X    input_stream = popen(command,"r");
X
X    parser();
X
X    pclose(input_stream);
}
X
void parameter(void)
/* parameter set in -P */
{
X    char tmp[BUFSIZ];
X
X    if(parameter_flag == On){
#ifdef JAPANESE
X	if(noconv == Off)
X	    sprintf(command,"cat %s | %s",paramfile,kconv);
X	else
#endif
X	    sprintf(command,"cat %s",paramfile);
X
X	input_stream = popen(command,"r");
X	parser();
X	pclose(input_stream);
X
X	remove(paramfile);
X    }
}
X
void option(int argc,char **argv)
/* handle options */
{
X    int i,l,p = -1;
X
X    for(i = 0 ; argv[0][i] != '\0' ; i++){	/* get executed command name */
X	if(argv[0][i] == '/')
X	    p = i;
X    }
X    strcpy(thiscmd,&argv[0][p+1]);
X
X    for(i = 1 ; i < argc ; i++){
X	if(argv[i][0] != '-'){
X	    if(filename[0] == '\0'){		/* input file name */
X		strcpy(filename,argv[i]);
X		l = strlen(argv[i]);
X		title = (char *)malloc((l+2) * sizeof(char));
X		strcpy(title,argv[i]);
X	    }else if(outfile[0] == '\0')	/* output file name */
X		strcpy(outfile,argv[i]);
X	    else if(nohelp == Off){
X		print_help();
X		exit(1);
X	    }
X	}else{				/* options */
X	    switch(argv[i][1]){
X		case 'd':
X		    if(strcmp(argv[i],"-dir") == 0){
X			strcpy(outdir,argv[++i]);
#ifdef DEBUG
X		    }else if(strcmp(argv[i],"-debug") == 0){
X			debug = On;
#endif
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 'h':
X		    if(strcmp(argv[i],"-help") == 0){
X			print_help();
X			exit(0);
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
#ifdef JAPANESE
X		case 'k':
X		    if(strcmp(argv[i],"-kconv") == 0  &&  i + 1 < argc){
X			strcpy(kconv,argv[++i]);
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
#endif
X		case 'n':
X		    if(strcmp(argv[i],"-nohelp") == 0){
X			nohelp = On;
#ifdef JAPANESE
X		    }else if(strcmp(argv[i],"-noconv") == 0){
X			noconv = On;
#endif
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 'P':
X		    if(strcmp(argv[i],"-P") == 0){
X			FILE *fp;
X
X			parameter_flag = On;
X			mktemp(paramfile);
X			fp = fopen(paramfile,"w");
X			i++;
X			while(i < argc  &&  argv[i][0] != '-'){
X			    fprintf(fp,"/* pad2ps: %s */\n",argv[i]);
X			    i++;
X			}
X			i--;
X			fclose(fp);
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 'q':
X		    if(strcmp(argv[i],"-quiet") == 0){
X			quiet = On;
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 's':
X		    if(strcmp(argv[i],"-stdin") == 0){
X			stdin_flag = On;
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 't':
X		    if(strcmp(argv[i],"-tab") == 0){
X			i++;
X			tab_width = atoi(argv[i]);
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		case 'w':
X		    if(strcmp(argv[i],"-warn") == 0){
X			print_warning = On;
X		    }else if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X		default:
X		    if(nohelp == Off){
X			print_help();
X			exit(1);
X		    }
X		    break;
X	    }
X	}
X    }
}
X
void print_help(void)
{
X    fprintf(stderr,"\n%s %s  by %s\n\n",thiscmd,VERSION,AUTHOR);
X    fprintf(stderr,"usage: %s [inputfile [outputfile]] [options]\n",thiscmd);
#ifdef DEBUG
X    fputs("-debug                  Print parser debug message.\n",stderr);
#endif
X    fputs("-dir directory          Directory to output files.\n",stderr);
X    fputs("-help                   Print help message.\n",stderr);
#ifdef JAPANESE
X    fputs("-kconv converter        Kanji code converter [default: \"nkf -e\"].\n",stderr);
X    fputs("-noconv                 Do not convert kanji code.\n",stderr);
#endif
X    fputs("-nohelp                 Do not print help message.\n",stderr);
X    fputs("-P parameters ...       Set parameters. Ex: -P page=1 figure=1\n",stderr);
X    fputs("-quiet                  Do not print messages.\n",stderr);
X    fputs("-stdin                  Input from stdin.\n",stderr);
X    fputs("-tab width              Set TAB width [default: 4].\n",stderr);
X    fputs("-warn                   Print warnings.\n",stderr);
}
X
X
#if defined(HAVE_ATEXIT) || defined(HAVE_ON_EXIT)
#if defined(HAVE_ATEXIT)
void at_exit(void)
#elif defined(HAVE_ON_EXIT)
void at_exit(int val, void *p)
#endif
/* handle termination process */
{
X    remove(paramfile);
}
#endif
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/pad2ps.c' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/pad2ps.c' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/pad2ps.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/pad2ps.c:' 'MD5 check failed'
fe4b66ddd680bac874a0433f30589a3c  pad2ps-3.1/src/pad2ps/pad2ps.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/pad2ps.c'`"
    test 11023 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/pad2ps.c:' 'original size' '11023,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/locate.c ==============
if test -f 'pad2ps-3.1/src/pad2ps/locate.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/locate.c' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/locate.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/locate.c' &&
/*                            */
/*  locate.c --  Locate PAD   */
/*                            */
/*  pad2ps  by S. Yoshida     */
/*                            */
X
#include "config.h"
X
#include <string.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#include "pad2ps.h"
#include "lib.h"
X
static int page_number = 0;
static int padtitle_center = EOF;
X
static void init_locate(void);
static void init_body(void);
X
static void body(PAD *);
static int commands(PAD *,int);
static int command(PAD *,int);
static int message(PAD *,int);
static int just_string(PAD *p,int);
static int label_statement(PAD *p,int);
static int block_statement(PAD *p,int);
static int refer_statement(PAD *p,int);
static int repeat_statement(PAD *p,int);
static int branch_statement(PAD *p,int);
static int if_statement(PAD *p,int);
static int switch_statement(PAD *p,int);
X
static void print_title(void);
static void print_padtitle(PAD *);
static void print_figure(char *);
static void print_padframe(int);
X
static void print_pagenumber(void);
static void centerize(BOX *);
static void check_overflow(int,int);
static double calc_hrate(void);
static void move_down(BOX *,int);
static void move_right(BOX *,int);
X
static void pad_allocate(PAD *,int,int);
static void allocate(char *,int,int,int,int,TYPE);
X
void locate(void)
/* locate PAD */
{
X    PAD *ptr;
X    int body_count = 0;
X    int h,page_height;
X
#ifdef DEBUG
X    if(quiet == Off)
X        fprintf(stderr,"PAD locating starts...");
#endif
X
X    init_locate();
X
X    if(title != NULL)
X	print_title();
X
X    for(ptr = root->next ; ptr != NULL ; ptr = ptr->next){
X	init_body();
X
X	switch(ptr->type){
X	    case Empty:
X		if(body_count > 0)
X		    next_y += pad_vspace;
X		break;
X	    case Newpage:
X		page_height = (int)((page_top - page_bottom) / vrate);
X		h = (next_y - vspace) % page_height;
X		next_y += page_height - h + 1;
X		break;
X	    case Vsp:
X		next_y += ptr->value;
X		break;
X	    default:
X		if (body_count > 0  &&  slice == On) {
X		    page_height = (int)((page_top - page_bottom) / vrate);
X		    h = (next_y - vspace) % page_height;
X		    next_y += page_height - h + 1;
X		}
X		body(ptr);
X		body_count++;
X	}
X    }
X
X    next_y -= pad_vspace;
X
X    if(quiet == Off  &&  print_warning == On){	/* print page number */
X        if(next_y / (int)((double)(page_top - page_bottom) / vrate) > page_number)
X	    print_pagenumber();
X        print_pagenumber();
X    }
X
#ifdef DEBUG
X    if(quiet == Off)
X        fprintf(stderr,"done\n");
#endif
}
X
void init_locate(void)
/* initialization */
{
X    first_x = 0;
X    next_y = 10;
X    page_number = 0;
X    first = NULL;
X    lp = NULL;
X
X    if(figure_locate_flag == Off){	/* figure_locate default */
X	if(figure == EOF)
X	    figure_locate = Top;
X	else
X	    figure_locate = Bottom;
X    }
}
X
void init_body(void)
/* initialze PAD body as a whole */
{
X    most_right = 0;
X    most_left = PAGE_RIGHT;
}
X
void body(PAD *ptr)
/* PAD body */
{
X    BOX *p;
X    int frame_y;
X
X    p = lp;
X
X    if(titlebox == On){
X	if(figure_locate == Top  &&  figure != EOF)
X	    print_figure(NULL);
X	if(padframe == On){
X	    frame_y = next_y;
X	    next_y += padframe_vspace;
X	}
X	if(ptr->str != NULL){
X	    pad_allocate(ptr,first_x,next_y);
X	    padtitle_center = next_y + lp->h / 2;
X	    next_y += lp->h + vspace;
X	}
X    }else{
X	if(figure_locate == Top){
X	    if(figure == EOF){
X		if(ptr->str != NULL)
X		    print_padtitle(ptr);
X	    }else
X		print_figure(ptr->str);
X
X	    p = lp;
X	}
X	if(padframe == On){
X	    frame_y = next_y;
X	    next_y += padframe_vspace;
X	}
X    }
X
X    if(ptr->child != NULL)
X	commands(ptr->child,first_x);
X
X    if(padframe == On)		/* print PAD frame */
X        print_padframe(frame_y);
X
X    if(centering == On)		/* print in center */
X        centerize(p);
X
X    proper_hrate = smaller(proper_hrate,calc_hrate());
X
X    if(figure_locate == Bottom){
X	if(figure == EOF){
X	    if(ptr->str != NULL  &&  titlebox == Off)
X		print_padtitle(ptr);
X	}else
X	    print_figure(ptr->str);
X    }
}
X
int commands(PAD *ptr,int x)
/* return y-coordinate of the initial PAD box's center line */
{
X    PAD *p;
X    int first_center = EOF;
X    int last_center,center;
X    int first_mes = EOF,last_mes;
X    int h,page_height;
X
X    for(p = ptr ; p != NULL ; p = p->next){
X	switch(p->type){
X	    case Newpage:
X		page_height = (int)((page_top - page_bottom) / vrate);
X		h = (next_y - vspace) % page_height;
X		next_y += page_height - h + 1;
X		break;
X	    case Empty:
X		next_y += vspace;
X		break;
X	    case Vsp:
X		next_y += p->value;
X		break;
X	    case Message:
X	    case Label:
X		last_mes = command(p,x);
X		if(first_mes == EOF)
X		    first_mes = last_mes;
X		break;
X	    default:
X		center = command(p,x);
X		if(center != EOF){
X		    if(first_center == EOF){
X			first_center = center;
X			if(padtitle_center != EOF  &&  x == first_x){
X						/* allocate with PAD title */
X			    allocate(NULL,x,padtitle_center,0,center - padtitle_center,Line);
X			    padtitle_center = EOF;
X			}
X		    }else
X			allocate(NULL,x,last_center,0,center - last_center,Line);
X						/* draw perpendicular line */
X		    last_center = center;
X		}
X	}
X    }
X
X    if(first_center != EOF){	/* normal case */
X	switch(locate_type){
X	    case Topdown:
X		return first_center;
X	    case Middle:
X		return (first_center + last_center) / 2;
X	    case Bottomup:
X		return last_center;
X	}
X    }else{
X	if(first_mes != EOF){	/* only message */
X	    switch(locate_type){
X		case Topdown:
X		    return first_mes;
X		case Middle:
X		    return (first_mes + last_mes) / 2;
X		case Bottomup:
X		    return last_mes;
X	    }
X	}else			/* no content or only empty lines */
X	    return EOF;
X    }
}
X
int command(PAD *ptr,int x)
/* return y-coordinate of the center line */
{
X    int center;
X
X    if(quiet == Off  &&  print_warning == On  && 
X       (next_y - vspace) / (int)((double)(page_top - page_bottom) / vrate) > page_number)
X        print_pagenumber();		/* print page number */
X
X    switch(ptr->type){
X	case For:
X	case While:
X	case Do:
X	    center = repeat_statement(ptr,x);
X	    break;
X	case If:
X	case Switch:
X	    center = branch_statement(ptr,x);
X	    break;
X	case Block:
X	    center = block_statement(ptr,x);
X	    break;
X	case Label:
X	    center = label_statement(ptr,x);
X	    break;
X	case Refer:
X	    center = refer_statement(ptr,x);
X	    break;
X	case Message:
X	    center = message(ptr,x);
X	    break;
X	default:
X	    center = just_string(ptr,x);
X	    break;
X    }
X
X    return center;
}
X
int message(PAD *ptr,int x)
/* messages */
{
X    int center;
X    refold_pad(ptr,right_limit - x - box_hspace);
X    allocate(ptr->str,x + box_hspace,next_y,get_str_width(ptr),get_str_height(ptr),Str);
X    center = next_y + lp->h / 2;
X    next_y += lp->h + vspace;
X    return center;
}
X
int just_string(PAD *ptr,int x)
/* PAD box */
{
X    PAD *p;
X    BOX *rt;
X    int center;
X    int h,w;
X
X    p = ptr->child;
X
X    if(p == NULL){			/* no comment */
X	refold_pad(ptr,right_limit - x - box_hspace * 2);
X	pad_allocate(ptr,x,next_y);
X	center = next_y + lp->h / 2;
X	next_y += lp->h + vspace;
X    }else{				/* with comment */
X	pad_allocate(ptr,x,next_y);
X	center = next_y + lp->h / 2;
X	h = lp->h;
X	w = lp->w + box_hspace;
X	rt = lp;
X
X	refold_pad(p,right_limit - x - w);
X	allocate(p->str,x + w,next_y,get_str_width(p),get_str_height(p),Str);
X
X	if(h > lp->h){			/* shift down the comment */
X	    move_down(lp,(h - lp->h) / 2);
X	    next_y += h + vspace;
X	}else{				/* shift down the box */
X	    move_down(rt,(lp->h - h) / 2);
X	    center += (lp->h - h) / 2;
X	    next_y += lp->h + vspace;
X	}
X    }
X
X    return center;
}
X
int label_statement(PAD *ptr,int x)
/* label */
{
X    PAD *p;
X    BOX *rt;
X    int center;
X    int h,w;
X
X    p = ptr->child;
X
X    if(p == NULL){			/* no comment */
X	refold_pad(ptr,(int)((double)(right_limit - x - linewidth) / SQRT2));
X	pad_allocate(ptr,x,next_y);
X	center = next_y + lp->h / 2;
X	next_y += lp->h + vspace;
X    }else{				/* with comment */
X	pad_allocate(ptr,x,next_y);
X	center = next_y + lp->h / 2;
X	h = lp->h;
X	w = lp->w + box_hspace;
X	rt = lp;
X
X	refold_pad(p,right_limit - x - w);
X	allocate(p->str,x + w,next_y,get_str_width(p),get_str_height(p),Str);
X
X	if(h > lp->h){			/* shift down the comment */
X	    move_down(lp,(h - lp->h) / 2);
X	    next_y += h + vspace;
X	}else{				/* shift down the box */
X	    move_down(rt,(lp->h - h) / 2);
X	    center += (lp->h - h) / 2;
X	    next_y += lp->h + vspace;
X	}
X    }
X
X    return center;
}
X
int block_statement(PAD *ptr,int x)
/* block */
{
X    PAD *p;
X    BOX *rt,*bp;
X    int center,dy,h,w = 0;
X
X    for(p = ptr->child ; p != NULL ; p = p->next){
X	if(p->type != Empty){
X	    if(ptr->depth == NULL)		/* no comment */
X		refold_pad(p,right_limit - x - box_hspace * 2);
X	    w = greater(w,get_str_width(p));
X	}
X    }
X
X    rt = lp;
X
X    dy = box_vspace;
X    for(p = ptr->child ; p != NULL ; p = p->next){
X	if(p->type == Empty){
X	    dy += vspace;
X	}else{
X	    allocate(p->str,x + box_hspace,next_y + dy,w,0,Str);
X	    p->lines = get_str_lines(p,w);
X	    lp->h = get_str_height(p);
X	    dy += lp->h;
X	}
X    }
X    dy += box_vspace;
X
X    w = lp->w + box_hspace * 2;
X    allocate(NULL,x,next_y,w,dy,Box);
X    center = next_y + lp->h / 2;
X    h = lp->h;
X    w = lp->w + box_hspace;
X
X    p = ptr->depth;
X
X    if(p != NULL){		/* with comment */
X	refold_pad(p,right_limit - x - w);
X	allocate(p->str,x + w,next_y,get_str_width(p),get_str_height(p),Str);
X
X	if(h > lp->h){			/* shift down the comment */
X	    move_down(lp,(h - lp->h) / 2);
X	    next_y += h + vspace;
X	}else{				/* shift down the block */
X	    for(bp = rt ; bp != lp ; bp = bp->next)
X		move_down(bp,(lp->h - h) / 2);
X	    center += (lp->h - h) / 2;
X	    next_y += lp->h + vspace;
X	}
X    }else			/* no comment */
X	next_y += h + vspace;
X
X    return center;
}
X
int refer_statement(PAD *ptr,int x)
/* reference */
{
X    PAD *p;
X    BOX *rt,*bp;
X    int center,dy,h,w = 0,rx;
X
X    for(p = ptr->child ; p != NULL ; p = p->next){
X	if(p->type != Empty){
X	    if(ptr->depth == NULL)		/* no comment */
X		refold_pad(p,right_limit - x - (int)((double)get_str_width(ptr) * SQRT2) - box_hspace * 3);
X	    w = greater(w,get_str_width(p));
X	}
X    }
X
X    rt = lp;
X
X    dy = box_vspace;
X    for(p = ptr->child ; p != NULL ; p = p->next){
X	if(p->type == Empty){
X	    dy += vspace;
X	}else{
X	    allocate(p->str,x + box_hspace,next_y + dy,w,0,Str);
X	    p->lines = get_str_lines(p,w);
X	    lp->h = get_str_height(p);
X	    dy += lp->h;
X	}
X    }
X    dy += box_vspace;
X
X    rx = x + box_hspace * 2 + lp->w;
X    w = lp->w + (int)((double)get_str_width(ptr) * SQRT2) + box_hspace * 3;
X    allocate(NULL,x,next_y,w,dy,Box);
X    center = next_y + lp->h / 2;
X    h = lp->h;
X    w = lp->w + box_hspace;
X
X    pad_allocate(ptr,rx,next_y + box_vspace);
X
X    if(h > lp->h + box_vspace * 2){	/* shift down the reference */
X	move_down(lp,(h - lp->h - box_vspace * 2) / 2);
X    }else{				/* shift down the block */
X	for(bp = rt ; bp->next != lp ; bp = bp->next)
X	    move_down(bp,(lp->h + box_vspace * 2 - h) / 2);
X	bp->h = lp->h + box_vspace * 2;
X	center += (lp->h + box_vspace * 2 - h) / 2;
X	h = lp->h + box_vspace * 2;
X    }
X
X    p = ptr->depth;
X
X    if(p != NULL){		/* with comment */
X	refold_pad(p,right_limit - x - w);
X	allocate(p->str,x + w,next_y,get_str_width(p),get_str_height(p),Str);
X
X	if(h > lp->h){			/* shift down the comment */
X	    move_down(lp,(h - lp->h) / 2);
X	    next_y += h + vspace;
X	}else{				/* shift down the block */
X	    for(bp = rt ; bp != lp ; bp = bp->next)
X		move_down(bp,(lp->h - h) / 2);
X	    center += (lp->h - h) / 2;
X	    next_y += lp->h + vspace;
X	}
X    }else			/* no comment */
X	next_y += h + vspace;
X
X    return center;
}
X
int repeat_statement(PAD *ptr,int x)
/* for statement, while statement, and do-while statement */
{
X    BOX *rt,*p;
X    int w,y,center,parent_next_y,child_y;
X    bool none = Off;
X
X    pad_allocate(ptr,x,next_y);
X    center = next_y + lp->h / 2;
X    parent_next_y = next_y + lp->h + vspace;
X
X    rt = lp;
X    w = lp->w;
X
X    y = next_y;
X    child_y = commands(ptr->child,x + w + hspace);
X    if(child_y == EOF){		/* no repetition body or with only empty lines */
X	child_y = (y + next_y - vspace) / 2;
X	none = On;
X    }
X
X    if(center < child_y){	/* shift down for/while/do-while statement */
X	move_down(rt,child_y - center);
X	center += child_y - center;
X	parent_next_y += child_y - center;
X    }else{			/* shift down the repetition PAD body */
X	for(p = rt->next ; p != NULL ; p = p->next)
X	    move_down(p,center - child_y);
X	next_y += center - child_y;
X    }
X
X    if(none == Off)
X	allocate(NULL,x + w,center,hspace,0,Line);	/* draw horizontal line */
X
X    next_y = greater(next_y,parent_next_y);
X    return center;
}
X
int branch_statement(PAD *ptr,int x)
/* if statement and switch statement */
{
X    if(ptr->type == If  &&  (ptr->child_number == 1  ||
X       (ptr->child_number == 2  &&  ptr->child->next->str == NULL)))
X	return if_statement(ptr,x);
X    else
X	return switch_statement(ptr,x);
}
X
int if_statement(PAD *ptr,int x)
/* if statement */
{
X    PAD *p;
X    BOX *rt;
X    int w,y,top,bottom,child_y;
X    bool none1 = Off, none2 = Off;
X
X    p = ptr->child;
X
X    w = get_str_width(p) + p->space_width;
X
X    y = next_y;
X    top = commands(p->child,x + w + hspace);			/* true part */
X    if(top == EOF){		/* no true part or only empty lines */
X	top = (y + next_y - vspace) / 2;
X	none1 = On;
X    }
X
X    pad_allocate(p,x + box_hspace,top + if_vspace);
X    rt = lp;
X    bottom = top + if_vspace * 2 + lp->h;
X
X    if(p->next != NULL){
X	y = next_y;
X	child_y = commands(p->next->child,x + w + hspace);	/* false part */
X	if(child_y == EOF){		/* no false part or only empty lines */
X	    child_y = (y + next_y - vspace) / 2;
X	    none2 = On;
X	}
X
X	if(bottom < child_y){			/* shift down the conditional statement */
X	    move_down(rt,(child_y - bottom) / 2);
X	    bottom = child_y;
X	}else{					/* shift down the branch part */
X	    for(rt = rt->next ; rt != NULL ; rt = rt->next)
X		move_down(rt,bottom - child_y);
X	    next_y += bottom - child_y;
X	}
X	if(none2 == Off)
X	    allocate(NULL,x + w,bottom,hspace,0,Line);	/* draw horizontal line */
X    }
X
X    if(none1 == Off)
X	allocate(NULL,x + w,top,hspace,0,Line);		/* draw horizontal line */
X    allocate(NULL,x,top,w,bottom - top,If);
X    lp->flag1 = On; lp->flag2 = On;
X
X    next_y = greater(next_y,bottom + vspace);
X    return (top + bottom) / 2;
}
X
int switch_statement(PAD *ptr,int x)
/* switch statement */
{
X    PAD *p,*q;
X    BOX *rt_labels,*rt;
X    int i,y,h,w = 0;
X    int cond_width;
X    int top,bottom,center;
X    int parent_next_y,child_y,prev_y,label_y;
X    int count = 0;
X    bool none = Off;
X
X    if(ptr->child == NULL)	/*  switch statement with no content */
X	return EOF;
X
X    parent_next_y = next_y;
X    top = next_y;
X
X    for(p = ptr->child ; p != NULL ; p = p->next)	/* unify length of conditional statements */
X	w = greater(w,get_str_width(p));
X    cond_width = w;
X    w += ptr->child->space_width;
X
X    for(p = ptr->child ; p != NULL ; p = p->next){
X	count++;
X
X	rt_labels = lp;
X
X	center = parent_next_y;
X	for(q = p ; q != NULL ; q = q->depth){		/* branch label */
X	    allocate(q->str,x + box_hspace,parent_next_y,cond_width,0,Str);
X	    q->lines = get_str_lines(q,cond_width);
X	    lp->h = get_str_height(q);
X	    parent_next_y += lp->h;
X	}
X	center = (center + parent_next_y) / 2;
X	parent_next_y += vspace;
X
X	rt = lp;
X
X	y = next_y;
X	none = Off;
X	child_y = commands(p->child,x + w + hspace);
X	if(child_y == EOF){	/* no branch part or only with empty lines */
X	    child_y = (y + next_y - vspace) / 2;
X	    none = On;
X	}
X
X	if(count == 1){				/* first conditional statement */
X	    for(i = 0 ; i <= p->depth_number ; i++){
X		rt_labels = rt_labels->next;
X		move_down(rt_labels,child_y - top);
X	    }
X	    parent_next_y += child_y - top;
X	    top = child_y;
X	}else{
X	    if(count == ptr->child_number)	/* last conditional statement */
X		label_y = parent_next_y - vspace;
X	    else				/* other conditional statement */
X		label_y = center;
X
X	    if(label_y < child_y){		/* shift down the conditional statement */
X		for(i = 0 ; i <= p->depth_number ; i++){
X		    rt_labels = rt_labels->next;
X		    move_down(rt_labels,child_y - label_y);
X		}
X		parent_next_y += child_y - label_y;
X	    }else{				/* shift down the conditional statement */
X		for(rt = rt->next ; rt != NULL ; rt = rt->next)
X		    move_down(rt,label_y - child_y);
X		next_y += label_y - child_y;
X		child_y += label_y - child_y;
X	    }
X
X	    bottom = parent_next_y;
X	}
X
X	if(count > 1){
X	    allocate(NULL,x,prev_y,w,child_y - prev_y,If);
X	    if(count == 2)
X		lp->flag1 = On;
X	    if(count == ptr->child_number)
X		lp->flag2 = On;
X	}
X
X	if(none == Off)
X	    allocate(NULL,x + w,child_y,hspace,0,Line);	/* draw horizontal line */
X
X	prev_y = child_y;
X    }
X
X    if(ptr->child_number == 1){			/* one branch destination */
X	h = greater(if_height,parent_next_y - top);
X	allocate(NULL,x,top,w,h,If);
X	lp->flag1 = On; lp->flag2 = On;
X	bottom = top + h;
X    }
X
X    next_y = greater(next_y,bottom + vspace);
X    return (top + bottom) / 2;
}
X
void print_title(void)
/* print overall title */
{
X    PAD pad;
X    int dx;
X
X    change_font(title_rate);
X    pad.type = Title;
X    pad.str = title;
X    refold_pad(&pad,page_width);
X    allocate(title,x_center,next_y,get_str_width(&pad),get_str_height(&pad),Title);
X    dx = - lp->w / 2;
X    move_right(lp,dx);
X    next_y += lp->h + pad_vspace;
X    restore_font();
}
X
void print_padtitle(PAD *ptr)
/* print PAD titile */
{
X    int dx;
X
X    change_font(padtitle_rate);
X    refold_pad(ptr,page_width);
X    allocate(ptr->str,x_center,next_y,get_str_width(ptr),get_str_height(ptr),Padtitle);
X    dx = - lp->w / 2;
X    move_right(lp,dx);
X    next_y += lp->h + vspace * 2;
X    restore_font();
}
X
void print_figure(char *str)
/* print figure */
{
X    PAD pad;
X    char *p,tmp[20];
X    int l,dx;
X
X    sprintf(tmp,"Figure %d",figure);
X    if(str != NULL  &&  titlebox == Off)
X        strcat(tmp,":  ");
X
X    l = strlen(tmp);
X    p = (char *)malloc((l+2) * sizeof(char));
X    strcpy(p,tmp);
X
X    if(str != NULL  &&  titlebox == Off)
X	p = joint(2,p,str);
X
X    change_font(figure_rate);
X    pad.type = Figure;
X    pad.str = p;
X    refold_pad(&pad,page_width);
X    allocate(p,x_center,next_y,get_str_width(&pad),get_str_height(&pad),Figure);
X    dx = - lp->w / 2;
X    move_right(lp,dx);
X    restore_font();
X
X    figure++;
X    next_y += lp->h + vspace;
}
X
void print_padframe(int y)
/* print PAD frame */
{
X    int lx,rx;
X
X    next_y += padframe_vspace - vspace;
X
X    if(centering == On){
X        most_left -= padframe_hspace;
X	most_right += padframe_hspace;
X	lx = most_left;
X	rx = most_right;
X    }else{
X        most_left -= page_left;
X        most_right += page_left;
X        lx = - page_left;
X	rx = greater(lx + (int)((double)(X_MAX / hrate)),most_right);
X    }
X
X    allocate(NULL, lx, y, rx - lx, 0 ,Padframe);
X    allocate(NULL, lx, y, 0, next_y - y, Padframe);
X    allocate(NULL, rx, y, 0, next_y - y, Padframe);
X    allocate(NULL, lx, next_y, rx - lx, 0, Padframe);
X
X    next_y += vspace;
}
X
void print_pagenumber(void)
/* print page number */
{
X    fprintf(stderr,"[%d]\n",page+(++page_number));
}
X
void centerize(BOX *ptr)
/* print in center */
{
X    BOX *p;
X
X    if(ptr == NULL)
X	p = first;
X    else
X	p = ptr->next;
X
X    for( ; p != NULL ; p = p->next)
X        move_right(p,- (most_right + most_left) / 2);
}
X
void check_overflow(int left,int right)
/* check for sticking out to side */
{
X    most_left = smaller(most_left,left);
X    most_right = greater(most_right,right);
}
X
double calc_hrate(void)
/* calculate appropriate hrate */
{
X    double r;
X
X    r = (double)X_MAX / (double)(most_right - most_left);
X
X    if(r < 0.0)
X	return proper_hrate;
X    else if(r >= hrate)
X	return r;
X    else
X	return r * 0.999;
}
X
void move_down(BOX *p,int dy)
/* move PAD lower */
{
X    STRING *s;
X
X    p->y += dy;
X    if(p->str != NULL){
X	for(s = p->str ; s != NULL ; s = s->next)
X	    s->y += dy;
X    }
}
X
void move_right(BOX *p,int dx)
/* move PAD to right */
{
X    STRING *s;
X
X    p->x += dx;
X    if(p->str != NULL){
X	for(s = p->str ; s != NULL ; s = s->next)
X	    s->x += dx;
X    }
}
X
void pad_allocate(PAD *ptr,int x0,int y0)
/* add list (from tree structure) */
{
X    int x,y,w,h;
X
X    x = x0; y = y0;
X
X    if(first == NULL){
X        first = (BOX *)malloc(sizeof(BOX));
X	lp = first;
X	lp->prev = NULL;
X    }else{
X        BOX *prev;
X	prev = lp;
X        lp->next = (BOX *)malloc(sizeof(BOX));
X	lp = lp->next;
X	lp->prev = prev;
X    }
X    lp->next = NULL;
X
X    lp->x = x;
X    lp->y = y;
X    lp->w = get_str_width(ptr);
X    lp->h = 0;
X    lp->flag1 = Off;
X    lp->flag2 = Off;
X
X    switch(ptr->type){
X	case Padtitle:
X	    lp->type = Box;
X	    x += box_hspace + sideline_space;
X	    y += box_vspace;
X	    lp->w += box_hspace * 2 + sideline_space * 2;
X	    lp->h += box_vspace * 2;
X	    lp->flag1 = On;
X	    lp->flag2 = On;
X	    break;
X	case Box:
X	    lp->type = Box;
X	    x += box_hspace;
X	    y += box_vspace;
X	    lp->w += box_hspace * 2;
X	    lp->h += box_vspace * 2;
X	    break;
X	case Label:
X	    x += linewidth;
X	    lp->w += linewidth;
X	case Refer:
X	    lp->type = Label;
X	    w = (int)((double)lp->w * (SQRT2 - 1.0));
X	    h = (int)((double)get_str_height(ptr) * (SQRT2 - 1.0));
X	    x += w / 2;
X	    y += h / 2;
X	    lp->w += w;
X	    lp->h += h;
X	    break;
X	case For:
X	case While:
X	    lp->type = Box;
X	    x += box_hspace + sideline_space;
X	    y += box_vspace;
X	    lp->w += box_hspace * 2 + sideline_space;
X	    lp->h += box_vspace * 2;
X	    lp->flag1 = On;
X	    break;
X	case Do:
X	    lp->type = Box;
X	    x += box_hspace;
X	    y += box_vspace;
X	    lp->w += box_hspace * 2 + sideline_space;
X	    lp->h += box_vspace * 2;
X	    lp->flag2 = On;
X	    break;
X	case Cond:
X	    lp->type = Str;
X	    break;
X    }
X
X    if(ptr->str == NULL)
X	lp->str = NULL;
X    else{
X	lp->str = string(ptr->str,x,y,get_str_width(ptr));
X	lp->h += get_str_height(ptr);
X    }
X
X    check_overflow(lp->x,lp->x + lp->w);
}
X
void allocate(char *s,int x,int y,int w,int h,TYPE type)
/* add list */
{
X    if(first == NULL){
X        first = (BOX *)malloc(sizeof(BOX));
X	lp = first;
X	lp->prev = NULL;
X    }else{
X        BOX *prev;
X	prev = lp;
X        lp->next = (BOX *)malloc(sizeof(BOX));
X	lp = lp->next;
X	lp->prev = prev;
X    }
X    lp->next = NULL;
X
X    lp->type = type;
X    lp->x = x;
X    lp->y = y;
X    lp->w = w;
X    lp->h = h;
X    lp->flag1 = Off;
X    lp->flag2 = Off;
X
X    if(s != NULL)
X	lp->str = string(s,x,y,w);
X    else
X	lp->str = NULL;
X
X    if( ! (type == Title  ||  type == Figure  ||
X	  (type == Padtitle  &&  titlebox == Off)))
X	check_overflow(lp->x,lp->x + lp->w);
}
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/locate.c' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/locate.c' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/locate.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/locate.c:' 'MD5 check failed'
1000931faf1aad7272f890bf7327dadd  pad2ps-3.1/src/pad2ps/locate.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/locate.c'`"
    test 22399 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/locate.c:' 'original size' '22399,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/fold.c ==============
if test -f 'pad2ps-3.1/src/pad2ps/fold.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/fold.c' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/fold.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/fold.c' &&
/*                                  */
/*  fold.c -- Auto-folding PAD      */
/*                                  */
/*  pad2ps  by S. Yoshida           */
/*                                  */
X
#include "config.h"
X
#include <string.h>
#include <math.h>
#include "pad2ps.h"
#include "lib.h"
X
static int total_amount = 0;
X
static void init_to_fold(void);
static void set_pagewidth(void);
static INT2 setting_tree(PAD *);
static void set_length(PAD *);
X
static void auto_fold(PAD *);
static PAD *find_fold(PAD *);
static void fold_pad(PAD *);
X
static void set_whole_width(PAD *);
static int over_maxlength(PAD *);
X
void fold(void)
/* folding PAD automatically */
{
X    PAD *ptr,*p;
X    int childs,amount;
X
#ifdef DEBUG
X    if(quiet == Off)
X        fprintf(stderr,"Automatic folding starts...");
#endif
X
X    init_to_fold();
X
X    for(ptr = root->next ; ptr != NULL ; ptr = ptr->next){
X	if(titlebox == On){		/* fold title */
X	    push(ptr->child); ptr->child = NULL;
X	    childs = ptr->child_number; ptr->child_number = 0;
X	    amount = ptr->amount;
X
X	    auto_fold(ptr);
X
X	    ptr->child = pop(); ptr->child_number = childs;
X	    ptr->amount = amount;
X	}
X	total_amount++;
X
X	for(p = ptr->child ; p != NULL ; p = p->next){
X	    auto_fold(p);
X	    total_amount += p->amount;
X	}
X    }
X
X    if(quiet == Off)
X	fputs("0% |*************************************************| 100%\n",stderr);
X
#ifdef DEBUG
X    if(quiet == Off)
X        fprintf(stderr,"done\n");
#endif
}
X
void init_to_fold(void)
/* initialization */
{
X    PAD *ptr;
X
X    set_pagewidth();
X    setting_tree(root);
X    root->amount = 0;
X    for(ptr = root->next ; ptr != NULL ; ptr = ptr->next){
X	root->amount += ptr->amount;
X    }
}
X
void set_pagewidth(void)
/* set page width */
{
X    if(centering == On){
X	x_center = 0;
X	left_limit = 0;
X	right_limit = X_MAX;
X    }else{
X	x_center = (int)((double)X_CENTER / hrate) - page_left;
X	left_limit = page_left;
X	right_limit = page_right;
X    }
X    left_limit = (int)((double)(left_limit / hrate));
X    right_limit = (int)((double)(right_limit / hrate));
X
X    if(padframe == On){
X	if(centering == On)
X	    right_limit -= padframe_hspace * 2;
X	else
X	    right_limit -= page_left * 2;
X    }
X
X    page_width = right_limit - left_limit;
}
X
INT2 setting_tree(PAD *rt)
/* setting tree structure */
{
X    PAD *ptr,*p;
X    INT2 t,tc;
X
X    t.count = 0;
X    t.amount = 0;
X
X    for(ptr = rt ; ptr != NULL ; ptr = ptr->next){
X	t.count++;
X	ptr->amount = 1;
X
X	set_length(ptr);
X
X	if(ptr->child != NULL){
X	    tc = setting_tree(ptr->child);
X	    ptr->child_number = tc.count;
X	    ptr->amount += tc.amount;
X	}
X
X	if(ptr->depth != NULL){
X	    for(p = ptr->depth ; p != NULL ; p = p->depth){
X		ptr->depth_number++;
X		ptr->amount++;
X
X		set_length(p);
X		p->child_number = ptr->child_number;
X	    }
X	}
X
X	t.amount += ptr->amount;
X    }
X
X    return t;
}
X
void set_length(PAD *ptr)
/* setting each PAD's side width */
{
X    ptr->lines = 1;
X    ptr->child_number = 0;
X    ptr->depth_number = 0;
X    ptr->enable_fold = On;
X
X    switch(ptr->type){
X	case Root:
X	case Empty:
X	case Newpage:
X	case Vsp:
X	case Str:
X	    ptr->space_width = 0;
X	    break;
X	case Message:
X	case Comment:
X	    ptr->space_width = box_hspace;
X	    break;
X	case Block:
X	case Box:
X	    ptr->space_width = box_hspace * 2;
X	    break;
X	case Label:
X	    ptr->space_width = linewidth + (int)((double)get_str_width(ptr) * (SQRT2 - 1.0));
X	    break;
X	case Refer:
X	    ptr->space_width = box_hspace * 3 + (int)((double)get_str_width(ptr) * (SQRT2 - 1.0));
X	    break;
X	case Padtitle:
X	    if(titlebox == On)
X		ptr->space_width = box_hspace * 2 + sideline_space * 2;
X	    else
X		ptr->space_width = 0;
X	    break;
X	case For:
X	case While:
X	case Do:
X	    ptr->space_width = box_hspace * 2 + sideline_space + hspace;
X	    break;
X	case If:
X	case Switch:
X	    ptr->space_width = hspace;
X	    break;
X	case Cond:
X	    ptr->space_width = box_hspace * 2 + if_rightspace;
X	    break;
X    }
}
X
void auto_fold(PAD *rt)
/* auto-fold PAD string (set the folding width automatically) */
{
X    PAD *p;
X    char buf[BUFSIZ];
X    int i,flag = 0;
X
X    set_whole_width(rt);
X
X    while(rt->whole_width > page_width  &&  poster == Off){
X      /* repeat as long as the string sticks out to right side */
X	if(quiet == Off){
X	    flag = (flag + 1) % 2;
X	    strcpy(buf,"0% |----+----+----+----+----+----+----+----+----+----| 100%\r");
X	    for(i = 0 ; i < (flag > 0 ? total_amount + rt->amount : total_amount) * 100 / root->amount / 2 ; i++)
X		buf[4+i] = '*';
X	    fputs(buf,stderr);
X	}
X
X	p = find_fold(rt);
X	if(p != NULL){
X	    fold_pad(p);
X	    set_whole_width(rt);
X	}else
X	    return;
X    }
}
X
PAD *find_fold(PAD *rt)
/* find PAD in need of folding */
{
X    PAD *ptr,*p;
X    PAD *p_max = NULL;
X    int w;
X    int max = 0;
X
X    if(rt->str != NULL  &&  rt->enable_fold == On){
X	p_max = rt;
X	max = get_str_width(rt);
X	if(is_box(rt)  &&  max > max_length)
X	    max = INFINITY;
X	else if(rt->child_number > 1)
X	    max *= (int)sqrt((double)rt->child_number);
X    }
X
X    if(rt->child != NULL){
X	for(ptr = rt->child ; ptr != NULL ; ptr = ptr->next){
X	    p = find_fold(ptr);
X	    if(p != NULL){
X		w = get_str_width(p);
X		if(is_box(p)  &&  w > max_length)
X		    w = INFINITY;
X		else if(p->child_number > 1)
X		    w *= (int)sqrt((double)p->child_number);
X		if(w > max){
X		    p_max = p;
X		    max = w;
X		}
X	    }
X	}
X    }
X
X    if(rt->depth != NULL){
X	for(ptr = rt->depth ; ptr != NULL ; ptr = ptr->depth){
X	    p = find_fold(ptr);
X	    if(p != NULL){
X		w = get_str_width(p);
X		if(is_box(p)  &&  w > max_length)
X		    w = INFINITY;
X		else if(p->child_number > 1)
X		    w *= (int)sqrt((double)p->child_number);
X		if(w > max){
X		    p_max = p;
X		    max = w;
X		}
X	    }
X	}
X    }
X
X    return p_max;
}
X
void fold_pad(PAD *ptr)
/* fold PAD */
{
X    int w,fw;
X
X    fw = fontwidth;
#ifdef JAPANESE
X    if(include_euc(ptr->str))
X	fw = greater(fw,jfontwidth);
#endif
X
X    ptr->lines++;
X    w = get_str_width(ptr);
X    if(w < min_length  ||  w < fw){
X	ptr->enable_fold = Off;
X	ptr->lines--;
X	w = get_str_width(ptr);
X    }
X
X    /* Adjust spaces when dealing with label or reference */
X    if (ptr->type == Label  ||  ptr->type == Refer) {
X	switch (ptr->type) {
X	    case Label:
X		ptr->space_width = linewidth + (int)((double)get_str_width(ptr) * (SQRT2 - 1.0));
X		break;
X	    case Refer:
X		ptr->space_width = box_hspace * 3 + (int)((double)get_str_width(ptr) * (SQRT2 - 1.0));
X		break;
X	}
X    }
}
X
void set_whole_width(PAD *rt)
/* set total width of PAD (under rt) */
{
X    PAD *ptr;
X    int m,max = 0,label_max = 0;
X
X    if(rt->child == NULL)
X	rt->whole_width = get_str_width(rt) + rt->space_width;
X    else{
X	if(rt->type == If  ||  rt->type == Switch){	/* find the longest label length in a branch */
X	    for(ptr = rt->child ; ptr != NULL ; ptr = ptr->next)
X		label_max = greater(label_max,get_str_width(ptr));
X	}
X
X	for(ptr = rt->child ; ptr != NULL ; ptr = ptr->next){
X	    set_whole_width(ptr);
X	    if(rt->type == If  ||  rt->type == Switch)
X		ptr->whole_width += (label_max - get_str_width(ptr));
X	    max = greater(max,ptr->whole_width);
X	}
X
X	if(rt->type == Block  ||  rt->type == Refer)
X	    m = 0;
X	else
X	    m = get_str_width(rt) + rt->space_width;
X
X	if(rt->depth != NULL){
X	    for(ptr = rt->depth ; ptr != NULL ; ptr = ptr->depth){
X		set_whole_width(ptr);
X		m = greater(m,ptr->whole_width);
X	    }
X	}
X
X	if(rt->type == Block  ||  rt->type == Refer)
X	    m += get_str_width(rt) + rt->space_width;
X
X	rt->whole_width = max + m;
X    }
}
X
int over_maxlength(PAD *rt)
/* search for length that is greater than max_length (under rt) */
{
X    PAD *ptr;
X
X    if(rt->child == NULL){
X	if(is_box(rt)  &&  get_str_width(rt) > max_length)
X	    return 1;
X    }else{
X	for(ptr = rt->child ; ptr != NULL ; ptr = ptr->next){
X	    if(over_maxlength(ptr))
X		return 1;
X	}
X
X	if(rt->depth != NULL){
X	    for(ptr = rt->depth ; ptr != NULL ; ptr = ptr->depth){
X		if(over_maxlength(ptr))
X		    return 1;
X	    }
X	}
X    }
X
X    return 0;
}
X
void refold_pad(PAD *p,int max)
/* refold PAD */
{
X    int w,fw;
X
X    if(poster == On)
X	max = INFINITY;
X
X    fw = fontwidth;
#ifdef JAPANESE
X    if(include_euc(p->str))
X	fw = greater(fw,jfontwidth);
#endif
X
X    p->lines = 1;
X    w = get_str_width(p);
X    while(w > max  ||  (is_box(p)  &&  w > max_length)){
X	p->lines++;
X	w = get_str_width(p);
X	if(w < min_length  ||  w < fw){
X	    p->lines--;
X	    w = get_str_width(p);
X	    return;
X	}
X    }
}
X
int is_box(PAD *p)
/* PAD box? */
{
X    switch(p->type){
X	case Root:
X	case Title:
X	case Figure:
X	case Empty:
X	case Newpage:
X	case Vsp:
X	    return 0;
X	case Padtitle:
X	    if(titlebox == Off)
X		return 0;
X    }
X
X    return 1;
}
SHAR_EOF
  $shar_touch -am 0820130496 'pad2ps-3.1/src/pad2ps/fold.c' &&
  chmod 0644 'pad2ps-3.1/src/pad2ps/fold.c' ||
  $echo 'restore of' 'pad2ps-3.1/src/pad2ps/fold.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'pad2ps-3.1/src/pad2ps/fold.c:' 'MD5 check failed'
24109c1feba292ec633c750b8859dfc5  pad2ps-3.1/src/pad2ps/fold.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pad2ps-3.1/src/pad2ps/fold.c'`"
    test 8579 -eq "$shar_count" ||
    $echo 'pad2ps-3.1/src/pad2ps/fold.c:' 'original size' '8579,' 'current size' "$shar_count!"
  fi
fi
# ============= pad2ps-3.1/src/pad2ps/string.c ==============
if test -f 'pad2ps-3.1/src/pad2ps/string.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'pad2ps-3.1/src/pad2ps/string.c' '(file already exists)'
  rm -f _sh23946/new
else
  > _sh23946/new
  $echo 'x -' extracting 'pad2ps-3.1/src/pad2ps/string.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'pad2ps-3.1/src/pad2ps/string.c' &&
/*                            */
/*  string.c -- treat string  */
/*                            */
/*  pad2ps  by S. Yoshida     */
/*                            */
X
#include "config.h"
X
#include <string.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#include "pad2ps.h"
#include "lib.h"
X
#ifdef ENGLISH
static STRING *get_string(char *,int,int,int);
#endif
#ifdef JAPANESE
static STRING *get_string(char *,int,int,int,bool);
#endif
X
STRING *string(char *str,int x0,int y0,int max)
/* create STRING-style data */
{
X    STRING *s0,*s = NULL;
X    int l,p1,p2 = 0;
X    int x,y,dx = 0;
#ifdef JAPANESE
X    bool jflag = None;
#endif
X
X    l = strlen(str);
X    x = x0; y = y0;
X
X    for(p1 = 0 ; p1 <= l ; p1++){
SHAR_EOF
  : || $echo 'restore of' 'pad2ps-3.1/src/pad2ps/string.c' 'failed'
fi
$echo 'End of' 'archive' 'part' '9'
$echo 'File' 'pad2ps-3.1/src/pad2ps/string.c' 'is continued in part' '10'
echo 10 > _sh23946/seq
exit 0


