]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine the code to have same function to process the string info. Also update the...
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Apr 2012 10:26:04 +0000 (10:26 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Apr 2012 10:26:04 +0000 (10:26 +0000)
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13205 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
MdeModulePkg/Universal/SetupBrowserDxe/Ui.c

index c91ba48d2172da8c5304b3214146167b9bcf4940..7fb292592f975f65a1afff6942353b54937ae24f 100644 (file)
@@ -988,200 +988,31 @@ ProcessHelpString (
   IN  UINTN   RowCount\r
   )\r
 {\r
-  UINTN BlockWidth;\r
-  UINTN AllocateSize;\r
-  //\r
-  // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r
-  //\r
-  UINTN CurrIndex;\r
-  UINTN PrevCurrIndex;\r
-  UINTN LineCount;\r
-  UINTN VirtualLineCount;\r
-  //\r
-  // GlyphOffset stores glyph width of current screen-line\r
-  //\r
-  UINTN GlyphOffset;\r
-  //\r
-  // GlyphWidth equals to 2 if we meet width directive\r
-  //\r
-  UINTN GlyphWidth;\r
-  //\r
-  // during scanning, we remember the position of last space character\r
-  // in case that if next word cannot put in current line, we could restore back to the position\r
-  // of last space character\r
-  // while we should also remmeber the glyph width of the last space character for restoring\r
-  //\r
-  UINTN LastSpaceIndex;\r
-  UINTN LastSpaceGlyphWidth;\r
-  //\r
-  // every time we begin to form a new screen-line, we should remember glyph width of single character\r
-  // of last line\r
-  //\r
-  UINTN LineStartGlyphWidth;\r
-  UINTN *IndexArray;\r
-  UINTN *OldIndexArray;\r
+  UINTN   Index;\r
+  CHAR16  *OutputString;\r
+  UINTN   TotalRowNum;\r
+  UINTN   CheckedNum;\r
 \r
-  BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
+  TotalRowNum = 0;\r
+  CheckedNum  = 0;\r
 \r
   //\r
-  // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r
-  // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r
-  // to bring the width directive of the last line to current screen-line.\r
-  // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line\r
-  // different from that of "\wideabcde", we should remember the width directive.\r
+  // Get row number of the String.\r
   //\r
-  AllocateSize  = 0x20;\r
-  IndexArray    = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
-  ASSERT (IndexArray != NULL);\r
-\r
-  if (*FormattedString != NULL) {\r
-    FreePool (*FormattedString);\r
-    *FormattedString = NULL;\r
+  for (Index = 0; GetLineByWidth (StringPtr, (UINTN) gHelpBlockWidth - 1, &Index, &OutputString) != 0x0000; ) {\r
+    TotalRowNum ++;\r
+    FreePool (OutputString);\r
   }\r
-\r
-  for (PrevCurrIndex = 0, CurrIndex  = 0, LineCount   = 0, LastSpaceIndex = 0,\r
-       IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;\r
-       (StringPtr[CurrIndex] != CHAR_NULL);\r
-       CurrIndex ++) {\r
-\r
-    if (LineCount == AllocateSize) {\r
-      AllocateSize += 0x10;\r
-      OldIndexArray  = IndexArray;\r
-      IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
-      ASSERT (IndexArray != NULL);\r
-\r
-      CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r
-      FreePool (OldIndexArray);\r
-    }\r
-    switch (StringPtr[CurrIndex]) {\r
-\r
-      case NARROW_CHAR:\r
-      case WIDE_CHAR:\r
-        GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);\r
-        if (CurrIndex == 0) {\r
-          LineStartGlyphWidth = GlyphWidth;\r
-        }\r
-        break;\r
-\r
-      //\r
-      // char is '\n'\r
-      // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN\r
-      //\r
-      case CHAR_LINEFEED:\r
-        //\r
-        // Store a range of string as a line\r
-        //\r
-        IndexArray[LineCount*3]   = PrevCurrIndex;\r
-        IndexArray[LineCount*3+1] = CurrIndex;\r
-        IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
-        LineCount ++;\r
-        //\r
-        // Reset offset and save begin position of line\r
-        //\r
-        GlyphOffset = 0;\r
-        LineStartGlyphWidth = GlyphWidth;\r
-        PrevCurrIndex = CurrIndex + 1;\r
-        break;\r
-\r
-      //\r
-      // char is '\r'\r
-      // "\r\n" and "\r" both are handled here\r
-      //\r
-      case CHAR_CARRIAGE_RETURN:\r
-        if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {\r
-          //\r
-          // next char is '\n'\r
-          //\r
-          IndexArray[LineCount*3]   = PrevCurrIndex;\r
-          IndexArray[LineCount*3+1] = CurrIndex;\r
-          IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
-          LineCount ++;\r
-          CurrIndex ++;\r
-        }\r
-        GlyphOffset = 0;\r
-        LineStartGlyphWidth = GlyphWidth;\r
-        PrevCurrIndex = CurrIndex + 1;\r
-        break;\r
-\r
-      //\r
-      // char is space or other char\r
-      //\r
-      default:\r
-        GlyphOffset     += GlyphWidth;\r
-        if (GlyphOffset >= BlockWidth) {\r
-          if (LastSpaceIndex > PrevCurrIndex) {\r
-            //\r
-            // LastSpaceIndex points to space inside current screen-line,\r
-            // restore to LastSpaceIndex\r
-            // (Otherwise the word is too long to fit one screen-line, just cut it)\r
-            //\r
-            CurrIndex  = LastSpaceIndex;\r
-            GlyphWidth = LastSpaceGlyphWidth;\r
-          } else if (GlyphOffset > BlockWidth) {\r
-            //\r
-            // the word is too long to fit one screen-line and we don't get the chance\r
-            // of GlyphOffset == BlockWidth because GlyphWidth = 2\r
-            //\r
-            CurrIndex --;\r
-          }\r
-\r
-          IndexArray[LineCount*3]   = PrevCurrIndex;\r
-          IndexArray[LineCount*3+1] = CurrIndex + 1;\r
-          IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
-          LineStartGlyphWidth = GlyphWidth;\r
-          LineCount ++;\r
-          //\r
-          // Reset offset and save begin position of line\r
-          //\r
-          GlyphOffset                 = 0;\r
-          PrevCurrIndex               = CurrIndex + 1;\r
-        }\r
-\r
-        //\r
-        // LastSpaceIndex: remember position of last space\r
-        //\r
-        if (StringPtr[CurrIndex] == CHAR_SPACE) {\r
-          LastSpaceIndex      = CurrIndex;\r
-          LastSpaceGlyphWidth = GlyphWidth;\r
-        }\r
-        break;\r
-    }\r
-  }\r
-\r
-  if (GlyphOffset > 0) {\r
-    IndexArray[LineCount*3]   = PrevCurrIndex;\r
-    IndexArray[LineCount*3+1] = CurrIndex;\r
-    IndexArray[LineCount*3+2] = GlyphWidth;\r
-    LineCount ++;\r
-  }\r
-\r
-  if (LineCount == 0) {\r
-    //\r
-    // in case we meet null string\r
-    //\r
-    IndexArray[0] = 0;\r
-    IndexArray[1] = 1;\r
-    //\r
-    // we assume null string's glyph width is 1\r
-    //\r
-    IndexArray[1] = 1;\r
-    LineCount ++;\r
-  }\r
-\r
-  VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r
-  *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r
+  \r
+  *FormattedString = AllocateZeroPool (TotalRowNum * gHelpBlockWidth * sizeof (CHAR16) * 2);\r
   ASSERT (*FormattedString != NULL);\r
 \r
-  for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r
-    *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16) ((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r
-    StrnCpy (\r
-      *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,\r
-      StringPtr + IndexArray[CurrIndex*3],\r
-      IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]\r
-      );\r
+  for (Index = 0; GetLineByWidth (StringPtr, (UINTN) gHelpBlockWidth - 1, &Index, &OutputString) != 0x0000; CheckedNum ++) {\r
+    CopyMem (*FormattedString + CheckedNum * gHelpBlockWidth * sizeof (CHAR16), OutputString, gHelpBlockWidth * sizeof (CHAR16));\r
+    FreePool (OutputString);\r
   }\r
 \r
-  FreePool (IndexArray);\r
+  ASSERT (CheckedNum == TotalRowNum);\r
 \r
-  return LineCount;\r
+  return TotalRowNum; \r
 }\r
index 82a82e5115f159829bbe8fdd385fc16fab56ece7..6999f625dba0a44bb43f2cd5002c30458ef7d4d1 100644 (file)
@@ -1308,6 +1308,7 @@ GetWidth (
 /**\r
   Will copy LineWidth amount of a string in the OutputString buffer and return the\r
   number of CHAR16 characters that were copied into the OutputString buffer.\r
+  In the code, it deals \r,\n,\r\n same as \n\r, also it not process the \r or \g.\r
 \r
   @param  InputString            String description for this option.\r
   @param  LineWidth              Width of the desired string to extract in CHAR16\r
@@ -1353,9 +1354,9 @@ GetLineByWidth (
    }\r
 \r
     //\r
-    // Fast-forward the string and see if there is a carriage-return in the string\r
+    // Fast-forward the string and see if there is a carriage-return or linefeed in the string\r
     //\r
-    for (; (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)\r
+    for (; (InputString[*Index + Count2] != CHAR_LINEFEED) && (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)\r
       ;\r
 \r
     //\r
@@ -1391,10 +1392,10 @@ GetLineByWidth (
     CopyMem (*OutputString, &InputString[*Index], LineWidth * 2);\r
 \r
     //\r
-    // If currently pointing to a space, increment the index to the first non-space character\r
+    // If currently pointing to a space or carriage-return or linefeed, increment the index to the first non-space character\r
     //\r
     for (;\r
-         (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN);\r
+         (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN)|| (InputString[*Index + LineWidth] == CHAR_LINEFEED);\r
          (*Index)++\r
         )\r
       ;\r
@@ -2923,7 +2924,7 @@ UiDisplayMenu (
       // Print the help string info.\r
       //\r
       if (!MultiHelpPage) {\r
-        for (Index = 0; Index < RowCount; Index++) {\r
+        for (Index = 0; Index < HelpLine; Index++) {\r
           PrintStringAt (\r
             LocalScreen.RightColumn - gHelpBlockWidth,\r
             Index + TopRow,\r