Recommended

Multicore community

 

Articles

Intel.com

Microsoft.co.il

 

Community

Microsoft Forums

Intel's Forum

Intel's Multicore Community

 

Resources

http://msdn.com/concurrency

Intel Multicore

NVidia Multicore GPU

 

Downloads

.Net Parallel Extensions

Intel's TBB

WinModules   

 

Tools

AsyncOp Logger

Intel thread analysis

Intel VTune

 

Contact

Asaf Shelly

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-->

 

 

 

 

 

 
2 / 2
 
 
 
 
 
 
 
    // /  This HTML file was produced by the ProjectPublisher WebService, By Asaf Shelly                   / //
   // /    WebService URL is: http://Services.AsyncOp.com/ProjectPublisher/ProjectPublisherWSvc.asmx      / //
  // /    Learn more and find the source code here: http://AsyncOp.com                                   / //


using System;
using System.IO;
using System.Web;

namespace PublishProjectLib
{
   public class KeywordsGeneral
   {
      public static string[] Types = { "int", "long", "bool", "void", "BYTE", "byte", "WORD", "DWORD", "char", "class", "typedef", "const", "short", "double", "float", "unsigned" };
      public static string[] Values = { "NULL", "null", "true", "false", "EOF", "TRUE", "FALSE" };
      public static string[] FlowMgmt = { "for", "while", "do", "continue", "break", "switch", "case" };
      public static string[] FlowCtrl = { "if", "else", "goto" };
      public static string[] Except = { "try", "catch", "throw", "finally" };
      public static string[] Typedefs = { "template", "class", "struct", "typedef", "public", "private", "protected", "union", "enum", "namespace", "using" };
      public static string[] TypeSpec = { "static", "__fastcall", "__cdecl", "__declspec", "__asm", "__pascal", "register", "auto", "__stdcall" };
   }


   public class ProjectPublisher
   {
      public static string WelcomeHeader =
         "<font color=\"#6B87B4\" style=\"font-size: 8pt\">" +
         "&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;/&nbsp;&nbsp;" + 
         "This HTML file was produced by the ProjectPublisher "+
         "WebService, By Asaf Shelly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;//<br>\n" +
         "&nbsp;&nbsp;&nbsp;//&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;" +
         "WebService URL is:" + 
         " <a href=\"http://Services.AsyncOp.com/ProjectPublisher/" +
         "ProjectPublisherWSvc.asmx\"><font color=\"#6b87b4\">" + 
         "http://Services.AsyncOp.com/ProjectPublisher/"+
         "ProjectPublisherWSvc.asmx</font></a>" + 
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;//<br>\n" +
         "&nbsp;&nbsp;//&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;" + 
         "Learn more and find the source code here:" + 
         " <a href=\"http://AsyncOp.com\"><font color=\"#6b87b4\">" + 
         "http://AsyncOp.com</font></a>&nbsp;" + 
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;//<br>\n" +
         "</font><br>\n<br>\n";

      private static int braceCountScope = 0;
      //private static int braceCountMath = 0;
   

      private static bool DefaultParsing(string text, ref int index, ref int indexLen, ref TextState state)
      {
         bool retval = true;           // retval: true = continue
         if (text[index] == '\'') state = TextStates.State_StringCh;
         else if (text[index] == '"') state = TextStates.State_String;
         else if (text[index] == '#') state = TextStates.State_Preprocess;
         else if (CLangParser.IsCharWord(text[index])) state = TextStates.State_Word;
         else if (CLangParser.IsCharNumber(text[index])) state = TextStates.State_Number;
         else if (CLangParser.IsCharWhite(text[index])) state = TextStates.State_White;
         else if ((text[index] == '/') && (text[index + 1] == '/')) { indexLen = 2; state = TextStates.State_CommentSingle; }
         else if ((text[index] == '/') && (text[index + 1] == '*')) { indexLen = 2; state = TextStates.State_CommentMulti; }

         else if ((text[index] == '&') && (text[index + 1] == '&')) { indexLen = 2; state = TextStates.State_OpBool; }
         else if ((text[index] == '|') && (text[index + 1] == '|')) { indexLen = 2; state = TextStates.State_OpBool; }

         else if ((text[index] == '<') && (text[index + 1] == '=')) { indexLen = 2; state = TextStates.State_OpEqu; }
         else if ((text[index] == '>') && (text[index + 1] == '=')) { indexLen = 2; state = TextStates.State_OpEqu; }
         else if ((text[index] == '+') && (text[index + 1] == '+')) { indexLen = 2; state = TextStates.State_OpMath; }
         else if ((text[index] == '-') && (text[index + 1] == '-')) { indexLen = 2; state = TextStates.State_OpMath; }
         else if ((text[index] == '<') && (text[index + 1] == '<')) { indexLen = 2; state = TextStates.State_OpLogic; }
         else if ((text[index] == '>') && (text[index + 1] == '>')) { indexLen = 2; state = TextStates.State_OpLogic; }
         else if ((text[index] == '-') && (text[index + 1] == '>')) { indexLen = 2; state = TextStates.State_OpDeRef; }
         else if ((text[index] == ':') && (text[index + 1] == ':')) { indexLen = 2; state = TextStates.State_OpDeRef; }

         else if (text[index] == '+') state = TextStates.State_OpMath;
         else if (text[index] == '-') state = TextStates.State_OpMath;
         else if (text[index] == '*') state = TextStates.State_OpMath;
         else if (text[index] == '/') state = TextStates.State_OpMath;
         else if (text[index] == '%') state = TextStates.State_OpMath;
         else if (text[index] == '^') state = TextStates.State_OpLogic;
         else if (text[index] == '&') state = TextStates.State_OpLogic;
         else if (text[index] == '|') state = TextStates.State_OpLogic;
         else if (text[index] == '!') state = TextStates.State_OpBool;
         else if (text[index] == '~') state = TextStates.State_OpLogic;
         else if (text[index] == ';') state = TextStates.State_OpSemicol;
         else if (text[index] == ',') state = TextStates.State_OpComma;
         else if (text[index] == '.') state = TextStates.State_OpDot;

         else if (text[index] == '(')
         {
            TextStates.Count_OpBraceMath++;
            switch (TextStates.Count_OpBraceMath % 8)
            {
               case (1): state = TextStates.State_OpBraceMathOpn1; break;
               case (2): state = TextStates.State_OpBraceMathOpn2; break;
               case (3): state = TextStates.State_OpBraceMathOpn3; break;
               case (4): state = TextStates.State_OpBraceMathOpn4; break;
               case (5): state = TextStates.State_OpBraceMathOpn5; break;
               case (6): state = TextStates.State_OpBraceMathOpn6; break;
               case (7): state = TextStates.State_OpBraceMathOpn7; break;
               case (0): state = TextStates.State_OpBraceMathOpn8; break;
               default : state = TextStates.State_OpBraceMathOpn1; break;
            }
            retval = false;
         }
         else if (text[index] == ')')
         {
            switch (TextStates.Count_OpBraceMath % 8)
            {
               case (1): state = TextStates.State_OpBraceMathCls1; break;
               case (2): state = TextStates.State_OpBraceMathCls2; break;
               case (3): state = TextStates.State_OpBraceMathCls3; break;
               case (4): state = TextStates.State_OpBraceMathCls4; break;
               case (5): state = TextStates.State_OpBraceMathCls5; break;
               case (6): state = TextStates.State_OpBraceMathCls6; break;
               case (7): state = TextStates.State_OpBraceMathCls7; break;
               case (0): state = TextStates.State_OpBraceMathCls8; break;
               default : state = TextStates.State_OpBraceMathCls1; break;
            }
            TextStates.Count_OpBraceMath--; if (TextStates.Count_OpBraceMath < 0) TextStates.Count_OpBraceMath = 0;
            //state = TextStates.State_OpBraceMath;
            retval = false;
         }
         else if (text[index] == '[') state = TextStates.State_OpBraceArr;
         else if (text[index] == ']') state = TextStates.State_OpBraceArr;

         else if (text[index] == '{')
         {
            braceCountScope++;
            if (1 == braceCountScope) state = TextStates.State_OpBraceScopeFirst;
            else state = TextStates.State_OpBraceScope;
         }
         else if (text[index] == '}')
         {
            braceCountScope--; if (braceCountScope < 0) braceCountScope = 0;
            state = TextStates.State_OpBraceScope;
         }

         else if (text[index] == '?') state = TextStates.State_OpTri;
         else if (text[index] == ':') state = TextStates.State_OpTri;      // also label and case

         else { indexLen = 1; state = TextStates.State_Undefined; }
         return (retval);
      }




      private static bool CompareStrings(string word, string[] list)
      {
         foreach (string str in list)
         {
            if (str == word) return (true);
         }
         return (false);
      }

      private static bool ParseKeywords(string word, ref TextState state)
      {
         if (CompareStrings(word, KeywordsGeneral.Types)) { state = TextStates.State_KeywType; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.Values)) { state = TextStates.State_KeywVal; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.FlowMgmt)) { state = TextStates.State_KeywFlowMgmt; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.FlowCtrl)) { state = TextStates.State_KeywFlowCtrl; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.Except)) { state = TextStates.State_KeywExcept; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.Typedefs)) { state = TextStates.State_KeywTypedef; return (true); }
         else if (CompareStrings(word, KeywordsGeneral.TypeSpec)) { state = TextStates.State_KeywTypespec; return (true); }
         return (false);
      }

      public static string ParseText(ref string text)
      {
         if (null == text) return ("Empty text file");
         string retval = null;
         string output = "<table border=\"0\" width=\"100%\" id=\"table_sample_code\" style=\"border-collapse: collapse; font-family: Courier New; margin-top: 0; margin-bottom: 0\"><tr><td"/* nowrap*/+"><font size=\"2\">\n" + WelcomeHeader;
         string tempStr;
         TextState state = TextStates.State_Undefined;
         TextState oldState = TextStates.State_Undefined;
         int index = 0;
         int oldIndex = 0;
         int indexLen = 1;
         bool force = false;
         for (index = 0; index < text.Length; index += indexLen)
         {
            indexLen = 1;
            if (TextStates.State_Undefined == state)
            {
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else if (TextStates.State_White == state)
            {
               if (CLangParser.IsCharWhite(text[index])) continue;
               else
               {
                  force = !DefaultParsing(text, ref index, ref indexLen, ref state);
                  if ((!force) && (oldState == state)) continue;
               }
            }
            else if (TextStates.State_Word == state)
            {
               if (CLangParser.IsCharWord(text[index])) continue;
               else if (CLangParser.IsCharNumber(text[index])) continue;
               else
               {
                  ParseKeywords(text.Substring(oldIndex, index - oldIndex), ref oldState);
                  force = !DefaultParsing(text, ref index, ref indexLen, ref state);
                  if ((!force) && (oldState == state)) continue;
               }
            }
            else if (TextStates.State_Number == state)
            {
               if (CLangParser.IsCharWord(text[index])) continue;
               else if (CLangParser.IsCharNumber(text[index])) continue;
               else if (text[index] == '.') continue;
               else
               {
                  force = !DefaultParsing(text, ref index, ref indexLen, ref state);
                  if ((!force) && (oldState == state)) continue;
               }
            }
            else if (TextStates.State_String == state)
            {
               if (text[index] == '\\') { index++; continue; }
               else if (text[index] != '"') continue;
               index++;
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else if (TextStates.State_StringCh == state)
            {
               if (text[index] == '\\') { index++; continue; }
               else if (text[index] != '\'') continue;
               index++;
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else if (TextStates.State_Preprocess == state)
            {
               if (text[index] == '\\') { index++; continue; }
               else if (text[index] != '\n') continue;
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else if (TextStates.State_CommentSingle == state)
            {
               if (text[index] != '\n') continue;
// if ((DefaultParsing(text, ref index, ref indexLen, ref state)) && (oldState == state)) continue;
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else if (TextStates.State_CommentMulti == state)
            {
               if ((text[index] == '*') && (text[index + 1] == '/')) index += 2;
               else continue;
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            else
            {
               force = !DefaultParsing(text, ref index, ref indexLen, ref state);
               if ((!force) && (oldState == state)) continue;
            }
            if ((oldState != state) || (force))
            {
               output = output + oldState.EnterString;
               tempStr = HttpUtility.HtmlEncode(text.Substring(oldIndex, index - oldIndex));
               if ((TextStates.State_White == oldState) && (tempStr.Length > 1)) tempStr = tempStr.Replace(" ", "&nbsp;");
               output = output + tempStr.Replace("\n", "<br>\n").Replace("\t", "&nbsp;&nbsp;&nbsp;");
               output = output + oldState.ExitString;
               oldState = state;
               oldIndex = index;
               force = false;
            }
         }
         output = output + oldState.EnterString;
         tempStr = HttpUtility.HtmlEncode(text.Substring(oldIndex, index - oldIndex));
         if ((TextStates.State_White == oldState) && (tempStr.Length > 1)) tempStr = tempStr.Replace(" ", "&nbsp;");
         output = output + tempStr.Replace("\n", "<br>\n").Replace("\t", "&nbsp;&nbsp;&nbsp;");
         output = output + oldState.ExitString;
         output = output + "</font></td></tr></table>\n";
         text = output;
         return (retval);
      }

      public static string GenerateHTMLForFile(string filePath)
      {
         string textFile = null;
         try { textFile = File.ReadAllText(filePath); }
         catch (Exception exp) { return("Internal Error: failed opening input file: \"" + exp.Message + "\""); }
         textFile = textFile.Replace("\r\n", "\n");
         return (ProduceHTML(textFile));
      }

      public static string ProduceHTML(string sourceFile)
      {
         string error = null;
         string textFile = sourceFile;
         error = ParseText(ref textFile);
         if (error != null) return ("Internal Error: Parsing failed: \"" + error + "\"");
         return ("<html dir=\"ltr\"><head><meta http-equiv=\"Content-Language\" content=\"en-us\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\"><title>Asaf Shelly</title></head><body>"
            + textFile + "</body></html>")
;
      }

   }

   class TextState
   {
      protected string enterString;
      protected string exitString;
      protected virtual string GetEnterString()
      {
         return (enterString);
      }
      protected virtual string GetExitString()
      {
         return (exitString);
      }
      public string EnterString { get { return (GetEnterString()); } }
      public string ExitString { get { return (GetExitString()); } }
      public TextState(string enter, string exit)
      {
         enterString = enter;
         exitString = exit;
      }
   }

   class TextStates
   {
      static public TextState State_Undefined = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_White = new TextState("", "");
      static public TextState State_String = new TextState("<font color=\"#00B300\">", "</font>");
      static public TextState State_StringCh = new TextState("<font color=\"#0000C6\">", "</font>");
      static public TextState State_Word = new TextState("<font color=\"#AF3D1B\">", "</font>");
      static public TextState State_Number = new TextState("<font color=\"#0000C6\">", "</font>");
      static public TextState State_Preprocess = new TextState("<font color=\"#000000\"><span style=\"background-color: #DCE9D6\">", "</span></font>");
      static public TextState State_CommentSingle = new TextState("<font color=\"#7F7F7F\">", "</font>");
      static public TextState State_CommentMulti = new TextState("<font color=\"#7F7F7F\">", "</font>");

      static public TextState State_OpMath = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpLogic = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpBool = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpAssign = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpEqu = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpTri = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpSemicol = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpComma = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpDot = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpDeRef = new TextState("<font color=\"#000000\">", "</font>");

      static public TextState State_OpBraceArr = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceScope = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceScopeFirst = new TextState("<font color=\"#000000\">", "</font>");

      static public int Count_OpBraceMath = 0;
      static public TextState State_OpBraceMath = new TextState("<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn1 = new TextState("<span style=\"background-color: #E9E8EE\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn2 = new TextState("<span style=\"background-color: #E1F2F2\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn3 = new TextState("<span style=\"background-color: #F2E1E1\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn4 = new TextState("<span style=\"background-color: #F2F2E1\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn5 = new TextState("<span style=\"background-color: #DFDEE4\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn6 = new TextState("<span style=\"background-color: #DAFADA\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn7 = new TextState("<span style=\"background-color: #FAE4DA\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathOpn8 = new TextState("<span style=\"background-color: #FAFADA\">" + "<font color=\"#000000\">", "</font>");
      static public TextState State_OpBraceMathCls1 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls2 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls3 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls4 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls5 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls6 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls7 = new TextState("<font color=\"#000000\">", "</font></span>");
      static public TextState State_OpBraceMathCls8 = new TextState("<font color=\"#000000\">", "</font></span>");

      static public TextState State_KeywType = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywTypedef = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywTypespec = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywVal = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywFlowMgmt = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywFlowCtrl = new TextState("<font color=\"#0000FF\">", "</font>");
      static public TextState State_KeywExcept = new TextState("<font color=\"#0000FF\">", "</font>");
   }






   class CLangParser
   {
      public static bool IsCharWord(char ch)
      {
         return (char.IsLetter(ch) || ('_' == ch));
      }
      public static bool IsCharWhite(char ch)
      {
         return (char.IsWhiteSpace(ch));
      }
      public static bool IsCharNumber(char ch)
      {
         return (char.IsNumber(ch));
      }
   }






}