FireBirdLib - Topfield TMS PVR TAP Programming Library
SeparateFileNameComponents.c
Go to the documentation of this file.
1#include <ctype.h>
2#include <string.h>
3#include <stdlib.h>
4#include "libFireBird.h"
5
6void SeparateFileNameComponents(const char *FileName, char *Path, char *Name, char *Ext, int *Index, bool *isRec, bool *isDel)
7{
9
10 char *dot, *slash;
11
12 if(!FileName || !*FileName || !Name)
13 {
14 TRACEEXIT();
15 return;
16 }
17
18 slash = strrchr(FileName, '/');
19 if(slash)
20 {
21 if(Path)
22 {
23 char *c;
24
25 strcpy(Path, FileName);
26 c = strrchr(Path, '/');
27 if(c) c[1] = '\0';
28 }
29 strcpy(Name, slash + 1);
30 }
31 else
32 {
33 if(Path) Path[0] = '\0';
34 strcpy(Name, FileName);
35 }
36
37 if(isDel)
38 {
39 *isDel = FALSE;
40 if(StringEndsWith(Name, ".del"))
41 {
42 *isDel = TRUE;
43 Name[strlen(Name) - 4] = '\0';
44 }
45 }
46
47 if(StringEndsWith(Name, ".rec.inf")) Name[strlen(Name) - 4] = '\0';
48 if(StringEndsWith(Name, ".mpg.inf")) Name[strlen(Name) - 4] = '\0';
49 if(StringEndsWith(Name, ".ts.inf")) Name[strlen(Name) - 4] = '\0';
50
51 if(StringEndsWith(Name, ".rec.nav")) Name[strlen(Name) - 4] = '\0';
52 if(StringEndsWith(Name, ".mpg.nav")) Name[strlen(Name) - 4] = '\0';
53 if(StringEndsWith(Name, ".ts.nav")) Name[strlen(Name) - 4] = '\0';
54
55 if(isRec) *isRec = HDD_isRecFileName(Name);
56
57 dot = strrchr(Name, '.');
58 if(Ext)
59 {
60 Ext[0] = '\0';
61 if(dot) strcpy(Ext, dot);
62 }
63 if(dot) *dot = '\0';
64
65 if(Index)
66 {
67 *Index = 0;
68 if(strlen(Name) > 2)
69 {
70 if((Name[strlen(Name) - 2] == '-') && isdigit(Name[strlen(Name) - 1]) && (Name[strlen(Name) - 1] != '0'))
71 {
72 *Index = strtol(&Name[strlen(Name) - 1], NULL, 10);
73 Name[strlen(Name) - 2] = '\0';
74 }
75 }
76 }
77
78 TRACEEXIT();
79}
void SeparateFileNameComponents(const char *FileName, char *Path, char *Name, char *Ext, int *Index, bool *isRec, bool *isDel)
bool HDD_isRecFileName(const char *FileName)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
bool StringEndsWith(const char *text, const char *postfix)
Definition: StringEndsWith.c:4