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