-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrmsg.cc
115 lines (95 loc) · 2.61 KB
/
errmsg.cc
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
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include "errmsg.h"
#define numof(A) (sizeof(A)/sizeof((A)[0]))
static char *errorMessages[]={
"Cannot find the specified drive.",
"Too near terminate charactor.",
"Nyaos's internal error.",
"Can't remove file(s).",
"Can't make directory(s).",
"Can't write .SUBJECT extend attribute.",
"Can't write .COMMENTS extend attribute.",
"Invalid key name.",
"Invalid keys-set name.",
"Invalid function name.",
"Too long variable name.",
"Can't input-redirect on built-in commands.",
"Invalid variable name.",
"Can't open output-redirect/pipe.",
"Too few arguments.",
"Too many nesting.",
"No such file.",
"No such alias.",
"Bad %HOME% directory.",
"No such directory.",
"Unknown Option.",
"Dir Stack Empty.",
"No such file or directory.",
"Can't get current directory.",
"Too large stack number.",
"Missing.",
"No such environment variable.",
"Error occurs in foreach loop.",
"Not available in REXX Script",
"Memory allocation error.",
"Current version of NYAOS does not support DOS/VDM.",
"Can't get DBCS table from operating system.",
"Not found CMD.EXE",
"Bad parameter",
"Ambiguous Output Redirect",
"Event Not Found",
"Too Many Errors.",
"File exists.",
#ifdef VMAX
"Bad Command or Filename.",
#endif
};
static char *mountedErrorMessages[ numof( errorMessages ) ];
static bool inited=false;
void ErrMsg::mount(int x,const char *s)
{
if( inited==false ){
memset( mountedErrorMessages , 0 , sizeof(mountedErrorMessages) );
inited = true;
}
if( x >= (int)numof(errorMessages) )
return;
if( mountedErrorMessages[x] != NULL )
free(mountedErrorMessages[x]);
mountedErrorMessages[x] = strdup(s);
}
void ErrMsg::say(int x,...)
{
if( inited==false ){
memset( mountedErrorMessages , 0 , sizeof(mountedErrorMessages) );
inited = true;
}
va_list vp;
va_start(vp,x);
const char *s;
while( (s=va_arg(vp,const char*)) != NULL )
fprintf(stderr,"%s: ",s);
fprintf(stderr,"%s\n"
, mountedErrorMessages[x] != NULL
? mountedErrorMessages[x]
: errorMessages[x] );
va_end(vp);
}
extern char *fgets_chop(char *,int,FILE*);
int source_errmsg(const char *fname)
{
FILE *fp=fopen(fname,"rt");
if( fp==NULL )
return -1;
char buffer[256];
int n=0;
while( !feof(fp) && fgets_chop(buffer,sizeof(buffer),fp) != NULL ){
if( buffer[0] != '#' && buffer[0] != '\0' )
ErrMsg::mount(n++,buffer);
}
fclose(fp);
return n;
}