From 5e8018ace0776f2a029183c914f36ec423108267 Mon Sep 17 00:00:00 2001 From: alphaKAI Date: Wed, 11 May 2016 19:45:18 +0900 Subject: [PATCH] fix many build errors, wanrings and deprecations --- src/med/buffer.d | 4 +- src/med/console.d | 2 +- src/med/disp.d | 2 +- src/med/display.d | 17 ++-- src/med/file.d | 10 +-- src/med/fileio.d | 1 + src/med/main.d | 200 ++++++++++++++++++++++++++++++++++++++++++++-- src/med/mouse.d | 1 + src/med/random.d | 1 + src/med/search.d | 13 +-- src/med/spawn.d | 6 +- src/med/tcap.d | 6 +- src/med/termio.d | 2 +- src/med/utf.d | 1 - src/med/window.d | 1 + src/med/word.d | 1 + src/med/xterm.d | 2 + 17 files changed, 237 insertions(+), 33 deletions(-) diff --git a/src/med/buffer.d b/src/med/buffer.d index 906229a..7ed8ad7 100644 --- a/src/med/buffer.d +++ b/src/med/buffer.d @@ -251,8 +251,8 @@ int makelist() int nbytes; int s; int type; - char b[6+1]; - char line[128]; + char[6+1] b; + char[128] line; blistp.b_flag &= ~BFCHG; /* Don't complain! */ if ((s=buffer_clear(blistp)) != TRUE) /* Blow old text away */ diff --git a/src/med/console.d b/src/med/console.d index bb5f871..c54a0c8 100644 --- a/src/med/console.d +++ b/src/med/console.d @@ -187,7 +187,7 @@ void updateline(int row,attchar_t[] buffer,attchar_t[] physical) int col; int numcols; CHAR_INFO *psb; - CHAR_INFO sbbuf[256]; + CHAR_INFO[256] sbbuf; CHAR_INFO *sb; COORD sbsize; static COORD sbcoord; diff --git a/src/med/disp.d b/src/med/disp.d index df69be5..e2fd658 100644 --- a/src/med/disp.d +++ b/src/med/disp.d @@ -31,7 +31,7 @@ struct disp_t ubyte mode; ubyte inited; ubyte ega; - ubyte reserved[3]; + ubyte[3] reserved; short nowrap; union diff --git a/src/med/display.d b/src/med/display.d index ac6b83a..a480344 100644 --- a/src/med/display.d +++ b/src/med/display.d @@ -34,7 +34,10 @@ import window; import main; import buffer; import disprev; +import console; +import termio; import terminal; +import xterm; import url; import utf; @@ -313,12 +316,13 @@ int getcol2(const(char)[] dotp, int doto) int coltodoto(LINE* lp, int col) { size_t len = llength(lp); - size_t i = 0; + int i = 0; while (i < len) { - if (getcol(lp,i) >= col) + if (getcol(lp, i) >= col) return i; - decodeUTF8(lp.l_text, i); + ulong j = i; + decodeUTF8(lp.l_text, j); } return i; } @@ -589,7 +593,7 @@ else wp.w_flag = 0; wp.w_force = 0; } - } /* if any update flags on */ + } /* if any update flags on */ debug (WFDEBUG) { modeline(wp); @@ -963,7 +967,7 @@ int mlyesno(string prompt) */ const HISTORY_MAX = 10; -string history[HISTORY_MAX]; +string[HISTORY_MAX] history; int history_top; int HDEC(int hi) { return (hi == 0) ? HISTORY_MAX - 1 : hi - 1; } @@ -1182,7 +1186,8 @@ int mlreply(string prompt, string init, out string result) //case InsKEY: case 0x11: /* ^Q, quote next */ c = term.t_getchar(); - default: + goto default; + default: if (c < 0 || c >= 0x7F) { // Error ctrlg(FALSE, 0); diff --git a/src/med/file.d b/src/med/file.d index 9a91713..46e1a2a 100644 --- a/src/med/file.d +++ b/src/med/file.d @@ -22,6 +22,7 @@ import core.stdc.stdlib; import std.stdio; import std.path; import std.string; +import std.file; import std.utf; import ed; @@ -164,7 +165,7 @@ int file_readin(string fname) { /* If the current buffer now becomes undisplayed */ if (--curbp.b_nwnd == 0) - { + { curbp.b_dotp = curwp.w_dotp; curbp.b_doto = curwp.w_doto; curbp.b_markp = curwp.w_markp; @@ -173,7 +174,7 @@ int file_readin(string fname) curbp = bp; curwp.w_bufp = bp; if (bp.b_nwnd++ == 0) /* if buffer not already displayed */ - { + { curwp.w_dotp = bp.b_dotp; curwp.w_doto = bp.b_doto; curwp.w_markp = bp.b_markp; @@ -183,9 +184,9 @@ int file_readin(string fname) { /* Set dot to be at place where other window has it */ foreach (wp; windows) - { + { if (wp!=curwp && wp.w_bufp==bp) - { + { curwp.w_dotp = wp.w_dotp; curwp.w_doto = wp.w_doto; curwp.w_markp = wp.w_markp; @@ -570,4 +571,3 @@ int file_writeregion(string dfilename, REGION* region) return FALSE; } } - diff --git a/src/med/fileio.d b/src/med/fileio.d index 4384dae..5dcb7a6 100644 --- a/src/med/fileio.d +++ b/src/med/fileio.d @@ -72,6 +72,7 @@ bool ffreadonly(string name) } else { + import core.sys.posix.sys.stat; return exists && (a & S_IWUSR) == 0; } } diff --git a/src/med/main.d b/src/med/main.d index 7581389..9d0cdfe 100644 --- a/src/med/main.d +++ b/src/med/main.d @@ -54,6 +54,9 @@ import word; import spawn; import display; import terminal; +import termio; +import xterm; +import console; import line; import mouse; @@ -68,7 +71,7 @@ BUFFER *curbp; /* Current buffer */ WINDOW *curwp; /* Current window */ BUFFER *bheadp; /* BUFFER listhead */ BUFFER *blistp; /* Buffer list BUFFER */ -dchar kbdm[256] = [CTLX|')']; /* Macro */ +dchar[256] kbdm = [CTLX|')']; /* Macro */ dchar *kbdmip; /* Input for above */ dchar *kbdmop; /* Output for above */ string pat; /* search pattern */ @@ -208,6 +211,8 @@ struct KEYTAB { int function(bool, int) k_fp; /* Routine to handle it */ } +version(Windows) +{ immutable KEYTAB[] keytab = [ /* Definitions common to all versions */ @@ -360,6 +365,159 @@ immutable KEYTAB[] keytab = {0x8048, &help}, {0x8049, &openBrowser}, ]; +} else { +immutable KEYTAB[] keytab = +[ + /* Definitions common to all versions */ + { CTRL('@'), &ctrlg}, /*basic_setmark*/ + { CTRL('A'), &gotobol}, + { CTRL('B'), &backchar}, + { CTRL('C'), &quit}, + { CTRL('D'), &random_forwdel}, + { CTRL('E'), &gotoeol}, + { CTRL('F'), &forwchar}, + { CTRL('G'), &ctrlg}, + { CTRL('H'), &random_backdel}, + { CTRL('I'), &random_tab}, + { CTRL('J'), &Ddelline}, + { CTRL('K'), &random_kill}, + { CTRL('L'), &window_refresh}, + { CTRL('M'), &random_newline}, + { CTRL('N'), &forwline}, + { CTRL('O'), &random_openline}, + { CTRL('P'), &backline}, + { CTRL('Q'), &random_quote}, /* Often unreachable */ + { CTRL('R'), &backsearch}, + { CTRL('S'), &forwsearch}, /* Often unreachable */ + { CTRL('T'), &random_twiddle}, + { CTRL('V'), &forwpage}, + { CTRL('W'), &search_paren}, + { CTRL('Y'), &random_yank}, + { 0x7F, &random_backdel}, +/+ + /* Unused definitions from original microEMACS */ + { CTRL('C'), &spawncli}, /* Run CLI in subjob. */ + { CTRL('J'), &random_indent}, + { CTRL('W'), ®ion_kill}, + { CTRL('Z'), &quickexit}, /* quick save and exit */ ++/ + { CTRL('Z'), &spawncli}, /* Run CLI in subjob. */ + { F2KEY, &Dsearchagain}, + { F3KEY, &search_paren}, + { F4KEY, &Dsearch}, + { F5KEY, &basic_nextline}, + { F6KEY, &window_next}, + { F7KEY, &basic_setmark}, + { F8KEY, ®ion_copy}, + { F9KEY, ®ion_kill}, + { F10KEY, &random_yank}, + {F11KEY, &ctlxe}, + {F12KEY, ¯otoggle}, + {AltF1KEY, &display_norm_bg}, + {AltF2KEY, &display_norm_fg}, + {AltF3KEY, &display_mode_bg}, + {AltF5KEY, &display_mark_fg}, + {AltF6KEY, &display_mark_bg}, + {AltF4KEY, &display_mode_fg}, + {AltF7KEY, &display_eol_bg}, + {AltF9KEY, &random_decindent}, + {AltF10KEY, &random_incindent}, + {ALTB, &buffer_next}, + {ALTC, &main_saveconfig}, + {ALTX, &normexit}, + {ALTZ, &spawn_pipe}, + {RTKEY, &forwchar}, + {LTKEY, &backchar}, + {DNKEY, &forwline}, + {UPKEY, &backline}, + {InsKEY, &toggleinsert}, + {DelKEY, &random_forwdel}, + {PgUpKEY, &backpage}, + {PgDnKEY, &forwpage}, + {HOMEKEY, &window_mvup}, + {ENDKEY, &window_mvdn}, + {CtrlRTKEY, &word_forw}, + {CtrlLFKEY, &word_back}, + {CtrlHome, &gotobob}, + {CtrlEnd, &gotoeob}, + + /* Commands with a special key value */ + {0x8001, &spawn_pipe}, + {0x8002, &spawn_filter}, + {0x8003, &random_showcpos}, + {0x8004, &ctlxlp}, + {CMD_ENDMACRO, &ctlxrp}, + {0x8006, &random_decindent}, + {0x8007, &random_incindent}, + {0x8008, &window_only}, + {0x8009, &removemark}, + {0x800A, &spawn.spawn}, /* Run 1 command. */ + {0x800B, &window_split}, + {0x800C, &usebuffer}, + {0x800D, &delwind}, + {0x800E, &ctlxe}, + {0x800F, &random_setfillcol}, + {0x8010, &buffer.killbuffer}, + {0x8011, &window_next}, + {0x8012, &window_prev}, + {0x8013, &random_quote}, + {0x8014, &buffer_next}, + {0x8015, &window_enlarge}, + {0x8016, &listbuffers}, + {0x8017, &filename}, + {0x8018, &filemodify}, + {0x8019, &window_mvdn}, + {0x801A, &random_deblank}, + {0x801B, &window_mvup}, + {0x801C, &fileread}, + {0x801D, &filesave}, /* Often unreachable */ + {0x801E, &window_reposition}, + {0x801F, &filevisit}, + {0x8020, &filewrite}, + {0x8021, &swapmark}, + {0x8022, &window_shrink}, + + {0x8023, &delbword}, + {0x8024, &random_opttab}, + {0x8025, &basic_setmark}, + {0x8026, &gotoeob}, + {0x8027, &gotobob}, + {0x8028, ®ion_copy}, + {0x8029, ®ion_kill}, + {0x802A, &word_back}, + {0x802B, &capword}, + {0x802C, &delfword}, + {0x802D, &word_forw}, + {0x802E, &misc_lower}, + {0x802F, &queryreplacestring}, + {0x8030, &replacestring}, + {0x8031, &misc_upper}, + {0x8032, &backpage}, + {0x8033, &word_select}, + {0x8034, &Dadvance}, + {0x8035, &Dbackup}, + {0x8036, &random_deblank}, + + {0x8037, &Dinsertdate}, + {0x8038, &Dinsertfile}, + {0x8039, &gotoline}, + {0x803A, &fileunmodify}, + {0x803B, &filenext}, + {0x803C, &quit}, + {0x803D, &normexit}, + {0x803E, &Dundelline}, + {0x803F, &Dsearch}, + {0x8040, &Dundelword}, + {0x8041, &random_undelchar}, + {0x8042, &random_openline}, + {0x8043, &random_kill}, + {0x8044, ®ion_togglemode}, + {0x8045, &Dcppcomment}, + {0x8046, &random_hardtab}, + {0x8047, &word_wrap_line}, + {0x8049, &openBrowser}, +]; +} /* Translation table from 2 key sequence to single value */ immutable ushort[2][] altf_tab = @@ -386,6 +544,7 @@ immutable ushort[2][] altf_tab = [InsKEY, 0x8042], /* random_openline */ ]; +version (Windows) { immutable ushort[2][] esc_tab = [ ['.', 0x8025], /* basic_setmark */ @@ -418,6 +577,39 @@ immutable ushort[2][] esc_tab = [DNKEY, 0x8034], // Dadvance [UPKEY, 0x8035], // Dbackup ]; +} else { + immutable ushort[2][] esc_tab = +[ + ['.', 0x8025], /* basic_setmark */ + ['>', 0x8026], /* gotoeob */ + [ENDKEY, 0x8026], /* gotoeob */ + ['<', 0x8027], /* gotobob */ + [HOMEKEY, 0x8027], /* gotobob */ + ['8', 0x8028], /* region_copy */ + ['9', 0x8029], /* region_kill */ + ['B', 0x802A], /* word_back */ + ['C', 0x802B], /* capword */ + ['D', 0x802C], /* delfword */ + ['E', 0x8049], // openBrowser + ['F', 0x802D], /* word_forw */ + ['H', 0x8023], /* delbword */ + ['I', 0x8024], /* random_opttab */ + ['J', 0x803E], // Dundelline + ['L', 0x802E], /* misc_lower */ + ['N', 0x8019], /* window_mvdn */ + ['P', 0x801B], /* window_mvup */ + ['Q', 0x802F], /* queryreplacestring */ + ['R', 0x8030], /* replacestring */ + ['T', 0x8044], /* region_togglemode */ + ['U', 0x8031], /* misc_upper */ + ['V', 0x8032], /* backpage */ + ['W', 0x8033], /* word_select */ + ['X', 0x8021], /* swapmark */ + ['Z', 0x8022], /* window_shrink */ + [DNKEY, 0x8034], // Dadvance + [UPKEY, 0x8035], // Dbackup +]; +} immutable ushort[2][] ctlx_tab = [ @@ -454,7 +646,7 @@ struct CMDTAB immutable ushort[2][] kt; /* which translation table */ }; -CMDTAB cmdtab[] = +CMDTAB[] cmdtab = [ { CTLX, ctlx_tab }, { META, esc_tab }, @@ -516,7 +708,6 @@ int main(string[] args) } execute(0, c, f, n); /* Do it. */ } - return 0; } /****************************** @@ -593,7 +784,7 @@ void edinit(string bname) wp.w_ntrows = term.t_nrow-2; /* -1 for mode line, -1 for minibuffer */ wp.w_flag = WFMODE|WFHARD; /* Full. */ } - + /* * This is the general command execution routine. It handles the fake binding * of all the keys to "self-insert". It also clears out the "thisflag" word, @@ -903,4 +1094,3 @@ int toggleinsert(bool f, int n) term.t_setcursor(insertmode); return true; } - diff --git a/src/med/mouse.d b/src/med/mouse.d index e9cec17..d79a7c1 100644 --- a/src/med/mouse.d +++ b/src/med/mouse.d @@ -19,6 +19,7 @@ import line; import main; import terminal; import display; +import xterm; import word; //#include diff --git a/src/med/random.d b/src/med/random.d index 7173efb..1057dfb 100644 --- a/src/med/random.d +++ b/src/med/random.d @@ -25,6 +25,7 @@ import region; import display; import basic; import terminal; +import xterm; int tabsize; /* Tab size (0: use real tabs) */ diff --git a/src/med/search.d b/src/med/search.d index 0c857cc..414f659 100644 --- a/src/med/search.d +++ b/src/med/search.d @@ -34,6 +34,7 @@ import main; import buffer; import basic; import terminal; +import xterm; enum CASESENSITIVE = true; /* TRUE means case sensitive */ @@ -203,16 +204,17 @@ fail:; bool eq(int bc, int pc) { - if (CASESENSITIVE) + static if (CASESENSITIVE) return bc == pc; - - if (bc>='a' && bc<='z') + else { + if (bc>='a' && bc<='z') bc -= 0x20; - if (pc>='a' && pc<='z') + if (pc>='a' && pc<='z') pc -= 0x20; - return (bc == pc); + return (bc == pc); + } } /********************************* @@ -325,6 +327,7 @@ private int replace(bool query) /*case 'R':*/ /* enter recursive edit */ case '!': /* change rest w/o asking */ query = FALSE; + goto case; /* FALL-THROUGH */ case ' ': /* change and continue to next */ break; diff --git a/src/med/spawn.d b/src/med/spawn.d index 719acb6..6ca77e9 100644 --- a/src/med/spawn.d +++ b/src/med/spawn.d @@ -37,6 +37,7 @@ import display; import main; import file; import terminal; +import xterm; @@ -102,6 +103,7 @@ int spawn(bool f, int n) term.t_flush(); term.t_close(); /* stty to old modes */ core.stdc.stdlib.system(toUTF8(line).toStringz()); + import core.sys.posix.unistd; sleep(2); term.t_open(); printf("[End]"); /* Pause. */ @@ -135,7 +137,7 @@ int spawn_pipe(bool f, int n) /* get rid of the command output buffer if it exists */ if ((bp=buffer_find(bname, FALSE, BFTEMP)) != null) /* if buffer exists */ - { + { /* If buffer is displayed, try to move it off screen */ /* (can't remove an on-screen buffer) */ if (bp.b_nwnd) /* if buffer is displayed */ @@ -256,5 +258,3 @@ ret: remove(toUTF8(filnam2)); return s; } - - diff --git a/src/med/tcap.d b/src/med/tcap.d index a35254f..c9d0d55 100644 --- a/src/med/tcap.d +++ b/src/med/tcap.d @@ -51,7 +51,7 @@ enum ESC = 0x1B, } -char tcapbuf[2048]; +char[2048] tcapbuf; static const(char) *p; /* roving pointer into tcapbuf[] */ const(char)* CM, @@ -206,7 +206,7 @@ struct TERM LONGKEY* lkp,tmpp; static int backlen; - static char backc[16]; + static char[16] backc; /* * If there was a previously almost complete LONGKEY sequence @@ -488,7 +488,7 @@ static void build_one_long(const(char)* s, int keyval) } else { - tmpp = cast(LONGKEY *)malloc( + tmpp = cast(LONGKEY *)malloc( LONGKEY.sizeof * ++i ); while( i-- ) { diff --git a/src/med/termio.d b/src/med/termio.d index c23cef6..a50ed7a 100644 --- a/src/med/termio.d +++ b/src/med/termio.d @@ -84,7 +84,7 @@ int ttkeysininput() { int n; ioctl(0, FIONREAD, &n); - return n != 0; + return n != 0; } /****************************** diff --git a/src/med/utf.d b/src/med/utf.d index 3c30f5d..412f7b0 100644 --- a/src/med/utf.d +++ b/src/med/utf.d @@ -168,4 +168,3 @@ char[] toUTF8(return out char[4] buf, dchar c) nothrow @nogc @safe return buf[0 .. 4]; } } - diff --git a/src/med/window.d b/src/med/window.d index 8449f78..4f59ab1 100644 --- a/src/med/window.d +++ b/src/med/window.d @@ -22,6 +22,7 @@ import buffer; import line; import main; import terminal; +import xterm; import display; /* diff --git a/src/med/word.d b/src/med/word.d index ceaa0a3..571a5a4 100644 --- a/src/med/word.d +++ b/src/med/word.d @@ -23,6 +23,7 @@ import window; import random; import line; import terminal; +import xterm; import region; import basic; import display; diff --git a/src/med/xterm.d b/src/med/xterm.d index 86b739d..3e29d2b 100644 --- a/src/med/xterm.d +++ b/src/med/xterm.d @@ -153,7 +153,9 @@ struct TERM { // Get size of terminal winsize ws; + import core.sys.posix.sys.ioctl; ioctl(1, TIOCGWINSZ, &ws); + //printf("Columns: %d\tRows: %d\n", ws.ws_col, ws.ws_row); term.t_ncol = ws.ws_col; term.t_nrow = ws.ws_row;