0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
1067N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1185N/A *
1185N/A * Portions Copyright 2011 Jens Elkner.
0N/A */
0N/A
0N/Apackage org.opensolaris.opengrok.analysis.document;
850N/Aimport org.opensolaris.opengrok.analysis.JFlexXref;
850N/Aimport java.io.IOException;
1384N/Aimport org.opensolaris.opengrok.analysis.XrefWriter;
0N/Aimport org.opensolaris.opengrok.web.Util;
0N/A
0N/A%%
0N/A%public
0N/A%class TroffXref
850N/A%extends JFlexXref
0N/A%unicode
0N/A%int
850N/A%{
1185N/A int p;
1185N/A int span;
1185N/A int div;
0N/A
1020N/A @Override
1384N/A public void write(XrefWriter out) throws IOException {
1281N/A p = 0;
1281N/A span = 0;
1281N/A div = 0;
1020N/A yyline++;
974N/A this.out = out;
974N/A while(yylex() != YYEOF) {
974N/A }
0N/A }
1020N/A
1020N/A // TODO move this into an include file when bug #16053 is fixed
1020N/A @Override
1020N/A protected int getLineNumber() { return yyline; }
1020N/A @Override
1020N/A protected void setLineNumber(int x) { yyline = x; }
1185N/A
1185N/A // Q&D methods to asure well-formed documents
1185N/A protected void closePara() throws IOException {
1281N/A if (p > 0) {
1281N/A out.write("</p>");
1281N/A p--;
1281N/A }
1185N/A }
1185N/A protected void closeSpan() throws IOException {
1281N/A if (span > 0) {
1281N/A out.write("</span>");
1281N/A span--;
1281N/A }
1185N/A }
1185N/A protected void closeDiv() throws IOException {
1281N/A if (div > 0) {
1281N/A out.write("</div>");
1281N/A div--;
1281N/A }
1185N/A }
1185N/A protected void openPara() throws IOException {
1281N/A out.write("<p>");
1281N/A p++;
1185N/A }
1185N/A protected void openSpan(char cssClass) throws IOException {
1281N/A out.write("<span class=\"");
1281N/A out.write(cssClass);
1281N/A out.write("\">");
1281N/A span++;
1185N/A }
1185N/A
1185N/A protected void openDiv(String cssClass) throws IOException {
1281N/A out.write("<div class=\"");
1281N/A out.write(cssClass);
1281N/A out.write("\">");
1281N/A div++;
1185N/A }
1185N/A
1185N/A protected void cleanup() {
1185N/A try {
1281N/A while (span > 0) {
1281N/A closeSpan();
1281N/A }
1281N/A while (p > 0) {
1281N/A closePara();
1281N/A }
1281N/A } catch (IOException e) {
1281N/A // nothing we can do here
1281N/A }
1185N/A }
0N/A%}
0N/A
1185N/A%eof{
1281N/A cleanup();
1281N/A try {
1281N/A while (div > 0) {
1281N/A closeDiv();
1281N/A }
1281N/A } catch (IOException e) {
1281N/A // nothing we can do here
1281N/A }
1185N/A%eof}
1185N/A
936N/AWhiteSpace = [ \t\f]
1020N/AEOL = \r|\n|\r\n
0N/AFNameChar = [a-zA-Z0-9_\-\.]
0N/AFile = {FNameChar}+ "." ([chtsCHS]|"conf"|"java"|"cpp"|"CC"|"txt"|"htm"|"html"|"pl"|"xml")
0N/APath = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*)+[a-zA-Z0-9]
0N/A
0N/A%state HEADER COMMENT BOLD TBL TBLL
0N/A
0N/A%%
0N/A<YYINITIAL> {
1390N/A^\.(SH|TH|SS|IP|NH|TL|UH) { yybegin(HEADER); cleanup(); openDiv("mnhd");}
1185N/A^(".\\\"")|(\'\\\")|("...\\\"") { yybegin(COMMENT);openSpan('c');}
0N/A}
0N/A
0N/A<HEADER> {
1185N/A{EOL} { yybegin(YYINITIAL); cleanup(); closeDiv(); yyline++;}
0N/A}
0N/A
0N/A<COMMENT> {
1185N/A{EOL} { yybegin(YYINITIAL); closeSpan(); out.write("<br/>"); yyline++;}
0N/A}
0N/A
1185N/A^\.(B|U|BI|BX|UL|LG|NL|SB|BR|RB) { yybegin(BOLD); openSpan('b'); }
1185N/A^\.(I|SM|IB|IR|RI|IX) { yybegin(BOLD); openSpan('s'); }
1185N/A^\.(CW) { yybegin(BOLD); openSpan('k'); }
1185N/A^\.(DS|LD|ID|BD|CD|RD) { openSpan('k'); }
1185N/A^\.DE { closeSpan(); }
0N/A
0N/A<BOLD> {
1185N/A{EOL} { yybegin(YYINITIAL); closeSpan(); out.write(' '); yyline++;}
0N/A}
0N/A
1185N/A"\\fB" { openSpan('b'); }
1185N/A"\\fI" { openSpan('s'); }
1185N/A"\\fC"|"\\f(CW" { openSpan('k'); }
1185N/A"\\fR" { closeSpan(); }
1185N/A"\\fP" { closeSpan(); }
0N/A
1185N/A^\.(PP|LP|P|TP|IP|HP|PD|SP|br|mk|ce) {
1185N/A cleanup();
1185N/A openPara();
0N/A}
0N/A
1390N/A^\.(RS)[^\n]* { cleanup(); openDiv("mnrs"); openPara(); }
1185N/A^\.(RE)[^\n]* { cleanup(); closeDiv(); }
0N/A
0N/A^\.so {out.write(".so ");}
1185N/A^\.(EQ|in|sp|ne|rt|pn|ds|de|if|ig|el|ft|hy|ie|ll|ps|rm|ta|ti|na|ad|te|hw|nh|pl)[^\n]*\n { }
0N/A^\.(NH|DT|EE)[^\n]* {}
0N/A^"\\(bu\n" {}
1185N/A^".nf" {closePara(); out.write("<pre>"); }
1185N/A^".fi" {cleanup(); out.write("</pre>"); }
1185N/A\\\*\(Tm { out.write("<sup>TM</sup> "); }
1185N/A\\\*\R { out.write("&reg; "); }
0N/A\\\((l|r)q { out.write('"'); }
0N/A\\\(mi { out.write('-'); }
0N/A
1185N/A^\.TS { cleanup(); yybegin(TBL);out.write("<table rules=\"all\"><tr><td>");}
0N/A<TBL> {
342N/Atab\(.\) { char tab = yycharat(4); }
0N/A\.$ { yybegin(TBLL); }
0N/A. {}
0N/A}
0N/A<TBLL> {
1185N/A\007 { cleanup(); out.write("</td><td>"); }
0N/A^[\_\=]\n {}
0N/AT[\{\}] {}
1185N/A^\.TE { yybegin(YYINITIAL); cleanup(); out.write("</td></tr></table>"); }
1185N/A{EOL} { cleanup(); out.write("</td></tr><tr><td>"); yyline++;}
0N/A}
0N/A
0N/A{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
974N/A {
1122N/A writeEMailAddress(yytext());
974N/A }
0N/A
1013N/A{File} {
1013N/A String path = yytext();
1013N/A out.write("<a href=\""+urlPrefix+"path=");
1013N/A out.write(path);
271N/A appendProject();
271N/A out.write("\">");
1013N/A out.write(path);
271N/A out.write("</a>");}
0N/A
0N/A{Path}
974N/A { out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
1013N/A\\&. {out.write(yycharat(yylength() - 1));}
974N/A\\- { out.write('-'); }
974N/A"\\ " { out.write(' '); }
974N/A"<" {out.write( "&lt;");}
974N/A">" {out.write( "&gt;");}
1281N/A"&" {out.write( "&amp;");}
1020N/A{EOL} { out.write("\n"); yyline++;}
974N/A{WhiteSpace}+ { out.write(' '); }
974N/A[!-~] { out.write(yycharat(0)); }
974N/A . { writeUnicodeChar(yycharat(0)); }