-
Notifications
You must be signed in to change notification settings - Fork 3
/
appeasy.c
123 lines (116 loc) · 2.76 KB
/
appeasy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* --------------------------------------------------------------- APPEASY.C */
/* -------------------------------------------------------------- C includes */
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
/* ---------------------------------------------------------------- includes */
#include "cisis.h"
#include "globdef.h"
#include "appeasy.h"
#if UNIX
/* ----------------------------------------------------------------- strlwr */
char *strlwr(p)
char *p;
{
while (*p) {
if (isupper(*p)) *p = tolower(*p);
p++;
}
}
#endif /* UNIX */
/* ------------------------------------------------------------------ strall */
UCHAR *strall(p)
UCHAR *p;
{
UCHAR *new_p;
if (!p) return (UCHAR *)NULL;
new_p = (UCHAR *)ALLOC((ALLOPARM)strlen(p)+1);
if (!new_p) fatal("strall");
return strcpy(new_p,p);
}
/* ---------------------------------------------------------------- strdeall */
UCHAR *strdeall(p)
UCHAR *p;
{
if (p) FREE(p);
return (UCHAR *)NULL;
}
/* ---------------------------------------------------------------- strreall */
UCHAR *strreall(old,from)
UCHAR *old,*from;
{
if (old) FREE(old);
return strall(from);
}
/* ----------------------------------------------------------- easy_trimleft */
UCHAR *easy_trimleft(s)
UCHAR *s;
{
UCHAR *dup,
*p;
if (!s) return (UCHAR *)NULL;
dup = strall(s);
for (p = dup; *p == ' '; p++);
if (*p) strcpy(s,p);
strdeall(dup);
return s;
}
/* ---------------------------------------------------------- easy_trimright */
UCHAR *easy_trimright(s)
UCHAR *s;
{
UCHAR *p;
int len;
if (!s) return (UCHAR *)NULL;
if (!*s) return s;
for (len = strlen(s),p = s+(len-1); len && *p == ' '; len--,p--)
if (*p == ' ') *p = '\0';
return s;
}
/* ------------------------------------------------------------ easy_getfile */
BOOLEAN easy_getfile(file_name,buff,max,ignore)
UCHAR *file_name,
*buff;
long max;
UCHAR *ignore;
{
int handle,
i,
qtt;
#if UTF8
char * pHeader = buff;
char * pSkipHeader;
int sizeHeader = strlen(file_header_utf8);
int checkHeader = 1;
#endif // UTF8
handle = OPEN(file_name,O_BINARY|O_RDONLY|O_DENYNONE);
if (handle < 0) fatal(file_name);
for (i = 0; i < max; ) {
qtt = CIREAD(handle,buff,1);
if (qtt < 0) fatal(file_name);
if (qtt == 0) break;
if (ignore)
if (strchr(ignore,*buff)) continue;
if (*buff == CONTROL_Z) continue;
buff++;
i++;
#if UTF8
if ( checkHeader )
{
if ( i == sizeHeader )
{
pSkipHeader = skip_header_file_utf8(pHeader);
if ( pSkipHeader != pHeader )
{
buff = pHeader;
i = 0;
}
checkHeader = 0;
}
}
#endif // UTF8
}
*buff = '\0';
CLOSE(handle);
return (BOOLEAN)(i < max);
}