PWB Extension Converts Selected Text to Uppercase Letters

Last reviewed: July 17, 1997
Article ID: Q94837
1.00 1.10 2.00 | 1.00 1.10
MS-DOS         | OS/2
kbtool kbcode

The information in this article applies to:

  • Microsoft Programmer's WorkBench for MS-DOS, versions 1.0, 1.1, 2.0
  • Microsoft Programmer's WorkBench for OS/2, versions 1.0, 1.1

SUMMARY

The text below demonstrates the process to create a Programmer's WorkBench (PWB) extension to convert one selected line of text to uppercase. Note that nothing appears to happen if the cursor is on a different line than the selected line.

MORE INFORMATION

To load and use the extension, perform the following five steps:

  1. Copy REVERSE.MXT into the same directory as PWB. By default on an MS-DOS system, this is the BIN subdirectory. By default on an OS/2 system, this is the BINP subdirectory.

  2. Modify the TOOLS.INI file to place a load command in the [PWB] section. For example,

          [pwb]
    
              load:[path\]reverse
    
    

  3. Start the PWB editor.

  4. Select the text to convert to uppercase letters. The selection must be on one line.

  5. From the Case menu, select Lower to Upper.

The source code for this PWB extension is as follows.

Sample Code

/*
 * Compile options needed:  cl /c /Gs /ACw reverse.c
 *                          link exthdr test, reverse.mxt;
 */

#define  BUF_LEN  250
#define  TRUE     1
#define  FALSE    0

#include <ext.h>
#include <string.h>
#include <ctype.h>


PWBFUNC ToUpper(unsigned argData, ARG _far *pArg, flagType fMeta); struct swiDesc swiTable[] = {
   {"ToUpper", toPIF(ToUpper), SWI_BOOLEAN},
   { NULL, NULL, 0}
};

struct cmdDesc cmdTable[] = {

   {"ToUpper", ToUpper, 0, STREAMARG},
   {NULL, NULL, 0, 0}
};

void EXTERNAL WhenLoaded(void)
{
   int hmatch;
   hmatch = AddMenu("~Case", "xxxx", "", TRUE);
   AddMenuItem(hmatch, "~Lower to Upper", "Case switch", NULL, "ToUpper");
}

PWBFUNC ToUpper(unsigned argData, ARG _far *pArg, flagType fMeta) {

   LINE    ycurr, ystart, yend;
   COL     xcurr, xstart, xend;
   char    buf[BUF_LEN + 1];
   PFILE   pfile;
   int     i;
   int     maxlines;

   switch (pArg->argType)
      {
   case STREAMARG:
      // The following code retrieves the corners
      // of the stream for future use
      ystart = pArg->arg.streamarg.yStart;
      yend = pArg->arg.streamarg.yEnd;
      xstart = pArg->arg.streamarg.xStart;
      xend = pArg->arg.streamarg.xEnd;
      pfile = FileNameToHandle("", "");
      maxlines = FileLength(pfile);
      ycurr = ystart;
      xcurr = xstart;

      // Read the argument
      pfile = FileNameToHandle("","");
      GetLine(ystart, buf, pfile);

      // Convert to uppercase letters
      for ( ; xcurr < xend ; xcurr++)
         buf[xcurr] = toupper(buf[xcurr]);

      // Output converted argument
      PutLine(ystart, buf, pfile);
      break;

   default:
      DoMessageBox("Default", buf, NULL, MBOX_OK, 0);
      break;
      }
}


Additional reference words: kbinf 1.00 1.10 2.00 PWBIss
KBCategory: kbtool kbcode
KBSubcategory: PWBIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.