From root@jedamus.Elliot Fri Sep  1 12:26:21 1995
Received: from burdell.cc.gatech.edu (root@burdell.cc.gatech.edu [130.207.3.207]) by anacreon.cc.gatech.edu (8.6.10/8.6.9) with ESMTP id MAA23312 for <gregh@anacreon.cc.gatech.edu>; Fri, 1 Sep 1995 12:26:13 -0400
Received: from mime.Worms.Fh-Rpl.DE (mime.Worms.Fh-Rpl.DE [143.93.160.2]) by burdell.cc.gatech.edu (8.6.12/8.6.9) with ESMTP id MAA12759 for <greg.hankins@cc.gatech.edu>; Fri, 1 Sep 1995 12:25:52 -0400
Received: from jedamus.Elliot (jedamus.Worms.Fh-Rpl.DE [193.175.41.77]) by mime.Worms.Fh-Rpl.DE (8.6.11/Worms.Fh-Rpl-6.0(8.6.9)) with ESMTP id SAA11290; Fri, 1 Sep 1995 18:25:26 +0200
Received: (from root@localhost) by jedamus.Elliot (8.6.12/8.6.12) id SAA01535; Fri, 1 Sep 1995 18:23:32 +0200
From: Leander Jedamus <root@jedamus.Elliot>
Message-Id: <199509011623.SAA01535@jedamus.Elliot>
Subject: linuxdoc-sgml-1.3 and nls
To: greg.hankins@cc.gatech.edu (Greg Hankins)
Date: Fri, 1 Sep 1995 18:23:32 +0200 (MET DST)
Cc: jedamus@Worms.Fh-Rpl.DE
Reply-To: jedamus@Worms.Fh-Rpl.DE
X-Mailer: ELM [version 2.4 PL24]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 13050     
Status: RO

Hi!

I changed html2html.l another time.
Now I included national language support, so in my German documents
one of the links says "Vorheriges Kapitel" instead of
"Previous Chapter".

What do you think of it? Do you think it is useful to install?

I appended three files, Makefile, html2html.l and html2html.m.
html2html.m is the message file. The German texts are in there.

The changes in html2html.l are just extensions. When you compile
it without the define NLS set, nothing has changed except the
source file. But when you compile html2html.c with -DNLS,
national language support is included.

Before that you have to get the gencat program. I found it in
my slackware distribution under source/a/bin/gencat.tar.gz .
I had to compile it by hand, the Makefile didn't work.
A nls tutorial can be found on
ftp://tsx-11.mit.edu/pub/linux/docs/locale.txt .

The next step is to create a catalog-file, which can be used
by html2html at runtime:

gencat html2html.cat html2html.m -h html2html-nls.h

This also creates the header file needed in html2html.c, if
NLS is defined.

The last step ist to create the directory
/usr/lib/locale/LC_MESSAGES/de_DE.88591
and copy html2html.cat to it.

When I want German language support, all I have to do now is
set LC_MESSAGES to "de_DE.88591" and set NLSPATH to
"/usr/lib/locale/LC_MESSAGES/%L/%N" in the environment.
If I unset both variables, I get the English texts.

Here is html2html.l
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<
/* -*- c -*- */

/* Modified by Leander Jedamus (jedamus@Worms.Fh-Rpl.DE). */

%{

#include <malloc.h>
#include <stdio.h>
#include <string.h>
#ifdef NLS
#include <locale.h>
#include <features.h>
#include <nl_types.h>
#include "html2html-nls.h"
#endif

/* Define Macros used */

#ifdef NLS
#define NLS_CATCLOSE(catfd) catclose (catfd)
#define NLS_CATINIT catinit ()
#define NLS_CATGETS(catfd, arg1, arg2, fmt) \
    catgets ((catfd), (arg1), (arg2), (fmt))
#else
#define NLS_CATCLOSE(catfd) /* empty */
#define NLS_CATINIT /* empty */
#define NLS_CATGETS(catfd, arg1, arg2, fmt) fmt
#endif

/* #define DEBUG */

FILE *out = stdout;

char buf[2048], sectname[256], labeltxt[256];
char firstname[256], outname[256];
char ssectname[256], Tmp1[4096], Tmp2[256], headname[256];
char urlname[256], Headbuf[4096], refname[256];

int filenum = 1;
int filecount = 1;
int tmpfn;
int secnr = 0;
int ssecnr;
int current;
int skipnewline = 0;

#ifdef NLS
/* Message catalog descriptor */
static nl_catd catfd = -1;
#endif

#define CHAPTER 1
#define SECTION 2
#define SUBSECT 3

int getstr( char *str, int n )
  {
    int i;
#ifdef DEBUG
    fprintf( stderr, "DEBUG: yytext: <<%s>>\n", yytext );
#endif
    if( strlen( yytext ) == n )
      return 0;
    strncpy( str, yytext+n, yyleng-n);
    str[ yyleng-n ] = 0;
    return 1;
  }

struct lprec
  {
    char *label;
    int fileno;
    struct lprec *next;
  };

typedef struct lprec lprec;

lprec *putlp();
lprec *getlp();

lprec *lp_table = (lprec *)0;
lprec *tmplp;

lprec *
putlp( char *lbl, int fn )
  {
    lprec *ptr;
    ptr = (lprec *) malloc (sizeof (lprec));
    ptr->label = (char *) malloc (strlen (lbl) +1 );
    strcpy( ptr->label, lbl );
    ptr->fileno = fn;
    ptr->next = (struct lprec *)lp_table;
    lp_table = ptr;
    return ptr;
  }

lprec *
getlp( char *lbl )
  {
    lprec *ptr;
    for (ptr = lp_table; ptr != (lprec *) 0;
	 ptr = (lprec *)ptr->next)
      if (strcmp (ptr->label,lbl) == 0)
	return ptr;
    return 0;
  }

void heading( FILE *out, char *titlename )
  {
    fprintf( out, "<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n", titlename );
    fprintf( out, "</HEAD>\n<BODY>\n" );
  }

void footing( FILE *out )
  {
    fprintf( out, "</BODY>\n</HTML>\n" );
  }

void problem( char *name )
  {
    fprintf( stderr, "%s %s!\n",
                     NLS_CATGETS(catfd, html2htmlSet, html2htmlProblem, "Problem with"),
                     name
           );
  }

#ifdef NLS
void
catinit(void)
{
  if (catfd == (nl_catd)-1)
    catfd = catopen("html2html.cat",MCLoadBySet);
};/* catinit */
#endif

%}

%s SECT

%%

^"<@@url>".*$		{

    skipnewline=1;
    getstr( urlname, 7 ); 
    sprintf( Headbuf, "<A HREF=\"%s\"> ", urlname);
}

^"<@@urlnam>".*$	{
    sprintf( Tmp1, " %s </A>", urlname);
    strcat (Headbuf, Tmp1);
}

^"<@@endurl>".*$	{

    skipnewline=0;
    fprintf( out, "%s", Headbuf);
    strcpy (Headbuf,"");
}

^"<@@title>".*$ 	{

    strcpy( sectname, yytext+9 );
    heading( stdout, sectname );
    printf( "<H1>%s</H1>\n", sectname );
}

^"<@@head>".*$		{

    skipnewline=1;
    getstr( headname, 8 ); 
    sprintf( Headbuf, "<H3> %s ", headname);
}

^"<@@endhead>".*$	{

  fprintf( out, "%s", Headbuf );
  strcpy(Headbuf, "");
  switch (current){
  case CHAPTER:
      current=0;
      break;
  case SECTION:
      current=0;
      fprintf( out, "</H1>\n<P>\n<A HREF=\"%s.html#toc%d\"> %s</A></P>\n",
                    firstname,
                    secnr,
                    NLS_CATGETS(catfd, html2htmlSet, html2htmlContents,
                                "Contents of this section")
              );
      break;
  case SUBSECT:
      current=0;
      fprintf( out, "</H2>\n");
      break;
  default:
      current=0;
      fprintf( out, "</H3>\n");
      break;
  }
  skipnewline=0;
}

^"<@@sect>".*$		{ 

    skipnewline=1;
    getstr( sectname, 8 ) ;
    if( out != stdout ) 
      {
        footing( out );
	fclose( out );
      }
    current=SECTION;
    secnr++;
    ssecnr=0;
    sprintf( outname, "%s-%d.html", firstname, filenum++ );
    out = fopen( outname, "w" );
    heading( out, sectname );
    sprintf( Headbuf, "<H1>%d <A NAME=\"s%d\"></A> %s ",secnr, secnr, sectname );
    fprintf( stdout, "<P>\n<H2> <A NAME=\"toc%d\"></A>",secnr);
    fprintf( stdout, "%d. <A HREF=\"%s\">%s</A></H2>\n<UL>\n", secnr, outname,
	    sectname );
}

^"<@@ssect>".*$          { 

    skipnewline=1;
    getstr( ssectname, 9 ) ;
    current=SUBSECT;
    ssecnr++;
    sprintf( Headbuf, "<H2>%d.%d <A NAME=\"ss%d.%d\"></A> %s ",secnr, ssecnr, secnr, ssecnr, ssectname );
    fprintf( stdout, "<LI> <A HREF=\"%s#ss%d.%d\">%d.%d %s</A>\n", outname, secnr, ssecnr, secnr, ssecnr,
            ssectname );
}

^"<@@chapt>".*$		{

getstr( sectname, 9 );
sectname[ yyleng-14 ] = 0;
printf( "<H1>%s</H1>\n", sectname );
}

^"<@@endchapt>".*$	;

^"<@@endsect>".*$	{

if (filenum<filecount) {
  sprintf(Tmp2,"%s-%d.html",firstname, (filenum ));
  fprintf(out, "<P>\n<A HREF=\"%s\">%s</A> %s",
               Tmp2,
               NLS_CATGETS(catfd, html2htmlSet, html2htmlNext, "Next" ),
               NLS_CATGETS(catfd, html2htmlSet, html2htmlChapter, "Chapter" )
         );
}
if (filenum>=3) {
  if(filenum<filecount)
  {
    fprintf(out, ",\n");
  }
  else {
    fprintf(out, "<P>\n");
  }
  sprintf(Tmp1,"%s-%d.html",firstname, (filenum - 2));
  fprintf(out, "<A HREF=\"%s\">%s</A> %s\n",
               Tmp1,
               NLS_CATGETS(catfd, html2htmlSet, html2htmlPrevious, "Previous" ),
               NLS_CATGETS(catfd, html2htmlSet, html2htmlChapter, "Chapter" )
         );
}

sprintf(Tmp2,"%s.html",firstname);
fprintf(out, "<P>\n%s <A HREF=\"%s#toc%d\">%s</A>,\n",
             NLS_CATGETS(catfd, html2htmlSet, html2htmlToC, "Table of contents of"),
             Tmp2,
             filenum-1,
             NLS_CATGETS(catfd, html2htmlSet, html2htmlThisChapter, "this chapter")
       );
fprintf(out, " %s <A HREF=\"%s#toc\">%s</A></P>\n",
             NLS_CATGETS(catfd, html2htmlSet, html2htmlGeneral, "General" ),
             Tmp2,
             NLS_CATGETS(catfd, html2htmlSet, html2htmlToC2, "table of contents" )
       );
fprintf(out, "<P>\n<A HREF=\"%s\">%s</A> %s,\n",
             Tmp2,
             NLS_CATGETS(catfd, html2htmlSet, html2htmlTop, "Top" ),
             NLS_CATGETS(catfd, html2htmlSet, html2htmlOfDocument, "of the document" )
       );
fprintf(out, "<A HREF=\"#0\"> %s</A></P>\n",
             NLS_CATGETS(catfd, html2htmlSet, html2htmlBeginOfChapter, "Beginning of this Chapter" )
       );
fprintf(stdout,"</UL>\n");
footing( out );
fclose(out); out = stdout;
}

^"<@@endssect>".*$       {
}

^"<@@enddoc>".*$      ;

^"<@@sectcount>".*$   {

  if (sscanf( yytext, "<@@sectcount>%d", &filecount ) != 1)
  {
    problem("@@sectcount");
  }
  else
  {
    filecount++;
  };
};


<SECT>^"<@@label>".*$	{
  
  strcpy( sectname, yytext+9 );
  if (!getlp( sectname ))
    {
      problem("@@label");
    } 
  else
    {
      strcpy( labeltxt, sectname );
    }
}

^"<@@label>".*$		{
  
  strcpy( sectname, yytext+9 );
  if (!getlp( sectname ))
    {
      problem("@@label");
    } 
  else
    {
      if( skipnewline ) {
        sprintf( Tmp1, "<A NAME=\"%s\"></A> %s", sectname, Headbuf);
	strcpy (Headbuf, Tmp1);
	strcpy (Tmp1,"");
      } else {
        fprintf( out, "<A NAME=\"%s\"></A> ", sectname );
      }
    }
}


^"<@@labelp>".*$	{

#ifdef DEBUG
fprintf( stderr, "DEBUG: yytext = <<%s>>\n", yytext );
#endif
if (sscanf( yytext, "<@@labelp>%[^#]#%d", sectname, &tmpfn ) != 2)
{
  problem("@@labelp");
#ifdef DEBUG
fprintf( stderr, "DEBUG: sectname = <<%s>>\n", sectname );
fprintf( stderr, "DEBUG: tmpfn = <<%d>>\n", tmpfn );
#endif
} else
putlp( sectname, tmpfn );

}

^"<@@ref>".*$           {

strcpy( refname, yytext+7 );
if (!(tmplp = getlp( refname )))
{
  problem("@@ref");
  skipnewline++;
} else {
  
  if(tmplp->fileno==secnr) {
    sprintf( Tmp1, "<A HREF=\"#%s\"> ", refname );
  } else if(tmplp->fileno==0) {
    sprintf( Tmp1, "<A HREF=\"%s.html#%s\"> ", firstname, refname );
  } else { 
    sprintf( Tmp1, "<A HREF=\"%s-%d.html#%s\"> ", firstname, tmplp->fileno,
              refname );
  }

  if(skipnewline) {
     strcat( Headbuf, Tmp1);
  } else {
     strcpy( Headbuf, Tmp1);
  }
  skipnewline++ ;
}
}

^"<@@refnam>".*$	{

   sprintf( Tmp1," %s </A> ", refname );
   strcat ( Headbuf, Tmp1);
}

^"<@@endref>".*$	{

   switch (skipnewline) {
   case 1:
     fprintf( out, "%s", Headbuf );
     break;
   case 2:
     break;
   default:
     problem("@@endref");
     break;
   }
   skipnewline--;
}

<SECT>^.*$		{ 

getstr( sectname, 0 );

if( out != stdout ) 
{
  footing( out );
  fclose( out );
}
sprintf( outname, "%s-%d.html", firstname, filenum++ );
out = fopen( outname, "w" );
heading( out, sectname );
if( strlen( labeltxt ))
{
  fprintf( out, "<A NAME=\"%s\"></A>\n", labeltxt );
  labeltxt[0] = 0;
}
fprintf( out, "<H1>%s</H1> ", sectname );
fprintf( stdout, "<H2> <A HREF=\"%s\">%s</A></H2>\n", outname,
	sectname );

BEGIN(0);
}

.*			{

if (skipnewline) {
    strcat(Headbuf, yytext );
  } else if( out != stdout ) {
    fprintf( out, "%s", yytext );
  } else {
    ECHO;
  }
}

\n			{

if(!skipnewline) {
  if( out != stdout )
  {
    fprintf( out, "%s", yytext );
  }
  else
  {
    ECHO;
  }
}
}


%%

void
main( int argc, char **argv )
{
#ifdef NLS
  setlocale(LC_MESSAGES,"");
#endif
  NLS_CATINIT;

  if( argc >= 2 )
    {
      strncpy( firstname, argv[1], 256 );
    }
  else
    {
      strcpy( firstname, "$$" );
    }

  secnr=0;
  yylex();
  footing( stdout );

  if( out != stdout )
    {
      footing( out );
      fclose( out );      
    }

  NLS_CATCLOSE(catfd);
  exit( 0 );
}
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<

And here ist html2html.m, the message file.
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<
$set 1 #html2html
$ #Problem              Original Message:(Problem with)
# Probleme mit
$ #Contents             Original Message:(Contents of this section)
# Inhalt dieses Abschnittes
$ #Next                 Original Message:(Next)
# N&auml;chstes
$ #Previous             Original Message:(Previous)
# Vorheriges
$ #Chapter              Original Message:(Chapter)
# Kapitel
$ #ToC                  Original Message:(Table of contents of)
# Inhaltsverzeichnis
$ #ThisChapter          Original Message:(this chapter)
# dieses Kapitels
$ #General              Original Message:(General)
# Generelles
$ #ToC2                 Original Message:(table of contents)
# Inhaltsverzeichnis
$ #Top                  Original Message:(Top)
# Beginn
$ #OfDocument           Original Message:(of the document)
# dieses Dokumentes
$ #BeginOfChapter	Original Message:(Beginning of this Chapter)
# Beginn dieses Kapitels
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<

And last the Makefile
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<
# Makefile for HTML post-processors

CC = gcc
CFLAGS = -O2 -s
DFLAGS = -DNLS
LFLAGS = -w

all: fixref html2html

fixref: fixref.c
	gcc $(CFLAGS) -o fixref fixref.c -lfl

html2html.cat html2html-nls.h: html2html.m
	gencat -new $@ $< -h html2html-nls.h

html2html.c: html2html.cat html2html-nls.h

html2html: html2html.c
	gcc $(CFLAGS) $(DFLAGS) -o html2html html2html.c -lfl

install:
	cp html2html fixref ../bin
	chmod 755 ../bin/html2html ../bin/fixref

clean:
	rm -f fixref fixref.c html2html html2html.c html2html.cat html2html-nls.h
----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<
-- 
Leander
http://www.Worms.Fh-Rpl.DE/~jedamus/

