index.html 3.1 KB

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