Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5 KiB

  1. /*** tglcase.c - case toggling editor extension
  2. *
  3. * Copyright <C> 1988, Microsoft Corporation
  4. *
  5. * Purpose:
  6. * Contains the tglcase function.
  7. *
  8. * Revision History:
  9. *
  10. * 28-Jun-1988 LN Created
  11. * 12-Sep-1988 mz Made WhenLoaded match declaration
  12. *
  13. *************************************************************************/
  14. #include <stdlib.h> /* min macro definition */
  15. #include <string.h> /* prototypes for string fcns */
  16. #include "zext.h"
  17. /*
  18. ** Internal function prototypes
  19. */
  20. void pascal id (char *);
  21. flagType pascal EXTERNAL tglcase (unsigned int, ARG far *, flagType);
  22. /*************************************************************************
  23. **
  24. ** tglcase
  25. ** Toggle the case of alphabetics contaied within the selected argument:
  26. **
  27. ** NOARG - Toggle case of entire current line
  28. ** NULLARG - Toggle case of current line, from cursor to end of line
  29. ** LINEARG - Toggle case of range of lines
  30. ** BOXARG - Toggle case of characters with the selected box
  31. ** NUMARG - Converted to LINEARG before extension is called.
  32. ** MARKARG - Converted to Appropriate ARG form above before extension is
  33. ** called.
  34. **
  35. ** STREAMARG - Not Allowed. Treated as BOXARG
  36. ** TEXTARG - Not Allowed
  37. **
  38. */
  39. flagType pascal EXTERNAL tglcase (
  40. unsigned int argData, /* keystroke invoked with */
  41. ARG *pArg, /* argument data */
  42. flagType fMeta /* indicates preceded by meta */
  43. )
  44. {
  45. PFILE pFile; /* file handle of current file */
  46. COL xStart; /* left border of arg area */
  47. LINE yStart; /* starting line of arg area */
  48. COL xEnd; /* right border of arg area */
  49. LINE yEnd; /* ending line of arg area */
  50. int cbLine; /* byte count of current line */
  51. COL xCur; /* current column being toggled */
  52. char buf[BUFLEN]; /* buffer for line being toggled*/
  53. register char c; /* character being analyzed */
  54. //
  55. // Unreferenced parameters
  56. //
  57. (void)argData;
  58. (void)fMeta;
  59. id ("");
  60. pFile = FileNameToHandle ("", "");
  61. switch (pArg->argType) {
  62. /*
  63. ** For the various argument types, set up a box (xStart, yStart) - (xEnd, yEnd)
  64. ** over which the case conversion code below can operate.
  65. */
  66. case NOARG: /* case switch entire line */
  67. xStart = 0;
  68. xEnd = 256;
  69. yStart = yEnd = pArg->arg.noarg.y;
  70. break;
  71. case NULLARG: /* case switch to EOL */
  72. xStart = pArg->arg.nullarg.x;
  73. xEnd = 32765;
  74. yStart = yEnd = pArg->arg.nullarg.y;
  75. break;
  76. case LINEARG: /* case switch line range */
  77. xStart = 0;
  78. xEnd = 32765;
  79. yStart = pArg->arg.linearg.yStart;
  80. yEnd = pArg->arg.linearg.yEnd;
  81. break;
  82. case BOXARG: /* case switch box */
  83. xStart = pArg->arg.boxarg.xLeft;
  84. xEnd = pArg->arg.boxarg.xRight;
  85. yStart = pArg->arg.boxarg.yTop;
  86. yEnd = pArg->arg.boxarg.yBottom;
  87. break;
  88. }
  89. /*
  90. ** Within the range of lines yStart to yEnd, get each line, and if non-null,
  91. ** check each character. If alphabetic, replace with it's case-converted
  92. ** value. After all characters have been checked, replace line in file.
  93. */
  94. while (yStart <= yEnd) {
  95. if (cbLine = GetLine (yStart, buf, pFile)) {
  96. for (xCur = xStart; (xCur <= min(cbLine, xEnd)); xCur++) {
  97. c = buf[xCur];
  98. if ((c >= 'A') && (c <= 'Z'))
  99. c += 'a'-'A';
  100. else if ((c >= 'a') && (c <= 'z'))
  101. c += 'A'-'a';
  102. buf[xCur] = c;
  103. }
  104. PutLine (yStart++, buf, pFile);
  105. }
  106. }
  107. return 1;
  108. }
  109. /*************************************************************************
  110. **
  111. ** WhenLoaded
  112. ** Executed when extension gets loaded.
  113. **
  114. ** Entry:
  115. ** none
  116. */
  117. void tglcaseWhenLoaded ()
  118. {
  119. return;
  120. }