Menu

[26e832]: / joe / builtin.c  Maximize  Restore  History

Download this file

85 lines (76 with data), 1.4 kB

 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
/*
* Built-in config files
* Copyright
* (C) 2006 Joseph H. Allen
*
* This file is part of JOE (Joe's Own Editor)
*/
#include "types.h"
JFILE *jfopen(const char *name, const char *mode)
{
if (name[0] == '*') {
int x;
for (x = 0; builtins[x]; x += 2) {
if (!zcmp(builtins[x], name + 1)) {
JFILE *j = (JFILE *)joe_malloc(SIZEOF(JFILE));
j->f = 0;
j->p = builtins[x + 1];
return j;
}
}
return 0;
} else {
FILE *f = fopen(name, mode);
if (f) {
JFILE *j = (JFILE *)joe_malloc(SIZEOF(JFILE));
j->f = f;
j->p = 0;
return j;
} else {
return 0;
}
}
}
int jfclose(JFILE *f)
{
int rtn = 0;
if (f->f)
rtn = fclose(f->f);
joe_free(f);
return rtn;
}
char *jfgets(char *buf,int len,JFILE *f)
{
if (f->f)
return fgets(buf, len, f->f);
else {
if (f->p[0]) {
ptrdiff_t x;
for (x = 0; f->p[x] && f->p[x] != '\n'; ++x)
buf[x] = f->p[x];
if (f->p[x] == '\n') {
buf[x++] = '\n';
}
buf[x] = 0;
f->p += x;
return buf;
} else
return 0;
}
}
char **jgetbuiltins(const char *suffix)
{
ptrdiff_t x;
ptrdiff_t sflen = 0;
char **result = NULL;
if (suffix)
sflen = zlen(suffix);
for (x = 0; builtins[x]; x += 2) {
const char *name = builtins[x];
ptrdiff_t nlen = zlen(name);
if (!suffix || (sflen <= nlen && !zcmp(suffix, &name[nlen - sflen]))) {
result = vaadd(result, vsncpy(NULL, 0, sz(name)));
}
}
return result;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.