home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1996 Microsoft Corporation. All rights reserved.
- * File: initcaps.cpp
- *
- * DLL Custom WebBot Example
- */
-
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- #include "stdlib.h"
- #include "../webbot.h"
-
- //////////////////////////////////
- // private string utilities
-
- static void UpperCase(char *str)
- {
- char *p = NULL;
- for(p=str;p && *p;p++)
- *p = toupper(*p);
- }
-
- static char *StringCopy(const char *str)
- {
- char *p = NULL;
- if(!str)
- return NULL;
- p = (char *)malloc(strlen(str)+1);
- if(!p)
- return NULL;
- strcpy(p,str);
- return p;
- }
-
- //////////////////////////////
- // BOT: SmallCaps
-
- BeginWebBotExpand(SmallCaps,ret,bot,cgi,form)
- {
- const char *pszText = NULL;
- const char *pszSize = NULL;
- int bBigger = 0;
- int nSize = 0;
- char *pszUCase = NULL;
- int slen = 0;
- char *p = NULL;
- char fontbeg[32];
- char fontend[32];
- char chout[2];
-
- /* fetch parameters and verify them; else return error HTML */
- pszText = bot.GetValue("S-Text");
- pszSize = bot.GetValue("I-Font-Size");
-
- if(!pszText || !pszText[0]
- || !pszSize || !pszSize[0])
- goto SmallCapsExpandError;
-
- /* convert any non-string parameters and do bounds checking */
- nSize = atoi(pszSize);
- if(nSize < 1)
- nSize = 1;
- if(nSize > 7)
- nSize = 7;
-
- /* copy source string and make it all upper-case */
- pszUCase = StringCopy(pszText);
- if(!pszUCase)
- goto SmallCapsExpandError;
- UpperCase(pszUCase);
-
- /* copy each word in source to output with initial font size as requested */
-
- chout[0] = chout[1] = 0;
-
- sprintf(fontbeg,"<FONT SIZE=%d>",nSize);
- sprintf(fontend,"</FONT>");
-
- p = pszUCase;
- while(p && *p)
- {
- /* find first non-alnum in remainder of string (ingoring apostrophes) */
- int idx = strspn(p,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'");
- if(idx > 0)
- {
- int chTmp = p[idx];
- p[idx] = 0;
- chout[0] = *p;
-
- ret.Append(fontbeg);
- ret.Append(chout);
- ret.Append(fontend);
- ret.Append(p+1);
-
- p[idx] = chTmp;
- p += idx;
- }
- else
- {
- /* not found or at beginning */
- chout[0] = *p;
-
- if(isalnum(*p) || *p == '\'')
- {
- /* no more non-alnum in string; use remainder */
- ret.Append(fontbeg);
- ret.Append(chout);
- ret.Append(fontend);
- ret.Append(p+1);
- p += strlen(p);
- }
- else
- {
- /* just stepping over non-alnum */
- ret.Append(chout);
- p++;
- }
- } /* end else */
- } /* end while */
-
- /* free up any memory we allocated */
- free((char *)pszUCase);
-
- return;
-
- SmallCapsExpandError:
- ret.Append("<STRONG>[SmallCaps]</STRONG>");
- return;
-
- }
- EndWebBotExpand
-