Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c7fcf6b4e000dfc1a63280f3ca47c38eedddc260
[simgrid.git] / tools / tesh2 / src / error.c
1 #include <error.h>
2
3 typedef struct s_entry
4 {
5         const char* name;
6         int code;
7         const char* string;
8 }entry_t;
9
10
11 static const
12 entry_t err[] =
13 {
14         {"ENOENT", ENOENT, "No such file of directory."},
15         {"ENOMEM", ENOMEM,"Insufficient memory is available."},
16         {"EACCES", EACCES, "Read or search permission was denied for a component of the pathname."},
17         {"ENOTDIR", ENOTDIR, "Not a directory."},
18         {"EREAD", EREAD, "a read pipe operation failed"},
19         {"EREADPIPE", EREADPIPE, "a pipe used to read from the stdout of a command is broken"},
20         {"ETIMEOUT", ETIMEOUT, "a command is timeouted"},
21         {"EWRITE", EWRITE, "a write operation failed"},
22         {"EWRITEPIPE", EWRITEPIPE, "a pipe used to write to the stdin of a command is broken"},
23         {"EEXEC", EEXEC, "can't execute a command"},
24         {"EWAIT", EWAIT, "wait function failed"},
25         {"ECMDNOTFOUND", ECMDNOTFOUND, "command is not found"},
26         {"EEXITCODENOTMATCH", EEXITCODENOTMATCH, "exit codes don't match"},
27         {"EOUTPUTNOTMATCH", EOUTPUTNOTMATCH, "outputs don't match"},
28         {"ESIGNOTMATCH", ESIGNOTMATCH, "signals don't match"},
29         {"EUNEXPECTEDSIG", EUNEXPECTEDSIG, "unexpected signal caught"},
30         {"ESIGNOTRECEIPT", ESIGNOTRECEIPT, "expected signal not receipt"},
31         {"EFILENOTFOUND", EFILENOTFOUND, "specified tesh file not found"},
32         {"EGETCWD", EGETCWD, "system error : the getcwd() function failed"},
33         {"EDIRNOTFOUND", EDIRNOTFOUND, "specified directory not found"},
34         {"ECHDIR", ECHDIR, "system error : the chdir() function failed"},
35         {"EPROCCMDLINE", EPROCCMDLINE, "process_command_line() failed : internal error"},
36         {"ENOARG", ENOARG, "none optional argument not specified"},
37         {"ENOTPOSITIVENUM", ENOTPOSITIVENUM, "argument option not strictly positive"},
38         {"ESYNTAX", ESYNTAX, "syntax error"},
39         {"EINVALIDTIMEOUT", EINVALIDTIMEOUT, "timeout value specified by metacommand invalid"},
40         {"EINVALIDEXITCODE", EINVALIDEXITCODE, "expected exit code value specified by the metacommand invalid"},
41         {"ESIGNOTSUPP", ESIGNOTSUPP, "signal specified by the metacommand not supported (Windows specific)"},
42         {"ELEADTIME", ELEADTIME, "lead time"},
43         {"EREADMENOTFOUND", EREADMENOTFOUND, "unable to locate the README.txt file"},
44         {"EINCLUDENOTFOUND", EINCLUDENOTFOUND, "include file specified by a metacommand is not found"},
45         {"ESUFFIXTOOLONG", ESUFFIXTOOLONG, "suffix is too long"},
46         {"EFILENOTINSPECDIR", EFILENOTINSPECDIR,"file not found in the specified directories"},
47         {"EFILENOTINCURDIR", EFILENOTINCURDIR,"file not found in the current directory"},
48         {"unkwown", -1, "unknown"}
49 };
50
51 #include <stdio.h>
52
53 const char*
54 error_to_string(int errcode)
55 {
56         int i;
57         
58         for(i = 0; err[i].code != -1; i++)
59                 if(err[i].code == errcode)
60                         return err[i].string;
61         
62         return "unknow error";  
63 }
64
65 const char*
66 error_get_at(int pos, int* code)
67 {
68         if(pos < 0 || (pos > (sizeof(err)/sizeof(entry_t)) - 2))
69         {
70                 errno = ERANGE;
71                 return NULL;
72         }
73         
74         *code = err[pos].code;
75         return err[pos].name;
76 }