head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC5:1.1.1.1
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	perseant-exfatfs-base-20250801:1.1.1.1
	netbsd-11:1.1.1.1.0.62
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	perseant-exfatfs-base-20240630:1.1.1.1
	perseant-exfatfs:1.1.1.1.0.60
	perseant-exfatfs-base:1.1.1.1
	netbsd-8-3-RELEASE:1.1.1.1
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.58
	netbsd-10-base:1.1.1.1
	netbsd-9-3-RELEASE:1.1.1.1
	cjep_sun2x-base1:1.1.1.1
	cjep_sun2x:1.1.1.1.0.56
	cjep_sun2x-base:1.1.1.1
	cjep_staticlib_x-base1:1.1.1.1
	netbsd-9-2-RELEASE:1.1.1.1
	cjep_staticlib_x:1.1.1.1.0.54
	cjep_staticlib_x-base:1.1.1.1
	netbsd-9-1-RELEASE:1.1.1.1
	phil-wifi-20200421:1.1.1.1
	phil-wifi-20200411:1.1.1.1
	is-mlppp:1.1.1.1.0.52
	is-mlppp-base:1.1.1.1
	phil-wifi-20200406:1.1.1.1
	netbsd-8-2-RELEASE:1.1.1.1
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	phil-wifi-20191119:1.1.1.1
	netbsd-9:1.1.1.1.0.50
	netbsd-9-base:1.1.1.1
	phil-wifi-20190609:1.1.1.1
	netbsd-8-1-RELEASE:1.1.1.1
	netbsd-8-1-RC1:1.1.1.1
	pgoyette-compat-merge-20190127:1.1.1.1
	pgoyette-compat-20190127:1.1.1.1
	pgoyette-compat-20190118:1.1.1.1
	pgoyette-compat-1226:1.1.1.1
	flex-2-6-4:1.1.1.1
	pgoyette-compat-1126:1.1.1.1
	pgoyette-compat-1020:1.1.1.1
	pgoyette-compat-0930:1.1.1.1
	pgoyette-compat-0906:1.1.1.1
	netbsd-7-2-RELEASE:1.1.1.1
	pgoyette-compat-0728:1.1.1.1
	netbsd-8-0-RELEASE:1.1.1.1
	phil-wifi:1.1.1.1.0.48
	phil-wifi-base:1.1.1.1
	pgoyette-compat-0625:1.1.1.1
	netbsd-8-0-RC2:1.1.1.1
	pgoyette-compat-0521:1.1.1.1
	pgoyette-compat-0502:1.1.1.1
	pgoyette-compat-0422:1.1.1.1
	netbsd-8-0-RC1:1.1.1.1
	pgoyette-compat-0415:1.1.1.1
	pgoyette-compat-0407:1.1.1.1
	pgoyette-compat-0330:1.1.1.1
	pgoyette-compat-0322:1.1.1.1
	pgoyette-compat-0315:1.1.1.1
	netbsd-7-1-2-RELEASE:1.1.1.1
	pgoyette-compat:1.1.1.1.0.46
	pgoyette-compat-base:1.1.1.1
	netbsd-7-1-1-RELEASE:1.1.1.1
	matt-nb8-mediatek:1.1.1.1.0.44
	matt-nb8-mediatek-base:1.1.1.1
	perseant-stdc-iso10646:1.1.1.1.0.42
	perseant-stdc-iso10646-base:1.1.1.1
	netbsd-8:1.1.1.1.0.40
	netbsd-8-base:1.1.1.1
	prg-localcount2-base3:1.1.1.1
	prg-localcount2-base2:1.1.1.1
	prg-localcount2-base1:1.1.1.1
	prg-localcount2:1.1.1.1.0.38
	prg-localcount2-base:1.1.1.1
	pgoyette-localcount-20170426:1.1.1.1
	bouyer-socketcan-base1:1.1.1.1
	pgoyette-localcount-20170320:1.1.1.1
	netbsd-7-1:1.1.1.1.0.36
	netbsd-7-1-RELEASE:1.1.1.1
	netbsd-7-1-RC2:1.1.1.1
	netbsd-7-nhusb-base-20170116:1.1.1.1
	bouyer-socketcan:1.1.1.1.0.34
	bouyer-socketcan-base:1.1.1.1
	pgoyette-localcount-20170107:1.1.1.1
	netbsd-7-1-RC1:1.1.1.1
	flex-2-6-3:1.1.1.1
	pgoyette-localcount-20161104:1.1.1.1
	netbsd-7-0-2-RELEASE:1.1.1.1
	localcount-20160914:1.1.1.1
	netbsd-7-nhusb:1.1.1.1.0.32
	netbsd-7-nhusb-base:1.1.1.1
	pgoyette-localcount-20160806:1.1.1.1
	pgoyette-localcount-20160726:1.1.1.1
	pgoyette-localcount:1.1.1.1.0.30
	pgoyette-localcount-base:1.1.1.1
	netbsd-7-0-1-RELEASE:1.1.1.1
	flex-2-6-0:1.1.1.1
	netbsd-7-0:1.1.1.1.0.28
	netbsd-7-0-RELEASE:1.1.1.1
	netbsd-7-0-RC3:1.1.1.1
	netbsd-7-0-RC2:1.1.1.1
	netbsd-7-0-RC1:1.1.1.1
	flex-2-5-39:1.1.1.1
	netbsd-6-0-6-RELEASE:1.1.1.1
	netbsd-6-1-5-RELEASE:1.1.1.1
	netbsd-7:1.1.1.1.0.26
	netbsd-7-base:1.1.1.1
	yamt-pagecache-base9:1.1.1.1
	yamt-pagecache-tag8:1.1.1.1
	netbsd-6-1-4-RELEASE:1.1.1.1
	netbsd-6-0-5-RELEASE:1.1.1.1
	tls-earlyentropy:1.1.1.1.0.24
	tls-earlyentropy-base:1.1.1.1
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2-base3:1.1.1.1
	netbsd-6-1-3-RELEASE:1.1.1.1
	netbsd-6-0-4-RELEASE:1.1.1.1
	netbsd-6-1-2-RELEASE:1.1.1.1
	netbsd-6-0-3-RELEASE:1.1.1.1
	netbsd-6-1-1-RELEASE:1.1.1.1
	riastradh-drm2-base2:1.1.1.1
	riastradh-drm2-base1:1.1.1.1
	riastradh-drm2:1.1.1.1.0.16
	riastradh-drm2-base:1.1.1.1
	netbsd-6-1:1.1.1.1.0.22
	netbsd-6-0-2-RELEASE:1.1.1.1
	netbsd-6-1-RELEASE:1.1.1.1
	khorben-n900:1.1.1.1.0.20
	netbsd-6-1-RC4:1.1.1.1
	flex-2-5-37:1.1.1.1
	netbsd-6-1-RC3:1.1.1.1
	agc-symver:1.1.1.1.0.18
	agc-symver-base:1.1.1.1
	netbsd-6-1-RC2:1.1.1.1
	netbsd-6-1-RC1:1.1.1.1
	yamt-pagecache-base8:1.1.1.1
	netbsd-6-0-1-RELEASE:1.1.1.1
	yamt-pagecache-base7:1.1.1.1
	matt-nb6-plus-nbase:1.1.1.1
	yamt-pagecache-base6:1.1.1.1
	netbsd-6-0:1.1.1.1.0.14
	netbsd-6-0-RELEASE:1.1.1.1
	netbsd-6-0-RC2:1.1.1.1
	tls-maxphys:1.1.1.1.0.12
	tls-maxphys-base:1.1.1.1
	matt-nb6-plus:1.1.1.1.0.10
	matt-nb6-plus-base:1.1.1.1
	netbsd-6-0-RC1:1.1.1.1
	yamt-pagecache-base5:1.1.1.1
	yamt-pagecache-base4:1.1.1.1
	netbsd-6:1.1.1.1.0.8
	netbsd-6-base:1.1.1.1
	yamt-pagecache-base3:1.1.1.1
	yamt-pagecache-base2:1.1.1.1
	yamt-pagecache:1.1.1.1.0.6
	yamt-pagecache-base:1.1.1.1
	cherry-xenmp:1.1.1.1.0.4
	cherry-xenmp-base:1.1.1.1
	bouyer-quota2-nbase:1.1.1.1
	bouyer-quota2:1.1.1.1.0.2
	bouyer-quota2-base:1.1.1.1
	matt-mips64-premerge-20101231:1.1.1.1
	matt-premerge-20091211:1.1.1.1
	flex-2-5-35:1.1.1.1
	FLEX:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2009.10.26.00.28.33;	author christos;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2009.10.26.00.28.33;	author christos;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@/*
 * j2t.lex : An example of the use (possibly abuse!)
 *           of start states.
 */

%{
#define MAX_STATES 1024
#define TRUE  1
#define FALSE 0

#define CHAPTER   "@@chapter"
#define SECTION   "@@section"
#define SSECTION  "@@subsection"
#define SSSECTION "@@subsubsection"

int  states[MAX_STATES];
int  statep = 0;

int  need_closing = FALSE;

char buffer[YY_BUF_SIZE];

extern char *yytext;

/*
 * set up the head of the *.texinfo file the program
 * will produce. This is a standard texinfo header.
 */

void print_header(void)
{
   printf("\\input texinfo @@c -*-texinfo-*-\n");
   printf("@@c           %c**start of header\n",'%');
   printf("@@setfilename       jargon.info\n");
   printf("@@settitle          The New Hackers Dictionary\n");
   printf("@@synindex          fn cp\n");
   printf("@@synindex          vr cp\n");
   printf("@@c           %c**end of header\n",'%');
   printf("@@setchapternewpage odd\n");
   printf("@@finalout\n");
   printf("@@c @@smallbook\n");
   printf("\n");
   printf("@@c ==========================================================\n\n");
   printf("@@c  This file was produced by j2t. Any mistakes are *not* the\n");
   printf("@@c  fault of the jargon file editors.                        \n");
   printf("@@c ==========================================================\n\n");
   printf("@@titlepage\n");
   printf("@@title     The New Hackers Dictionary\n");
   printf("@@subtitle  Version 2.9.10\n");
   printf("@@subtitle  Generated by j2t\n");
   printf("@@author    Eric S. Raymond, Guy L. Steel, Mark Crispin et al.\n"); 
   printf("@@end titlepage\n");
   printf("@@page\n");
   printf("\n@@c ==========================================================\n");
   printf("\n\n");
   printf("@@unnumbered Preface\n");
   printf("@@c          *******\n");
}

/*
 * create the tail of the texinfo file produced.
 */

void print_trailer(void)
{
   printf("\n@@c ==========================================================\n");
   printf("@@contents\n");   /* print the table of contents */
   printf("@@bye\n\n");     
}

/*
 * write an underline under a section
 * or chapter so we can find it later. 
 */

void write_underline(int len, int space, char ch)
{
  int loop;

  printf("@@c ");

  for(loop=3; loop<space; loop++){
    printf(" ");
  }

  while(len--){
    printf("%c",ch);
  }
  printf("\n\n");
}

/*
 * check for texinfo special characters
 * and escape them
 */

char *check_and_convert(char *string)
{
  int  buffpos = 0;
  int  len,loop;

  len = strlen(string);  
  for(loop=0; loop<len; loop++){
    if(string[loop] == '@@' || string[loop] == '{' || string[loop] == '}'){
      buffer[buffpos++] = '@@';
      buffer[buffpos++] = string[loop];
    } else {
      buffer[buffpos++] = string[loop];
    }
  }
  buffer[buffpos] = '\0';
  return(buffer);
}

/*
 * write out a chapter,section, or subsection
 * header
 */

void write_block_header(char *type)
{
  int loop;
  int len;

  (void)check_and_convert(yytext);
  len = strlen(buffer);
  for(loop=0; buffer[loop] != '\n';loop++)
         ;
  buffer[loop] = '\0';
  printf("%s %s\n",type,buffer);
  write_underline(strlen(buffer),strlen(type)+1,'*');
}

%}

/*
 * the flex description starts here 
 */

%x HEADING EXAMPLE ENUM EXAMPLE2
%x BITEM BITEM_ITEM 
%s LITEM LITEM2 

%%

^#[^#]*"#"  /* skip the header & trailer */
                     /* chapters have asterisks under them 
                      * and are terminated by a colon
                      */
^[^\n:]+\n[*]+\n      write_block_header(CHAPTER); 

^"= "[A-Z]" ="\n"="*  { /* we create a seciton for each category */
                        if(need_closing == TRUE){
                          printf("@@end table\n\n\n");
                        }
                        need_closing = TRUE;
                        write_block_header(SECTION);
                        printf("\n\n@@table @@b\n");
                      }

"Examples:"[^\.]+     ECHO;

"*"[^*\n]+"*"         { /* @@emph{}(emphasized) text */
                        yytext[yyleng-1] = '\0';
                        (void)check_and_convert(&yytext[1]);
                        printf("@@i{%s}",buffer);
                      }

"{{"[^}]+"}}"         { /* special emphasis */
                        yytext[yyleng-2] = '\0';
                        (void)check_and_convert(&yytext[2]);
                        printf("@@b{%s}",buffer);
                      }

"{"[^}]+"}"           { /* special emphasis */
                        yytext[yyleng-1] = '\0';
                        (void)check_and_convert(&yytext[1]);
                        printf("@@b{%s}",buffer);
                      }
  
 /* escape some special texinfo characters */
<INITIAL,LITEM,LITEM2,BITEM,ENUM,EXAMPLE,EXAMPLE2>"@@"  printf("@@@@");
<INITIAL,LITEM,LITEM2,BITEM,ENUM,EXAMPLE,EXAMPLE2>"{"  printf("@@{");
<INITIAL,LITEM,LITEM2,BITEM,ENUM,EXAMPLE,EXAMPLE2>"}"  printf("@@}");

 /*
  * reproduce @@example code
  */

":"\n+[^\n0-9*]+\n"     "[^ ]   {
                        int loop;
                        int len;
                        int cnt;

                        printf(":\n\n@@example \n");
                        strcpy(buffer,yytext);
                        len = strlen(buffer);
                        cnt = 0;
                        for(loop=len; loop > 0;loop--){
                          if(buffer[loop] == '\n')
                             cnt++;
                          if(cnt == 2)
                              break;
                        }
                        yyless(loop+1);
                        statep++;
                        states[statep] = EXAMPLE2;
                        BEGIN(EXAMPLE2);
                      }
<EXAMPLE,EXAMPLE2>^\n  {
                      printf("@@end example\n\n");
                      statep--; 
                      BEGIN(states[statep]);
                    }

 /*
  * repoduce @@enumerate lists
  */

":"\n+[ \t]*[0-9]+"."   {
                      int loop;
                      int len;

                      printf(":\n\n@@enumerate \n");
                      strcpy(buffer,yytext);
                      len = strlen(buffer);
                      for(loop=len; loop > 0;loop--){
                        if(buffer[loop] == '\n')
                           break;
                      }
                      yyless(loop);
                      statep++;
                      states[statep] = ENUM;
                      BEGIN(ENUM);
                    }

<ENUM>"@@"           printf("@@@@");
<ENUM>":"\n+"     "[^0-9]    {
                    printf(":\n\n@@example\n");
                    statep++;
                    states[statep] = EXAMPLE;
                    BEGIN(EXAMPLE); 
                  }


<ENUM>\n[ \t]+[0-9]+"." {
                    printf("\n\n@@item ");
                   }
<ENUM>^[^ ] | 
<ENUM>\n\n\n[ \t]+[^0-9] {
                    printf("\n\n@@end enumerate\n\n");
                    statep--;
                    BEGIN(states[statep]);
                  }
 
 /* 
  * reproduce one kind of @@itemize list
  */

":"\n+":"         {
                    int loop;
                    int len;

                    printf(":\n\n@@itemize @@bullet \n");
                    yyless(2);
                    statep++;
                    states[statep] = LITEM2;
                    BEGIN(LITEM2);
                  }
<LITEM2>^":".+":" {
                    (void)check_and_convert(&yytext[1]);
                    buffer[strlen(buffer)-1]='\0';
                    printf("@@item @@b{%s:}\n",buffer);
                  }
 
<LITEM2>\n\n\n+[^:\n] {
                    printf("\n\n@@end itemize\n\n");
                    ECHO;
                    statep--;
                    BEGIN(states[statep]);
                  }
 
 /*
  * create a list out of the revision history part.
  * We need the "Version" for this because it 
  * clashes with other rules otherwise.
  */

:[\n]+"Version"[^:\n*]+":" {
                    int loop;
                    int len;

                    printf(":\n\n@@itemize @@bullet \n");
                    strcpy(buffer,yytext);
                    len = strlen(buffer);
                    for(loop=len; loop > 0;loop--){
                      if(buffer[loop] == '\n')
                         break;
                    }
                    yyless(loop);
                    statep++;
                    states[statep] = LITEM;
                    BEGIN(LITEM);
                  }
<LITEM>^.+":"     {
                    (void)check_and_convert(yytext);
                    buffer[strlen(buffer)-1]='\0';
                    printf("@@item @@b{%s}\n\n",buffer);
                  }
 
<LITEM>^[^:\n]+\n\n[^:\n]+\n  {
                    int loop;

                    strcpy(buffer,yytext);
                    for(loop=0; buffer[loop] != '\n'; loop++);
                    buffer[loop] = '\0';
                    printf("%s\n",buffer);
                    printf("@@end itemize\n\n");
                    printf("%s",&buffer[loop+1]);
                    statep--;
                    BEGIN(states[statep]);
                  }
 
 /*
  * reproduce @@itemize @@bullet lists
  */

":"\n[ ]*"*"      {
                    int loop;
                    int len;

                    printf(":\n\n@@itemize @@bullet \n");
                    len = strlen(buffer);
                    for(loop=0; loop < len;loop++){
                      if(buffer[loop] == '\n')
                         break;
                    }
                    yyless((len-loop)+2);
                    statep++;
                    states[statep] = BITEM;
                    BEGIN(BITEM);
                  }

<BITEM>^" "*"*"   {
                    printf("@@item");
                    statep++;
                    states[statep] = BITEM_ITEM;
                    BEGIN(BITEM_ITEM);
                  }
<BITEM>"@@"          printf("@@@@");
<BITEM>^\n        { 
                    printf("@@end itemize\n\n");
                    statep--;
                    BEGIN(states[statep]);
                  } 
<BITEM_ITEM>[^\:]* {
                     printf(" @@b{%s}\n\n",check_and_convert(yytext));
                   }
<BITEM_ITEM>":"   { 
                    statep--; 
                    BEGIN(states[statep]);
                  }

 /* 
  * recreate @@chapter, @@section etc.
  */

^:[^:]*           { 
                    (void)check_and_convert(&yytext[1]); 
                    statep++;
                    states[statep] = HEADING;
                    BEGIN(HEADING); 
                  }
<HEADING>:[^\n]   {
                    printf("@@item @@b{%s}\n",buffer); 
                    write_underline(strlen(buffer),6,'~');
                    statep--; 
                    BEGIN(states[statep]);
                  }
<HEADING>:\n"*"*  { 
                    if(need_closing == TRUE){
                      printf("@@end table\n\n\n");
                      need_closing = FALSE;
                    }
                    printf("@@chapter %s\n",buffer); 
                    write_underline(strlen(buffer),9,'*');
                    statep--; 
                    BEGIN(states[statep]);
                  }
<HEADING>:\n"="*  { 
                    if(need_closing == TRUE){
                     printf("@@end table\n\n\n");
                      need_closing = FALSE;
                    }
                    printf("@@section %s\n",buffer); 
                    write_underline(strlen(buffer),9,'=');
                    statep--; 
                    BEGIN(states[statep]);
                  }
<HEADING>"@@"        printf("@@@@");
<HEADING>:\n"-"*  { 
                    if(need_closing == TRUE){
                      printf("@@end table\n\n\n");
                      need_closing = FALSE;
                    }
                    printf("@@subsection %s\n",buffer); 
                    write_underline(strlen(buffer),12,'-');
                    statep--; 
                    BEGIN(states[statep]);
                  }

 /*
  * recreate @@example text
  */

^"     "          {
                    printf("@@example\n");
                    statep++;
                    states[statep] = EXAMPLE;
                    BEGIN(EXAMPLE); 
                  }
<EXAMPLE>^"     "
.                 ECHO;

%%

/*
 * initialise and go.
 */

int main(int argc, char *argv[])
{
  states[0] = INITIAL;
  statep    = 0;
  print_header();
  yylex();
  print_trailer();
  return(0);
}



@


1.1.1.1
log
@from sourceforge.
@
text
@@
