Functions for editing file names.
More...
Go to the source code of this file.
Functions for editing file names.
- Author
- Vesa Oikonen
Definition in file filename.c.
◆ filenameGetExtension()
char * filenameGetExtension |
( |
char * | s | ) |
|
Get the last extension of a filename.
Extension(s) in pathname are not searched for. Note that pointer points to the original string.
- Returns
- Pointer to the filename extension starting with '.', or NULL if no extension is found.
- Parameters
-
s | Pointer to string; string is not edited here. |
Definition at line 139 of file filename.c.
142 {
143 if(s==NULL || strlen(s)<1) return((char*)NULL);
144
145 char *pptr=strrchr(s, '/'); if(pptr==NULL) pptr=strrchr(s, '\\');
146 if(pptr==NULL) pptr=s; else pptr++;
147
148 char *cptr=strrchr(pptr, '.'); if(cptr==NULL) return(cptr);
149
150 if(strlen(pptr)==strlen(cptr)) return((char*)NULL);
151 return(cptr);
152}
◆ filenameGetExtensions()
char * filenameGetExtensions |
( |
char * | s | ) |
|
Get all extensions of a filename.
Extension(s) in pathname are not searched for. Note that pointer points to the original string.
- Returns
- Pointer to the filename extension starting with '.', or NULL if no extension is found.
- Parameters
-
s | Pointer to string; string is not edited here. |
Definition at line 164 of file filename.c.
167 {
168 if(s==NULL || strlen(s)<1) return((char*)NULL);
169
170 char *pptr=strrchr(s, '/'); if(pptr==NULL) pptr=strrchr(s, '\\');
171 if(pptr==NULL) pptr=s; else pptr++;
172
173
174 char *cptr=strchr(pptr+1, '.');
175 return(cptr);
176}
◆ filenameRmExtension()
int filenameRmExtension |
( |
char * | s | ) |
|
Remove the last extension from file name.
- Author
- Vesa Oikonen
- Returns
- 1 if extension was found (and removed), 0 if not.
- Parameters
-
Definition at line 34 of file filename.c.
37 {
38 if(s==NULL || strlen(s)<1) return(0);
39 char *cptr;
40 cptr=strrchr(s, '.'); if(cptr==NULL) return(0);
41 if(cptr[1]=='/' || cptr[1]=='\\') return(0);
42 *cptr=(char)0;
43 return(1);
44}
Referenced by filenameRmExtensions(), tpcHtmlUsage(), tpcPrintBuild(), tpcPrintUsage(), and tpcProgramName().
◆ filenameRmExtensions()
void filenameRmExtensions |
( |
char * | s | ) |
|
Remove all extensions from file name.
- Author
- Vesa Oikonen
- Parameters
-
Definition at line 51 of file filename.c.
54 {
55 if(s==NULL || strlen(s)<1) return;
57 return;
58}
int filenameRmExtension(char *s)
◆ filenameRmPath()
void filenameRmPath |
( |
char * | s | ) |
|
Remove path from file name.
- Author
- Vesa Oikonen
- Parameters
-
Definition at line 13 of file filename.c.
16 {
17 if(s==NULL || strlen(s)<1) return;
18 char *cptr;
19 cptr=strrchr(s, '/'); if(cptr==NULL) cptr=strrchr(s, '\\');
20 if(cptr==NULL) return;
21 cptr++;
22 int i, n=strlen(cptr);
23 for(i=0; i<n; i++, cptr++) s[i]=*cptr;
24 s[i]=(char)0;
25 return;
26}
Referenced by tpcHtmlUsage(), tpcPrintBuild(), tpcPrintUsage(), and tpcProgramName().
◆ fncasematch()
int fncasematch |
( |
const char * | fname, |
|
|
const char * | key ) |
Case-independent check whether string fname matches string key, which may contain wildcards ? and *.
- Returns
- 1 if strings do match and 0 if not.
- Parameters
-
fname | filename that is evaluated |
key | key string which may contain wildcards '?' and '*' |
Definition at line 100 of file filename.c.
105 {
106 if(fname==NULL || key==NULL) return(0);
107 char *key_ptr=NULL, *fname_ptr=NULL;
108
109 while((*key)&&(*fname)) {
110 if((*key=='?')||(toupper((int)*key)==toupper((int)*fname))) {
111 key++; fname++;
112 } else if(*key=='*') {
113 if(toupper((int)*(key+1))==toupper((int)*fname)) {
114 key_ptr=(char*)key++; fname_ptr=(char*)fname+1;
115 } else {
116 fname++;
117 if(*(key+1)=='?') {key_ptr=(char*)key++; fname_ptr=(char*)fname;}
118 }
119 } else if((key_ptr!=NULL) && (*fname_ptr)) {
120 return(
fnmatch(key_ptr, fname_ptr));
121 } else {
122 return(0);
123 }
124 }
125 if((*fname)&&(key_ptr!=NULL)) {
return(
fnmatch(key_ptr, fname_ptr));}
126 else {if(*key=='*') key++; return(toupper((int)*key)==toupper((int)*fname));}
127}
int fnmatch(const char *fname, const char *key)
Referenced by dftFormat(), dftWrite(), and rnameMatch().
◆ fnmatch()
int fnmatch |
( |
const char * | fname, |
|
|
const char * | key ) |
Check if string fname matches string key, which may contain wildcards ? and *.
- Returns
- 1 if strings do match and 0 if not.
- Parameters
-
fname | filename that is evaluated |
key | key string which may contain wildcards '?' and '*' |
Definition at line 66 of file filename.c.
71 {
72 if(fname==NULL || key==NULL) return(0);
73 char *key_ptr=NULL, *fname_ptr=NULL;
74
75 while((*key)&&(*fname)) {
76 if((*key=='?')||(*key==*fname)) {
77 key++; fname++;
78 } else if(*key=='*') {
79 if(*(key+1)==*fname) {key_ptr=(char*)key++; fname_ptr=(char*)fname+1;
80 } else {
81 fname++;
82 if(*(key+1)=='?') {key_ptr=(char*)key++; fname_ptr=(char*)fname;}
83 }
84 } else if((key_ptr!=NULL) && (*fname_ptr)) {
85 return(
fnmatch(key_ptr, fname_ptr));
86 } else {
87 return(0);
88 }
89 }
90 if((*fname)&&(key_ptr!=NULL)) {
return(
fnmatch(key_ptr, fname_ptr));}
91 else {if(*key=='*') key++; return(*key==*fname);}
92}
Referenced by fncasematch(), and fnmatch().