Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / mode / clike / index.html
1 <!doctype html>
2
3 <title>CodeMirror: C-like mode</title>
4 <meta charset="utf-8"/>
5 <link rel=stylesheet href="../../doc/docs.css">
6
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>
12 <div id=nav>
13 <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
14
15 <ul>
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>
19 </ul>
20 <ul>
21 <li><a href="../index.html">Language modes</a>
22 <li><a class=active href="#">C-like</a>
23 </ul>
24 </div>
25
26 <article>
27 <h2>C-like mode</h2>
28
29 <div><textarea id="c-code">
30 /* C demo code */
31
32 #include <zmq.h>
33 #include <pthread.h>
34 #include <semaphore.h>
35 #include <time.h>
36 #include <stdio.h>
37 #include <fcntl.h>
38 #include <malloc.h>
39
40 typedef struct {
41 void* arg_socket;
42 zmq_msg_t* arg_msg;
43 char* arg_string;
44 unsigned long arg_len;
45 int arg_int, arg_command;
46
47 int signal_fd;
48 int pad;
49 void* context;
50 sem_t sem;
51 } acl_zmq_context;
52
53 #define p(X) (context->arg_##X)
54
55 void* zmq_thread(void* context_pointer) {
56 acl_zmq_context* context = (acl_zmq_context*)context_pointer;
57 char ok = 'K', err = 'X';
58 int res;
59
60 while (1) {
61 while ((res = sem_wait(&amp;context->sem)) == EINTR);
62 if (res) {write(context->signal_fd, &amp;err, 1); goto cleanup;}
63 switch(p(command)) {
64 case 0: 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), &amp;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;
74 }
75 p(command) = errno;
76 write(context->signal_fd, &amp;ok, 1);
77 }
78 cleanup:
79 close(context->signal_fd);
80 free(context_pointer);
81 return 0;
82 }
83
84 void* zmq_thread_init(void* zmq_context, int signal_fd) {
85 acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
86 pthread_t thread;
87
88 context->context = zmq_context;
89 context->signal_fd = signal_fd;
90 sem_init(&amp;context->sem, 1, 0);
91 pthread_create(&amp;thread, 0, &amp;zmq_thread, context);
92 pthread_detach(thread);
93 return context;
94 }
95 </textarea></div>
96
97 <h2>C++ example</h2>
98
99 <div><textarea id="cpp-code">
100 #include <iostream>
101 #include "mystuff/util.h"
102
103 namespace {
104 enum Enum {
105 VAL1, VAL2, VAL3
106 };
107
108 char32_t unicode_string = U"\U0010FFFF";
109 string raw_string = R"delim(anything
110 you
111 want)delim";
112
113 int Helper(const MyType& param) {
114 return 0;
115 }
116 } // namespace
117
118 class ForwardDec;
119
120 template <class T, class V>
121 class Class : public BaseClass {
122 const MyType<T, V> member_;
123
124 public:
125 const MyType<T, V>& Method() const {
126 return member_;
127 }
128
129 void Method2(MyType<T, V>* value);
130 }
131
132 template <class T, class V>
133 void Class::Method2(MyType<T, V>* value) {
134 std::out << 1 >> method();
135 value->Method3(member_);
136 member_ = value;
137 }
138 </textarea></div>
139
140 <h2>Java example</h2>
141
142 <div><textarea id="java-code">
143 import com.demo.util.MyType;
144 import com.demo.util.MyInterface;
145
146 public enum Enum {
147 VAL1, VAL2, VAL3
148 }
149
150 public class Class<T, V> implements MyInterface {
151 public static final MyType<T, V> member;
152
153 private class InnerClass {
154 public int zero() {
155 return 0;
156 }
157 }
158
159 @Override
160 public MyType method() {
161 return member;
162 }
163
164 public void method2(MyType<T, V> value) {
165 method();
166 value.method3();
167 member = value;
168 }
169 }
170 </textarea></div>
171
172 <script>
173 var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), {
174 lineNumbers: true,
175 matchBrackets: true,
176 mode: "text/x-csrc"
177 });
178 var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), {
179 lineNumbers: true,
180 matchBrackets: true,
181 mode: "text/x-c++src"
182 });
183 var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), {
184 lineNumbers: true,
185 matchBrackets: true,
186 mode: "text/x-java"
187 });
188 </script>
189
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>
195
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>
200 </article>