📄 tohtml.java
字号:
"-r --" + labels.getString("r.option") + " <" + labels.getString("translate") + ">", }; int maxLength = 0; for (int i=0; i<helpFlags.length; i++){ maxLength = Math.max(maxLength, helpFlags[i].length()); } maxLength += 1; System.out.println( labels.getString("tohtml") + " [-" + StringHelper.replace(oneLetterOptions, ":", "") + "] <" + labels.getString("files") + ">\n" + labels.getString("purpose.message") + "\n" + labels.getString("stdin.message") + "\n" + " " + StringHelper.postpad(helpFlags[0] ,maxLength, ' ') + labels.getString("help.message") + "\n" + " " + StringHelper.postpad(helpFlags[1] ,maxLength, ' ') + labels.getString("version.message") + "\n" + " " + StringHelper.postpad(helpFlags[2] ,maxLength, ' ') + labels.getString("about.message") + "\n" + " " + StringHelper.postpad(helpFlags[3] ,maxLength, ' ') + labels.getString("m.message") + "\n" + " " + StringHelper.postpad(helpFlags[4] ,maxLength, ' ') + labels.getString("l.message") + "\n" + " " + StringHelper.postpad(helpFlags[5] ,maxLength, ' ') + labels.getString("T.message") + "\n" + " " + StringHelper.postpad(helpFlags[6] ,maxLength, ' ') + labels.getString("i.message") + "\n" + " " + StringHelper.postpad(helpFlags[7] ,maxLength, ' ') + labels.getString("t.message") + "\n" + " " + StringHelper.postpad(helpFlags[8] ,maxLength, ' ') + labels.getString("s.message") + "\n" + " " + StringHelper.postpad(helpFlags[9] ,maxLength, ' ') + labels.getString("o.message") + "\n" + " " + StringHelper.postpad(helpFlags[10] ,maxLength, ' ') + labels.getString("f.message") + "\n" + " " + StringHelper.postpad(helpFlags[11] ,maxLength, ' ') + labels.getString("r.message") + "\n" ); System.exit(0); } break; case 2:{ // print out the version message System.out.println(MessageFormat.format(labels.getString("version"), new String[] {version})); System.exit(0); } break; case 3:{ System.out.println( labels.getString("tohtml") + " -- " + labels.getString("purpose.message") + "\n" + MessageFormat.format(labels.getString("copyright"), new String[] {"1999-2002", "Stephen Ostermiller (http://ostermiller.org/contact.pl?regarding=Syntax+Highlighting)"}) + "\n\n" + labels.getString("license") ); System.exit(0); } break; case 'm':{ toHTML.setMimeType(opts.getOptarg()); } break; case 'l':{ toHTML.setLexerType(opts.getOptarg()); } break; case 'T':{ title = opts.getOptarg(); } break; case 'i':{ toHTML.addIgnoreStyle(opts.getOptarg()); } break; case 't':{ String template = opts.getOptarg(); File f = new File(opts.getOptarg()); if (f.exists()){ try { toHTML.setTemplate(f.toURL().toString()); } catch (MalformedURLException mfue){ toHTML.setTemplate(template); } } else { toHTML.setTemplate(template); } } break; case 's':{ toHTML.setStyleSheet(opts.getOptarg()); } break; case 'o':{ output = opts.getOptarg(); } break; case 'f':{ force = true; } break; case 'r':{ java.util.StringTokenizer st = new java.util.StringTokenizer(opts.getOptarg(), "=", false); if (st.countTokens() != 2){ System.err.println(labels.getString("unexpectedTranslation")); System.exit(1); } toHTML.translateStyle(st.nextToken().trim(), st.nextToken().trim()); } break; default:{ System.err.println(labels.getString("unexpectedArgument")); System.exit(1); } } } try { if (args.length <= opts.getOptind()){ try { if (output == null) output = "--"; toHTML.setOutput(output, "out.html", force); toHTML.setInput(new InputStreamReader(System.in)); toHTML.setTitle((title!=null)?(title):("HTML of System.in" + ((toHTML.getMimeType()==null)?"":(" ("+toHTML.getMimeType()+")")))); toHTML.writeFullHTML(); } catch (IOException e){ System.err.println(e.getMessage()); } } else { for (int i=opts.getOptind(); i<args.length; i++){ try { String defaultName = args[i] + ".html"; String outputFileName = null; outputFileName = (output == null)?defaultName:output; toHTML.setOutput(outputFileName, defaultName, force); toHTML.setExtFromFileName(args[i]); toHTML.setDocNameFromFileName(args[i]); toHTML.setInput(new FileReader(args[i])); toHTML.setTitle((title!=null)?(title):("HTML of " + getDocName(args[i]) + ((toHTML.getMimeType()==null)?"":(" ("+toHTML.getMimeType()+")")))); toHTML.writeFullHTML(); } catch (IOException e){ System.err.println(e.getMessage()); } } } } catch (InvocationTargetException x){ System.err.println(x.getMessage()); } catch (CompileException x){ System.err.println(x.getMessage()); } } private static String getDocName(String fileName){ String docName = null; if (fileName != null) { docName = ""; int dotIndex = fileName.lastIndexOf("."); int sepIndex = fileName.lastIndexOf(System.getProperty("file.separator")); int start = sepIndex + 1; if (sepIndex == -1){ start = 0; } int end = dotIndex; if (dotIndex == -1 || dotIndex < sepIndex){ end = fileName.length(); } docName = fileName.substring(start, end); } return docName; } /** * Sets the document name minus the path and extension * * @param inputFileName file name from which to extract the document name. */ public void setDocNameFromFileName(String inputFileName){ setDocName(getDocName(inputFileName)); } /** * Sets the file extension to be anything after the last '.' in the * given file name. * * @param inputFileName file name from which to extract the extension. */ public void setExtFromFileName(String inputFileName){ String extension = null; if (inputFileName != null) { extension = ""; int dotIndex = inputFileName.lastIndexOf("."); int sepIndex = inputFileName.lastIndexOf(System.getProperty("file.separator")); if (dotIndex != -1 && dotIndex > sepIndex) { extension = inputFileName.substring(dotIndex+1, inputFileName.length()); } } setFileExt(extension); } private void setOutput(String output, String defaultName, boolean force) throws IOException { if (output.equals("--")){ setOutput(new PrintWriter(System.out, true)); } else { File outputFile = new File(defaultName); if (output != null){ outputFile = new File(output); if (outputFile.isDirectory()){ int dirIndex = defaultName.lastIndexOf(System.getProperty("file.separator")); if (dirIndex != -1){ defaultName = defaultName.substring(dirIndex+1, defaultName.length()); } outputFile = new File (outputFile, defaultName); } } if (!force && outputFile.exists()){ throw new IOException( MessageFormat.format( labels.getString("fileExists"), new Object[] { outputFile.toString() } ) ); } setOutput(outputFile); if (getStyleSheet().equals("syntax.css")){ putSyntaxCSS(outputFile.getParentFile()); } } } private static boolean putSyntaxCSS(File directory) throws IOException { File f; if (directory==null) { f = new File("syntax.css"); } else { f = new File(directory, "syntax.css"); } if (f.exists()) return false; FileOutputStream out = new FileOutputStream(f); InputStream in = ClassLoader.getSystemResourceAsStream("com/Ostermiller/Syntax/doc/syntax.css"); byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer,0,read); } in.close(); out.close(); return true; } /** * Write the html encoded version of a document * using syntax highlighting for Java. * <p> * The document produced is not a full html document but rather * an html fragment that may be inserted into a full document. * <p> * This is a convenience method that creates an new ToHTML object. * * @param in Data stream that needs to be formatted in html. * @param out html document gets written here. * @param mimeType the mime type of the document to be used for syntax highlighting purposes. * @throws IOException if an I/O error occurs. */ public static void htmlifyJava(Reader in, PrintWriter out) throws IOException { try { ToHTML toHTML = new ToHTML(); toHTML.setLexer(new JavaLexer(in)); toHTML.setOutput(out); toHTML.writeHTMLFragment(); } catch (InvocationTargetException x){ // can't happen } } /** * Write the html encoded version of a document * using syntax highlighting for C. * <p> * The document produced is not a full html document but rather * an html fragment that may be inserted into a full document. * <p> * This is a convenience method that creates an new ToHTML object. * * @param in Data stream that needs to be formatted in html. * @param out html document gets written here. * @param mimeType the mime type of the document to be used for syntax highlighting purposes. * @throws IOException if an I/O error occurs. */ public static void htmlifyC(Reader in, PrintWriter out) throws IOException { try { ToHTML toHTML = new ToHTML(); toHTML.setLexer(new CLexer(in)); toHTML.setOutput(out); toHTML.writeHTMLFragment(); } catch (InvocationTargetException x){ // can't happen } } /** * Write the html encoded version of a document * using syntax highlighting for HTML using a simple coloring * algorithm. * <p> * The document produced is not a full html document but rather * an html fragment that may be inserted into a full document. * <p> * This is a convenience method that creates an new ToHTML object. * * @param in Data stream that needs to be formatted in html. * @param out html document gets written here. * @param mimeType the mime type of the document to be used for syntax highlighting purposes. * @throws IOException if an I/O error occurs. */ public static void htmlifySimpleHTML(Reader in, PrintWriter out) throws IOException { try { ToHTML toHTML = new ToHTML(); toHTML.setLexer(new HTMLLexer(in)); toHTML.setOutput(out); toHTML.writeHTMLFragment(); } catch (InvocationTargetException x){ // can't happen } } /** * Write the html encoded version of a document * using syntax highlighting for HTML using a complex coloring * algorithm. * <p> * The document produced is not a full html document but rather * an html fragment that may be inserted into a full document. * <p> * This is a convenience method that creates an new ToHTML object. * * @param in Data stream that needs to be formatted in html. * @param out html document gets written here. * @param mimeType the mime type of the document to be used for syntax highlighting purposes. * @throws IOException if an I/O error occurs. */ public static void htmlifyComplexHTML(Reader in, PrintWriter out) throws IOException { try { ToHTML toHTML = new ToHTML(); toHTML.setLexer(new HTMLLexer1(in)); toHTML.setOutput(out); toHTML.writeHTMLFragment(); } catch (InvocationTargetException x){ // can't happen } } /** * Write the html encoded version of a document * using no syntax highlighting. * <p> * The document produced is not a full html document but rather * an html fragment that may be inserted into a full document. * <p> * This is a convenience method that creates an new ToHTML object. * * @param in Data stream that needs to be formatted in html.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -