The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
SetExtn.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file SetExtn.c
5 
6  \version V1.21
7  \date 07.07.14
8  \brief
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 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.1 08.02.91 Added KillLine()
50 - V1.2 10.02.91 Added setextn() and index()
51 - V1.3 20.03.91 Added Word()
52 - V1.4 28.05.92 ANSIed
53 - V1.5 22.06.92 Added tab check to Word(). Improved setextn().
54  Added WordN(). Documented other routines.
55 - V1.6 27.07.93 Corrected fsscanf() for double precision
56 - V1.7 07.10.93 Checks made on case before toupper()/tolower()
57  for SysV compatibility. Also index() becomes
58  chindex()
59 - V1.8 18.03.94 getc() -> fgetc()
60 - V1.9 11.05.94 Added GetFilestem(), upstrcmp(), upstrncmp() &
61  GetWord()
62 - V1.10 24.08.94 Added OpenStdFiles()
63 - V1.11 08.03.95 Corrected OpenFile() for non-UNIX
64 - V1.12 09.03.95 Added check on non-NULL filename in OpenFile()
65 - V1.13 17.07.95 Added countchar()
66 - V1.14 18.10.95 Moved YorN() to WindIO.c
67 - V1.15 06.11.95 Added StoreString(), InStringList() and FreeStringList()
68 - V1.16 22.11.95 Moved ftostr() to generam.c
69 - V1.17 15.12.95 Added QueryStrStr()
70 - V1.18 18.12.95 OpenStdFiles() treats filename of - as stdin/stdout
71 - V1.19 05.02.96 OpenStdFiles() allows NULL pointers instead if filenames
72 - V1.20 18.09.96 Added padchar()
73 - V2.21 07.07.14 Use bl prefix for functions By: CTP
74 
75 *************************************************************************/
76 /* Doxygen
77  -------
78  #GROUP General Programming
79  #SUBGROUP File IO
80  #FUNCTION blSetExtn()
81  Force a filename extension. Modifies the input filename to have the
82  specified extension.
83 */
84 /************************************************************************/
85 /* Includes
86 */
87 #include <string.h>
88 #include "SysDefs.h"
89 
90 /************************************************************************/
91 /* Defines and macros
92 */
93 
94 /************************************************************************/
95 /* Globals
96 */
97 
98 /************************************************************************/
99 /* Prototypes
100 */
101 
102 
103 /************************************************************************/
104 /*>void blSetExtn(char *File, char *Ext)
105  -------------------------------------
106 *//**
107 
108  \param[in,out] *File Filename to be modified
109  \param[in] *Ext New extension
110 
111  Force a filename extension. Modifies the input filename to have the
112  specified extension. Note that the string File should be large enough
113  to cope with longer extensions, if required. Searches back through the
114  string to find a `.' Anything after this is replaced with the
115  specified extension. The search for a `.' stops as soon as a `/',`\',
116  or a `:' is found as these indicate a directory. If no `.' is found,
117  one is appended to the string and the extension is added.
118 
119 - 10.02.91 Original
120 - 28.05.92 ANSIed
121 - 22.06.92 Improved to work from end of string for Unix filenames, etc.
122 - 11.03.94 Added check on '\' for MS-DOS
123 - 07.07.14 Use bl prefix for functions By: CTP
124 */
125 void blSetExtn(char *File, char *Ext)
126 {
127  int pos,
128  InDir = FALSE;
129 
130  pos = strlen(File);
131 
132  while(--pos >= 0 && File[pos] != '.')
133  {
134  if(File[pos] == ':' || File[pos] == '/' || File[pos] == '\\')
135  {
136  InDir = TRUE;
137  break;
138  }
139  }
140 
141  if(pos >= 0 && !InDir) /* Dot found, change extension */
142  {
143  strcpy(File+pos+1, Ext);
144  File[pos+1+strlen(Ext)] = '\0';
145  }
146  else /* No dot found, just append ext. */
147  {
148  strcat(File,".");
149  strcat(File,Ext);
150  }
151 }
152 
153 
#define FALSE
Definition: macros.h:223
void blSetExtn(char *File, char *Ext)
Definition: SetExtn.c:125
#define TRUE
Definition: macros.h:219
System-type variable type definitions.