1 /****************************************************************************** 2 * 3 * Module Name: asconvrt - Source conversion code 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include "acpisrc.h" 153 154 AS_BRACE_INFO Gbl_BraceInfo[] = 155 { 156 {" if", 3}, 157 {" else if", 8}, 158 {" else while", 11}, 159 {" else", 5}, 160 {" do ", 4}, 161 {NULL, 0} 162 }; 163 164 165 /* Local prototypes */ 166 167 static char * 168 AsMatchValidToken ( 169 char *Buffer, 170 char *Filename, 171 char TargetChar, 172 AS_SCAN_CALLBACK Callback); 173 174 static char * 175 AsCheckBracesCallback ( 176 char *Buffer, 177 char *Filename, 178 UINT32 LineNumber); 179 180 static UINT32 181 AsCountLines ( 182 char *Buffer, 183 char *Filename); 184 185 186 /* Opening signature of the Intel legal header */ 187 188 char *HeaderBegin = "/******************************************************************************\n *\n * 1. Copyright Notice"; 189 190 UINT32 NonAnsiCommentCount; 191 192 193 /****************************************************************************** 194 * 195 * FUNCTION: AsCountNonAnsiComments 196 * 197 * DESCRIPTION: Count the number of "//" comments. This type of comment is 198 * non-ANSI C. 199 * 200 * NOTE: July 2014: Allows // within quoted strings and within normal 201 * comments. Eliminates extraneous warnings from this utility. 202 * 203 ******************************************************************************/ 204 205 void 206 AsCountNonAnsiComments ( 207 char *Buffer, 208 char *Filename) 209 { 210 211 AsMatchValidToken (Buffer, Filename, 0, NULL); 212 213 /* Error if any slash-slash comments found */ 214 215 if (NonAnsiCommentCount) 216 { 217 AsPrint ("Non-ANSI // Comments Found", NonAnsiCommentCount, Filename); 218 Gbl_NonAnsiComments += NonAnsiCommentCount; 219 } 220 } 221 222 223 /****************************************************************************** 224 * 225 * FUNCTION: AsCheckForBraces 226 * 227 * DESCRIPTION: Check for an open brace after each if/else/do (etc.) 228 * statement 229 * 230 ******************************************************************************/ 231 232 void 233 AsCheckForBraces ( 234 char *Buffer, 235 char *Filename) 236 { 237 238 AsMatchValidToken (Buffer, Filename, 0, AsCheckBracesCallback); 239 } 240 241 242 /****************************************************************************** 243 * 244 * FUNCTION: AsCheckBracesCallback 245 * 246 * DESCRIPTION: Check if/else/do statements. Ensure that braces 247 * are always used. 248 * 249 * TBD: Currently, don't check while() statements. The problem is that there 250 * are two forms: do {} while (); and while () {}. 251 * 252 ******************************************************************************/ 253 254 static char * 255 AsCheckBracesCallback ( 256 char *Buffer, 257 char *Filename, 258 UINT32 LineNumber) 259 { 260 char *SubBuffer = Buffer; 261 char *NextBrace; 262 char *NextSemicolon; 263 AS_BRACE_INFO *BraceInfo; 264 265 266 for (BraceInfo = Gbl_BraceInfo; BraceInfo->Operator; BraceInfo++) 267 { 268 if (!(strncmp (BraceInfo->Operator, SubBuffer, BraceInfo->Length))) 269 { 270 SubBuffer += (BraceInfo->Length - 1); 271 272 /* Find next brace and the next semicolon */ 273 274 NextBrace = AsMatchValidToken (SubBuffer, Filename, '{', NULL); 275 NextSemicolon = AsMatchValidToken (SubBuffer, Filename, ';', NULL); 276 277 /* Next brace should appear before next semicolon */ 278 279 if ((!NextBrace) || 280 (NextSemicolon && (NextBrace > NextSemicolon))) 281 { 282 Gbl_MissingBraces++; 283 284 if (!Gbl_QuietMode) 285 { 286 printf ("Missing braces for <%s>, line %u: %s\n", 287 BraceInfo->Operator + 1, LineNumber, Filename); 288 } 289 } 290 291 return (SubBuffer); 292 } 293 } 294 295 /* No match, just return original buffer */ 296 297 return (Buffer); 298 } 299 300 301 /****************************************************************************** 302 * 303 * FUNCTION: AsMatchValidToken 304 * 305 * DESCRIPTION: Find the next matching token in the input buffer. 306 * 307 ******************************************************************************/ 308 309 static char * 310 AsMatchValidToken ( 311 char *Buffer, 312 char *Filename, 313 char TargetChar, 314 AS_SCAN_CALLBACK Callback) 315 { 316 char *SubBuffer = Buffer; 317 char *StringStart; 318 UINT32 TotalLines; 319 320 321 TotalLines = 1; 322 NonAnsiCommentCount = 0; 323 324 /* Scan from current position up to the end if necessary */ 325 326 while (*SubBuffer) 327 { 328 /* Skip normal comments */ 329 330 if ((*SubBuffer == '/') && 331 (*(SubBuffer + 1) == '*')) 332 { 333 /* Must maintain line count */ 334 335 SubBuffer += 2; 336 while (strncmp ("*/", SubBuffer, 2)) 337 { 338 if (*SubBuffer == '\n') 339 { 340 TotalLines++; 341 } 342 SubBuffer++; 343 } 344 345 SubBuffer += 2; 346 continue; 347 } 348 349 /* Skip single quoted chars */ 350 351 if (*SubBuffer == '\'') 352 { 353 SubBuffer++; 354 if (!(*SubBuffer)) 355 { 356 break; 357 } 358 359 if (*SubBuffer == '\\') 360 { 361 SubBuffer++; 362 } 363 364 SubBuffer++; 365 continue; 366 } 367 368 /* Skip quoted strings */ 369 370 if (*SubBuffer == '"') 371 { 372 StringStart = SubBuffer; 373 SubBuffer++; 374 if (!(*SubBuffer)) 375 { 376 break; 377 } 378 379 while (*SubBuffer != '"') 380 { 381 if ((*SubBuffer == '\n') || 382 (!(*SubBuffer))) 383 { 384 AsPrint ("Unbalanced quoted string",1, Filename); 385 printf (" %.32s (line %u)\n", StringStart, TotalLines); 386 break; 387 } 388 389 /* Handle escapes within the string */ 390 391 if (*SubBuffer == '\\') 392 { 393 SubBuffer++; 394 } 395 396 SubBuffer++; 397 } 398 399 SubBuffer++; 400 continue; 401 } 402 403 /* Now we can check for a slash-slash comment */ 404 405 if ((*SubBuffer == '/') && 406 (*(SubBuffer + 1) == '/')) 407 { 408 NonAnsiCommentCount++; 409 410 /* Skip to end-of-line */ 411 412 while ((*SubBuffer != '\n') && 413 (*SubBuffer)) 414 { 415 SubBuffer++; 416 } 417 418 if (!(*SubBuffer)) 419 { 420 break; 421 } 422 423 if (*SubBuffer == '\n') 424 { 425 TotalLines++; 426 } 427 428 SubBuffer++; 429 continue; 430 } 431 432 /* Finally, check for a newline */ 433 434 if (*SubBuffer == '\n') 435 { 436 TotalLines++; 437 SubBuffer++; 438 continue; 439 } 440 441 /* Normal character, do the user actions */ 442 443 if (Callback) 444 { 445 SubBuffer = Callback (SubBuffer, Filename, TotalLines); 446 } 447 448 if (TargetChar && (*SubBuffer == TargetChar)) 449 { 450 return (SubBuffer); 451 } 452 453 SubBuffer++; 454 } 455 456 return (NULL); 457 } 458 459 460 /****************************************************************************** 461 * 462 * FUNCTION: AsRemoveExtraLines 463 * 464 * DESCRIPTION: Remove all extra lines at the start and end of the file. 465 * 466 ******************************************************************************/ 467 468 void 469 AsRemoveExtraLines ( 470 char *FileBuffer, 471 char *Filename) 472 { 473 char *FileEnd; 474 int Length; 475 476 477 /* Remove any extra lines at the start of the file */ 478 479 while (*FileBuffer == '\n') 480 { 481 printf ("Removing extra line at start of file: %s\n", Filename); 482 AsRemoveData (FileBuffer, FileBuffer + 1); 483 } 484 485 /* Remove any extra lines at the end of the file */ 486 487 Length = strlen (FileBuffer); 488 FileEnd = FileBuffer + (Length - 2); 489 490 while (*FileEnd == '\n') 491 { 492 printf ("Removing extra line at end of file: %s\n", Filename); 493 AsRemoveData (FileEnd, FileEnd + 1); 494 FileEnd--; 495 } 496 } 497 498 499 /****************************************************************************** 500 * 501 * FUNCTION: AsRemoveSpacesAfterPeriod 502 * 503 * DESCRIPTION: Remove an extra space after a period. 504 * 505 ******************************************************************************/ 506 507 void 508 AsRemoveSpacesAfterPeriod ( 509 char *FileBuffer, 510 char *Filename) 511 { 512 int ReplaceCount = 0; 513 char *Possible; 514 515 516 Possible = FileBuffer; 517 while (Possible) 518 { 519 Possible = strstr (Possible, ". "); 520 if (Possible) 521 { 522 if ((*(Possible -1) == '.') || 523 (*(Possible -1) == '\"') || 524 (*(Possible -1) == '\n')) 525 { 526 Possible += 3; 527 continue; 528 } 529 530 Possible = AsReplaceData (Possible, 3, ". ", 2); 531 ReplaceCount++; 532 } 533 } 534 535 if (ReplaceCount) 536 { 537 printf ("Removed %d extra blanks after a period: %s\n", 538 ReplaceCount, Filename); 539 } 540 } 541 542 543 /****************************************************************************** 544 * 545 * FUNCTION: AsMatchExactWord 546 * 547 * DESCRIPTION: Check previous and next characters for whitespace 548 * 549 ******************************************************************************/ 550 551 BOOLEAN 552 AsMatchExactWord ( 553 char *Word, 554 UINT32 WordLength) 555 { 556 char NextChar; 557 char PrevChar; 558 559 560 NextChar = Word[WordLength]; 561 PrevChar = * (Word -1); 562 563 if (isalnum ((int) NextChar) || 564 (NextChar == '_') || 565 isalnum ((int) PrevChar) || 566 (PrevChar == '_')) 567 { 568 return (FALSE); 569 } 570 571 return (TRUE); 572 } 573 574 575 /****************************************************************************** 576 * 577 * FUNCTION: AsPrint 578 * 579 * DESCRIPTION: Common formatted print 580 * 581 ******************************************************************************/ 582 583 void 584 AsPrint ( 585 char *Message, 586 UINT32 Count, 587 char *Filename) 588 { 589 590 if (Gbl_QuietMode) 591 { 592 return; 593 } 594 595 printf ("-- %4u %28.28s : %s\n", Count, Message, Filename); 596 } 597 598 599 /****************************************************************************** 600 * 601 * FUNCTION: AsTrimLines 602 * 603 * DESCRIPTION: Remove extra blanks from the end of source lines. Does not 604 * check for tabs. 605 * 606 ******************************************************************************/ 607 608 void 609 AsTrimLines ( 610 char *Buffer, 611 char *Filename) 612 { 613 char *SubBuffer = Buffer; 614 char *StartWhiteSpace = NULL; 615 UINT32 SpaceCount = 0; 616 617 618 while (*SubBuffer) 619 { 620 while (*SubBuffer != '\n') 621 { 622 if (!*SubBuffer) 623 { 624 goto Exit; 625 } 626 627 if (*SubBuffer == ' ') 628 { 629 if (!StartWhiteSpace) 630 { 631 StartWhiteSpace = SubBuffer; 632 } 633 } 634 else 635 { 636 StartWhiteSpace = NULL; 637 } 638 639 SubBuffer++; 640 } 641 642 if (StartWhiteSpace) 643 { 644 SpaceCount += (SubBuffer - StartWhiteSpace); 645 646 /* Remove the spaces */ 647 648 SubBuffer = AsRemoveData (StartWhiteSpace, SubBuffer); 649 StartWhiteSpace = NULL; 650 } 651 652 SubBuffer++; 653 } 654 655 656 Exit: 657 if (SpaceCount) 658 { 659 Gbl_MadeChanges = TRUE; 660 AsPrint ("Extraneous spaces removed", SpaceCount, Filename); 661 } 662 } 663 664 665 /****************************************************************************** 666 * 667 * FUNCTION: AsTrimWhitespace 668 * 669 * DESCRIPTION: Remove "excess" blank lines - any more than 2 blank lines. 670 * this can happen during the translation when lines are removed. 671 * 672 ******************************************************************************/ 673 674 void 675 AsTrimWhitespace ( 676 char *Buffer) 677 { 678 char *SubBuffer; 679 int ReplaceCount = 1; 680 681 682 while (ReplaceCount) 683 { 684 ReplaceCount = AsReplaceString ("\n\n\n\n", "\n\n\n", 685 REPLACE_SUBSTRINGS, Buffer); 686 } 687 688 /* 689 * Check for exactly one blank line after the copyright header 690 */ 691 692 /* Find the header */ 693 694 SubBuffer = strstr (Buffer, HeaderBegin); 695 if (!SubBuffer) 696 { 697 return; 698 } 699 700 /* Find the end of the header */ 701 702 SubBuffer = strstr (SubBuffer, "*/"); 703 SubBuffer = AsSkipPastChar (SubBuffer, '\n'); 704 705 /* Replace a double blank line with a single */ 706 707 if (!strncmp (SubBuffer, "\n\n", 2)) 708 { 709 AsReplaceData (SubBuffer, 2, "\n", 1); 710 AcpiOsPrintf ("Found multiple blank lines after copyright\n"); 711 } 712 713 /* If no blank line after header, insert one */ 714 715 else if (*SubBuffer != '\n') 716 { 717 AsInsertData (SubBuffer, "\n", 1); 718 AcpiOsPrintf ("Inserted blank line after copyright\n"); 719 } 720 } 721 722 723 /****************************************************************************** 724 * 725 * FUNCTION: AsReplaceHeader 726 * 727 * DESCRIPTION: Replace the default Intel legal header with a new header 728 * 729 ******************************************************************************/ 730 731 void 732 AsReplaceHeader ( 733 char *Buffer, 734 char *NewHeader) 735 { 736 char *SubBuffer; 737 char *TokenEnd; 738 739 740 /* Find the original header */ 741 742 SubBuffer = strstr (Buffer, HeaderBegin); 743 if (!SubBuffer) 744 { 745 return; 746 } 747 748 /* Find the end of the original header */ 749 750 TokenEnd = strstr (SubBuffer, "*/"); 751 TokenEnd = AsSkipPastChar (TokenEnd, '\n'); 752 753 /* Delete old header, insert new one */ 754 755 AsReplaceData (SubBuffer, TokenEnd - SubBuffer, 756 NewHeader, strlen (NewHeader)); 757 } 758 759 760 /****************************************************************************** 761 * 762 * FUNCTION: AsReplaceString 763 * 764 * DESCRIPTION: Replace all instances of a target string with a replacement 765 * string. Returns count of the strings replaced. 766 * 767 ******************************************************************************/ 768 769 int 770 AsReplaceString ( 771 char *Target, 772 char *Replacement, 773 UINT8 Type, 774 char *Buffer) 775 { 776 char *SubString1; 777 char *SubString2; 778 char *SubBuffer; 779 int TargetLength; 780 int ReplacementLength; 781 int ReplaceCount = 0; 782 783 784 TargetLength = strlen (Target); 785 ReplacementLength = strlen (Replacement); 786 787 SubBuffer = Buffer; 788 SubString1 = Buffer; 789 790 while (SubString1) 791 { 792 /* Find the target string */ 793 794 SubString1 = strstr (SubBuffer, Target); 795 if (!SubString1) 796 { 797 return (ReplaceCount); 798 } 799 800 /* 801 * Check for translation escape string -- means to ignore 802 * blocks of code while replacing 803 */ 804 if (Gbl_IgnoreTranslationEscapes) 805 { 806 SubString2 = NULL; 807 } 808 else 809 { 810 SubString2 = strstr (SubBuffer, AS_START_IGNORE); 811 } 812 813 if ((SubString2) && 814 (SubString2 < SubString1)) 815 { 816 /* Find end of the escape block starting at "Substring2" */ 817 818 SubString2 = strstr (SubString2, AS_STOP_IGNORE); 819 if (!SubString2) 820 { 821 /* Didn't find terminator */ 822 823 return (ReplaceCount); 824 } 825 826 /* Move buffer to end of escape block and continue */ 827 828 SubBuffer = SubString2; 829 } 830 831 /* Do the actual replace if the target was found */ 832 833 else 834 { 835 if ((Type & REPLACE_MASK) == REPLACE_WHOLE_WORD) 836 { 837 if (!AsMatchExactWord (SubString1, TargetLength)) 838 { 839 SubBuffer = SubString1 + 1; 840 continue; 841 } 842 } 843 844 SubBuffer = AsReplaceData (SubString1, TargetLength, 845 Replacement, ReplacementLength); 846 847 if ((Type & EXTRA_INDENT_C) && 848 (!Gbl_StructDefs)) 849 { 850 SubBuffer = AsInsertData (SubBuffer, " ", 8); 851 } 852 853 ReplaceCount++; 854 } 855 } 856 857 return (ReplaceCount); 858 } 859 860 861 /****************************************************************************** 862 * 863 * FUNCTION: AsConvertToLineFeeds 864 * 865 * DESCRIPTION: Convert all CR/LF pairs to LF only. 866 * 867 ******************************************************************************/ 868 869 void 870 AsConvertToLineFeeds ( 871 char *Buffer) 872 { 873 char *SubString; 874 char *SubBuffer; 875 876 877 SubBuffer = Buffer; 878 SubString = Buffer; 879 880 while (SubString) 881 { 882 /* Find the target string */ 883 884 SubString = strstr (SubBuffer, "\r\n"); 885 if (!SubString) 886 { 887 return; 888 } 889 890 SubBuffer = AsReplaceData (SubString, 1, NULL, 0); 891 } 892 } 893 894 895 /****************************************************************************** 896 * 897 * FUNCTION: AsInsertCarriageReturns 898 * 899 * DESCRIPTION: Convert lone LFs to CR/LF pairs. 900 * 901 ******************************************************************************/ 902 903 void 904 AsInsertCarriageReturns ( 905 char *Buffer) 906 { 907 char *SubString; 908 char *SubBuffer; 909 910 911 SubBuffer = Buffer; 912 SubString = Buffer; 913 914 while (SubString) 915 { 916 /* Find the target string */ 917 918 SubString = strstr (SubBuffer, "\n"); 919 if (!SubString) 920 { 921 return; 922 } 923 924 SubBuffer = AsInsertData (SubString, "\r", 1); 925 SubBuffer += 1; 926 } 927 } 928 929 930 /****************************************************************************** 931 * 932 * FUNCTION: AsBracesOnSameLine 933 * 934 * DESCRIPTION: Move opening braces up to the same line as an if, for, else, 935 * or while statement (leave function opening brace on separate 936 * line). 937 * 938 ******************************************************************************/ 939 940 void 941 AsBracesOnSameLine ( 942 char *Buffer) 943 { 944 char *SubBuffer = Buffer; 945 char *Beginning; 946 char *StartOfThisLine; 947 char *Next; 948 BOOLEAN BlockBegin = TRUE; 949 950 951 while (*SubBuffer) 952 { 953 /* Ignore comments */ 954 955 if ((SubBuffer[0] == '/') && 956 (SubBuffer[1] == '*')) 957 { 958 SubBuffer = strstr (SubBuffer, "*/"); 959 if (!SubBuffer) 960 { 961 return; 962 } 963 964 SubBuffer += 2; 965 continue; 966 } 967 968 /* Ignore quoted strings */ 969 970 if (*SubBuffer == '\"') 971 { 972 SubBuffer++; 973 SubBuffer = AsSkipPastChar (SubBuffer, '\"'); 974 if (!SubBuffer) 975 { 976 return; 977 } 978 } 979 980 if (!strncmp ("\n}", SubBuffer, 2)) 981 { 982 /* 983 * A newline followed by a closing brace closes a function 984 * or struct or initializer block 985 */ 986 BlockBegin = TRUE; 987 } 988 989 /* 990 * Move every standalone brace up to the previous line 991 * Check for digit will ignore initializer lists surrounded by braces. 992 * This will work until we we need more complex detection. 993 */ 994 if ((*SubBuffer == '{') && !isdigit ((int) SubBuffer[1])) 995 { 996 if (BlockBegin) 997 { 998 BlockBegin = FALSE; 999 } 1000 else 1001 { 1002 /* 1003 * Backup to previous non-whitespace 1004 */ 1005 Beginning = SubBuffer - 1; 1006 while ((*Beginning == ' ') || 1007 (*Beginning == '\n')) 1008 { 1009 Beginning--; 1010 } 1011 1012 StartOfThisLine = Beginning; 1013 while (*StartOfThisLine != '\n') 1014 { 1015 StartOfThisLine--; 1016 } 1017 1018 /* 1019 * Move the brace up to the previous line, UNLESS: 1020 * 1021 * 1) There is a conditional compile on the line (starts with '#') 1022 * 2) Previous line ends with an '=' (Start of initializer block) 1023 * 3) Previous line ends with a comma (part of an init list) 1024 * 4) Previous line ends with a backslash (part of a macro) 1025 */ 1026 if ((StartOfThisLine[1] != '#') && 1027 (*Beginning != '\\') && 1028 (*Beginning != '/') && 1029 (*Beginning != '{') && 1030 (*Beginning != '=') && 1031 (*Beginning != ',')) 1032 { 1033 Beginning++; 1034 SubBuffer++; 1035 1036 Gbl_MadeChanges = TRUE; 1037 1038 #ifdef ADD_EXTRA_WHITESPACE 1039 AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3); 1040 #else 1041 /* Find non-whitespace start of next line */ 1042 1043 Next = SubBuffer + 1; 1044 while ((*Next == ' ') || 1045 (*Next == '\t')) 1046 { 1047 Next++; 1048 } 1049 1050 /* Find non-whitespace start of this line */ 1051 1052 StartOfThisLine++; 1053 while ((*StartOfThisLine == ' ') || 1054 (*StartOfThisLine == '\t')) 1055 { 1056 StartOfThisLine++; 1057 } 1058 1059 /* 1060 * Must be a single-line comment to need more whitespace 1061 * Even then, we don't need more if the previous statement 1062 * is an "else". 1063 */ 1064 if ((Next[0] == '/') && 1065 (Next[1] == '*') && 1066 (Next[2] != '\n') && 1067 1068 (!strncmp (StartOfThisLine, "else if", 7) || 1069 !strncmp (StartOfThisLine, "else while", 10) || 1070 strncmp (StartOfThisLine, "else", 4))) 1071 { 1072 AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3); 1073 } 1074 else 1075 { 1076 AsReplaceData (Beginning, SubBuffer - Beginning, " {", 2); 1077 } 1078 #endif 1079 } 1080 } 1081 } 1082 1083 SubBuffer++; 1084 } 1085 } 1086 1087 1088 /****************************************************************************** 1089 * 1090 * FUNCTION: AsTabify4 1091 * 1092 * DESCRIPTION: Convert the text to tabbed text. Alignment of text is 1093 * preserved. 1094 * 1095 ******************************************************************************/ 1096 1097 void 1098 AsTabify4 ( 1099 char *Buffer) 1100 { 1101 char *SubBuffer = Buffer; 1102 char *NewSubBuffer; 1103 UINT32 SpaceCount = 0; 1104 UINT32 Column = 0; 1105 1106 1107 while (*SubBuffer) 1108 { 1109 if (*SubBuffer == '\n') 1110 { 1111 Column = 0; 1112 } 1113 else 1114 { 1115 Column++; 1116 } 1117 1118 /* Ignore comments */ 1119 1120 if ((SubBuffer[0] == '/') && 1121 (SubBuffer[1] == '*')) 1122 { 1123 SubBuffer = strstr (SubBuffer, "*/"); 1124 if (!SubBuffer) 1125 { 1126 return; 1127 } 1128 1129 SubBuffer += 2; 1130 continue; 1131 } 1132 1133 /* Ignore quoted strings */ 1134 1135 if (*SubBuffer == '\"') 1136 { 1137 SubBuffer++; 1138 SubBuffer = AsSkipPastChar (SubBuffer, '\"'); 1139 if (!SubBuffer) 1140 { 1141 return; 1142 } 1143 SpaceCount = 0; 1144 } 1145 1146 if (*SubBuffer == ' ') 1147 { 1148 SpaceCount++; 1149 1150 if (SpaceCount >= 4) 1151 { 1152 SpaceCount = 0; 1153 1154 NewSubBuffer = (SubBuffer + 1) - 4; 1155 *NewSubBuffer = '\t'; 1156 NewSubBuffer++; 1157 1158 /* Remove the spaces */ 1159 1160 SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer + 1); 1161 } 1162 1163 if ((Column % 4) == 0) 1164 { 1165 SpaceCount = 0; 1166 } 1167 } 1168 else 1169 { 1170 SpaceCount = 0; 1171 } 1172 1173 SubBuffer++; 1174 } 1175 } 1176 1177 1178 /****************************************************************************** 1179 * 1180 * FUNCTION: AsTabify8 1181 * 1182 * DESCRIPTION: Convert the text to tabbed text. Alignment of text is 1183 * preserved. 1184 * 1185 ******************************************************************************/ 1186 1187 void 1188 AsTabify8 ( 1189 char *Buffer) 1190 { 1191 char *SubBuffer = Buffer; 1192 char *NewSubBuffer; 1193 char *CommentEnd = NULL; 1194 UINT32 SpaceCount = 0; 1195 UINT32 Column = 0; 1196 UINT32 TabCount = 0; 1197 UINT32 LastLineTabCount = 0; 1198 UINT32 LastLineColumnStart = 0; 1199 UINT32 ThisColumnStart = 0; 1200 UINT32 ThisTabCount = 0; 1201 char *FirstNonBlank = NULL; 1202 1203 1204 while (*SubBuffer) 1205 { 1206 if (*SubBuffer == '\n') 1207 { 1208 /* This is a standalone blank line */ 1209 1210 FirstNonBlank = NULL; 1211 Column = 0; 1212 SpaceCount = 0; 1213 TabCount = 0; 1214 SubBuffer++; 1215 continue; 1216 } 1217 1218 if (!FirstNonBlank) 1219 { 1220 /* Find the first non-blank character on this line */ 1221 1222 FirstNonBlank = SubBuffer; 1223 while (*FirstNonBlank == ' ') 1224 { 1225 FirstNonBlank++; 1226 } 1227 1228 /* 1229 * This mechanism limits the difference in tab counts from 1230 * line to line. It helps avoid the situation where a second 1231 * continuation line (which was indented correctly for tabs=4) would 1232 * get indented off the screen if we just blindly converted to tabs. 1233 */ 1234 ThisColumnStart = FirstNonBlank - SubBuffer; 1235 1236 if (LastLineTabCount == 0) 1237 { 1238 ThisTabCount = 0; 1239 } 1240 else if (ThisColumnStart == LastLineColumnStart) 1241 { 1242 ThisTabCount = LastLineTabCount -1; 1243 } 1244 else 1245 { 1246 ThisTabCount = LastLineTabCount + 1; 1247 } 1248 } 1249 1250 Column++; 1251 1252 /* Check if we are in a comment */ 1253 1254 if ((SubBuffer[0] == '*') && 1255 (SubBuffer[1] == '/')) 1256 { 1257 SpaceCount = 0; 1258 SubBuffer += 2; 1259 1260 if (*SubBuffer == '\n') 1261 { 1262 if (TabCount > 0) 1263 { 1264 LastLineTabCount = TabCount; 1265 TabCount = 0; 1266 } 1267 1268 FirstNonBlank = NULL; 1269 LastLineColumnStart = ThisColumnStart; 1270 SubBuffer++; 1271 } 1272 1273 continue; 1274 } 1275 1276 /* Check for comment open */ 1277 1278 if ((SubBuffer[0] == '/') && 1279 (SubBuffer[1] == '*')) 1280 { 1281 /* Find the end of the comment, it must exist */ 1282 1283 CommentEnd = strstr (SubBuffer, "*/"); 1284 if (!CommentEnd) 1285 { 1286 return; 1287 } 1288 1289 /* Toss the rest of this line or single-line comment */ 1290 1291 while ((SubBuffer < CommentEnd) && 1292 (*SubBuffer != '\n')) 1293 { 1294 SubBuffer++; 1295 } 1296 1297 if (*SubBuffer == '\n') 1298 { 1299 if (TabCount > 0) 1300 { 1301 LastLineTabCount = TabCount; 1302 TabCount = 0; 1303 } 1304 1305 FirstNonBlank = NULL; 1306 LastLineColumnStart = ThisColumnStart; 1307 } 1308 1309 SpaceCount = 0; 1310 continue; 1311 } 1312 1313 /* Ignore quoted strings */ 1314 1315 if ((!CommentEnd) && (*SubBuffer == '\"')) 1316 { 1317 SubBuffer++; 1318 SubBuffer = AsSkipPastChar (SubBuffer, '\"'); 1319 if (!SubBuffer) 1320 { 1321 return; 1322 } 1323 1324 SpaceCount = 0; 1325 } 1326 1327 if (*SubBuffer != ' ') 1328 { 1329 /* Not a space, skip to end of line */ 1330 1331 SubBuffer = AsSkipUntilChar (SubBuffer, '\n'); 1332 if (!SubBuffer) 1333 { 1334 return; 1335 } 1336 if (TabCount > 0) 1337 { 1338 LastLineTabCount = TabCount; 1339 TabCount = 0; 1340 } 1341 1342 FirstNonBlank = NULL; 1343 LastLineColumnStart = ThisColumnStart; 1344 Column = 0; 1345 SpaceCount = 0; 1346 } 1347 else 1348 { 1349 /* Another space */ 1350 1351 SpaceCount++; 1352 1353 if (SpaceCount >= 4) 1354 { 1355 /* Replace this group of spaces with a tab character */ 1356 1357 SpaceCount = 0; 1358 1359 NewSubBuffer = SubBuffer - 3; 1360 1361 if (TabCount <= ThisTabCount ? (ThisTabCount +1) : 0) 1362 { 1363 *NewSubBuffer = '\t'; 1364 NewSubBuffer++; 1365 SubBuffer++; 1366 TabCount++; 1367 } 1368 1369 /* Remove the spaces */ 1370 1371 SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer); 1372 continue; 1373 } 1374 } 1375 1376 SubBuffer++; 1377 } 1378 } 1379 1380 1381 /****************************************************************************** 1382 * 1383 * FUNCTION: AsCountLines 1384 * 1385 * DESCRIPTION: Count the number of lines in the input buffer. Also count 1386 * the number of long lines (lines longer than 80 chars). 1387 * 1388 ******************************************************************************/ 1389 1390 static UINT32 1391 AsCountLines ( 1392 char *Buffer, 1393 char *Filename) 1394 { 1395 char *SubBuffer = Buffer; 1396 char *EndOfLine; 1397 UINT32 LineCount = 0; 1398 UINT32 LongLineCount = 0; 1399 1400 1401 while (*SubBuffer) 1402 { 1403 EndOfLine = AsSkipUntilChar (SubBuffer, '\n'); 1404 if (!EndOfLine) 1405 { 1406 Gbl_TotalLines += LineCount; 1407 return (LineCount); 1408 } 1409 1410 if ((EndOfLine - SubBuffer) > 80) 1411 { 1412 LongLineCount++; 1413 VERBOSE_PRINT (("long: %.80s\n", SubBuffer)); 1414 } 1415 1416 LineCount++; 1417 SubBuffer = EndOfLine + 1; 1418 } 1419 1420 if (LongLineCount) 1421 { 1422 VERBOSE_PRINT (("%u Lines longer than 80 found in %s\n", 1423 LongLineCount, Filename)); 1424 1425 Gbl_LongLines += LongLineCount; 1426 } 1427 1428 Gbl_TotalLines += LineCount; 1429 return (LineCount); 1430 } 1431 1432 1433 /****************************************************************************** 1434 * 1435 * FUNCTION: AsCountTabs 1436 * 1437 * DESCRIPTION: Simply count the number of tabs in the input file buffer 1438 * 1439 ******************************************************************************/ 1440 1441 void 1442 AsCountTabs ( 1443 char *Buffer, 1444 char *Filename) 1445 { 1446 UINT32 i; 1447 UINT32 TabCount = 0; 1448 1449 1450 for (i = 0; Buffer[i]; i++) 1451 { 1452 if (Buffer[i] == '\t') 1453 { 1454 TabCount++; 1455 } 1456 } 1457 1458 if (TabCount) 1459 { 1460 AsPrint ("Tabs found", TabCount, Filename); 1461 Gbl_Tabs += TabCount; 1462 } 1463 1464 AsCountLines (Buffer, Filename); 1465 } 1466 1467 1468 /****************************************************************************** 1469 * 1470 * FUNCTION: AsCountSourceLines 1471 * 1472 * DESCRIPTION: Count the number of C source lines. Defined by 1) not a 1473 * comment, and 2) not a blank line. 1474 * 1475 ******************************************************************************/ 1476 1477 void 1478 AsCountSourceLines ( 1479 char *Buffer, 1480 char *Filename) 1481 { 1482 char *SubBuffer = Buffer; 1483 UINT32 LineCount = 0; 1484 UINT32 WhiteCount = 0; 1485 UINT32 CommentCount = 0; 1486 1487 1488 while (*SubBuffer) 1489 { 1490 /* Detect comments (// comments are not used, non-ansii) */ 1491 1492 if ((SubBuffer[0] == '/') && 1493 (SubBuffer[1] == '*')) 1494 { 1495 SubBuffer += 2; 1496 1497 /* First line of multi-line comment is often just whitespace */ 1498 1499 if (SubBuffer[0] == '\n') 1500 { 1501 WhiteCount++; 1502 SubBuffer++; 1503 } 1504 else 1505 { 1506 CommentCount++; 1507 } 1508 1509 /* Find end of comment */ 1510 1511 while (SubBuffer[0] && SubBuffer[1] && 1512 !(((SubBuffer[0] == '*') && 1513 (SubBuffer[1] == '/')))) 1514 { 1515 if (SubBuffer[0] == '\n') 1516 { 1517 CommentCount++; 1518 } 1519 1520 SubBuffer++; 1521 } 1522 } 1523 1524 /* A linefeed followed by a non-linefeed is a valid source line */ 1525 1526 else if ((SubBuffer[0] == '\n') && 1527 (SubBuffer[1] != '\n')) 1528 { 1529 LineCount++; 1530 } 1531 1532 /* Two back-to-back linefeeds indicate a whitespace line */ 1533 1534 else if ((SubBuffer[0] == '\n') && 1535 (SubBuffer[1] == '\n')) 1536 { 1537 WhiteCount++; 1538 } 1539 1540 SubBuffer++; 1541 } 1542 1543 /* Adjust comment count for legal header */ 1544 1545 if (Gbl_HeaderSize < CommentCount) 1546 { 1547 CommentCount -= Gbl_HeaderSize; 1548 Gbl_HeaderLines += Gbl_HeaderSize; 1549 } 1550 1551 Gbl_SourceLines += LineCount; 1552 Gbl_WhiteLines += WhiteCount; 1553 Gbl_CommentLines += CommentCount; 1554 1555 VERBOSE_PRINT (("%u Comment %u White %u Code %u Lines in %s\n", 1556 CommentCount, WhiteCount, LineCount, 1557 LineCount + WhiteCount + CommentCount, Filename)); 1558 } 1559 1560 1561 /****************************************************************************** 1562 * 1563 * FUNCTION: AsInsertPrefix 1564 * 1565 * DESCRIPTION: Insert struct or union prefixes 1566 * 1567 ******************************************************************************/ 1568 1569 void 1570 AsInsertPrefix ( 1571 char *Buffer, 1572 char *Keyword, 1573 UINT8 Type) 1574 { 1575 char *SubString; 1576 char *SubBuffer; 1577 char *EndKeyword; 1578 int InsertLength; 1579 char *InsertString; 1580 int TrailingSpaces; 1581 char LowerKeyword[128]; 1582 int KeywordLength; 1583 1584 1585 switch (Type) 1586 { 1587 case SRC_TYPE_STRUCT: 1588 1589 InsertString = "struct "; 1590 break; 1591 1592 case SRC_TYPE_UNION: 1593 1594 InsertString = "union "; 1595 break; 1596 1597 default: 1598 1599 return; 1600 } 1601 1602 strcpy (LowerKeyword, Keyword); 1603 AcpiUtStrlwr (LowerKeyword); 1604 1605 SubBuffer = Buffer; 1606 SubString = Buffer; 1607 InsertLength = strlen (InsertString); 1608 KeywordLength = strlen (Keyword); 1609 1610 1611 while (SubString) 1612 { 1613 /* Find an instance of the keyword */ 1614 1615 SubString = strstr (SubBuffer, LowerKeyword); 1616 if (!SubString) 1617 { 1618 return; 1619 } 1620 1621 SubBuffer = SubString; 1622 1623 /* Must be standalone word, not a substring */ 1624 1625 if (AsMatchExactWord (SubString, KeywordLength)) 1626 { 1627 /* Make sure the keyword isn't already prefixed with the insert */ 1628 1629 if (!strncmp (SubString - InsertLength, InsertString, InsertLength)) 1630 { 1631 /* Add spaces if not already at the end-of-line */ 1632 1633 if (*(SubBuffer + KeywordLength) != '\n') 1634 { 1635 /* Already present, add spaces after to align structure members */ 1636 1637 #if 0 1638 /* ONLY FOR C FILES */ 1639 AsInsertData (SubBuffer + KeywordLength, " ", 8); 1640 #endif 1641 } 1642 goto Next; 1643 } 1644 1645 /* Make sure the keyword isn't at the end of a struct/union */ 1646 /* Note: This code depends on a single space after the brace */ 1647 1648 if (*(SubString - 2) == '}') 1649 { 1650 goto Next; 1651 } 1652 1653 /* Prefix the keyword with the insert string */ 1654 1655 Gbl_MadeChanges = TRUE; 1656 1657 /* Is there room for insertion */ 1658 1659 EndKeyword = SubString + strlen (LowerKeyword); 1660 1661 TrailingSpaces = 0; 1662 while (EndKeyword[TrailingSpaces] == ' ') 1663 { 1664 TrailingSpaces++; 1665 } 1666 1667 /* 1668 * Use "if (TrailingSpaces > 1)" if we want to ignore casts 1669 */ 1670 SubBuffer = SubString + InsertLength; 1671 1672 if (TrailingSpaces > InsertLength) 1673 { 1674 /* Insert the keyword */ 1675 1676 memmove (SubBuffer, SubString, KeywordLength); 1677 1678 /* Insert the keyword */ 1679 1680 memmove (SubString, InsertString, InsertLength); 1681 } 1682 else 1683 { 1684 AsInsertData (SubString, InsertString, InsertLength); 1685 } 1686 } 1687 1688 Next: 1689 SubBuffer += KeywordLength; 1690 } 1691 } 1692 1693 #ifdef ACPI_FUTURE_IMPLEMENTATION 1694 /****************************************************************************** 1695 * 1696 * FUNCTION: AsTrimComments 1697 * 1698 * DESCRIPTION: Finds 3-line comments with only a single line of text 1699 * 1700 ******************************************************************************/ 1701 1702 void 1703 AsTrimComments ( 1704 char *Buffer, 1705 char *Filename) 1706 { 1707 char *SubBuffer = Buffer; 1708 char *Ptr1; 1709 char *Ptr2; 1710 UINT32 LineCount; 1711 UINT32 ShortCommentCount = 0; 1712 1713 1714 while (1) 1715 { 1716 /* Find comment open, within procedure level */ 1717 1718 SubBuffer = strstr (SubBuffer, " /*"); 1719 if (!SubBuffer) 1720 { 1721 goto Exit; 1722 } 1723 1724 /* Find comment terminator */ 1725 1726 Ptr1 = strstr (SubBuffer, "*/"); 1727 if (!Ptr1) 1728 { 1729 goto Exit; 1730 } 1731 1732 /* Find next EOL (from original buffer) */ 1733 1734 Ptr2 = strstr (SubBuffer, "\n"); 1735 if (!Ptr2) 1736 { 1737 goto Exit; 1738 } 1739 1740 /* Ignore one-line comments */ 1741 1742 if (Ptr1 < Ptr2) 1743 { 1744 /* Normal comment, ignore and continue; */ 1745 1746 SubBuffer = Ptr2; 1747 continue; 1748 } 1749 1750 /* Examine multi-line comment */ 1751 1752 LineCount = 1; 1753 while (Ptr1 > Ptr2) 1754 { 1755 /* Find next EOL */ 1756 1757 Ptr2++; 1758 Ptr2 = strstr (Ptr2, "\n"); 1759 if (!Ptr2) 1760 { 1761 goto Exit; 1762 } 1763 1764 LineCount++; 1765 } 1766 1767 SubBuffer = Ptr1; 1768 1769 if (LineCount <= 3) 1770 { 1771 ShortCommentCount++; 1772 } 1773 } 1774 1775 1776 Exit: 1777 1778 if (ShortCommentCount) 1779 { 1780 AsPrint ("Short Comments found", ShortCommentCount, Filename); 1781 } 1782 } 1783 #endif 1784 1785 #ifdef ACPI_UNUSED_FUNCTIONS 1786 /****************************************************************************** 1787 * 1788 * FUNCTION: AsCheckAndSkipLiterals 1789 * 1790 * DESCRIPTION: Generic routine to skip comments and quoted string literals. 1791 * Keeps a line count. 1792 * 1793 ******************************************************************************/ 1794 1795 static char * 1796 AsCheckAndSkipLiterals ( 1797 char *Buffer, 1798 UINT32 *TotalLines); 1799 1800 1801 static char * 1802 AsCheckAndSkipLiterals ( 1803 char *Buffer, 1804 UINT32 *TotalLines) 1805 { 1806 UINT32 NewLines = 0; 1807 char *SubBuffer = Buffer; 1808 char *LiteralEnd; 1809 1810 1811 /* Ignore comments */ 1812 1813 if ((SubBuffer[0] == '/') && 1814 (SubBuffer[1] == '*')) 1815 { 1816 LiteralEnd = strstr (SubBuffer, "*/"); 1817 SubBuffer += 2; /* Get past comment opening */ 1818 1819 if (!LiteralEnd) 1820 { 1821 return (SubBuffer); 1822 } 1823 1824 while (SubBuffer < LiteralEnd) 1825 { 1826 if (*SubBuffer == '\n') 1827 { 1828 NewLines++; 1829 } 1830 1831 SubBuffer++; 1832 } 1833 1834 SubBuffer += 2; /* Get past comment close */ 1835 } 1836 1837 /* Ignore quoted strings */ 1838 1839 else if (*SubBuffer == '\"') 1840 { 1841 SubBuffer++; 1842 LiteralEnd = AsSkipPastChar (SubBuffer, '\"'); 1843 if (!LiteralEnd) 1844 { 1845 return (SubBuffer); 1846 } 1847 } 1848 1849 if (TotalLines) 1850 { 1851 (*TotalLines) += NewLines; 1852 } 1853 return (SubBuffer); 1854 } 1855 #endif 1856