⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hackguide.html

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 HTML
📖 第 1 页 / 共 3 页
字号:
interfaces to a small set of basic functions and data structures usedto manipulate the virtual screen (in particular, none of this codedoes any I/O except through calls to more fundamental modulesdescribed below).  The files<blockquote><CODE>lib_addch.clib_bkgd.clib_box.clib_chgat.clib_clear.clib_clearok.clib_clrbot.clib_clreol.clib_colorset.clib_data.clib_delch.clib_delwin.clib_echo.clib_erase.clib_gen.clib_getstr.clib_hline.clib_immedok.clib_inchstr.clib_insch.clib_insdel.clib_insstr.clib_instr.clib_isendwin.clib_keyname.clib_leaveok.clib_move.clib_mvwin.clib_overlay.clib_pad.clib_printw.clib_redrawln.clib_scanw.clib_screen.clib_scroll.clib_scrollok.clib_scrreg.clib_set_term.clib_slk.clib_slkatr_set.clib_slkatrof.clib_slkatron.clib_slkatrset.clib_slkattr.clib_slkclear.clib_slkcolor.clib_slkinit.clib_slklab.clib_slkrefr.clib_slkset.clib_slktouch.clib_touch.clib_unctrl.clib_vline.clib_wattroff.clib_wattron.clib_window.c</CODE></blockquote>are all in this category.  They are veryunlikely to need change, barring bugs or some fundamentalreorganization in the underlying data structures. <P>These files are used only for debugging support:<blockquote><code>lib_trace.clib_traceatr.clib_tracebits.clib_tracechr.clib_tracedmp.clib_tracemse.ctrace_buf.c</code></blockquote>It is rather unlikely you will ever need to change these, unlessyou want to introduce a new debug trace level for some reasoon.<P>There is another group of files that do direct I/O via <EM>tputs()</EM>,computations on the terminal capabilities, or queries to the OSenvironment, but nevertheless have only fairly low complexity.  Theseinclude:<blockquote><code>lib_acs.clib_beep.clib_color.clib_endwin.clib_initscr.clib_longname.clib_newterm.clib_options.clib_termcap.clib_ti.clib_tparm.clib_tputs.clib_vidattr.cread_entry.c.</code></blockquote>They are likely to need revision only ifncurses is being ported to an environment without an underlyingterminfo capability representation. <P>These fileshave serious hooks intothe tty driver and signal facilities:<blockquote><code>lib_kernel.clib_baudrate.clib_raw.clib_tstp.clib_twait.c</code></blockquote>If you run into porting snafusmoving the package to another UNIX, the problem is likely to be in oneof these files.The file <CODE>lib_print.c</CODE> uses sleep(2) and alsofalls in this category.<P>Almost all of the real work is done in the files<blockquote><code>hardscroll.chashmap.clib_addch.clib_doupdate.clib_getch.clib_mouse.clib_mvcur.clib_refresh.clib_setup.clib_vidattr.c</code></blockquote>Most of the algorithmic complexity in thelibrary lives in these files.If there is a real bug in <STRONG>ncurses</STRONG> itself, it's probably here.We'll tour some of these files in detailbelow (see <A HREF="#engine">The Engine Room</A>). <P>Finally, there is a group of files that is actually most of theterminfo compiler.  The reason this code lives in the <STRONG>ncurses</STRONG>library is to support fallback to /etc/termcap.  These files include<blockquote><code>alloc_entry.ccaptoinfo.ccomp_captab.ccomp_error.ccomp_hash.ccomp_parse.ccomp_scan.cparse_entry.cread_termcap.cwrite_entry.c</code></blockquote>We'll discuss these in the compiler tour.<H2><A NAME="engine">The Engine Room</A></H2><H3><A NAME="input">Keyboard Input</A></H3>All <CODE>ncurses</CODE> input funnels through the function<CODE>wgetch()</CODE>, defined in <CODE>lib_getch.c</CODE>.  This function istricky; it has to poll for keyboard and mouse events and do a runningmatch of incoming input against the set of defined special keys. <P>The central data structure in this module is a FIFO queue, used tomatch multiple-character input sequences against special-keycapabilities; also to implement pushback via <CODE>ungetch()</CODE>. <P>The <CODE>wgetch()</CODE> code distinguishes between function keysequences and the same sequences typed manually by doing a timed waitafter each input character that could lead a function key sequence.If the entire sequence takes less than 1 second, it is assumed to havebeen generated by a function key press. <P>Hackers bruised by previous encounters with variant <CODE>select(2)</CODE>calls may find the code in <CODE>lib_twait.c</CODE> interesting.  It dealswith the problem that some BSD selects don't return a reliabletime-left value.  The function <CODE>timed_wait()</CODE> effectivelysimulates a System V select.<H3><A NAME="mouse">Mouse Events</A></H3>If the mouse interface is active, <CODE>wgetch()</CODE> polls for mouseevents each call, before it goes to the keyboard for input.  It isup to <CODE>lib_mouse.c</CODE> how the polling is accomplished; it may varyfor different devices. <P>Under xterm, however, mouse event notifications come in via the keyboardinput stream.  They are recognized by having the <STRONG>kmous</STRONG> capabilityas a prefix.  This is kind of klugey, but trying to wire in recognition ofa mouse key prefix without going through the function-key machinery wouldbe just too painful, and this turns out to imply having the prefix somewherein the function-key capabilities at terminal-type initialization. <P>This kluge only works because <STRONG>kmous</STRONG> isn't actually used by anyhistoric terminal type or curses implementation we know of.  Bestguess is it's a relic of some forgotten experiment in-house at BellLabs that didn't leave any traces in the publicly-distributed System Vterminfo files.  If System V or XPG4 ever gets serious about using itagain, this kluge may have to change. <P>Here are some more details about mouse event handling: <P>The <CODE>lib_mouse()</CODE>code is logically split into a lower level thataccepts event reports in a device-dependent format and an upper level thatparses mouse gestures and filters events.  The mediating data structure is acircular queue of event structures. <P>Functionally, the lower level's job is to pick up primitive events andput them on the circular queue.  This can happen in one of two ways:either (a) <CODE>_nc_mouse_event()</CODE> detects a series of incomingmouse reports and queues them, or (b) code in <CODE>lib_getch.c</CODE> detects the<STRONG>kmous</STRONG> prefix in the keyboard input stream and calls _nc_mouse_inlineto queue up a series of adjacent mouse reports. <P>In either case, <CODE>_nc_mouse_parse()</CODE> should be called after theseries is accepted to parse the digested mouse reports (low-levelevents) into a gesture (a high-level or composite event).<H3><A NAME="output">Output and Screen Updating</A></H3>With the single exception of character echoes during a <CODE>wgetnstr()</CODE>call (which simulates cooked-mode line editing in an ncurses window),the library normally does all its output at refresh time. <P>The main job is to go from the current state of the screen (as representedin the <CODE>curscr</CODE> window structure) to the desired new state (asrepresented in the <CODE>newscr</CODE> window structure), while doing aslittle I/O as possible. <P>The brains of this operation are the modules <CODE>hashmap.c</CODE>,<CODE>hardscroll.c</CODE> and <CODE>lib_doupdate.c</CODE>; the latter two use<CODE>lib_mvcur.c</CODE>.  Essentially, what happens looks like this: <P>The <CODE>hashmap.c</CODE> module tries to detect vertical motionchanges between the real and virtual screens.  This informationis represented by the oldindex members in the newscr structure.These are modified by vertical-motion and clear operations, and both arere-initialized after each update. To this change-journallinginformation, the hashmap code adds deductions made using a modified Heckelalgorithm on hash values generated from the line contents. <P>The <CODE>hardscroll.c</CODE> module computes an optimum set of scroll,insertion, and deletion operations to make the indices match.  It calls<CODE>_nc_mvcur_scrolln()</CODE> in <CODE>lib_mvcur.c</CODE> to do those motions. <P>Then <CODE>lib_doupdate.c</CODE> goes to work.  Its job is to do line-by-linetransformations of <CODE>curscr</CODE> lines to <CODE>newscr</CODE> lines.  Its maintool is the routine <CODE>mvcur()</CODE> in <CODE>lib_mvcur.c</CODE>.  This routinedoes cursor-movement optimization, attempting to get from given screenlocation A to given location B in the fewest output characters posible. <P>If you want to work on screen optimizations, you should use the factthat (in the trace-enabled version of the library) enabling the<CODE>TRACE_TIMES</CODE> trace level causes a report to be emitted aftereach screen update giving the elapsed time and a count of charactersemitted during the update.  You can use this to tell when an updateoptimization improves efficiency. <P>In the trace-enabled version of the library, it is also possible to disableand re-enable various optimizations at runtime by tweaking the variable<CODE>_nc_optimize_enable</CODE>.  See the file <CODE>include/curses.h.in</CODE>for mask values, near the end.<H1><A NAME="fmnote">The Forms and Menu Libraries</A></H1>The forms and menu libraries should work reliably in any environment youcan port ncurses to. The only portability issue anywhere in them is whatflavor of regular expressions the built-in form field type TYPE_REGEXPwill recognize. <P>The configuration code prefers the POSIX regex facility, modeled onSystem V's, but will settle for BSD regexps if the former isn't available. <P>Historical note: the panels code was written primarily to assist inporting u386mon 2.0 (comp.sources.misc v14i001-4) to systems lackingpanels support; u386mon 2.10 and beyond use it.  This version has beenslightly cleaned up for <CODE>ncurses</CODE>.<H1><A NAME="tic">A Tour of the Terminfo Compiler</A></H1>The <STRONG>ncurses</STRONG> implementation of <STRONG>tic</STRONG> is rather complexinternally; it has to do a trying combination of missions. This startswith the fact that, in addition to its normal duty of compilingterminfo sources into loadable terminfo binaries, it has to be able to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -