/winsamp.d

http://github.com/wilkie/djehuty · D · 283 lines · 218 code · 51 blank · 14 comment · 8 complexity · ebd99cbccb66b0c178dd67899f62b65e MD5 · raw file

  1. import djehuty;
  2. import data.list;
  3. import gui.application;
  4. import gui.window;
  5. import gui.button;
  6. import gui.widget;
  7. import gui.listbox;
  8. import hashes.digest;
  9. import resource.menu;
  10. import graphics.graphics;
  11. import resource.image;
  12. import resource.sound;
  13. import cui.application;
  14. import cui.window;
  15. import cui.label;
  16. import cui.textfield;
  17. import cui.tabbox;
  18. import cui.container;
  19. import synch.timer;
  20. import synch.thread;
  21. import synch.atomic;
  22. import networking.irc;
  23. import io.console;
  24. import hashes.md5;
  25. import spec.test;
  26. import parsing.options;
  27. import io.file;
  28. import math.vector;
  29. import core.date;
  30. import cui.textfield;
  31. import core.application;
  32. import cui.textbox;
  33. import cui.codebox;
  34. import cui.dialog;
  35. import cui.filebox;
  36. import cui.listbox;
  37. import math.fixed;
  38. import math.currency;
  39. import math.integer;
  40. import parsing.d.parser;
  41. import networking.ftp;
  42. private template _switch_string(T) {
  43. int _switch_string(T[][] table, T[] compare) {
  44. if (table.length == 0) {
  45. return -1;
  46. }
  47. TypeInfo ti = typeid(T[]);
  48. // Binary search the table
  49. size_t min = 0;
  50. size_t max = table.length;
  51. // Current comparing position
  52. size_t cur;
  53. // Temp for compare value
  54. int cmp;
  55. while(max > min) {
  56. cur = (max + min) / 2;
  57. cmp = ti.compare(&table[cur], &compare);
  58. if (cmp == 0) {
  59. return cur;
  60. }
  61. else if (cmp > 0) {
  62. max = cur;
  63. }
  64. else {
  65. min = cur + 1;
  66. }
  67. }
  68. return -1;
  69. }
  70. }
  71. import spec.specification;
  72. import data.queue2;
  73. class MyConsoleApp : Application {
  74. static this() { new MyConsoleApp(); }
  75. override void onApplicationStart() {
  76. q = new Queue2!(string);
  77. Thread t = Thread.current;
  78. ulong a, b, c;
  79. a = 4;
  80. b = 0b10011101_10110011_11100011_11011010;
  81. c = 5;
  82. Console.putln("{1}, {0}, {1}, {0:X}, {} {} {X8} {00.0000}".format(12, 11, 13, 3.4));
  83. Console.putln(a,b,c);
  84. Console.putln(Atomic.compareExchange(a,b,c));
  85. Console.putln(a,b,c);
  86. float d,e,f;
  87. d = 1.0;
  88. e = 1.1;
  89. f = 2.234;
  90. Console.putln(d,e,f);
  91. Console.putln(Atomic.compareExchange(d,e,f));
  92. Console.putln(d,e,f);
  93. void* A=null;
  94. void* B=cast(void*)0xfe;
  95. void* C=cast(void*)0xff;
  96. Console.putln(A,B,C);
  97. Console.putln(Atomic.compareExchange(A,B,C));
  98. Console.putln(A,B,C);
  99. short g,h,i;
  100. g = 3;
  101. h = 4;
  102. i = 4;
  103. Console.putln(g,h,i);
  104. Console.putln(Atomic.compareExchange(g,h,i));
  105. Console.putln(g,h,i);
  106. Console.putln([1,2,3,4].rotate(2));
  107. Console.putln("hello"c.dup.reverse);
  108. /*Console.putln("he\u0364llo"c.dup.reverse);
  109. Console.putln("hlle\u0364o"c.dup.reverse);
  110. Console.putln("he\u0364po"c.dup.reverse);
  111. Console.putln("he\u0364llo"w.dup.reverse);
  112. Console.putln("he\u0364llo"d.dup.reverse);
  113. Console.putln("he\u0364llo"d.dup.reverse());*/
  114. Console.putln([1,2,3,4,5,6,7,8].dup.reverse());
  115. Console.putln(new Fixed(3.5));
  116. //Atomic.exchange(a,6);
  117. Console.putln(a,b,c);
  118. Console.putln("{c}".format(1500.42));
  119. Locale.id = LocaleId.French_FR;
  120. Console.putln("{c}".format(1500.42));
  121. Console.putln(new Currency(150042,2));
  122. t = new Thread(&foo);
  123. t.start();
  124. t = new Thread(&foo);
  125. t.start();
  126. t = new Thread(&foo);
  127. t.start();
  128. t = new Thread(&foo);
  129. t.start();
  130. t = new Thread(&foo);
  131. t.start();
  132. t = new Thread(&foo);
  133. t.start();
  134. t = new Thread(&foo);
  135. t.start();
  136. t = new Thread(&foo);
  137. t.start();
  138. t = new Thread(&foo);
  139. t.start();
  140. Timer tmr = new Timer(250);
  141. push(tmr);
  142. tmr.start();
  143. //while(freak < 9) {
  144. //}
  145. Console.forecolor = Color.White;
  146. Console.putln("White");
  147. Console.forecolor = Color.Red;
  148. Console.putln("Red");
  149. Console.forecolor = Color.Green;
  150. Console.putln("Green");
  151. Console.forecolor = Color.Blue;
  152. Console.putln("Blue");
  153. Console.forecolor = Color.Yellow;
  154. Console.putln("Yellow");
  155. Console.forecolor = Color.Magenta;
  156. Console.putln("Magenta");
  157. Console.forecolor = Color.Cyan;
  158. Console.putln("Cyan");
  159. Console.forecolor = Color.Gray;
  160. Console.putln("Gray");
  161. Console.forecolor = Color.DarkGray;
  162. Console.putln("DarkGray");
  163. Console.forecolor = Color.DarkRed;
  164. Console.putln("DarkRed");
  165. Console.forecolor = Color.DarkGreen;
  166. Console.putln("DarkGreen");
  167. Console.forecolor = Color.DarkBlue;
  168. Console.putln("DarkBlue");
  169. Console.forecolor = Color.DarkYellow;
  170. Console.putln("DarkYellow");
  171. Console.forecolor = Color.DarkMagenta;
  172. Console.putln("DarkMagenta");
  173. Console.forecolor = Color.DarkCyan;
  174. Console.putln("DarkCyan");
  175. Console.forecolor = Color.Black;
  176. Console.putln("Black");
  177. Console.forecolor = Color.Gray;
  178. ulong foo = 45;
  179. Console.putln(foo);
  180. Atomic.add(foo, 45);
  181. Console.putln(foo);
  182. Console.putln(q);
  183. Console.putln([1,2,3,4].rotate(-1));
  184. foreach_reverse(dchar d; "he\u0364llo"c) {
  185. Console.putln(d);
  186. }
  187. Console.putln([3,2,1].sort);
  188. Console.putln([[1,2],[2,3],[3],[1],[0]].sort);
  189. typedef int oneint = 3;
  190. oneint fb;
  191. oneint[] oneints = new oneint[10];
  192. //Console.putln(oneints[0]);
  193. //Console.putln(fb);
  194. dstring[] fuzz = [
  195. "abc",
  196. "zzt"
  197. "hello",
  198. ];
  199. string foobe = "hello";
  200. switch(foobe) {
  201. case "abc":
  202. case "zzt":
  203. break;
  204. case "hello":
  205. Console.putln("yay");
  206. break;
  207. default:
  208. break;
  209. }
  210. Console.putln(_switch_string(fuzz, "hello"d));
  211. for(;;){}
  212. }
  213. override bool onSignal(Dispatcher dsp, uint signal) {
  214. Console.putln("fire");
  215. return true;
  216. }
  217. void foo(bool bar) {
  218. Atomic.increment(fudge);
  219. while(fudge < 9) {
  220. }
  221. q.add("foobara");
  222. q.add("foobarb");
  223. q.remove();
  224. q.add("foobarc");
  225. q.add("foobard");
  226. q.remove();
  227. Atomic.increment(freak);
  228. }
  229. ulong fudge;
  230. ulong freak;
  231. Queue2!(string) q;
  232. }