├── .gitmodules ├── 1594979779.jpg ├── 3rd ├── CMakeLists.txt └── pdcurses │ ├── CMakeLists.txt │ ├── common │ ├── README.md │ ├── acs437.h │ ├── acsgr.h │ ├── acsuni.h │ ├── borland.lrf │ ├── font437.h │ ├── icon32.xpm │ ├── icon64.xpm │ ├── iconbmp.h │ ├── libobjs.mif │ ├── pdcurses.rc │ └── watcom.mif │ └── src │ ├── README.md │ ├── addch.c │ ├── addchstr.c │ ├── addstr.c │ ├── attr.c │ ├── beep.c │ ├── bkgd.c │ ├── border.c │ ├── clear.c │ ├── color.c │ ├── debug.c │ ├── delch.c │ ├── deleteln.c │ ├── getch.c │ ├── getstr.c │ ├── getyx.c │ ├── inch.c │ ├── inchstr.c │ ├── initscr.c │ ├── inopts.c │ ├── insch.c │ ├── insstr.c │ ├── instr.c │ ├── kernel.c │ ├── keyname.c │ ├── mouse.c │ ├── move.c │ ├── outopts.c │ ├── overlay.c │ ├── pad.c │ ├── panel.c │ ├── pdcclip.c │ ├── pdcdisp.c │ ├── pdcgetsc.c │ ├── pdckbd.c │ ├── pdcscrn.c │ ├── pdcsetsc.c │ ├── pdcutil.c │ ├── pdcwin.h │ ├── printw.c │ ├── refresh.c │ ├── scanw.c │ ├── scr_dump.c │ ├── scroll.c │ ├── slk.c │ ├── termattr.c │ ├── touch.c │ ├── util.c │ └── window.c ├── CMakeLists.txt ├── README.md ├── include ├── colors.h ├── command_bar.h ├── earn.h ├── fund.h ├── fund_board.h ├── help.h ├── msg.h ├── pdcurses │ ├── curses.h │ ├── curspriv.h │ └── panel.h ├── port.h ├── status_bar.h ├── timer.h ├── util.h └── win.h ├── src ├── colors.cc ├── command_bar.cc ├── earn.cc ├── fund_board.cc ├── help.cc ├── main.cc ├── msg.cc ├── status_bar.cc ├── timer.cc └── util.cc └── test.json /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd/rapidjson"] 2 | path = 3rd/rapidjson 3 | url = https://github.com/Tencent/rapidjson.git 4 | [submodule "3rd/curl"] 5 | path = 3rd/curl 6 | url = https://github.com/curl/curl.git 7 | [submodule "3rd/csylib"] 8 | path = 3rd/csylib 9 | url = https://github.com/geniusC/csylib.git 10 | -------------------------------------------------------------------------------- /1594979779.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanhan-GKD/BigMoney/22e39ff0ac73c3e4ba5c6228345725c789a9f308/1594979779.jpg -------------------------------------------------------------------------------- /3rd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | execute_process(COMMAND git submodule init 2 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 3 | if (WIN32 OR MSVC) 4 | message(STATUS "Fetch submodule code into 3rd...") 5 | execute_process(COMMAND git submodule update 3rd/curl 6 | COMMAND git submodule update 3rd/rapidjson 7 | COMMAND git submodule update 3rd/csylib 8 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 9 | add_subdirectory(pdcurses) 10 | # option for curl, static lib only 11 | option(BUILD_CURL_EXE "" OFF) 12 | option(BUILD_SHARED_LIBS "" OFF ) 13 | add_subdirectory(curl) 14 | else() 15 | message(STATUS "Fetch submodule code into 3rd...") 16 | execute_process(COMMAND git submodule update 3rd/rapidjson 17 | COMMAND git submodule update 3rd/csylib 18 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 19 | endif() 20 | -------------------------------------------------------------------------------- /3rd/pdcurses/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | aux_source_directory(src PD_SOURCE) 2 | add_library(pdcurses STATIC ${PD_SOURCE}) 3 | target_include_directories(pdcurses PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 4 | target_include_directories(pdcurses PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include/pdcurses) -------------------------------------------------------------------------------- /3rd/pdcurses/common/README.md: -------------------------------------------------------------------------------- 1 | PDCurses common files 2 | ===================== 3 | 4 | This directory is for files which are platform-specific, yet shared by 5 | more than one platform, in contrast to the "common core" in ../pdcurses. 6 | 7 | 8 | Distribution Status 9 | ------------------- 10 | 11 | The files in this directory are released to the public domain. 12 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/acs437.h: -------------------------------------------------------------------------------- 1 | /* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these 2 | match code page 437 and compatible pages (CP850, CP852, etc.) */ 3 | 4 | chtype acs_map[128] = 5 | { 6 | PDC_ACS(0), PDC_ACS(1), PDC_ACS(2), PDC_ACS(3), PDC_ACS(4), 7 | PDC_ACS(5), PDC_ACS(6), PDC_ACS(7), PDC_ACS(8), PDC_ACS(9), 8 | PDC_ACS(10), PDC_ACS(11), PDC_ACS(12), PDC_ACS(13), PDC_ACS(14), 9 | PDC_ACS(15), PDC_ACS(16), PDC_ACS(17), PDC_ACS(18), PDC_ACS(19), 10 | PDC_ACS(20), PDC_ACS(21), PDC_ACS(22), PDC_ACS(23), PDC_ACS(24), 11 | PDC_ACS(25), PDC_ACS(26), PDC_ACS(27), PDC_ACS(28), PDC_ACS(29), 12 | PDC_ACS(30), PDC_ACS(31), ' ', '!', '"', '#', '$', '%', '&', '\'', 13 | '(', ')', '*', 14 | 15 | PDC_ACS(0x1a), PDC_ACS(0x1b), PDC_ACS(0x18), PDC_ACS(0x19), 16 | 17 | '/', 18 | 19 | 0xdb, 20 | 21 | '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', 22 | '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 23 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 24 | 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', 25 | 26 | PDC_ACS(0x04), 0xb1, 27 | 28 | 'b', 'c', 'd', 'e', 29 | 30 | 0xf8, 0xf1, 0xb0, PDC_ACS(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 31 | 0x2d, 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 32 | 0xe3, 0xd8, 0x9c, 0xf9, 33 | 34 | PDC_ACS(127) 35 | }; 36 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/acsgr.h: -------------------------------------------------------------------------------- 1 | /* ACS Unicode mapping with punchouts for box characters et al. */ 2 | 3 | chtype acs_map[128] = 4 | { 5 | PDC_ACS(0), PDC_ACS(1), PDC_ACS(2), PDC_ACS(3), PDC_ACS(4), 6 | PDC_ACS(5), PDC_ACS(6), PDC_ACS(7), PDC_ACS(8), PDC_ACS(9), 7 | PDC_ACS(10), PDC_ACS(11), PDC_ACS(12), PDC_ACS(13), PDC_ACS(14), 8 | PDC_ACS(15), PDC_ACS(16), PDC_ACS(17), PDC_ACS(18), PDC_ACS(19), 9 | PDC_ACS(20), PDC_ACS(21), PDC_ACS(22), PDC_ACS(23), PDC_ACS(24), 10 | PDC_ACS(25), PDC_ACS(26), PDC_ACS(27), PDC_ACS(28), PDC_ACS(29), 11 | PDC_ACS(30), PDC_ACS(31), ' ', '!', '"', '#', '$', '%', '&', '\'', 12 | '(', ')', '*', 13 | 14 | 0x2192, 0x2190, 0x2191, 0x2193, 15 | 16 | '/', 17 | 18 | ACS_BLOCK, 19 | 20 | '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', 21 | '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 22 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 23 | 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', 24 | 25 | 0x2666, 0x2592, 26 | 27 | 'b', 'c', 'd', 'e', 28 | 29 | 0x00b0, 0x00b1, 0x2591, 0x00a4, ACS_LRCORNER, ACS_URCORNER, 30 | ACS_ULCORNER, ACS_LLCORNER, ACS_PLUS, ACS_S1, ACS_S3, ACS_HLINE, 31 | ACS_S7, ACS_S9, ACS_LTEE, ACS_RTEE, ACS_BTEE, ACS_TTEE, ACS_VLINE, 32 | 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, 33 | 34 | PDC_ACS(127) 35 | }; 36 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/acsuni.h: -------------------------------------------------------------------------------- 1 | /* ACS Unicode mapping */ 2 | 3 | chtype acs_map[128] = 4 | { 5 | PDC_ACS(0), PDC_ACS(1), PDC_ACS(2), PDC_ACS(3), PDC_ACS(4), 6 | PDC_ACS(5), PDC_ACS(6), PDC_ACS(7), PDC_ACS(8), PDC_ACS(9), 7 | PDC_ACS(10), PDC_ACS(11), PDC_ACS(12), PDC_ACS(13), PDC_ACS(14), 8 | PDC_ACS(15), PDC_ACS(16), PDC_ACS(17), PDC_ACS(18), PDC_ACS(19), 9 | PDC_ACS(20), PDC_ACS(21), PDC_ACS(22), PDC_ACS(23), PDC_ACS(24), 10 | PDC_ACS(25), PDC_ACS(26), PDC_ACS(27), PDC_ACS(28), PDC_ACS(29), 11 | PDC_ACS(30), PDC_ACS(31), ' ', '!', '"', '#', '$', '%', '&', '\'', 12 | '(', ')', '*', 13 | 14 | 0x2192, 0x2190, 0x2191, 0x2193, 15 | 16 | '/', 17 | 18 | 0x2588, 19 | 20 | '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', 21 | '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 22 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 23 | 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', 24 | 25 | 0x2666, 0x2592, 26 | 27 | 'b', 'c', 'd', 'e', 28 | 29 | 0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514, 30 | 0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 31 | 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 32 | 0x00b7, 33 | 34 | PDC_ACS(127) 35 | }; 36 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/borland.lrf: -------------------------------------------------------------------------------- 1 | +addch.obj +addchstr.obj +addstr.obj +attr.obj +beep.obj +bkgd.obj & 2 | +border.obj +clear.obj +color.obj +delch.obj +deleteln.obj & 3 | +getch.obj +getstr.obj +getyx.obj +inch.obj +inchstr.obj +initscr.obj & 4 | +inopts.obj +insch.obj +insstr.obj +instr.obj +kernel.obj +keyname.obj & 5 | +mouse.obj +move.obj +outopts.obj +overlay.obj +pad.obj +panel.obj & 6 | +printw.obj +refresh.obj +scanw.obj +scr_dump.obj +scroll.obj +slk.obj & 7 | +termattr.obj +touch.obj +util.obj +window.obj +debug.obj & 8 | +pdcclip.obj +pdcdisp.obj +pdcgetsc.obj +pdckbd.obj +pdcscrn.obj & 9 | +pdcsetsc.obj +pdcutil.obj ,lib.map 10 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/icon32.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *icon32[] = { 3 | /* width height ncolors chars_per_pixel */ 4 | "32 32 3 1", 5 | /* colors */ 6 | " c #000", 7 | ". c #FFF", 8 | "X c None", 9 | /* pixels */ 10 | "................................", 11 | "................................", 12 | "................................", 13 | ".......... .... ..........", 14 | ".......... ... ..........", 15 | ".......... ... .. ..........", 16 | ".......... .... .. ..........", 17 | ".......... .... .. ..........", 18 | ".......... ... .. ..........", 19 | ".......... .. .. ..........", 20 | ".......... . .. ..........", 21 | ".......... .. ..........", 22 | ".......... .. . ..........", 23 | ".......... .. .. ..........", 24 | ".......... .. ... ..........", 25 | ".......... .. .... ..........", 26 | ".......... .. .... ..........", 27 | ".......... .. ... ..........", 28 | ".......... ... ..........", 29 | ".......... .... ..........", 30 | "................................", 31 | "................................", 32 | ".. .. .. . . ... ... ... ...", 33 | ". .. . .. . . . .. . .. . .. ..", 34 | ". .... .. . .... .... .. . .....", 35 | ". .... .. . ..... .. ... ...", 36 | ". .... .. . ....... . ....... ..", 37 | ". .. . .. . .... .. . .. . .. ..", 38 | ".. ... .. ..... ... ... ...", 39 | "................................", 40 | "................................", 41 | "................................" 42 | }; 43 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/icon64.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *icon64[] = { 3 | /* width height ncolors chars_per_pixel */ 4 | "64 64 3 1", 5 | /* colors */ 6 | " c #000", 7 | ". c #FFF", 8 | "X c None", 9 | /* pixels */ 10 | "................................................................", 11 | "................................................................", 12 | "................................................................", 13 | "................................................................", 14 | "................................................................", 15 | "................................................................", 16 | "................................................................", 17 | ".................... ...... ......................", 18 | ".................... ..... ......................", 19 | ".................... .... ......................", 20 | ".................... .... ......................", 21 | ".................... ...... ... ......................", 22 | ".................... ....... ... ......................", 23 | ".................... ....... ... ......................", 24 | ".................... ....... ... ......................", 25 | ".................... ....... ... ......................", 26 | ".................... ...... ... ......................", 27 | ".................... ..... .... ......................", 28 | ".................... .... ... ......................", 29 | ".................... ... ... ......................", 30 | ".................... .. ... ......................", 31 | ".................... . ... ......................", 32 | ".................... ... ......................", 33 | ".................... ... ......................", 34 | ".................... ... . ......................", 35 | ".................... ... .. ......................", 36 | ".................... ... ... ......................", 37 | ".................... ... .... ......................", 38 | ".................... .... ..... ......................", 39 | ".................... ... ...... ......................", 40 | ".................... ... ....... ......................", 41 | ".................... ... ....... ......................", 42 | ".................... ... ....... ......................", 43 | ".................... ... ....... ......................", 44 | ".................... ... ...... ......................", 45 | ".................... .... ......................", 46 | ".................... .... ......................", 47 | ".................... ..... ......................", 48 | ".................... ...... ......................", 49 | "................................................................", 50 | "................................................................", 51 | "................................................................", 52 | "................................................................", 53 | "...... ... ...... . .. ..... ..... ..... ......", 54 | "..... .. .. ...... . . .. ... ... ... .. ... ... .....", 55 | ".... .... . ...... . .... . ..... . .... . ..... ....", 56 | ".... ...... . ...... . ...... . ....... . ...... . ....... ....", 57 | ".... ........ ...... . ......... ....... . ...... . ....... ....", 58 | ".... ........ ...... . ......... ........ ...... . ...........", 59 | ".... ........ ...... . .......... ....... ...... .. ..........", 60 | ".... ........ ...... . ........... ... ... ......", 61 | ".... ........ ...... . ............... .. .............. .....", 62 | ".... ........ ...... . ................ . ............... ....", 63 | ".... ........ ...... . ......... ....... . ...... . ....... ....", 64 | ".... ...... . ...... . ......... ....... . ...... . ....... ....", 65 | ".... .... . .... . ......... ..... . .... . ..... ....", 66 | "..... .. ... .. .. .......... ... ... .. ... ... .....", 67 | "...... ..... ... ........... ..... ..... ......", 68 | "................................................................", 69 | "................................................................", 70 | "................................................................", 71 | "................................................................", 72 | "................................................................", 73 | "................................................................" 74 | }; 75 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/iconbmp.h: -------------------------------------------------------------------------------- 1 | /* The PDCurses logo as #include'able BMP (from icon32.xpm), 2 | for use by SDL. */ 3 | 4 | unsigned char iconbmp[] = 5 | { 6 | 0x42, 0x4d, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 7 | 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 8 | 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x80, 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 10 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 11 | 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 12 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xce, 0x6f, 0x9c, 13 | 0xe7, 0xb5, 0xaf, 0x6b, 0x5b, 0xbd, 0xaf, 0xeb, 0xfb, 0xbd, 0xaf, 14 | 0x98, 0xe7, 0xbd, 0xaf, 0x7b, 0x5f, 0xb5, 0xa5, 0x6b, 0x5b, 0xcd, 15 | 0xab, 0x9c, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 16 | 0xff, 0xcf, 0x03, 0xff, 0xff, 0xce, 0x03, 0xff, 0xff, 0xcc, 0x73, 17 | 0xff, 0xff, 0xcc, 0xf3, 0xff, 0xff, 0xcc, 0xf3, 0xff, 0xff, 0xcc, 18 | 0x73, 0xff, 0xff, 0xc6, 0x33, 0xff, 0xff, 0xc3, 0x13, 0xff, 0xff, 19 | 0xc1, 0x83, 0xff, 0xff, 0xc8, 0xc3, 0xff, 0xff, 0xcc, 0x63, 0xff, 20 | 0xff, 0xce, 0x33, 0xff, 0xff, 0xcf, 0x33, 0xff, 0xff, 0xcf, 0x33, 21 | 0xff, 0xff, 0xce, 0x33, 0xff, 0xff, 0xc0, 0x73, 0xff, 0xff, 0xc0, 22 | 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 23 | 0xff, 0xff, 0xff 24 | }; 25 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/libobjs.mif: -------------------------------------------------------------------------------- 1 | # Common elements for most of the DOS, OS/2 and Windows 2 | # makefiles (not Watcom) 3 | 4 | PDCURSES_CURSES_H = $(PDCURSES_SRCDIR)/curses.h 5 | PDCURSES_CURSPRIV_H = $(PDCURSES_SRCDIR)/curspriv.h 6 | PDCURSES_HEADERS = $(PDCURSES_CURSES_H) $(PDCURSES_CURSPRIV_H) 7 | PANEL_HEADER = $(PDCURSES_SRCDIR)/panel.h 8 | 9 | srcdir = $(PDCURSES_SRCDIR)/pdcurses 10 | demodir = $(PDCURSES_SRCDIR)/demos 11 | 12 | LIBOBJS = addch.$(O) addchstr.$(O) addstr.$(O) attr.$(O) beep.$(O) \ 13 | bkgd.$(O) border.$(O) clear.$(O) color.$(O) delch.$(O) deleteln.$(O) \ 14 | getch.$(O) getstr.$(O) getyx.$(O) inch.$(O) inchstr.$(O) \ 15 | initscr.$(O) inopts.$(O) insch.$(O) insstr.$(O) instr.$(O) kernel.$(O) \ 16 | keyname.$(O) mouse.$(O) move.$(O) outopts.$(O) overlay.$(O) pad.$(O) \ 17 | panel.$(O) printw.$(O) refresh.$(O) scanw.$(O) scr_dump.$(O) scroll.$(O) \ 18 | slk.$(O) termattr.$(O) touch.$(O) util.$(O) window.$(O) debug.$(O) 19 | 20 | PDCOBJS = pdcclip.$(O) pdcdisp.$(O) pdcgetsc.$(O) pdckbd.$(O) pdcscrn.$(O) \ 21 | pdcsetsc.$(O) pdcutil.$(O) 22 | 23 | DEMOS = testcurs$(E) ozdemo$(E) xmas$(E) tuidemo$(E) firework$(E) \ 24 | ptest$(E) rain$(E) worm$(E) 25 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/pdcurses.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../curses.h" 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION PDC_VER_MAJOR,PDC_VER_MINOR,0,0 6 | PRODUCTVERSION PDC_VER_MAJOR,PDC_VER_MINOR,0,0 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 | #ifdef _DEBUG 9 | FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE 10 | #else 11 | FILEFLAGS 0 12 | #endif 13 | FILEOS VOS_NT_WINDOWS32 14 | FILETYPE VFT_DLL 15 | FILESUBTYPE VFT2_UNKNOWN 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "04090000" 20 | BEGIN 21 | VALUE "CompanyName", "PDCurses.org" 22 | VALUE "FileDescription", "PDCurses Library" 23 | VALUE "FileVersion", PDC_VERDOT ".0.0" 24 | VALUE "InternalName", "PDCurses" 25 | VALUE "LegalCopyright", "Public Domain" 26 | VALUE "OriginalFilename", "pdcurses.dll" 27 | VALUE "ProductName", "PDCurses" 28 | VALUE "ProductVersion", PDC_VERDOT ".0.0" 29 | END 30 | END 31 | BLOCK "VarFileInfo" 32 | BEGIN 33 | VALUE "Translation", 0x409, 0 34 | END 35 | END 36 | -------------------------------------------------------------------------------- /3rd/pdcurses/common/watcom.mif: -------------------------------------------------------------------------------- 1 | # Common elements for the Watcom makefiles 2 | 3 | CFLAGS += -wx -zq -i=$(PDCURSES_SRCDIR) 4 | 5 | !ifeq DEBUG Y 6 | CFLAGS += -d2 -DPDCDEBUG 7 | LDFLAGS = D W A op q sys $(TARGET) 8 | !else 9 | CFLAGS += -oneatx 10 | LDFLAGS = op q sys $(TARGET) 11 | !endif 12 | 13 | RM = del 14 | LIBEXE = wlib -q -n -b -c -t 15 | 16 | srcdir = $(PDCURSES_SRCDIR)/pdcurses 17 | demodir = $(PDCURSES_SRCDIR)/demos 18 | 19 | LIBOBJS = addch.obj addchstr.obj addstr.obj attr.obj beep.obj bkgd.obj & 20 | border.obj clear.obj color.obj delch.obj deleteln.obj & 21 | getch.obj getstr.obj getyx.obj inch.obj inchstr.obj initscr.obj inopts.obj & 22 | insch.obj insstr.obj instr.obj kernel.obj keyname.obj mouse.obj move.obj & 23 | outopts.obj overlay.obj pad.obj panel.obj printw.obj refresh.obj & 24 | scanw.obj scr_dump.obj scroll.obj slk.obj termattr.obj & 25 | touch.obj util.obj window.obj debug.obj 26 | 27 | PDCOBJS = pdcclip.obj pdcdisp.obj pdcgetsc.obj pdckbd.obj pdcscrn.obj & 28 | pdcsetsc.obj pdcutil.obj 29 | 30 | DEMOS = testcurs.exe ozdemo.exe xmas.exe tuidemo.exe firework.exe & 31 | ptest.exe rain.exe worm.exe 32 | 33 | LIBCURSES = pdcurses.lib 34 | 35 | LINK = wlink 36 | 37 | !ifdef __LOADDLL__ 38 | ! loaddll wcc wccd 39 | ! loaddll wcc386 wccd386 40 | ! loaddll wlink wlinkd 41 | ! loaddll wlib wlibd 42 | !endif 43 | 44 | all: $(LIBCURSES) 45 | 46 | clean 47 | -$(RM) *.obj 48 | -$(RM) *.lib 49 | -$(RM) *.exe 50 | -$(RM) *.err 51 | 52 | demos: $(DEMOS) 53 | 54 | .c: $(srcdir);$(osdir);$(demodir) 55 | .c.obj: .autodepend 56 | $(CC) $(CFLAGS) $< 57 | 58 | .obj.exe: 59 | $(LINK) $(LDFLAGS) n $@ f $*.obj l $(LIBCURSES) 60 | 61 | testcurs.exe: testcurs.obj $(LIBCURSES) 62 | ozdemo.exe: ozdemo.obj $(LIBCURSES) 63 | xmas.exe: xmas.obj $(LIBCURSES) 64 | firework.exe: firework.obj $(LIBCURSES) 65 | rain.exe: rain.obj $(LIBCURSES) 66 | worm.exe: worm.obj $(LIBCURSES) 67 | ptest.exe: ptest.obj $(LIBCURSES) 68 | 69 | tuidemo.exe: tuidemo.obj tui.obj $(LIBCURSES) 70 | $(LINK) $(LDFLAGS) n $@ f tuidemo.obj f tui.obj l $(LIBCURSES) 71 | 72 | dist: .symbolic 73 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/README.md: -------------------------------------------------------------------------------- 1 | PDCurses Portable Core 2 | ====================== 3 | 4 | This directory contains core PDCurses source code files common to all 5 | platforms. 6 | 7 | 8 | Building 9 | -------- 10 | 11 | These modules are built by the platform-specific makefiles, in the 12 | platform directories. 13 | 14 | 15 | Distribution Status 16 | ------------------- 17 | 18 | The files in this directory are released to the public domain. 19 | 20 | 21 | Acknowledgements 22 | ---------------- 23 | 24 | The panel library was originally provided by 25 | Warren Tucker 26 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/addchstr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | addchstr 8 | -------- 9 | 10 | ### Synopsis 11 | 12 | int addchstr(const chtype *ch); 13 | int addchnstr(const chtype *ch, int n); 14 | int waddchstr(WINDOW *win, const chtype *ch); 15 | int waddchnstr(WINDOW *win, const chtype *ch, int n); 16 | int mvaddchstr(int y, int x, const chtype *ch); 17 | int mvaddchnstr(int y, int x, const chtype *ch, int n); 18 | int mvwaddchstr(WINDOW *, int y, int x, const chtype *ch); 19 | int mvwaddchnstr(WINDOW *, int y, int x, const chtype *ch, int n); 20 | 21 | int add_wchstr(const cchar_t *wch); 22 | int add_wchnstr(const cchar_t *wch, int n); 23 | int wadd_wchstr(WINDOW *win, const cchar_t *wch); 24 | int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n); 25 | int mvadd_wchstr(int y, int x, const cchar_t *wch); 26 | int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n); 27 | int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch); 28 | int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, 29 | int n); 30 | 31 | ### Description 32 | 33 | These routines write a chtype or cchar_t string directly into the 34 | window structure, starting at the current or specified position. The 35 | four routines with n as the last argument copy at most n elements, 36 | but no more than will fit on the line. If n == -1 then the whole 37 | string is copied, up to the maximum number that will fit on the line. 38 | 39 | The cursor position is not advanced. These routines do not check for 40 | newline or other special characters, nor does any line wrapping 41 | occur. 42 | 43 | ### Return Value 44 | 45 | All functions return OK or ERR. 46 | 47 | ### Portability 48 | X/Open ncurses NetBSD 49 | addchstr Y Y Y 50 | waddchstr Y Y Y 51 | mvaddchstr Y Y Y 52 | mvwaddchstr Y Y Y 53 | addchnstr Y Y Y 54 | waddchnstr Y Y Y 55 | mvaddchnstr Y Y Y 56 | mvwaddchnstr Y Y Y 57 | add_wchstr Y Y Y 58 | wadd_wchstr Y Y Y 59 | mvadd_wchstr Y Y Y 60 | mvwadd_wchstr Y Y Y 61 | add_wchnstr Y Y Y 62 | wadd_wchnstr Y Y Y 63 | mvadd_wchnstr Y Y Y 64 | mvwadd_wchnstr Y Y Y 65 | 66 | **man-end****************************************************************/ 67 | 68 | #include 69 | 70 | int waddchnstr(WINDOW *win, const chtype *ch, int n) 71 | { 72 | int y, x, maxx, minx; 73 | chtype *ptr; 74 | 75 | PDC_LOG(("waddchnstr() - called: win=%p n=%d\n", win, n)); 76 | 77 | if (!win || !ch || !n || n < -1) 78 | return ERR; 79 | 80 | x = win->_curx; 81 | y = win->_cury; 82 | ptr = &(win->_y[y][x]); 83 | 84 | if (n == -1 || n > win->_maxx - x) 85 | n = win->_maxx - x; 86 | 87 | minx = win->_firstch[y]; 88 | maxx = win->_lastch[y]; 89 | 90 | for (; n && *ch; n--, x++, ptr++, ch++) 91 | { 92 | if (*ptr != *ch) 93 | { 94 | if (x < minx || minx == _NO_CHANGE) 95 | minx = x; 96 | 97 | if (x > maxx) 98 | maxx = x; 99 | 100 | PDC_LOG(("y %d x %d minx %d maxx %d *ptr %x *ch" 101 | " %x firstch: %d lastch: %d\n", 102 | y, x, minx, maxx, *ptr, *ch, 103 | win->_firstch[y], win->_lastch[y])); 104 | 105 | *ptr = *ch; 106 | } 107 | } 108 | 109 | win->_firstch[y] = minx; 110 | win->_lastch[y] = maxx; 111 | 112 | return OK; 113 | } 114 | 115 | int addchstr(const chtype *ch) 116 | { 117 | PDC_LOG(("addchstr() - called\n")); 118 | 119 | return waddchnstr(stdscr, ch, -1); 120 | } 121 | 122 | int addchnstr(const chtype *ch, int n) 123 | { 124 | PDC_LOG(("addchnstr() - called\n")); 125 | 126 | return waddchnstr(stdscr, ch, n); 127 | } 128 | 129 | int waddchstr(WINDOW *win, const chtype *ch) 130 | { 131 | PDC_LOG(("waddchstr() - called: win=%p\n", win)); 132 | 133 | return waddchnstr(win, ch, -1); 134 | } 135 | 136 | int mvaddchstr(int y, int x, const chtype *ch) 137 | { 138 | PDC_LOG(("mvaddchstr() - called: y %d x %d\n", y, x)); 139 | 140 | if (move(y, x) == ERR) 141 | return ERR; 142 | 143 | return waddchnstr(stdscr, ch, -1); 144 | } 145 | 146 | int mvaddchnstr(int y, int x, const chtype *ch, int n) 147 | { 148 | PDC_LOG(("mvaddchnstr() - called: y %d x %d n %d\n", y, x, n)); 149 | 150 | if (move(y, x) == ERR) 151 | return ERR; 152 | 153 | return waddchnstr(stdscr, ch, n); 154 | } 155 | 156 | int mvwaddchstr(WINDOW *win, int y, int x, const chtype *ch) 157 | { 158 | PDC_LOG(("mvwaddchstr() - called:\n")); 159 | 160 | if (wmove(win, y, x) == ERR) 161 | return ERR; 162 | 163 | return waddchnstr(win, ch, -1); 164 | } 165 | 166 | int mvwaddchnstr(WINDOW *win, int y, int x, const chtype *ch, int n) 167 | { 168 | PDC_LOG(("mvwaddchnstr() - called: y %d x %d n %d \n", y, x, n)); 169 | 170 | if (wmove(win, y, x) == ERR) 171 | return ERR; 172 | 173 | return waddchnstr(win, ch, n); 174 | } 175 | 176 | #ifdef PDC_WIDE 177 | int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n) 178 | { 179 | PDC_LOG(("wadd_wchnstr() - called: win=%p n=%d\n", win, n)); 180 | 181 | return waddchnstr(win, wch, n); 182 | } 183 | 184 | int add_wchstr(const cchar_t *wch) 185 | { 186 | PDC_LOG(("add_wchstr() - called\n")); 187 | 188 | return wadd_wchnstr(stdscr, wch, -1); 189 | } 190 | 191 | int add_wchnstr(const cchar_t *wch, int n) 192 | { 193 | PDC_LOG(("add_wchnstr() - called\n")); 194 | 195 | return wadd_wchnstr(stdscr, wch, n); 196 | } 197 | 198 | int wadd_wchstr(WINDOW *win, const cchar_t *wch) 199 | { 200 | PDC_LOG(("wadd_wchstr() - called: win=%p\n", win)); 201 | 202 | return wadd_wchnstr(win, wch, -1); 203 | } 204 | 205 | int mvadd_wchstr(int y, int x, const cchar_t *wch) 206 | { 207 | PDC_LOG(("mvadd_wchstr() - called: y %d x %d\n", y, x)); 208 | 209 | if (move(y, x) == ERR) 210 | return ERR; 211 | 212 | return wadd_wchnstr(stdscr, wch, -1); 213 | } 214 | 215 | int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n) 216 | { 217 | PDC_LOG(("mvadd_wchnstr() - called: y %d x %d n %d\n", y, x, n)); 218 | 219 | if (move(y, x) == ERR) 220 | return ERR; 221 | 222 | return wadd_wchnstr(stdscr, wch, n); 223 | } 224 | 225 | int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch) 226 | { 227 | PDC_LOG(("mvwadd_wchstr() - called:\n")); 228 | 229 | if (wmove(win, y, x) == ERR) 230 | return ERR; 231 | 232 | return wadd_wchnstr(win, wch, -1); 233 | } 234 | 235 | int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, int n) 236 | { 237 | PDC_LOG(("mvwadd_wchnstr() - called: y %d x %d n %d \n", y, x, n)); 238 | 239 | if (wmove(win, y, x) == ERR) 240 | return ERR; 241 | 242 | return wadd_wchnstr(win, wch, n); 243 | } 244 | #endif 245 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/addstr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | addstr 8 | ------ 9 | 10 | ### Synopsis 11 | 12 | int addstr(const char *str); 13 | int addnstr(const char *str, int n); 14 | int waddstr(WINDOW *win, const char *str); 15 | int waddnstr(WINDOW *win, const char *str, int n); 16 | int mvaddstr(int y, int x, const char *str); 17 | int mvaddnstr(int y, int x, const char *str, int n); 18 | int mvwaddstr(WINDOW *win, int y, int x, const char *str); 19 | int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n); 20 | 21 | int addwstr(const wchar_t *wstr); 22 | int addnwstr(const wchar_t *wstr, int n); 23 | int waddwstr(WINDOW *win, const wchar_t *wstr); 24 | int waddnwstr(WINDOW *win, const wchar_t *wstr, int n); 25 | int mvaddwstr(int y, int x, const wchar_t *wstr); 26 | int mvaddnwstr(int y, int x, const wchar_t *wstr, int n); 27 | int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr); 28 | int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n); 29 | 30 | ### Description 31 | 32 | These routines write all the characters of the null-terminated string 33 | str or wide-character string wstr to the given window. The 34 | functionality is similar to calling waddch() once for each character 35 | in the string; except that, when PDCurses is built with wide- 36 | character support enabled, the narrow-character functions treat the 37 | string as a multibyte string in the current locale, and convert it. 38 | The routines with n as the last argument write at most n characters; 39 | if n is negative, then the entire string will be added. 40 | 41 | ### Return Value 42 | 43 | All functions return OK or ERR. 44 | 45 | ### Portability 46 | X/Open ncurses NetBSD 47 | addstr Y Y Y 48 | waddstr Y Y Y 49 | mvaddstr Y Y Y 50 | mvwaddstr Y Y Y 51 | addnstr Y Y Y 52 | waddnstr Y Y Y 53 | mvaddnstr Y Y Y 54 | mvwaddnstr Y Y Y 55 | addwstr Y Y Y 56 | waddwstr Y Y Y 57 | mvaddwstr Y Y Y 58 | mvwaddwstr Y Y Y 59 | addnwstr Y Y Y 60 | waddnwstr Y Y Y 61 | mvaddnwstr Y Y Y 62 | mvwaddnwstr Y Y Y 63 | 64 | **man-end****************************************************************/ 65 | 66 | int waddnstr(WINDOW *win, const char *str, int n) 67 | { 68 | int i = 0; 69 | 70 | PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n)); 71 | 72 | if (!win || !str) 73 | return ERR; 74 | 75 | while (str[i] && (i < n || n < 0)) 76 | { 77 | #ifdef PDC_WIDE 78 | wchar_t wch; 79 | int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6); 80 | 81 | if (retval <= 0) 82 | return OK; 83 | 84 | i += retval; 85 | #else 86 | chtype wch = (unsigned char)(str[i++]); 87 | #endif 88 | if (waddch(win, wch) == ERR) 89 | return ERR; 90 | } 91 | 92 | return OK; 93 | } 94 | 95 | int addstr(const char *str) 96 | { 97 | PDC_LOG(("addstr() - called: string=\"%s\"\n", str)); 98 | 99 | return waddnstr(stdscr, str, -1); 100 | } 101 | 102 | int addnstr(const char *str, int n) 103 | { 104 | PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n)); 105 | 106 | return waddnstr(stdscr, str, n); 107 | } 108 | 109 | int waddstr(WINDOW *win, const char *str) 110 | { 111 | PDC_LOG(("waddstr() - called: string=\"%s\"\n", str)); 112 | 113 | return waddnstr(win, str, -1); 114 | } 115 | 116 | int mvaddstr(int y, int x, const char *str) 117 | { 118 | PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); 119 | 120 | if (move(y, x) == ERR) 121 | return ERR; 122 | 123 | return waddnstr(stdscr, str, -1); 124 | } 125 | 126 | int mvaddnstr(int y, int x, const char *str, int n) 127 | { 128 | PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n", 129 | y, x, str, n)); 130 | 131 | if (move(y, x) == ERR) 132 | return ERR; 133 | 134 | return waddnstr(stdscr, str, n); 135 | } 136 | 137 | int mvwaddstr(WINDOW *win, int y, int x, const char *str) 138 | { 139 | PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str)); 140 | 141 | if (wmove(win, y, x) == ERR) 142 | return ERR; 143 | 144 | return waddnstr(win, str, -1); 145 | } 146 | 147 | int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n) 148 | { 149 | PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n", 150 | y, x, str, n)); 151 | 152 | if (wmove(win, y, x) == ERR) 153 | return ERR; 154 | 155 | return waddnstr(win, str, n); 156 | } 157 | 158 | #ifdef PDC_WIDE 159 | int waddnwstr(WINDOW *win, const wchar_t *wstr, int n) 160 | { 161 | int i = 0; 162 | 163 | PDC_LOG(("waddnwstr() - called\n")); 164 | 165 | if (!win || !wstr) 166 | return ERR; 167 | 168 | while (wstr[i] && (i < n || n < 0)) 169 | { 170 | chtype wch = wstr[i++]; 171 | 172 | if (waddch(win, wch) == ERR) 173 | return ERR; 174 | } 175 | 176 | return OK; 177 | } 178 | 179 | int addwstr(const wchar_t *wstr) 180 | { 181 | PDC_LOG(("addwstr() - called\n")); 182 | 183 | return waddnwstr(stdscr, wstr, -1); 184 | } 185 | 186 | int addnwstr(const wchar_t *wstr, int n) 187 | { 188 | PDC_LOG(("addnwstr() - called\n")); 189 | 190 | return waddnwstr(stdscr, wstr, n); 191 | } 192 | 193 | int waddwstr(WINDOW *win, const wchar_t *wstr) 194 | { 195 | PDC_LOG(("waddwstr() - called\n")); 196 | 197 | return waddnwstr(win, wstr, -1); 198 | } 199 | 200 | int mvaddwstr(int y, int x, const wchar_t *wstr) 201 | { 202 | PDC_LOG(("mvaddstr() - called\n")); 203 | 204 | if (move(y, x) == ERR) 205 | return ERR; 206 | 207 | return waddnwstr(stdscr, wstr, -1); 208 | } 209 | 210 | int mvaddnwstr(int y, int x, const wchar_t *wstr, int n) 211 | { 212 | PDC_LOG(("mvaddnstr() - called\n")); 213 | 214 | if (move(y, x) == ERR) 215 | return ERR; 216 | 217 | return waddnwstr(stdscr, wstr, n); 218 | } 219 | 220 | int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr) 221 | { 222 | PDC_LOG(("mvwaddstr() - called\n")); 223 | 224 | if (wmove(win, y, x) == ERR) 225 | return ERR; 226 | 227 | return waddnwstr(win, wstr, -1); 228 | } 229 | 230 | int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) 231 | { 232 | PDC_LOG(("mvwaddnstr() - called\n")); 233 | 234 | if (wmove(win, y, x) == ERR) 235 | return ERR; 236 | 237 | return waddnwstr(win, wstr, n); 238 | } 239 | #endif 240 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/beep.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | beep 8 | ---- 9 | 10 | ### Synopsis 11 | 12 | int beep(void); 13 | int flash(void); 14 | 15 | ### Description 16 | 17 | beep() sounds the audible bell on the terminal, if possible; if not, 18 | it calls flash(). 19 | 20 | flash() "flashes" the screen, by inverting the foreground and 21 | background of every cell, pausing, and then restoring the original 22 | attributes. 23 | 24 | ### Return Value 25 | 26 | These functions return ERR if called before initscr(), otherwise OK. 27 | 28 | ### Portability 29 | X/Open ncurses NetBSD 30 | beep Y Y Y 31 | flash Y Y Y 32 | 33 | **man-end****************************************************************/ 34 | 35 | int beep(void) 36 | { 37 | PDC_LOG(("beep() - called\n")); 38 | 39 | if (!SP) 40 | return ERR; 41 | 42 | if (SP->audible) 43 | PDC_beep(); 44 | else 45 | flash(); 46 | 47 | return OK; 48 | } 49 | 50 | int flash(void) 51 | { 52 | int z, y, x; 53 | 54 | PDC_LOG(("flash() - called\n")); 55 | 56 | if (!curscr) 57 | return ERR; 58 | 59 | /* Reverse each cell; wait; restore the screen */ 60 | 61 | for (z = 0; z < 2; z++) 62 | { 63 | for (y = 0; y < LINES; y++) 64 | for (x = 0; x < COLS; x++) 65 | curscr->_y[y][x] ^= A_REVERSE; 66 | 67 | wrefresh(curscr); 68 | 69 | if (!z) 70 | napms(50); 71 | } 72 | 73 | return OK; 74 | } 75 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/bkgd.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | bkgd 8 | ---- 9 | 10 | ### Synopsis 11 | 12 | int bkgd(chtype ch); 13 | void bkgdset(chtype ch); 14 | chtype getbkgd(WINDOW *win); 15 | int wbkgd(WINDOW *win, chtype ch); 16 | void wbkgdset(WINDOW *win, chtype ch); 17 | 18 | int bkgrnd(const cchar_t *wch); 19 | void bkgrndset(const cchar_t *wch); 20 | int getbkgrnd(cchar_t *wch); 21 | int wbkgrnd(WINDOW *win, const cchar_t *wch); 22 | void wbkgrndset(WINDOW *win, const cchar_t *wch); 23 | int wgetbkgrnd(WINDOW *win, cchar_t *wch); 24 | 25 | ### Description 26 | 27 | bkgdset() and wbkgdset() manipulate the background of a window. The 28 | background is a chtype consisting of any combination of attributes 29 | and a character; it is combined with each chtype added or inserted to 30 | the window by waddch() or winsch(). Only the attribute part is used 31 | to set the background of non-blank characters, while both character 32 | and attributes are used for blank positions. 33 | 34 | bkgd() and wbkgd() not only change the background, but apply it 35 | immediately to every cell in the window. 36 | 37 | wbkgrnd(), wbkgrndset() and wgetbkgrnd() are the "wide-character" 38 | versions of these functions, taking a pointer to a cchar_t instead of 39 | a chtype. However, in PDCurses, cchar_t and chtype are the same. 40 | 41 | The attributes that are defined with the attrset()/attron() set of 42 | functions take precedence over the background attributes if there is 43 | a conflict (e.g., different color pairs). 44 | 45 | ### Return Value 46 | 47 | bkgd() and wbkgd() return OK, unless the window is NULL, in which 48 | case they return ERR. 49 | 50 | ### Portability 51 | X/Open ncurses NetBSD 52 | bkgd Y Y Y 53 | bkgdset Y Y Y 54 | getbkgd Y Y Y 55 | wbkgd Y Y Y 56 | wbkgdset Y Y Y 57 | bkgrnd Y Y Y 58 | bkgrndset Y Y Y 59 | getbkgrnd Y Y Y 60 | wbkgrnd Y Y Y 61 | wbkgrndset Y Y Y 62 | wgetbkgrnd Y Y Y 63 | 64 | **man-end****************************************************************/ 65 | 66 | int wbkgd(WINDOW *win, chtype ch) 67 | { 68 | int x, y; 69 | chtype oldcolr, oldch, newcolr, newch, colr, attr; 70 | chtype oldattr = 0, newattr = 0; 71 | chtype *winptr; 72 | 73 | PDC_LOG(("wbkgd() - called\n")); 74 | 75 | if (!win) 76 | return ERR; 77 | 78 | if (win->_bkgd == ch) 79 | return OK; 80 | 81 | oldcolr = win->_bkgd & A_COLOR; 82 | if (oldcolr) 83 | oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr; 84 | 85 | oldch = win->_bkgd & A_CHARTEXT; 86 | 87 | wbkgdset(win, ch); 88 | 89 | newcolr = win->_bkgd & A_COLOR; 90 | if (newcolr) 91 | newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr; 92 | 93 | newch = win->_bkgd & A_CHARTEXT; 94 | 95 | /* what follows is what seems to occur in the System V 96 | implementation of this routine */ 97 | 98 | for (y = 0; y < win->_maxy; y++) 99 | { 100 | for (x = 0; x < win->_maxx; x++) 101 | { 102 | winptr = win->_y[y] + x; 103 | 104 | ch = *winptr; 105 | 106 | /* determine the colors and attributes of the character read 107 | from the window */ 108 | 109 | colr = ch & A_COLOR; 110 | attr = ch & (A_ATTRIBUTES ^ A_COLOR); 111 | 112 | /* if the color is the same as the old background color, 113 | then make it the new background color, otherwise leave it */ 114 | 115 | if (colr == oldcolr) 116 | colr = newcolr; 117 | 118 | /* remove any attributes (non color) from the character that 119 | were part of the old background, then combine the 120 | remaining ones with the new background */ 121 | 122 | attr ^= oldattr; 123 | attr |= newattr; 124 | 125 | /* change character if it is there because it was the old 126 | background character */ 127 | 128 | ch &= A_CHARTEXT; 129 | if (ch == oldch) 130 | ch = newch; 131 | 132 | ch |= (attr | colr); 133 | 134 | *winptr = ch; 135 | 136 | } 137 | } 138 | 139 | touchwin(win); 140 | PDC_sync(win); 141 | return OK; 142 | } 143 | 144 | int bkgd(chtype ch) 145 | { 146 | PDC_LOG(("bkgd() - called\n")); 147 | 148 | return wbkgd(stdscr, ch); 149 | } 150 | 151 | void wbkgdset(WINDOW *win, chtype ch) 152 | { 153 | PDC_LOG(("wbkgdset() - called\n")); 154 | 155 | if (win) 156 | { 157 | if (!(ch & A_CHARTEXT)) 158 | ch |= ' '; 159 | 160 | win->_bkgd = ch; 161 | } 162 | } 163 | 164 | void bkgdset(chtype ch) 165 | { 166 | PDC_LOG(("bkgdset() - called\n")); 167 | 168 | wbkgdset(stdscr, ch); 169 | } 170 | 171 | chtype getbkgd(WINDOW *win) 172 | { 173 | PDC_LOG(("getbkgd() - called\n")); 174 | 175 | return win ? win->_bkgd : (chtype)ERR; 176 | } 177 | 178 | #ifdef PDC_WIDE 179 | int wbkgrnd(WINDOW *win, const cchar_t *wch) 180 | { 181 | PDC_LOG(("wbkgrnd() - called\n")); 182 | 183 | return wch ? wbkgd(win, *wch) : ERR; 184 | } 185 | 186 | int bkgrnd(const cchar_t *wch) 187 | { 188 | PDC_LOG(("bkgrnd() - called\n")); 189 | 190 | return wbkgrnd(stdscr, wch); 191 | } 192 | 193 | void wbkgrndset(WINDOW *win, const cchar_t *wch) 194 | { 195 | PDC_LOG(("wbkgdset() - called\n")); 196 | 197 | if (wch) 198 | wbkgdset(win, *wch); 199 | } 200 | 201 | void bkgrndset(const cchar_t *wch) 202 | { 203 | PDC_LOG(("bkgrndset() - called\n")); 204 | 205 | wbkgrndset(stdscr, wch); 206 | } 207 | 208 | int wgetbkgrnd(WINDOW *win, cchar_t *wch) 209 | { 210 | PDC_LOG(("wgetbkgrnd() - called\n")); 211 | 212 | if (!win || !wch) 213 | return ERR; 214 | 215 | *wch = win->_bkgd; 216 | 217 | return OK; 218 | } 219 | 220 | int getbkgrnd(cchar_t *wch) 221 | { 222 | PDC_LOG(("getbkgrnd() - called\n")); 223 | 224 | return wgetbkgrnd(stdscr, wch); 225 | } 226 | #endif 227 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/clear.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | clear 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | int clear(void); 13 | int wclear(WINDOW *win); 14 | int erase(void); 15 | int werase(WINDOW *win); 16 | int clrtobot(void); 17 | int wclrtobot(WINDOW *win); 18 | int clrtoeol(void); 19 | int wclrtoeol(WINDOW *win); 20 | 21 | ### Description 22 | 23 | erase() and werase() copy blanks (i.e. the background chtype) to 24 | every cell of the window. 25 | 26 | clear() and wclear() are similar to erase() and werase(), but they 27 | also call clearok() to ensure that the the window is cleared on the 28 | next wrefresh(). 29 | 30 | clrtobot() and wclrtobot() clear the window from the current cursor 31 | position to the end of the window. 32 | 33 | clrtoeol() and wclrtoeol() clear the window from the current cursor 34 | position to the end of the current line. 35 | 36 | ### Return Value 37 | 38 | All functions return OK on success and ERR on error. 39 | 40 | ### Portability 41 | X/Open ncurses NetBSD 42 | clear Y Y Y 43 | wclear Y Y Y 44 | erase Y Y Y 45 | werase Y Y Y 46 | clrtobot Y Y Y 47 | wclrtobot Y Y Y 48 | clrtoeol Y Y Y 49 | wclrtoeol Y Y Y 50 | 51 | **man-end****************************************************************/ 52 | 53 | int wclrtoeol(WINDOW *win) 54 | { 55 | int x, y, minx; 56 | chtype blank, *ptr; 57 | 58 | PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n", 59 | win->_cury, win->_curx)); 60 | 61 | if (!win) 62 | return ERR; 63 | 64 | y = win->_cury; 65 | x = win->_curx; 66 | 67 | /* wrs (4/10/93) account for window background */ 68 | 69 | blank = win->_bkgd; 70 | 71 | for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++) 72 | *ptr = blank; 73 | 74 | if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE) 75 | win->_firstch[y] = x; 76 | 77 | win->_lastch[y] = win->_maxx - 1; 78 | 79 | PDC_sync(win); 80 | return OK; 81 | } 82 | 83 | int clrtoeol(void) 84 | { 85 | PDC_LOG(("clrtoeol() - called\n")); 86 | 87 | return wclrtoeol(stdscr); 88 | } 89 | 90 | int wclrtobot(WINDOW *win) 91 | { 92 | int savey, savex; 93 | 94 | PDC_LOG(("wclrtobot() - called\n")); 95 | 96 | if (!win) 97 | return ERR; 98 | 99 | savey = win->_cury; 100 | savex = win->_curx; 101 | 102 | /* should this involve scrolling region somehow ? */ 103 | 104 | if (win->_cury + 1 < win->_maxy) 105 | { 106 | win->_curx = 0; 107 | win->_cury++; 108 | for (; win->_maxy > win->_cury; win->_cury++) 109 | wclrtoeol(win); 110 | win->_cury = savey; 111 | win->_curx = savex; 112 | } 113 | wclrtoeol(win); 114 | 115 | PDC_sync(win); 116 | return OK; 117 | } 118 | 119 | int clrtobot(void) 120 | { 121 | PDC_LOG(("clrtobot() - called\n")); 122 | 123 | return wclrtobot(stdscr); 124 | } 125 | 126 | int werase(WINDOW *win) 127 | { 128 | PDC_LOG(("werase() - called\n")); 129 | 130 | if (wmove(win, 0, 0) == ERR) 131 | return ERR; 132 | 133 | return wclrtobot(win); 134 | } 135 | 136 | int erase(void) 137 | { 138 | PDC_LOG(("erase() - called\n")); 139 | 140 | return werase(stdscr); 141 | } 142 | 143 | int wclear(WINDOW *win) 144 | { 145 | PDC_LOG(("wclear() - called\n")); 146 | 147 | if (!win) 148 | return ERR; 149 | 150 | win->_clear = TRUE; 151 | return werase(win); 152 | } 153 | 154 | int clear(void) 155 | { 156 | PDC_LOG(("clear() - called\n")); 157 | 158 | return wclear(stdscr); 159 | } 160 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/debug.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | debug 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | void traceon(void); 13 | void traceoff(void); 14 | void PDC_debug(const char *, ...); 15 | 16 | ### Description 17 | 18 | traceon() and traceoff() toggle the recording of debugging 19 | information to the file "trace". Although not standard, similar 20 | functions are in some other curses implementations. 21 | 22 | PDC_debug() is the function that writes to the file, based on whether 23 | traceon() has been called. It's used from the PDC_LOG() macro. 24 | 25 | The environment variable PDC_TRACE_FLUSH controls whether the trace 26 | file contents are fflushed after each write. The default is not. Set 27 | it to enable this (may affect performance). 28 | 29 | ### Portability 30 | X/Open ncurses NetBSD 31 | traceon - - - 32 | traceoff - - - 33 | PDC_debug - - - 34 | 35 | **man-end****************************************************************/ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static bool want_fflush = FALSE; 43 | 44 | void PDC_debug(const char *fmt, ...) 45 | { 46 | va_list args; 47 | char hms[9]; 48 | time_t now; 49 | 50 | if (!SP || !SP->dbfp) 51 | return; 52 | 53 | time(&now); 54 | strftime(hms, 9, "%H:%M:%S", localtime(&now)); 55 | fprintf(SP->dbfp, "At: %8.8ld - %s ", (long) clock(), hms); 56 | 57 | va_start(args, fmt); 58 | vfprintf(SP->dbfp, fmt, args); 59 | va_end(args); 60 | 61 | /* If you are crashing and losing debugging information, enable this 62 | by setting the environment variable PDC_TRACE_FLUSH. This may 63 | impact performance. */ 64 | 65 | if (want_fflush) 66 | fflush(SP->dbfp); 67 | 68 | /* If with PDC_TRACE_FLUSH enabled you are still losing logging in 69 | crashes, you may need to add a platform-dependent mechanism to 70 | flush the OS buffers as well (such as fsync() on POSIX) -- but 71 | expect terrible performance. */ 72 | } 73 | 74 | void traceon(void) 75 | { 76 | if (!SP) 77 | return; 78 | 79 | if (SP->dbfp) 80 | fclose(SP->dbfp); 81 | 82 | /* open debug log file append */ 83 | SP->dbfp = fopen("trace", "a"); 84 | if (!SP->dbfp) 85 | { 86 | fprintf(stderr, "PDC_debug(): Unable to open debug log file\n"); 87 | return; 88 | } 89 | 90 | if (getenv("PDC_TRACE_FLUSH")) 91 | want_fflush = TRUE; 92 | 93 | PDC_LOG(("traceon() - called\n")); 94 | } 95 | 96 | void traceoff(void) 97 | { 98 | if (!SP || !SP->dbfp) 99 | return; 100 | 101 | PDC_LOG(("traceoff() - called\n")); 102 | 103 | fclose(SP->dbfp); 104 | SP->dbfp = NULL; 105 | want_fflush = FALSE; 106 | } 107 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/delch.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | delch 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | int delch(void); 13 | int wdelch(WINDOW *win); 14 | int mvdelch(int y, int x); 15 | int mvwdelch(WINDOW *win, int y, int x); 16 | 17 | ### Description 18 | 19 | The character under the cursor in the window is deleted. All 20 | characters to the right on the same line are moved to the left one 21 | position and the last character on the line is filled with a blank. 22 | The cursor position does not change (after moving to y, x if 23 | coordinates are specified). 24 | 25 | ### Return Value 26 | 27 | All functions return OK on success and ERR on error. 28 | 29 | ### Portability 30 | X/Open ncurses NetBSD 31 | delch Y Y Y 32 | wdelch Y Y Y 33 | mvdelch Y Y Y 34 | mvwdelch Y Y Y 35 | 36 | **man-end****************************************************************/ 37 | 38 | #include 39 | 40 | int wdelch(WINDOW *win) 41 | { 42 | int y, x, maxx; 43 | chtype *temp1; 44 | 45 | PDC_LOG(("wdelch() - called\n")); 46 | 47 | if (!win) 48 | return ERR; 49 | 50 | y = win->_cury; 51 | x = win->_curx; 52 | maxx = win->_maxx - 1; 53 | temp1 = &win->_y[y][x]; 54 | 55 | memmove(temp1, temp1 + 1, (maxx - x) * sizeof(chtype)); 56 | 57 | /* wrs (4/10/93) account for window background */ 58 | 59 | win->_y[y][maxx] = win->_bkgd; 60 | 61 | win->_lastch[y] = maxx; 62 | 63 | if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) 64 | win->_firstch[y] = x; 65 | 66 | PDC_sync(win); 67 | 68 | return OK; 69 | } 70 | 71 | int delch(void) 72 | { 73 | PDC_LOG(("delch() - called\n")); 74 | 75 | return wdelch(stdscr); 76 | } 77 | 78 | int mvdelch(int y, int x) 79 | { 80 | PDC_LOG(("mvdelch() - called\n")); 81 | 82 | if (move(y, x) == ERR) 83 | return ERR; 84 | 85 | return wdelch(stdscr); 86 | } 87 | 88 | int mvwdelch(WINDOW *win, int y, int x) 89 | { 90 | PDC_LOG(("mvwdelch() - called\n")); 91 | 92 | if (wmove(win, y, x) == ERR) 93 | return ERR; 94 | 95 | return wdelch(win); 96 | } 97 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/deleteln.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | deleteln 8 | -------- 9 | 10 | ### Synopsis 11 | 12 | int deleteln(void); 13 | int wdeleteln(WINDOW *win); 14 | int insdelln(int n); 15 | int winsdelln(WINDOW *win, int n); 16 | int insertln(void); 17 | int winsertln(WINDOW *win); 18 | 19 | int mvdeleteln(int y, int x); 20 | int mvwdeleteln(WINDOW *win, int y, int x); 21 | int mvinsertln(int y, int x); 22 | int mvwinsertln(WINDOW *win, int y, int x); 23 | 24 | ### Description 25 | 26 | With the deleteln() and wdeleteln() functions, the line under the 27 | cursor in the window is deleted. All lines below the current line are 28 | moved up one line. The bottom line of the window is cleared. The 29 | cursor position does not change. 30 | 31 | With the insertln() and winsertn() functions, a blank line is 32 | inserted above the current line and the bottom line is lost. 33 | 34 | mvdeleteln(), mvwdeleteln(), mvinsertln() and mvwinsertln() allow 35 | moving the cursor and inserting/deleting in one call. 36 | 37 | ### Return Value 38 | 39 | All functions return OK on success and ERR on error. 40 | 41 | ### Portability 42 | X/Open ncurses NetBSD 43 | deleteln Y Y Y 44 | wdeleteln Y Y Y 45 | mvdeleteln - - - 46 | mvwdeleteln - - - 47 | insdelln Y Y Y 48 | winsdelln Y Y Y 49 | insertln Y Y Y 50 | winsertln Y Y Y 51 | mvinsertln - - - 52 | mvwinsertln - - - 53 | 54 | **man-end****************************************************************/ 55 | 56 | int wdeleteln(WINDOW *win) 57 | { 58 | chtype blank, *temp, *ptr; 59 | int y; 60 | 61 | PDC_LOG(("wdeleteln() - called\n")); 62 | 63 | if (!win) 64 | return ERR; 65 | 66 | /* wrs (4/10/93) account for window background */ 67 | 68 | blank = win->_bkgd; 69 | 70 | temp = win->_y[win->_cury]; 71 | 72 | for (y = win->_cury; y < win->_bmarg; y++) 73 | { 74 | win->_y[y] = win->_y[y + 1]; 75 | win->_firstch[y] = 0; 76 | win->_lastch[y] = win->_maxx - 1; 77 | } 78 | 79 | for (ptr = temp; (ptr - temp < win->_maxx); ptr++) 80 | *ptr = blank; /* make a blank line */ 81 | 82 | if (win->_cury <= win->_bmarg) 83 | { 84 | win->_firstch[win->_bmarg] = 0; 85 | win->_lastch[win->_bmarg] = win->_maxx - 1; 86 | win->_y[win->_bmarg] = temp; 87 | } 88 | 89 | return OK; 90 | } 91 | 92 | int deleteln(void) 93 | { 94 | PDC_LOG(("deleteln() - called\n")); 95 | 96 | return wdeleteln(stdscr); 97 | } 98 | 99 | int mvdeleteln(int y, int x) 100 | { 101 | PDC_LOG(("mvdeleteln() - called\n")); 102 | 103 | if (move(y, x) == ERR) 104 | return ERR; 105 | 106 | return wdeleteln(stdscr); 107 | } 108 | 109 | int mvwdeleteln(WINDOW *win, int y, int x) 110 | { 111 | PDC_LOG(("mvwdeleteln() - called\n")); 112 | 113 | if (wmove(win, y, x) == ERR) 114 | return ERR; 115 | 116 | return wdeleteln(win); 117 | } 118 | 119 | int winsdelln(WINDOW *win, int n) 120 | { 121 | int i; 122 | 123 | PDC_LOG(("winsdelln() - called\n")); 124 | 125 | if (!win) 126 | return ERR; 127 | 128 | if (n > 0) 129 | { 130 | for (i = 0; i < n; i++) 131 | if (winsertln(win) == ERR) 132 | return ERR; 133 | } 134 | else if (n < 0) 135 | { 136 | n = -n; 137 | for (i = 0; i < n; i++) 138 | if (wdeleteln(win) == ERR) 139 | return ERR; 140 | } 141 | 142 | return OK; 143 | } 144 | 145 | int insdelln(int n) 146 | { 147 | PDC_LOG(("insdelln() - called\n")); 148 | 149 | return winsdelln(stdscr, n); 150 | } 151 | 152 | int winsertln(WINDOW *win) 153 | { 154 | chtype blank, *temp, *end; 155 | int y; 156 | 157 | PDC_LOG(("winsertln() - called\n")); 158 | 159 | if (!win) 160 | return ERR; 161 | 162 | /* wrs (4/10/93) account for window background */ 163 | 164 | blank = win->_bkgd; 165 | 166 | temp = win->_y[win->_maxy - 1]; 167 | 168 | for (y = win->_maxy - 1; y > win->_cury; y--) 169 | { 170 | win->_y[y] = win->_y[y - 1]; 171 | win->_firstch[y] = 0; 172 | win->_lastch[y] = win->_maxx - 1; 173 | } 174 | 175 | win->_y[win->_cury] = temp; 176 | 177 | for (end = &temp[win->_maxx - 1]; temp <= end; temp++) 178 | *temp = blank; 179 | 180 | win->_firstch[win->_cury] = 0; 181 | win->_lastch[win->_cury] = win->_maxx - 1; 182 | 183 | return OK; 184 | } 185 | 186 | int insertln(void) 187 | { 188 | PDC_LOG(("insertln() - called\n")); 189 | 190 | return winsertln(stdscr); 191 | } 192 | 193 | int mvinsertln(int y, int x) 194 | { 195 | PDC_LOG(("mvinsertln() - called\n")); 196 | 197 | if (move(y, x) == ERR) 198 | return ERR; 199 | 200 | return winsertln(stdscr); 201 | } 202 | 203 | int mvwinsertln(WINDOW *win, int y, int x) 204 | { 205 | PDC_LOG(("mvwinsertln() - called\n")); 206 | 207 | if (wmove(win, y, x) == ERR) 208 | return ERR; 209 | 210 | return winsertln(win); 211 | } 212 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/getyx.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | getyx 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | void getyx(WINDOW *win, int y, int x); 13 | void getparyx(WINDOW *win, int y, int x); 14 | void getbegyx(WINDOW *win, int y, int x); 15 | void getmaxyx(WINDOW *win, int y, int x); 16 | 17 | void getsyx(int y, int x); 18 | void setsyx(int y, int x); 19 | 20 | int getbegy(WINDOW *win); 21 | int getbegx(WINDOW *win); 22 | int getcury(WINDOW *win); 23 | int getcurx(WINDOW *win); 24 | int getpary(WINDOW *win); 25 | int getparx(WINDOW *win); 26 | int getmaxy(WINDOW *win); 27 | int getmaxx(WINDOW *win); 28 | 29 | ### Description 30 | 31 | The getyx() macro (defined in curses.h -- the prototypes here are 32 | merely illustrative) puts the current cursor position of the 33 | specified window into y and x. getbegyx() and getmaxyx() return the 34 | starting coordinates and size of the specified window, respectively. 35 | getparyx() returns the starting coordinates of the parent's window, 36 | if the specified window is a subwindow; otherwise it sets y and x to 37 | -1. These are all macros. 38 | 39 | getsyx() gets the coordinates of the virtual screen cursor, and 40 | stores them in y and x. If leaveok() is TRUE, it returns -1, -1. If 41 | lines have been removed with ripoffline(), then getsyx() includes 42 | these lines in its count; so, the returned y and x values should only 43 | be used with setsyx(). 44 | 45 | setsyx() sets the virtual screen cursor to the y, x coordinates. If 46 | either y or x is -1, leaveok() is set TRUE, else it's set FALSE. 47 | 48 | getsyx() and setsyx() are meant to be used by a library routine that 49 | manipulates curses windows without altering the position of the 50 | cursor. Note that getsyx() is defined only as a macro. 51 | 52 | getbegy(), getbegx(), getcurx(), getcury(), getmaxy(), getmaxx(), 53 | getpary(), and getparx() return the appropriate coordinate or size 54 | values, or ERR in the case of a NULL window. 55 | 56 | ### Portability 57 | X/Open ncurses NetBSD 58 | getyx Y Y Y 59 | getparyx Y Y Y 60 | getbegyx Y Y Y 61 | getmaxyx Y Y Y 62 | getsyx - Y Y 63 | setsyx - Y Y 64 | getbegy - Y Y 65 | getbegx - Y Y 66 | getcury - Y Y 67 | getcurx - Y Y 68 | getpary - Y Y 69 | getparx - Y Y 70 | getmaxy - Y Y 71 | getmaxx - Y Y 72 | 73 | **man-end****************************************************************/ 74 | 75 | int getbegy(WINDOW *win) 76 | { 77 | PDC_LOG(("getbegy() - called\n")); 78 | 79 | return win ? win->_begy : ERR; 80 | } 81 | 82 | int getbegx(WINDOW *win) 83 | { 84 | PDC_LOG(("getbegx() - called\n")); 85 | 86 | return win ? win->_begx : ERR; 87 | } 88 | 89 | int getcury(WINDOW *win) 90 | { 91 | PDC_LOG(("getcury() - called\n")); 92 | 93 | return win ? win->_cury : ERR; 94 | } 95 | 96 | int getcurx(WINDOW *win) 97 | { 98 | PDC_LOG(("getcurx() - called\n")); 99 | 100 | return win ? win->_curx : ERR; 101 | } 102 | 103 | int getpary(WINDOW *win) 104 | { 105 | PDC_LOG(("getpary() - called\n")); 106 | 107 | return win ? win->_pary : ERR; 108 | } 109 | 110 | int getparx(WINDOW *win) 111 | { 112 | PDC_LOG(("getparx() - called\n")); 113 | 114 | return win ? win->_parx : ERR; 115 | } 116 | 117 | int getmaxy(WINDOW *win) 118 | { 119 | PDC_LOG(("getmaxy() - called\n")); 120 | 121 | return win ? win->_maxy : ERR; 122 | } 123 | 124 | int getmaxx(WINDOW *win) 125 | { 126 | PDC_LOG(("getmaxx() - called\n")); 127 | 128 | return win ? win->_maxx : ERR; 129 | } 130 | 131 | void setsyx(int y, int x) 132 | { 133 | PDC_LOG(("setsyx() - called\n")); 134 | 135 | if (curscr) 136 | { 137 | curscr->_leaveit = y == -1 || x == -1; 138 | 139 | if (!curscr->_leaveit) 140 | wmove(curscr, y, x); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/inch.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | inch 8 | ---- 9 | 10 | ### Synopsis 11 | 12 | chtype inch(void); 13 | chtype winch(WINDOW *win); 14 | chtype mvinch(int y, int x); 15 | chtype mvwinch(WINDOW *win, int y, int x); 16 | 17 | int in_wch(cchar_t *wcval); 18 | int win_wch(WINDOW *win, cchar_t *wcval); 19 | int mvin_wch(int y, int x, cchar_t *wcval); 20 | int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval); 21 | 22 | ### Description 23 | 24 | The inch() functions retrieve the character and attribute from the 25 | current or specified window position, in the form of a chtype. If a 26 | NULL window is specified, (chtype)ERR is returned. 27 | 28 | The in_wch() functions are the wide-character versions; instead of 29 | returning a chtype, they store a cchar_t at the address specified by 30 | wcval, and return OK or ERR. (No value is stored when ERR is 31 | returned.) Note that in PDCurses, chtype and cchar_t are the same. 32 | 33 | ### Portability 34 | X/Open ncurses NetBSD 35 | inch Y Y Y 36 | winch Y Y Y 37 | mvinch Y Y Y 38 | mvwinch Y Y Y 39 | in_wch Y Y Y 40 | win_wch Y Y Y 41 | mvin_wch Y Y Y 42 | mvwin_wch Y Y Y 43 | 44 | **man-end****************************************************************/ 45 | 46 | chtype winch(WINDOW *win) 47 | { 48 | PDC_LOG(("winch() - called\n")); 49 | 50 | if (!win) 51 | return (chtype)ERR; 52 | 53 | return win->_y[win->_cury][win->_curx]; 54 | } 55 | 56 | chtype inch(void) 57 | { 58 | PDC_LOG(("inch() - called\n")); 59 | 60 | return winch(stdscr); 61 | } 62 | 63 | chtype mvinch(int y, int x) 64 | { 65 | PDC_LOG(("mvinch() - called\n")); 66 | 67 | if (move(y, x) == ERR) 68 | return (chtype)ERR; 69 | 70 | return stdscr->_y[stdscr->_cury][stdscr->_curx]; 71 | } 72 | 73 | chtype mvwinch(WINDOW *win, int y, int x) 74 | { 75 | PDC_LOG(("mvwinch() - called\n")); 76 | 77 | if (wmove(win, y, x) == ERR) 78 | return (chtype)ERR; 79 | 80 | return win->_y[win->_cury][win->_curx]; 81 | } 82 | 83 | #ifdef PDC_WIDE 84 | int win_wch(WINDOW *win, cchar_t *wcval) 85 | { 86 | PDC_LOG(("win_wch() - called\n")); 87 | 88 | if (!win || !wcval) 89 | return ERR; 90 | 91 | *wcval = win->_y[win->_cury][win->_curx]; 92 | 93 | return OK; 94 | } 95 | 96 | int in_wch(cchar_t *wcval) 97 | { 98 | PDC_LOG(("in_wch() - called\n")); 99 | 100 | return win_wch(stdscr, wcval); 101 | } 102 | 103 | int mvin_wch(int y, int x, cchar_t *wcval) 104 | { 105 | PDC_LOG(("mvin_wch() - called\n")); 106 | 107 | if (!wcval || (move(y, x) == ERR)) 108 | return ERR; 109 | 110 | *wcval = stdscr->_y[stdscr->_cury][stdscr->_curx]; 111 | 112 | return OK; 113 | } 114 | 115 | int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval) 116 | { 117 | PDC_LOG(("mvwin_wch() - called\n")); 118 | 119 | if (!wcval || (wmove(win, y, x) == ERR)) 120 | return ERR; 121 | 122 | *wcval = win->_y[win->_cury][win->_curx]; 123 | 124 | return OK; 125 | } 126 | #endif 127 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/inchstr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | inchstr 8 | ------- 9 | 10 | ### Synopsis 11 | 12 | int inchstr(chtype *ch); 13 | int inchnstr(chtype *ch, int n); 14 | int winchstr(WINDOW *win, chtype *ch); 15 | int winchnstr(WINDOW *win, chtype *ch, int n); 16 | int mvinchstr(int y, int x, chtype *ch); 17 | int mvinchnstr(int y, int x, chtype *ch, int n); 18 | int mvwinchstr(WINDOW *, int y, int x, chtype *ch); 19 | int mvwinchnstr(WINDOW *, int y, int x, chtype *ch, int n); 20 | 21 | int in_wchstr(cchar_t *wch); 22 | int in_wchnstr(cchar_t *wch, int n); 23 | int win_wchstr(WINDOW *win, cchar_t *wch); 24 | int win_wchnstr(WINDOW *win, cchar_t *wch, int n); 25 | int mvin_wchstr(int y, int x, cchar_t *wch); 26 | int mvin_wchnstr(int y, int x, cchar_t *wch, int n); 27 | int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch); 28 | int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n); 29 | 30 | ### Description 31 | 32 | These routines read a chtype or cchar_t string from the window, 33 | starting at the current or specified position, and ending at the 34 | right margin, or after n elements, whichever is less. 35 | 36 | ### Return Value 37 | 38 | All functions return the number of elements read, or ERR on error. 39 | 40 | ### Portability 41 | X/Open ncurses NetBSD 42 | inchstr Y Y Y 43 | winchstr Y Y Y 44 | mvinchstr Y Y Y 45 | mvwinchstr Y Y Y 46 | inchnstr Y Y Y 47 | winchnstr Y Y Y 48 | mvinchnstr Y Y Y 49 | mvwinchnstr Y Y Y 50 | in_wchstr Y Y Y 51 | win_wchstr Y Y Y 52 | mvin_wchstr Y Y Y 53 | mvwin_wchstr Y Y Y 54 | in_wchnstr Y Y Y 55 | win_wchnstr Y Y Y 56 | mvin_wchnstr Y Y Y 57 | mvwin_wchnstr Y Y Y 58 | 59 | **man-end****************************************************************/ 60 | 61 | int winchnstr(WINDOW *win, chtype *ch, int n) 62 | { 63 | chtype *src; 64 | int i; 65 | 66 | PDC_LOG(("winchnstr() - called\n")); 67 | 68 | if (!win || !ch || n < 0) 69 | return ERR; 70 | 71 | if ((win->_curx + n) > win->_maxx) 72 | n = win->_maxx - win->_curx; 73 | 74 | src = win->_y[win->_cury] + win->_curx; 75 | 76 | for (i = 0; i < n; i++) 77 | *ch++ = *src++; 78 | 79 | *ch = (chtype)0; 80 | 81 | return OK; 82 | } 83 | 84 | int inchstr(chtype *ch) 85 | { 86 | PDC_LOG(("inchstr() - called\n")); 87 | 88 | return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx); 89 | } 90 | 91 | int winchstr(WINDOW *win, chtype *ch) 92 | { 93 | PDC_LOG(("winchstr() - called\n")); 94 | 95 | return winchnstr(win, ch, win->_maxx - win->_curx); 96 | } 97 | 98 | int mvinchstr(int y, int x, chtype *ch) 99 | { 100 | PDC_LOG(("mvinchstr() - called: y %d x %d\n", y, x)); 101 | 102 | if (move(y, x) == ERR) 103 | return ERR; 104 | 105 | return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx); 106 | } 107 | 108 | int mvwinchstr(WINDOW *win, int y, int x, chtype *ch) 109 | { 110 | PDC_LOG(("mvwinchstr() - called:\n")); 111 | 112 | if (wmove(win, y, x) == ERR) 113 | return ERR; 114 | 115 | return winchnstr(win, ch, win->_maxx - win->_curx); 116 | } 117 | 118 | int inchnstr(chtype *ch, int n) 119 | { 120 | PDC_LOG(("inchnstr() - called\n")); 121 | 122 | return winchnstr(stdscr, ch, n); 123 | } 124 | 125 | int mvinchnstr(int y, int x, chtype *ch, int n) 126 | { 127 | PDC_LOG(("mvinchnstr() - called: y %d x %d n %d\n", y, x, n)); 128 | 129 | if (move(y, x) == ERR) 130 | return ERR; 131 | 132 | return winchnstr(stdscr, ch, n); 133 | } 134 | 135 | int mvwinchnstr(WINDOW *win, int y, int x, chtype *ch, int n) 136 | { 137 | PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n)); 138 | 139 | if (wmove(win, y, x) == ERR) 140 | return ERR; 141 | 142 | return winchnstr(win, ch, n); 143 | } 144 | 145 | #ifdef PDC_WIDE 146 | int win_wchnstr(WINDOW *win, cchar_t *wch, int n) 147 | { 148 | PDC_LOG(("win_wchnstr() - called\n")); 149 | 150 | return winchnstr(win, wch, n); 151 | } 152 | 153 | int in_wchstr(cchar_t *wch) 154 | { 155 | PDC_LOG(("in_wchstr() - called\n")); 156 | 157 | return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx); 158 | } 159 | 160 | int win_wchstr(WINDOW *win, cchar_t *wch) 161 | { 162 | PDC_LOG(("win_wchstr() - called\n")); 163 | 164 | return win_wchnstr(win, wch, win->_maxx - win->_curx); 165 | } 166 | 167 | int mvin_wchstr(int y, int x, cchar_t *wch) 168 | { 169 | PDC_LOG(("mvin_wchstr() - called: y %d x %d\n", y, x)); 170 | 171 | if (move(y, x) == ERR) 172 | return ERR; 173 | 174 | return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx); 175 | } 176 | 177 | int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch) 178 | { 179 | PDC_LOG(("mvwin_wchstr() - called:\n")); 180 | 181 | if (wmove(win, y, x) == ERR) 182 | return ERR; 183 | 184 | return win_wchnstr(win, wch, win->_maxx - win->_curx); 185 | } 186 | 187 | int in_wchnstr(cchar_t *wch, int n) 188 | { 189 | PDC_LOG(("in_wchnstr() - called\n")); 190 | 191 | return win_wchnstr(stdscr, wch, n); 192 | } 193 | 194 | int mvin_wchnstr(int y, int x, cchar_t *wch, int n) 195 | { 196 | PDC_LOG(("mvin_wchnstr() - called: y %d x %d n %d\n", y, x, n)); 197 | 198 | if (move(y, x) == ERR) 199 | return ERR; 200 | 201 | return win_wchnstr(stdscr, wch, n); 202 | } 203 | 204 | int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n) 205 | { 206 | PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n)); 207 | 208 | if (wmove(win, y, x) == ERR) 209 | return ERR; 210 | 211 | return win_wchnstr(win, wch, n); 212 | } 213 | #endif 214 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/insch.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | insch 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | int insch(chtype ch); 13 | int winsch(WINDOW *win, chtype ch); 14 | int mvinsch(int y, int x, chtype ch); 15 | int mvwinsch(WINDOW *win, int y, int x, chtype ch); 16 | 17 | int insrawch(chtype ch); 18 | int winsrawch(WINDOW *win, chtype ch); 19 | int mvinsrawch(int y, int x, chtype ch); 20 | int mvwinsrawch(WINDOW *win, int y, int x, chtype ch); 21 | 22 | int ins_wch(const cchar_t *wch); 23 | int wins_wch(WINDOW *win, const cchar_t *wch); 24 | int mvins_wch(int y, int x, const cchar_t *wch); 25 | int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch); 26 | 27 | ### Description 28 | 29 | The insch() functions insert a chtype into the window at the current 30 | or specified cursor position. The cursor is NOT advanced. A newline 31 | is equivalent to clrtoeol(); tabs are expanded; other control 32 | characters are converted as with unctrl(). 33 | 34 | The ins_wch() functions are the wide-character equivalents, taking 35 | cchar_t pointers rather than chtypes. 36 | 37 | Video attributes can be combined with a character by ORing them into 38 | the parameter. Text, including attributes, can be copied from one 39 | place to another using inch() and insch(). 40 | 41 | insrawch() etc. are PDCurses-specific wrappers for insch() etc. that 42 | disable the translation of control characters. 43 | 44 | ### Return Value 45 | 46 | All functions return OK on success and ERR on error. 47 | 48 | ### Portability 49 | X/Open ncurses NetBSD 50 | insch Y Y Y 51 | winsch Y Y Y 52 | mvinsch Y Y Y 53 | mvwinsch Y Y Y 54 | ins_wch Y Y Y 55 | wins_wch Y Y Y 56 | mvins_wch Y Y Y 57 | mvwins_wch Y Y Y 58 | insrawch - - - 59 | winsrawch - - - 60 | 61 | **man-end****************************************************************/ 62 | 63 | #include 64 | 65 | int winsch(WINDOW *win, chtype ch) 66 | { 67 | int x, y; 68 | chtype attr; 69 | bool xlat; 70 | 71 | PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", 72 | win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); 73 | 74 | if (!win) 75 | return ERR; 76 | 77 | x = win->_curx; 78 | y = win->_cury; 79 | 80 | if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) 81 | return ERR; 82 | 83 | xlat = !SP->raw_out && !(ch & A_ALTCHARSET); 84 | attr = ch & A_ATTRIBUTES; 85 | ch &= A_CHARTEXT; 86 | 87 | if (xlat && (ch < ' ' || ch == 0x7f)) 88 | { 89 | int x2; 90 | 91 | switch (ch) 92 | { 93 | case '\t': 94 | for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) 95 | { 96 | if (winsch(win, attr | ' ') == ERR) 97 | return ERR; 98 | } 99 | return OK; 100 | 101 | case '\n': 102 | wclrtoeol(win); 103 | break; 104 | 105 | case 0x7f: 106 | if (winsch(win, attr | '?') == ERR) 107 | return ERR; 108 | 109 | return winsch(win, attr | '^'); 110 | 111 | default: 112 | /* handle control chars */ 113 | 114 | if (winsch(win, attr | (ch + '@')) == ERR) 115 | return ERR; 116 | 117 | return winsch(win, attr | '^'); 118 | } 119 | } 120 | else 121 | { 122 | int maxx; 123 | chtype *temp; 124 | 125 | /* If the incoming character doesn't have its own attribute, 126 | then use the current attributes for the window. If it has 127 | attributes but not a color component, OR the attributes to 128 | the current attributes for the window. If it has a color 129 | component, use the attributes solely from the incoming 130 | character. */ 131 | 132 | if (!(attr & A_COLOR)) 133 | attr |= win->_attrs; 134 | 135 | /* wrs (4/10/93): Apply the same sort of logic for the window 136 | background, in that it only takes precedence if other color 137 | attributes are not there and that the background character 138 | will only print if the printing character is blank. */ 139 | 140 | if (!(attr & A_COLOR)) 141 | attr |= win->_bkgd & A_ATTRIBUTES; 142 | else 143 | attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); 144 | 145 | if (ch == ' ') 146 | ch = win->_bkgd & A_CHARTEXT; 147 | 148 | /* Add the attribute back into the character. */ 149 | 150 | ch |= attr; 151 | 152 | maxx = win->_maxx; 153 | temp = &win->_y[y][x]; 154 | 155 | memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype)); 156 | 157 | win->_lastch[y] = maxx - 1; 158 | 159 | if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) 160 | win->_firstch[y] = x; 161 | 162 | *temp = ch; 163 | } 164 | 165 | PDC_sync(win); 166 | 167 | return OK; 168 | } 169 | 170 | int insch(chtype ch) 171 | { 172 | PDC_LOG(("insch() - called\n")); 173 | 174 | return winsch(stdscr, ch); 175 | } 176 | 177 | int mvinsch(int y, int x, chtype ch) 178 | { 179 | PDC_LOG(("mvinsch() - called\n")); 180 | 181 | if (move(y, x) == ERR) 182 | return ERR; 183 | 184 | return winsch(stdscr, ch); 185 | } 186 | 187 | int mvwinsch(WINDOW *win, int y, int x, chtype ch) 188 | { 189 | PDC_LOG(("mvwinsch() - called\n")); 190 | 191 | if (wmove(win, y, x) == ERR) 192 | return ERR; 193 | 194 | return winsch(win, ch); 195 | } 196 | 197 | int winsrawch(WINDOW *win, chtype ch) 198 | { 199 | PDC_LOG(("winsrawch() - called: win=%p ch=%x " 200 | "(char=%c attr=0x%x)\n", win, ch, 201 | ch & A_CHARTEXT, ch & A_ATTRIBUTES)); 202 | 203 | if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) 204 | ch |= A_ALTCHARSET; 205 | 206 | return winsch(win, ch); 207 | } 208 | 209 | int insrawch(chtype ch) 210 | { 211 | PDC_LOG(("insrawch() - called\n")); 212 | 213 | return winsrawch(stdscr, ch); 214 | } 215 | 216 | int mvinsrawch(int y, int x, chtype ch) 217 | { 218 | PDC_LOG(("mvinsrawch() - called\n")); 219 | 220 | if (move(y, x) == ERR) 221 | return ERR; 222 | 223 | return winsrawch(stdscr, ch); 224 | } 225 | 226 | int mvwinsrawch(WINDOW *win, int y, int x, chtype ch) 227 | { 228 | PDC_LOG(("mvwinsrawch() - called\n")); 229 | 230 | if (wmove(win, y, x) == ERR) 231 | return ERR; 232 | 233 | return winsrawch(win, ch); 234 | } 235 | 236 | #ifdef PDC_WIDE 237 | int wins_wch(WINDOW *win, const cchar_t *wch) 238 | { 239 | PDC_LOG(("wins_wch() - called\n")); 240 | 241 | return wch ? winsch(win, *wch) : ERR; 242 | } 243 | 244 | int ins_wch(const cchar_t *wch) 245 | { 246 | PDC_LOG(("ins_wch() - called\n")); 247 | 248 | return wins_wch(stdscr, wch); 249 | } 250 | 251 | int mvins_wch(int y, int x, const cchar_t *wch) 252 | { 253 | PDC_LOG(("mvins_wch() - called\n")); 254 | 255 | if (move(y, x) == ERR) 256 | return ERR; 257 | 258 | return wins_wch(stdscr, wch); 259 | } 260 | 261 | int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) 262 | { 263 | PDC_LOG(("mvwins_wch() - called\n")); 264 | 265 | if (wmove(win, y, x) == ERR) 266 | return ERR; 267 | 268 | return wins_wch(win, wch); 269 | } 270 | #endif 271 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/insstr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | insstr 8 | ------ 9 | 10 | ### Synopsis 11 | 12 | int insstr(const char *str); 13 | int insnstr(const char *str, int n); 14 | int winsstr(WINDOW *win, const char *str); 15 | int winsnstr(WINDOW *win, const char *str, int n); 16 | int mvinsstr(int y, int x, const char *str); 17 | int mvinsnstr(int y, int x, const char *str, int n); 18 | int mvwinsstr(WINDOW *win, int y, int x, const char *str); 19 | int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n); 20 | 21 | int ins_wstr(const wchar_t *wstr); 22 | int ins_nwstr(const wchar_t *wstr, int n); 23 | int wins_wstr(WINDOW *win, const wchar_t *wstr); 24 | int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n); 25 | int mvins_wstr(int y, int x, const wchar_t *wstr); 26 | int mvins_nwstr(int y, int x, const wchar_t *wstr, int n); 27 | int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr); 28 | int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n); 29 | 30 | ### Description 31 | 32 | The insstr() functions insert a character string into a window at the 33 | current cursor position, by repeatedly calling winsch(). When 34 | PDCurses is built with wide-character support enabled, the narrow- 35 | character functions treat the string as a multibyte string in the 36 | current locale, and convert it first. All characters to the right of 37 | the cursor are moved to the right, with the possibility of the 38 | rightmost characters on the line being lost. The cursor position 39 | does not change (after moving to y, x, if specified). The routines 40 | with n as the last argument insert at most n characters; if n is 41 | negative, then the entire string is inserted. 42 | 43 | ### Return Value 44 | 45 | All functions return OK on success and ERR on error. 46 | 47 | ### Portability 48 | X/Open ncurses NetBSD 49 | insstr Y Y Y 50 | winsstr Y Y Y 51 | mvinsstr Y Y Y 52 | mvwinsstr Y Y Y 53 | insnstr Y Y Y 54 | winsnstr Y Y Y 55 | mvinsnstr Y Y Y 56 | mvwinsnstr Y Y Y 57 | ins_wstr Y Y Y 58 | wins_wstr Y Y Y 59 | mvins_wstr Y Y Y 60 | mvwins_wstr Y Y Y 61 | ins_nwstr Y Y Y 62 | wins_nwstr Y Y Y 63 | mvins_nwstr Y Y Y 64 | mvwins_nwstr Y Y Y 65 | 66 | **man-end****************************************************************/ 67 | 68 | #include 69 | 70 | int winsnstr(WINDOW *win, const char *str, int n) 71 | { 72 | #ifdef PDC_WIDE 73 | wchar_t wstr[513], *p; 74 | int i; 75 | #endif 76 | int len; 77 | 78 | PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n)); 79 | 80 | if (!win || !str) 81 | return ERR; 82 | 83 | len = strlen(str); 84 | 85 | if (n < 0 || n > len) 86 | n = len; 87 | 88 | #ifdef PDC_WIDE 89 | if (n > 512) 90 | n = 512; 91 | 92 | p = wstr; 93 | i = 0; 94 | 95 | while (str[i] && i < n) 96 | { 97 | int retval = PDC_mbtowc(p, str + i, n - i); 98 | 99 | if (retval <= 0) 100 | break; 101 | p++; 102 | i += retval; 103 | } 104 | 105 | while (p > wstr) 106 | if (winsch(win, *--p) == ERR) 107 | #else 108 | while (n) 109 | if (winsch(win, (unsigned char)(str[--n])) == ERR) 110 | #endif 111 | return ERR; 112 | 113 | return OK; 114 | } 115 | 116 | int insstr(const char *str) 117 | { 118 | PDC_LOG(("insstr() - called: string=\"%s\"\n", str)); 119 | 120 | return winsnstr(stdscr, str, -1); 121 | } 122 | 123 | int winsstr(WINDOW *win, const char *str) 124 | { 125 | PDC_LOG(("winsstr() - called: string=\"%s\"\n", str)); 126 | 127 | return winsnstr(win, str, -1); 128 | } 129 | 130 | int mvinsstr(int y, int x, const char *str) 131 | { 132 | PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); 133 | 134 | if (move(y, x) == ERR) 135 | return ERR; 136 | 137 | return winsnstr(stdscr, str, -1); 138 | } 139 | 140 | int mvwinsstr(WINDOW *win, int y, int x, const char *str) 141 | { 142 | PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str)); 143 | 144 | if (wmove(win, y, x) == ERR) 145 | return ERR; 146 | 147 | return winsnstr(win, str, -1); 148 | } 149 | 150 | int insnstr(const char *str, int n) 151 | { 152 | PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str, n)); 153 | 154 | return winsnstr(stdscr, str, n); 155 | } 156 | 157 | int mvinsnstr(int y, int x, const char *str, int n) 158 | { 159 | PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n", 160 | y, x, str, n)); 161 | 162 | if (move(y, x) == ERR) 163 | return ERR; 164 | 165 | return winsnstr(stdscr, str, n); 166 | } 167 | 168 | int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) 169 | { 170 | PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n", 171 | y, x, str, n)); 172 | 173 | if (wmove(win, y, x) == ERR) 174 | return ERR; 175 | 176 | return winsnstr(win, str, n); 177 | } 178 | 179 | #ifdef PDC_WIDE 180 | int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) 181 | { 182 | const wchar_t *p; 183 | int len; 184 | 185 | PDC_LOG(("wins_nwstr() - called\n")); 186 | 187 | if (!win || !wstr) 188 | return ERR; 189 | 190 | for (len = 0, p = wstr; *p; p++) 191 | len++; 192 | 193 | if (n < 0 || n > len) 194 | n = len; 195 | 196 | while (n) 197 | if (winsch(win, wstr[--n]) == ERR) 198 | return ERR; 199 | 200 | return OK; 201 | } 202 | 203 | int ins_wstr(const wchar_t *wstr) 204 | { 205 | PDC_LOG(("ins_wstr() - called\n")); 206 | 207 | return wins_nwstr(stdscr, wstr, -1); 208 | } 209 | 210 | int wins_wstr(WINDOW *win, const wchar_t *wstr) 211 | { 212 | PDC_LOG(("wins_wstr() - called\n")); 213 | 214 | return wins_nwstr(win, wstr, -1); 215 | } 216 | 217 | int mvins_wstr(int y, int x, const wchar_t *wstr) 218 | { 219 | PDC_LOG(("mvins_wstr() - called\n")); 220 | 221 | if (move(y, x) == ERR) 222 | return ERR; 223 | 224 | return wins_nwstr(stdscr, wstr, -1); 225 | } 226 | 227 | int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) 228 | { 229 | PDC_LOG(("mvwinsstr() - called\n")); 230 | 231 | if (wmove(win, y, x) == ERR) 232 | return ERR; 233 | 234 | return wins_nwstr(win, wstr, -1); 235 | } 236 | 237 | int ins_nwstr(const wchar_t *wstr, int n) 238 | { 239 | PDC_LOG(("ins_nwstr() - called\n")); 240 | 241 | return wins_nwstr(stdscr, wstr, n); 242 | } 243 | 244 | int mvins_nwstr(int y, int x, const wchar_t *wstr, int n) 245 | { 246 | PDC_LOG(("mvinsnstr() - called\n")); 247 | 248 | if (move(y, x) == ERR) 249 | return ERR; 250 | 251 | return wins_nwstr(stdscr, wstr, n); 252 | } 253 | 254 | int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) 255 | { 256 | PDC_LOG(("mvwinsnstr() - called\n")); 257 | 258 | if (wmove(win, y, x) == ERR) 259 | return ERR; 260 | 261 | return wins_nwstr(win, wstr, n); 262 | } 263 | #endif 264 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/instr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | instr 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | int instr(char *str); 13 | int innstr(char *str, int n); 14 | int winstr(WINDOW *win, char *str); 15 | int winnstr(WINDOW *win, char *str, int n); 16 | int mvinstr(int y, int x, char *str); 17 | int mvinnstr(int y, int x, char *str, int n); 18 | int mvwinstr(WINDOW *win, int y, int x, char *str); 19 | int mvwinnstr(WINDOW *win, int y, int x, char *str, int n); 20 | 21 | int inwstr(wchar_t *wstr); 22 | int innwstr(wchar_t *wstr, int n); 23 | int winwstr(WINDOW *win, wchar_t *wstr); 24 | int winnwstr(WINDOW *win, wchar_t *wstr, int n); 25 | int mvinwstr(int y, int x, wchar_t *wstr); 26 | int mvinnwstr(int y, int x, wchar_t *wstr, int n); 27 | int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr); 28 | int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n); 29 | 30 | ### Description 31 | 32 | These functions take characters (or wide characters) from the current 33 | or specified position in the window, and return them as a string in 34 | str (or wstr). Attributes are ignored. The functions with n as the 35 | last argument return a string at most n characters long. 36 | 37 | ### Return Value 38 | 39 | Upon successful completion, innstr(), mvinnstr(), mvwinnstr() and 40 | winnstr() return the number of characters actually read into the 41 | string; instr(), mvinstr(), mvwinstr() and winstr() return OK. 42 | Otherwise, all these functions return ERR. 43 | 44 | ### Portability 45 | X/Open ncurses NetBSD 46 | instr Y Y Y 47 | winstr Y Y Y 48 | mvinstr Y Y Y 49 | mvwinstr Y Y Y 50 | innstr Y Y Y 51 | winnstr Y Y Y 52 | mvinnstr Y Y Y 53 | mvwinnstr Y Y Y 54 | inwstr Y Y Y 55 | winwstr Y Y Y 56 | mvinwstr Y Y Y 57 | mvwinwstr Y Y Y 58 | innwstr Y Y Y 59 | winnwstr Y Y Y 60 | mvinnwstr Y Y Y 61 | mvwinnwstr Y Y Y 62 | 63 | **man-end****************************************************************/ 64 | 65 | int winnstr(WINDOW *win, char *str, int n) 66 | { 67 | #ifdef PDC_WIDE 68 | wchar_t wstr[513]; 69 | 70 | if (n < 0 || n > 512) 71 | n = 512; 72 | 73 | if (winnwstr(win, wstr, n) == ERR) 74 | return ERR; 75 | 76 | return PDC_wcstombs(str, wstr, n); 77 | #else 78 | chtype *src; 79 | int i; 80 | 81 | PDC_LOG(("winnstr() - called: n %d \n", n)); 82 | 83 | if (!win || !str) 84 | return ERR; 85 | 86 | if (n < 0 || (win->_curx + n) > win->_maxx) 87 | n = win->_maxx - win->_curx; 88 | 89 | src = win->_y[win->_cury] + win->_curx; 90 | 91 | for (i = 0; i < n; i++) 92 | str[i] = src[i] & A_CHARTEXT; 93 | 94 | str[i] = '\0'; 95 | 96 | return i; 97 | #endif 98 | } 99 | 100 | int instr(char *str) 101 | { 102 | PDC_LOG(("instr() - called: string=\"%s\"\n", str)); 103 | 104 | return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK; 105 | } 106 | 107 | int winstr(WINDOW *win, char *str) 108 | { 109 | PDC_LOG(("winstr() - called: \n")); 110 | 111 | return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK; 112 | } 113 | 114 | int mvinstr(int y, int x, char *str) 115 | { 116 | PDC_LOG(("mvinstr() - called: y %d x %d \n", y, x)); 117 | 118 | if (move(y, x) == ERR) 119 | return ERR; 120 | 121 | return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK; 122 | } 123 | 124 | int mvwinstr(WINDOW *win, int y, int x, char *str) 125 | { 126 | PDC_LOG(("mvwinstr() - called: y %d x %d \n", y, x)); 127 | 128 | if (wmove(win, y, x) == ERR) 129 | return ERR; 130 | 131 | return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK; 132 | } 133 | 134 | int innstr(char *str, int n) 135 | { 136 | PDC_LOG(("innstr() - called: n %d \n", n)); 137 | 138 | return winnstr(stdscr, str, n); 139 | } 140 | 141 | int mvinnstr(int y, int x, char *str, int n) 142 | { 143 | PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y, x, n)); 144 | 145 | if (move(y, x) == ERR) 146 | return ERR; 147 | 148 | return winnstr(stdscr, str, n); 149 | } 150 | 151 | int mvwinnstr(WINDOW *win, int y, int x, char *str, int n) 152 | { 153 | PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y, x, n)); 154 | 155 | if (wmove(win, y, x) == ERR) 156 | return ERR; 157 | 158 | return winnstr(win, str, n); 159 | } 160 | 161 | #ifdef PDC_WIDE 162 | int winnwstr(WINDOW *win, wchar_t *wstr, int n) 163 | { 164 | chtype *src; 165 | int i; 166 | 167 | PDC_LOG(("winnstr() - called: n %d \n", n)); 168 | 169 | if (!win || !wstr) 170 | return ERR; 171 | 172 | if (n < 0 || (win->_curx + n) > win->_maxx) 173 | n = win->_maxx - win->_curx; 174 | 175 | src = win->_y[win->_cury] + win->_curx; 176 | 177 | for (i = 0; i < n; i++) 178 | wstr[i] = src[i] & A_CHARTEXT; 179 | 180 | wstr[i] = L'\0'; 181 | 182 | return i; 183 | } 184 | 185 | int inwstr(wchar_t *wstr) 186 | { 187 | PDC_LOG(("inwstr() - called\n")); 188 | 189 | return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK; 190 | } 191 | 192 | int winwstr(WINDOW *win, wchar_t *wstr) 193 | { 194 | PDC_LOG(("winwstr() - called\n")); 195 | 196 | return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK; 197 | } 198 | 199 | int mvinwstr(int y, int x, wchar_t *wstr) 200 | { 201 | PDC_LOG(("mvinwstr() - called\n")); 202 | 203 | if (move(y, x) == ERR) 204 | return ERR; 205 | 206 | return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK; 207 | } 208 | 209 | int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr) 210 | { 211 | PDC_LOG(("mvwinstr() - called\n")); 212 | 213 | if (wmove(win, y, x) == ERR) 214 | return ERR; 215 | 216 | return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK; 217 | } 218 | 219 | int innwstr(wchar_t *wstr, int n) 220 | { 221 | PDC_LOG(("innwstr() - called\n")); 222 | 223 | return winnwstr(stdscr, wstr, n); 224 | } 225 | 226 | int mvinnwstr(int y, int x, wchar_t *wstr, int n) 227 | { 228 | PDC_LOG(("mvinnstr() - called\n")); 229 | 230 | if (move(y, x) == ERR) 231 | return ERR; 232 | 233 | return winnwstr(stdscr, wstr, n); 234 | } 235 | 236 | int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n) 237 | { 238 | PDC_LOG(("mvwinnwstr() - called\n")); 239 | 240 | if (wmove(win, y, x) == ERR) 241 | return ERR; 242 | 243 | return winnwstr(win, wstr, n); 244 | } 245 | #endif 246 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/kernel.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | kernel 8 | ------ 9 | 10 | ### Synopsis 11 | 12 | int def_prog_mode(void); 13 | int def_shell_mode(void); 14 | int reset_prog_mode(void); 15 | int reset_shell_mode(void); 16 | int resetty(void); 17 | int savetty(void); 18 | int ripoffline(int line, int (*init)(WINDOW *, int)); 19 | int curs_set(int visibility); 20 | int napms(int ms); 21 | 22 | int draino(int ms); 23 | int resetterm(void); 24 | int fixterm(void); 25 | int saveterm(void); 26 | 27 | ### Description 28 | 29 | def_prog_mode() and def_shell_mode() save the current terminal modes 30 | as the "program" (in curses) or "shell" (not in curses) state for use 31 | by the reset_prog_mode() and reset_shell_mode() functions. This is 32 | done automatically by initscr(). 33 | 34 | reset_prog_mode() and reset_shell_mode() restore the terminal to 35 | "program" (in curses) or "shell" (not in curses) state. These are 36 | done automatically by endwin() and doupdate() after an endwin(), so 37 | they would normally not be called before these functions. 38 | 39 | savetty() and resetty() save and restore the state of the terminal 40 | modes. savetty() saves the current state in a buffer, and resetty() 41 | restores the state to what it was at the last call to savetty(). 42 | 43 | curs_set() alters the appearance of the cursor. A visibility of 0 44 | makes it disappear; 1 makes it appear "normal" (usually an underline) 45 | and 2 makes it "highly visible" (usually a block). 46 | 47 | ripoffline() reduces the size of stdscr by one line. If the "line" 48 | parameter is positive, the line is removed from the top of the 49 | screen; if negative, from the bottom. Up to 5 lines can be ripped off 50 | stdscr by calling ripoffline() repeatedly. The function argument, 51 | init, is called from within initscr() or newterm(), so ripoffline() 52 | must be called before either of these functions. The init function 53 | receives a pointer to a one-line WINDOW, and the width of the window. 54 | Calling ripoffline() with a NULL init function pointer is an error. 55 | 56 | napms() suspends the program for the specified number of 57 | milliseconds. draino() is an archaic equivalent. Note that since 58 | napms() attempts to give up a time slice and yield control back to 59 | the OS, all times are approximate. (In DOS, the delay is actually 60 | rounded down to 50ms (1/20th sec) intervals, with a minimum of one 61 | interval; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms, etc.) 62 | 0 returns immediately. 63 | 64 | resetterm(), fixterm() and saveterm() are archaic equivalents for 65 | reset_shell_mode(), reset_prog_mode() and def_prog_mode(), 66 | respectively. 67 | 68 | ### Return Value 69 | 70 | All functions return OK on success and ERR on error, except 71 | curs_set(), which returns the previous visibility. 72 | 73 | ### Portability 74 | X/Open ncurses NetBSD 75 | def_prog_mode Y Y Y 76 | def_shell_mode Y Y Y 77 | reset_prog_mode Y Y Y 78 | reset_shell_mode Y Y Y 79 | resetty Y Y Y 80 | savetty Y Y Y 81 | ripoffline Y Y Y 82 | curs_set Y Y Y 83 | napms Y Y Y 84 | fixterm - Y - 85 | resetterm - Y - 86 | saveterm - Y - 87 | draino - - - 88 | 89 | **man-end****************************************************************/ 90 | 91 | #include 92 | 93 | RIPPEDOFFLINE linesripped[5]; 94 | char linesrippedoff = 0; 95 | 96 | static struct cttyset 97 | { 98 | bool been_set; 99 | SCREEN saved; 100 | } ctty[3]; 101 | 102 | enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY }; 103 | 104 | static void _save_mode(int i) 105 | { 106 | ctty[i].been_set = TRUE; 107 | 108 | memcpy(&(ctty[i].saved), SP, sizeof(SCREEN)); 109 | 110 | PDC_save_screen_mode(i); 111 | } 112 | 113 | static int _restore_mode(int i) 114 | { 115 | if (ctty[i].been_set == TRUE) 116 | { 117 | memcpy(SP, &(ctty[i].saved), sizeof(SCREEN)); 118 | 119 | if (ctty[i].saved.raw_out) 120 | raw(); 121 | 122 | PDC_restore_screen_mode(i); 123 | 124 | if ((LINES != ctty[i].saved.lines) || 125 | (COLS != ctty[i].saved.cols)) 126 | resize_term(ctty[i].saved.lines, ctty[i].saved.cols); 127 | 128 | PDC_curs_set(ctty[i].saved.visibility); 129 | 130 | PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol); 131 | } 132 | 133 | return ctty[i].been_set ? OK : ERR; 134 | } 135 | 136 | int def_prog_mode(void) 137 | { 138 | PDC_LOG(("def_prog_mode() - called\n")); 139 | 140 | if (!SP) 141 | return ERR; 142 | 143 | _save_mode(PDC_PR_TTY); 144 | 145 | return OK; 146 | } 147 | 148 | int def_shell_mode(void) 149 | { 150 | PDC_LOG(("def_shell_mode() - called\n")); 151 | 152 | if (!SP) 153 | return ERR; 154 | 155 | _save_mode(PDC_SH_TTY); 156 | 157 | return OK; 158 | } 159 | 160 | int reset_prog_mode(void) 161 | { 162 | PDC_LOG(("reset_prog_mode() - called\n")); 163 | 164 | if (!SP) 165 | return ERR; 166 | 167 | _restore_mode(PDC_PR_TTY); 168 | PDC_reset_prog_mode(); 169 | 170 | return OK; 171 | } 172 | 173 | int reset_shell_mode(void) 174 | { 175 | PDC_LOG(("reset_shell_mode() - called\n")); 176 | 177 | if (!SP) 178 | return ERR; 179 | 180 | _restore_mode(PDC_SH_TTY); 181 | PDC_reset_shell_mode(); 182 | 183 | return OK; 184 | } 185 | 186 | int resetty(void) 187 | { 188 | PDC_LOG(("resetty() - called\n")); 189 | 190 | if (!SP) 191 | return ERR; 192 | 193 | return _restore_mode(PDC_SAVE_TTY); 194 | } 195 | 196 | int savetty(void) 197 | { 198 | PDC_LOG(("savetty() - called\n")); 199 | 200 | if (!SP) 201 | return ERR; 202 | 203 | _save_mode(PDC_SAVE_TTY); 204 | 205 | return OK; 206 | } 207 | 208 | int curs_set(int visibility) 209 | { 210 | int ret_vis; 211 | 212 | PDC_LOG(("curs_set() - called: visibility=%d\n", visibility)); 213 | 214 | if (!SP || visibility < 0 || visibility > 2) 215 | return ERR; 216 | 217 | ret_vis = PDC_curs_set(visibility); 218 | 219 | /* If the cursor is changing from invisible to visible, update 220 | its position */ 221 | 222 | if (visibility && !ret_vis) 223 | PDC_gotoyx(SP->cursrow, SP->curscol); 224 | 225 | return ret_vis; 226 | } 227 | 228 | int napms(int ms) 229 | { 230 | PDC_LOG(("napms() - called: ms=%d\n", ms)); 231 | 232 | if (!SP) 233 | return ERR; 234 | 235 | if (SP->dirty) 236 | { 237 | int curs_state = SP->visibility; 238 | bool leave_state = is_leaveok(curscr); 239 | 240 | SP->dirty = FALSE; 241 | 242 | leaveok(curscr, TRUE); 243 | 244 | wrefresh(curscr); 245 | 246 | leaveok(curscr, leave_state); 247 | curs_set(curs_state); 248 | } 249 | 250 | if (ms) 251 | PDC_napms(ms); 252 | 253 | return OK; 254 | } 255 | 256 | int ripoffline(int line, int (*init)(WINDOW *, int)) 257 | { 258 | PDC_LOG(("ripoffline() - called: line=%d\n", line)); 259 | 260 | if (linesrippedoff < 5 && line && init) 261 | { 262 | linesripped[(int)linesrippedoff].line = line; 263 | linesripped[(int)linesrippedoff++].init = init; 264 | 265 | return OK; 266 | } 267 | 268 | return ERR; 269 | } 270 | 271 | int draino(int ms) 272 | { 273 | PDC_LOG(("draino() - called\n")); 274 | 275 | return napms(ms); 276 | } 277 | 278 | int resetterm(void) 279 | { 280 | PDC_LOG(("resetterm() - called\n")); 281 | 282 | return reset_shell_mode(); 283 | } 284 | 285 | int fixterm(void) 286 | { 287 | PDC_LOG(("fixterm() - called\n")); 288 | 289 | return reset_prog_mode(); 290 | } 291 | 292 | int saveterm(void) 293 | { 294 | PDC_LOG(("saveterm() - called\n")); 295 | 296 | return def_prog_mode(); 297 | } 298 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/keyname.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | keyname 8 | ------- 9 | 10 | ### Synopsis 11 | 12 | char *keyname(int key); 13 | 14 | char *key_name(wchar_t c); 15 | 16 | bool has_key(int key); 17 | 18 | ### Description 19 | 20 | keyname() returns a string corresponding to the argument key. key may 21 | be any key returned by wgetch(). 22 | 23 | key_name() is the wide-character version. It takes a wchar_t 24 | parameter, but still returns a char *. 25 | 26 | has_key() returns TRUE for recognized keys, FALSE otherwise. This 27 | function is an ncurses extension. 28 | 29 | ### Portability 30 | X/Open ncurses NetBSD 31 | keyname Y Y Y 32 | key_name Y Y Y 33 | has_key - Y Y 34 | 35 | **man-end****************************************************************/ 36 | 37 | #include 38 | 39 | static const char *names[] = 40 | { 41 | "KEY_BREAK", "KEY_DOWN", "KEY_UP", "KEY_LEFT", "KEY_RIGHT", 42 | "KEY_HOME", "KEY_BACKSPACE", "KEY_F0", "KEY_F(1)", "KEY_F(2)", 43 | "KEY_F(3)", "KEY_F(4)", "KEY_F(5)", "KEY_F(6)", "KEY_F(7)", 44 | "KEY_F(8)", "KEY_F(9)", "KEY_F(10)", "KEY_F(11)", "KEY_F(12)", 45 | "KEY_F(13)", "KEY_F(14)", "KEY_F(15)", "KEY_F(16)", "KEY_F(17)", 46 | "KEY_F(18)", "KEY_F(19)", "KEY_F(20)", "KEY_F(21)", "KEY_F(22)", 47 | "KEY_F(23)", "KEY_F(24)", "KEY_F(25)", "KEY_F(26)", "KEY_F(27)", 48 | "KEY_F(28)", "KEY_F(29)", "KEY_F(30)", "KEY_F(31)", "KEY_F(32)", 49 | "KEY_F(33)", "KEY_F(34)", "KEY_F(35)", "KEY_F(36)", "KEY_F(37)", 50 | "KEY_F(38)", "KEY_F(39)", "KEY_F(40)", "KEY_F(41)", "KEY_F(42)", 51 | "KEY_F(43)", "KEY_F(44)", "KEY_F(45)", "KEY_F(46)", "KEY_F(47)", 52 | "KEY_F(48)", "KEY_F(49)", "KEY_F(50)", "KEY_F(51)", "KEY_F(52)", 53 | "KEY_F(53)", "KEY_F(54)", "KEY_F(55)", "KEY_F(56)", "KEY_F(57)", 54 | "KEY_F(58)", "KEY_F(59)", "KEY_F(60)", "KEY_F(61)", "KEY_F(62)", 55 | "KEY_F(63)", "KEY_DL", "KEY_IL", "KEY_DC", "KEY_IC", "KEY_EIC", 56 | "KEY_CLEAR", "KEY_EOS", "KEY_EOL", "KEY_SF", "KEY_SR", "KEY_NPAGE", 57 | "KEY_PPAGE", "KEY_STAB", "KEY_CTAB", "KEY_CATAB", "KEY_ENTER", 58 | "KEY_SRESET", "KEY_RESET", "KEY_PRINT", "KEY_LL", "KEY_ABORT", 59 | "KEY_SHELP", "KEY_LHELP", "KEY_BTAB", "KEY_BEG", "KEY_CANCEL", 60 | "KEY_CLOSE", "KEY_COMMAND", "KEY_COPY", "KEY_CREATE", "KEY_END", 61 | "KEY_EXIT", "KEY_FIND", "KEY_HELP", "KEY_MARK", "KEY_MESSAGE", 62 | "KEY_MOVE", "KEY_NEXT", "KEY_OPEN", "KEY_OPTIONS", "KEY_PREVIOUS", 63 | "KEY_REDO", "KEY_REFERENCE", "KEY_REFRESH", "KEY_REPLACE", 64 | "KEY_RESTART", "KEY_RESUME", "KEY_SAVE", "KEY_SBEG", "KEY_SCANCEL", 65 | "KEY_SCOMMAND", "KEY_SCOPY", "KEY_SCREATE", "KEY_SDC", "KEY_SDL", 66 | "KEY_SELECT", "KEY_SEND", "KEY_SEOL", "KEY_SEXIT", "KEY_SFIND", 67 | "KEY_SHOME", "KEY_SIC", "UNKNOWN KEY", "KEY_SLEFT", "KEY_SMESSAGE", 68 | "KEY_SMOVE", "KEY_SNEXT", "KEY_SOPTIONS", "KEY_SPREVIOUS", 69 | "KEY_SPRINT", "KEY_SREDO", "KEY_SREPLACE", "KEY_SRIGHT", 70 | "KEY_SRSUME", "KEY_SSAVE", "KEY_SSUSPEND", "KEY_SUNDO", 71 | "KEY_SUSPEND", "KEY_UNDO", "ALT_0", "ALT_1", "ALT_2", "ALT_3", 72 | "ALT_4", "ALT_5", "ALT_6", "ALT_7", "ALT_8", "ALT_9", "ALT_A", 73 | "ALT_B", "ALT_C", "ALT_D", "ALT_E", "ALT_F", "ALT_G", "ALT_H", 74 | "ALT_I", "ALT_J", "ALT_K", "ALT_L", "ALT_M", "ALT_N", "ALT_O", 75 | "ALT_P", "ALT_Q", "ALT_R", "ALT_S", "ALT_T", "ALT_U", "ALT_V", 76 | "ALT_W", "ALT_X", "ALT_Y", "ALT_Z", "CTL_LEFT", "CTL_RIGHT", 77 | "CTL_PGUP", "CTL_PGDN", "CTL_HOME", "CTL_END", "KEY_A1", "KEY_A2", 78 | "KEY_A3", "KEY_B1", "KEY_B2", "KEY_B3", "KEY_C1", "KEY_C2", 79 | "KEY_C3", "PADSLASH", "PADENTER", "CTL_PADENTER", "ALT_PADENTER", 80 | "PADSTOP", "PADSTAR", "PADMINUS", "PADPLUS", "CTL_PADSTOP", 81 | "CTL_PADCENTER", "CTL_PADPLUS", "CTL_PADMINUS", "CTL_PADSLASH", 82 | "CTL_PADSTAR", "ALT_PADPLUS", "ALT_PADMINUS", "ALT_PADSLASH", 83 | "ALT_PADSTAR", "ALT_PADSTOP", "CTL_INS", "ALT_DEL", "ALT_INS", 84 | "CTL_UP", "CTL_DOWN", "CTL_TAB", "ALT_TAB", "ALT_MINUS", 85 | "ALT_EQUAL", "ALT_HOME", "ALT_PGUP", "ALT_PGDN", "ALT_END", 86 | "ALT_UP", "ALT_DOWN", "ALT_RIGHT", "ALT_LEFT", "ALT_ENTER", 87 | "ALT_ESC", "ALT_BQUOTE", "ALT_LBRACKET", "ALT_RBRACKET", 88 | "ALT_SEMICOLON", "ALT_FQUOTE", "ALT_COMMA", "ALT_STOP", 89 | "ALT_FSLASH", "ALT_BKSP", "CTL_BKSP", "PAD0", "CTL_PAD0", 90 | "CTL_PAD1", "CTL_PAD2", "CTL_PAD3", "CTL_PAD4", "CTL_PAD5", 91 | "CTL_PAD6", "CTL_PAD7","CTL_PAD8", "CTL_PAD9", "ALT_PAD0", 92 | "ALT_PAD1", "ALT_PAD2", "ALT_PAD3", "ALT_PAD4", "ALT_PAD5", 93 | "ALT_PAD6", "ALT_PAD7", "ALT_PAD8", "ALT_PAD9", "CTL_DEL", 94 | "ALT_BSLASH", "CTL_ENTER", "SHF_PADENTER", "SHF_PADSLASH", 95 | "SHF_PADSTAR", "SHF_PADPLUS", "SHF_PADMINUS", "SHF_UP", "SHF_DOWN", 96 | "SHF_IC", "SHF_DC", "KEY_MOUSE", "KEY_SHIFT_L", "KEY_SHIFT_R", 97 | "KEY_CONTROL_L", "KEY_CONTROL_R", "KEY_ALT_L", "KEY_ALT_R", 98 | "KEY_RESIZE", "KEY_SUP", "KEY_SDOWN" 99 | }; 100 | 101 | char *keyname(int key) 102 | { 103 | static char _keyname[14]; 104 | 105 | /* Key names must be in exactly the same order as in curses.h */ 106 | 107 | PDC_LOG(("keyname() - called: key %d\n", key)); 108 | 109 | strcpy(_keyname, ((key >= 0) && (key < 0x80)) ? unctrl((chtype)key) : 110 | has_key(key) ? names[key - KEY_MIN] : "UNKNOWN KEY"); 111 | 112 | return _keyname; 113 | } 114 | 115 | bool has_key(int key) 116 | { 117 | PDC_LOG(("has_key() - called: key %d\n", key)); 118 | 119 | return (key >= KEY_MIN && key <= KEY_MAX); 120 | } 121 | 122 | #ifdef PDC_WIDE 123 | char *key_name(wchar_t c) 124 | { 125 | PDC_LOG(("key_name() - called\n")); 126 | 127 | return keyname((int)c); 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/move.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | move 8 | ---- 9 | 10 | ### Synopsis 11 | 12 | int move(int y, int x); 13 | int mvcur(int oldrow, int oldcol, int newrow, int newcol); 14 | int wmove(WINDOW *win, int y, int x); 15 | 16 | ### Description 17 | 18 | move() and wmove() move the cursor associated with the window to the 19 | given location. This does not move the physical cursor of the 20 | terminal until refresh() is called. The position specified is 21 | relative to the upper left corner of the window, which is (0,0). 22 | 23 | mvcur() moves the physical cursor without updating any window cursor 24 | positions. 25 | 26 | ### Return Value 27 | 28 | All functions return OK on success and ERR on error. 29 | 30 | ### Portability 31 | X/Open ncurses NetBSD 32 | move Y Y Y 33 | mvcur Y Y Y 34 | wmove Y Y Y 35 | 36 | **man-end****************************************************************/ 37 | 38 | int move(int y, int x) 39 | { 40 | PDC_LOG(("move() - called: y=%d x=%d\n", y, x)); 41 | 42 | if (!stdscr || x < 0 || y < 0 || x >= stdscr->_maxx || y >= stdscr->_maxy) 43 | return ERR; 44 | 45 | stdscr->_curx = x; 46 | stdscr->_cury = y; 47 | 48 | return OK; 49 | } 50 | 51 | int mvcur(int oldrow, int oldcol, int newrow, int newcol) 52 | { 53 | PDC_LOG(("mvcur() - called: oldrow %d oldcol %d newrow %d newcol %d\n", 54 | oldrow, oldcol, newrow, newcol)); 55 | 56 | if (!SP || newrow < 0 || newrow >= LINES || newcol < 0 || newcol >= COLS) 57 | return ERR; 58 | 59 | PDC_gotoyx(newrow, newcol); 60 | SP->cursrow = newrow; 61 | SP->curscol = newcol; 62 | 63 | return OK; 64 | } 65 | 66 | int wmove(WINDOW *win, int y, int x) 67 | { 68 | PDC_LOG(("wmove() - called: y=%d x=%d\n", y, x)); 69 | 70 | if (!win || x < 0 || y < 0 || x >= win->_maxx || y >= win->_maxy) 71 | return ERR; 72 | 73 | win->_curx = x; 74 | win->_cury = y; 75 | 76 | return OK; 77 | } 78 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/outopts.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | outopts 8 | ------- 9 | 10 | ### Synopsis 11 | 12 | int clearok(WINDOW *win, bool bf); 13 | int idlok(WINDOW *win, bool bf); 14 | void idcok(WINDOW *win, bool bf); 15 | void immedok(WINDOW *win, bool bf); 16 | int leaveok(WINDOW *win, bool bf); 17 | int setscrreg(int top, int bot); 18 | int wsetscrreg(WINDOW *win, int top, int bot); 19 | int scrollok(WINDOW *win, bool bf); 20 | 21 | int raw_output(bool bf); 22 | 23 | bool is_leaveok(const WINDOW *win); 24 | 25 | ### Description 26 | 27 | With clearok(), if bf is TRUE, the next call to wrefresh() with this 28 | window will clear the screen completely and redraw the entire screen. 29 | 30 | immedok(), called with a second argument of TRUE, causes an automatic 31 | wrefresh() every time a change is made to the specified window. 32 | 33 | Normally, the hardware cursor is left at the location of the window 34 | being refreshed. leaveok() allows the cursor to be left wherever the 35 | update happens to leave it. It's useful for applications where the 36 | cursor is not used, since it reduces the need for cursor motions. If 37 | possible, the cursor is made invisible when this option is enabled. 38 | 39 | wsetscrreg() sets a scrolling region in a window; "top" and "bot" are 40 | the line numbers for the top and bottom margins. If this option and 41 | scrollok() are enabled, any attempt to move off the bottom margin 42 | will cause all lines in the scrolling region to scroll up one line. 43 | setscrreg() is the stdscr version. 44 | 45 | idlok() and idcok() do nothing in PDCurses, but are provided for 46 | compatibility with other curses implementations. 47 | 48 | raw_output() enables the output of raw characters using the standard 49 | *add* and *ins* curses functions (that is, it disables translation of 50 | control characters). 51 | 52 | is_leaveok() reports whether the specified window is in leaveok mode. 53 | 54 | ### Return Value 55 | 56 | All functions except is_leaveok() return OK on success and ERR on 57 | error. 58 | 59 | ### Portability 60 | X/Open ncurses NetBSD 61 | clearok Y Y Y 62 | idlok Y Y Y 63 | idcok Y Y Y 64 | immedok Y Y Y 65 | leaveok Y Y Y 66 | setscrreg Y Y Y 67 | wsetscrreg Y Y Y 68 | scrollok Y Y Y 69 | is_leaveok - Y Y 70 | raw_output - - - 71 | 72 | **man-end****************************************************************/ 73 | 74 | int clearok(WINDOW *win, bool bf) 75 | { 76 | PDC_LOG(("clearok() - called\n")); 77 | 78 | if (!win) 79 | return ERR; 80 | 81 | win->_clear = bf; 82 | 83 | return OK; 84 | } 85 | 86 | int idlok(WINDOW *win, bool bf) 87 | { 88 | PDC_LOG(("idlok() - called\n")); 89 | 90 | return OK; 91 | } 92 | 93 | void idcok(WINDOW *win, bool bf) 94 | { 95 | PDC_LOG(("idcok() - called\n")); 96 | } 97 | 98 | void immedok(WINDOW *win, bool bf) 99 | { 100 | PDC_LOG(("immedok() - called\n")); 101 | 102 | if (win) 103 | win->_immed = bf; 104 | } 105 | 106 | int leaveok(WINDOW *win, bool bf) 107 | { 108 | PDC_LOG(("leaveok() - called\n")); 109 | 110 | if (!win) 111 | return ERR; 112 | 113 | win->_leaveit = bf; 114 | 115 | curs_set(!bf); 116 | 117 | return OK; 118 | } 119 | 120 | int setscrreg(int top, int bottom) 121 | { 122 | PDC_LOG(("setscrreg() - called: top %d bottom %d\n", top, bottom)); 123 | 124 | return wsetscrreg(stdscr, top, bottom); 125 | } 126 | 127 | int wsetscrreg(WINDOW *win, int top, int bottom) 128 | { 129 | PDC_LOG(("wsetscrreg() - called: top %d bottom %d\n", top, bottom)); 130 | 131 | if (win && 0 <= top && top <= win->_cury && 132 | win->_cury <= bottom && bottom < win->_maxy) 133 | { 134 | win->_tmarg = top; 135 | win->_bmarg = bottom; 136 | 137 | return OK; 138 | } 139 | else 140 | return ERR; 141 | } 142 | 143 | int scrollok(WINDOW *win, bool bf) 144 | { 145 | PDC_LOG(("scrollok() - called\n")); 146 | 147 | if (!win) 148 | return ERR; 149 | 150 | win->_scroll = bf; 151 | 152 | return OK; 153 | } 154 | 155 | int raw_output(bool bf) 156 | { 157 | PDC_LOG(("raw_output() - called\n")); 158 | 159 | if (!SP) 160 | return ERR; 161 | 162 | SP->raw_out = bf; 163 | 164 | return OK; 165 | } 166 | 167 | bool is_leaveok(const WINDOW *win) 168 | { 169 | PDC_LOG(("is_leaveok() - called\n")); 170 | 171 | if (!win) 172 | return FALSE; 173 | 174 | return win->_leaveit; 175 | } 176 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/overlay.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | overlay 8 | ------- 9 | 10 | ### Synopsis 11 | 12 | int overlay(const WINDOW *src_w, WINDOW *dst_w) 13 | int overwrite(const WINDOW *src_w, WINDOW *dst_w) 14 | int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, 15 | int src_tc, int dst_tr, int dst_tc, int dst_br, 16 | int dst_bc, int _overlay) 17 | 18 | ### Description 19 | 20 | overlay() and overwrite() copy all the text from src_w into dst_w. 21 | The windows need not be the same size. Those characters in the source 22 | window that intersect with the destination window are copied, so that 23 | the characters appear in the same physical position on the screen. 24 | The difference between the two functions is that overlay() is non- 25 | destructive (blanks are not copied) while overwrite() is destructive 26 | (blanks are copied). 27 | 28 | copywin() is similar, but doesn't require that the two windows 29 | overlap. The arguments src_tc and src_tr specify the top left corner 30 | of the region to be copied. dst_tc, dst_tr, dst_br, and dst_bc 31 | specify the region within the destination window to copy to. The 32 | argument "overlay", if TRUE, indicates that the copy is done non- 33 | destructively (as in overlay()); blanks in the source window are not 34 | copied to the destination window. When overlay is FALSE, blanks are 35 | copied. 36 | 37 | ### Return Value 38 | 39 | All functions return OK on success and ERR on error. 40 | 41 | ### Portability 42 | X/Open ncurses NetBSD 43 | overlay Y Y Y 44 | overwrite Y Y Y 45 | copywin Y Y Y 46 | 47 | **man-end****************************************************************/ 48 | 49 | /* Thanks to Andreas Otte for the 50 | corrected overlay()/overwrite() behavior. */ 51 | 52 | static int _copy_win(const WINDOW *src_w, WINDOW *dst_w, int src_tr, 53 | int src_tc, int src_br, int src_bc, int dst_tr, 54 | int dst_tc, bool _overlay) 55 | { 56 | int col, line, y1, fc, *minchng, *maxchng; 57 | chtype *w1ptr, *w2ptr; 58 | 59 | int lc = 0; 60 | int xdiff = src_bc - src_tc; 61 | int ydiff = src_br - src_tr; 62 | 63 | if (!src_w || !dst_w) 64 | return ERR; 65 | 66 | minchng = dst_w->_firstch; 67 | maxchng = dst_w->_lastch; 68 | 69 | for (y1 = 0; y1 < dst_tr; y1++) 70 | { 71 | minchng++; 72 | maxchng++; 73 | } 74 | 75 | for (line = 0; line < ydiff; line++) 76 | { 77 | w1ptr = src_w->_y[line + src_tr] + src_tc; 78 | w2ptr = dst_w->_y[line + dst_tr] + dst_tc; 79 | 80 | fc = _NO_CHANGE; 81 | 82 | for (col = 0; col < xdiff; col++) 83 | { 84 | if ((*w1ptr) != (*w2ptr) && 85 | !((*w1ptr & A_CHARTEXT) == ' ' && _overlay)) 86 | { 87 | *w2ptr = *w1ptr; 88 | 89 | if (fc == _NO_CHANGE) 90 | fc = col + dst_tc; 91 | 92 | lc = col + dst_tc; 93 | } 94 | 95 | w1ptr++; 96 | w2ptr++; 97 | } 98 | 99 | if (*minchng == _NO_CHANGE) 100 | { 101 | *minchng = fc; 102 | *maxchng = lc; 103 | } 104 | else if (fc != _NO_CHANGE) 105 | { 106 | if (fc < *minchng) 107 | *minchng = fc; 108 | if (lc > *maxchng) 109 | *maxchng = lc; 110 | } 111 | 112 | minchng++; 113 | maxchng++; 114 | } 115 | 116 | return OK; 117 | } 118 | 119 | int _copy_overlap(const WINDOW *src_w, WINDOW *dst_w, bool overlay) 120 | { 121 | int first_line, first_col, last_line, last_col; 122 | int src_start_x, src_start_y, dst_start_x, dst_start_y; 123 | int xdiff, ydiff; 124 | 125 | if (!src_w || !dst_w) 126 | return ERR; 127 | 128 | first_col = max(dst_w->_begx, src_w->_begx); 129 | first_line = max(dst_w->_begy, src_w->_begy); 130 | 131 | last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx); 132 | last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy); 133 | 134 | /* determine the overlapping region of the two windows in real 135 | coordinates */ 136 | 137 | /* if no overlapping region, do nothing */ 138 | 139 | if ((last_col < first_col) || (last_line < first_line)) 140 | return OK; 141 | 142 | /* size of overlapping region */ 143 | 144 | xdiff = last_col - first_col; 145 | ydiff = last_line - first_line; 146 | 147 | if (src_w->_begx <= dst_w->_begx) 148 | { 149 | src_start_x = dst_w->_begx - src_w->_begx; 150 | dst_start_x = 0; 151 | } 152 | else 153 | { 154 | dst_start_x = src_w->_begx - dst_w->_begx; 155 | src_start_x = 0; 156 | } 157 | 158 | if (src_w->_begy <= dst_w->_begy) 159 | { 160 | src_start_y = dst_w->_begy - src_w->_begy; 161 | dst_start_y = 0; 162 | } 163 | else 164 | { 165 | dst_start_y = src_w->_begy - dst_w->_begy; 166 | src_start_y = 0; 167 | } 168 | 169 | return _copy_win(src_w, dst_w, src_start_y, src_start_x, 170 | src_start_y + ydiff, src_start_x + xdiff, 171 | dst_start_y, dst_start_x, overlay); 172 | } 173 | 174 | int overlay(const WINDOW *src_w, WINDOW *dst_w) 175 | { 176 | PDC_LOG(("overlay() - called\n")); 177 | 178 | return _copy_overlap(src_w, dst_w, TRUE); 179 | } 180 | 181 | int overwrite(const WINDOW *src_w, WINDOW *dst_w) 182 | { 183 | PDC_LOG(("overwrite() - called\n")); 184 | 185 | return _copy_overlap(src_w, dst_w, FALSE); 186 | } 187 | 188 | int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, int src_tc, 189 | int dst_tr, int dst_tc, int dst_br, int dst_bc, int _overlay) 190 | { 191 | int src_end_x, src_end_y; 192 | int src_rows, src_cols, dst_rows, dst_cols; 193 | int min_rows, min_cols; 194 | 195 | PDC_LOG(("copywin() - called\n")); 196 | 197 | if (!src_w || !dst_w || dst_w == curscr || dst_br >= dst_w->_maxy 198 | || dst_bc >= dst_w->_maxx || dst_tr < 0 || dst_tc < 0) 199 | return ERR; 200 | 201 | src_rows = src_w->_maxy - src_tr; 202 | src_cols = src_w->_maxx - src_tc; 203 | dst_rows = dst_br - dst_tr + 1; 204 | dst_cols = dst_bc - dst_tc + 1; 205 | 206 | min_rows = min(src_rows, dst_rows); 207 | min_cols = min(src_cols, dst_cols); 208 | 209 | src_end_y = src_tr + min_rows; 210 | src_end_x = src_tc + min_cols; 211 | 212 | return _copy_win(src_w, dst_w, src_tr, src_tc, src_end_y, src_end_x, 213 | dst_tr, dst_tc, _overlay); 214 | } 215 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcclip.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include "pdcwin.h" 4 | 5 | #include 6 | 7 | /*man-start************************************************************** 8 | 9 | clipboard 10 | --------- 11 | 12 | ### Synopsis 13 | 14 | int PDC_getclipboard(char **contents, long *length); 15 | int PDC_setclipboard(const char *contents, long length); 16 | int PDC_freeclipboard(char *contents); 17 | int PDC_clearclipboard(void); 18 | 19 | ### Description 20 | 21 | PDC_getclipboard() gets the textual contents of the system's 22 | clipboard. This function returns the contents of the clipboard in the 23 | contents argument. It is the responsibility of the caller to free the 24 | memory returned, via PDC_freeclipboard(). The length of the clipboard 25 | contents is returned in the length argument. 26 | 27 | PDC_setclipboard copies the supplied text into the system's 28 | clipboard, emptying the clipboard prior to the copy. 29 | 30 | PDC_clearclipboard() clears the internal clipboard. 31 | 32 | ### Return Values 33 | 34 | indicator of success/failure of call. 35 | PDC_CLIP_SUCCESS the call was successful 36 | PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for 37 | the clipboard contents 38 | PDC_CLIP_EMPTY the clipboard contains no text 39 | PDC_CLIP_ACCESS_ERROR no clipboard support 40 | 41 | ### Portability 42 | X/Open ncurses NetBSD 43 | PDC_getclipboard - - - 44 | PDC_setclipboard - - - 45 | PDC_freeclipboard - - - 46 | PDC_clearclipboard - - - 47 | 48 | **man-end****************************************************************/ 49 | 50 | #ifdef PDC_WIDE 51 | # define PDC_TEXT CF_UNICODETEXT 52 | #else 53 | # define PDC_TEXT CF_OEMTEXT 54 | #endif 55 | 56 | int PDC_getclipboard(char **contents, long *length) 57 | { 58 | HANDLE handle; 59 | long len; 60 | 61 | PDC_LOG(("PDC_getclipboard() - called\n")); 62 | 63 | if (!OpenClipboard(NULL)) 64 | return PDC_CLIP_ACCESS_ERROR; 65 | 66 | if ((handle = GetClipboardData(PDC_TEXT)) == NULL) 67 | { 68 | CloseClipboard(); 69 | return PDC_CLIP_EMPTY; 70 | } 71 | 72 | #ifdef PDC_WIDE 73 | len = wcslen((wchar_t *)handle) * 3; 74 | #else 75 | len = strlen((char *)handle); 76 | #endif 77 | *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1); 78 | 79 | if (!*contents) 80 | { 81 | CloseClipboard(); 82 | return PDC_CLIP_MEMORY_ERROR; 83 | } 84 | 85 | #ifdef PDC_WIDE 86 | len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len); 87 | #else 88 | strcpy((char *)*contents, (char *)handle); 89 | #endif 90 | *length = len; 91 | CloseClipboard(); 92 | 93 | return PDC_CLIP_SUCCESS; 94 | } 95 | 96 | int PDC_setclipboard(const char *contents, long length) 97 | { 98 | HGLOBAL ptr1; 99 | LPTSTR ptr2; 100 | 101 | PDC_LOG(("PDC_setclipboard() - called\n")); 102 | 103 | if (!OpenClipboard(NULL)) 104 | return PDC_CLIP_ACCESS_ERROR; 105 | 106 | ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, 107 | (length + 1) * sizeof(TCHAR)); 108 | 109 | if (!ptr1) 110 | return PDC_CLIP_MEMORY_ERROR; 111 | 112 | ptr2 = GlobalLock(ptr1); 113 | 114 | #ifdef PDC_WIDE 115 | PDC_mbstowcs((wchar_t *)ptr2, contents, length); 116 | #else 117 | memcpy((char *)ptr2, contents, length + 1); 118 | #endif 119 | GlobalUnlock(ptr1); 120 | EmptyClipboard(); 121 | 122 | if (!SetClipboardData(PDC_TEXT, ptr1)) 123 | { 124 | GlobalFree(ptr1); 125 | return PDC_CLIP_ACCESS_ERROR; 126 | } 127 | 128 | CloseClipboard(); 129 | GlobalFree(ptr1); 130 | 131 | return PDC_CLIP_SUCCESS; 132 | } 133 | 134 | int PDC_freeclipboard(char *contents) 135 | { 136 | PDC_LOG(("PDC_freeclipboard() - called\n")); 137 | 138 | GlobalFree(contents); 139 | return PDC_CLIP_SUCCESS; 140 | } 141 | 142 | int PDC_clearclipboard(void) 143 | { 144 | PDC_LOG(("PDC_clearclipboard() - called\n")); 145 | 146 | EmptyClipboard(); 147 | 148 | return PDC_CLIP_SUCCESS; 149 | } 150 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcdisp.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include "pdcwin.h" 4 | 5 | #include 6 | #include 7 | 8 | #ifdef PDC_WIDE 9 | # include "../common/acsuni.h" 10 | #else 11 | # include "../common/acs437.h" 12 | #endif 13 | 14 | DWORD pdc_last_blink; 15 | static bool blinked_off = FALSE; 16 | static bool in_italic = FALSE; 17 | 18 | /* position hardware cursor at (y, x) */ 19 | 20 | void PDC_gotoyx(int row, int col) 21 | { 22 | COORD coord; 23 | 24 | PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n", 25 | row, col, SP->cursrow, SP->curscol)); 26 | 27 | coord.X = col; 28 | coord.Y = row; 29 | 30 | SetConsoleCursorPosition(pdc_con_out, coord); 31 | } 32 | 33 | void _set_ansi_color(short f, short b, attr_t attr) 34 | { 35 | char esc[64], *p; 36 | short tmp, underline; 37 | bool italic; 38 | 39 | if (f < 16 && !pdc_color[f].mapped) 40 | f = pdc_curstoansi[f]; 41 | 42 | if (b < 16 && !pdc_color[b].mapped) 43 | b = pdc_curstoansi[b]; 44 | 45 | if (attr & A_REVERSE) 46 | { 47 | tmp = f; 48 | f = b; 49 | b = tmp; 50 | } 51 | attr &= SP->termattrs; 52 | italic = !!(attr & A_ITALIC); 53 | underline = !!(attr & A_UNDERLINE); 54 | 55 | p = esc + sprintf(esc, "\x1b["); 56 | 57 | if (f != pdc_oldf) 58 | { 59 | if (f < 8 && !pdc_color[f].mapped) 60 | p += sprintf(p, "%d", f + 30); 61 | else if (f < 16 && !pdc_color[f].mapped) 62 | p += sprintf(p, "%d", f + 82); 63 | else if (f < 256 && !pdc_color[f].mapped) 64 | p += sprintf(p, "38;5;%d", f); 65 | else 66 | { 67 | short red = DIVROUND(pdc_color[f].r * 255, 1000); 68 | short green = DIVROUND(pdc_color[f].g * 255, 1000); 69 | short blue = DIVROUND(pdc_color[f].b * 255, 1000); 70 | 71 | p += sprintf(p, "38;2;%d;%d;%d", red, green, blue); 72 | } 73 | 74 | pdc_oldf = f; 75 | } 76 | 77 | if (b != pdc_oldb) 78 | { 79 | if (strlen(esc) > 2) 80 | p += sprintf(p, ";"); 81 | 82 | if (b < 8 && !pdc_color[b].mapped) 83 | p += sprintf(p, "%d", b + 40); 84 | else if (b < 16 && !pdc_color[b].mapped) 85 | p += sprintf(p, "%d", b + 92); 86 | else if (b < 256 && !pdc_color[b].mapped) 87 | p += sprintf(p, "48;5;%d", b); 88 | else 89 | { 90 | short red = DIVROUND(pdc_color[b].r * 255, 1000); 91 | short green = DIVROUND(pdc_color[b].g * 255, 1000); 92 | short blue = DIVROUND(pdc_color[b].b * 255, 1000); 93 | 94 | p += sprintf(p, "48;2;%d;%d;%d", red, green, blue); 95 | } 96 | 97 | pdc_oldb = b; 98 | } 99 | 100 | if (italic != in_italic) 101 | { 102 | if (strlen(esc) > 2) 103 | p += sprintf(p, ";"); 104 | 105 | if (italic) 106 | p += sprintf(p, "3"); 107 | else 108 | p += sprintf(p, "23"); 109 | 110 | in_italic = italic; 111 | } 112 | 113 | if (underline != pdc_oldu) 114 | { 115 | if (strlen(esc) > 2) 116 | p += sprintf(p, ";"); 117 | 118 | if (underline) 119 | p += sprintf(p, "4"); 120 | else 121 | p += sprintf(p, "24"); 122 | 123 | pdc_oldu = underline; 124 | } 125 | 126 | if (strlen(esc) > 2) 127 | { 128 | sprintf(p, "m"); 129 | if (!pdc_conemu) 130 | SetConsoleMode(pdc_con_out, 0x0015); 131 | 132 | WriteConsoleA(pdc_con_out, esc, strlen(esc), NULL, NULL); 133 | 134 | if (!pdc_conemu) 135 | SetConsoleMode(pdc_con_out, 0x0010); 136 | } 137 | } 138 | 139 | void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp) 140 | { 141 | int j; 142 | short fore, back; 143 | bool blink, ansi; 144 | 145 | if (pdc_ansi && (lineno == (SP->lines - 1)) && ((x + len) == SP->cols)) 146 | { 147 | len--; 148 | if (len) 149 | _new_packet(attr, lineno, x, len, srcp); 150 | pdc_ansi = FALSE; 151 | _new_packet(attr, lineno, x + len, 1, srcp + len); 152 | pdc_ansi = TRUE; 153 | return; 154 | } 155 | 156 | pair_content(PAIR_NUMBER(attr), &fore, &back); 157 | ansi = pdc_ansi || (fore >= 16 || back >= 16); 158 | blink = (SP->termattrs & A_BLINK) && (attr & A_BLINK); 159 | 160 | if (blink) 161 | { 162 | attr &= ~A_BLINK; 163 | if (blinked_off) 164 | attr &= ~(A_UNDERLINE | A_RIGHT | A_LEFT); 165 | } 166 | 167 | if (attr & A_BOLD) 168 | fore |= 8; 169 | if (attr & A_BLINK) 170 | back |= 8; 171 | 172 | if (ansi) 173 | { 174 | #ifdef PDC_WIDE 175 | WCHAR buffer[512]; 176 | #else 177 | char buffer[512]; 178 | #endif 179 | for (j = 0; j < len; j++) 180 | { 181 | chtype ch = srcp[j]; 182 | 183 | if (ch & A_ALTCHARSET && !(ch & 0xff80)) 184 | ch = acs_map[ch & 0x7f]; 185 | 186 | if (blink && blinked_off) 187 | ch = ' '; 188 | 189 | buffer[j] = ch & A_CHARTEXT; 190 | } 191 | 192 | PDC_gotoyx(lineno, x); 193 | _set_ansi_color(fore, back, attr); 194 | #ifdef PDC_WIDE 195 | WriteConsoleW(pdc_con_out, buffer, len, NULL, NULL); 196 | #else 197 | WriteConsoleA(pdc_con_out, buffer, len, NULL, NULL); 198 | #endif 199 | } 200 | else 201 | { 202 | CHAR_INFO buffer[512]; 203 | COORD bufSize, bufPos; 204 | SMALL_RECT sr; 205 | WORD mapped_attr; 206 | 207 | fore = pdc_curstoreal[fore]; 208 | back = pdc_curstoreal[back]; 209 | 210 | if (attr & A_REVERSE) 211 | mapped_attr = back | (fore << 4); 212 | else 213 | mapped_attr = fore | (back << 4); 214 | 215 | if (attr & A_UNDERLINE) 216 | mapped_attr |= 0x8000; /* COMMON_LVB_UNDERSCORE */ 217 | if (attr & A_LEFT) 218 | mapped_attr |= 0x0800; /* COMMON_LVB_GRID_LVERTICAL */ 219 | if (attr & A_RIGHT) 220 | mapped_attr |= 0x1000; /* COMMON_LVB_GRID_RVERTICAL */ 221 | 222 | for (j = 0; j < len; j++) 223 | { 224 | chtype ch = srcp[j]; 225 | 226 | if (ch & A_ALTCHARSET && !(ch & 0xff80)) 227 | ch = acs_map[ch & 0x7f]; 228 | 229 | if (blink && blinked_off) 230 | ch = ' '; 231 | 232 | buffer[j].Attributes = mapped_attr; 233 | buffer[j].Char.UnicodeChar = ch & A_CHARTEXT; 234 | } 235 | 236 | bufPos.X = bufPos.Y = 0; 237 | bufSize.X = len; 238 | bufSize.Y = 1; 239 | 240 | sr.Top = sr.Bottom = lineno; 241 | sr.Left = x; 242 | sr.Right = x + len - 1; 243 | 244 | WriteConsoleOutput(pdc_con_out, buffer, bufSize, bufPos, &sr); 245 | } 246 | } 247 | 248 | /* update the given physical line to look like the corresponding line in 249 | curscr */ 250 | 251 | void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) 252 | { 253 | attr_t old_attr, attr; 254 | int i, j; 255 | 256 | PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); 257 | 258 | old_attr = *srcp & (A_ATTRIBUTES ^ A_ALTCHARSET); 259 | 260 | for (i = 1, j = 1; j < len; i++, j++) 261 | { 262 | attr = srcp[i] & (A_ATTRIBUTES ^ A_ALTCHARSET); 263 | 264 | if (attr != old_attr) 265 | { 266 | _new_packet(old_attr, lineno, x, i, srcp); 267 | old_attr = attr; 268 | srcp += i; 269 | x += i; 270 | i = 0; 271 | } 272 | } 273 | 274 | _new_packet(old_attr, lineno, x, i, srcp); 275 | } 276 | 277 | void PDC_blink_text(void) 278 | { 279 | int i, j, k; 280 | 281 | if (!(SP->termattrs & A_BLINK)) 282 | blinked_off = FALSE; 283 | else 284 | blinked_off = !blinked_off; 285 | 286 | for (i = 0; i < SP->lines; i++) 287 | { 288 | const chtype *srcp = curscr->_y[i]; 289 | 290 | for (j = 0; j < SP->cols; j++) 291 | if (srcp[j] & A_BLINK) 292 | { 293 | k = j; 294 | while (k < SP->cols && (srcp[k] & A_BLINK)) 295 | k++; 296 | PDC_transform_line(i, j, k - j, srcp + j); 297 | j = k; 298 | } 299 | } 300 | 301 | PDC_gotoyx(SP->cursrow, SP->curscol); 302 | pdc_last_blink = GetTickCount(); 303 | } 304 | 305 | void PDC_doupdate(void) 306 | { 307 | } 308 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcgetsc.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include "pdcwin.h" 4 | 5 | /* get the cursor size/shape */ 6 | 7 | int PDC_get_cursor_mode(void) 8 | { 9 | CONSOLE_CURSOR_INFO ci; 10 | 11 | PDC_LOG(("PDC_get_cursor_mode() - called\n")); 12 | 13 | GetConsoleCursorInfo(pdc_con_out, &ci); 14 | 15 | return ci.dwSize; 16 | } 17 | 18 | /* return number of screen rows */ 19 | 20 | int PDC_get_rows(void) 21 | { 22 | CONSOLE_SCREEN_BUFFER_INFO scr; 23 | 24 | PDC_LOG(("PDC_get_rows() - called\n")); 25 | 26 | GetConsoleScreenBufferInfo(pdc_con_out, &scr); 27 | 28 | return scr.srWindow.Bottom - scr.srWindow.Top + 1; 29 | } 30 | 31 | /* return width of screen/viewport */ 32 | 33 | int PDC_get_columns(void) 34 | { 35 | CONSOLE_SCREEN_BUFFER_INFO scr; 36 | 37 | PDC_LOG(("PDC_get_columns() - called\n")); 38 | 39 | GetConsoleScreenBufferInfo(pdc_con_out, &scr); 40 | 41 | return scr.srWindow.Right - scr.srWindow.Left + 1; 42 | } 43 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcsetsc.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include "pdcwin.h" 4 | 5 | /*man-start************************************************************** 6 | 7 | pdcsetsc 8 | -------- 9 | 10 | ### Synopsis 11 | 12 | int PDC_set_blink(bool blinkon); 13 | int PDC_set_bold(bool boldon); 14 | void PDC_set_title(const char *title); 15 | 16 | ### Description 17 | 18 | PDC_set_blink() toggles whether the A_BLINK attribute sets an actual 19 | blink mode (TRUE), or sets the background color to high intensity 20 | (FALSE). The default is platform-dependent (FALSE in most cases). It 21 | returns OK if it could set the state to match the given parameter, 22 | ERR otherwise. 23 | 24 | PDC_set_bold() toggles whether the A_BOLD attribute selects an actual 25 | bold font (TRUE), or sets the foreground color to high intensity 26 | (FALSE). It returns OK if it could set the state to match the given 27 | parameter, ERR otherwise. 28 | 29 | PDC_set_title() sets the title of the window in which the curses 30 | program is running. This function may not do anything on some 31 | platforms. 32 | 33 | ### Portability 34 | X/Open ncurses NetBSD 35 | PDC_set_blink - - - 36 | PDC_set_title - - - 37 | 38 | **man-end****************************************************************/ 39 | 40 | int PDC_curs_set(int visibility) 41 | { 42 | CONSOLE_CURSOR_INFO cci; 43 | int ret_vis; 44 | 45 | PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility)); 46 | 47 | ret_vis = SP->visibility; 48 | 49 | if (GetConsoleCursorInfo(pdc_con_out, &cci) == FALSE) 50 | return ERR; 51 | 52 | switch(visibility) 53 | { 54 | case 0: /* invisible */ 55 | cci.bVisible = FALSE; 56 | break; 57 | case 2: /* highly visible */ 58 | cci.bVisible = TRUE; 59 | cci.dwSize = 95; 60 | break; 61 | default: /* normal visibility */ 62 | cci.bVisible = TRUE; 63 | cci.dwSize = SP->orig_cursor; 64 | break; 65 | } 66 | 67 | if (SetConsoleCursorInfo(pdc_con_out, &cci) == FALSE) 68 | return ERR; 69 | 70 | SP->visibility = visibility; 71 | return ret_vis; 72 | } 73 | 74 | void PDC_set_title(const char *title) 75 | { 76 | #ifdef PDC_WIDE 77 | wchar_t wtitle[512]; 78 | #endif 79 | PDC_LOG(("PDC_set_title() - called:<%s>\n", title)); 80 | 81 | #ifdef PDC_WIDE 82 | PDC_mbstowcs(wtitle, title, 511); 83 | SetConsoleTitleW(wtitle); 84 | #else 85 | SetConsoleTitleA(title); 86 | #endif 87 | } 88 | 89 | int PDC_set_blink(bool blinkon) 90 | { 91 | if (!SP) 92 | return ERR; 93 | 94 | if (SP->color_started) 95 | { 96 | COLORS = 16; 97 | if (PDC_can_change_color()) /* is_nt */ 98 | { 99 | if (pdc_conemu || SetConsoleMode(pdc_con_out, 0x0004)) /* VT */ 100 | COLORS = PDC_MAXCOL; 101 | 102 | if (!pdc_conemu) 103 | SetConsoleMode(pdc_con_out, 0x0010); /* LVB */ 104 | } 105 | } 106 | 107 | if (blinkon) 108 | { 109 | if (!(SP->termattrs & A_BLINK)) 110 | { 111 | SP->termattrs |= A_BLINK; 112 | pdc_last_blink = GetTickCount(); 113 | } 114 | } 115 | else 116 | { 117 | if (SP->termattrs & A_BLINK) 118 | { 119 | SP->termattrs &= ~A_BLINK; 120 | PDC_blink_text(); 121 | } 122 | } 123 | 124 | return OK; 125 | } 126 | 127 | int PDC_set_bold(bool boldon) 128 | { 129 | return boldon ? ERR : OK; 130 | } 131 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcutil.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include "pdcwin.h" 4 | 5 | void PDC_beep(void) 6 | { 7 | PDC_LOG(("PDC_beep() - called\n")); 8 | 9 | /* MessageBeep(MB_OK); */ 10 | MessageBeep(0XFFFFFFFF); 11 | } 12 | 13 | void PDC_napms(int ms) 14 | { 15 | PDC_LOG(("PDC_napms() - called: ms=%d\n", ms)); 16 | 17 | if ((SP->termattrs & A_BLINK) && (GetTickCount() >= pdc_last_blink + 500)) 18 | PDC_blink_text(); 19 | 20 | Sleep(ms); 21 | } 22 | 23 | const char *PDC_sysname(void) 24 | { 25 | return "Windows"; 26 | } 27 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/pdcwin.h: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #if defined(PDC_WIDE) && !defined(UNICODE) 4 | # define UNICODE 5 | #endif 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #include 9 | #undef MOUSE_MOVED 10 | #include 11 | 12 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 13 | # define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */ 14 | #endif 15 | 16 | typedef struct {short r, g, b; bool mapped;} PDCCOLOR; 17 | 18 | extern PDCCOLOR pdc_color[PDC_MAXCOL]; 19 | 20 | extern HANDLE pdc_con_out, pdc_con_in; 21 | extern DWORD pdc_quick_edit; 22 | extern DWORD pdc_last_blink; 23 | extern short pdc_curstoreal[16], pdc_curstoansi[16]; 24 | extern short pdc_oldf, pdc_oldb, pdc_oldu; 25 | extern bool pdc_conemu, pdc_ansi; 26 | 27 | extern void PDC_blink_text(void); 28 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/printw.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | printw 8 | ------ 9 | 10 | ### Synopsis 11 | 12 | int printw(const char *fmt, ...); 13 | int wprintw(WINDOW *win, const char *fmt, ...); 14 | int mvprintw(int y, int x, const char *fmt, ...); 15 | int mvwprintw(WINDOW *win, int y, int x, const char *fmt,...); 16 | int vwprintw(WINDOW *win, const char *fmt, va_list varglist); 17 | int vw_printw(WINDOW *win, const char *fmt, va_list varglist); 18 | 19 | ### Description 20 | 21 | The printw() functions add a formatted string to the window at the 22 | current or specified cursor position. The format strings are the same 23 | as used in the standard C library's printf(). (printw() can be used 24 | as a drop-in replacement for printf().) 25 | 26 | The duplication between vwprintw() and vw_printw() is for historic 27 | reasons. In PDCurses, they're the same. 28 | 29 | ### Return Value 30 | 31 | All functions return the number of characters printed, or ERR on 32 | error. 33 | 34 | ### Portability 35 | X/Open ncurses NetBSD 36 | printw Y Y Y 37 | wprintw Y Y Y 38 | mvprintw Y Y Y 39 | mvwprintw Y Y Y 40 | vwprintw Y Y Y 41 | vw_printw Y Y Y 42 | 43 | **man-end****************************************************************/ 44 | 45 | #include 46 | 47 | int vwprintw(WINDOW *win, const char *fmt, va_list varglist) 48 | { 49 | char printbuf[513]; 50 | int len; 51 | 52 | PDC_LOG(("vwprintw() - called\n")); 53 | 54 | #ifdef HAVE_VSNPRINTF 55 | len = vsnprintf(printbuf, 512, fmt, varglist); 56 | #else 57 | len = vsprintf(printbuf, fmt, varglist); 58 | #endif 59 | return (waddstr(win, printbuf) == ERR) ? ERR : len; 60 | } 61 | 62 | int printw(const char *fmt, ...) 63 | { 64 | va_list args; 65 | int retval; 66 | 67 | PDC_LOG(("printw() - called\n")); 68 | 69 | va_start(args, fmt); 70 | retval = vwprintw(stdscr, fmt, args); 71 | va_end(args); 72 | 73 | return retval; 74 | } 75 | 76 | int wprintw(WINDOW *win, const char *fmt, ...) 77 | { 78 | va_list args; 79 | int retval; 80 | 81 | PDC_LOG(("wprintw() - called\n")); 82 | 83 | va_start(args, fmt); 84 | retval = vwprintw(win, fmt, args); 85 | va_end(args); 86 | 87 | return retval; 88 | } 89 | 90 | int mvprintw(int y, int x, const char *fmt, ...) 91 | { 92 | va_list args; 93 | int retval; 94 | 95 | PDC_LOG(("mvprintw() - called\n")); 96 | 97 | if (move(y, x) == ERR) 98 | return ERR; 99 | 100 | va_start(args, fmt); 101 | retval = vwprintw(stdscr, fmt, args); 102 | va_end(args); 103 | 104 | return retval; 105 | } 106 | 107 | int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) 108 | { 109 | va_list args; 110 | int retval; 111 | 112 | PDC_LOG(("mvwprintw() - called\n")); 113 | 114 | if (wmove(win, y, x) == ERR) 115 | return ERR; 116 | 117 | va_start(args, fmt); 118 | retval = vwprintw(win, fmt, args); 119 | va_end(args); 120 | 121 | return retval; 122 | } 123 | 124 | int vw_printw(WINDOW *win, const char *fmt, va_list varglist) 125 | { 126 | PDC_LOG(("vw_printw() - called\n")); 127 | 128 | return vwprintw(win, fmt, varglist); 129 | } 130 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/refresh.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | refresh 8 | ------- 9 | 10 | ### Synopsis 11 | 12 | int refresh(void); 13 | int wrefresh(WINDOW *win); 14 | int wnoutrefresh(WINDOW *win); 15 | int doupdate(void); 16 | int redrawwin(WINDOW *win); 17 | int wredrawln(WINDOW *win, int beg_line, int num_lines); 18 | 19 | ### Description 20 | 21 | wrefresh() copies the named window to the physical terminal screen, 22 | taking into account what is already there in order to optimize cursor 23 | movement. refresh() does the same, using stdscr. These routines must 24 | be called to get any output on the terminal, as other routines only 25 | manipulate data structures. Unless leaveok() has been enabled, the 26 | physical cursor of the terminal is left at the location of the 27 | window's cursor. 28 | 29 | wnoutrefresh() and doupdate() allow multiple updates with more 30 | efficiency than wrefresh() alone. wrefresh() works by first calling 31 | wnoutrefresh(), which copies the named window to the virtual screen. 32 | It then calls doupdate(), which compares the virtual screen to the 33 | physical screen and does the actual update. A series of calls to 34 | wrefresh() will result in alternating calls to wnoutrefresh() and 35 | doupdate(), causing several bursts of output to the screen. By first 36 | calling wnoutrefresh() for each window, it is then possible to call 37 | doupdate() only once. 38 | 39 | In PDCurses, redrawwin() is equivalent to touchwin(), and wredrawln() 40 | is the same as touchline(). In some other curses implementations, 41 | there's a subtle distinction, but it has no meaning in PDCurses. 42 | 43 | ### Return Value 44 | 45 | All functions return OK on success and ERR on error. 46 | 47 | ### Portability 48 | X/Open ncurses NetBSD 49 | refresh Y Y Y 50 | wrefresh Y Y Y 51 | wnoutrefresh Y Y Y 52 | doupdate Y Y Y 53 | redrawwin Y Y Y 54 | wredrawln Y Y Y 55 | 56 | **man-end****************************************************************/ 57 | 58 | #include 59 | 60 | int wnoutrefresh(WINDOW *win) 61 | { 62 | int begy, begx; /* window's place on screen */ 63 | int i, j; 64 | 65 | PDC_LOG(("wnoutrefresh() - called: win=%p\n", win)); 66 | 67 | if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) 68 | return ERR; 69 | 70 | begy = win->_begy; 71 | begx = win->_begx; 72 | 73 | for (i = 0, j = begy; i < win->_maxy; i++, j++) 74 | { 75 | if (win->_firstch[i] != _NO_CHANGE) 76 | { 77 | chtype *src = win->_y[i]; 78 | chtype *dest = curscr->_y[j] + begx; 79 | 80 | int first = win->_firstch[i]; /* first changed */ 81 | int last = win->_lastch[i]; /* last changed */ 82 | 83 | /* ignore areas on the outside that are marked as changed, 84 | but really aren't */ 85 | 86 | while (first <= last && src[first] == dest[first]) 87 | first++; 88 | 89 | while (last >= first && src[last] == dest[last]) 90 | last--; 91 | 92 | /* if any have really changed... */ 93 | 94 | if (first <= last) 95 | { 96 | memcpy(dest + first, src + first, 97 | (last - first + 1) * sizeof(chtype)); 98 | 99 | first += begx; 100 | last += begx; 101 | 102 | if (first < curscr->_firstch[j] || 103 | curscr->_firstch[j] == _NO_CHANGE) 104 | curscr->_firstch[j] = first; 105 | 106 | if (last > curscr->_lastch[j]) 107 | curscr->_lastch[j] = last; 108 | } 109 | 110 | win->_firstch[i] = _NO_CHANGE; /* updated now */ 111 | } 112 | 113 | win->_lastch[i] = _NO_CHANGE; /* updated now */ 114 | } 115 | 116 | if (win->_clear) 117 | win->_clear = FALSE; 118 | 119 | if (!win->_leaveit) 120 | { 121 | curscr->_cury = win->_cury + begy; 122 | curscr->_curx = win->_curx + begx; 123 | } 124 | 125 | return OK; 126 | } 127 | 128 | int doupdate(void) 129 | { 130 | int y; 131 | bool clearall; 132 | 133 | PDC_LOG(("doupdate() - called\n")); 134 | 135 | if (!SP || !curscr) 136 | return ERR; 137 | 138 | if (isendwin()) /* coming back after endwin() called */ 139 | { 140 | reset_prog_mode(); 141 | clearall = TRUE; 142 | SP->alive = TRUE; /* so isendwin() result is correct */ 143 | } 144 | else 145 | clearall = curscr->_clear; 146 | 147 | for (y = 0; y < SP->lines; y++) 148 | { 149 | PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n", 150 | y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ? 151 | "Yes" : "No")); 152 | 153 | if (clearall || curscr->_firstch[y] != _NO_CHANGE) 154 | { 155 | int first, last; 156 | 157 | chtype *src = curscr->_y[y]; 158 | chtype *dest = SP->lastscr->_y[y]; 159 | 160 | if (clearall) 161 | { 162 | first = 0; 163 | last = COLS - 1; 164 | } 165 | else 166 | { 167 | first = curscr->_firstch[y]; 168 | last = curscr->_lastch[y]; 169 | } 170 | 171 | while (first <= last) 172 | { 173 | int len = 0; 174 | 175 | /* build up a run of changed cells; if two runs are 176 | separated by a single unchanged cell, ignore the 177 | break */ 178 | 179 | if (clearall) 180 | len = last - first + 1; 181 | else 182 | while (first + len <= last && 183 | (src[first + len] != dest[first + len] || 184 | (len && first + len < last && 185 | src[first + len + 1] != dest[first + len + 1]) 186 | ) 187 | ) 188 | len++; 189 | 190 | /* update the screen, and SP->lastscr */ 191 | 192 | if (len) 193 | { 194 | PDC_transform_line(y, first, len, src + first); 195 | memcpy(dest + first, src + first, len * sizeof(chtype)); 196 | first += len; 197 | } 198 | 199 | /* skip over runs of unchanged cells */ 200 | 201 | while (first <= last && src[first] == dest[first]) 202 | first++; 203 | } 204 | 205 | curscr->_firstch[y] = _NO_CHANGE; 206 | curscr->_lastch[y] = _NO_CHANGE; 207 | } 208 | } 209 | 210 | curscr->_clear = FALSE; 211 | 212 | if (SP->visibility) 213 | PDC_gotoyx(curscr->_cury, curscr->_curx); 214 | 215 | SP->cursrow = curscr->_cury; 216 | SP->curscol = curscr->_curx; 217 | 218 | PDC_doupdate(); 219 | 220 | return OK; 221 | } 222 | 223 | int wrefresh(WINDOW *win) 224 | { 225 | bool save_clear; 226 | 227 | PDC_LOG(("wrefresh() - called\n")); 228 | 229 | if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) 230 | return ERR; 231 | 232 | save_clear = win->_clear; 233 | 234 | if (win == curscr) 235 | curscr->_clear = TRUE; 236 | else 237 | wnoutrefresh(win); 238 | 239 | if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols) 240 | curscr->_clear = TRUE; 241 | 242 | return doupdate(); 243 | } 244 | 245 | int refresh(void) 246 | { 247 | PDC_LOG(("refresh() - called\n")); 248 | 249 | return wrefresh(stdscr); 250 | } 251 | 252 | int wredrawln(WINDOW *win, int start, int num) 253 | { 254 | int i; 255 | 256 | PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n", 257 | win, start, num)); 258 | 259 | if (!win || start > win->_maxy || start + num > win->_maxy) 260 | return ERR; 261 | 262 | for (i = start; i < start + num; i++) 263 | { 264 | win->_firstch[i] = 0; 265 | win->_lastch[i] = win->_maxx - 1; 266 | } 267 | 268 | return OK; 269 | } 270 | 271 | int redrawwin(WINDOW *win) 272 | { 273 | PDC_LOG(("redrawwin() - called: win=%p\n", win)); 274 | 275 | if (!win) 276 | return ERR; 277 | 278 | return wredrawln(win, 0, win->_maxy); 279 | } 280 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/scr_dump.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | scr_dump 8 | -------- 9 | 10 | ### Synopsis 11 | 12 | int putwin(WINDOW *win, FILE *filep); 13 | WINDOW *getwin(FILE *filep); 14 | int scr_dump(const char *filename); 15 | int scr_init(const char *filename); 16 | int scr_restore(const char *filename); 17 | int scr_set(const char *filename); 18 | 19 | ### Description 20 | 21 | getwin() reads window-related data previously stored in a file by 22 | putwin(). It then creates and initialises a new window using that 23 | data. 24 | 25 | putwin() writes all data associated with a window into a file, using 26 | an unspecified format. This information can be retrieved later using 27 | getwin(). 28 | 29 | scr_dump() writes the current contents of the virtual screen to the 30 | file named by filename in an unspecified format. 31 | 32 | scr_restore() function sets the virtual screen to the contents of the 33 | file named by filename, which must have been written using 34 | scr_dump(). The next refresh operation restores the screen to the way 35 | it looked in the dump file. 36 | 37 | In PDCurses, scr_init() does nothing, and scr_set() is a synonym for 38 | scr_restore(). Also, scr_dump() and scr_restore() save and load from 39 | curscr. This differs from some other implementations, where 40 | scr_init() works with curscr, and scr_restore() works with newscr; 41 | but the effect should be the same. (PDCurses has no newscr.) 42 | 43 | ### Return Value 44 | 45 | On successful completion, getwin() returns a pointer to the window it 46 | created. Otherwise, it returns a null pointer. Other functions return 47 | OK or ERR. 48 | 49 | ### Portability 50 | X/Open ncurses NetBSD 51 | putwin Y Y Y 52 | getwin Y Y Y 53 | scr_dump Y Y - 54 | scr_init Y Y - 55 | scr_restore Y Y - 56 | scr_set Y Y - 57 | 58 | **man-end****************************************************************/ 59 | 60 | #include 61 | #include 62 | 63 | #define DUMPVER 1 /* Should be updated whenever the WINDOW struct is 64 | changed */ 65 | 66 | int putwin(WINDOW *win, FILE *filep) 67 | { 68 | static const char *marker = "PDC"; 69 | static const unsigned char version = DUMPVER; 70 | 71 | PDC_LOG(("putwin() - called\n")); 72 | 73 | /* write the marker and the WINDOW struct */ 74 | 75 | if (filep && fwrite(marker, strlen(marker), 1, filep) 76 | && fwrite(&version, 1, 1, filep) 77 | && fwrite(win, sizeof(WINDOW), 1, filep)) 78 | { 79 | int i; 80 | 81 | /* write each line */ 82 | 83 | for (i = 0; i < win->_maxy && win->_y[i]; i++) 84 | if (!fwrite(win->_y[i], win->_maxx * sizeof(chtype), 1, filep)) 85 | return ERR; 86 | 87 | return OK; 88 | } 89 | 90 | return ERR; 91 | } 92 | 93 | WINDOW *getwin(FILE *filep) 94 | { 95 | WINDOW *win; 96 | char marker[4]; 97 | int i, nlines, ncols; 98 | 99 | PDC_LOG(("getwin() - called\n")); 100 | 101 | win = malloc(sizeof(WINDOW)); 102 | if (!win) 103 | return (WINDOW *)NULL; 104 | 105 | /* check for the marker, and load the WINDOW struct */ 106 | 107 | if (!filep || !fread(marker, 4, 1, filep) || strncmp(marker, "PDC", 3) 108 | || marker[3] != DUMPVER || !fread(win, sizeof(WINDOW), 1, filep)) 109 | { 110 | free(win); 111 | return (WINDOW *)NULL; 112 | } 113 | 114 | nlines = win->_maxy; 115 | ncols = win->_maxx; 116 | 117 | /* allocate the line pointer array */ 118 | 119 | win->_y = malloc(nlines * sizeof(chtype *)); 120 | if (!win->_y) 121 | { 122 | free(win); 123 | return (WINDOW *)NULL; 124 | } 125 | 126 | /* allocate the minchng and maxchng arrays */ 127 | 128 | win->_firstch = malloc(nlines * sizeof(int)); 129 | if (!win->_firstch) 130 | { 131 | free(win->_y); 132 | free(win); 133 | return (WINDOW *)NULL; 134 | } 135 | 136 | win->_lastch = malloc(nlines * sizeof(int)); 137 | if (!win->_lastch) 138 | { 139 | free(win->_firstch); 140 | free(win->_y); 141 | free(win); 142 | return (WINDOW *)NULL; 143 | } 144 | 145 | /* allocate the lines */ 146 | 147 | win = PDC_makelines(win); 148 | if (!win) 149 | return (WINDOW *)NULL; 150 | 151 | /* read them */ 152 | 153 | for (i = 0; i < nlines; i++) 154 | { 155 | if (!fread(win->_y[i], ncols * sizeof(chtype), 1, filep)) 156 | { 157 | delwin(win); 158 | return (WINDOW *)NULL; 159 | } 160 | } 161 | 162 | touchwin(win); 163 | 164 | return win; 165 | } 166 | 167 | int scr_dump(const char *filename) 168 | { 169 | FILE *filep; 170 | 171 | PDC_LOG(("scr_dump() - called: filename %s\n", filename)); 172 | 173 | if (filename && (filep = fopen(filename, "wb")) != NULL) 174 | { 175 | int result = putwin(curscr, filep); 176 | fclose(filep); 177 | return result; 178 | } 179 | 180 | return ERR; 181 | } 182 | 183 | int scr_init(const char *filename) 184 | { 185 | PDC_LOG(("scr_init() - called: filename %s\n", filename)); 186 | 187 | return OK; 188 | } 189 | 190 | int scr_restore(const char *filename) 191 | { 192 | FILE *filep; 193 | 194 | PDC_LOG(("scr_restore() - called: filename %s\n", filename)); 195 | 196 | if (filename && (filep = fopen(filename, "rb")) != NULL) 197 | { 198 | WINDOW *replacement = getwin(filep); 199 | fclose(filep); 200 | 201 | if (replacement) 202 | { 203 | int result = overwrite(replacement, curscr); 204 | delwin(replacement); 205 | return result; 206 | } 207 | } 208 | 209 | return ERR; 210 | } 211 | 212 | int scr_set(const char *filename) 213 | { 214 | PDC_LOG(("scr_set() - called: filename %s\n", filename)); 215 | 216 | return scr_restore(filename); 217 | } 218 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/scroll.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | scroll 8 | ------ 9 | 10 | ### Synopsis 11 | 12 | int scroll(WINDOW *win); 13 | int scrl(int n); 14 | int wscrl(WINDOW *win, int n); 15 | 16 | ### Description 17 | 18 | scroll() causes the window to scroll up one line. This involves 19 | moving the lines in the window data strcture. 20 | 21 | With a positive n, scrl() and wscrl() scroll the window up n lines 22 | (line i + n becomes i); otherwise they scroll the window down n 23 | lines. 24 | 25 | For these functions to work, scrolling must be enabled via 26 | scrollok(). Note also that scrolling is not allowed if the supplied 27 | window is a pad. 28 | 29 | ### Return Value 30 | 31 | All functions return OK on success and ERR on error. 32 | 33 | ### Portability 34 | X/Open ncurses NetBSD 35 | scroll Y Y Y 36 | scrl Y Y Y 37 | wscrl Y Y Y 38 | 39 | **man-end****************************************************************/ 40 | 41 | int wscrl(WINDOW *win, int n) 42 | { 43 | int i, l, dir, start, end; 44 | chtype blank, *temp; 45 | 46 | /* Check if window scrolls. Valid for window AND pad */ 47 | 48 | if (!win || !win->_scroll || !n) 49 | return ERR; 50 | 51 | blank = win->_bkgd; 52 | 53 | if (n > 0) 54 | { 55 | start = win->_tmarg; 56 | end = win->_bmarg; 57 | dir = 1; 58 | } 59 | else 60 | { 61 | start = win->_bmarg; 62 | end = win->_tmarg; 63 | dir = -1; 64 | } 65 | 66 | for (l = 0; l < (n * dir); l++) 67 | { 68 | temp = win->_y[start]; 69 | 70 | /* re-arrange line pointers */ 71 | 72 | for (i = start; i != end; i += dir) 73 | win->_y[i] = win->_y[i + dir]; 74 | 75 | win->_y[end] = temp; 76 | 77 | /* make a blank line */ 78 | 79 | for (i = 0; i < win->_maxx; i++) 80 | *temp++ = blank; 81 | } 82 | 83 | touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1); 84 | 85 | PDC_sync(win); 86 | return OK; 87 | } 88 | 89 | int scrl(int n) 90 | { 91 | PDC_LOG(("scrl() - called\n")); 92 | 93 | return wscrl(stdscr, n); 94 | } 95 | 96 | int scroll(WINDOW *win) 97 | { 98 | PDC_LOG(("scroll() - called\n")); 99 | 100 | return wscrl(win, 1); 101 | } 102 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/termattr.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | termattr 8 | -------- 9 | 10 | ### Synopsis 11 | 12 | int baudrate(void); 13 | char erasechar(void); 14 | bool has_ic(void); 15 | bool has_il(void); 16 | char killchar(void); 17 | char *longname(void); 18 | chtype termattrs(void); 19 | attr_t term_attrs(void); 20 | char *termname(void); 21 | 22 | int erasewchar(wchar_t *ch); 23 | int killwchar(wchar_t *ch); 24 | 25 | char wordchar(void); 26 | 27 | ### Description 28 | 29 | baudrate() is supposed to return the output speed of the terminal. In 30 | PDCurses, it simply returns INT_MAX. 31 | 32 | has_ic and has_il() return TRUE. These functions have meaning in some 33 | other implementations of curses. 34 | 35 | erasechar() and killchar() return ^H and ^U, respectively -- the 36 | ERASE and KILL characters. In other curses implementations, these may 37 | vary by terminal type. erasewchar() and killwchar() are the wide- 38 | character versions; they take a pointer to a location in which to 39 | store the character, and return OK or ERR. 40 | 41 | longname() returns a pointer to a static area containing a verbose 42 | description of the current terminal. The maximum length of the string 43 | is 128 characters. It is defined only after the call to initscr() or 44 | newterm(). 45 | 46 | termname() returns a pointer to a static area containing a short 47 | description of the current terminal (14 characters). 48 | 49 | termattrs() returns a logical OR of all video attributes supported by 50 | the terminal. 51 | 52 | wordchar() is a PDCurses extension of the concept behind the 53 | functions erasechar() and killchar(), returning the "delete word" 54 | character, ^W. 55 | 56 | ### Portability 57 | X/Open ncurses NetBSD 58 | baudrate Y Y Y 59 | erasechar Y Y Y 60 | has_ic Y Y Y 61 | has_il Y Y Y 62 | killchar Y Y Y 63 | longname Y Y Y 64 | termattrs Y Y Y 65 | termname Y Y Y 66 | erasewchar Y Y Y 67 | killwchar Y Y Y 68 | term_attrs Y Y Y 69 | wordchar - - - 70 | 71 | **man-end****************************************************************/ 72 | 73 | #include 74 | #include 75 | 76 | int baudrate(void) 77 | { 78 | PDC_LOG(("baudrate() - called\n")); 79 | 80 | return INT_MAX; 81 | } 82 | 83 | char erasechar(void) 84 | { 85 | PDC_LOG(("erasechar() - called\n")); 86 | 87 | return _ECHAR; /* character delete char (^H) */ 88 | } 89 | 90 | bool has_ic(void) 91 | { 92 | PDC_LOG(("has_ic() - called\n")); 93 | 94 | return TRUE; 95 | } 96 | 97 | bool has_il(void) 98 | { 99 | PDC_LOG(("has_il() - called\n")); 100 | 101 | return TRUE; 102 | } 103 | 104 | char killchar(void) 105 | { 106 | PDC_LOG(("killchar() - called\n")); 107 | 108 | return _DLCHAR; /* line delete char (^U) */ 109 | } 110 | 111 | char *longname(void) 112 | { 113 | PDC_LOG(("longname() - called\n")); 114 | 115 | return ttytype + 9; /* skip "pdcurses|" */ 116 | } 117 | 118 | chtype termattrs(void) 119 | { 120 | PDC_LOG(("termattrs() - called\n")); 121 | 122 | return SP ? SP->termattrs : (chtype)0; 123 | } 124 | 125 | attr_t term_attrs(void) 126 | { 127 | PDC_LOG(("term_attrs() - called\n")); 128 | 129 | return SP ? SP->termattrs : (attr_t)0; 130 | } 131 | 132 | char *termname(void) 133 | { 134 | static char _termname[14] = "pdcurses"; 135 | 136 | PDC_LOG(("termname() - called\n")); 137 | 138 | return _termname; 139 | } 140 | 141 | char wordchar(void) 142 | { 143 | PDC_LOG(("wordchar() - called\n")); 144 | 145 | return _DWCHAR; /* word delete char */ 146 | } 147 | 148 | #ifdef PDC_WIDE 149 | int erasewchar(wchar_t *ch) 150 | { 151 | PDC_LOG(("erasewchar() - called\n")); 152 | 153 | if (!ch) 154 | return ERR; 155 | 156 | *ch = (wchar_t)_ECHAR; 157 | 158 | return OK; 159 | } 160 | 161 | int killwchar(wchar_t *ch) 162 | { 163 | PDC_LOG(("killwchar() - called\n")); 164 | 165 | if (!ch) 166 | return ERR; 167 | 168 | *ch = (wchar_t)_DLCHAR; 169 | 170 | return OK; 171 | } 172 | #endif 173 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/touch.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | touch 8 | ----- 9 | 10 | ### Synopsis 11 | 12 | int touchwin(WINDOW *win); 13 | int touchline(WINDOW *win, int start, int count); 14 | int untouchwin(WINDOW *win); 15 | int wtouchln(WINDOW *win, int y, int n, int changed); 16 | bool is_linetouched(WINDOW *win, int line); 17 | bool is_wintouched(WINDOW *win); 18 | 19 | int touchoverlap(const WINDOW *win1, WINDOW *win2); 20 | 21 | ### Description 22 | 23 | touchwin() and touchline() throw away all information about which 24 | parts of the window have been touched, pretending that the entire 25 | window has been drawn on. This is sometimes necessary when using 26 | overlapping windows, since a change to one window will affect the 27 | other window, but the records of which lines have been changed in the 28 | other window will not reflect the change. 29 | 30 | untouchwin() marks all lines in the window as unchanged since the 31 | last call to wrefresh(). 32 | 33 | wtouchln() makes n lines in the window, starting at line y, look as 34 | if they have (changed == 1) or have not (changed == 0) been changed 35 | since the last call to wrefresh(). 36 | 37 | is_linetouched() returns TRUE if the specified line in the specified 38 | window has been changed since the last call to wrefresh(). 39 | 40 | is_wintouched() returns TRUE if the specified window has been changed 41 | since the last call to wrefresh(). 42 | 43 | touchoverlap(win1, win2) marks the portion of win2 which overlaps 44 | with win1 as modified. 45 | 46 | ### Return Value 47 | 48 | All functions return OK on success and ERR on error except 49 | is_wintouched() and is_linetouched(). 50 | 51 | ### Portability 52 | X/Open ncurses NetBSD 53 | touchwin Y Y Y 54 | touchline Y Y Y 55 | untouchwin Y Y Y 56 | wtouchln Y Y Y 57 | is_linetouched Y Y Y 58 | is_wintouched Y Y Y 59 | touchoverlap - - Y 60 | 61 | **man-end****************************************************************/ 62 | 63 | int touchwin(WINDOW *win) 64 | { 65 | int i; 66 | 67 | PDC_LOG(("touchwin() - called: Win=%x\n", win)); 68 | 69 | if (!win) 70 | return ERR; 71 | 72 | for (i = 0; i < win->_maxy; i++) 73 | { 74 | win->_firstch[i] = 0; 75 | win->_lastch[i] = win->_maxx - 1; 76 | } 77 | 78 | return OK; 79 | } 80 | 81 | int touchline(WINDOW *win, int start, int count) 82 | { 83 | int i; 84 | 85 | PDC_LOG(("touchline() - called: win=%p start %d count %d\n", 86 | win, start, count)); 87 | 88 | if (!win || start > win->_maxy || start + count > win->_maxy) 89 | return ERR; 90 | 91 | for (i = start; i < start + count; i++) 92 | { 93 | win->_firstch[i] = 0; 94 | win->_lastch[i] = win->_maxx - 1; 95 | } 96 | 97 | return OK; 98 | } 99 | 100 | int untouchwin(WINDOW *win) 101 | { 102 | int i; 103 | 104 | PDC_LOG(("untouchwin() - called: win=%p", win)); 105 | 106 | if (!win) 107 | return ERR; 108 | 109 | for (i = 0; i < win->_maxy; i++) 110 | { 111 | win->_firstch[i] = _NO_CHANGE; 112 | win->_lastch[i] = _NO_CHANGE; 113 | } 114 | 115 | return OK; 116 | } 117 | 118 | int wtouchln(WINDOW *win, int y, int n, int changed) 119 | { 120 | int i; 121 | 122 | PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n", 123 | win, y, n, changed)); 124 | 125 | if (!win || y > win->_maxy || y + n > win->_maxy) 126 | return ERR; 127 | 128 | for (i = y; i < y + n; i++) 129 | { 130 | if (changed) 131 | { 132 | win->_firstch[i] = 0; 133 | win->_lastch[i] = win->_maxx - 1; 134 | } 135 | else 136 | { 137 | win->_firstch[i] = _NO_CHANGE; 138 | win->_lastch[i] = _NO_CHANGE; 139 | } 140 | } 141 | 142 | return OK; 143 | } 144 | 145 | bool is_linetouched(WINDOW *win, int line) 146 | { 147 | PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line)); 148 | 149 | if (!win || line > win->_maxy || line < 0) 150 | return FALSE; 151 | 152 | return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE; 153 | } 154 | 155 | bool is_wintouched(WINDOW *win) 156 | { 157 | int i; 158 | 159 | PDC_LOG(("is_wintouched() - called: win=%p\n", win)); 160 | 161 | if (win) 162 | for (i = 0; i < win->_maxy; i++) 163 | if (win->_firstch[i] != _NO_CHANGE) 164 | return TRUE; 165 | 166 | return FALSE; 167 | } 168 | 169 | int touchoverlap(const WINDOW *win1, WINDOW *win2) 170 | { 171 | int y, endy, endx, starty, startx; 172 | 173 | PDC_LOG(("touchoverlap() - called: win1=%p win2=%p\n", win1, win2)); 174 | 175 | if (!win1 || !win2) 176 | return ERR; 177 | 178 | starty = max(win1->_begy, win2->_begy); 179 | startx = max(win1->_begx, win2->_begx); 180 | endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy); 181 | endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx); 182 | 183 | if (starty >= endy || startx >= endx) 184 | return OK; 185 | 186 | starty -= win2->_begy; 187 | startx -= win2->_begx; 188 | endy -= win2->_begy; 189 | endx -= win2->_begx; 190 | endx -= 1; 191 | 192 | for (y = starty; y < endy; y++) 193 | { 194 | win2->_firstch[y] = startx; 195 | win2->_lastch[y] = endx; 196 | } 197 | 198 | return OK; 199 | } 200 | -------------------------------------------------------------------------------- /3rd/pdcurses/src/util.c: -------------------------------------------------------------------------------- 1 | /* PDCurses */ 2 | 3 | #include 4 | 5 | /*man-start************************************************************** 6 | 7 | util 8 | ---- 9 | 10 | ### Synopsis 11 | 12 | char *unctrl(chtype c); 13 | void filter(void); 14 | void use_env(bool x); 15 | int delay_output(int ms); 16 | 17 | int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs, 18 | short *color_pair, void *opts); 19 | int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, 20 | short color_pair, const void *opts); 21 | wchar_t *wunctrl(cchar_t *wc); 22 | 23 | int PDC_mbtowc(wchar_t *pwc, const char *s, size_t n); 24 | size_t PDC_mbstowcs(wchar_t *dest, const char *src, size_t n); 25 | size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n); 26 | 27 | ### Description 28 | 29 | unctrl() expands the text portion of the chtype c into a printable 30 | string. Control characters are changed to the "^X" notation; others 31 | are passed through. wunctrl() is the wide-character version of the 32 | function. 33 | 34 | filter() and use_env() are no-ops in PDCurses. 35 | 36 | delay_output() inserts an ms millisecond pause in output. 37 | 38 | getcchar() works in two modes: When wch is not NULL, it reads the 39 | cchar_t pointed to by wcval and stores the attributes in attrs, the 40 | color pair in color_pair, and the text in the wide-character string 41 | wch. When wch is NULL, getcchar() merely returns the number of wide 42 | characters in wcval. In either mode, the opts argument is unused. 43 | 44 | setcchar constructs a cchar_t at wcval from the wide-character text 45 | at wch, the attributes in attr and the color pair in color_pair. The 46 | opts argument is unused. 47 | 48 | Currently, the length returned by getcchar() is always 1 or 0. 49 | Similarly, setcchar() will only take the first wide character from 50 | wch, and ignore any others that it "should" take (i.e., combining 51 | characters). Nor will it correctly handle any character outside the 52 | basic multilingual plane (UCS-2). 53 | 54 | ### Return Value 55 | 56 | wunctrl() returns NULL on failure. delay_output() always returns OK. 57 | 58 | getcchar() returns the number of wide characters wcval points to when 59 | wch is NULL; when it's not, getcchar() returns OK or ERR. 60 | 61 | setcchar() returns OK or ERR. 62 | 63 | ### Portability 64 | X/Open ncurses NetBSD 65 | unctrl Y Y Y 66 | filter Y Y Y 67 | use_env Y Y Y 68 | delay_output Y Y Y 69 | getcchar Y Y Y 70 | setcchar Y Y Y 71 | wunctrl Y Y Y 72 | PDC_mbtowc - - - 73 | PDC_mbstowcs - - - 74 | PDC_wcstombs - - - 75 | 76 | **man-end****************************************************************/ 77 | 78 | #include 79 | #include 80 | 81 | char *unctrl(chtype c) 82 | { 83 | static char strbuf[3] = {0, 0, 0}; 84 | 85 | chtype ic; 86 | 87 | PDC_LOG(("unctrl() - called\n")); 88 | 89 | ic = c & A_CHARTEXT; 90 | 91 | if (ic >= 0x20 && ic != 0x7f) /* normal characters */ 92 | { 93 | strbuf[0] = (char)ic; 94 | strbuf[1] = '\0'; 95 | return strbuf; 96 | } 97 | 98 | strbuf[0] = '^'; /* '^' prefix */ 99 | 100 | if (ic == 0x7f) /* 0x7f == DEL */ 101 | strbuf[1] = '?'; 102 | else /* other control */ 103 | strbuf[1] = (char)(ic + '@'); 104 | 105 | return strbuf; 106 | } 107 | 108 | void filter(void) 109 | { 110 | PDC_LOG(("filter() - called\n")); 111 | } 112 | 113 | void use_env(bool x) 114 | { 115 | PDC_LOG(("use_env() - called: x %d\n", x)); 116 | } 117 | 118 | int delay_output(int ms) 119 | { 120 | PDC_LOG(("delay_output() - called: ms %d\n", ms)); 121 | 122 | return napms(ms); 123 | } 124 | 125 | #ifdef PDC_WIDE 126 | int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs, 127 | short *color_pair, void *opts) 128 | { 129 | if (!wcval) 130 | return ERR; 131 | 132 | if (wch) 133 | { 134 | if (!attrs || !color_pair) 135 | return ERR; 136 | 137 | *wch = (*wcval & A_CHARTEXT); 138 | *attrs = (*wcval & (A_ATTRIBUTES & ~A_COLOR)); 139 | *color_pair = PAIR_NUMBER(*wcval & A_COLOR); 140 | 141 | if (*wch) 142 | *++wch = L'\0'; 143 | 144 | return OK; 145 | } 146 | else 147 | return ((*wcval & A_CHARTEXT) != L'\0'); 148 | } 149 | 150 | int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, 151 | short color_pair, const void *opts) 152 | { 153 | if (!wcval || !wch) 154 | return ERR; 155 | 156 | *wcval = *wch | attrs | COLOR_PAIR(color_pair); 157 | 158 | return OK; 159 | } 160 | 161 | wchar_t *wunctrl(cchar_t *wc) 162 | { 163 | static wchar_t strbuf[3] = {0, 0, 0}; 164 | 165 | cchar_t ic; 166 | 167 | PDC_LOG(("wunctrl() - called\n")); 168 | 169 | if (!wc) 170 | return NULL; 171 | 172 | ic = *wc & A_CHARTEXT; 173 | 174 | if (ic >= 0x20 && ic != 0x7f) /* normal characters */ 175 | { 176 | strbuf[0] = (wchar_t)ic; 177 | strbuf[1] = L'\0'; 178 | return strbuf; 179 | } 180 | 181 | strbuf[0] = '^'; /* '^' prefix */ 182 | 183 | if (ic == 0x7f) /* 0x7f == DEL */ 184 | strbuf[1] = '?'; 185 | else /* other control */ 186 | strbuf[1] = (wchar_t)(ic + '@'); 187 | 188 | return strbuf; 189 | } 190 | 191 | int PDC_mbtowc(wchar_t *pwc, const char *s, size_t n) 192 | { 193 | # ifdef PDC_FORCE_UTF8 194 | wchar_t key; 195 | int i = -1; 196 | const unsigned char *string; 197 | 198 | if (!s || (n < 1)) 199 | return -1; 200 | 201 | if (!*s) 202 | return 0; 203 | 204 | string = (const unsigned char *)s; 205 | 206 | key = string[0]; 207 | 208 | /* Simplistic UTF-8 decoder -- only does the BMP, minimal validation */ 209 | 210 | if (key & 0x80) 211 | { 212 | if ((key & 0xe0) == 0xc0) 213 | { 214 | if (1 < n) 215 | { 216 | key = ((key & 0x1f) << 6) | (string[1] & 0x3f); 217 | i = 2; 218 | } 219 | } 220 | else if ((key & 0xe0) == 0xe0) 221 | { 222 | if (2 < n) 223 | { 224 | key = ((key & 0x0f) << 12) | ((string[1] & 0x3f) << 6) | 225 | (string[2] & 0x3f); 226 | i = 3; 227 | } 228 | } 229 | } 230 | else 231 | i = 1; 232 | 233 | if (i) 234 | *pwc = key; 235 | 236 | return i; 237 | # else 238 | return mbtowc(pwc, s, n); 239 | # endif 240 | } 241 | 242 | size_t PDC_mbstowcs(wchar_t *dest, const char *src, size_t n) 243 | { 244 | # ifdef PDC_FORCE_UTF8 245 | size_t i = 0, len; 246 | 247 | if (!src || !dest) 248 | return 0; 249 | 250 | len = strlen(src); 251 | 252 | while (*src && i < n) 253 | { 254 | int retval = PDC_mbtowc(dest + i, src, len); 255 | 256 | if (retval < 1) 257 | return -1; 258 | 259 | src += retval; 260 | len -= retval; 261 | i++; 262 | } 263 | # else 264 | size_t i = mbstowcs(dest, src, n); 265 | # endif 266 | dest[i] = 0; 267 | return i; 268 | } 269 | 270 | size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n) 271 | { 272 | # ifdef PDC_FORCE_UTF8 273 | size_t i = 0; 274 | 275 | if (!src || !dest) 276 | return 0; 277 | 278 | while (*src && i < n) 279 | { 280 | chtype code = *src++; 281 | 282 | if (code < 0x80) 283 | { 284 | dest[i] = code; 285 | i++; 286 | } 287 | else 288 | if (code < 0x800) 289 | { 290 | dest[i] = ((code & 0x07c0) >> 6) | 0xc0; 291 | dest[i + 1] = (code & 0x003f) | 0x80; 292 | i += 2; 293 | } 294 | else 295 | { 296 | dest[i] = ((code & 0xf000) >> 12) | 0xe0; 297 | dest[i + 1] = ((code & 0x0fc0) >> 6) | 0x80; 298 | dest[i + 2] = (code & 0x003f) | 0x80; 299 | i += 3; 300 | } 301 | } 302 | # else 303 | size_t i = wcstombs(dest, src, n); 304 | # endif 305 | dest[i] = '\0'; 306 | return i; 307 | } 308 | #endif 309 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2.0) 2 | project(big_money) 3 | 4 | add_subdirectory(3rd) 5 | aux_source_directory(${CMAKE_SOURCE_DIR}/src SRC) 6 | 7 | add_executable(big_money ${SRC}) 8 | 9 | if (MSVC) 10 | target_compile_options(big_money PRIVATE /utf-8) 11 | endif() 12 | 13 | if (WIN32 OR MSVC) 14 | message(STATUS "Build big_money on windows system") 15 | add_dependencies(big_money libcurl) 16 | target_include_directories(big_money PUBLIC ${CMAKE_SOUREC_DIR}/include/pdcurses) 17 | target_link_libraries(big_money pdcurses libcurl) 18 | add_definitions(-DNOMINMAX) 19 | else() 20 | message(STATUS "Build big_money on *nix system") 21 | target_compile_options(big_money PRIVATE -std=c++11) 22 | find_package(CURL, REQUIRED) 23 | if (CURL_FOUND) 24 | message(STATUS "Looking for curl. Ok") 25 | else() 26 | message(FATAL_ERROR "Looking for curl. Fail") 27 | endif() 28 | 29 | set(CURSES_NEED_NCURSES TRUE) 30 | find_package(Curses REQUIRED) 31 | if (CURSES_FOUND) 32 | message(STATUS "Looking for curses. Ok") 33 | else() 34 | message(FATAL_ERROR "Looking for curses. Fail") 35 | endif() 36 | target_link_libraries(big_money ncursesw curl) 37 | endif() 38 | 39 | 40 | target_include_directories(big_money PRIVATE 41 | ${CMAKE_SOURCE_DIR}/include 42 | ${CMAKE_SOURCE_DIR}/3rd/rapidjson/include 43 | ${CMAKE_SOURCE_DIR}/3rd/csylib/ 44 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 投资有风险 入市需谨慎 2 | 3 | ![sample](./1594979779.jpg) 4 | ### 下载 5 | [Windows Release](https://github.com/hanhan-GKD/BigMoney/releases/download/0.14/big_money_win_x86_release.zip) 6 | 7 | [OSX Release](https://github.com/hanhan-GKD/BigMoney/releases/download/0.14/big_money_macOS_release.zip) 8 | 9 | ### 使用 10 | ``` 11 | 1. 添加/更新基金 12 | update <基金编号> <持有份额> 13 | 2. 删除基金 14 | delete <基金编号> 15 | 3. 退出程序 16 | quit 17 | 4. 帮助 18 | help 19 | ``` 20 | 21 | ### 已知问题 22 | 23 | 1. 部分win10 文字会叠在一起 ? 24 | 25 | 在cmd属性面板中勾选使用旧版控制台(原因未知) 26 | 27 | ### 祝各位老板早日发财 -------------------------------------------------------------------------------- /include/colors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "port.h" 3 | 4 | 5 | namespace BigMoney { 6 | 7 | enum Color { 8 | kRedBlack = 1, 9 | kGreenBlack = 2, 10 | kWhiteBlue = 3 11 | }; 12 | 13 | int GetColorPair(Color color); 14 | 15 | } // namespace BigMoney 16 | -------------------------------------------------------------------------------- /include/command_bar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "port.h" 5 | #include "msg.h" 6 | #include "win.h" 7 | 8 | namespace BigMoney { 9 | 10 | class CommandBar : public Window{ 11 | public: 12 | CommandBar(int x, int y, int startx, int starty); 13 | void GetCommand(); 14 | ~CommandBar(); 15 | 16 | private: 17 | void ParseCommand(const std::string &cmd); 18 | private: 19 | std::thread *listen_thread_{nullptr}; 20 | bool is_listen_{false}; 21 | }; 22 | 23 | } // namespace BigMoney 24 | -------------------------------------------------------------------------------- /include/earn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fund_board.h" 4 | #include "status_bar.h" 5 | #include "command_bar.h" 6 | #include "help.h" 7 | 8 | namespace BigMoney { 9 | 10 | class Earn { 11 | public: 12 | Earn(); 13 | ~Earn(); 14 | private: 15 | FundBoard *fund_board_{nullptr}; 16 | HelpWindow* help_windows_{nullptr}; 17 | StatusBar *status_bar_{nullptr}; 18 | CommandBar *command_bar_{nullptr}; 19 | }; 20 | 21 | } // namespace BigMoney 22 | -------------------------------------------------------------------------------- /include/fund.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace BigMoney { 7 | struct Fund { 8 | std::string fund_code; 9 | float fund_worth{0.0f}; 10 | float valuation{0.0f}; 11 | float fluctuations{0.0f}; 12 | float share{0.0f}; 13 | float income{0.0f}; 14 | float sum{0.0f}; 15 | std::string fund_name; 16 | std::string last_update_time; 17 | }; 18 | struct FundIncome { 19 | float income{0.0f}; 20 | float sum{0.0f}; 21 | }; 22 | } // namespace BigMoney 23 | -------------------------------------------------------------------------------- /include/fund_board.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "port.h" 4 | #include "fund.h" 5 | #include 6 | #include 7 | #include 8 | #include "msg.h" 9 | #include "win.h" 10 | #include 11 | #include "timer.h" 12 | 13 | namespace BigMoney { 14 | class FundBoard : public Window { 15 | public: 16 | FundBoard(int x, int y, int startx, int starty); 17 | ~FundBoard(); 18 | void Paint() override; 19 | virtual bool MessageProc(const Msg &msg) override; 20 | private: 21 | void GetFundData(); 22 | void LoadFundFromFile(); 23 | static size_t WriteFunction(void *data, size_t size, size_t bytes, void *user_data); 24 | bool UpdateFund(const Fund& fund); 25 | bool DeleteFund(const std::string &fund_code); 26 | bool Serialize(); 27 | private: 28 | const static std::array, 9> FIELD_WIDTH_MAP; 29 | std::vector funds_; 30 | CURL *curl_{nullptr}; 31 | std::mutex fund_mutex_; 32 | Timer *timer{nullptr}; 33 | uint32_t page_{0}; 34 | uint32_t per_page_{0}; 35 | uint32_t max_page_{0}; 36 | std::atomic request_flag_{false}; 37 | std::atomic running_{true}; 38 | std::thread *request_thread_{nullptr}; 39 | }; 40 | } // namespace BigMoney 41 | -------------------------------------------------------------------------------- /include/help.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "win.h" 4 | 5 | #define GITHUB "GitHub: https://github.com/hanhan-GKD/BigMoney" 6 | #define BIG_MONEY_VERSION "0.14" 7 | 8 | namespace BigMoney { 9 | 10 | class HelpWindow : public Window { 11 | public: 12 | HelpWindow(int x, int y, int startx, int starty); 13 | bool MessageProc(const Msg& msg) override; 14 | void Paint() override; 15 | private: 16 | bool show_{ false }; 17 | }; 18 | 19 | } // namespace BigMoney 20 | -------------------------------------------------------------------------------- /include/msg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace BigMoney { 11 | 12 | enum MsgType { 13 | kUpdateFund, 14 | kDeleteFund, 15 | kUpdateIncome, 16 | kUpdateStatus, 17 | kPrePage, 18 | kNextPage, 19 | kPaint, 20 | kShowHelp, 21 | kHiddenPop, 22 | kReloadFile, 23 | kQuit, 24 | }; 25 | 26 | struct Msg { 27 | MsgType msg_type; 28 | void *lparam; 29 | void *rparam; 30 | }; 31 | 32 | class MsgQueue { 33 | public: 34 | bool Enqueue(const Msg& msg); 35 | bool Dequeue(Msg *msg); 36 | bool Empty(); 37 | private: 38 | std::queue msg_queue_; 39 | std::mutex mutex_; 40 | }; 41 | 42 | 43 | class MsgReactor { 44 | public: 45 | MsgReactor(); 46 | virtual ~MsgReactor(); 47 | virtual bool MessageProc(const Msg &msg) = 0; 48 | }; 49 | 50 | class MsgManager : public sy::Singleton { 51 | public: 52 | inline bool Enqueue(const Msg& msg) { 53 | return msg_queue_.Enqueue(msg); 54 | } 55 | inline bool Dequeue(Msg *msg) { 56 | return msg_queue_.Dequeue(msg); 57 | } 58 | inline bool QueueEmpty() { 59 | return msg_queue_.Empty(); 60 | } 61 | void AddReactor(MsgReactor *reactor); 62 | void RemoveReactor(MsgReactor *reactor); 63 | void StartMainLoop(); 64 | private: 65 | MsgQueue msg_queue_; 66 | std::unordered_set reactors_; 67 | std::mutex reactors_mutex_; 68 | }; 69 | 70 | bool GetMsg(Msg *msg); 71 | bool PostMsg(const Msg &msg); 72 | void StartMainLoop(); 73 | } // namespace BigMoney 74 | -------------------------------------------------------------------------------- /include/pdcurses/curspriv.h: -------------------------------------------------------------------------------- 1 | /* Private definitions and declarations for use within PDCurses. 2 | These should generally not be referenced by applications. */ 3 | 4 | #ifndef __CURSES_INTERNALS__ 5 | #define __CURSES_INTERNALS__ 1 6 | 7 | #define CURSES_LIBRARY 8 | #include 9 | 10 | #if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \ 11 | defined(PDC_99) || defined(__WATCOMC__) 12 | # ifndef HAVE_VSSCANF 13 | # define HAVE_VSSCANF /* have vsscanf() */ 14 | # endif 15 | #endif 16 | 17 | #if defined(PDC_99) || defined(__WATCOMC__) 18 | # ifndef HAVE_VSNPRINTF 19 | # define HAVE_VSNPRINTF /* have vsnprintf() */ 20 | # endif 21 | #endif 22 | 23 | /*----------------------------------------------------------------------*/ 24 | 25 | typedef struct /* structure for ripped off lines */ 26 | { 27 | int line; 28 | int (*init)(WINDOW *, int); 29 | } RIPPEDOFFLINE; 30 | 31 | /* Window properties */ 32 | 33 | #define _SUBWIN 0x01 /* window is a subwindow */ 34 | #define _PAD 0x10 /* X/Open Pad. */ 35 | #define _SUBPAD 0x20 /* X/Open subpad. */ 36 | 37 | /* Miscellaneous */ 38 | 39 | #define _NO_CHANGE -1 /* flags line edge unchanged */ 40 | 41 | #define _ECHAR 0x08 /* Erase char (^H) */ 42 | #define _DWCHAR 0x17 /* Delete Word char (^W) */ 43 | #define _DLCHAR 0x15 /* Delete Line char (^U) */ 44 | 45 | /*----------------------------------------------------------------------*/ 46 | 47 | /* Platform implementation functions */ 48 | 49 | void PDC_beep(void); 50 | bool PDC_can_change_color(void); 51 | int PDC_color_content(short, short *, short *, short *); 52 | bool PDC_check_key(void); 53 | int PDC_curs_set(int); 54 | void PDC_doupdate(void); 55 | void PDC_flushinp(void); 56 | int PDC_get_columns(void); 57 | int PDC_get_cursor_mode(void); 58 | int PDC_get_key(void); 59 | int PDC_get_rows(void); 60 | void PDC_gotoyx(int, int); 61 | bool PDC_has_mouse(void); 62 | int PDC_init_color(short, short, short, short); 63 | int PDC_modifiers_set(void); 64 | int PDC_mouse_set(void); 65 | void PDC_napms(int); 66 | void PDC_reset_prog_mode(void); 67 | void PDC_reset_shell_mode(void); 68 | int PDC_resize_screen(int, int); 69 | void PDC_restore_screen_mode(int); 70 | void PDC_save_screen_mode(int); 71 | #ifdef XCURSES 72 | void PDC_set_args(int, char **); 73 | #endif 74 | void PDC_scr_close(void); 75 | void PDC_scr_free(void); 76 | int PDC_scr_open(void); 77 | void PDC_set_keyboard_binary(bool); 78 | void PDC_transform_line(int, int, int, const chtype *); 79 | const char *PDC_sysname(void); 80 | 81 | /* Internal cross-module functions */ 82 | 83 | void PDC_init_atrtab(void); 84 | WINDOW *PDC_makelines(WINDOW *); 85 | WINDOW *PDC_makenew(int, int, int, int); 86 | int PDC_mouse_in_slk(int, int); 87 | void PDC_slk_free(void); 88 | void PDC_slk_initialize(void); 89 | void PDC_sync(WINDOW *); 90 | 91 | #ifdef PDC_WIDE 92 | int PDC_mbtowc(wchar_t *, const char *, size_t); 93 | size_t PDC_mbstowcs(wchar_t *, const char *, size_t); 94 | size_t PDC_wcstombs(char *, const wchar_t *, size_t); 95 | #endif 96 | 97 | #ifdef PDCDEBUG 98 | # define PDC_LOG(x) if (SP && SP->dbfp) PDC_debug x 99 | #else 100 | # define PDC_LOG(x) 101 | #endif 102 | 103 | /* Internal macros for attributes */ 104 | 105 | #ifndef max 106 | # define max(a,b) (((a) > (b)) ? (a) : (b)) 107 | #endif 108 | #ifndef min 109 | # define min(a,b) (((a) < (b)) ? (a) : (b)) 110 | #endif 111 | 112 | #define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor) 113 | 114 | #define PDC_CLICK_PERIOD 150 /* time to wait for a click, if 115 | not set by mouseinterval() */ 116 | #define PDC_COLOR_PAIRS 256 117 | #define PDC_MAXCOL 768 /* maximum possible COLORS; may be less */ 118 | 119 | #define _INBUFSIZ 512 /* size of terminal input buffer */ 120 | #define NUNGETCH 256 /* max # chars to ungetch() */ 121 | 122 | #endif /* __CURSES_INTERNALS__ */ 123 | -------------------------------------------------------------------------------- /include/pdcurses/panel.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------* 2 | * Panels for PDCurses * 3 | *----------------------------------------------------------------------*/ 4 | 5 | #ifndef __PDCURSES_PANEL_H__ 6 | #define __PDCURSES_PANEL_H__ 1 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | typedef struct panelobs 16 | { 17 | struct panelobs *above; 18 | struct panel *pan; 19 | } PANELOBS; 20 | 21 | typedef struct panel 22 | { 23 | WINDOW *win; 24 | int wstarty; 25 | int wendy; 26 | int wstartx; 27 | int wendx; 28 | struct panel *below; 29 | struct panel *above; 30 | const void *user; 31 | struct panelobs *obscure; 32 | } PANEL; 33 | 34 | PDCEX int bottom_panel(PANEL *pan); 35 | PDCEX int del_panel(PANEL *pan); 36 | PDCEX int hide_panel(PANEL *pan); 37 | PDCEX int move_panel(PANEL *pan, int starty, int startx); 38 | PDCEX PANEL *new_panel(WINDOW *win); 39 | PDCEX PANEL *panel_above(const PANEL *pan); 40 | PDCEX PANEL *panel_below(const PANEL *pan); 41 | PDCEX int panel_hidden(const PANEL *pan); 42 | PDCEX const void *panel_userptr(const PANEL *pan); 43 | PDCEX WINDOW *panel_window(const PANEL *pan); 44 | PDCEX int replace_panel(PANEL *pan, WINDOW *win); 45 | PDCEX int set_panel_userptr(PANEL *pan, const void *uptr); 46 | PDCEX int show_panel(PANEL *pan); 47 | PDCEX int top_panel(PANEL *pan); 48 | PDCEX void update_panels(void); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __PDCURSES_PANEL_H__ */ 55 | -------------------------------------------------------------------------------- /include/port.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "util.h" 4 | 5 | #ifdef _WIN32 6 | #include 7 | #define _TEXT(str) UTF8ToANSI((str)).c_str() 8 | #else 9 | #include 10 | #define _TEXT(str) str 11 | #endif 12 | -------------------------------------------------------------------------------- /include/status_bar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "win.h" 3 | #include "timer.h" 4 | #include 5 | #include 6 | #include "fund.h" 7 | 8 | namespace BigMoney { 9 | 10 | class StatusBar : Window{ 11 | public: 12 | StatusBar(int x, int y, int startx, int starty); 13 | ~StatusBar(); 14 | void Paint() override; 15 | bool MessageProc(const Msg &msg) override; 16 | private: 17 | std::string show_msg_; 18 | FundIncome fund_income_; 19 | Timer *timer_{nullptr}; 20 | std::atomic update_{false}; 21 | std::mutex msg_mutex_; 22 | }; 23 | } // namespace BigMoney 24 | -------------------------------------------------------------------------------- /include/timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "msg.h" 8 | #include 9 | #include 10 | 11 | 12 | namespace BigMoney { 13 | 14 | class TimerManager; 15 | 16 | class Timer { 17 | friend class TimerManager; 18 | typedef std::function TimeoutCallback; 19 | public: 20 | Timer(const TimeoutCallback &callback); 21 | ~Timer(); 22 | void Start(uint32_t milliseconds); 23 | void Stop(); 24 | private: 25 | std::atomic running_{false}; 26 | TimeoutCallback callback_; 27 | std::chrono::time_point start_time_; 28 | int timeout_{0}; 29 | }; 30 | 31 | class TimerManager : 32 | public sy::Singleton, public MsgReactor { 33 | public: 34 | void AddTimer(Timer *timer); 35 | void RemoveTimer(Timer *timer); 36 | bool MessageProc(const Msg &msg) override; 37 | void StartWork(); 38 | ~TimerManager(); 39 | private: 40 | std::unordered_set timers_; 41 | std::mutex timers_mutex_; 42 | std::atomic running_{false}; 43 | std::thread work_thread_; 44 | }; 45 | 46 | void StartTimerLoop(); 47 | } // namespace BigMoney 48 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define UPDATE_STATUS(format, ...) \ 7 | do {\ 8 | auto *buf = new std::vector(255);\ 9 | snprintf(buf->data(), buf->size(), (format), ##__VA_ARGS__);\ 10 | PostMsg({MsgType::kUpdateStatus, buf, nullptr});\ 11 | }while(0) 12 | 13 | 14 | #define JSON_GET(type, key, v, json)\ 15 | do {\ 16 | auto itr = (json).FindMember(key);\ 17 | if (itr != (json).MemberEnd()) {\ 18 | if (itr->value.Is##type()) {\ 19 | (v) = itr->value.Get##type();\ 20 | } else {\ 21 | assert(0 && "Type mismatch, get json value fail: "#key);\ 22 | }\ 23 | } else {\ 24 | assert(0 && "Cannot find key, get json value fail: "#key);\ 25 | }\ 26 | }while (0) 27 | 28 | #include 29 | 30 | std::string UTF8ToANSI(const std::string &str); 31 | 32 | 33 | #define FUND_DATA_URL "http://fundgz.1234567.com.cn/js/" 34 | 35 | inline std::string GenerateFundUrl(const std::string& code) { 36 | std::ostringstream os; 37 | os << FUND_DATA_URL << code << ".js"; 38 | return os.str(); 39 | } 40 | 41 | #include "fund.h" 42 | 43 | #define FUND_REAL_INCOME "http://hq.sinajs.cn/list=" 44 | 45 | inline std::string GenerateRealIncomeUrl(const std::vector &fund_list) { 46 | std::string url = FUND_REAL_INCOME; 47 | for (auto &fund : fund_list) { 48 | url.append("f_").append(fund.fund_code).append(","); 49 | } 50 | return url; 51 | } 52 | 53 | int StringWidth(const std::string &str) ; 54 | 55 | int FloatWidth(float f, const std::string &format); 56 | 57 | inline bool IsNumber(const std::string &str) { 58 | if (str.empty()) { 59 | return false; 60 | } 61 | for (auto ch : str) { 62 | if (ch > '9' || ch < '0') { 63 | return false; 64 | } 65 | } 66 | return true; 67 | } 68 | -------------------------------------------------------------------------------- /include/win.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "port.h" 3 | #include "msg.h" 4 | 5 | namespace BigMoney { 6 | class Window : public MsgReactor{ 7 | public: 8 | Window(int x = 0, int y = 0, int startx = 0, int starty = 0) 9 | : x_(x), 10 | y_(y), 11 | startx_(startx), 12 | starty_(starty) { 13 | win_ = newwin(y_, x_, starty_, startx_); 14 | } 15 | bool MessageProc(const Msg &msg) override { 16 | if (msg.msg_type == kPaint) { 17 | if (static_cast(msg.lparam) == this) { 18 | Paint(); 19 | return true; 20 | } 21 | } 22 | else if (msg.msg_type == kHiddenPop) { 23 | Update(); 24 | return false; 25 | } 26 | return false; 27 | } 28 | void UpdateNow() { 29 | Paint(); 30 | } 31 | void Update() { 32 | Msg msg{kPaint, static_cast(this), 0}; 33 | PostMsg(msg); 34 | } 35 | virtual void Paint() { }; 36 | virtual ~Window() { 37 | if (win_) { 38 | delwin(win_); 39 | } 40 | } 41 | 42 | protected: 43 | WINDOW *win_{nullptr}; 44 | int x_; 45 | int y_; 46 | int startx_; 47 | int starty_; 48 | }; 49 | } // namespace BigMoney 50 | -------------------------------------------------------------------------------- /src/colors.cc: -------------------------------------------------------------------------------- 1 | #include "colors.h" 2 | #include 3 | 4 | namespace BigMoney { 5 | 6 | void Init() { 7 | static bool is_init = false; 8 | if (!is_init) { 9 | start_color(); 10 | init_pair(kGreenBlack, COLOR_GREEN, COLOR_BLACK) ; 11 | init_pair(kRedBlack, COLOR_RED, COLOR_BLACK); 12 | init_pair(kWhiteBlue, COLOR_WHITE, COLOR_BLUE); 13 | is_init = true; 14 | } 15 | } 16 | 17 | int GetColorPair(Color color) { 18 | Init(); 19 | return COLOR_PAIR(color); 20 | } 21 | 22 | } // namespace BigMoney 23 | -------------------------------------------------------------------------------- /src/command_bar.cc: -------------------------------------------------------------------------------- 1 | #include "command_bar.h" 2 | #include 3 | #include 4 | #include "fund.h" 5 | #include 6 | 7 | 8 | namespace BigMoney { 9 | CommandBar::CommandBar(int x, int y, int startx, int starty) 10 | :Window(x, y, startx, starty){ 11 | } 12 | 13 | CommandBar::~CommandBar() { 14 | if (listen_thread_ && listen_thread_->joinable()) { 15 | listen_thread_->join(); 16 | } 17 | } 18 | void CommandBar::GetCommand() { 19 | is_listen_ = true; 20 | listen_thread_ = new std::thread([this]{ 21 | std::array input_buf; 22 | while(is_listen_) { 23 | wclear(win_); 24 | wgetnstr(win_, input_buf.data(), input_buf.size()); 25 | ParseCommand(input_buf.data()); 26 | } 27 | }); 28 | } 29 | 30 | void CommandBar::ParseCommand(const std::string &cmd) { 31 | if (cmd.empty()) { 32 | return; 33 | } 34 | std::istringstream is(cmd); 35 | std::string action; 36 | is >> action; 37 | if (action == "add" || action == "update") { 38 | std::string fund_id; 39 | float fund_share = 0; 40 | is >> fund_id >> fund_share; 41 | if (IsNumber(fund_id)) { 42 | Fund *fund = new Fund(); 43 | fund->fund_code = fund_id; 44 | fund->share = fund_share; 45 | Msg msg = {kUpdateFund, fund, nullptr}; 46 | PostMsg(msg); 47 | } 48 | } else if (action == "delete") { 49 | std::string *fund_id = new std::string(); 50 | is >> *fund_id; 51 | if (IsNumber(fund_id->c_str()) || *fund_id == "all") { 52 | Msg msg{kDeleteFund, fund_id, nullptr}; 53 | PostMsg(msg); 54 | } 55 | } else if (action == "reload" || action == "r") { 56 | PostMsg({kReloadFile, nullptr, nullptr}); 57 | } else if (action == "help" || action == "h") { 58 | PostMsg({kShowHelp, nullptr, nullptr}); 59 | } else if (action == "q") { 60 | PostMsg({kHiddenPop, nullptr, nullptr}); 61 | } else if (action == "quit") { 62 | Msg msg = {kQuit, nullptr, nullptr}; 63 | is_listen_ = false; 64 | PostMsg(msg); 65 | } else if (action == "pre" || action == "p") { 66 | PostMsg({kPrePage, nullptr, nullptr}); 67 | } else if (action == "next" || action == "n") { 68 | PostMsg({kNextPage, nullptr, nullptr}); 69 | } else { 70 | UPDATE_STATUS("无效命令: %s", cmd.c_str()); 71 | } 72 | } 73 | 74 | } // namespace BigMoney 75 | -------------------------------------------------------------------------------- /src/earn.cc: -------------------------------------------------------------------------------- 1 | #include "earn.h" 2 | #include "port.h" 3 | 4 | namespace BigMoney { 5 | 6 | Earn::Earn() { 7 | setlocale(LC_ALL, ""); 8 | #ifdef __APPLE__ 9 | setenv("TERM", "xterm-basic", 1); 10 | setenv("TERMINFO", "/usr/share/terminfo", 1); 11 | #endif 12 | initscr(); 13 | raw(); 14 | keypad(stdscr, TRUE); 15 | curs_set(0); 16 | cbreak(); 17 | int max_row = 0, max_col = 0; 18 | getmaxyx(stdscr, max_col, max_row); 19 | 20 | fund_board_ = new FundBoard(max_row, max_col - 2, 0, 0); 21 | int help_win_width = max_row * 0.6; 22 | int help_win_height = (max_col -2) * 0.6; 23 | int help_win_left = (max_row - help_win_width) / 2; 24 | int help_win_top = (max_col - help_win_height - 2) / 2; 25 | help_windows_ = new HelpWindow(help_win_width, 26 | help_win_height, help_win_left, help_win_top); 27 | status_bar_ = new StatusBar(max_row, 1, 0, max_col - 2); 28 | command_bar_ = new CommandBar(max_row, 1, 0, max_col - 1); 29 | command_bar_->GetCommand(); 30 | } 31 | 32 | Earn::~Earn() { 33 | endwin(); 34 | if (fund_board_) { 35 | delete fund_board_; 36 | } 37 | if (help_windows_) { 38 | delete help_windows_; 39 | } 40 | if (status_bar_) { 41 | delete status_bar_; 42 | } 43 | if (command_bar_) { 44 | delete command_bar_; 45 | } 46 | } 47 | 48 | } // namespace BigMoney 49 | -------------------------------------------------------------------------------- /src/help.cc: -------------------------------------------------------------------------------- 1 | #include "help.h" 2 | #include "colors.h" 3 | #include 4 | 5 | namespace BigMoney { 6 | 7 | static const std::array HELP_INFO = { 8 | "使用方法:", 9 | "\t添加/修改基金: \t\tupdate <基金编号> <持有份额>", 10 | "\t删除基金: \t\tdelete <基金编号>", 11 | "\t删除全部: \t\tdelete all", 12 | "\t重新加载: \t\treload", 13 | "\t上一页: \t\tpre", 14 | "\t下一页: \t\tnext", 15 | "\t关闭: \t\t\tq", 16 | "\t退出程序: \t\tquit", 17 | "\t帮助: \t\t\thelp" 18 | }; 19 | 20 | 21 | HelpWindow::HelpWindow(int x, int y, int startx, int starty) 22 | :Window(x, y, startx, starty){ 23 | } 24 | bool HelpWindow::MessageProc(const Msg& msg) { 25 | bool processed = false; 26 | if (msg.msg_type == kHiddenPop) { 27 | show_ = false; 28 | UpdateNow(); 29 | } 30 | else if (msg.msg_type == kShowHelp) { 31 | show_ = true; 32 | Update(); 33 | processed = true; 34 | } else { 35 | processed = Window::MessageProc(msg); 36 | } 37 | return processed; 38 | } 39 | 40 | void HelpWindow::Paint() { 41 | wclear(win_); 42 | if (show_) { 43 | wborder(win_, '|', '|', '-', '-', '+', '+', '+', '+'); 44 | int y_offset = 1; 45 | for (auto item : HELP_INFO) { 46 | mvwprintw(win_, y_offset, 1, _TEXT(item)); 47 | y_offset++; 48 | } 49 | mvwprintw(win_, y_ - 3, 1, GITHUB); 50 | mvwprintw(win_, y_ - 2, 1, "Version: %s", BIG_MONEY_VERSION); 51 | } 52 | wrefresh(win_); 53 | } 54 | } // namespace BigMoney 55 | -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "port.h" 3 | #include "msg.h" 4 | #include "earn.h" 5 | 6 | using namespace BigMoney; 7 | 8 | int main() { 9 | Earn earn; 10 | StartMainLoop(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/msg.cc: -------------------------------------------------------------------------------- 1 | #include "msg.h" 2 | #include 3 | #include "port.h" 4 | #include "timer.h" 5 | 6 | 7 | 8 | namespace BigMoney { 9 | 10 | bool MsgQueue::Enqueue(const Msg &msg) { 11 | std::lock_guard lock(mutex_); 12 | msg_queue_.push(msg); 13 | return true; 14 | } 15 | bool MsgQueue::Dequeue(Msg *msg) { 16 | std::lock_guard lock(mutex_); 17 | if (msg_queue_.empty()) { 18 | return false; 19 | } 20 | *msg = msg_queue_.front(); 21 | msg_queue_.pop(); 22 | return true; 23 | } 24 | bool MsgQueue::Empty() { 25 | std::lock_guard lock(mutex_); 26 | return msg_queue_.empty(); 27 | } 28 | 29 | MsgReactor::MsgReactor() { 30 | MsgManager::instance().AddReactor(this); 31 | } 32 | 33 | MsgReactor::~MsgReactor() { 34 | MsgManager::instance().RemoveReactor(this); 35 | } 36 | 37 | void MsgManager::AddReactor(MsgReactor *reactor) { 38 | std::lock_guard lock(reactors_mutex_); 39 | reactors_.insert(reactor); 40 | } 41 | 42 | void MsgManager::RemoveReactor(MsgReactor *reactor) { 43 | std::lock_guard lock(reactors_mutex_); 44 | reactors_.erase(reactor); 45 | } 46 | 47 | bool GetMsg(Msg *msg) { 48 | if (MsgManager::instance().QueueEmpty()) { 49 | return false; 50 | } 51 | return MsgManager::instance().Dequeue(msg); 52 | } 53 | 54 | bool PostMsg(const Msg &msg) { 55 | return MsgManager::instance().Enqueue(msg); 56 | } 57 | 58 | void MsgManager::StartMainLoop() { 59 | for(;;) { 60 | if(QueueEmpty()) { 61 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 62 | continue; 63 | } 64 | Msg msg; 65 | if (Dequeue(&msg)) { 66 | for (auto reactor : reactors_) { 67 | if (reactor->MessageProc(msg)) { 68 | break; 69 | } 70 | } 71 | if (msg.msg_type == kQuit) { 72 | break; 73 | } 74 | } 75 | 76 | } 77 | } 78 | 79 | void StartMainLoop() { 80 | StartTimerLoop(); 81 | MsgManager msn; 82 | MsgManager::instance().StartMainLoop(); 83 | } 84 | } // namespace BigMoney 85 | -------------------------------------------------------------------------------- /src/status_bar.cc: -------------------------------------------------------------------------------- 1 | #include "status_bar.h" 2 | #include "colors.h" 3 | #include "util.h" 4 | #include 5 | 6 | namespace BigMoney { 7 | 8 | StatusBar::StatusBar(int x, int y, int startx, int starty) 9 | :Window(x, y, startx, starty){ 10 | wbkgd(win_, GetColorPair(kWhiteBlue)); 11 | Update(); 12 | timer_ = new Timer([this]{ 13 | if (!update_) { 14 | std::lock_guard lock(msg_mutex_); 15 | show_msg_.clear(); 16 | Update(); 17 | } 18 | update_ = false; 19 | }); 20 | timer_->Start(3000); 21 | } 22 | 23 | StatusBar::~StatusBar() { 24 | if (timer_) { 25 | timer_->Stop(); 26 | } 27 | delete timer_; 28 | } 29 | void StatusBar::Paint() { 30 | update_ = true; 31 | wclear(win_); 32 | std::vector output_buf(x_ + 2); 33 | msg_mutex_.lock(); 34 | wprintw(win_, _TEXT(show_msg_.c_str())); 35 | msg_mutex_.unlock(); 36 | snprintf(output_buf.data(), output_buf.size(), 37 | " 估算收益: %.2f 估算总值: %.2f ", 38 | fund_income_.income, fund_income_.sum); 39 | int width = StringWidth(output_buf.data()); 40 | mvwprintw(win_, 0, x_ - width, _TEXT(output_buf.data())); 41 | wrefresh(win_); 42 | } 43 | 44 | bool StatusBar::MessageProc(const Msg &msg) { 45 | bool processed = false; 46 | if (msg.msg_type == kUpdateIncome) { 47 | auto fund_income = static_cast(msg.lparam); 48 | fund_income_ = *fund_income; 49 | delete fund_income; 50 | Update(); 51 | processed = true; 52 | } else if (msg.msg_type == kUpdateStatus){ 53 | auto *str = reinterpret_cast*>(msg.lparam); 54 | msg_mutex_.lock(); 55 | show_msg_ = str->data(); 56 | msg_mutex_.unlock(); 57 | delete str; 58 | Update(); 59 | processed = true; 60 | } else { 61 | processed = Window::MessageProc(msg); 62 | } 63 | return processed; 64 | } 65 | 66 | } // namespace BigMoney 67 | -------------------------------------------------------------------------------- /src/timer.cc: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std::chrono; 7 | 8 | namespace BigMoney { 9 | 10 | Timer::Timer(const TimeoutCallback &callback) 11 | : callback_(callback){ 12 | TimerManager::instance().AddTimer(this); 13 | } 14 | void Timer::Start(uint32_t milliseconds) { 15 | running_ = true; 16 | timeout_ = milliseconds; 17 | start_time_ = system_clock::now(); 18 | } 19 | void Timer::Stop() { 20 | running_ = false; 21 | } 22 | 23 | Timer::~Timer() { 24 | TimerManager::instance().RemoveTimer(this); 25 | } 26 | 27 | void TimerManager::AddTimer(Timer *timer) { 28 | std::lock_guard lock(timers_mutex_); 29 | timers_.insert(timer); 30 | } 31 | void TimerManager::RemoveTimer(Timer *timer) { 32 | std::lock_guard lock(timers_mutex_); 33 | timers_.erase(timer); 34 | } 35 | 36 | void TimerManager::StartWork() { 37 | running_ = true; 38 | work_thread_ = std::thread([this] { 39 | while (running_) { 40 | timers_mutex_.lock(); 41 | auto now = system_clock::now(); 42 | for (auto timer : timers_) { 43 | if (timer->running_) { 44 | auto elapsed = duration_cast(now - timer->start_time_).count(); 45 | if (elapsed > timer->timeout_) { 46 | timer->callback_(); 47 | timer->start_time_ = now; 48 | } 49 | } 50 | } 51 | timers_mutex_.unlock(); 52 | std::this_thread::sleep_for(milliseconds(200)); 53 | } 54 | }); 55 | } 56 | 57 | TimerManager::~TimerManager() { 58 | if (work_thread_.joinable()) { 59 | work_thread_.join(); 60 | } 61 | } 62 | 63 | bool TimerManager::MessageProc(const Msg &msg) { 64 | if (msg.msg_type == kQuit) { 65 | running_ = false; 66 | } 67 | return false; 68 | } 69 | 70 | void StartTimerLoop() { 71 | TimerManager::instance().StartWork(); 72 | } 73 | 74 | } // namespace BigMoney 75 | -------------------------------------------------------------------------------- /src/util.cc: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | #include 3 | #include 4 | #include "port.h" 5 | 6 | 7 | int StringWidth(const std::string &str) { 8 | int width = 0; 9 | for (size_t i = 0; i < str.size();){ 10 | char ch = str[i]; 11 | if (!(ch & 0x80)) { 12 | width += 1; 13 | i ++; 14 | } else { 15 | width += 2; 16 | if ((ch & 0xE0) == 0xC0) { 17 | i += 2; 18 | } else if ((ch & 0xF0) == 0xE0) { 19 | i += 3; 20 | } else if ((ch & 0xF8) == 0xF0) { 21 | i += 4; 22 | } else { 23 | return -1; 24 | } 25 | } 26 | } 27 | return width; 28 | } 29 | 30 | int FloatWidth(float f, const std::string &format) { 31 | std::array format_buf; 32 | snprintf(format_buf.data(), format_buf.size(), format.c_str(), f); 33 | return strlen(format_buf.data()); 34 | } 35 | 36 | 37 | #ifdef _WIN32 38 | #include 39 | std::string UTF8ToANSI(const std::string &str) { 40 | BSTR bstr; 41 | char *psz = nullptr; 42 | int length; 43 | char * utf8_str = nullptr; 44 | 45 | length = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), nullptr, 0); 46 | bstr = SysAllocStringLen(nullptr, length); 47 | 48 | MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), bstr, length); 49 | 50 | length = WideCharToMultiByte(CP_ACP, 0, bstr, -1, nullptr, 0, nullptr, nullptr); 51 | utf8_str = new char[length]; 52 | 53 | WideCharToMultiByte(CP_ACP, 0, bstr, -1, utf8_str, length, nullptr, nullptr); 54 | SysFreeString(bstr); 55 | 56 | std::string ret(utf8_str); 57 | delete[] utf8_str; 58 | return ret; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /test.json: -------------------------------------------------------------------------------- 1 | { 2 | "test":"ok" 3 | } --------------------------------------------------------------------------------