File: builtin.c

package info (click to toggle)
joe 3.7-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,300 kB
  • ctags: 2,460
  • sloc: ansic: 34,071; sh: 3,419; makefile: 138
file content (63 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (5)
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
/*
 *	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(unsigned char *name, 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((char *)name, (char *)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;
}

unsigned char *jfgets(unsigned char *buf,int len,JFILE *f)
{
	if (f->f)
		return (unsigned char *)fgets((char *)buf, len, f->f);
	else {
		if (f->p[0]) {
			int 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;
	}
}