2
0

index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>CodeMirror 2: C-like mode</title>
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="clike.js"></script>
  8. <link rel="stylesheet" href="../../theme/default.css">
  9. <link rel="stylesheet" href="../../css/docs.css">
  10. <style>.CodeMirror {border: 2px inset #dee;}</style>
  11. </head>
  12. <body>
  13. <h1>CodeMirror 2: C-like mode</h1>
  14. <form><textarea id="code" name="code">
  15. /* C demo code */
  16. #include <zmq.h>
  17. #include <pthread.h>
  18. #include <semaphore.h>
  19. #include <time.h>
  20. #include <stdio.h>
  21. #include <fcntl.h>
  22. #include <malloc.h>
  23. typedef struct {
  24. void* arg_socket;
  25. zmq_msg_t* arg_msg;
  26. char* arg_string;
  27. unsigned long arg_len;
  28. int arg_int, arg_command;
  29. int signal_fd;
  30. int pad;
  31. void* context;
  32. sem_t sem;
  33. } acl_zmq_context;
  34. #define p(X) (context->arg_##X)
  35. void* zmq_thread(void* context_pointer) {
  36. acl_zmq_context* context = (acl_zmq_context*)context_pointer;
  37. char ok = 'K', err = 'X';
  38. int res;
  39. while (1) {
  40. while ((res = sem_wait(&amp;context->sem)) == EINTR);
  41. if (res) {write(context->signal_fd, &amp;err, 1); goto cleanup;}
  42. switch(p(command)) {
  43. case 0: goto cleanup;
  44. case 1: p(socket) = zmq_socket(context->context, p(int)); break;
  45. case 2: p(int) = zmq_close(p(socket)); break;
  46. case 3: p(int) = zmq_bind(p(socket), p(string)); break;
  47. case 4: p(int) = zmq_connect(p(socket), p(string)); break;
  48. case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &amp;p(len)); break;
  49. case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
  50. case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
  51. case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
  52. case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
  53. }
  54. p(command) = errno;
  55. write(context->signal_fd, &amp;ok, 1);
  56. }
  57. cleanup:
  58. close(context->signal_fd);
  59. free(context_pointer);
  60. return 0;
  61. }
  62. void* zmq_thread_init(void* zmq_context, int signal_fd) {
  63. acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
  64. pthread_t thread;
  65. context->context = zmq_context;
  66. context->signal_fd = signal_fd;
  67. sem_init(&amp;context->sem, 1, 0);
  68. pthread_create(&amp;thread, 0, &amp;zmq_thread, context);
  69. pthread_detach(thread);
  70. return context;
  71. }
  72. </textarea></form>
  73. <script>
  74. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  75. lineNumbers: true,
  76. matchBrackets: true,
  77. mode: "text/x-csrc"
  78. });
  79. </script>
  80. <p>Simple mode that tries to handle C-like languages as well as it
  81. can. Takes two configuration parameters: <code>keywords</code>, an
  82. object whose property names are the keywords in the language,
  83. and <code>useCPP</code>, which determines whether C preprocessor
  84. directives are recognized.</p>
  85. <p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
  86. (C code), <code>text/x-c++src</code> (C++
  87. code), <code>text/x-java</code> (Java
  88. code), <code>text/x-groovy</code> (Groovy code).</p>
  89. </body>
  90. </html>