Leaked source code of windows server 2003
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.

171 lines
4.9 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. #define EXT_ID " tglcase ver 1.00 "##__DATE__##" "##__TIME__
  15. #include <stdlib.h> /* min macro definition */
  16. #include <string.h> /* prototypes for string fcns */
  17. #include "ext.h"
  18. /*
  19. ** Internal function prototypes
  20. */
  21. void pascal id (char *);
  22. void EXTERNAL WhenLoaded (void);
  23. flagType pascal EXTERNAL tglcase (unsigned int, ARG far *, flagType);
  24. /*************************************************************************
  25. **
  26. ** tglcase
  27. ** Toggle the case of alphabetics contaied within the selected argument:
  28. **
  29. ** NOARG - Toggle case of entire current line
  30. ** NULLARG - Toggle case of current line, from cursor to end of line
  31. ** LINEARG - Toggle case of range of lines
  32. ** BOXARG - Toggle case of characters with the selected box
  33. ** NUMARG - Converted to LINEARG before extension is called.
  34. ** MARKARG - Converted to Appropriate ARG form above before extension is
  35. ** called.
  36. **
  37. ** STREAMARG - Not Allowed. Treated as BOXARG
  38. ** TEXTARG - Not Allowed
  39. **
  40. */
  41. flagType pascal EXTERNAL tglcase (
  42. unsigned int argData, /* keystroke invoked with */
  43. ARG *pArg, /* argument data */
  44. flagType fMeta /* indicates preceded by meta */
  45. )
  46. {
  47. PFILE pFile; /* file handle of current file */
  48. COL xStart; /* left border of arg area */
  49. LINE yStart; /* starting line of arg area */
  50. COL xEnd; /* right border of arg area */
  51. LINE yEnd; /* ending line of arg area */
  52. int cbLine; /* byte count of current line */
  53. COL xCur; /* current column being toggled */
  54. char buf[BUFLEN]; /* buffer for line being toggled*/
  55. register char c; /* character being analyzed */
  56. //
  57. // Unreferenced parameters
  58. //
  59. (void)argData;
  60. (void)fMeta;
  61. id ("");
  62. pFile = FileNameToHandle ("", "");
  63. switch (pArg->argType) {
  64. /*
  65. ** For the various argument types, set up a box (xStart, yStart) - (xEnd, yEnd)
  66. ** over which the case conversion code below can operate.
  67. */
  68. case NOARG: /* case switch entire line */
  69. xStart = 0;
  70. xEnd = 256;
  71. yStart = yEnd = pArg->arg.noarg.y;
  72. break;
  73. case NULLARG: /* case switch to EOL */
  74. xStart = pArg->arg.nullarg.x;
  75. xEnd = 32765;
  76. yStart = yEnd = pArg->arg.nullarg.y;
  77. break;
  78. case LINEARG: /* case switch line range */
  79. xStart = 0;
  80. xEnd = 32765;
  81. yStart = pArg->arg.linearg.yStart;
  82. yEnd = pArg->arg.linearg.yEnd;
  83. break;
  84. case BOXARG: /* case switch box */
  85. xStart = pArg->arg.boxarg.xLeft;
  86. xEnd = pArg->arg.boxarg.xRight;
  87. yStart = pArg->arg.boxarg.yTop;
  88. yEnd = pArg->arg.boxarg.yBottom;
  89. break;
  90. }
  91. /*
  92. ** Within the range of lines yStart to yEnd, get each line, and if non-null,
  93. ** check each character. If alphabetic, replace with it's case-converted
  94. ** value. After all characters have been checked, replace line in file.
  95. */
  96. while (yStart <= yEnd) {
  97. if (cbLine = GetLine (yStart, buf, pFile)) {
  98. for (xCur = xStart; (xCur <= min(cbLine, xEnd)); xCur++) {
  99. c = buf[xCur];
  100. if ((c >= 'A') && (c <= 'Z'))
  101. c += 'a'-'A';
  102. else if ((c >= 'a') && (c <= 'z'))
  103. c += 'A'-'a';
  104. buf[xCur] = c;
  105. }
  106. PutLine (yStart++, buf, pFile);
  107. }
  108. }
  109. return 1;
  110. }
  111. /*************************************************************************
  112. **
  113. ** WhenLoaded
  114. ** Executed when extension gets loaded. Identify self & assign default
  115. ** keystroke.
  116. **
  117. ** Entry:
  118. ** none
  119. */
  120. void EXTERNAL WhenLoaded () {
  121. id("case conversion extension:");
  122. SetKey ("tglcase", "alt+c");
  123. /* end WhenLoaded */}
  124. /*************************************************************************
  125. **
  126. ** id
  127. ** identify ourselves, along with any passed informative message.
  128. **
  129. ** Entry:
  130. ** pszMsg = Pointer to asciiz message, to which the extension name
  131. ** and version are appended prior to display.
  132. */
  133. void pascal id (char *pszFcn)
  134. {
  135. char buf[80] = {0}; /* message buffer */
  136. strncat (buf,pszFcn, sizeof(buf)-1); /* start with message */
  137. strncat (buf,EXT_ID, sizeof(buf)-strlen(buf)-1); /* append version */
  138. DoMessage (buf);
  139. }
  140. /*************************************************************************
  141. **
  142. ** Switch communication table to the editor.
  143. ** This extension defines no switches.
  144. */
  145. struct swiDesc swiTable[] = {
  146. {0, 0, 0}
  147. };
  148. /*************************************************************************
  149. **
  150. ** Command communication table to the editor.
  151. ** Defines the name, location and acceptable argument types.
  152. */
  153. struct cmdDesc cmdTable[] = {
  154. {"tglcase", (funcCmd) tglcase,0, KEEPMETA | NOARG | BOXARG | NULLARG | LINEARG | MARKARG | NUMARG | MODIFIES},
  155. {0, 0, 0}
  156. };