Mercurial > hg > dmlib
annotate minijss/jss.c @ 2313:866e036d7706
Clean up some code duplication.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 09 Jul 2019 11:52:15 +0300 |
parents | aa3738b121d1 |
children | 9807ae37ad69 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - General functions | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1163 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #include "jss.h" | |
7 #include <stdarg.h> | |
8 | |
9 | |
10 /* Memory and error handling functions | |
11 */ | |
12 | |
13 BOOL jssWarningIsFatal, jssErrorIsFatal; | |
14 | |
15 #ifndef JSS_LIGHT | |
1133
2af228303727
#ifdef out code that is not needed or used if JSS_LIGHT is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
16 |
520 | 17 void (*jssError) (int code, const char *filename, int linen, const char *fmt, ...); |
18 void (*jssWarning) (int code, const char *filename, int linen, const char *fmt, ...); | |
0 | 19 |
20 | |
520 | 21 void jssDefaultPrint(int code, const char *filename, int linen, const char *fmt) |
0 | 22 { |
23 fprintf(stderr, "JSS"); | |
24 if (filename) | |
25 fprintf(stderr, "[%s:%i]", filename, linen); | |
520 | 26 fprintf(stderr, "%s", fmt); |
0 | 27 if (code > 0) |
28 fprintf(stderr, "(%i)", code); | |
29 fprintf(stderr, ": "); | |
30 } | |
31 | |
32 | |
520 | 33 void jssDefaultError(int code, const char *filename, int linen, const char *fmt, ...) |
0 | 34 { |
35 va_list ap; | |
36 jssDefaultPrint(code, filename, linen, "E"); | |
37 | |
38 va_start(ap, fmt); | |
39 vfprintf(stderr, fmt, ap); | |
40 va_end(ap); | |
41 } | |
42 | |
43 | |
520 | 44 void jssDefaultWarning(int code, const char *filename, int linen, const char *fmt, ...) |
0 | 45 { |
46 va_list ap; | |
47 jssDefaultPrint(code, filename, linen, "W"); | |
48 | |
49 va_start(ap, fmt); | |
50 vfprintf(stderr, fmt, ap); | |
51 va_end(ap); | |
52 } | |
53 | |
1133
2af228303727
#ifdef out code that is not needed or used if JSS_LIGHT is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
54 #endif |
2af228303727
#ifdef out code that is not needed or used if JSS_LIGHT is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
55 |
0 | 56 |
57 /* System initialization | |
58 */ | |
59 int jssInit(void) | |
60 { | |
61 // Error handling | |
1133
2af228303727
#ifdef out code that is not needed or used if JSS_LIGHT is defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
62 #ifndef JSS_LIGHT |
0 | 63 jssWarningIsFatal = FALSE; |
64 jssErrorIsFatal = TRUE; | |
65 | |
66 jssError = jssDefaultError; | |
67 jssWarning = jssDefaultWarning; | |
68 #endif | |
69 | |
70 // Allocate global tables | |
71 | |
72 return DMERR_OK; | |
73 } | |
74 | |
75 | |
76 /* System shutdown | |
77 */ | |
78 int jssClose(void) | |
79 { | |
80 return DMERR_OK; | |
81 } |