C-like mode
x
1
/* C demo code */
2
3
4
5
6
7
8
9
10
11
typedef struct {
12
void* arg_socket;
13
zmq_msg_t* arg_msg;
14
char* arg_string;
15
unsigned long arg_len;
16
int arg_int, arg_command;
17
18
int signal_fd;
19
int pad;
20
void* context;
21
sem_t sem;
22
} acl_zmq_context;
23
24
25
26
void* zmq_thread(void* context_pointer) {
27
acl_zmq_context* context = (acl_zmq_context*)context_pointer;
28
char ok = 'K', err = 'X';
29
int res;
30
31
while (1) {
32
while ((res = sem_wait(&context->sem)) == EINTR);
33
if (res) {write(context->signal_fd, &err, 1); goto cleanup;}
34
switch(p(command)) {
35
case 0: goto cleanup;
36
case 1: p(socket) = zmq_socket(context->context, p(int)); break;
37
case 2: p(int) = zmq_close(p(socket)); break;
38
case 3: p(int) = zmq_bind(p(socket), p(string)); break;
39
case 4: p(int) = zmq_connect(p(socket), p(string)); break;
40
case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break;
41
case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
42
case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
43
case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
44
case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
45
}
46
p(command) = errno;
47
write(context->signal_fd, &ok, 1);
48
}
49
cleanup:
50
close(context->signal_fd);
51
free(context_pointer);
52
return 0;
53
}
54
55
void* zmq_thread_init(void* zmq_context, int signal_fd) {
56
acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
57
pthread_t thread;
58
59
context->context = zmq_context;
60
context->signal_fd = signal_fd;
61
sem_init(&context->sem, 1, 0);
62
pthread_create(&thread, 0, &zmq_thread, context);
63
pthread_detach(thread);
64
return context;
65
}
66
C++ example
39
1
2
3
4
namespace {
5
enum Enum {
6
VAL1, VAL2, VAL3
7
};
8
9
char32_t unicode_string = U"\U0010FFFF";
10
string raw_string = R"delim(anything
11
you
12
want)delim";
13
14
int Helper(const MyType& param) {
15
return 0;
16
}
17
} // namespace
18
19
class ForwardDec;
20
21
template <class T, class V>
22
class Class : public BaseClass {
23
const MyType<T, V> member_;
24
25
public:
26
const MyType<T, V>& Method() const {
27
return member_;
28
}
29
30
void Method2(MyType<T, V>* value);
31
}
32
33
template <class T, class V>
34
void Class::Method2(MyType<T, V>* value) {
35
std::out << 1 >> method();
36
value->Method3(member_);
37
member_ = value;
38
}
39
Objective-C example
16
1
/*
2
This is a longer comment
3
That spans two lines
4
*/
5
6
7
@implementation YourAppDelegate
8
9
// This is a one-line comment
10
11
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
12
char myString[] = "This is a C character array";
13
int test = 5;
14
return YES;
15
}
16
Java example
28
1
import com.demo.util.MyType;
2
import com.demo.util.MyInterface;
3
4
public enum Enum {
5
VAL1, VAL2, VAL3
6
}
7
8
public class Class<T, V> implements MyInterface {
9
public static final MyType<T, V> member;
10
11
private class InnerClass {
12
public int zero() {
13
return 0;
14
}
15
}
16
17
18
public MyType method() {
19
return member;
20
}
21
22
public void method2(MyType<T, V> value) {
23
method();
24
value.method3();
25
member = value;
26
}
27
}
28
Scala example
11
1
object FilterTest extends App {
2
def filter(xs: List[Int], threshold: Int) = {
3
def process(ys: List[Int]): List[Int] =
4
if (ys.isEmpty) ys
5
else if (ys.head < threshold) ys.head :: process(ys.tail)
6
else process(ys.tail)
7
process(xs)
8
}
9
println(filter(List(1, 9, 2, 8, 3, 7, 4), 5))
10
}
11
Simple mode that tries to handle C-like languages as well as it
can. Takes two configuration parameters: keywords
, an
object whose property names are the keywords in the language,
and useCPP
, which determines whether C preprocessor
directives are recognized.
MIME types defined: text/x-csrc
(C), text/x-c++src
(C++), text/x-java
(Java), text/x-csharp
(C#),
text/x-objectivec
(Objective-C),
text/x-scala
(Scala), text/x-vertex
and x-shader/x-fragment
(shader programs),
text/x-squirrel
(Squirrel).