home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / zoo / stuff2.arc / SLASH.C < prev    next >
C/C++ Source or Header  |  1989-03-21  |  2KB  |  65 lines

  1. /*
  2. Stuff 2.0.
  3.  
  4. Checksum: 1637129305 (verify with "brik")
  5.  
  6. (C) Copyright 1988 Rahul Dhesi.  Permission is granted to copy and
  7. distribute this file in modified or unmodified form, whether for
  8. noncommercial or commercial use, provided (a) this copyright notice
  9. is preserved, (b) no attempt is made to restrict redistribution of
  10. this file, and (c) this file is not distributed as part of any
  11. collection whose redistribution is restricted by a compilation
  12. copyright.
  13. */
  14.  
  15. #include "stuff.h"
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <assert.h>
  19. #include <stddef.h>
  20.  
  21. /*
  22. forceslash() Removes slashes from a pathname
  23. */
  24. void forceslash (char *pathname)
  25. {
  26.    char *s;
  27.    for (s = pathname;  *s != '\0';  s++)
  28.       if (*s == '\\')
  29.          *s = '/';
  30. }
  31.  
  32. /*
  33. findlast() finds last occurrence of character from 'component' in 'str'
  34. */
  35.  
  36. char *findlast (char *str, char *component)
  37. {
  38.    char *p;
  39.  
  40.    assert (str != NULL && *str != '\0');
  41.    assert (component != NULL && *component != '\0');
  42.  
  43.    if (str == NULL || *str == '\0' || component == NULL || *component == '\0')
  44.       return (NULL);
  45.    p = str + strlen (str) - 1;      /* p points to end of str */
  46.  
  47.    while (p > str && strchr (component, *p) == NULL)
  48.       p--;
  49.    
  50.    /* exit loop when found char, or reached beginning, or both */
  51.    if (strchr (component, *p) != NULL)
  52.       return (p);
  53.    else
  54.       return (NULL);
  55. }
  56.  
  57. /* returns pointer to last char of string */
  58. char *lastptr (char *str)
  59. {
  60.    if (str == NULL || *str == '\0')
  61.       return (NULL);
  62.    else
  63.       return (str + strlen(str) - 1);
  64. }
  65.