All pastes #1743858 Raw Edit

Something

public html v1 · immutable
#1743858 ·published 2010-01-09 08:58 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org"><meta http-equiv="Content-type" content="text/html; charset=utf-8"><title>C/C++ Formatter for Orkut</title><script type="text/javascript" language="javascript"><!--// configurationsKeyWord = '[b][blue]';sKeyWordEnd = '[/blue][/b]'sPreprocessor = '[maroon]';sPreprocessorEnd = '[/maroon]'sComment = '[i][green]';sCommentEnd = '[/i][/green]';        sDocComment = '[i][green]'sDocCommentEnd = '[/i][/green]'sString = '[red]';sStringEnd = '[/red]';sChar = '[purple]';sCharEnd = '[/purple]';sTab = "&#160;&#160;&#160;&#160;";sNewLine = "\n";// change this to simple space instead of HTML entity // to allow more characters in one postsSpace = "&#160;"  function highlightKeywords(sSourceText) {        // keywords, alphabetical order        sSourceText = sSourceText.replace(/\b(auto|asm)\b/g, sKeyWord + "$1" + sKeyWordEnd  );        sSourceText = sSourceText.replace(/\b(break|bool)\b/g, sKeyWord + "$1" + sKeyWordEnd );        sSourceText = sSourceText.replace(/\b(case|char|const|continue|catch|class|const_cast)\b/g,sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(default|do|double|delete|dynamic_cast)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(else|enum|extern)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(float|for|false|friend)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(goto)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(if|int|inline)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(long)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(mutable)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(namespace|new)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(operator)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(private|public|protected)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(register|return|reinterpret_cast|restrict)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(short|signed|sizeof|static|struct|switch|static_cast|size_t)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(typedef|template|this|throw|true|try|typedef|typeid|typename)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(union|unsigned|using)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(void|volatile|virtual)\b/g, sKeyWord + "$1" + sKeyWordEnd);        sSourceText = sSourceText.replace(/\b(while|wchat_t)\b/g, sKeyWord + "$1" + sKeyWordEnd);               return sSourceText;}function highlightPreprocessor(sSourceText){        return sSourceText.replace(/(#)+(include|if|ifdef|ifndef|else|elif|endif|define|pragma|error|warning|undef)+(.*)/g, sPreprocessor + "#$2$3" + sPreprocessorEnd);}function convert(){        var x = 0, sNewText = "";        var sSourceText = document.getElementById("code").value;        var temp = "", tok = "";		var lines = 0;                // replace < and > with HTML entities		// RegExp objects used to ensure		// this document passes HTML 4.01		// validation		var lt = new RegExp("<", "g");         sSourceText = sSourceText.replace(lt, "&lt;");				var gt = new RegExp(">", "g");        sSourceText = sSourceText.replace(gt, "&gt;");        // start parsing                for(x = 0; x < sSourceText.length; x++)        {                tok = sSourceText.charAt(x);                                if( tok == "\n" ) // newline                {                        sNewText += sNewLine;						lines++;                }                else if( tok == "\t" ) // tab                {                        sNewText += sTab;                }				else if( tok == " ") // space				{					sNewText += sSpace;				}		                else if( tok == "#" ) // preprocessor                {                        var flag = 1, t;                        temp = "";                        while( (sSourceText.charAt(x) != "\n" && x < sSourceText.length)  !="" || flag )                        {                                flag = 0;                                t = sSourceText.charAt(x);                                if( t == "\n" )                                {                                        temp += sNewLine;                                }                                else                                {                                        temp += t;                                }                                if( sSourceText.charAt(x) == "\\" && sSourceText.charAt(x + 1) == "\n") // multiline macro                                {                                        flag = 1;                                }                                x++;                        }                        sNewText += highlightPreprocessor(temp) + sNewLine                } // preprocessing                                else if( tok == "/" ) // start of comment                {                        var sStart  = sComment, sEnd = sCommentEnd;                        t1 = sSourceText.charAt(x + 1);                        t2 = sSourceText.charAt(x + 2);                        temp = "";                        if( t1 == "*") // multiline comment                        {                                if( t2 == "*") // doc commnent                                {                                        sStart = sDocComment;                                        sEnd = sDocCommentEnd;                                }                                var end = sSourceText.indexOf("*/", x);                                while( x < end )                                {                                        t1 = sSourceText.charAt(x++);                                        if( t1 == "\n")                                                temp += sNewLine                                        else if( t1 == "\t")                                                temp += sTab;                                        else if( t1 == " ")                                                temp += sSpace;                                        else                                                temp += t1;                                }                                sNewText += sStart + temp + "*/" + sEnd;                                x++;                        }                        else if(sSourceText.substr(x, 2) =="\/\/") // single line comment                        {                                 sNewText += sComment + sSourceText.substr(x).replace(/[\n\r][\w\W]*/,'') + sCommentEnd;                                x += sSourceText.substr(x).replace(/[\n\r][\w\W]*/,'').length - 1;                        }                        else                        {                                sNewText += tok;                        }                } // comment                                else if( tok == '"' || tok == "'") // string or character literal                {                        temp = "";                        var flag = 1, t;                        while( (sSourceText.charAt(x) != tok && x < sSourceText.length) || flag)                        {                                flag = 0;                                t = sSourceText.charAt(x);                                if( t == "\n")                                 {                                        temp += sNewLine;                                }                                else                                {                                        temp += t;                                }                                if( sSourceText.charAt(x) == "\\" && sSourceText.charAt(x+1) == '"') // handle escaped strings                                {                                        flag = 1;                                }                                                               x++;                        }                        sNewText += ( tok == '"' ? sString : sChar) + temp + tok + ( tok == '"' ? sStringEnd : sCharEnd );                } // string or character literal                                else if(!sSourceText.substr(x, 1).replace(/\w/,''))                 {                        // variable, keyword or literal                        temp = sSourceText.substr(x).replace(/\W[\w\W]*/,'');                        x += temp.length - 1; // skip over this token                        sNewText += highlightKeywords(temp);                }                                else                {                        sNewText += tok;                }        }                // write highlighted code        var output = "";        output += sNewText;        document.getElementById("output").value = output;		if( sNewText.length < 2048 )			document.getElementById("usage").innerHTML = "Formatted code will use use " + Math.round((sNewText.length / 2048)*100) + "% of allowable characters in one post";		else			alert("Warning! Formatted output will not fit in one post!");}// insert tabs into the textarea// instead of switching focusfunction handleTab(sender, e) {	if (e.keyCode == 9)	{		if (e.srcElement)		{			sender.selection = document.selection.createRange();			sender.selection.text = "\t";		}		else if (e.target)		{			var start = sender.value.substring(0, sender.selectionStart);			var end = sender.value.substring(sender.selectionEnd, sender.value.length);									var newRange = sender.selectionEnd + 1;			var scrollPos = sender.scrollTop;			sender.value = String.concat(start, "\t", end);								sender.setSelectionRange(newRange, newRange);			sender.scrollTop = scrollPos;		}		return false;	}	else	{		return true;	}}// --></script><style type="text/css"> span.c4 {font-style: italic;} textarea.c3 {width: 616px; height: 223px;} textarea.c2 {width: 616px; height: 231px;} p.c1 {font-style: italic;}</style></head><body><h2>C/C++ Formatter for Orkut</h2><p class="c1">Version 0.4b</p><p>Input C/C++ code here:</p><textarea id="code" class="c2" name="TEXTAREA1" rows="12" cols="66" onkeydown="return handleTab(this, event)"></textarea><div><input id="button1" value="Convert" name="button1" onclick="convert()" type="button"></div><p>Formatted C/C++ code:<br></p><textarea id="output" class="c3" name="TEXTAREA2" rows="11" cols="66"></textarea><p><span id="usage"></span></p></body></html>