home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / text_cla / str.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  18.0 KB  |  986 lines

  1. /***********************************************************************
  2. **+
  3. **  Module Name:  str.c
  4. **
  5. **  Description:  Generic String Functions
  6. **
  7. **  Written by:  John Tal
  8. **
  9. **
  10. **  Modification history:
  11. **
  12. **  Date         Engineer     Mod #          Modification Description
  13. **
  14. **  1987         Tal          v 1.0-001      Initial release
  15. **-
  16. ***********************************************************************/
  17.  
  18.  
  19. #include <memincs.h>
  20. #include <fildir.h>
  21.  
  22. #include <string.h>
  23. #include <stdlib.h>
  24.  
  25.  
  26. /* Strncopy - like strncpy but also places null on end */
  27.  
  28. #ifdef C_ANSI
  29. INT Strncopy( char *szStr1,
  30.              char *szStr2,
  31.              INT   nLen)
  32. #else
  33. INT Strncopy( *szStr1,*szStr2,nLen)
  34. char * szStr1;
  35. char * szStr2;
  36. INT  nLen;
  37. #endif
  38. {
  39.    INT i;
  40.  
  41.    /* Strncpy does not put a NULL if the source is > than the Dest */
  42.  
  43.    strncpy( szStr1, szStr2, nLen );
  44.    i           = strlen( szStr2 );
  45.    i           = ( nLen > i ) ? i : ( nLen - 1 );
  46.    szStr1[ i ] = NULL;
  47.  
  48.    return ( 0 );
  49. }
  50.  
  51. /* Strnappend - like strncat but also places null on end */
  52.  
  53. #ifdef C_ANSI
  54. INT Strnappend( char *szStr1,
  55.              char *szStr2,
  56.              INT   nLen)
  57. #else
  58. INT Strnappend( *szStr1,*szStr2,nLen)
  59. char * szStr1;
  60. char * szStr2;
  61. INT  nLen;
  62. #endif
  63. {
  64.    INT i;
  65.    INT iLen;
  66.  
  67.    /* Strnappend does not put a NULL if the source is > than the Dest */
  68.  
  69.    iLen = strlen(szStr1);
  70.  
  71.    strncat( szStr1, szStr2, nLen );
  72.    i           = iLen + strlen(szStr2);
  73.    i           = ( nLen > (i + iLen)) ? (i + iLen) : ( (nLen + iLen)  );
  74.    szStr1[ i ] = NULL;
  75.  
  76.    return ( 0 );
  77. }
  78.  
  79.  
  80.  
  81. /****************************************************************************
  82.  
  83.     FUNCTION: StrAppendPath
  84.  
  85.     PURPOSE:  Append sz2 to sz1 returned as sz3
  86.  
  87. ****************************************************************************/
  88.  
  89. #ifdef C_ANSI
  90. INT StrAppendPath(char * sz1, char * sz2, char * sz3)
  91. #else
  92. INT StrAppendPath(sz1,sz2,sz3)
  93. char * sz1;
  94. char * sz2;
  95. char * sz3;
  96. #endif
  97. {
  98.     C_DEF_MODULE("StrAppendPath")
  99.  
  100.     char     cChar;
  101.  
  102.     strcpy(sz3,sz1);                     /* copy sz1 to sz3 */
  103.  
  104.     cChar = sz3[strlen(sz3)-1];
  105.  
  106.                                             /* if last char not \, then add \ */
  107.     if((cChar != DIR_SEPERATOR) &&
  108.        (sz2[0] != DIR_SEPERATOR) &&
  109.        (sz2[1] != ':')
  110.        )
  111.         strcat(sz3,DIR_SEPERATOR_STR);
  112.  
  113.       strcat(sz3,sz2);                    /* append sz2 to sz3 */
  114.  
  115.  
  116.     C_RETURN
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /****************************************************************************
  124.  
  125.     FUNCTION: StrBreakFName
  126.  
  127.     PURPOSE:  Seperate pathfilename into pathname and filename
  128.  
  129. ****************************************************************************/
  130.  
  131. #ifdef C_ANSI
  132. INT StrBreakFName(char * pcPathFile, char * pcPath, char * pcFile)
  133. #else
  134. INT StrBreakFName(pcPathFile,pcPath,pcFile)
  135. char * pcPathFile;
  136. char * pcPath;
  137. char * pcFile;
  138. #endif
  139. {
  140.     C_DEF_MODULE("StrBreakFName")
  141.  
  142.     INT  iPos;
  143.  
  144.  
  145.     iPos = strlen(pcPathFile) -1;
  146.  
  147.     while(iPos)
  148.     {
  149.         if(pcPathFile[iPos] == DIR_SEPERATOR)
  150.             break;
  151.  
  152.         iPos--;
  153.     }
  154.  
  155.  
  156.     if(iPos)
  157.     {
  158.         /* filename and path present, break them up into components */
  159.  
  160.         Strncopy(pcPath,pcPathFile,iPos+1);
  161.  
  162.         strcpy(pcFile,&pcPathFile[iPos + 1]);
  163.  
  164.     }
  165.     else
  166.     {
  167.         /* no path, filename only */
  168.  
  169.         strcpy(pcPath,"");
  170.         strcpy(pcFile,pcPathFile);
  171.     }
  172.  
  173.  
  174.     C_RETURN
  175. }
  176.  
  177.  
  178. /****************************************************************************
  179.  
  180.     FUNCTION: StrBreakFirst
  181.  
  182.     PURPOSE:  Seperate pathfilename into first dir and rest
  183.  
  184. ****************************************************************************/
  185.  
  186. #ifdef C_ANSI
  187. INT StrBreakFirst(char * pcPathFile, char * pcFirst, char * pcRest)
  188. #else
  189. INT StrBreakFirst(pcPathFile,pcFirst,pcRest)
  190. char * pcPathFile;
  191. char * pcFirst;
  192. char * pcRest;
  193. #endif
  194.  
  195. {
  196.     C_DEF_MODULE("StrBreakFName")
  197.  
  198.     INT  iPos = 0;
  199.     INT  ilength;
  200.  
  201.     while(1)
  202.     {
  203.         if((pcPathFile[iPos] == DIR_SEPERATOR) && (iPos != 0))
  204.             break;
  205.  
  206.       iPos++;
  207.  
  208.     ilength = strlen(pcPathFile);
  209.  
  210.     if (iPos >= ilength)
  211.          break;
  212.     }
  213.  
  214.  
  215.     if (iPos < ilength)
  216.     {
  217.         /* filename and path present, break them up into components */
  218.  
  219.         Strncopy(pcFirst,pcPathFile,iPos+1);
  220.  
  221.       if (iPos == ilength)
  222.          pcRest[0] = '\0';          /* no seperator found */
  223.       else
  224.            strcpy(pcRest,&pcPathFile[iPos + 1]);
  225.  
  226.     }
  227.     else
  228.     {
  229.         /* no path, filename only */
  230.  
  231.         strcpy(pcFirst,"");
  232.         strcpy(pcRest,pcPathFile);
  233.     }
  234.  
  235.  
  236.     C_RETURN
  237. }
  238.  
  239.  
  240.  
  241.  
  242. /* Misc String functions Tal - 1987 */
  243.  
  244. /****************************************************************************
  245.  
  246.     FUNCTION: StrReverse
  247.  
  248.     PURPOSE:  Reverse a string in place
  249.  
  250.               1234 becomes 4321
  251.  
  252. ****************************************************************************/
  253.  
  254. #ifdef C_ANSI
  255. VOID StrReverse(CHAR * s)
  256. #else
  257. VOID StrReverse(s)
  258. CHAR * s;
  259. #endif
  260. {
  261.  int c,i,j;
  262.  
  263.  for( i= 0, j=strlen(s)-1; i < j; i++, j--)
  264.   {
  265.     c = s[i];
  266.     s[i] = s[j];
  267.     s[j] = (char)c;
  268.   }
  269. }
  270.  
  271.  
  272. /****************************************************************************
  273.  
  274.     FUNCTION: StrItoa
  275.  
  276.     PURPOSE:  Turn an integer into a string (like sprintf("%d"))
  277.  
  278. ****************************************************************************/
  279.  
  280. #ifdef C_ANSI
  281. VOID StrItoa(CHAR * s, INT n)
  282. #else
  283. VOID StrItoa(s,n)     /*  itoa  */
  284. CHAR * s;
  285. INT n;
  286. #endif
  287. {
  288.  int i,sign;
  289.  
  290.  if ((sign = n) < 0)
  291.      n = -n;
  292.  i = 0;
  293.  do {
  294.     s[i++] = n % 10 + '0';
  295.  }  while ((n /= 10) > 0);
  296.  if (sign < 0)
  297.      s[i++] = '-';
  298.  s[i] = '\0';
  299.  StrReverse(s);
  300. }
  301.  
  302.  
  303. /****************************************************************************
  304.  
  305.     FUNCTION: StrSpaces
  306.  
  307.     PURPOSE:  Fill a string with spaces
  308.  
  309.               StrSpaces(s,5)   s = "     "
  310.  
  311. ****************************************************************************/
  312.  
  313. #ifdef C_ANSI
  314. VOID StrSpaces(CHAR * s, INT i)
  315. #else
  316. VOID StrSpaces(s,i)
  317. CHAR * s;
  318. int i;
  319. #endif
  320. {
  321.  int k;
  322.  
  323.  for ( k = 0; k < i; k++)
  324.      *s++ = ' ';
  325.  *s = '\0';
  326. }
  327.  
  328.  
  329. /****************************************************************************
  330.  
  331.     FUNCTION: StrLeft
  332.  
  333.     PURPOSE:  Take specified chars from left of source into dest
  334.  
  335.               StrLeft(dest,"This is a",2)   dest = "Th"
  336.  
  337. ****************************************************************************/
  338.  
  339. #ifdef C_ANSI
  340. VOID StrLeft(CHAR * dest, CHAR * source, INT i)
  341. #else
  342. VOID StrLeft(dest,source,i)
  343. CHAR * dest,* source;
  344. INT i;
  345. #endif
  346. {
  347.   int k;
  348.  
  349.   for (k = 0; k < i; k++)
  350.     * dest++ = source[k];
  351.     * dest++ = '\0';
  352. }
  353.  
  354.  
  355. /****************************************************************************
  356.  
  357.     FUNCTION: StrRight
  358.  
  359.     PURPOSE:  Take specified chars from right of source into dest
  360.  
  361.               StrRight(dest,"This is a",2)   dest = " a"
  362.  
  363. ****************************************************************************/
  364.  
  365. #ifdef C_ANSI
  366. VOID StrRight(CHAR * dest, CHAR * source, INT i)
  367. #else
  368. VOID StrRight(dest,source,i)
  369. CHAR * dest,* source;
  370. INT i;
  371. #endif
  372. {
  373.   int j,k,m,p;
  374.  
  375.   p = strlen(source);
  376.   m = MIN(p,i);
  377.   j = p - m;
  378.  
  379.   for (k = j; k < p; k++)
  380.     * dest++ = source[k];
  381.  
  382.   * dest++ = '\0';
  383. }
  384.  
  385.  
  386. /****************************************************************************
  387.  
  388.     FUNCTION: StrRtrim
  389.  
  390.     PURPOSE:  Remove spaces from right of string
  391.  
  392.               StrRtrim(dest,"  123  ")     dest = "  123"
  393.  
  394. ****************************************************************************/
  395.  
  396. #ifdef C_ANSI
  397. VOID StrRtrim(CHAR * dest, CHAR * source)
  398. #else
  399. VOID StrRtrim(dest,source)
  400. CHAR * dest,* source;
  401. #endif
  402. {
  403.   int k,y;
  404.  
  405.   y = strlen(source)-1;
  406.   while (source[y] == ' ')
  407.       y--;
  408.  
  409.   for (k = 0; k < y+1; k++)
  410.     * dest++ = source[k];
  411.     * dest++ = '\0';
  412. }
  413.  
  414.  
  415. /****************************************************************************
  416.  
  417.     FUNCTION: StrLtrim
  418.  
  419.     PURPOSE:  Remove spaces from left of string
  420.  
  421.               StrLtrim(dest,"  123  ")    dest = "123   "
  422.  
  423. ****************************************************************************/
  424.  
  425. #ifdef C_ANSI
  426. VOID StrLtrim(CHAR * dest, CHAR * source)
  427. #else
  428. VOID StrLtrim(dest,source)
  429. CHAR * dest,* source;
  430. #endif
  431. {
  432.   int k,m,y;
  433.  
  434.   m = strlen(source);
  435.   y = 0;
  436.  
  437.   while (source[y] == ' ')
  438.       y++;
  439.  
  440.   for (k = y; k < m; k++)
  441.     * dest++ = source[k];
  442.     * dest++ = '\0';
  443. }
  444.  
  445.  
  446. /****************************************************************************
  447.  
  448.     FUNCTION: StrRpad
  449.  
  450.     PURPOSE:  Pad with spaces on right
  451.  
  452.               StrRpad(dest,"123", 6)    dest = "123   "
  453.  
  454. ****************************************************************************/
  455.  
  456. #ifdef C_ANSI
  457. VOID StrRpad(CHAR * dest, CHAR * source, INT i)
  458. #else
  459. VOID StrRpad(dest,source,i)
  460. CHAR * dest,* source;
  461. int i;
  462. #endif
  463. {
  464.  int c,q;
  465.  
  466.  c = strlen(source);
  467.  if (c <= i)
  468.   {
  469.    strcpy(dest,source);
  470.  
  471.    for (q = c; q < i; q++)
  472.         *(dest+q) = ' ';
  473.    *(dest+i+1) = '\0';
  474.   }
  475. }
  476.  
  477. #ifdef C_ANSI
  478. VOID StrRpad2(CHAR * dest, CHAR * source, INT i)
  479. #else
  480. VOID StrRpad2(dest,source,i)
  481. CHAR * dest,* source;
  482. INT i;
  483. #endif
  484. {
  485.  CHAR temp1[255],temp2[255];
  486.  int k;
  487.  
  488.  strcpy(temp1,source);
  489.  k = abs(i-strlen(source));
  490.  StrSpaces(temp2,k);
  491.  strcat(temp1,temp2);
  492.  strncpy(dest,temp1,i);
  493. }
  494.  
  495. /****************************************************************************
  496.  
  497.     FUNCTION: StrLpad
  498.  
  499.     PURPOSE:  Pad with spaces on left
  500.  
  501.               StrRpad(dest,"123", 6)    dest = "   123"
  502.  
  503. ****************************************************************************/
  504.  
  505. #ifdef C_ANSI
  506. VOID StrLpad(CHAR * dest, CHAR * source, INT i)
  507. #else
  508. VOID StrLpad(dest,source,i)
  509. CHAR * dest, * source;
  510. int i;
  511. #endif
  512. {
  513.  int c,q,m;
  514.  
  515.  c = strlen(source);
  516.  if (c < i)
  517.     {
  518.      q = i-c;
  519.      StrSpaces(dest,q);
  520.      for (m = 0; m < q; m++)
  521.       *(dest+m+q) = source[m];
  522.  
  523.      *(dest+i+1) = '\0';
  524.     }
  525. }
  526.  
  527. /****************************************************************************
  528.  
  529.     FUNCTION: StrMid
  530.  
  531.     PURPOSE:  Like basic mid$()  extract from middle of string
  532.  
  533.               StrMid(dest,"123",2,2)    dest = "23"
  534.  
  535. ****************************************************************************/
  536.  
  537. #ifdef C_ANSI
  538. VOID StrMid(CHAR * dest, CHAR * source, INT beg, INT len)
  539. #else
  540. VOID StrMid(dest,source,beg,len)  /* like Mid$() */
  541. CHAR * dest,* source;
  542. INT beg,len;
  543. #endif
  544. {
  545.  int i,k;
  546.  
  547.  k = MIN(len,strlen(source));
  548.  for (i = 0; i < k; i++)
  549.        * dest++ = source[beg+i];
  550.        * dest = '\0';
  551. }
  552.  
  553. #if 0
  554. /****************************************************************************
  555.  
  556.     FUNCTION: StrCopy
  557.  
  558.     PURPOSE:  string copy
  559.  
  560. ****************************************************************************/
  561.  
  562. #ifdef C_ANSI
  563. VOID StrCopy(CHAR * dest, CHAR * source)
  564. #else
  565. VOID StrCopy(dest,source)
  566. CHAR * dest,* source;
  567. #endif
  568. {
  569.  int i,k;
  570.  
  571.  k = strlen(source);
  572.  for (i = 0; i < k; i++)
  573.        * dest++ = source[i];
  574.        * dest = '\0';
  575. }
  576.  
  577. /****************************************************************************
  578.  
  579.     FUNCTION: StrCat
  580.  
  581.     PURPOSE:  string cat
  582.  
  583. ****************************************************************************/
  584.  
  585. #ifdef C_ANSI
  586. VOID StrCat(CHAR * dest, CHAR * source)
  587. #else
  588. VOID StrCat(dest,source)
  589. CHAR * dest,* source;
  590. #endif
  591. {
  592.  int i,k,m;
  593.  
  594.  k = strlen(dest);
  595.  m = strlen(source);
  596.  for (i = 0; i < m; i++)
  597.      dest[k+i] = source[i];
  598.  
  599.  dest[k+m] = '\0';
  600. }
  601.  
  602. #endif
  603.  
  604. /****************************************************************************
  605.  
  606.     FUNCTION: StrInChar
  607.  
  608.     PURPOSE:  Find a character within a string
  609.  
  610.               StrInChar("123", '3')    return = [2]
  611.  
  612. ****************************************************************************/
  613.  
  614. #ifdef C_ANSI
  615. INT StrInChar(CHAR * source, CHAR find_char)
  616. #else
  617. INT StrInChar(source,find_char)   /* Instr$() */
  618. CHAR * source;
  619. CHAR find_char;
  620. #endif
  621. {
  622.   int i = 0;
  623.  
  624.   while ((source[i] != find_char) && (source[i] != '\0'))
  625.     i++;
  626.  
  627.   if (source[i] == find_char)
  628.     return(i);
  629.    else
  630.     return(-1);
  631. }
  632.  
  633. /****************************************************************************
  634.  
  635.     FUNCTION: StrPos
  636.  
  637.     PURPOSE:  Find one string within another, returns -1 if not in
  638.  
  639.               StrPos("1234567", "456" )   return = [3]
  640.  
  641. ****************************************************************************/
  642.  
  643. #ifdef C_ANSI
  644. INT StrPos(CHAR * s, CHAR *t)
  645. #else
  646. INT StrPos(s,t)   /* look for t in s */
  647. CHAR *s, *t;
  648. #endif
  649. {
  650.  int i,j,k;
  651.  
  652.  for (i = 0; s[i] != '\0'; i++)
  653.   {
  654.     for (j = i, k = 0; t[k] != '\0' && s[j]==t[k]; j++, k++);
  655.     if (t[k] == '\0')
  656.       return(i);
  657.    }
  658.     return(-1);
  659.  
  660. }
  661.  
  662.  
  663. /****************************************************************************
  664.  
  665.     FUNCTION: StrRep
  666.  
  667.     PURPOSE:  Replace characters within a string
  668.  
  669.               StrRep(dest,"_1_2_3", '_', ' ')    dest = " 1 2 3"
  670.  
  671. ****************************************************************************/
  672.  
  673. #ifdef C_ANSI
  674. VOID StrRep(CHAR * dest, CHAR * source, CHAR find_char, CHAR rep_char)
  675. #else
  676. VOID StrRep(dest,source,find_char,rep_char)  /* replace chars */
  677. CHAR * dest,* source;
  678. CHAR find_char,rep_char;
  679. #endif
  680. {
  681.   int k,m,n;
  682.  
  683.   m = strlen(source);
  684.   for (n = 0; n < m; n++)
  685.    *(dest+n) = source[n];
  686.    *(dest+m) = '\0';
  687.   while ((k = StrInChar(dest,find_char)) != -1)
  688.      *(dest+k) = rep_char;
  689.  
  690. }
  691.  
  692.  
  693. /****************************************************************************
  694.  
  695.     FUNCTION: StrRpt
  696.  
  697.     PURPOSE:  Repeat characters into a string
  698.  
  699.               StrRpt(dest,"0", 9)    dest = "000000000"
  700.  
  701. ****************************************************************************/
  702.  
  703. #ifdef C_ANSI
  704. VOID StrRpt(CHAR * dest, CHAR rpt_char, INT i)
  705. #else
  706. VOID StrRpt(dest,rpt_char,i)  /* repeating digits */
  707. CHAR * dest;
  708. CHAR rpt_char;
  709. INT i;
  710. #endif
  711. {
  712.   int q;
  713.  
  714.    for (q = 0; q < i; q++)
  715.         * dest++ = rpt_char;
  716.    * dest++ = '\0';
  717. }
  718.  
  719. #if 0
  720.  
  721. double fnround(x,m)
  722. double x;
  723. int m;
  724. {
  725.  int k;
  726.  double f,g;
  727.  double fabs();
  728.  
  729.  f = (fabs(x) + 0.00501);
  730.  k = (f * 100.0);
  731.  g = k / 100.0;
  732.  g = g * SGN(x);
  733.  
  734.  return(g);
  735. }
  736.  
  737. wait_key(command)
  738. CHAR *command;
  739. {
  740.   CHAR inky;
  741.  
  742.       inky = getcnb();
  743.       printf("%c",inky);
  744.  
  745.       if ( inky == '\00')
  746.         {
  747.           *command = getcnb();
  748.           return(1);
  749.         }
  750.        else
  751.         {
  752.          *command = inky;
  753.           return(0);
  754.         }
  755. }
  756.  
  757.  
  758. void print_tab_mid(fp,tab,str,beg,len)
  759. FILE *fp;
  760. int tab;
  761. CHAR *str;
  762. int beg,len;
  763. {
  764.  static int print_head;
  765.  static CHAR temp_s[255];
  766.  static CHAR s_s;
  767.  
  768.  int i,k,r,crlf = 0;
  769.  
  770.  if (tab < 0)
  771.    {
  772.     crlf = 1;
  773.     tab = abs(tab);
  774.    }
  775.  
  776.  k = MIN(len,strlen(str));
  777.  for (i = 0; i < k; i++)
  778.        temp_s[i] = str[beg+i];
  779.        temp_s[k] = '\0';
  780.  
  781.  r = tab-print_head;
  782.  if (r > 1)
  783.   {
  784.    StrSpaces(s_s,r);
  785.    fprintf(fp,s_s);    /* advance spaces from last position to new tab */
  786.   }
  787.  if (r > -1)
  788.   {
  789.    fprintf(fp,temp_s);    /* print data */
  790.    print_head = (print_head + r + strlen(str));
  791.                        /* increment print_head for next read */
  792.    }
  793.  if (r < 0)
  794.     {
  795.      fprintf("\n");    /* do newline if tab too close */
  796.      StrSpaces(s_s,tab);
  797.      fprintf(fp,temp_s);
  798.      print_head = tab + strlen(temp_s);
  799.     }
  800.  if (crlf)
  801.   {
  802.    fprintf(fp,"\n");
  803.    print_head = 1;
  804.   }
  805.  
  806. }
  807.  
  808.  
  809.  
  810. void print_tab(fp,tab,str)
  811. FILE *fp;
  812. int tab;
  813. CHAR *str;
  814. {
  815.  static int print_head;
  816.  static CHAR s_s;
  817.  
  818.  int k,r,crlf = 0;
  819.  
  820.  if (tab < 0)
  821.    {
  822.     crlf = 1;
  823.     tab = abs(tab);
  824.    }
  825.  k = strlen(str);
  826.  r = tab-print_head;
  827.  if (r > 1)
  828.   {
  829.    StrSpaces(s_s,r);
  830.    fprintf(fp,s_s);    /* advance spaces from last position to new tab */
  831.   }
  832.  if (r > -1)
  833.   {
  834.    fprintf(fp,str);    /* print data */
  835.    print_head = (print_head + r + strlen(str));
  836.                        /* increment print_head for next read */
  837.    }
  838.  if (r < 0)
  839.     {
  840.      fprintf("\n");    /* do newline if tab too close */
  841.      StrSpaces(s_s,tab);
  842.      fprintf(fp,str);
  843.      print_head = tab + strlen(str);
  844.     }
  845.  if (crlf)
  846.   {
  847.    fprintf(fp,"\n");
  848.    print_head = 1;
  849.   }
  850.  
  851. }
  852.  
  853. void print_mid(source,beg,len)
  854. CHAR * source;
  855. int beg,len;
  856. {
  857.  int i,j;
  858.  j = MIN(strlen(source),(beg+len));
  859.  for (i = beg; i < j; i++)
  860.       putchar(source[i]);
  861. }
  862.  
  863. void print_midrtrm(source,beg,len)
  864. CHAR * source;
  865. int beg,len;
  866. {
  867.  int i,j;
  868.  static CHAR temp_1[255],temp_2[255];
  869.  
  870.  copy_s(temp_1,source);
  871.  rtrm(temp_2,temp_1);
  872.  j = MIN(strlen(temp_2),(beg+len));
  873.  for (i = beg; i < j; i++)
  874.       putchar(temp_2[i]);
  875. }
  876.  
  877. CHAR mid_asn(dest,beg,len,source)
  878. CHAR * dest;
  879. int beg,len;
  880. CHAR * source;
  881. {
  882.  int i,k,p,x;
  883.  static CHAR temp_s[255];
  884.  
  885.  k = MIN(len,strlen(source));
  886.  p = strlen(dest);
  887.  if (p == 0)
  888.   {
  889.    StrSpaces(dest,beg);
  890.    p = beg;
  891.   }
  892.  x = beg - p;
  893.  if ( x > 0 )
  894.    {
  895.     rpad(temp_s,dest,beg);
  896.     copy_s(dest,temp_s);
  897.    }
  898.  for (i = beg; i < beg+len; i++)
  899.        dest[i] = source[i-beg];
  900.  if (strlen(dest) <= (beg+len) )
  901.        dest[beg+len] = '\0';
  902. }
  903.  
  904. CHAR mid_asn_mid(dest,beg1,len1,source,beg2,len2)
  905. CHAR * dest;
  906. int beg1,len1;
  907. CHAR * source;
  908. int beg2,len2;
  909. {
  910.  int i,j,k,p,x;
  911.  static CHAR temp_s[255];
  912.  
  913.  k = MIN(len1,strlen(source));
  914.  p = strlen(dest);
  915.  
  916.  if (p == 0)
  917.   {
  918.    StrSpaces(dest,beg1);
  919.    p = beg1;
  920.   }
  921.  
  922.  x = beg1 - p;
  923.  
  924.  if ( x > 0 )
  925.    {
  926.     rpad(temp_s,dest,beg1);
  927.     copy_s(dest,temp_s);
  928.    }
  929.  
  930.  for (i = beg1, j = beg2; i < beg1+len1; i++, j++)
  931.        dest[i] = source[j];
  932.  if (strlen(dest) <= (beg1+len1) )
  933.        dest[beg1+len1] = '\0';
  934. }
  935.  
  936.  
  937.  
  938.  
  939. #ifdef UNIX
  940. int strstr(pcStr1,pcStr2)
  941. char * pcStr1;
  942. char * pcStr2;
  943. {
  944.    int iLen1;
  945.    int iLen2;
  946.    int iNdx1;
  947.    int iNdx2;
  948.    int iRet = C_FALSE;
  949.    int iMatches;
  950.  
  951.    iLen1 = strlen(pcStr1);  /* main string */
  952.    iLen2 = strlen(pcStr2);  /* string being looked for in main string */
  953.  
  954.    for(iNdx1 = 0; iNdx1 < iLen1; iNdx1++)
  955.    {
  956.        iMatches = 0;
  957.  
  958.        for(iNdx2 = 0; (iNdx2 < iLen2) && (iNdx1+iNdx2 < iLen1); iNdx2++)
  959.           if(pcStr1[iNdx1 + iNdx2] == pcStr2[iNdx2])
  960.              iMatches++;
  961.  
  962.        if(iMatches == iLen2)
  963.        {
  964.           iRet = C_TRUE;
  965.           break;
  966.        }
  967.     }
  968.  
  969.     return(iRet);
  970.  
  971. }
  972. #endif
  973.  
  974.  
  975.  
  976. #endif
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.