console.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // console.cpp: the console buffer, its display, and command line control
  2. #include "cube.h"
  3. #define CONSPAD (FONTH/3)
  4. VARP(altconsize, 0, 0, 100);
  5. VARP(fullconsize, 0, 40, 100);
  6. VARP(consize, 0, 6, 100);
  7. VARP(confade, 0, 20, 60);
  8. VARP(conalpha, 0, 255, 255);
  9. VAR(conopen, 1, 0, 0);
  10. VAR(numconlines, 0, 0, 1);
  11. struct console : consolebuffer<cline>
  12. {
  13. int conskip;
  14. void setconskip(int n)
  15. {
  16. int visible_lines = (int)(min(fullconsole ? ((VIRTH*2 - 2*CONSPAD - 2*FONTH/3)*(fullconsole==1 ? altconsize : fullconsize))/100 : FONTH*consize, (VIRTH*2 - 2*CONSPAD - 2*FONTH/3))/ (CONSPAD + 2*FONTH/3)) - 1;
  17. conskip = clamp(conskip + n, 0, clamp(conlines.length()-visible_lines, 0, conlines.length()));
  18. }
  19. static const int WORDWRAP = 80;
  20. int fullconsole;
  21. void toggleconsole()
  22. {
  23. if(!fullconsole) fullconsole = altconsize ? 1 : 2;
  24. else fullconsole = (fullconsole + 1) % 3;
  25. conopen = fullconsole;
  26. }
  27. void addline(const char *sf) { consolebuffer<cline>::addline(sf, totalmillis); numconlines++; }
  28. void render()
  29. {
  30. int miny = CONSPAD+FONTH/3;
  31. int conwidth = (fullconsole ? VIRTW : int(floor(getradarpos().x)))*2 - 2*CONSPAD - 2*FONTH/3;
  32. int h = VIRTH*2 - 2*CONSPAD - 2*FONTH/3;
  33. int conheight = min(fullconsole ? (h*(fullconsole==1 ? altconsize : fullconsize))/100 : FONTH*consize, h);
  34. #ifdef __ANDROID__
  35. if(fullconsole)
  36. {
  37. miny = 3*FONTH;
  38. glPushMatrix();
  39. glLoadIdentity();
  40. conwidth = 3*VIRTW/4 - FONTH;
  41. conheight = 3*VIRTH/4 - 3*FONTH;
  42. glOrtho(0,3*VIRTW/4,3*VIRTH/4,0,-1,1);
  43. blendbox(0, 5*FONTH/2, 3*VIRTW/4, 3*VIRTH/4, false);
  44. }
  45. else
  46. {
  47. miny = 6*FONTH;
  48. }
  49. #else
  50. if(fullconsole) blendbox(CONSPAD, CONSPAD, conwidth+CONSPAD+2*FONTH/3, conheight+CONSPAD+2*FONTH/3, true);
  51. #endif
  52. int numl = conlines.length(), offset = min(conskip, numl);
  53. if(!fullconsole && confade)
  54. {
  55. if(!conskip)
  56. {
  57. numl = 0;
  58. loopvrev(conlines) if(totalmillis-conlines[i].millis < confade*1000) { numl = i+1; break; }
  59. }
  60. else offset--;
  61. }
  62. int y=0;
  63. loopi(numl) //determine visible height
  64. {
  65. // shuffle backwards to fill if necessary
  66. int idx = offset+i < numl ? offset+i : --offset;
  67. char *line = conlines[idx].line;
  68. int width, height;
  69. text_bounds(line, width, height, conwidth);
  70. y += height;
  71. if(y > conheight) { numl = i; if(offset == idx) ++offset; break; }
  72. }
  73. y = miny;
  74. loopi(numl)
  75. {
  76. int idx = offset + numl-i-1;
  77. char *line = conlines[idx].line;
  78. draw_text(line, CONSPAD+FONTH/3, y, 0xFF, 0xFF, 0xFF, fullconsole ? 0xFF : conalpha, -1, conwidth);
  79. int width, height;
  80. text_bounds(line, width, height, conwidth);
  81. y += height;
  82. }
  83. #ifdef __ANDROID__
  84. if( fullconsole ) glPopMatrix();
  85. #endif
  86. }
  87. console() : consolebuffer<cline>(200), fullconsole(0) {}
  88. };
  89. console con;
  90. textinputbuffer cmdline;
  91. char *cmdaction = NULL, *cmdprompt = NULL;
  92. bool saycommandon = false, storeinputcommand = false;
  93. VARFP(maxcon, 10, 200, 1000, con.setmaxlines(maxcon));
  94. void setconskip(int *n) { con.setconskip(*n); }
  95. COMMANDN(conskip, setconskip, "i");
  96. void toggleconsole() { con.toggleconsole(); }
  97. COMMANDN(toggleconsole, toggleconsole, "");
  98. void renderconsole() { con.render(); }
  99. stream *clientlogfile = NULL;
  100. vector<char> *bootclientlog = new vector<char>;
  101. int clientloglinesremaining = INT_MAX;
  102. void clientlogf(const char *s, ...)
  103. {
  104. defvformatstring(sp, s, s);
  105. filtertext(sp, sp, FTXT__LOG);
  106. extern struct servercommandline scl;
  107. const char *ts = scl.logtimestamp ? timestring(true, "%b %d %H:%M:%S ") : "";
  108. char *p, *l = sp;
  109. do
  110. { // break into single lines first
  111. if((p = strchr(l, '\n'))) *p = '\0';
  112. printf("%s%s\n", ts, l);
  113. if(clientlogfile)
  114. {
  115. clientlogfile->printf("%s%s\n", ts, l);
  116. if(--clientloglinesremaining <= 0) DELETEP(clientlogfile);
  117. }
  118. else if(bootclientlog) cvecprintf(*bootclientlog, "%s%s\n", ts, l);
  119. l = p + 1;
  120. }
  121. while(p);
  122. }
  123. SVAR(conline,"n/a");
  124. void conoutf(const char *s, ...)
  125. {
  126. defvformatstring(sf, s, s);
  127. clientlogf("%s", sf);
  128. con.addline(sf);
  129. delete[] conline; conline=newstring(sf);
  130. }
  131. int rendercommand(int x, int y, int w)
  132. {
  133. const char *useprompt = cmdprompt ? cmdprompt : "#";
  134. defformatstring(s)("%s %s", useprompt, cmdline.buf);
  135. int width, height;
  136. text_bounds(s, width, height, w);
  137. y -= height - FONTH;
  138. if (x >= 0) draw_text(s, x, y, 0xFF, 0xFF, 0xFF, 0xFF, cmdline.pos>=0 ? cmdline.pos + strlen(useprompt) + 1 : (int)strlen(s), w);
  139. return height;
  140. }
  141. // keymap is defined externally in keymap.cfg
  142. vector<keym> keyms;
  143. const char *keycmds[keym::NUMACTIONS] = { "bind", "editbind", "specbind" };
  144. inline const char *keycmd(int type) { return type >= 0 && type < keym::NUMACTIONS ? keycmds[type] : ""; }
  145. void keymap(int *code, char *key)
  146. {
  147. keym &km = keyms.add();
  148. km.code = *code;
  149. km.name = newstring(key);
  150. }
  151. COMMAND(keymap, "is");
  152. keym *findbind(const char *key)
  153. {
  154. loopv(keyms) if(!strcasecmp(keyms[i].name, key)) return &keyms[i];
  155. return NULL;
  156. }
  157. keym **findbinda(const char *action, int type)
  158. {
  159. static vector<keym *> res;
  160. res.setsize(0);
  161. loopv(keyms) if(!strcasecmp(keyms[i].actions[type], action)) res.add(&keyms[i]);
  162. res.add(NULL);
  163. return res.getbuf();
  164. }
  165. keym *findbindc(int code)
  166. {
  167. loopv(keyms) if(keyms[i].code==code) return &keyms[i];
  168. return NULL;
  169. }
  170. void findkey(int *code)
  171. {
  172. const char *res = "-255";
  173. loopv(keyms)
  174. {
  175. if(keyms[i].code == *code)
  176. {
  177. res = keyms[i].name;
  178. break;
  179. }
  180. }
  181. result(res);
  182. }
  183. COMMAND(findkey, "i");
  184. void findkeycode(const char* s)
  185. {
  186. int res = -255;
  187. loopv(keyms)
  188. {
  189. if(!strcmp(s, keyms[i].name))
  190. {
  191. res = keyms[i].code;
  192. break;
  193. }
  194. }
  195. intret(res);
  196. }
  197. COMMAND(findkeycode, "s");
  198. COMMANDF(modkeypressed, "", () { intret((SDL_GetModState() & MOD_KEYS_CTRL) ? 1 : 0); });
  199. keym *keypressed = NULL;
  200. char *keyaction = NULL;
  201. VAR(_defaultbinds, 0, 0, 1);
  202. COMMANDF(_resetallbinds, "", () { if(_defaultbinds) loopv(keyms) loopj(keym::NUMACTIONS) bindkey(&keyms[i], "", j); });
  203. bool bindkey(keym *km, const char *action, int type)
  204. {
  205. if(!km || type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) return false;
  206. if(strcmp(action, km->actions[type]))
  207. {
  208. if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type];
  209. km->actions[type] = newstring(action);
  210. km->unchangeddefault[type] = _defaultbinds != 0;
  211. }
  212. return true;
  213. }
  214. void bindk(const char *key, const char *action, int type)
  215. {
  216. keym *km = findbind(key);
  217. if(!km) { conoutf("unknown key \"%s\"", key); return; }
  218. bindkey(km, action, type);
  219. }
  220. void keybind(const char *key, int type)
  221. {
  222. keym *km = findbind(key);
  223. if(!km) { conoutf("unknown key \"%s\"", key); return; }
  224. if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%d\"", type); return; }
  225. result(km->actions[type]);
  226. }
  227. bool bindc(int code, const char *action, int type)
  228. {
  229. keym *km = findbindc(code);
  230. if(km) return bindkey(km, action, type);
  231. else return false;
  232. }
  233. void searchbinds(const char *action, int type)
  234. {
  235. if(!action || !action[0]) return;
  236. if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%d\"", type); return; }
  237. vector<char> names;
  238. loopv(keyms)
  239. {
  240. if(!strcmp(keyms[i].actions[type], action))
  241. {
  242. if(names.length()) names.add(' ');
  243. names.put(keyms[i].name, strlen(keyms[i].name));
  244. }
  245. }
  246. resultcharvector(names, 0);
  247. }
  248. COMMANDF(keybind, "s", (const char *key) { keybind(key, keym::ACTION_DEFAULT); } );
  249. COMMANDF(keyspecbind, "s", (const char *key) { keybind(key, keym::ACTION_SPECTATOR); } );
  250. COMMANDF(keyeditbind, "s", (const char *key) { keybind(key, keym::ACTION_EDITING); } );
  251. COMMANDF(bind, "ss", (const char *key, const char *action) { bindk(key, action, keym::ACTION_DEFAULT); } );
  252. COMMANDF(specbind, "ss", (const char *key, const char *action) { bindk(key, action, keym::ACTION_SPECTATOR); } );
  253. COMMANDF(editbind, "ss", (const char *key, const char *action) { bindk(key, action, keym::ACTION_EDITING); } );
  254. COMMANDF(searchbinds, "s", (const char *action) { searchbinds(action, keym::ACTION_DEFAULT); });
  255. COMMANDF(searchspecbinds, "s", (const char *action) { searchbinds(action, keym::ACTION_SPECTATOR); });
  256. COMMANDF(searcheditbinds, "s", (const char *action) { searchbinds(action, keym::ACTION_EDITING); });
  257. struct releaseaction
  258. {
  259. keym *key;
  260. char *action;
  261. };
  262. vector<releaseaction> releaseactions;
  263. char *addreleaseaction(const char *s)
  264. {
  265. if(!keypressed) return NULL;
  266. releaseaction &ra = releaseactions.add();
  267. ra.key = keypressed;
  268. ra.action = newstring(s);
  269. return keypressed->name;
  270. }
  271. void onrelease(char *s)
  272. {
  273. addreleaseaction(s);
  274. }
  275. COMMAND(onrelease, "s");
  276. void saycommand(char *init) // turns input to the command line on or off
  277. {
  278. setscope(false);
  279. setburst(false);
  280. if(!editmode) keyrepeat(saycommandon);
  281. copystring(cmdline.buf, init ? escapestring(init, false, true) : "");
  282. DELETEA(cmdaction);
  283. DELETEA(cmdprompt);
  284. cmdline.pos = -1;
  285. }
  286. COMMAND(saycommand, "c");
  287. void inputcommand(char *init, char *action, char *prompt, int *nopersist)
  288. {
  289. saycommand(init);
  290. if(action[0]) cmdaction = newstring(action);
  291. if(prompt[0]) cmdprompt = newstring(prompt);
  292. storeinputcommand = cmdaction && !*nopersist;
  293. }
  294. COMMAND(inputcommand, "sssi");
  295. SVARFF(mapmsg,
  296. { // read mapmsg
  297. hdr.maptitle[127] = '\0';
  298. mapmsg = exchangestr(mapmsg, hdr.maptitle);
  299. },
  300. { // set new mapmsg
  301. string text;
  302. filtertext(text, mapmsg, FTXT__MAPMSG);
  303. copystring(hdr.maptitle, text, 128);
  304. if(editmode) unsavededits++;
  305. });
  306. #if !defined(WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
  307. #include <X11/Xlib.h>
  308. #include <SDL_syswm.h>
  309. #endif
  310. void pasteconsole(char *dst)
  311. {
  312. #ifdef WIN32
  313. if(!IsClipboardFormatAvailable(CF_TEXT)) return;
  314. if(!OpenClipboard(NULL)) return;
  315. char *cb = (char *)GlobalLock(GetClipboardData(CF_TEXT));
  316. concatstring(dst, cb);
  317. GlobalUnlock(cb);
  318. CloseClipboard();
  319. #elif defined(__APPLE__)
  320. extern void mac_pasteconsole(char *commandbuf);
  321. mac_pasteconsole(dst);
  322. #elif defined(__ANDROID__)
  323. #else
  324. SDL_SysWMinfo wminfo;
  325. SDL_VERSION(&wminfo.version);
  326. wminfo.subsystem = SDL_SYSWM_X11;
  327. if(!SDL_GetWindowWMInfo(screen, &wminfo)) return;
  328. int cbsize;
  329. char *cb = XFetchBytes(wminfo.info.x11.display, &cbsize);
  330. if(!cb || !cbsize) return;
  331. int commandlen = strlen(dst);
  332. for(char *cbline = cb, *cbend; commandlen + 1 < MAXSTRLEN && cbline < &cb[cbsize]; cbline = cbend + 1)
  333. {
  334. cbend = (char *)memchr(cbline, '\0', &cb[cbsize] - cbline);
  335. if(!cbend) cbend = &cb[cbsize];
  336. if(commandlen + cbend - cbline + 1 > MAXSTRLEN) cbend = cbline + MAXSTRLEN - commandlen - 1;
  337. memcpy(&dst[commandlen], cbline, cbend - cbline);
  338. commandlen += cbend - cbline;
  339. dst[commandlen] = '\n';
  340. if(commandlen + 1 < MAXSTRLEN && cbend < &cb[cbsize]) ++commandlen;
  341. dst[commandlen] = '\0';
  342. }
  343. XFree(cb);
  344. #endif
  345. }
  346. struct hline
  347. {
  348. char *buf, *action, *prompt;
  349. hline() : buf(NULL), action(NULL), prompt(NULL) {}
  350. ~hline()
  351. {
  352. DELETEA(buf);
  353. DELETEA(action);
  354. DELETEA(prompt);
  355. }
  356. void restore()
  357. {
  358. copystring(cmdline.buf, buf);
  359. if(cmdline.pos >= (int)strlen(cmdline.buf)) cmdline.pos = -1;
  360. DELETEA(cmdaction);
  361. DELETEA(cmdprompt);
  362. if(action) cmdaction = newstring(action);
  363. if(prompt) cmdprompt = newstring(prompt);
  364. storeinputcommand = false;
  365. }
  366. bool shouldsave()
  367. {
  368. return strcmp(cmdline.buf, buf) ||
  369. (cmdaction ? !action || strcmp(cmdaction, action) : action!=NULL) ||
  370. (cmdprompt ? !prompt || strcmp(cmdprompt, prompt) : prompt!=NULL);
  371. }
  372. void save()
  373. {
  374. buf = newstring(cmdline.buf);
  375. if(cmdaction) action = newstring(cmdaction);
  376. if(cmdprompt) prompt = newstring(cmdprompt);
  377. }
  378. void run()
  379. {
  380. pushscontext(IEXC_PROMPT);
  381. if(action)
  382. {
  383. push("cmdbuf", buf);
  384. execute(action);
  385. pop("cmdbuf");
  386. }
  387. else if(buf[0]=='/') execute(buf+1);
  388. else toserver(buf);
  389. popscontext();
  390. }
  391. };
  392. vector<hline *> history;
  393. int histpos = 0;
  394. VARP(maxhistory, 0, 1000, 10000);
  395. void history_(int *n)
  396. {
  397. static bool inhistory = false;
  398. if(!inhistory && history.inrange(*n))
  399. {
  400. inhistory = true;
  401. history[history.length() - *n - 1]->run();
  402. inhistory = false;
  403. }
  404. }
  405. COMMANDN(history, history_, "i");
  406. void savehistory()
  407. {
  408. stream *f = openfile(path("config/history", true), "w");
  409. if(!f) return;
  410. loopv(history)
  411. {
  412. hline *h = history[i];
  413. if(!h->action && !h->prompt && strncmp(h->buf, "/ ", 2))
  414. f->printf("%s\n",h->buf);
  415. }
  416. delete f;
  417. }
  418. void loadhistory()
  419. {
  420. char *histbuf = loadfile(path("config/history", true), NULL);
  421. if(!histbuf) return;
  422. char *line = NULL, *b;
  423. line = strtok_r(histbuf, "\n", &b);
  424. while(line)
  425. {
  426. history.add(new hline)->buf = newstring(line);
  427. line = strtok_r(NULL, "\n", &b);
  428. }
  429. DELETEA(histbuf);
  430. histpos = history.length();
  431. }
  432. void execbind(keym &k, bool isdown)
  433. {
  434. loopv(releaseactions)
  435. {
  436. releaseaction &ra = releaseactions[i];
  437. if(ra.key==&k)
  438. {
  439. if(!isdown) execute(ra.action);
  440. delete[] ra.action;
  441. releaseactions.remove(i--);
  442. }
  443. }
  444. if(isdown)
  445. {
  446. int state = keym::ACTION_DEFAULT;
  447. if(editmode) state = keym::ACTION_EDITING;
  448. else if(player1->isspectating()) state = keym::ACTION_SPECTATOR;
  449. char *&action = k.actions[state][0] ? k.actions[state] : k.actions[keym::ACTION_DEFAULT];
  450. keyaction = action;
  451. keypressed = &k;
  452. execute(keyaction);
  453. keypressed = NULL;
  454. if(keyaction!=action) delete[] keyaction;
  455. }
  456. k.pressed = isdown;
  457. }
  458. void consolekey(int code, bool isdown, int cooked, SDL_Keymod mod)
  459. {
  460. static char *beforecomplete = NULL;
  461. static bool ignoreescup = false;
  462. if(isdown)
  463. {
  464. switch(code)
  465. {
  466. case SDLK_F1:
  467. toggledoc();
  468. break;
  469. case SDLK_F2:
  470. scrolldoc(-4);
  471. break;
  472. case SDLK_F3:
  473. scrolldoc(4);
  474. break;
  475. case SDL_AC_BUTTON_WHEELUP:
  476. case SDLK_UP:
  477. if(histpos > history.length()) histpos = history.length();
  478. if(histpos > 0) history[--histpos]->restore();
  479. break;
  480. case SDL_AC_BUTTON_WHEELDOWN:
  481. case SDLK_DOWN:
  482. if(histpos + 1 < history.length()) history[++histpos]->restore();
  483. break;
  484. case SDLK_TAB:
  485. if(!cmdaction)
  486. {
  487. if(!beforecomplete) beforecomplete = newstring(cmdline.buf);
  488. complete(cmdline.buf, (mod & KMOD_LSHIFT) ? true : false);
  489. if(cmdline.pos >= 0 && cmdline.pos >= (int)strlen(cmdline.buf)) cmdline.pos = -1;
  490. }
  491. break;
  492. case SDLK_ESCAPE:
  493. if(mod & KMOD_LSHIFT) // LSHIFT+ESC restores buffer from before complete()
  494. {
  495. if(beforecomplete) copystring(cmdline.buf, beforecomplete);
  496. ignoreescup = true;
  497. }
  498. else ignoreescup = false;
  499. break;
  500. default:
  501. resetcomplete();
  502. DELETEA(beforecomplete);
  503. case SDLK_LSHIFT:
  504. cmdline.key(code, isdown, cooked);
  505. break;
  506. }
  507. }
  508. else
  509. {
  510. if(code==SDLK_RETURN || code==SDLK_KP_ENTER || code==SDL_AC_BUTTON_LEFT || code==SDL_AC_BUTTON_MIDDLE)
  511. {
  512. // make laptop users happy; LMB shall only work with history
  513. if(code == SDL_AC_BUTTON_LEFT && histpos == history.length()) return;
  514. hline *h = NULL;
  515. if(cmdline.buf[0] || cmdaction)
  516. {
  517. if(history.empty() || history.last()->shouldsave())
  518. {
  519. if(maxhistory && history.length() >= maxhistory)
  520. {
  521. loopi(history.length()-maxhistory+1) delete history[i];
  522. history.remove(0, history.length()-maxhistory+1);
  523. }
  524. history.add(h = new hline)->save();
  525. }
  526. else h = history.last();
  527. }
  528. histpos = history.length();
  529. saycommand(NULL);
  530. if(h)
  531. {
  532. h->run();
  533. if(h->action && !storeinputcommand) history.drop();
  534. }
  535. }
  536. else if((code==SDLK_ESCAPE && !ignoreescup) || code== SDL_AC_BUTTON_RIGHT)
  537. {
  538. histpos = history.length();
  539. saycommand(NULL);
  540. }
  541. }
  542. }
  543. void keypress(int code, bool isdown, int cooked, SDL_Keymod mod)
  544. {
  545. keym *haskey = NULL;
  546. loopv(keyms) if(keyms[i].code==code) { haskey = &keyms[i]; break; }
  547. if(haskey && haskey->pressed) execbind(*haskey, isdown); // allow pressed keys to release
  548. else if(saycommandon) consolekey(code, isdown, cooked, mod); // keystrokes go to commandline
  549. else if(!menukey(code, isdown, cooked, mod)) // keystrokes go to menu
  550. {
  551. if(haskey) {
  552. execbind(*haskey, isdown);
  553. }
  554. }
  555. if(isdown) exechook(HOOK_SP, "KEYPRESS", "KEYPRESS %d", code);
  556. else exechook(HOOK_SP, "KEYRELEASE", "%d", code);
  557. }
  558. char *getcurcommand(int *pos)
  559. {
  560. if(pos && saycommandon) *pos = cmdline.pos;
  561. return saycommandon ? cmdline.buf : NULL;
  562. }
  563. VARP(omitunchangeddefaultbinds, 0, 1, 2);
  564. void writebinds(stream *f)
  565. {
  566. loopv(keyms)
  567. {
  568. keym *km = &keyms[i];
  569. loopj(3) if(*km->actions[j] && (!km->unchangeddefault[j] || omitunchangeddefaultbinds < 2))
  570. f->printf("%s%s \"%s\" %s\n", km->unchangeddefault[j] && omitunchangeddefaultbinds ? "//" : "", keycmd(j), km->name, escapestring(km->actions[j]));
  571. }
  572. }