Newsgroups: fj.lang.postscript,fj.comp.texhax
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!spinnews!spinnews!m5w114!zunet!ashizawa
From: ashizawa@zuken.co.jp (Shuji Ashizawa)
Subject: Re: texfix bug
Sender: news@zuken.co.jp
Message-ID: <ASHIZAWA.95Feb26145942@r3e23.zuken.co.jp>
In-Reply-To: kazama@square.ntt.jp's message of 24 Feb 1995 00:04:52 GMT
Date: Sun, 26 Feb 1995 05:59:19 GMT
Distribution: fj
References: <ASHIZAWA.95Feb23091837@r3e23.zuken.co.jp>
	<5ko.2p6v8n@gulag.ntt.jp>
Nntp-Posting-Host: r3e23
Organization: ZUKEN Inc. Yokohama, JAPAN
Lines: 218
Xref: galaxy.trc.rwcp.or.jp fj.lang.postscript:556 fj.comp.texhax:5958
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.comp.texhax&nb=5958&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


$B02_7!w?^8&$G$9!#(B

In article <5ko.2p6v8n@gulag.ntt.jp> kazama@square.ntt.jp (Kazuhiro Kazama) writes:

=> $BIw4V!w#N#T#T4pAC8&5f=j$G$9!#(B

$B$$$D$b$*@$OC$K$J$j$^$9!#(B

=> In article <ASHIZAWA.95Feb23091837@r3e23.zuken.co.jp> ashizawa@zuken.co.jp (Shuji Ashizawa) writes:
=> $B!!$3$l$O$"$kFCDj$N5!<o$G(BEPS$B$r4^$`0u;z$,$G$-$J$$%P%0$r2sHr$9$k$b$N$G$9!#(B
=> $B$3$l$O(BAdobe Systems$B$G$b%P%0$H$7$FG'<1$5$l$F$$$?$h$&$G!"$"$l$r;H$o$:$K(B
=> $BLdBj$J$/0u:~$G$-$k$J$i;H$o$J$$$G$/$@$5$$!#(B

Apple LaserWriter$B$r;HMQ$7$F$$$k$N$G!$;H$o$J$$Lu$K$O$$$-$^$;$s!#(B
=> 
=> $B!!$J$*%I%-%e%a%s%H$OG[IU$5$l$F$$$kCf$K4^$^$l$F$$$^$9$h!#(B

doc $B$K$"$j$^$7$?!#$3$l$G$O!$3($rA0$K;}$C$F$$$/$HLdBj$,H/@8$7$J$$$H$$$&;v$,=q$$$F(B
$B$"$j$^$7$?!#(B
$B3($H$$$C$7$g$KOH$r;}$C$F$$$C$F$bNI$$$N$+;d$K$OH=$j$^$;$s$N$G!$$d$O$jEj9F$7$?$$$H(B
$B;W$$$^$9!#(B

$B%=!<%9$O>.$5$$$N$G!$$3$N8e$KE:IU$7$^$9!#(B

BEGIN--cut here--cut here
/*
 *texfix.c
 *
 *version 1.5 (September 25, 1992)
 *written by Kazuhiro Kazama (kazama@square.ntt.jp)
 *
 *This original program is "retexps" made by takeba@otsl.oki.co.jp.
 */
#include<stdio.h>
#include<string.h>
#include<signal.h>
char*mktemp();

#ifdefSTRSTR
char*strstr();
#endif

#definePAGECOM"%%Page:"
#defineBSP"@beginspecial\n"
#defineESP"@endspecial\n"
#define RU"ru\n"

#ifdef JDVI2KPS || JDVI2KPS2
#defineBOP"@bop0\n"
#defineEOP"@eop\n"
#else
#ifdef JDVI2KPS3
#defineBOP"@bop\n"
#defineEOP"@eop\n"
#else
#defineBOP"BP\n"
#defineEOP"EP\n"
#endif
#endif

charline[BUFSIZ], line2[BUFSIZ];
chartmpstr[] = "/tmp/tfXXXXXX";
chartmprustr[] = "/tmp/ruXXXXXX";

char*tmpfn;
char*tmprufn;
intcleanup();

main()
{
    if ((tmpfn = mktemp(tmpstr)) == NULL) {
        perror("mktemp failed.");
        exit(1);
    }
    if ((tmprufn = mktemp(tmprustr)) == NULL) {
        perror("mktemp failed.");
        exit(1);
    }
    signal(SIGHUP, cleanup);
    signal(SIGINT, cleanup);
    signal(SIGQUIT, cleanup);
    signal(SIGPIPE, cleanup);
    signal(SIGTERM, cleanup);
    while (fgets(line, BUFSIZ, stdin) != NULL) {
fputs(line, stdout);
if (strncmp(line, PAGECOM, sizeof(PAGECOM) - 1) == 0)
    if (pageout()) {
fprintf(stderr, "unexpected EOF\n");
unlink(tmpfn);
exit(1);
    }
    }
    unlink(tmpfn);
    unlink(tmprufn);
    exit(0);
}

pageout()
{
    FILE*tmpfp, *tmprufp=NULL;
    intlinekind=0;

    linekind =0;
    while (fgets(line, BUFSIZ, stdin) != NULL) {
fputs(line, stdout);
if (strcmp(line, BOP) == 0) {
    if ((tmpfp = fopen(tmpfn, "w")) == NULL) {
perror("fopen failed.");
exit(1);
    }
    while (fgets(line, BUFSIZ, stdin) != NULL) {
if (strcmp(line, EOP) == 0) {
    fclose(tmpfp);
    if ((tmpfp = fopen(tmpfn, "r")) == NULL) {
perror("fopen failed.");
exit(1);
    }
    while (fgets(line2, BUFSIZ, tmpfp) != NULL)
fputs(line2, stdout);
    fclose(tmpfp);
    fputs(line, stdout);
    return 0;
} else if (strstr(line, BSP) != NULL) {
    if (tmprufp) {
fclose(tmprufp);
if ((tmprufp = fopen(tmprufn, "r")) == NULL) {
    perror("fopen failed.");
    exit(1);
}
while (fgets(line2, BUFSIZ, tmprufp) != NULL)
    fputs(line2, stdout);
fclose(tmprufp);
tmprufp = NULL;
    }
    fputs(line, stdout);
    if (specialout()) {
fclose(tmpfp);
return 1;
    }
    linekind =1;
} else if (strstr(line, RU) != NULL) {
    if (linekind == 1) {
fputs(line, stdout);
    }
    else {
if (!tmprufp) {
    if ((tmprufp = fopen(tmprufn, "w")) == NULL) {
perror("fopen failed.");
exit(1);
    }
}
fputs(line, tmprufp);
linekind =2;
    }
} else {
    if (tmprufp) {
fclose(tmprufp);
if ((tmprufp = fopen(tmprufn, "r")) == NULL) {
    perror("fopen failed.");
    exit(1);
}
while (fgets(line2, BUFSIZ, tmprufp) != NULL)
    fputs(line2, tmpfp);
fclose(tmprufp);
tmprufp = NULL;
    }
    fputs(line, tmpfp);
    linekind =0;
}
    }
}
    }
    return 0;
}

specialout()
{
    intinspecial = 1;

    while (fgets(line, BUFSIZ, stdin) != NULL) {
fputs(line, stdout);
if (strcmp(line, ESP) == 0 && --inspecial == 0)
    return 0;
else if (strstr(line, BSP) != NULL)
    inspecial++;
    }
    return 1;
}

cleanup()
{
    unlink(tmpfn);
    unlink(tmprufn);
    exit(0);
}

#ifdefSTRSTR
char*strstr(s1, s2)
register char*s1, *s2;
{
    register intl1, l2;
    register charc2;

    if ((c2 = *s2) != '\0')
for (l1 = strlen(s1), l2 = strlen(++s2); l1 > l2; l1--)
    if (*s1++ == c2 && strncmp(s1, s2, l2) == 0)
return --s1;
    return NULL;
}
#endif
END--cut here--cut here
--
    ~v~    ~v~   _       _
        ~s~        - _ -         
 (    (     (  (  (( o ))  )     
-- ---__----  -  _ -_-_-- _      Shuji.Ashizawa
-  --- --- --- -- -- -- -- --    E-mail ashizawa@zuken.co.jp
