enabled compiler flags "-pedantic", "-Wall", …

… "-Werror" and "-Wextra". Corrected some issues resulting from the
switch.
This commit is contained in:
Christian Burger 2022-05-22 00:02:37 +02:00
parent 4b709c92fb
commit 10c3edb5d9
8 changed files with 319 additions and 255 deletions

View file

@ -56,7 +56,8 @@
"pointers": "cpp",
"list": "cpp",
"condition_variable": "cpp",
"mutex": "cpp"
"mutex": "cpp",
"gsl_util": "cpp"
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp.default.includePath": [

View file

@ -17,6 +17,9 @@ add_library(kNCurses Window.cpp PtyWindow.cpp SingleUserInput.cpp Debug.cpp
TilingWindowManager.cpp VerticalTilingWindowManager.cpp
HorizontalTilingWindowManager.cpp)
### let's be annoyingly pedantic
target_compile_options(kNCurses PRIVATE "-Wall" "-Wextra" "-Werror" "-pedantic")
### path to own system includes
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/include")
@ -42,6 +45,7 @@ target_link_libraries(kNCurses Threads::Threads)
### demo application
add_executable(kNCursesDemoApp main.cpp DemoApp.cpp)
target_compile_options(kNCursesDemoApp PRIVATE "-Wall" "-Wextra" "-Werror" "-pedantic")
target_link_libraries(kNCursesDemoApp kNCurses)
### installation and packaging
@ -57,7 +61,7 @@ set_target_properties(kNCurses PROPERTIES
PUBLIC_HEADER "${KNCURSES_PUBLIC_HEADERS}"
VERSION "${CMAKE_PROJECT_VERSION}")
include(GNUInstallDirs)
install(TARGETS kNCurses ARCHIVE
install(TARGETS kNCurses kNCursesDemoApp ARCHIVE
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kNCurses/")
set(CPACK_PROJECT_NAME ${PROJECT_NAME})

446
Debug.cpp
View file

@ -97,10 +97,10 @@ namespace krikkel
{
std::string result;
for(int index = 0; index < length / sizeof(long); ++index)
for(size_t index = 0; index < length / sizeof(long); ++index)
{
long datum = ptrace(PTRACE_PEEKDATA, shellPid, ((char *) data) + index * sizeof(long));
if(length == -1)
if(length == (size_t) -1)
{
size_t datumLength = strnlen((char *) &datum, sizeof(long));
result += string((char *) &datum, datumLength);
@ -139,7 +139,7 @@ namespace krikkel
{
case SYS_read:
if(returnedFromSysCall)
message += (result == -1 ? "-1" : std::to_string((size_t) result)) + " = ";
message += (result == (unsigned long long) -1 ? "-1" : std::to_string((size_t) result)) + " = ";
message += sysCallName
+ "(" + std::to_string((int) firstArgument)
+ ", \"" + (returnedFromSysCall ? __debug_make_bytes_printable(peekData(shellPid, (char *) secondArgument, (size_t) min<unsigned long long>(thirdArgument, maxStringLength))) : "")
@ -149,7 +149,7 @@ namespace krikkel
break;
case SYS_write:
if(returnedFromSysCall)
message += (result == -1 ? "-1" : std::to_string((size_t) result)) + " = ";
message += (result == (unsigned long long) -1 ? "-1" : std::to_string((size_t) result)) + " = ";
message += sysCallName
+ "(" + std::to_string((int) firstArgument)
+ ", \"" + __debug_make_bytes_printable(peekData(shellPid, (char *) secondArgument, (size_t) min<unsigned long long>(thirdArgument, maxStringLength)))
@ -234,7 +234,7 @@ namespace krikkel
break;
*/ default:
if(returnedFromSysCall)
message += (result == -1 ? "-1" : std::to_string(result)) + " = ";
message += (result == (unsigned long long) -1 ? "-1" : std::to_string(result)) + " = ";
message += sysCallName
+ "(" + formatToAddress(firstArgument)
+ ", " + formatToAddress(secondArgument)
@ -253,224 +253,224 @@ namespace krikkel
return debug;
}
const char *Debug::syscalls[MAX_NUMBER_OF_SYSCALLS] = {[0] = "read",[1] = "write",
[2] = "open",[3] = "close",
[4] = "stat",[5] = "fstat",
[6] = "lstat",[7] = "poll",
[8] = "lseek",[9] = "mmap",
[10] = "mprotect",[11] = "munmap",
[12] = "brk",[13] = "rt_sigaction",
[14] = "rt_sigprocmask",[15] = "rt_sigreturn",
[16] = "ioctl",[17] = "pread64",
[18] = "pwrite64",[19] = "readv",
[20] = "writev",[21] = "access",
[22] = "pipe",[23] = "select",
[24] = "sched_yield",[25] = "mremap",
[26] = "msync",[27] = "mincore",
[28] = "madvise",[29] = "shmget",
[30] = "shmat",[31] = "shmctl",
[32] = "dup",[33] = "dup2",
[34] = "pause",[35] = "nanosleep",
[36] = "getitimer",[37] = "alarm",
[38] = "setitimer",[39] = "getpid",
[40] = "sendfile",[41] = "socket",
[42] = "connect",[43] = "accept",
[44] = "sendto",[45] = "recvfrom",
[46] = "sendmsg",[47] = "recvmsg",
[48] = "shutdown",[49] = "bind",
[50] = "listen",[51] = "getsockname",
[52] = "getpeername",[53] = "socketpair",
[54] = "setsockopt",[55] = "getsockopt",
[56] = "clone",[57] = "fork",
[58] = "vfork",[59] = "execve",
[60] = "exit",[61] = "wait4",
[62] = "kill",[63] = "uname",
[64] = "semget",[65] = "semop",
[66] = "semctl",[67] = "shmdt",
[68] = "msgget",[69] = "msgsnd",
[70] = "msgrcv",[71] = "msgctl",
[72] = "fcntl",[73] = "flock",
[74] = "fsync",[75] = "fdatasync",
[76] = "truncate",[77] = "ftruncate",
[78] = "getdents",[79] = "getcwd",
[80] = "chdir",[81] = "fchdir",
[82] = "rename",[83] = "mkdir",
[84] = "rmdir",[85] = "creat",
[86] = "link",[87] = "unlink",
[88] = "symlink",[89] = "readlink",
[90] = "chmod",[91] = "fchmod",
[92] = "chown",[93] = "fchown",
[94] = "lchown",[95] = "umask",
[96] = "gettimeofday",[97] = "getrlimit",
[98] = "getrusage",[99] = "sysinfo",
[100] = "times",[101] = "ptrace",
[102] = "getuid",[103] = "syslog",
[104] = "getgid",[105] = "setuid",
[106] = "setgid",[107] = "geteuid",
[108] = "getegid",[109] = "setpgid",
[110] = "getppid",[111] = "getpgrp",
[112] = "setsid",[113] = "setreuid",
[114] = "setregid",[115] = "getgroups",
[116] = "setgroups",[117] = "setresuid",
[118] = "getresuid",[119] = "setresgid",
[120] = "getresgid",[121] = "getpgid",
[122] = "setfsuid",[123] = "setfsgid",
[124] = "getsid",[125] = "capget",
[126] = "capset",[127] = "rt_sigpending",
[128] = "rt_sigtimedwait",[129] = "rt_sigqueueinfo",
[130] = "rt_sigsuspend",[131] = "sigaltstack",
[132] = "utime",[133] = "mknod",
[134] = "uselib",[135] = "personality",
[136] = "ustat",[137] = "statfs",
[138] = "fstatfs",[139] = "sysfs",
[140] = "getpriority",[141] = "setpriority",
[142] = "sched_setparam",[143] = "sched_getparam",
[144] = "sched_setscheduler",[145] = "sched_getscheduler",
[146] = "sched_get_priority_max",[147] = "sched_get_priority_min",
[148] = "sched_rr_get_interval",[149] = "mlock",
[150] = "munlock",[151] = "mlockall",
[152] = "munlockall",[153] = "vhangup",
[154] = "modify_ldt",[155] = "pivot_root",
[156] = "",[157] = "prctl",
[158] = "arch_prctl",[159] = "adjtimex",
[160] = "setrlimit",[161] = "chroot",
[162] = "sync",[163] = "acct",
[164] = "settimeofday",[165] = "mount",
[166] = "",[167] = "swapon",
[168] = "swapoff",[169] = "reboot",
[170] = "sethostname",[171] = "setdomainname",
[172] = "iopl",[173] = "ioperm",
[174] = "",[175] = "init_module",
[176] = "delete_module",[177] = "",
[178] = "",[179] = "quotactl",
[180] = "",[181] = "",
[182] = "",[183] = "",
[184] = "",[185] = "",
[186] = "gettid",[187] = "readahead",
[188] = "setxattr",[189] = "lsetxattr",
[190] = "fsetxattr",[191] = "getxattr",
[192] = "lgetxattr",[193] = "fgetxattr",
[194] = "listxattr",[195] = "llistxattr",
[196] = "flistxattr",[197] = "removexattr",
[198] = "lremovexattr",[199] = "fremovexattr",
[200] = "tkill",[201] = "time",
[202] = "futex",[203] = "sched_setaffinity",
[204] = "sched_getaffinity",[205] = "set_thread_area",
[206] = "io_setup",[207] = "io_destroy",
[208] = "io_getevents",[209] = "io_submit",
[210] = "io_cancel",[211] = "get_thread_area",
[212] = "",[213] = "epoll_create",
[214] = "",[215] = "",
[216] = "remap_file_pages",[217] = "getdents64",
[218] = "set_tid_address",[219] = "restart_syscall",
[220] = "semtimedop",[221] = "fadvise64",
[222] = "timer_create",[223] = "timer_settime",
[224] = "timer_gettime",[225] = "timer_getoverrun",
[226] = "timer_delete",[227] = "clock_settime",
[228] = "clock_gettime",[229] = "clock_getres",
[230] = "clock_nanosleep",[231] = "exit_group",
[232] = "epoll_wait",[233] = "epoll_ctl",
[234] = "tgkill",[235] = "utimes",
[236] = "",[237] = "mbind",
[238] = "set_mempolicy",[239] = "get_mempolicy",
[240] = "mq_open",[241] = "mq_unlink",
[242] = "mq_timedsend",[243] = "mq_timedreceive",
[244] = "mq_notify",[245] = "mq_getsetattr",
[246] = "kexec_load",[247] = "waitid",
[248] = "add_key",[249] = "request_key",
[250] = "keyctl",[251] = "ioprio_set",
[252] = "ioprio_get",[253] = "inotify_init",
[254] = "inotify_add_watch",[255] = "inotify_rm_watch",
[256] = "migrate_pages",[257] = "openat",
[258] = "mkdirat",[259] = "mknodat",
[260] = "fchownat",[261] = "futimesat",
[262] = "newfstatat",[263] = "unlinkat",
[264] = "renameat",[265] = "linkat",
[266] = "symlinkat",[267] = "readlinkat",
[268] = "fchmodat",[269] = "faccessat",
[270] = "pselect6",[271] = "ppoll",
[272] = "unshare",[273] = "set_robust_list",
[274] = "get_robust_list",[275] = "splice",
[276] = "tee",[277] = "sync_file_range",
[278] = "vmsplice",[279] = "move_pages",
[280] = "utimensat",[281] = "epoll_pwait",
[282] = "signalfd",[283] = "timerfd_create",
[284] = "eventfd",[285] = "fallocate",
[286] = "timerfd_settime",[287] = "timerfd_gettime",
[288] = "accept4",[289] = "signalfd4",
[290] = "eventfd2",[291] = "epoll_create1",
[292] = "dup3",[293] = "pipe2",
[294] = "inotify_init1",[295] = "preadv",
[296] = "pwritev",[297] = "rt_tgsigqueueinfo",
[298] = "perf_event_open",[299] = "recvmmsg",
[300] = "fanotify_init",[301] = "fanotify_mark",
[302] = "prlimit64",[303] = "name_to_handle_at",
[304] = "open_by_handle_at",[305] = "clock_adjtime",
[306] = "syncfs",[307] = "sendmmsg",
[308] = "setns",[309] = "getcpu",
[310] = "process_vm_readv",[311] = "process_vm_writev",
[312] = "kcmp",[313] = "finit_module",
[314] = "sched_setattr",[315] = "sched_getattr",
[316] = "renameat2",[317] = "seccomp",
[318] = "getrandom",[319] = "memfd_create",
[320] = "kexec_file_load",[321] = "bpf",
[322] = "execveat",[323] = "userfaultfd",
[324] = "membarrier",[325] = "mlock2",
[326] = "copy_file_range",[327] = "preadv2",
[328] = "pwritev2",[329] = "pkey_mprotect",
[330] = "pkey_alloc",[331] = "pkey_free",
[332] = "statx",[333] = "io_pgetevents",
[334] = "rseq",[335] = "",
[336] = "",[337] = "",
[338] = "",[339] = "",
[340] = "",[341] = "",
[342] = "",[343] = "",
[344] = "",[345] = "",
[346] = "",[347] = "",
[348] = "",[349] = "",
[350] = "",[351] = "",
[352] = "",[353] = "",
[354] = "",[355] = "",
[356] = "",[357] = "",
[358] = "",[359] = "",
[360] = "",[361] = "",
[362] = "",[363] = "",
[364] = "",[365] = "",
[366] = "",[367] = "",
[368] = "",[369] = "",
[370] = "",[371] = "",
[372] = "",[373] = "",
[374] = "",[375] = "",
[376] = "",[377] = "",
[378] = "",[379] = "",
[380] = "",[381] = "",
[382] = "",[383] = "",
[384] = "",[385] = "",
[386] = "",[387] = "",
[388] = "",[389] = "",
[390] = "",[391] = "",
[392] = "",[393] = "",
[394] = "",[395] = "",
[396] = "",[397] = "",
[398] = "",[399] = "",
[400] = "",[401] = "",
[402] = "",[403] = "",
[404] = "",[405] = "",
[406] = "",[407] = "",
[408] = "",[409] = "",
[410] = "",[411] = "",
[412] = "",[413] = "",
[414] = "",[415] = "",
[416] = "",[417] = "",
[418] = "",[419] = "",
[420] = "",[421] = "",
[422] = "",[423] = "",
[424] = "pidfd_send_signal",[425] = "io_uring_setup",
[426] = "io_uring_enter",[427] = "io_uring_register",
[428] = "open_tree",[429] = "move_mount",
[430] = "fsopen",[431] = "fsconfig",
[432] = "fsmount",[433] = "fspick",
[434] = "pidfd_open",[435] = "clone3" };
const char *Debug::syscalls[MAX_NUMBER_OF_SYSCALLS] = {/*[0] =*/ "read",/*[1] =*/ "write",
/*[2] =*/ "open",/*[3] =*/ "close",
/*[4] =*/ "stat",/*[5] =*/ "fstat",
/*[6] =*/ "lstat",/*[7] =*/ "poll",
/*[8] =*/ "lseek",/*[9] =*/ "mmap",
/*[10] =*/ "mprotect",/*[11] =*/ "munmap",
/*[12] =*/ "brk",/*[13] =*/ "rt_sigaction",
/*[14] =*/ "rt_sigprocmask",/*[15] =*/ "rt_sigreturn",
/*[16] =*/ "ioctl",/*[17] =*/ "pread64",
/*[18] =*/ "pwrite64",/*[19] =*/ "readv",
/*[20] =*/ "writev",/*[21] =*/ "access",
/*[22] =*/ "pipe",/*[23] =*/ "select",
/*[24] =*/ "sched_yield",/*[25] =*/ "mremap",
/*[26] =*/ "msync",/*[27] =*/ "mincore",
/*[28] =*/ "madvise",/*[29] =*/ "shmget",
/*[30] =*/ "shmat",/*[31] =*/ "shmctl",
/*[32] =*/ "dup",/*[33] =*/ "dup2",
/*[34] =*/ "pause",/*[35] =*/ "nanosleep",
/*[36] =*/ "getitimer",/*[37] =*/ "alarm",
/*[38] =*/ "setitimer",/*[39] =*/ "getpid",
/*[40] =*/ "sendfile",/*[41] =*/ "socket",
/*[42] =*/ "connect",/*[43] =*/ "accept",
/*[44] =*/ "sendto",/*[45] =*/ "recvfrom",
/*[46] =*/ "sendmsg",/*[47] =*/ "recvmsg",
/*[48] =*/ "shutdown",/*[49] =*/ "bind",
/*[50] =*/ "listen",/*[51] =*/ "getsockname",
/*[52] =*/ "getpeername",/*[53] =*/ "socketpair",
/*[54] =*/ "setsockopt",/*[55] =*/ "getsockopt",
/*[56] =*/ "clone",/*[57] =*/ "fork",
/*[58] =*/ "vfork",/*[59] =*/ "execve",
/*[60] =*/ "exit",/*[61] =*/ "wait4",
/*[62] =*/ "kill",/*[63] =*/ "uname",
/*[64] =*/ "semget",/*[65] =*/ "semop",
/*[66] =*/ "semctl",/*[67] =*/ "shmdt",
/*[68] =*/ "msgget",/*[69] =*/ "msgsnd",
/*[70] =*/ "msgrcv",/*[71] =*/ "msgctl",
/*[72] =*/ "fcntl",/*[73] =*/ "flock",
/*[74] =*/ "fsync",/*[75] =*/ "fdatasync",
/*[76] =*/ "truncate",/*[77] =*/ "ftruncate",
/*[78] =*/ "getdents",/*[79] =*/ "getcwd",
/*[80] =*/ "chdir",/*[81] =*/ "fchdir",
/*[82] =*/ "rename",/*[83] =*/ "mkdir",
/*[84] =*/ "rmdir",/*[85] =*/ "creat",
/*[86] =*/ "link",/*[87] =*/ "unlink",
/*[88] =*/ "symlink",/*[89] =*/ "readlink",
/*[90] =*/ "chmod",/*[91] =*/ "fchmod",
/*[92] =*/ "chown",/*[93] =*/ "fchown",
/*[94] =*/ "lchown",/*[95] =*/ "umask",
/*[96] =*/ "gettimeofday",/*[97] =*/ "getrlimit",
/*[98] =*/ "getrusage",/*[99] =*/ "sysinfo",
/*[100] =*/ "times",/*[101] =*/ "ptrace",
/*[102] =*/ "getuid",/*[103] =*/ "syslog",
/*[104] =*/ "getgid",/*[105] =*/ "setuid",
/*[106] =*/ "setgid",/*[107] =*/ "geteuid",
/*[108] =*/ "getegid",/*[109] =*/ "setpgid",
/*[110] =*/ "getppid",/*[111] =*/ "getpgrp",
/*[112] =*/ "setsid",/*[113] =*/ "setreuid",
/*[114] =*/ "setregid",/*[115] =*/ "getgroups",
/*[116] =*/ "setgroups",/*[117] =*/ "setresuid",
/*[118] =*/ "getresuid",/*[119] =*/ "setresgid",
/*[120] =*/ "getresgid",/*[121] =*/ "getpgid",
/*[122] =*/ "setfsuid",/*[123] =*/ "setfsgid",
/*[124] =*/ "getsid",/*[125] =*/ "capget",
/*[126] =*/ "capset",/*[127] =*/ "rt_sigpending",
/*[128] =*/ "rt_sigtimedwait",/*[129] =*/ "rt_sigqueueinfo",
/*[130] =*/ "rt_sigsuspend",/*[131] =*/ "sigaltstack",
/*[132] =*/ "utime",/*[133] =*/ "mknod",
/*[134] =*/ "uselib",/*[135] =*/ "personality",
/*[136] =*/ "ustat",/*[137] =*/ "statfs",
/*[138] =*/ "fstatfs",/*[139] =*/ "sysfs",
/*[140] =*/ "getpriority",/*[141] =*/ "setpriority",
/*[142] =*/ "sched_setparam",/*[143] =*/ "sched_getparam",
/*[144] =*/ "sched_setscheduler",/*[145] =*/ "sched_getscheduler",
/*[146] =*/ "sched_get_priority_max",/*[147] =*/ "sched_get_priority_min",
/*[148] =*/ "sched_rr_get_interval",/*[149] =*/ "mlock",
/*[150] =*/ "munlock",/*[151] =*/ "mlockall",
/*[152] =*/ "munlockall",/*[153] =*/ "vhangup",
/*[154] =*/ "modify_ldt",/*[155] =*/ "pivot_root",
/*[156] =*/ "",/*[157] =*/ "prctl",
/*[158] =*/ "arch_prctl",/*[159] =*/ "adjtimex",
/*[160] =*/ "setrlimit",/*[161] =*/ "chroot",
/*[162] =*/ "sync",/*[163] =*/ "acct",
/*[164] =*/ "settimeofday",/*[165] =*/ "mount",
/*[166] =*/ "",/*[167] =*/ "swapon",
/*[168] =*/ "swapoff",/*[169] =*/ "reboot",
/*[170] =*/ "sethostname",/*[171] =*/ "setdomainname",
/*[172] =*/ "iopl",/*[173] =*/ "ioperm",
/*[174] =*/ "",/*[175] =*/ "init_module",
/*[176] =*/ "delete_module",/*[177] =*/ "",
/*[178] =*/ "",/*[179] =*/ "quotactl",
/*[180] =*/ "",/*[181] =*/ "",
/*[182] =*/ "",/*[183] =*/ "",
/*[184] =*/ "",/*[185] =*/ "",
/*[186] =*/ "gettid",/*[187] =*/ "readahead",
/*[188] =*/ "setxattr",/*[189] =*/ "lsetxattr",
/*[190] =*/ "fsetxattr",/*[191] =*/ "getxattr",
/*[192] =*/ "lgetxattr",/*[193] =*/ "fgetxattr",
/*[194] =*/ "listxattr",/*[195] =*/ "llistxattr",
/*[196] =*/ "flistxattr",/*[197] =*/ "removexattr",
/*[198] =*/ "lremovexattr",/*[199] =*/ "fremovexattr",
/*[200] =*/ "tkill",/*[201] =*/ "time",
/*[202] =*/ "futex",/*[203] =*/ "sched_setaffinity",
/*[204] =*/ "sched_getaffinity",/*[205] =*/ "set_thread_area",
/*[206] =*/ "io_setup",/*[207] =*/ "io_destroy",
/*[208] =*/ "io_getevents",/*[209] =*/ "io_submit",
/*[210] =*/ "io_cancel",/*[211] =*/ "get_thread_area",
/*[212] =*/ "",/*[213] =*/ "epoll_create",
/*[214] =*/ "",/*[215] =*/ "",
/*[216] =*/ "remap_file_pages",/*[217] =*/ "getdents64",
/*[218] =*/ "set_tid_address",/*[219] =*/ "restart_syscall",
/*[220] =*/ "semtimedop",/*[221] =*/ "fadvise64",
/*[222] =*/ "timer_create",/*[223] =*/ "timer_settime",
/*[224] =*/ "timer_gettime",/*[225] =*/ "timer_getoverrun",
/*[226] =*/ "timer_delete",/*[227] =*/ "clock_settime",
/*[228] =*/ "clock_gettime",/*[229] =*/ "clock_getres",
/*[230] =*/ "clock_nanosleep",/*[231] =*/ "exit_group",
/*[232] =*/ "epoll_wait",/*[233] =*/ "epoll_ctl",
/*[234] =*/ "tgkill",/*[235] =*/ "utimes",
/*[236] =*/ "",/*[237] =*/ "mbind",
/*[238] =*/ "set_mempolicy",/*[239] =*/ "get_mempolicy",
/*[240] =*/ "mq_open",/*[241] =*/ "mq_unlink",
/*[242] =*/ "mq_timedsend",/*[243] =*/ "mq_timedreceive",
/*[244] =*/ "mq_notify",/*[245] =*/ "mq_getsetattr",
/*[246] =*/ "kexec_load",/*[247] =*/ "waitid",
/*[248] =*/ "add_key",/*[249] =*/ "request_key",
/*[250] =*/ "keyctl",/*[251] =*/ "ioprio_set",
/*[252] =*/ "ioprio_get",/*[253] =*/ "inotify_init",
/*[254] =*/ "inotify_add_watch",/*[255] =*/ "inotify_rm_watch",
/*[256] =*/ "migrate_pages",/*[257] =*/ "openat",
/*[258] =*/ "mkdirat",/*[259] =*/ "mknodat",
/*[260] =*/ "fchownat",/*[261] =*/ "futimesat",
/*[262] =*/ "newfstatat",/*[263] =*/ "unlinkat",
/*[264] =*/ "renameat",/*[265] =*/ "linkat",
/*[266] =*/ "symlinkat",/*[267] =*/ "readlinkat",
/*[268] =*/ "fchmodat",/*[269] =*/ "faccessat",
/*[270] =*/ "pselect6",/*[271] =*/ "ppoll",
/*[272] =*/ "unshare",/*[273] =*/ "set_robust_list",
/*[274] =*/ "get_robust_list",/*[275] =*/ "splice",
/*[276] =*/ "tee",/*[277] =*/ "sync_file_range",
/*[278] =*/ "vmsplice",/*[279] =*/ "move_pages",
/*[280] =*/ "utimensat",/*[281] =*/ "epoll_pwait",
/*[282] =*/ "signalfd",/*[283] =*/ "timerfd_create",
/*[284] =*/ "eventfd",/*[285] =*/ "fallocate",
/*[286] =*/ "timerfd_settime",/*[287] =*/ "timerfd_gettime",
/*[288] =*/ "accept4",/*[289] =*/ "signalfd4",
/*[290] =*/ "eventfd2",/*[291] =*/ "epoll_create1",
/*[292] =*/ "dup3",/*[293] =*/ "pipe2",
/*[294] =*/ "inotify_init1",/*[295] =*/ "preadv",
/*[296] =*/ "pwritev",/*[297] =*/ "rt_tgsigqueueinfo",
/*[298] =*/ "perf_event_open",/*[299] =*/ "recvmmsg",
/*[300] =*/ "fanotify_init",/*[301] =*/ "fanotify_mark",
/*[302] =*/ "prlimit64",/*[303] =*/ "name_to_handle_at",
/*[304] =*/ "open_by_handle_at",/*[305] =*/ "clock_adjtime",
/*[306] =*/ "syncfs",/*[307] =*/ "sendmmsg",
/*[308] =*/ "setns",/*[309] =*/ "getcpu",
/*[310] =*/ "process_vm_readv",/*[311] =*/ "process_vm_writev",
/*[312] =*/ "kcmp",/*[313] =*/ "finit_module",
/*[314] =*/ "sched_setattr",/*[315] =*/ "sched_getattr",
/*[316] =*/ "renameat2",/*[317] =*/ "seccomp",
/*[318] =*/ "getrandom",/*[319] =*/ "memfd_create",
/*[320] =*/ "kexec_file_load",/*[321] =*/ "bpf",
/*[322] =*/ "execveat",/*[323] =*/ "userfaultfd",
/*[324] =*/ "membarrier",/*[325] =*/ "mlock2",
/*[326] =*/ "copy_file_range",/*[327] =*/ "preadv2",
/*[328] =*/ "pwritev2",/*[329] =*/ "pkey_mprotect",
/*[330] =*/ "pkey_alloc",/*[331] =*/ "pkey_free",
/*[332] =*/ "statx",/*[333] =*/ "io_pgetevents",
/*[334] =*/ "rseq",/*[335] =*/ "",
/*[336] =*/ "",/*[337] =*/ "",
/*[338] =*/ "",/*[339] =*/ "",
/*[340] =*/ "",/*[341] =*/ "",
/*[342] =*/ "",/*[343] =*/ "",
/*[344] =*/ "",/*[345] =*/ "",
/*[346] =*/ "",/*[347] =*/ "",
/*[348] =*/ "",/*[349] =*/ "",
/*[350] =*/ "",/*[351] =*/ "",
/*[352] =*/ "",/*[353] =*/ "",
/*[354] =*/ "",/*[355] =*/ "",
/*[356] =*/ "",/*[357] =*/ "",
/*[358] =*/ "",/*[359] =*/ "",
/*[360] =*/ "",/*[361] =*/ "",
/*[362] =*/ "",/*[363] =*/ "",
/*[364] =*/ "",/*[365] =*/ "",
/*[366] =*/ "",/*[367] =*/ "",
/*[368] =*/ "",/*[369] =*/ "",
/*[370] =*/ "",/*[371] =*/ "",
/*[372] =*/ "",/*[373] =*/ "",
/*[374] =*/ "",/*[375] =*/ "",
/*[376] =*/ "",/*[377] =*/ "",
/*[378] =*/ "",/*[379] =*/ "",
/*[380] =*/ "",/*[381] =*/ "",
/*[382] =*/ "",/*[383] =*/ "",
/*[384] =*/ "",/*[385] =*/ "",
/*[386] =*/ "",/*[387] =*/ "",
/*[388] =*/ "",/*[389] =*/ "",
/*[390] =*/ "",/*[391] =*/ "",
/*[392] =*/ "",/*[393] =*/ "",
/*[394] =*/ "",/*[395] =*/ "",
/*[396] =*/ "",/*[397] =*/ "",
/*[398] =*/ "",/*[399] =*/ "",
/*[400] =*/ "",/*[401] =*/ "",
/*[402] =*/ "",/*[403] =*/ "",
/*[404] =*/ "",/*[405] =*/ "",
/*[406] =*/ "",/*[407] =*/ "",
/*[408] =*/ "",/*[409] =*/ "",
/*[410] =*/ "",/*[411] =*/ "",
/*[412] =*/ "",/*[413] =*/ "",
/*[414] =*/ "",/*[415] =*/ "",
/*[416] =*/ "",/*[417] =*/ "",
/*[418] =*/ "",/*[419] =*/ "",
/*[420] =*/ "",/*[421] =*/ "",
/*[422] =*/ "",/*[423] =*/ "",
/*[424] =*/ "pidfd_send_signal",/*[425] =*/ "io_uring_setup",
/*[426] =*/ "io_uring_enter",/*[427] =*/ "io_uring_register",
/*[428] =*/ "open_tree",/*[429] =*/ "move_mount",
/*[430] =*/ "fsopen",/*[431] =*/ "fsconfig",
/*[432] =*/ "fsmount",/*[433] =*/ "fspick",
/*[434] =*/ "pidfd_open",/*[435] =*/ "clone3" };
}
#endif

View file

@ -53,14 +53,21 @@ namespace krikkel
{
#define __debug_stringify_switch_case(caseTestValue) \
case caseTestValue: \
propertyName = (propertyName.empty() ? #caseTestValue : propertyName)
#define __debug_stringify_switch_case_end_bool(value) \
propertyName = (propertyName.empty() ? #caseTestValue : propertyName); \
[[fallthrough]]
#define __debug_stringify_switch_last_case_bool(caseTestValue, value) \
case caseTestValue: \
propertyName = (propertyName.empty() ? #caseTestValue : propertyName); \
valueString = (value ? "true" : "false"); \
break
#define __debug_stringify_switch_case_end_string(value) \
#define __debug_stringify_switch_last_case_string(caseTestValue, value) \
case caseTestValue: \
propertyName = (propertyName.empty() ? #caseTestValue : propertyName); \
valueString = "\"" + std::string(value) + "\""; \
break
#define __debug_stringify_switch_case_end_number(value) \
#define __debug_stringify_switch_last_case_number(caseTestValue, value) \
case caseTestValue: \
propertyName = (propertyName.empty() ? #caseTestValue : propertyName); \
valueString = std::to_string(value); \
break;
#define __debug_stringify_switch_end(__prop) \
@ -120,9 +127,9 @@ namespace krikkel
#define __debug_log(message)
#define __debug_stringify_switch_begin(closureName, __prop, __value)
#define __debug_stringify_switch_case(caseTestValue)
#define __debug_stringify_switch_case_end_bool(value)
#define __debug_stringify_switch_case_end_string(value)
#define __debug_stringify_switch_case_end_number(value)
#define __debug_stringify_switch_last_case_bool(caseTestValue, value)
#define __debug_stringify_switch_last_case_string(caseTestValue, value)
#define __debug_stringify_switch_last_case_number(caseTestValue, value)
#define __debug_stringify_switch_end(__prop)
#define __debug_make_bytes_printable_table(__bytes)
#define __debug_make_bytes_printable(__bytes)

View file

@ -134,6 +134,7 @@ namespace krikkel::NCurses
windowManager->invertWindowsVisibility();
windowManager->updateLayout();
windowManager->refresh();
break;
case KEY_F(5):
windowManager->refresh();
break;

View file

@ -12,15 +12,20 @@
#include <cctype>
#include <termios.h>
#include <fcntl.h>
#include <exception>
#include <cerrno>
namespace krikkel::NCurses
{
using gsl::narrow;
using std::scoped_lock;
using std::recursive_mutex;
using std::system_error;
using std::system_category;
using std::string;
PtyWindow::PtyWindow(recursive_mutex *ncursesMutex, int lines, int columns, int y, int x)
: ncursesMutex(ncursesMutex), Window(lines, columns, y, x)
: Window(lines, columns, y, x), ncursesMutex(ncursesMutex)
{
// to get the original terminal we need to shutdown ncurses for a moment
/// @todo maybe try `reset_prog_mode()` and `reset_shell_mode()` instead
@ -30,8 +35,10 @@ namespace krikkel::NCurses
winsize windowSize =
{
.ws_row = narrow<short unsigned int>(this->height())
, .ws_col = narrow<short unsigned int>(this->width())
/*.ws_row =*/ narrow<short unsigned int>(this->height())
, /*.ws_col =*/ narrow<short unsigned int>(this->width())
, /*.y =*/ 0
, /*.x =*/ 0
};
openpty(&fdPtyHost, &fdPtyClient, NULL, &terminalParameters, &windowSize);
@ -69,7 +76,13 @@ namespace krikkel::NCurses
void PtyWindow::writeToPtyClient(const char *output, size_t length)
{
write(fdPtyHost, output, length);
size_t bytesWritten = write(fdPtyHost, output, length);
/// @todo this is a bit too simple; partial write is possible
if(bytesWritten != length)
{
string basicError("Could not write to PTY client (i. e. the shell).");
throw system_error(errno, system_category(), basicError);
}
//__debug_log("written to PTY client: '" + __debug_make_bytes_printable(std::string(output, length)) + '\'');
}
@ -93,7 +106,7 @@ namespace krikkel::NCurses
while(1)
{
readFromPtyClient();
struct timeval timeout = { .tv_sec = 0, .tv_usec = 200000 };
struct timeval timeout = { /*.tv_sec =*/ 0, /*.tv_usec =*/ 200000 };
fd_set readFds;
FD_ZERO(&readFds);
@ -106,7 +119,7 @@ namespace krikkel::NCurses
void PtyWindow::readFromPtyClient()
{
size_t bytesRead = read(fdPtyHost, ptyClientOutputBuffer, PTY_CLIENT_OUTPUT_BUFFER_SIZE);
if(bytesRead != -1 && bytesRead != 0)
if(bytesRead != (size_t) -1 && bytesRead != 0)
{
scoped_lock lock(ptyMutex, *ncursesMutex);
vterm_input_write(pseudoTerminal, ptyClientOutputBuffer, bytesRead);
@ -116,14 +129,14 @@ namespace krikkel::NCurses
VTermScreenCallbacks PtyWindow::screenCallbacks =
{
.damage = staticHandlerDamage,
.moverect = staticHandlerMoveRect,
.movecursor = staticHandlerMoveCursor,
.settermprop = staticHandlerSetTermProp,
.bell = staticHandlerBell,
.resize = staticHandlerResize,
.sb_pushline = staticHandlerPushLine,
.sb_popline = staticHandlerPopLine,
/*.damage =*/ staticHandlerDamage
, /*.moverect =*/ staticHandlerMoveRect
, /*.movecursor =*/ staticHandlerMoveCursor
, /*.settermprop =*/ staticHandlerSetTermProp
, /*.bell =*/ staticHandlerBell
, /*.resize =*/ staticHandlerResize
, /*.sb_pushline =*/ staticHandlerPushLine
, /*.sb_popline =*/ staticHandlerPopLine
};
int PtyWindow::handlerDamage(VTermRect rect)
@ -141,6 +154,9 @@ namespace krikkel::NCurses
int PtyWindow::handlerMoveRect(VTermRect dest, VTermRect src)
{
(void) dest;
(void) src;
__debug_log("(unimplemented) move content in rectangle from ("
+ std::to_string(src.start_col) + ", "
+ std::to_string(src.start_row) + ", "
@ -158,6 +174,9 @@ namespace krikkel::NCurses
int PtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible)
{
(void) oldpos;
(void) visible;
scoped_lock lock(*ncursesMutex);
cursorX = pos.col;
cursorY = pos.row;
@ -167,19 +186,19 @@ namespace krikkel::NCurses
int PtyWindow::handlerSetTermProp(VTermProp prop, VTermValue *val)
{
(void) prop;
(void) val;
/// @todo maybe use "vterm_get_prop_type() —> bool, number, string"?
__debug_stringify_switch_begin(handlerSetTermProp, prop, val);
__debug_stringify_switch_case(VTERM_PROP_CURSORVISIBLE);
__debug_stringify_switch_case(VTERM_PROP_CURSORBLINK);
__debug_stringify_switch_case(VTERM_PROP_ALTSCREEN);
__debug_stringify_switch_case(VTERM_PROP_REVERSE);
__debug_stringify_switch_case_end_bool(val->boolean);
__debug_stringify_switch_last_case_bool(VTERM_PROP_REVERSE, val->boolean);
__debug_stringify_switch_case(VTERM_PROP_TITLE);
__debug_stringify_switch_case(VTERM_PROP_ICONNAME);
__debug_stringify_switch_case_end_string(val->string);
__debug_stringify_switch_last_case_string(VTERM_PROP_ICONNAME, val->string);
__debug_stringify_switch_case(VTERM_PROP_CURSORSHAPE);
__debug_stringify_switch_case(VTERM_PROP_MOUSE);
__debug_stringify_switch_case_end_number(val->number);
__debug_stringify_switch_last_case_number(VTERM_PROP_MOUSE, val->number);
__debug_stringify_switch_end(prop);
__debug_log(std::string("unimplemented handler called: ")
@ -196,24 +215,35 @@ namespace krikkel::NCurses
int PtyWindow::handlerResize(int rows, int cols)
{
(void) rows;
(void) cols;
__debug_log("unimplemented handler called");
return 0;
}
int PtyWindow::handlerPushLine(int cols, const VTermScreenCell *cells)
{
(void) cols;
(void) cells;
__debug_log("(unimplemented) push line with " + std::to_string(cols) + " columns");
return 0;
}
int PtyWindow::handlerPopLine(int cols, VTermScreenCell *cells)
{
(void) cols;
(void) cells;
__debug_log("unimplemented handler called");
return 0;
}
attr_t PtyWindow::extractAttributesFromVTermCell(VTermScreenCell vTermCell)
{
(void) vTermCell;
attr_t result = A_NORMAL;
//__debug_log("unimplemented method called");
return result;
@ -221,6 +251,8 @@ namespace krikkel::NCurses
short PtyWindow::extractColorFromVTermCell(VTermScreenCell vTermCell)
{
(void) vTermCell;
//__debug_log("unimplemented method called");
return 0;
}
@ -268,8 +300,10 @@ namespace krikkel::NCurses
winsize windowSize =
{
.ws_row = narrow<unsigned short>(rows)
, .ws_col = narrow<unsigned short>(cols)
/*.ws_row =*/ narrow<unsigned short>(rows)
, /*.ws_col =*/ narrow<unsigned short>(cols)
, 0
, 0
};
ioctl(fdPtyHost, TIOCSWINSZ, &windowSize);
vterm_set_size(pseudoTerminal, rows, cols);

View file

@ -150,7 +150,6 @@ namespace krikkel::NCurses
{
uint16_t numberOfRelativeUnits = 0;
windowDimension absoluteSum = 0;
list<WindowStackElement>::iterator windowIterator = stack.begin();
for(WindowStackElement stackElement : visibleStack)
{

18
default.nix Normal file
View file

@ -0,0 +1,18 @@
{ debug ? false }:
with import <nixpkgs> { };
let
ncursesPkg = ncurses.overrideAttrs (oldAttrs: rec { configureFlags = oldAttrs.configureFlags ++ [ "--with-cxx-shared" ];});
in
stdenv.mkDerivation {
name = "kNCurses";
src = ./.;
buildInputs = [ libvterm-neovim ncursesPkg microsoft_gsl];
nativeBuildInputs = [ cmake ];
cmakeBuildType = if debug then "Debug" else "Release";
makeFlags = lib.lists.optional debug "VERBOSE=1";
hardeningDisable = lib.lists.optionals debug [ "fortify" ];
dontStrip = debug;
}