3 <title>CodeMirror: C-like mode
</title>
4 <meta charset=
"utf-8"/>
5 <link rel=stylesheet
href=
"../../doc/docs.css">
7 <link rel=
"stylesheet" href=
"../../lib/codemirror.css">
8 <script src=
"../../lib/codemirror.js"></script>
9 <script src=
"../../addon/edit/matchbrackets.js"></script>
10 <script src=
"clike.js"></script>
11 <style>.CodeMirror {border:
2px inset #dee;}
</style>
13 <a href=
"http://codemirror.net"><img id=logo
src=
"../../doc/logo.png"></a>
16 <li><a href=
"../../index.html">Home
</a>
17 <li><a href=
"../../doc/manual.html">Manual
</a>
18 <li><a href=
"https://github.com/marijnh/codemirror">Code
</a>
21 <li><a href=
"../index.html">Language modes
</a>
22 <li><a class=active
href=
"#">C-like
</a>
29 <div><textarea id=
"c-code">
34 #include
<semaphore.h
>
44 unsigned long arg_len;
45 int arg_int, arg_command;
53 #define p(X) (context-
>arg_##X)
55 void* zmq_thread(void* context_pointer) {
56 acl_zmq_context* context = (acl_zmq_context*)context_pointer;
57 char ok = 'K', err = 'X';
61 while ((res = sem_wait(
&context-
>sem)) == EINTR);
62 if (res) {write(context-
>signal_fd,
&err,
1); goto cleanup;}
65 case
1: p(socket) = zmq_socket(context-
>context, p(int)); break;
66 case
2: p(int) = zmq_close(p(socket)); break;
67 case
3: p(int) = zmq_bind(p(socket), p(string)); break;
68 case
4: p(int) = zmq_connect(p(socket), p(string)); break;
69 case
5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string),
&p(len)); break;
70 case
6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
71 case
7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
72 case
8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
73 case
9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
76 write(context-
>signal_fd,
&ok,
1);
79 close(context-
>signal_fd);
80 free(context_pointer);
84 void* zmq_thread_init(void* zmq_context, int signal_fd) {
85 acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
88 context-
>context = zmq_context;
89 context-
>signal_fd = signal_fd;
90 sem_init(
&context-
>sem,
1,
0);
91 pthread_create(
&thread,
0,
&zmq_thread, context);
92 pthread_detach(thread);
99 <div><textarea id=
"cpp-code">
101 #include
"mystuff/util.h"
108 char32_t unicode_string = U
"\U0010FFFF";
109 string raw_string = R
"delim(anything
113 int Helper(const MyType& param) {
120 template
<class T, class V
>
121 class Class : public BaseClass {
122 const MyType
<T, V
> member_;
125 const MyType
<T, V
>& Method() const {
129 void Method2(MyType
<T, V
>* value);
132 template
<class T, class V
>
133 void Class::Method2(MyType
<T, V
>* value) {
134 std::out <<
1 >> method();
135 value-
>Method3(member_);
140 <h2>Java example
</h2>
142 <div><textarea id=
"java-code">
143 import com.demo.util.MyType;
144 import com.demo.util.MyInterface;
150 public class Class
<T, V
> implements MyInterface {
151 public static final MyType
<T, V
> member;
153 private class InnerClass {
160 public MyType method() {
164 public void method2(MyType
<T, V
> value) {
173 var cEditor = CodeMirror.fromTextArea(document.getElementById(
"c-code"), {
178 var cppEditor = CodeMirror.fromTextArea(document.getElementById(
"cpp-code"), {
181 mode:
"text/x-c++src"
183 var javaEditor = CodeMirror.fromTextArea(document.getElementById(
"java-code"), {
190 <p>Simple mode that tries to handle C-like languages as well as it
191 can. Takes two configuration parameters:
<code>keywords
</code>, an
192 object whose property names are the keywords in the language,
193 and
<code>useCPP
</code>, which determines whether C preprocessor
194 directives are recognized.
</p>
196 <p><strong>MIME types defined:
</strong> <code>text/x-csrc
</code>
197 (C code),
<code>text/x-c++src
</code> (C++
198 code),
<code>text/x-java
</code> (Java
199 code),
<code>text/x-csharp
</code> (C#).
</p>