-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiofile.cpp
More file actions
150 lines (112 loc) · 2.53 KB
/
iofile.cpp
File metadata and controls
150 lines (112 loc) · 2.53 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// awBASIC interpreter (c) 2002 Anthony J. Wood
// www.awsoftware.org
//
// This file is part of awbasic.
// awbasic is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
#include <stdio.h>
#include "basic.h"
struct IoConsoleFile {
struct IoConsole io;
FILE *fp;
};
void IoFilePutc(IoConsole* io, char c)
{
FILE* fp;
fp=((IoConsoleFile*)io)->fp;
fputc(c, fp);
}
/*
void IoFilePutstr(IoConsole* io, char* cp)
{
FILE* fp;
fp=((IoConsoleFile*)io)->fp;
if (fp==NULL)
{
fp = IoFileOpenFile();
((IoConsoleFile*)io)->fp = fp;
}
if (fp==NULL)
return;
fprintf(fp, "%s",cp);
}
*/
void IoFileWriteClose(IoConsole* io)
{
fclose(((IoConsoleFile*)io)->fp);
}
FILE* IoFileOpenFile(char *in_fname)
{
char fname[400];
FILE* fp = NULL;
if (in_fname)
{
fp = fopen(in_fname, "wt");
}
else
{
if (WinGetFileName(fname, sizeof(fname), 0))
fp = fopen(fname, "wt");
}
return fp;
}
struct IoConsole* IoFileWriteOpen(char *in_fname)
{
static struct IoConsoleFile iof;
iof.io.io_inkey = NULL;
iof.io.io_putc = IoFilePutc;
iof.io.io_chk_brk = NULL;
iof.io.io_getc = NULL;
iof.io.io_close = IoFileWriteClose;
iof.io.io_width = 0;
iof.io.io_height = 0;
iof.io.cursor=0;
/* Window functions that are not needed for simple streaming console */
iof.io.io_draw_range= NULL;
iof.io.io_peek_keyboard=NULL;
iof.io.cursor_visable = FALSE;
iof.io.video_mem = NULL;
/* values specific to this console type */
iof.fp = IoFileOpenFile(in_fname);
if (iof.fp)
return (IoConsole*)&iof;
else
return NULL;
}
/*****************************************************/
void IoNullPutc(IoConsole* io, char c)
{
return;
}
char IoNullInkey(struct IoConsole* io)
{
return 0;
}
char IoNullGetc(struct IoConsole* io)
{
return 0;
}
int IoNullChkBrk(struct IoConsole* io)
{
return ERR_OKAY;
}
struct IoConsole* IoNullOpen(void)
{
static struct IoConsole ionull;
ionull.io_inkey = IoNullInkey;
ionull.io_putc = IoNullPutc;
ionull.io_chk_brk = IoNullChkBrk;
ionull.io_getc = IoNullGetc;
ionull.io_close = NULL; // null okay, just won't call any close function
ionull.io_width = 0;
ionull.io_height = 0;
ionull.cursor=0;
/* Window functions that are not needed for simple streaming console */
ionull.io_draw_range= NULL;
ionull.io_peek_keyboard=NULL;
ionull.cursor_visable = FALSE;
ionull.video_mem = NULL;
return &ionull;
}