FireBirdLib - Topfield TMS PVR TAP Programming Library
LogEntry.c
Go to the documentation of this file.
1
#include <fcntl.h>
2
#include <stdlib.h>
3
#include <unistd.h>
4
#include <stdio.h>
5
#include <string.h>
6
#include <sys/types.h>
7
#include <utime.h>
8
#include "
libFireBird.h
"
9
10
void
LogEntry
(
char
*FileName,
char
*ProgramName,
bool
Console,
eTimeStampFormat
TimeStampFormat,
char
*Text)
11
{
12
TRACEENTER
();
13
14
int
f;
15
char
TimeResult[40];
16
char
CRLF[] = {
'\r'
,
'\n'
};
17
byte
Sec;
18
byte
*ISOText;
19
char
AbsFileName[
FBLIB_DIR_SIZE
];
20
struct
utimbuf times;
21
22
if
(!Text)
23
{
24
TRACEEXIT
();
25
return
;
26
}
27
28
TimeFormat
(
Now
(&Sec), Sec, TimeStampFormat, TimeResult);
29
if
(TimeResult[0]) strcat(TimeResult,
" "
);
30
31
if
(FileName && FileName[0])
32
{
33
ConvertPathType
(FileName, AbsFileName,
PF_FullLinuxPath
);
34
f = open(AbsFileName, O_WRONLY | O_CREAT | O_APPEND);
35
if
(f >= 0)
36
{
37
write(f, TimeResult, strlen(TimeResult));
38
if
(Text && Text[0]) write(f, Text, strlen(Text));
39
write(f, CRLF, 2);
40
close(f);
41
42
//As the log would receive the Linux time stamp (01.01.2000), adjust to the PVR's time
43
times.actime =
PvrTimeToLinux
(
Now
(NULL));
44
times.modtime = times.actime;
45
utime(AbsFileName, ×);
46
}
47
}
48
49
if
(Console)
50
{
51
if
(TimeStampFormat !=
TIMESTAMP_NONE
)
TAP_Print
(TimeResult);
52
if
(ProgramName && ProgramName[0])
TAP_Print
(
"%s: "
, ProgramName);
53
54
if
(
isUTFToppy
())
55
{
56
if
(strlen(Text) < 510)
57
{
58
TAP_Print
(
"%s"
, Text);
59
}
60
else
61
{
62
char
*p = Text;
63
64
while
(*p)
65
{
66
int
l;
67
char
q;
68
69
l = strlen(p);
70
q = p[l];
71
p[l] =
'\0'
;
72
TAP_Print
(
"%s"
, p);
73
p[l] = q;
74
p += l;
75
}
76
}
77
TAP_Print
(
"\n"
);
78
}
79
else
80
{
81
//Max length is 512. If above, a buffer overflow may occur
82
StrToISOAlloc
(Text, &ISOText);
83
if
(ISOText && ISOText[0])
84
{
85
if
(strlen(ISOText) < 510)
86
{
87
TAP_Print
(
"%s"
, ISOText);
88
}
89
else
90
{
91
char
*p = ISOText;
92
93
while
(*p)
94
{
95
int
l;
96
char
q;
97
98
l = strlen(p);
99
if
(l > 510) l = 510;
100
101
q = p[l];
102
p[l] =
'\0'
;
103
TAP_Print
(
"%s"
, p);
104
p[l] = q;
105
p += l;
106
}
107
}
108
}
109
TAP_Print
(
"\n"
);
110
TAP_MemFree(ISOText);
111
}
112
}
113
114
TRACEEXIT
();
115
}
ConvertPathType
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
Definition:
ConvertPathType.c:4
LogEntry
void LogEntry(char *FileName, char *ProgramName, bool Console, eTimeStampFormat TimeStampFormat, char *Text)
Definition:
LogEntry.c:10
PvrTimeToLinux
dword PvrTimeToLinux(dword PVRTime)
Definition:
PvrTimeToLinux.c:3
libFireBird.h
isUTFToppy
bool isUTFToppy(void)
Definition:
isUTFToppy.c:3
FBLIB_DIR_SIZE
#define FBLIB_DIR_SIZE
Definition:
libFireBird.h:1871
TAP_Print
#define TAP_Print
Definition:
libFireBird.h:181
TimeFormat
char * TimeFormat(dword DateTime, byte Sec, eTimeStampFormat TimeStampFormat, char *Result)
Definition:
TimeFormat.c:4
TRACEEXIT
#define TRACEEXIT()
Definition:
libFireBird.h:1244
eTimeStampFormat
eTimeStampFormat
Definition:
libFireBird.h:94
TIMESTAMP_NONE
@ TIMESTAMP_NONE
Definition:
libFireBird.h:95
TRACEENTER
#define TRACEENTER()
Definition:
libFireBird.h:1243
StrToISOAlloc
void StrToISOAlloc(const byte *SourceString, byte **DestString)
Definition:
StrToISOAlloc.c:5
PF_FullLinuxPath
@ PF_FullLinuxPath
Definition:
libFireBird.h:1926
Now
dword Now(byte *Sec)
Definition:
Now.c:3
debug
LogEntry.c
Generated on Fri Apr 29 2022 13:34:01 for FireBirdLib - Topfield TMS PVR TAP Programming Library by
1.9.3