home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / u_fileextn.c < prev    next >
C/C++ Source or Header  |  2008-07-13  |  1KB  |  76 lines

  1. /* u_fileextn.c
  2.  *
  3.  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #include "syshdrs.h"
  9. #ifdef PRAGMA_HDRSTOP
  10. #    pragma hdrstop
  11. #endif
  12.  
  13. #define _CRT_SECURE_NO_WARNINGS 1
  14.  
  15. int
  16. FilenameExtensionIndicatesASCII(const char *const pathName, const char *const extnList)
  17. {
  18.     const char *extn;
  19.     char *cp;
  20.     int c;
  21.     char extnPattern[16];
  22.  
  23.     if ((pathName == NULL) || (pathName[0] == '\0'))
  24.         return (0);
  25.  
  26.     extn = pathName + strlen(pathName) - 1;
  27.     forever {
  28.         if (extn <= pathName)
  29.             return (0);    /* End of pathname, no extension. */
  30.         c = (int) *--extn;
  31.         if (IsLocalPathDelim(c))
  32.             return (0);    /* End of filename, no extension. */
  33.         if (c == '.') {
  34.             extn += 1;
  35.             break;
  36.         }
  37.     }
  38.     if (strlen(extn) > (sizeof(extnPattern) - 2 - 1 - 1)) {
  39.         return (0);
  40.     }
  41. #ifdef HAVE_SNPRINTF
  42.     snprintf(extnPattern, sizeof(extnPattern),
  43. #else
  44.     sprintf(extnPattern,
  45. #endif
  46.         "|.%s|",
  47.         extn
  48.     );
  49.  
  50.     cp = extnPattern;
  51.     forever {
  52.         c = *cp;
  53.         if (c == '\0')
  54.             break;
  55.         if (isupper(c)) {
  56.             c = tolower(c);
  57.             *cp++ = (char) c;
  58.         } else {
  59.             cp++;
  60.         }
  61.     }
  62.  
  63.     /* Extension list is specially formatted, like this:
  64.      *
  65.      *     |ext1|ext2|ext3|...|extN|
  66.      *
  67.      * I.e, each filename extension is delimited with 
  68.      * a pipe, and we always begin and end the string
  69.      * with a pipe.
  70.      */
  71.     if (strstr(extnList, extnPattern) != NULL) {
  72.         return (1);
  73.     }
  74.     return (0);
  75. }    /* FilenameExtensionIndicatesASCII */
  76.