Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
CheckExtn.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file CheckExtn.c
5 
6  \version V1.21
7  \date 07.07.14
8  \brief General purpose routines
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1991-2014
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39  These are generally useful C routines, mostly string handling.
40 
41 **************************************************************************
42 
43  Usage:
44  ======
45 
46 **************************************************************************
47 
48  Revision History:
49  =================
50 - V1.1 08.02.91 Added KillLine()
51 - V1.2 10.02.91 Added setextn() and index()
52 - V1.3 20.03.91 Added Word()
53 - V1.4 28.05.92 ANSIed
54 - V1.5 22.06.92 Added tab check to Word(). Improved setextn().
55  Added WordN(). Documented other routines.
56 - V1.6 27.07.93 Corrected fsscanf() for double precision
57 - V1.7 07.10.93 Checks made on case before toupper()/tolower()
58  for SysV compatibility. Also index() becomes
59  chindex()
60 - V1.8 18.03.94 getc() -> fgetc()
61 - V1.9 11.05.94 Added GetFilestem(), upstrcmp(), upstrncmp() &
62  GetWord()
63 - V1.10 24.08.94 Added OpenStdFiles()
64 - V1.11 08.03.95 Corrected OpenFile() for non-UNIX
65 - V1.12 09.03.95 Added check on non-NULL filename in OpenFile()
66 - V1.13 17.07.95 Added countchar()
67 - V1.14 18.10.95 Moved YorN() to WindIO.c
68 - V1.15 06.11.95 Added StoreString(), InStringList() and FreeStringList()
69 - V1.16 22.11.95 Moved ftostr() to generam.c
70 - V1.17 15.12.95 Added QueryStrStr()
71 - V1.18 18.12.95 OpenStdFiles() treats filename of - as stdin/stdout
72 - V1.19 05.02.96 OpenStdFiles() allows NULL pointers instead if filenames
73 - V1.20 18.09.96 Added padchar()
74 - V1.21 07.07.14 Use bl prefix for functions By: CTP
75 
76 *************************************************************************/
77 /* Doxygen
78  -------
79  #GROUP General Programming
80  #SUBGROUP File IO
81  #FUNCTION blCheckExtn()
82  Check the extension of a filename. Case insensitive!
83 */
84 /************************************************************************/
85 /* Includes
86 */
87 
88 #include <string.h>
89 #include <stdlib.h>
90 #include "general.h"
91 #include "SysDefs.h"
92 
93 
94 /************************************************************************/
95 /* Defines and macros
96 */
97 
98 /************************************************************************/
99 /* Globals
100 */
101 
102 /************************************************************************/
103 /* Prototypes
104 */
105 /************************************************************************/
106 /*>BOOL blCheckExtn(char *string, char *ext)
107  -----------------------------------------
108 *//**
109 
110  \param[in] *string String to be checked for given extension
111  \param[in] *ext Extension to check for
112  \return Found?
113 
114  Check the extension of a filename. For use on machines like VAXes,
115  MS-DOS and Amigas, everything is converted to upper case first.
116 
117 - 18.06.93 Original By: ACRM
118 - 07.07.14 Use bl prefix for functions By: CTP
119 */
120 BOOL blCheckExtn(char *string,
121  char *ext)
122 {
123  int extl = strlen(ext),
124  strl = strlen(string);
125  char *buff1,
126  *buff2;
127  BOOL RetVal = TRUE;
128 
129  buff1 = (char *)malloc(strl * sizeof(char));
130  buff2 = (char *)malloc(extl * sizeof(char));
131 
132  if(buff1==NULL || buff2==NULL)
133  {
134  if(buff1) free(buff1);
135  if(buff2) free(buff2);
136  return(FALSE);
137  }
138 
139  blStringToUpper(string,buff1);
140  blStringToUpper(ext, buff2);
141 
142  if(strncmp(buff2,buff1+(strl-extl),extl))
143  RetVal = FALSE;
144 
145  free(buff1);
146  free(buff2);
147  return(RetVal);
148 }
149 
150 
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
void blStringToUpper(char *string1, char *string2)
#define FALSE
Definition: macros.h:223
BOOL blCheckExtn(char *string, char *ext)
Definition: CheckExtn.c:120
#define TRUE
Definition: macros.h:219
Header file for general purpose routines.
System-type variable type definitions.