Browse code

add package to the repository

msa


git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/msa@102253 bc3139a8-67e5-0310-9ffc-ced21a209358

Sonali Arora authored on 10/04/2015 00:12:33
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+/*
2
+ * exceptions4c lightweight version 1.0
3
+ *
4
+ * Copyright (c) 2013 Guillermo Calvo
5
+ * Licensed under the GNU Lesser General Public License
6
+ */
7
+
8
+#include <stdlib.h>
9
+#include <stdio.h>
10
+#include "e4c_lite.h"
11
+
12
+E4C_DEFINE_EXCEPTION(RuntimeException, "Runtime exception.", RuntimeException);
13
+E4C_DEFINE_EXCEPTION(NullPointerException, "Null pointer.", RuntimeException);
14
+E4C_DEFINE_EXCEPTION(ClustalOmegaException, "ClustalOmega exception", RuntimeException);
15
+
16
+struct e4c_context e4c = {0};
17
+static const char * err_msg[] = {"\n\nError: %s (%s)\n\n", "\n\nUncaught %s: %s\n\n    thrown at %s:%d\n\n"};
18
+
19
+static void e4c_propagate(void){
20
+
21
+    e4c.frame[e4c.frames].uncaught = 1;
22
+
23
+    if(e4c.frames > 0) longjmp(e4c.jump[e4c.frames - 1], 1);
24
+
25
+    if(fprintf(stderr, e4c.err.file == NULL ? err_msg[0] : err_msg[1], e4c.err.type->name, e4c.err.message, e4c.err.file, e4c.err.line) > 0)
26
+        (void)fflush(stderr);
27
+
28
+    //exit(EXIT_FAILURE);
29
+}
30
+
31
+int e4c_try(const char * file, int line){
32
+
33
+    if(e4c.frames >= E4C_MAX_FRAMES) e4c_throw(&RuntimeException, file, line, "Too many `try` blocks nested.");
34
+
35
+    e4c.frames++;
36
+
37
+    e4c.frame[e4c.frames].stage = e4c_beginning;
38
+    e4c.frame[e4c.frames].uncaught = 0;
39
+
40
+    return 1;
41
+}
42
+
43
+int e4c_hook(int is_catch){
44
+
45
+    int uncaught;
46
+
47
+    if(is_catch) return !(e4c.frame[e4c.frames].uncaught = 0);
48
+
49
+    uncaught = e4c.frame[e4c.frames].uncaught;
50
+
51
+    e4c.frame[e4c.frames].stage++;
52
+    if(e4c.frame[e4c.frames].stage == e4c_catching && !uncaught) e4c.frame[e4c.frames].stage++;
53
+
54
+    if(e4c.frame[e4c.frames].stage < e4c_done) return 1;
55
+
56
+    e4c.frames--;
57
+
58
+    if(uncaught) e4c_propagate();
59
+
60
+    return 0;
61
+}
62
+
63
+int e4c_extends(const struct e4c_exception_type * child, const struct e4c_exception_type * parent){
64
+
65
+    for(; child != NULL && child->supertype != child; child = child->supertype)
66
+        if(child->supertype == parent) return 1;
67
+
68
+    return 0;
69
+}
70
+
71
+void e4c_throw(const struct e4c_exception_type * exception_type, const char * file, int line, const char * message){
72
+
73
+    e4c.err.type = (exception_type != NULL ? exception_type : &NullPointerException);
74
+    e4c.err.file = file;
75
+    e4c.err.line = line;
76
+
77
+    (void)sprintf(e4c.err.message, "%.*s", (int)E4C_MESSAGE_SIZE - 1, (message != NULL ? message : e4c.err.type->default_message));
78
+
79
+    e4c_propagate();
80
+}