home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TCXOS2.ZIP / DEMO / STR_DEMO.C < prev    next >
Text File  |  1991-11-05  |  21KB  |  594 lines

  1. /*=====[ The TesSeRact(TM) CXL User Interface Development System ]======*
  2.  | Copyright (c) 1987-1991, Innovative Data Concepts, Inc.
  3.  | All Rights Reserved.
  4.  |
  5.  | This Library is part of IDC's TesSeRact Development Tools product
  6.  | line. For information about other IDC products, call  1-215-443-9705.
  7.  *-V--------------------------------------------------------------------*
  8.  | $Header:   D:/beta/version/str_demo.c_v   552.2   22 Jun 1991 14:03:52  $
  9.  |
  10.  | $Log:   D:/beta/version/str_demo.c_v  $
  11.  | 
  12.  |    Rev 552.2   22 Jun 1991 14:03:52
  13.  | check correct return value from Wopen
  14.  | 
  15.  |    Rev 552.1   17 Mar 1991 20:03:02
  16.  | Version 5.52 (after unlog/build)
  17.  *-D--------------------------------------------------------------------*
  18.  | Str_Demo.C : Demonstration of TCXL string system. The demo consists of
  19.  | a selection-list of demonstration types which is used to select an
  20.  | element of a control structure, then invoke and display the code for
  21.  | and display the results of the selected operations.  StringDemo() is
  22.  | invoked from the main menu of Mid_Demo.C.
  23.  *-N-----------------------[ Notes and Caveats ]------------------------*
  24.  | 1) Use the MakeDemo.Bat file to compile this file.
  25.  *======================================================================*/
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include "demo\TCXLdemo.h"             /* TCXL demo-specific            */
  29. #include <TCXLsel.h>                   /* TCXL selection/window/video   */
  30. #include <TCXLstr.h>                   /* TCXL strings                  */
  31.  
  32. /*----------------------------[ Local data ]----------------------------*/
  33.  
  34. LCL   ChrP  CDC   BefAft =             /* Before/after format           */
  35.    " Before: <%s>\n  After: <%s>\n";
  36.  
  37. ChrP  CDC   sDstrmatch[] =             /* sample demo-source text       */
  38. {
  39.    "VOID CTYP  Dstrmatch(NOARG)\n",
  40.    "{\n",
  41.    "  ChrP strings[] = { \"Hello\", \"There\", \"Computer\", \"World\", "
  42.       "NULL };\n",
  43.    "  ChrP str1 = \"xhelpx\";\n",
  44.    "  IntT i = 0;\n",
  45.    "\n",
  46.    "  while(strings[i] != NULL)\n",
  47.    "  {\n",
  48.    "    Wputf(\" <%s> vs. <%s> = <%d>\\n\", \n",
  49.    "      str1, strings[i], strmatch(str1, strings[i]));\n",
  50.    "    i++;\n",
  51.    "  }\n",
  52.    "\n",
  53.    "  Wputf(\" <%s> best matches <%s>\\n\", str1, strbmatch(str1, string"
  54.       "s));\n",
  55.    "}\n",
  56.    NULL,
  57. };
  58. ChrP  CDC   sDstrtrim[] =
  59. {
  60.    "VOID CTYP  Dstrtrim(NOARG)\n",
  61.    "{\n",
  62.    "  ChrP str1 = \"     Hello, world     \";\n",
  63.    "  ChrT str2[25];\n",
  64.    "\n",
  65.    "  strcpy(str2, str1);\n",
  66.    "  strltrim(str2);\n",
  67.    "  Wputf(BefAft, str1, str2);\n",
  68.    "\n",
  69.    "  strcpy(str2, str1);\n",
  70.    "  strrtrim(str2);      /* identical to strtrim() */\n",
  71.    "  Wputf(BefAft, str1, str2);\n",
  72.    "\n",
  73.    "  strcpy(str2, str1);\n",
  74.    "  strbtrim(str2);\n",
  75.    "  Wputf(BefAft, str1, str2);\n",
  76.    "\n",
  77.    "}\n",
  78.    NULL,
  79. };
  80. ChrP  CDC   sDstrchg[] =
  81. {
  82.    "VOID CTYP  Dstrchg(NOARG)\n",
  83.    "{ ChrP str1 = \"HelLo, worLd\";\n",
  84.    "  ChrP str2 = \"Hello, world\";\n",
  85.    "  ChrP str3 = \"xxxhElLoyyyHElLOzzz\";\n",
  86.    "  ChrP str4 = \"xxxhElloyyyhellozzz\";\n",
  87.    "  ChrT str5[30];\n",
  88.    "\n",
  89.    "  strcpy(str5, str1);\n",
  90.    "  strchg(str5, 'l', 'z');\n",
  91.    "  Wputf(BefAft, str1, str5);\n",
  92.    "\n",
  93.    "  strcpy(str5, str2);\n",
  94.    "  strichg(str5, 'l', 'z');\n",
  95.    "  Wputf(BefAft, str2, str5);\n",
  96.    "\n",
  97.    "  strcpy(str5, str3);\n",
  98.    "  strischg(str5, \"HeLlO\", \"goodbye\");\n",
  99.    "  Wputf(BefAft, str3, str5);\n",
  100.    "\n",
  101.    "  strcpy(str5, str4);\n",
  102.    "  strschg(str5,\"hello\",\"goodbye\");\n",
  103.    "  Wputf(BefAft, str4, str5);\n",
  104.    "}\n",
  105.    NULL,
  106. };
  107. ChrP  CDC   sDstrchksum[] =
  108. {
  109.    "VOID CTYP  Dstrchksum(NOARG)\n",
  110.    "{\n",
  111.    "  ChrP str1 = \"Hello, world\";\n",
  112.    "\n",
  113.    "  Wputf(\"Checksum is %lu, I-Checksum is %lu\\n\",\n",
  114.    "    strchksum(str1), strichksum(str1));\n",
  115.    "}\n",
  116.    NULL,
  117. };
  118. ChrP  CDC   sDstrdel[] =
  119. {
  120.    "VOID CTYP  Dstrdel(NOARG)\n",
  121.    "{\n",
  122.    "  ChrP str1 = \"XyZHello, xYzworldXyZxYz\";\n",
  123.    "  ChrT str2[35];\n",
  124.    "  \n",
  125.    "  strcpy(str2, str1);\n",
  126.    "  strdel(\"xYz\", str2);\n",
  127.    "  Wputf(BefAft, str1, str2);\n",
  128.    "  strcpy(str2, str1);\n",
  129.    "  strdela(\"xYz\", str2);\n",
  130.    "  Wputf(BefAft, str1, str2);\n",
  131.    "  strcpy(str2, str1);\n",
  132.    "  stridel(\"xYz\", str2);\n",
  133.    "  Wputf(BefAft, str1, str2);\n",
  134.    "  strcpy(str2, str1);\n",
  135.    "  stridela(\"xYz\", str2);\n",
  136.    "  Wputf(BefAft, str1, str2);\n",
  137.    "  strcpy(str1, str2);\n",
  138.    "  strins(\"xYz\", str2, 4);\n",
  139.    "  Wputf(BefAft, str1, str2);\n",
  140.    "}\n",
  141.    NULL,
  142. };
  143. ChrP  CDC   sDstrinc[] =
  144. {
  145.    "VOID CTYP  Dstrinc(NOARG)\n",
  146.    "{\n",
  147.    "  ChrP str1 = \"Hello1HELLO2HeLlO3hElLo\";\n",
  148.    "  ChrP str2 = \"hello\";\n",
  149.    "\n",
  150.    "  Wputf(\"str2 is %sincluded in str1\\n\",\n",
  151.    "    ( (strinc(str2,str1) == NULL) ? \n",
  152.    "    \"not \" : \"\"));\n",
  153.    "\n",
  154.    "  Wputf(\"str2 is %sincluded in str1\\n\",\n",
  155.    "    ( (striinc(str2,str1) == NULL) ? \n",
  156.    "    \"not \" : \"\"));\n",
  157.    "\n",
  158.    "  Wputf(\"There are %d occurrences of '%c' in str1\\n\",\n",
  159.    "            strocc(str1, 'l'), 'l');\n",
  160.    "  Wputf(\"There are %d occurrences of '%c' in str1\\n\",\n",
  161.    "            striocc(str1, 'l'), 'l');\n",
  162.    "\n",
  163.    "  Wputf(\"str2 occurs in str1 %d times\\n\",\n",
  164.    "    strsocc(str2, str1));\n",
  165.    "  Wputf(\"str2 occurs in str1 %d times\\n\",\n",
  166.    "    strisocc(str2, str1));\n",
  167.    "}\n",
  168.    NULL,
  169. };
  170. ChrP  CDC   sDstrsrep[] =
  171. {
  172.    "VOID CTYP  Dstrsrep(NOARG)\n",
  173.    "{\n",
  174.    "  ChrP str1 = \"This is a big string\";\n",
  175.    "  ChrT str2[25];\n",
  176.    "\n",
  177.    "  strcpy(str2, str1);\n",
  178.    "  strsrep(str2, \"str\", \"th\");\n",
  179.    "  Wputf(BefAft, str1, str2);\n",
  180.    "\n",
  181.    "  strcpy(str2, str1);\n",
  182.    "  strisrep(str2, \"str\", \"th\");\n",
  183.    "  Wputf(BefAft, str1, str2);\n",
  184.    "\n",
  185.    "}\n",
  186.    NULL,
  187. };
  188. ChrP  CDC   sDstrmid[] =
  189. {
  190.    "VOID CTYP  Dstrmid(NOARG)\n",
  191.    "{\n",
  192.    "  ChrP p;\n",
  193.    "  ChrP str = \"Hello, world\";\n",
  194.    "\n",
  195.    "  Wputf(\"    %s\\n\", p = strmid(str, 5, 5));\n",
  196.    "  free(p);\n",
  197.    "\n",
  198.    "  Wputf(\"    %s\\n\", p = strleft(str, 5));\n",
  199.    "  free(p);\n",
  200.    "\n",
  201.    "  Wputf(\"    %s\\n\", p = strright(str, 5));\n",
  202.    "  free(p);\n",
  203.    "  \n",
  204.    "}\n",
  205.    NULL,
  206. };
  207. ChrP  CDC   sDstrljust[] =
  208. {
  209.    "VOID CTYP  Dstrljust(NOARG)\n",
  210.    "{ ChrP str1 = \"     Hello, world     \";\n",
  211.    "  ChrP str2 = \"Hello, world\";\n",
  212.    "  ChrT str3[25];\n",
  213.    "  strcpy(str3, str1);\n",
  214.    "  strljust(str3);\n",
  215.    "  Wputf(BefAft, str1, str3);\n",
  216.    "  strcpy(str3, str1);\n",
  217.    "  strrjust(str3);\n",
  218.    "  Wputf(BefAft, str1, str3);\n",
  219.    "  strcpy(str3, str2);\n",
  220.    "  strrol(str3, 3);\n",
  221.    "  Wputf(BefAft, str2, str3);\n",
  222.    "  strcpy(str3, str2);\n",
  223.    "  strror(str3, 3);\n",
  224.    "  Wputf(BefAft, str2, str3);\n",
  225.    "  strcpy(str3, str2);\n",
  226.    "  strshl(str3, 3);\n",
  227.    "  Wputf(BefAft, str2, str3);\n",
  228.    "  strcpy(str3, str2);\n",
  229.    "  strshr(str3, 3);\n",
  230.    "  Wputf(BefAft, str2, str3);\n",
  231.    "}\n",
  232.    NULL,
  233. };
  234. ChrP  CDC   sDstrblank[] =
  235. {
  236.    "VOID CTYP  Dstrblank(NOARG)\n",
  237.    "{ ChrP str1 = \"  Hello  \";\n",
  238.    "  ChrP str2 = \" \\n  \\t \\r \";\n",
  239.    "  ChrP str3 = \"Hello, world\";\n",
  240.    "  ChrP str4 = \"hElLo, wOrLd\";\n",
  241.    "  ChrT str5[20];\n",
  242.    "  Wputf(\" str1 is %sblank\\n\", strblank(str1) ? \"\" : \"not \");\n",
  243.    "  Wputf(\" str2 is %sblank\\n\", strblank(str2) ? \"\" : \"not \");\n",
  244.    "  Wputf(\" Before:    <%s>\\n\", str3);\n",
  245.    "  strcode(str3, \"34&*#Mdq\");\n",
  246.    "  Wputf(\" Encrypted: <%s>\\n\", str3);\n",
  247.    "  strcode(str3, \"34&*#Mdq\");\n",
  248.    "  Wputf(\" Decrypted: <%s>\\n\", str3);\n",
  249.    "  strcpy(str5, str3);\n",
  250.    "  Wputf(\" Before:  <%s>\\n\", str5);\n",
  251.    "  strsetsz(str5, 20);\n",
  252.    "  Wputf(\" Len=20:  <%s>\\n\", str5);\n",
  253.    "  strsetsz(str5, 5);\n",
  254.    "  Wputf(\" Len=5:   <%s>\\n\", str5);\n",
  255.    "  strcpy(str5, str4);\n",
  256.    "  struplow(str5);\n",
  257.    "  Wputf(BefAft, str4, str5);\n",
  258.    "}\n",
  259.    NULL,
  260. };
  261.  
  262. LCL   ChrP  CDC   Dstrings[] =         /* text for strings demo         */
  263. {
  264.    "Hello", "There", "Computer", "World", NULL
  265. };
  266.  
  267. LCL   ChrP Sdemo1[] =                  /* Selection items/titles        */
  268. {
  269.    "Trimming",    "Changing",       "Checksum",    "Delete/Insert",
  270.    "Inclusion",   "Replacement",    "Substrings",  "Justification",
  271.    "Matching",    "Miscellaneous",  "Exit",        NULL
  272. };
  273.  
  274. TYP struct _StrDmo
  275. {
  276.    ChrI  Dsp;                          /* sample source text array      */
  277.    VfvCP Fun;                          /* demo function                 */
  278.    IntT  Wrws;                         /* coords for result window      */
  279.    IntT  Wcls;                         /* "      "   "      "           */
  280. }   STRDMO;
  281.  
  282. /*---------------------[ Local function prototypes ]--------------------*/
  283.  
  284. LCL   VOID  CTYP  Dstrmatch(NOARG);
  285. LCL   VOID  CTYP  Dstrtrim(NOARG);
  286. LCL   VOID  CTYP  Dstrchg(NOARG);
  287. LCL   VOID  CTYP  Dstrchksum(NOARG);
  288. LCL   VOID  CTYP  Dstrdel(NOARG);
  289. LCL   VOID  CTYP  Dstrinc(NOARG);
  290. LCL   VOID  CTYP  Dstrsrep(NOARG);
  291. LCL   VOID  CTYP  Dstrmid (NOARG);
  292. LCL   VOID  CTYP  Dstrljust(NOARG);
  293. LCL   VOID  CTYP  Dstrblank(NOARG);
  294.  
  295. STRDMO Sdemo[] =                       /* string demo control object    */
  296. {                                      /* _VFVCP casts are for C++      */
  297.    {  sDstrtrim,   _VFVCP(Dstrtrim),    9, 35  },
  298.    {  sDstrchg,    _VFVCP(Dstrchg),    11, 36  },
  299.    {  sDstrchksum, _VFVCP(Dstrchksum),  5, 19  },
  300.    {  sDstrdel,    _VFVCP(Dstrdel),    13, 37  },
  301.    {  sDstrinc,    _VFVCP(Dstrinc),    11, 32  },
  302.    {  sDstrsrep,   _VFVCP(Dstrsrep),    7, 33  },
  303.    {  sDstrmid,    _VFVCP(Dstrmid),     7, 15  },
  304.    {  sDstrljust,  _VFVCP(Dstrljust),  15, 35  },
  305.    {  sDstrmatch,  _VFVCP(Dstrmatch),   8, 32  },
  306.    {  sDstrblank,  _VFVCP(Dstrblank),  13, 34  },
  307. };
  308.  
  309. /*=======================[ The TCXL Strings demo ]======================*
  310.  | Called from the [S]trings item of the Mid_Demo.C main menu.
  311.  *----------------------------------------------------------------------*/
  312.  
  313. VOID  CTYP  StringDemo(NOARG)
  314. {
  315.    VcelFP   s;
  316.    IntT     Sel = 0, i;
  317.  
  318.    s = FarVsave(LGREY|_BLACK);         /* save screen                   */
  319.    MouPush(MOU_FULL);                  /* full mouse support            */
  320.    CurSave();                          /* save cursor state             */
  321.    LeftRow = ((VidDep - 1) / 2) - 6;   /* menu coordinates              */
  322.    RightRow = LeftRow + 12;
  323.    LeftCol = ((VidWid - 1) / 2) - 9;
  324.    RightCol = LeftCol + 16;
  325.  
  326.    LOOP                                /*- Endless loop ----------------*/
  327.    {                                   /* display selection list        */
  328.       Sel = SelStr(LeftRow, LeftCol, RightRow, RightCol, 1, LCYAN|_BLUE,
  329.          LCYAN|_BLUE, YELLOW|_LGREY, Sdemo1, Sel, NULL);
  330.       if((Sel >= 10) || (Sel < 0))
  331.          break;                        /* time to quit                  */
  332.  
  333.       if(!WpopUp(CNT_CNT, 0, 0, 24,    /* pop up a demo window          */
  334.             VidWid - 1, 1, LCYAN|_BLUE, LCYAN|_BLUE))
  335.          ErrorExit(1);                 /* windowing error!              */
  336.  
  337.       Wtitle(Sdemo1[Sel], TTL_CNT, LCYAN|_BLUE);   /* add title         */
  338.       Wmessage(" [Press a Key to Continue ] ",     /* add message       */
  339.          BRD_BOT, MsByt(((VidWid - 1) / 2) - 15), LCYAN|_BLUE);
  340.  
  341.       i = 0;
  342.       while(Sdemo[Sel].Dsp[i] != NULL) /* display source-code text      */
  343.          Wputs(Sdemo[Sel].Dsp[i++]);
  344.                                        /* open result window            */
  345.       if(ERR_ARG == Wopen(((VidDep - 25) / 2) + 1, 
  346.             VidWid - 1 - Sdemo[Sel].Wcls - 1,
  347.             ((VidDep - 25) / 2) + 1 + Sdemo[Sel].Wrws, VidWid - 2, 0,
  348.             WHITE|_RED, WHITE|_BLUE))
  349.          ErrorExit(1);                 /* can't open the window!        */
  350.  
  351.       (*Sdemo[Sel].Fun)();             /* invoke the demo function      */
  352.       PressAKey1(MsByt(Sdemo[Sel].Wrws - 2), -1);
  353.       Wclose();                        /* close up windows              */
  354.       Wclose();
  355.       Sel++;                           /* move selection bar down       */
  356.    }  /* LOOP */
  357.  
  358.    CurPop();                           /* restore cursor state          */
  359.    MouPop();                           /* restore mouse                 */
  360.    FarVrestore(s);                     /* restore screen                */
  361.    KeyClear();                         /* flush any lurking keycodes    */
  362.    MoveBarDn();                        /* next main-menu selection      */
  363. }  /* StringDemo() */
  364.  
  365. /*-----------------------[ String Matching demo ]-----------------------*/
  366.  
  367. LCL   VOID  CTYP  Dstrmatch(NOARG)
  368. {
  369.    ChrP  str1 = "xhelpx";
  370.    IntT  i = 0;
  371.  
  372.    while(Dstrings[i] != NULL)          /* Find best match               */
  373.    {
  374.       Wputf(" <%s> vs. <%s> = <%d>\n",
  375.            str1, Dstrings[i], strmatch(str1, Dstrings[i]));
  376.       i++;
  377.    }
  378.  
  379.    Wputf(" <%s> best matches <%s>\n", str1, strbmatch(str1, Dstrings));
  380. }  /* Dstrmatch() */
  381.  
  382. /*-----------------------[ String Trimming demo ]-----------------------*/
  383.  
  384. LCL   VOID  CTYP  Dstrtrim(NOARG)
  385. {
  386.    ChrP  str1 = "     Hello, world     ";
  387.    ChrT  str2[25];
  388.  
  389.    strcpy(str2, str1);                 /* Trim leading blanks           */
  390.    strltrim(str2);
  391.    Wputf(BefAft, str1, str2);
  392.  
  393.    strcpy(str2, str1);                 /* Trim trailing blanks          */
  394.    strrtrim(str2);                     /* identical to strtrim()        */
  395.    Wputf(BefAft, str1, str2);
  396.  
  397.    strcpy(str2, str1);                 /* Trim leading and trailing     */
  398.    strbtrim(str2);
  399.    Wputf(BefAft, str1, str2);
  400. }  /* Dstrtrim() */
  401.  
  402. /*-----------------------[ String Changing demo ]-----------------------*/
  403.  
  404. LCL   VOID  CTYP  Dstrchg(NOARG)
  405. {
  406.    ChrP  str1 = "HelLo, worLd";
  407.    ChrP  str2 = "Hello, world";
  408.    ChrP  str3 = "xxxhElLoyyyHElLOzzz";
  409.    ChrP  str4 = "xxxhElloyyyhellozzz";
  410.    ChrT  str5[30];
  411.  
  412.    strcpy(str5, str1);                 /* Change all characters         */
  413.    strchg(str5, 'l', 'z');
  414.    Wputf(BefAft, str1, str5);
  415.  
  416.    strcpy(str5, str2);                 /* Change all case-independent   */
  417.    strichg(str5, 'l', 'z');            /* characters                    */
  418.    Wputf(BefAft, str2, str5);
  419.  
  420.    strcpy(str5, str3);                 /* Change case-independent       */
  421.    strischg(str5, "HeLlO", "goodbye"); /* substring                     */
  422.    Wputf(BefAft, str3, str5);
  423.  
  424.    strcpy(str5, str4);                 /* Change substring              */
  425.    strschg(str5, "hello", "goodbye");
  426.    Wputf(BefAft, str4, str5);
  427. }  /* Dstrchg() */
  428.  
  429. /*-----------------------[ String Checksum demo ]-----------------------*/
  430.  
  431. LCL   VOID  CTYP  Dstrchksum(NOARG)
  432. {
  433.    ChrP  str1 = "Hello, world";
  434.  
  435.    Wputf("Checksum is %lu, I-Checksum is %lu\n",
  436.         strchksum(str1), strichksum(str1));
  437. }  /* Dstrchksum() */
  438.  
  439. /*---------------------[ String Delete/Insert demo ]--------------------*/
  440.  
  441. LCL   VOID  CTYP  Dstrdel(NOARG)
  442. {
  443.    ChrP  str1 = "XyZHello, xYzworldXyZxYz";
  444.    ChrT  str2[35];
  445.  
  446.    strcpy(str2, str1);                 /* Delete first substring        */
  447.    strdel("xYz", str2);
  448.    Wputf(BefAft, str1, str2);
  449.  
  450.    strcpy(str2, str1);                 /* Delete all substrings         */
  451.    strdela("xYz", str2);
  452.    Wputf(BefAft, str1, str2);
  453.  
  454.    strcpy(str2, str1);                 /* Delete first case-independent */
  455.    stridel("xYz", str2);               /* substring                     */
  456.    Wputf(BefAft, str1, str2);
  457.  
  458.    strcpy(str2, str1);                 /* Delete all case-independent   */
  459.    stridela("xYz", str2);              /* substrings                    */
  460.    Wputf(BefAft, str1, str2);
  461.  
  462.    strcpy(str1, str2);                 /* Insert substring              */
  463.    strins("xYz", str2, 4);
  464.    Wputf(BefAft, str1, str2);
  465. }  /* Dstrdel() */
  466.  
  467. /*-----------------------[ String Inclusion demo ]----------------------*/
  468.  
  469. LCL   VOID  CTYP  Dstrinc(NOARG)
  470. {
  471.    ChrP  str1 = "Hello1HELLO2HeLlO3hElLo";
  472.    ChrP  str2 = "hello";
  473.  
  474.                                        /* Case-dependent substring      */
  475.    Wputf("str2 is %sincluded in str1\n",
  476.       ((strinc(str2, str1) == NULL) ? "not " : ""));
  477.                                        /* Case-independent substring    */
  478.    Wputf("str2 is %sincluded in str1\n",
  479.         ((striinc(str2, str1) == NULL) ? "not " : ""));
  480.                                        /* Case-dependent character      */
  481.    Wputf("There are %d occurrences of '%c' in str1\n",
  482.         strocc(str1, 'l'), 'l');
  483.                                        /* Case-independent character    */
  484.    Wputf("There are %d occurrences of '%c' in str1\n",
  485.         striocc(str1, 'l'), 'l');
  486.                                        /* Case-dependent substring      */
  487.    Wputf("str2 occurs in str1 %d times\n",
  488.         strsocc(str2, str1));
  489.                                        /* Case-independent substring    */
  490.    Wputf("str2 occurs in str1 %d times\n",
  491.         strisocc(str2, str1));
  492. }  /* Dstrinc() */
  493.  
  494. /*----------------------[ String Replacement demo ]---------------------*/
  495.  
  496. LCL   VOID  CTYP  Dstrsrep(NOARG)
  497. {
  498.    ChrP  str1 = "This is a big string";
  499.    ChrT  str2[25];
  500.  
  501.    strcpy(str2, str1);                 /* Case-dependent                */
  502.    strsrep(str2, "str", "th");
  503.    Wputf(BefAft, str1, str2);
  504.  
  505.    strcpy(str2, str1);                 /* Case-independent              */
  506.    strisrep(str2, "str", "th");
  507.    Wputf(BefAft, str1, str2);
  508. }  /* Dstrsrep() */
  509.  
  510. /*-----------------------[ String Substring demo ]----------------------*/
  511.  
  512. LCL   VOID  CTYP  Dstrmid(NOARG)
  513. {
  514.    ChrP  p;
  515.    ChrP  str = "Hello, world";
  516.  
  517.                                        /* Middle substring              */
  518.    Wputf("    %s\n", p = strmid(str, 5, 5));
  519.    free(p);
  520.                                        /* Left substring                */
  521.    Wputf("    %s\n", p = strleft(str, 5));
  522.    free(p);
  523.                                        /* Right substring               */
  524.    Wputf("    %s\n", p = strright(str, 5));
  525.    free(p);
  526. }  /* Dstrmid() */
  527.  
  528. /*---------------------[ String Justification demo ]--------------------*/
  529.  
  530. LCL   VOID  CTYP  Dstrljust(NOARG)
  531. {
  532.    ChrP  str1 = "     Hello, world     ";
  533.    ChrP  str2 = "Hello, world";
  534.    ChrT  str3[25];
  535.  
  536.    strcpy(str3, str1);                 /* Left justify                  */
  537.    strljust(str3);
  538.    Wputf(BefAft, str1, str3);
  539.  
  540.    strcpy(str3, str1);                 /* Right justify                 */
  541.    strrjust(str3);
  542.    Wputf(BefAft, str1, str3);
  543.  
  544.    strcpy(str3, str2);                 /* Rotate left                   */
  545.    strrol(str3, 3);
  546.    Wputf(BefAft, str2, str3);
  547.  
  548.    strcpy(str3, str2);                 /* Rotate right                  */
  549.    strror(str3, 3);
  550.    Wputf(BefAft, str2, str3);
  551.  
  552.    strcpy(str3, str2);                 /* Shift left                    */
  553.    strshl(str3, 3);
  554.    Wputf(BefAft, str2, str3);
  555.  
  556.    strcpy(str3, str2);                 /* Shift right                   */
  557.    strshr(str3, 3);
  558.    Wputf(BefAft, str2, str3);
  559. }  /* Dstrljust() */
  560.  
  561. /*---------------------[ String Miscellaneous demo ]--------------------*/
  562.  
  563. LCL   VOID  CTYP  Dstrblank(NOARG)
  564. {
  565.    ChrP  str1 = "  Hello  ";
  566.    ChrP  str2 = " \n  \t \r ";
  567.    ChrP  str3 = "Hello, world";
  568.    ChrP  str4 = "hElLo, wOrLd";
  569.    ChrT  str5[25];
  570.                                        /* Test for blank                */
  571.    Wputf(" str1 is %sblank\n", strblank(str1) ? "" : "not ");
  572.    Wputf(" str2 is %sblank\n", strblank(str2) ? "" : "not ");
  573.  
  574.    Wputf(" Before:    <%s>\n", str3);  /* Encrypt/Decrypt               */
  575.    strcode(str3, "34&*#Mdq");
  576.    Wputf(" Encrypted: <%s>\n", str3);
  577.    strcode(str3, "34&*#Mdq");
  578.    Wputf(" Decrypted: <%s>\n", str3);
  579.  
  580.    strcpy(str5, str3);                 /* Adjust size                   */
  581.    Wputf(" Before:  <%s>\n", str5);
  582.    strsetsz(str5, 20);
  583.    Wputf(" Len=20:  <%s>\n", str5);
  584.    strsetsz(str5, 5);
  585.    Wputf(" Len=5:   <%s>\n", str5);
  586.  
  587.    strcpy(str5, str4);                 /* Convert to Initial-capitals   */
  588.    struplow(str5);
  589.    Wputf(BefAft, str4, str5);
  590. }  /* Dstrblank() */
  591.  
  592. /*- end of Str_Demo.C --------------------------------------------------*/
  593.  
  594.