Skip to content

Commit 7ab5f4c

Browse files
committed
UNIX cleanup refactoring to fix unix console build
1 parent eabdb2d commit 7ab5f4c

25 files changed

+1836
-4489
lines changed

COPYING

+674
Large diffs are not rendered by default.

src/platform/unix/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ bin_PROGRAMS = sbasic
2727
sbasic_SOURCES = \
2828
dev_ndcfb.c \
2929
dev_genfb.c \
30-
device.c \
3130
dev_oss.c \
3231
dev_term.c \
3332
console_main.c \
33+
../../common/device.c \
3434
../../common/g_line.c \
3535
../../common/decomp.c
3636

@@ -40,4 +40,4 @@ if !WITH_WIN32
4040
sbasic_LDADD += -ldl
4141
endif
4242

43-
sbasic_DEPENDENCIES = ../libsb_common.a
43+
sbasic_DEPENDENCIES = $(top_srcdir)/src/common/libsb_common.a

src/platform/unix/chr2c

-14.3 KB
Binary file not shown.

src/platform/unix/chr2c.c

+46-51
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
11
#include <stdio.h>
22
#include <string.h>
33

4-
void change_ext(char *name, char *ext)
5-
{
6-
char *e = ext;
7-
char *p;
8-
9-
p = strrchr(name, '.');
10-
if ( *e == '.' )
11-
e ++;
12-
13-
if ( p ) {
14-
*(p+1) = '\0';
15-
strcat(name, e);
16-
}
17-
else {
18-
strcat(name, ".");
19-
strcat(name, e);
20-
}
4+
void change_ext(char *name, char *ext) {
5+
char *e = ext;
6+
char *p;
7+
8+
p = strrchr(name, '.');
9+
if (*e == '.')
10+
e++;
11+
12+
if (p) {
13+
*(p + 1) = '\0';
14+
strcat(name, e);
15+
} else {
16+
strcat(name, ".");
17+
strcat(name, e);
18+
}
2119
}
2220

23-
void font2c(const char *file_name)
24-
{
25-
FILE *fin, *fout;
26-
char new_name[1024];
27-
char buff[4096];
28-
int i;
29-
30-
fin = fopen(file_name, "rb");
31-
if ( fin ) {
32-
strcpy(new_name, file_name);
33-
change_ext(new_name, ".c");
34-
fout = fopen(new_name, "wb");
35-
36-
fread(buff, 4096, 1, fin);
37-
38-
fprintf(fout, "unsigned char font8x16[] = {\n");
39-
for ( i = 0; i < 4096; i ++ ) {
40-
fprintf(fout, "0x%02X, ", (unsigned char) buff[i]);
41-
if ( (i % 16) == 0 )
42-
fprintf(fout, "\n");
43-
}
44-
fprintf(fout, "0 };\n");
45-
46-
fclose(fin);
47-
fclose(fout);
48-
}
49-
else
50-
perror("font2c");
21+
void font2c(const char *file_name) {
22+
FILE *fin, *fout;
23+
char new_name[1024];
24+
char buff[4096];
25+
int i;
26+
27+
fin = fopen(file_name, "rb");
28+
if (fin) {
29+
strcpy(new_name, file_name);
30+
change_ext(new_name, ".c");
31+
fout = fopen(new_name, "wb");
32+
33+
fread(buff, 4096, 1, fin);
34+
35+
fprintf(fout, "unsigned char font8x16[] = {\n");
36+
for (i = 0; i < 4096; i++) {
37+
fprintf(fout, "0x%02X, ", (unsigned char)buff[i]);
38+
if ((i % 16) == 0)
39+
fprintf(fout, "\n");
40+
}
41+
fprintf(fout, "0 };\n");
42+
43+
fclose(fin);
44+
fclose(fout);
45+
} else
46+
perror("font2c");
5147
}
5248

53-
int main(int argc, char *argv[])
54-
{
55-
int i;
49+
int main(int argc, char *argv[]) {
50+
int i;
5651

57-
for ( i = 1; i < argc; i ++ )
58-
font2c(argv[i]);
59-
return 0;
52+
for (i = 1; i < argc; i++)
53+
font2c(argv[i]);
54+
return 0;
6055
}

src/platform/unix/console_main.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ void remove_temp_file(void) {
4949
void set_bas_dir(const char *cwd, const char *bas_file) {
5050
char bas_dir[OS_PATHNAME_SIZE + 10];
5151
int path_len = strrchr(bas_file, OS_DIRSEP) - bas_file;
52-
52+
5353
bas_dir[0] = 0;
5454
strcat(bas_dir, "BASDIR=");
55-
55+
5656
if (bas_file[0] == OS_DIRSEP) {
5757
// full path
5858
strncat(bas_dir, bas_file, path_len + 1);
@@ -312,7 +312,6 @@ int process_options(int argc, char *argv[]) {
312312
// check if it is a terminal.
313313
opt_interactive = 1;
314314
}
315-
316315
#if defined(_Win32) || defined(_DOS)
317316
char *slash = strchr(argv[0], OS_DIRSEP);
318317
if (slash) {
@@ -327,7 +326,7 @@ int process_options(int argc, char *argv[]) {
327326
#elif defined(_UnixOS)
328327
sprintf(g_file, "%ctmp%csb%d.bas", OS_DIRSEP, OS_DIRSEP, getpid());
329328
#else
330-
sprintf(g_file, "sb%d.bas", getpid()); // for minimal GNU systems like
329+
sprintf(g_file, "sb%d.bas", getpid()); // for minimal GNU systems like
331330
// MINGW
332331
#endif
333332

@@ -390,7 +389,6 @@ int MAIN_FUNC(int argc, char *argv[]) {
390389
if (!opt_quiet) {
391390
printf("SmallBASIC version %s, use -h for help\n", SB_STR_VER);
392391
}
393-
394392
// run it
395393
if (!opt_interactive) {
396394
sbasic_main(g_file);

0 commit comments

Comments
 (0)