summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1996-05-31 05:40:03 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1996-05-31 05:40:03 +0000
commit839cb2ba6a15ccd5e074d855db52b1f5eb1dd210 (patch)
tree04a2d3fb760bd3e7c427a15bce955771f34f033d /lib
parent0b9e76142c4ba9e39793706de41a4d37280cdb8c (diff)
Terminfo emulation library; currently understands only about reading from
termcap database using cgetent(3)
Diffstat (limited to 'lib')
-rw-r--r--lib/libtermlib/Capabilities565
-rw-r--r--lib/libtermlib/Makefile73
-rw-r--r--lib/libtermlib/TODO7
-rw-r--r--lib/libtermlib/captoinfo.c322
-rw-r--r--lib/libtermlib/def_prog_mode.c49
-rw-r--r--lib/libtermlib/def_shell_mode.c49
-rw-r--r--lib/libtermlib/del_curterm.c66
-rw-r--r--lib/libtermlib/fillcap.c124
-rw-r--r--lib/libtermlib/findcap.c64
-rw-r--r--lib/libtermlib/findinfo.c64
-rw-r--r--lib/libtermlib/getterm.c237
-rw-r--r--lib/libtermlib/mkcaps.sh54
-rw-r--r--lib/libtermlib/mkinfo.c269
-rw-r--r--lib/libtermlib/mvcur.c111
-rw-r--r--lib/libtermlib/outc.c55
-rw-r--r--lib/libtermlib/pathnames.h33
-rw-r--r--lib/libtermlib/putp.c51
-rw-r--r--lib/libtermlib/reset_prog_mode.c48
-rw-r--r--lib/libtermlib/reset_shell_mode.c48
-rw-r--r--lib/libtermlib/restartterm.c67
-rw-r--r--lib/libtermlib/set_curterm.c51
-rw-r--r--lib/libtermlib/setterm.c50
-rw-r--r--lib/libtermlib/setupterm.c82
-rw-r--r--lib/libtermlib/shlib_version2
-rw-r--r--lib/libtermlib/term.h.head38
-rw-r--r--lib/libtermlib/term.h.tail124
-rw-r--r--lib/libtermlib/term.private.h57
-rw-r--r--lib/libtermlib/tgetent.c62
-rw-r--r--lib/libtermlib/tgetflag.c52
-rw-r--r--lib/libtermlib/tgetnum.c52
-rw-r--r--lib/libtermlib/tgetstr.c58
-rw-r--r--lib/libtermlib/tgoto.c47
-rw-r--r--lib/libtermlib/tigetflag.c52
-rw-r--r--lib/libtermlib/tigetnum.c52
-rw-r--r--lib/libtermlib/tigetstr.c52
-rw-r--r--lib/libtermlib/tparm.c362
-rw-r--r--lib/libtermlib/tputs.c117
-rw-r--r--lib/libtermlib/tty_init.c68
-rw-r--r--lib/libtermlib/vidattr.c47
-rw-r--r--lib/libtermlib/vidputs.c126
40 files changed, 3907 insertions, 0 deletions
diff --git a/lib/libtermlib/Capabilities b/lib/libtermlib/Capabilities
new file mode 100644
index 00000000000..d5874c19eb4
--- /dev/null
+++ b/lib/libtermlib/Capabilities
@@ -0,0 +1,565 @@
+# $OpenBSD: Capabilities,v 1.1 1996/05/31 05:40:02 tholo Exp $
+#
+# Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by SigmaSoft, Th. Lockert.
+# 4. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#
+# The following is a list of terminfo capabilities with their
+# corresponding termcap alias. All entries up to the marker
+# "#endbinary" are found in compiled terminfo files IN THE ORDER
+# SPECIFIED. Do NOT reorder or add capabilities before the
+# marker.
+#
+# type variable capname termcap
+#
+# Standard terminfo capabilities:
+#
+bool auto_left_margin bw bw
+bool auto_right_margin am am
+bool no_esc_ctlc xsb xb
+bool ceol_standout_glitch xhp xs
+bool eat_newline_glitch xenl xn
+bool erase_overstrike eo eo
+bool generic_type gn gn
+bool hard_copy hc hc
+bool has_meta_key km km
+bool has_status_line hs hs
+bool insert_null_glitch in in
+bool memory_above da da
+bool memory_below db db
+bool move_insert_mode mir mi
+bool move_standout_mode msgr ms
+bool over_strike os os
+bool status_line_esc_ok eslok es
+bool dest_tabs_magic_smso xt xt
+bool tilde_glitch hz hz
+bool transparent_underline ul ul
+bool xon_xoff xon xo
+bool needs_xon_xoff nxon nx
+bool prtr_silent mc5i 5i
+bool hard_cursor chts HC
+bool non_rev_rmcup nrrmc NR
+bool no_pad_char npc NP
+bool non_dest_scroll_region ndscr ND
+bool can_change ccc cc
+bool back_color_erase bce ut
+bool hue_lightness_saturation hls hl
+bool cool_addr_glitch xhpa YA
+bool cr_cancels_micro_mode crxm YB
+bool has_print_wheel daisy YC
+bool row_addr_glitch xvpa YD
+bool semi_auto_right_margin sam YE
+bool cpi_changes_res cpix YF
+bool lpi_changes_res lpix YG
+#
+num columns cols co
+num init_tabs it it
+num lines lines li
+num lines_of_memory lm lm
+num magic_cookie_glitch xmc sg
+num padding_baud_rate pb pb
+num virtual_terminal vt vt
+num width_status_line wsl ws
+num num_labels nlab Nl
+num label_height lh lh
+num label_width lw lw
+num max_attributes ma ma
+num maximum_windows wnum MW
+num max_colors colors Co
+num max_pairs pairs pa
+num no_color_video ncv NC
+#
+str back_tab cbt bt
+str bell bel bl
+str carriage_return cr cr
+str change_scroll_region csr cs
+str clear_all_tabs tbc ct
+str clear_screen clear cl
+str clr_eol el ce
+str clr_eos ed cd
+str column_address hpa ch
+str command_character cmdch CC
+str cursor_address cup cm
+str cursor_down cud1 do
+str cursor_home home ho
+str cursor_invisible civis vi
+str cursor_left cub1 le
+str cursor_mem_address mrcup CM
+str cursor_normal cnorm ve
+str cursor_right cuf1 nd
+str cursor_to_ll ll ll
+str cursor_up cuu1 up
+str cursor_visible cvvis vs
+str delete_character dch1 dc
+str delete_line dl1 dl
+str dis_status_line dsl ds
+str down_half_line hd hd
+str enter_alt_charset_mode smacs as
+str enter_blink_mode blink mb
+str enter_bold_mode bold md
+str enter_ca_mode smcup ti
+str enter_delete_mode smdc dm
+str enter_dim_mode dim mh
+str enter_insert_mode smir im
+str enter_secure_mode invis mk
+str enter_protected_mode prot mp
+str enter_reverse_mode rev mr
+str enter_standout_mode smso so
+str enter_underline_mode smul us
+str erase_chars ech ec
+str exit_alt_charset_mode rmacs ae
+str exit_attribute_mode sgr0 me
+str exit_ca_mode rmcup te
+str exit_delete_mode rmdc ed
+str exit_insert_mode rmir ei
+str exit_standout_mode rmso se
+str exit_underline_mode rmul ue
+str flash_screen flash vb
+str form_feed ff ff
+str from_status_line fsl fs
+str init_1string is1 i1
+str init_2string is2 is
+str init_3string is3 i3
+str init_file if if
+str insert_character ich1 ic
+str insert_line il1 al
+str insert_padding ip ip
+str key_backspace kbs kb
+str key_catab ktbc ka
+str key_clear kclr kC
+str key_ctab kctab kt
+str key_dc kdch1 kD
+str key_dl kdl1 kL
+str key_down kcud1 kd
+str key_eic krmir kM
+str key_eol kel kE
+str key_eos ked kS
+str key_f0 kf0 k0
+str key_f1 kf1 k1
+str key_f10 kf10 k;
+str key_f2 kf2 k2
+str key_f3 kf3 k3
+str key_f4 kf4 k4
+str key_f5 kf5 k5
+str key_f6 kf6 k6
+str key_f7 kf7 k7
+str key_f8 kf8 k8
+str key_f9 kf9 k9
+str key_home khome kh
+str key_ic kich1 kI
+str key_il kil1 kA
+str key_left kcub1 kl
+str key_ll kll kH
+str key_npage knp kN
+str key_ppage kpp kP
+str key_right kcuf1 kr
+str key_sf kind kF
+str key_sr kri kR
+str key_stab khts kT
+str key_up kcuu1 ku
+str keypad_local rmkx ke
+str keypad_xmit smkx ks
+str lab_f0 lf0 l0
+str lab_f1 lf1 l1
+str lab_f10 lf10 la
+str lab_f2 lf2 l2
+str lab_f3 lf3 l3
+str lab_f4 lf4 l4
+str lab_f5 lf5 l5
+str lab_f6 lf6 l6
+str lab_f7 lf7 l7
+str lab_f8 lf8 l8
+str lab_f9 lf9 l9
+str meta_off rmm mo
+str meta_on smm mm
+str newline nel nw
+str pad_char pad pc
+str parm_dch dch DC
+str parm_delete_line dl DL
+str parm_down_cursor cud DO
+str parm_ich ich IC
+str parm_index indn SF
+str parm_insert_line il AL
+str parm_left_cursor cub LE
+str parm_right_cursor cuf RI
+str parm_rindex rin SR
+str parm_up_cursor cuu UP
+str pkey_key pfkey pk
+str pkey_local pfloc pl
+str pkey_xmit pfx px
+str print_screen mc0 ps
+str prtr_off mc4 pf
+str prtr_on mc5 po
+str repeat_char rep rp
+str reset_1string rs1 r1
+str reset_2string rs2 r2
+str reset_3string rs3 r3
+str reset_file rf rf
+str restore_cursor rc rc
+str row_address vpa cv
+str save_cursor sc sc
+str scroll_forward ind sf
+str scroll_reverse ri sr
+str set_attributes sgr sa
+str set_tab hts st
+str set_window wind wi
+str tab ht ta
+str to_status_line tsl ts
+str underline_char uc uc
+str up_half_line hu hu
+str init_prog iprog iP
+str key_a1 ka1 K1
+str key_a3 ka3 K3
+str key_b2 kb2 K2
+str key_c1 kc1 K4
+str key_c3 kc3 K5
+str prtr_non mc5p pO
+#
+# Release 4 capabilities
+#
+num buffer_capacity bufsz Ya
+num dot_vert_spacing spinv Yb
+num dot_horz_spacing spinh Yc
+num max_micro_address maddr Yd
+num max_micro_jump mjump Ye
+num micro_char_size mcs Yf
+num micro_line_size mls Yg
+num number_of_pins npins Yh
+num output_res_char orc Yi
+num output_res_line orl Yj
+num output_res_horz_inch orhi Yk
+num output_res_vert_inch orvi Yl
+num print_rate cps Ym
+num wide_char_size widcs Yn
+num buttons btns BT
+num bit_image_entwining bitwin Yo
+num bit_image_type bitype Yp
+#
+str char_padding rmp rP
+str acs_chars acsc ac
+str plab_norm pln pn
+str key_btab kcbt kB
+str enter_xon_mode smxon SX
+str exit_xon_mode rmxon RX
+str enter_am_mode smam SA
+str exit_am_mode rmam RA
+str xon_character xonc XN
+str xoff_character xoffc XF
+str ena_acs enacs eA
+str label_on smln LO
+str label_off rmln LF
+str key_beg kbeg @1
+str key_cancel kcan @2
+str key_close kclo @3
+str key_command kcmd @4
+str key_copy kcpy @5
+str key_create kcrt @6
+str key_end kend @7
+str key_enter kent @8
+str key_exit kext @9
+str key_find kfnd @0
+str key_help khlp %1
+str key_mark kmrk %2
+str key_message kmsg %3
+str key_move kmov %4
+str key_next knxt %5
+str key_open kopn %6
+str key_options kopt %7
+str key_previous kprv %8
+str key_print kprt %9
+str key_redo krdo %0
+str key_reference kref &1
+str key_refresh krfr &2
+str key_replace krpl &3
+str key_restart krst &4
+str key_resume kres &5
+str key_save ksav &6
+str key_suspend kspd &7
+str key_undo kund &8
+str key_sbeg kBEG &9
+str key_scancel kCAN &0
+str key_scommand kCMD *1
+str key_scopy kCPY *2
+str key_screate kCRT *3
+str key_sdc kDC *4
+str key_sdl kDL *5
+str key_select kslt *6
+str key_send kEND *7
+str key_seol kEOL *8
+str key_sexit kEXT *9
+str key_sfind kFND *0
+str key_shelp kHLP #1
+str key_shome kHOM #2
+str key_sic kIC #3
+str key_sleft kLFT #4
+str key_smessage kMSG %a
+str key_smove kMOV %b
+str key_snext kNXT %c
+str key_soptions kOPT %d
+str key_sprevious kPRV %e
+str key_sprint kPRT %f
+str key_sredo kRDO %g
+str key_sreplace kRPL %h
+str key_sright kRIT %i
+str key_srsume kRES %j
+str key_ssave kSAV !1
+str key_ssuspend kSPD !2
+str key_sundo kUND !3
+str req_for_input rfi RF
+str key_f11 kf11 F1
+str key_f12 kf12 F2
+str key_f13 kf13 F3
+str key_f14 kf14 F4
+str key_f15 kf15 F5
+str key_f16 kf16 F6
+str key_f17 kf17 F7
+str key_f18 kf18 F8
+str key_f19 kf19 F9
+str key_f20 kf20 FA
+str key_f21 kf21 FB
+str key_f22 kf22 FC
+str key_f23 kf23 FD
+str key_f24 kf24 FE
+str key_f25 kf25 FF
+str key_f26 kf26 FG
+str key_f27 kf27 FH
+str key_f28 kf28 FI
+str key_f29 kf29 FJ
+str key_f30 kf30 FK
+str key_f31 kf31 FL
+str key_f32 kf32 FM
+str key_f33 kf33 FN
+str key_f34 kf34 FO
+str key_f35 kf35 FP
+str key_f36 kf36 FQ
+str key_f37 kf37 FR
+str key_f38 kf38 FS
+str key_f39 kf39 FT
+str key_f40 kf40 FU
+str key_f41 kf41 FV
+str key_f42 kf42 FW
+str key_f43 kf43 FX
+str key_f44 kf44 FY
+str key_f45 kf45 FZ
+str key_f46 kf46 Fa
+str key_f47 kf47 Fb
+str key_f48 kf48 Fc
+str key_f49 kf49 Fd
+str key_f50 kf50 Fe
+str key_f51 kf51 Ff
+str key_f52 kf52 Fg
+str key_f53 kf53 Fh
+str key_f54 kf54 Fi
+str key_f55 kf55 Fj
+str key_f56 kf56 Fk
+str key_f57 kf57 Fl
+str key_f58 kf58 Fm
+str key_f59 kf59 Fn
+str key_f60 kf60 Fo
+str key_f61 kf61 Fp
+str key_f62 kf62 Fq
+str key_f63 kf63 Fr
+str clr_bol el1 cb
+str clear_margins mgc MC
+str set_left_margin smgl ML
+str set_right_margin smgr MR
+str label_format fln Lf
+str set_clock sclk SC
+str display_clock dclk DK
+str remove_clock rmclk RC
+str create_window cwin CW
+str goto_window wingo WG
+str hangup hup HU
+str dial_phone dial DI
+str quick_dial qdial QD
+str tone tone TO
+str pulse pulse PU
+str flash_hook hook fh
+str fixed_pause pause PA
+str wait_tone wait WA
+str user0 u0 u0
+str user1 u1 u1
+str user2 u2 u2
+str user3 u3 u3
+str user4 u4 u4
+str user5 u5 u5
+str user6 u6 u6
+str user7 u7 u7
+str user8 u8 u8
+str user9 u9 u9
+str orig_colors oc oc
+str orig_pair op op
+str initialize_color initc Ic
+str initialize_pair initp Ip
+str set_color_pair scp sp
+str set_foreground setf Sf
+str set_background setb Sb
+str change_char_pitch cpi ZA
+str change_line_pitch lpi ZB
+str change_res_horz chr ZC
+str change_res_vert cvr ZD
+str define_char defc ZE
+str enter_doublewide_mode swidm ZF
+str enter_draft_quality sdrfq ZG
+str enter_italics_mode sitm ZH
+str enter_leftward_mode slm ZI
+str enter_micro_mode smicm ZJ
+str enter_near_letter_quality snlq ZK
+str enter_normal_quality snrmq ZL
+str enter_shadow_mode sshm ZM
+str enter_subscript_mode ssubm ZN
+str enter_superscript_mode ssupm ZO
+str enter_upward_mode sum ZP
+str exit_doublewide_mode rwidm ZQ
+str exit_italics_mode ritm ZR
+str exit_leftward_mode rlm ZS
+str exit_micro_mode rmicm ZT
+str exit_shadow_mode rshm ZU
+str exit_subscript_mode rsubm ZV
+str exit_superscript_mode rsupm ZW
+str exit_upward_mode rum ZX
+str micro_column_address mhpa ZY
+str micro_down mcud1 ZZ
+str micro_left mcub1 Za
+str micro_right mcuf1 Zb
+str micro_row_address mvpa Zc
+str micro_up mcuu1 Zd
+str order_of_pins porder Ze
+str parm_down_micro mcud Zf
+str parm_left_micro mcub Zg
+str parm_right_micro mcuf Zh
+str parm_up_micro mcuu Zi
+str select_char_set scs Zj
+str set_bottom_margin smgb Zk
+str set_bottom_margin_parm smgbp Zl
+str set_left_margin_parm smglp Zm
+str set_right_margin_parm smgrp Zn
+str set_top_margin smgt Zo
+str set_top_margin_parm smgtp Zp
+str start_bit_image sbim Zq
+str start_char_set_def scsd Zr
+str stop_bit_image rbim Zs
+str stop_char_set_def rcsd Zt
+str subscript_characters subcs Zu
+str superscript_characters supcs Zv
+str these_cause_cr docr Zw
+str zero_motion zerom Zx
+str char_set_names csnm Zy
+str key_mouse kmous Km
+str mouse_info minfo Mi
+str req_mouse_pos reqmp RQ
+str get_mouse getm Gm
+str set_a_foreground setaf AF
+str set_a_background setab AB
+str pkey_plab pfxl xl
+str device_type devt dv
+str code_set_init csin ci
+str set0_des_seq s0ds s0
+str set1_des_seq s1ds s1
+str set2_des_seq s2ds s2
+str set3_des_seq s3ds s3
+str set_lr_margin smglr ML
+str set_tb_margin smgtb MT
+str bit_image_repeat birep Xy
+str bit_image_newline binel Zz
+str bit_image_carriage_return bicr Yv
+str color_names colornm Yw
+str define_bit_image_region defbi Yx
+str end_bit_image_region endbi Yy
+str set_color_band setcolor Yz
+str set_page_length slines YZ
+str display_pc_char dispc S1
+str enter_pc_charset_mode smpch S2
+str exit_pc_charset_mode rmpch S3
+str enter_scancode_mode smsc S4
+str exit_scancode_mode rmsc S5
+str pc_term_options pctrm S6
+str scancode_escape scesc S7
+str alt_scancode_esc scesa S8
+#
+#endbinary
+#
+# XSI Curses capabilities
+#
+str enter_horizontal_hl_mode ehhlm Xh
+str enter_left_hl_mode elhlm Xl
+str enter_low_hl_mode elohlm Xo
+str enter_right_hl_mode erhlm Xr
+str enter_top_hl_mode ethlm Xt
+str enter_vertical_hl_mode evhlm Xv
+#
+# Termcap capabilities with no Terminfo equivalent, for compatibility
+#
+bool backspaces_with_bs OTbs bs
+bool crt_no_scrolling OTns ns
+bool no_correctly_working_cr OTnc nc
+#
+num carriage_return_delay OTdC dC
+num magic_cookie_glitch_ul OTug ug
+num new_line_delay OTdN dN
+#
+str backspace_if_not_bs OTbc bc
+str linefeed_if_not_lf OTnl nl
+str termcap_init2 OTi2 i2
+str termcap_reset OTrs rs
+#
+# GNU Termcap capabilities with no Terminfo equivalent, for compatability
+#
+bool gnu_has_meta_key OTMT MT
+#
+# Ancient Termcap capabilites; should not be in use
+#
+bool has_hardware_tabs OTpt pt
+bool linefeed_is_newline OTNL NL
+bool return_does_clr_eol OTxr xr
+#
+num backspace_delay OTdB dB
+num horizontal_tab_delay OTdT dT
+num number_of_function_keys OTkn kn
+num other_non_function_keys OTko ko
+#
+str arrow_key_map OTma ma
+#
+# Xenix Termcap capabilities
+#
+str acs_btee OTGU GU
+str acs_hline OTGH GH
+str acs_llcorner OTG3 G3
+str acs_lrcorner OTG4 G4
+str acs_ltee OTGR GR
+str acs_plus OTGC GC
+str acs_rtee OTGL GL
+str acs_ttee OTGD GD
+str acs_ulcorner OTG2 G2
+str acs_urcorner OTG1 G1
+str acs_vline OTGV GV
+#
+# HP Terminfo extensions
+#
+str memory_lock meml ml
+str memory_unlock memu mu
diff --git a/lib/libtermlib/Makefile b/lib/libtermlib/Makefile
new file mode 100644
index 00000000000..5282fc60683
--- /dev/null
+++ b/lib/libtermlib/Makefile
@@ -0,0 +1,73 @@
+# $OpenBSD: Makefile,v 1.1 1996/05/31 05:40:02 tholo Exp $
+#
+# Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by SigmaSoft, Th. Lockert.
+# 4. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+LIB= termlib
+SRCS= captoinfo.c def_prog_mode.c def_shell_mode.c del_curterm.c \
+ fillcap.c findcap.c findinfo.c getterm.c mvcur.c outc.c putp.c \
+ reset_prog_mode.c reset_shell_mode.c restartterm.c setterm.c \
+ setupterm.c set_curterm.c tgetent.c tgetflag.c tgetnum.c \
+ tgetstr.c tgoto.c tigetflag.c tigetnum.c tigetstr.c tparm.c \
+ tputs.c tty_init.c vidattr.c vidputs.c captoidx.c infotoidx.c \
+ boolnames.c boolcodes.c boolfnames.c \
+ numnames.c numcodes.c numfnames.c \
+ strnames.c strcodes.c strfnames.c
+HDRS= term.h
+CLEANFILES+= ${HDRS} binaries.h captoidx.c infotoidx.c mkinfo \
+ boolnames.c boolcodes.c boolfnames.c \
+ numnames.c numcodes.c numfnames.c \
+ strnames.c strcodes.c strfnames.c
+CFLAGS+= -I. -I${.CURDIR}
+NOMAN=
+
+beforedepend: ${HDRS} binaries.h
+
+term.h: mkcaps.sh term.h.head Capabilities term.h.tail
+ sh ${.CURDIR}/mkcaps.sh ${.CURDIR}/term.h.head \
+ ${.CURDIR}/Capabilities \
+ ${.CURDIR}/term.h.tail >$@
+
+boolnames.c boolcodes.c boolfnames.c \
+numnames.c numcodes.c numfnames.c \
+strnames.c strcodes.c strfnames.c \
+captoidx.c infotoidx.c \
+binaries.h: mkinfo Capabilities
+ ./mkinfo ${.CURDIR}/Capabilities
+
+includes: ${HDRS}
+ @for i in ${HDRS}; do \
+ cmp -s $$i ${DESTDIR}/usr/include/$$i || \
+ install -c -o ${BINOWN} -g ${BINGRP} -m 444 $$i \
+ ${DESTDIR}/usr/include; \
+ done
+
+.include <bsd.lib.mk>
+
+.depend: mkinfo.c
diff --git a/lib/libtermlib/TODO b/lib/libtermlib/TODO
new file mode 100644
index 00000000000..80039fa1c40
--- /dev/null
+++ b/lib/libtermlib/TODO
@@ -0,0 +1,7 @@
+Make mvcur() work on terminals without cursor_address - look in curses
+color support in vidputs() - look in ncurses
+
+Code to read from compiled terminfo files
+Code to read from terminfo source?
+
+Manual pages
diff --git a/lib/libtermlib/captoinfo.c b/lib/libtermlib/captoinfo.c
new file mode 100644
index 00000000000..9c850d492bb
--- /dev/null
+++ b/lib/libtermlib/captoinfo.c
@@ -0,0 +1,322 @@
+/* $OpenBSD: captoinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: captoinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "term.private.h"
+
+#define STKSIZ 64
+
+static int stack[STKSIZ];
+static int stkidx;
+static int nflag;
+static int rflag;
+static int param;
+static int onstack;
+static char *d;
+
+static void
+pop()
+{
+ if (stkidx > 0)
+ onstack = stack[--stkidx];
+ else
+ onstack = 0;
+ param++;
+}
+
+static void
+push()
+{
+ if (stkidx < STKSIZ)
+ stack[stkidx++] = onstack;
+}
+
+static void
+getparam(p, n)
+ int p;
+ int n;
+{
+ if (rflag)
+ if (p == 1)
+ p++;
+ else if (p == 2)
+ p--;
+ if (onstack == p) {
+ if (n > 1) {
+ *d++ = '%';
+ *d++ = 'P';
+ *d++ = 'a';
+ while (n--) {
+ *d++ = '%';
+ *d++ = 'g';
+ *d++ = 'a';
+ }
+ }
+ return;
+ }
+ if (onstack)
+ push();
+ onstack = p;
+ while (n--) {
+ *d++ = '%';
+ *d++ = 'p';
+ *d++ = '0' + p;
+ }
+ if (nflag && p < 3) {
+ *d++ = '%';
+ *d++ = '{';
+ *d++ = '9';
+ *d++ = '6';
+ *d++ = '}';
+ *d++ = '%';
+ *d++ = '^';
+ }
+}
+
+static int
+cvtchar(p)
+ const char *p;
+{
+ char ch = 0;
+ int len;
+
+ switch (*p) {
+ case '\\':
+ switch (*++p) {
+ case '\'':
+ case '$':
+ case '\\':
+ case '%':
+ ch = *p;
+ len = 2;
+ break;
+ case '\0':
+ ch = '\\';
+ len = 1;
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ len = 1;
+ while (isdigit(*p)) {
+ ch = ch * 8 + (*p++ - '0');
+ len++;
+ }
+ break;
+ default:
+ ch = *p;
+ len = 2;
+ break;
+ }
+ break;
+ case '^':
+ ch = (*p++ & 0x1F);
+ len = 2;
+ break;
+ default:
+ ch = *p;
+ len = 1;
+ break;
+ }
+
+ if (isgraph(ch) && ch != ',' && ch != '\'' && ch != '\\' && ch != ':') {
+ *d++ = '%';
+ *d++ = '\'';
+ *d++ = ch;
+ *d++ = '\'';
+ }
+ else {
+ *d++ = '%';
+ *d++ = '{';
+ if (ch > 99)
+ *d++ = ch / 100 + '0';
+ if (ch > 9)
+ *d++ = ((int)ch / 10) % 10 + '0';
+ *d++ = ch % 10 + '0';
+ *d++ = '}';
+ }
+ return len;
+}
+
+char *
+_ti_captoinfo(cap)
+ const char *cap;
+{
+ char ch, new[4096];
+ const char *cost;
+
+ if (cap == NULL)
+ return NULL;
+ stkidx = 0;
+ onstack = 0;
+ nflag = 0;
+ rflag = 0;
+ param = 1;
+ d = new;
+ cost = NULL;
+ if (isdigit(*cap))
+ for (cost = cap; isdigit(*cap) || *cap == '*' || *cap == '.'; cap++)
+ ;
+
+ while (*cap) {
+ switch (*cap) {
+ case '%':
+ cap++;
+ switch (ch = *cap++) {
+ case '%':
+ *d++ = '%';
+ break;
+ case 'r':
+ rflag++;
+ break;
+ case 'n':
+ nflag++;
+ break;
+ case 'i':
+ *d++ = '%';
+ *d++ = 'i';
+ break;
+ case '6':
+ case 'B':
+ getparam(param, 2);
+ *d++ = '%';
+ *d++ = '{';
+ *d++ = '6';
+ *d++ = '}';
+ *d++ = '%';
+ *d++ = '*';
+ *d++ = '%';
+ *d++ = '+';
+ break;
+ case '8':
+ case 'D':
+ getparam(param, 2);
+ *d++ = '%';
+ *d++ = '{';
+ *d++ = '2';
+ *d++ = '}';
+ *d++ = '%';
+ *d++ = '*';
+ *d++ = '%';
+ *d++ = '-';
+ break;
+ case '>':
+ getparam(param, 2);
+ *d++ = '%';
+ *d++ = '?';
+ cap += cvtchar(cap);
+ *d++ = '%';
+ *d++ = '>';
+ *d++ = '%';
+ *d++ = 't';
+ cap += cvtchar(cap);
+ *d++ = '%';
+ *d++ = '+';
+ *d++ = '%';
+ *d++ = ';';
+ break;
+ case 'a':
+ getparam(param, 1);
+ cap += cvtchar(cap);
+ *d++ = '%';
+ *d++ = '+';
+ break;
+ case 'd':
+ case 's':
+ getparam(param, 1);
+ *d++ = '%';
+ *d++ = ch;
+ pop();
+ break;
+ case '+':
+ case '-':
+ getparam(param, 1);
+ cap += cvtchar(cap);
+ *d++ = '%';
+ *d++ = ch;
+ *d++ = '%';
+ *d++ = 'c';
+ pop();
+ break;
+ case '.':
+ getparam(param, 1);
+ *d++ = '%';
+ *d++ = 'c';
+ pop();
+ break;
+ case '2':
+ case '3':
+ getparam(param, 1);
+ *d++ = '%';
+ *d++ = ch;
+ *d++ = 'd';
+ pop();
+ break;
+ case '\\':
+ *d++ = '%';
+ *d++ = '\\';
+ break;
+ default:
+ *d++ = '%';
+ cap--;
+ break;
+ }
+ break;
+ default:
+ *d++ = *cap++;
+ break;
+ }
+ }
+
+ if (cost) {
+ *d++ = '$';
+ *d++ = '<';
+ for (cap = cost;; cap++)
+ if (isdigit(*cap) || *cap == '*' || *cap == '.')
+ *d++ = *cap;
+ else
+ break;
+ *d++ = '/';
+ *d++ = '>';
+ }
+
+ *d = '\0';
+
+ return strdup(new);
+}
diff --git a/lib/libtermlib/def_prog_mode.c b/lib/libtermlib/def_prog_mode.c
new file mode 100644
index 00000000000..63bdbc5c2d5
--- /dev/null
+++ b/lib/libtermlib/def_prog_mode.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: def_prog_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: def_prog_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "term.h"
+
+/*
+ * Save current mode as "program" mode, so that it can later be
+ * restored using reset_prog_mode()
+ */
+int
+def_prog_mode()
+{
+ return (tcgetattr(cur_term->fd, &cur_term->pmode) == 0) ? OK : ERR;
+}
diff --git a/lib/libtermlib/def_shell_mode.c b/lib/libtermlib/def_shell_mode.c
new file mode 100644
index 00000000000..f202ec26057
--- /dev/null
+++ b/lib/libtermlib/def_shell_mode.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: def_shell_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: def_shell_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "term.h"
+
+/*
+ * Save current mode as default "shell" mode so that it can later
+ * be restored with reset_shell_mode()
+ */
+int
+def_shell_mode()
+{
+ return (tcgetattr(cur_term->fd, &cur_term->smode) == 0) ? OK : ERR;
+}
diff --git a/lib/libtermlib/del_curterm.c b/lib/libtermlib/del_curterm.c
new file mode 100644
index 00000000000..9f0e2faf168
--- /dev/null
+++ b/lib/libtermlib/del_curterm.c
@@ -0,0 +1,66 @@
+/* $OpenBSD: del_curterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: del_curterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+
+/*
+ * Free storage associated with the terminal description
+ * passed in. Note that it is legal to free cur_term in
+ * this manner. If this is done, we also set cur_term
+ * to NULL so that any references to that will cause an
+ * error unless it is reinitialized with a call to
+ * set_curterm() or setupterm()
+ */
+int
+del_curterm(term)
+ TERMINAL *term;
+{
+ int i;
+
+ for (i = 0; i < _tStrCnt; i++)
+ if (term->strs[i] != NULL)
+ free(term->strs[i]);
+ free(term->name);
+ free(term);
+ /*
+ * If the terminal description just freed was the current
+ * one, set cur_term to NULL
+ */
+ if (term == cur_term)
+ cur_term = NULL;
+ return OK;
+}
diff --git a/lib/libtermlib/fillcap.c b/lib/libtermlib/fillcap.c
new file mode 100644
index 00000000000..cc103e81cd1
--- /dev/null
+++ b/lib/libtermlib/fillcap.c
@@ -0,0 +1,124 @@
+/* $OpenBSD: fillcap.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: fillcap.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "term.h"
+#include "term.private.h"
+
+void
+_ti_fillcap(term)
+ struct _terminal *term;
+{
+ TERMINAL *save = cur_term;
+ char buf[4096];
+
+ cur_term = term;
+ if (carriage_return == NULL)
+ if (carriage_return_delay > 0) {
+ sprintf(buf, "\r$<%d>", carriage_return_delay);
+ carriage_return = strdup(buf);
+ }
+ else
+ carriage_return = strdup("\r");
+ if (cursor_left == NULL)
+ if (backspace_delay > 0) {
+ sprintf(buf, "\b$<%d>", backspace_delay);
+ cursor_left = strdup(buf);
+ }
+ else if (backspaces_with_bs)
+ cursor_left = strdup("\b");
+ else if (backspace_if_not_bs != NULL)
+ cursor_left = strdup(backspace_if_not_bs);
+ if (cursor_down == NULL)
+ if (linefeed_if_not_lf != NULL)
+ cursor_down = strdup(linefeed_if_not_lf);
+ else if (linefeed_is_newline != 1)
+ if (new_line_delay > 0) {
+ sprintf(buf, "\n$<%d>", new_line_delay);
+ cursor_down = strdup(buf);
+ }
+ else
+ cursor_down = strdup("\n");
+ if (newline == NULL)
+ if (linefeed_is_newline == 1) {
+ if (new_line_delay > 0) {
+ sprintf(buf, "\n$<%d>", new_line_delay);
+ newline = strdup(buf);
+ }
+ else
+ newline = strdup("\n");
+ }
+ else if (carriage_return != NULL && carriage_return_delay <= 0) {
+ if (linefeed_if_not_lf != NULL) {
+ strncpy(buf, carriage_return, sizeof(buf) >> 1);
+ buf[sizeof(buf) >> 1] = '\0';
+ strncat(buf, linefeed_if_not_lf, sizeof(buf) - 1);
+ }
+ else if (new_line_delay > 0)
+ sprintf(buf, "%s\n$<%d>", carriage_return, new_line_delay);
+ else {
+ strncpy(buf, carriage_return, sizeof(buf) >> 1);
+ buf[sizeof(buf) - 2] = '\0';
+ strncat(buf, "\n", sizeof(buf) - 1);
+ }
+ buf[sizeof(buf) - 1] = '\0';
+ newline = strdup(buf);
+ }
+ if (return_does_clr_eol || no_correctly_working_cr) {
+ if (carriage_return != NULL)
+ free(carriage_return);
+ carriage_return = NULL;
+ }
+ if (tab == NULL)
+ if (horizontal_tab_delay > 0) {
+ sprintf(buf, "\t$<%d>", horizontal_tab_delay);
+ tab = strdup(buf);
+ }
+ else
+ tab = strdup("\t");
+ if (init_tabs == 0 && has_hardware_tabs == 1)
+ init_tabs = 8;
+ if (key_backspace == NULL)
+ key_backspace = strdup("\b");
+ if (key_left == NULL)
+ key_left = strdup("\b");
+ if (key_down == NULL)
+ key_down = strdup("\n");
+ if (gnu_has_meta_key == 1 && has_meta_key == 0)
+ has_meta_key = 1;
+ cur_term = save;
+}
diff --git a/lib/libtermlib/findcap.c b/lib/libtermlib/findcap.c
new file mode 100644
index 00000000000..848625b7506
--- /dev/null
+++ b/lib/libtermlib/findcap.c
@@ -0,0 +1,64 @@
+/* $OpenBSD: findcap.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: findcap.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "term.private.h"
+
+static int compare __P((const void *, const void *));
+
+/*
+ * Compare routine for bsearch(); see if the current entry matches
+ * the one we want
+ */
+static int
+compare(p1, p2)
+ const void *p1;
+ const void *p2;
+{
+ return strcmp((const char *)p1, ((const struct xtoidx *)p2)->name);
+}
+
+/*
+ * Given a termcap capability name, find the structure describing it.
+ * Note that the capability list _must_ be sorted
+ */
+struct xtoidx *
+_ti_findcap(capname)
+ const char *capname;
+{
+ return bsearch(capname, _ti_captoidx, _ti_numcaps, sizeof(struct xtoidx), compare);
+}
diff --git a/lib/libtermlib/findinfo.c b/lib/libtermlib/findinfo.c
new file mode 100644
index 00000000000..909e87db91b
--- /dev/null
+++ b/lib/libtermlib/findinfo.c
@@ -0,0 +1,64 @@
+/* $OpenBSD: findinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: findinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "term.private.h"
+
+static int compare __P((const void *, const void *));
+
+/*
+ * Compare routine for bsearch(); see if the current entry matches
+ * the one we want
+ */
+static int
+compare(p1, p2)
+ const void *p1;
+ const void *p2;
+{
+ return strcmp((const char *)p1, ((const struct xtoidx *)p2)->name);
+}
+
+/*
+ * Given a terminfo capability name, find the structure describing it.
+ * Note that the capability list _must_ be sorted
+ */
+struct xtoidx *
+_ti_findinfo(capname)
+ const char *capname;
+{
+ return bsearch(capname, _ti_infotoidx, _ti_numinfos, sizeof(struct xtoidx), compare);
+}
diff --git a/lib/libtermlib/getterm.c b/lib/libtermlib/getterm.c
new file mode 100644
index 00000000000..f2c8c0a9b10
--- /dev/null
+++ b/lib/libtermlib/getterm.c
@@ -0,0 +1,237 @@
+/* $OpenBSD: getterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: getterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include "term.h"
+#include "term.private.h"
+#include "pathnames.h"
+
+#define PVECSIZ 32
+
+TERMINAL *cur_term;
+char *_ti_buf;
+char *UP;
+char *BC;
+char PC;
+int LINES, COLS, TABSIZE;
+
+static int _ti_use_env = TRUE;
+
+/*
+ * Internal routine to read in a terminal description.
+ * Currently supports reading from termcap files and databases
+ * only; should be extended to also support reading from binary
+ * terminfo files
+ *
+ * Will also set up global variables for compatibility with old
+ * termcap routines, as well as populate cur_term's capability
+ * variables. If called from the termcap tgetent() compatibility
+ * routine, it will copy the termcap entry into the buffer
+ * provided to that routine. Note that no other code in this
+ * library depends on the termcap entry being kept
+ */
+int
+_ti_getterm(name)
+ const char *name;
+{
+ register char *p;
+ register char *cp;
+ char *dummy;
+ char **fname;
+ char *home;
+ int i;
+ char pathbuf[MAXPATHLEN]; /* holds raw path of filenames */
+ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
+ char *termpath;
+ long num;
+#ifdef TIOCGWINSZ
+ struct winsize winsz;
+#endif
+
+ fname = pathvec;
+ p = pathbuf;
+ cp = getenv("TERMCAP");
+ /*
+ * TERMCAP can have one of two things in it. It can be the
+ * name of a file to use instead of /etc/termcap. In this
+ * case it better start with a "/". Or it can be an entry to
+ * use so we don't have to read the file. In this case it
+ * has to already have the newlines crunched out. If TERMCAP
+ * does not hold a file name then a path of names is searched
+ * instead. The path is found in the TERMPATH variable, or
+ * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
+ */
+ if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */
+ if ((termpath = getenv("TERMPATH")) != NULL)
+ strncpy(pathbuf, termpath, MAXPATHLEN);
+ else {
+ if ((home = getenv("HOME")) != NULL) {
+ /* set up default */
+ p += strlen(home); /* path, looking in */
+ strcpy(pathbuf, home); /* $HOME first */
+ *p++ = '/';
+ } /* if no $HOME look in current directory */
+ strncpy(p, _PATH_DEF, MAXPATHLEN - (p - pathbuf));
+ }
+ }
+ else /* user-defined name in TERMCAP */
+ strncpy(pathbuf, cp, MAXPATHLEN); /* still can be tokenized */
+
+ *fname++ = pathbuf; /* tokenize path into vector of names */
+ while (*++p)
+ if (*p == ' ' || *p == ':') {
+ *p = '\0';
+ while (*++p)
+ if (*p != ' ' && *p != ':')
+ break;
+ if (*p == '\0')
+ break;
+ *fname++ = p;
+ if (fname >= pathvec + PVECSIZ) {
+ fname--;
+ break;
+ }
+ }
+ *fname = (char *) 0; /* mark end of vector */
+ if (cp && *cp && *cp != '/')
+ if (cgetset(cp) < 0)
+ return (-2);
+
+ dummy = NULL;
+ i = cgetent(&dummy, pathvec, (char *)name);
+
+ if (i == 0) {
+ char *s;
+
+ if ((s = home = strchr(dummy, ':')) == NULL)
+ cur_term->name = strdup(name);
+ else {
+ *home = '\0';
+ while (s > dummy && *s != '|')
+ s--;
+ if (s > dummy)
+ s++;
+ cur_term->name = strdup(s);
+ *home = ':';
+ }
+ for (i = 0; i < _ti_numcaps; i++) {
+ switch (_ti_captoidx[i].type) {
+ case TYPE_BOOL:
+ if (cgetcap(dummy, (char *)_ti_captoidx[i].name, ':') == NULL)
+ cur_term->bools[_ti_captoidx[i].idx] = 0;
+ else
+ cur_term->bools[_ti_captoidx[i].idx] = 1;
+ break;
+ case TYPE_NUM:
+ if (cgetnum(dummy, (char *)_ti_captoidx[i].name, &num) < 0)
+ cur_term->nums[_ti_captoidx[i].idx] = 0;
+ else
+ cur_term->nums[_ti_captoidx[i].idx] = (int)num;
+ break;
+ case TYPE_STR:
+ if (cgetstr(dummy, (char *)_ti_captoidx[i].name, &s) < 0)
+ cur_term->strs[_ti_captoidx[i].idx] = NULL;
+ else {
+ cur_term->strs[_ti_captoidx[i].idx] = _ti_captoinfo(s);
+ free(s);
+ }
+ break;
+ }
+ }
+ _ti_fillcap(cur_term);
+ if (_ti_buf)
+ strcpy(_ti_buf, dummy);
+ UP = cursor_up;
+ BC = backspace_if_not_bs;
+ PC = pad_char ? pad_char[0] : '\0';
+ i = 0;
+
+ LINES = lines;
+ COLS = columns;
+ TABSIZE = init_tabs;
+ if (TABSIZE == 0)
+ TABSIZE = 8;
+ init_tabs = TABSIZE;
+ if (_ti_use_env) {
+#ifdef TIOCGWINSZ
+ /*
+ * get the current window size, overrides entries in termcap
+ */
+ if (ioctl(cur_term->fd, TIOCGWINSZ, &winsz) >= 0) {
+ if (winsz.ws_row > 0)
+ LINES = winsz.ws_row;
+ if (winsz.ws_col > 0)
+ COLS = winsz.ws_col;
+ }
+#endif
+ /*
+ * LINES and COLS environment variables overrides any other
+ * method of getting the terminal window size
+ */
+ if ((s = getenv("LINES")) != NULL)
+ LINES = atoi(s);
+ if ((s = getenv("COLS")) != NULL)
+ COLS = atoi(s);
+ }
+ lines = LINES;
+ columns = COLS;
+ }
+
+ /* We are done with the returned termcap buffer now; free it */
+ if (dummy)
+ free(dummy);
+
+ /* we found a "tc" reference loop, return error */
+ if (i == -3)
+ return (-1);
+
+ return (i + 1);
+}
+
+/*
+ * Allows the calling program to not have the window size or
+ * environment variables LINES and COLS override the termcap
+ * or terminfo lines/columns specifications
+ */
+void
+use_env(flag)
+ int flag;
+{
+ _ti_use_env = flag;
+}
diff --git a/lib/libtermlib/mkcaps.sh b/lib/libtermlib/mkcaps.sh
new file mode 100644
index 00000000000..0387a871599
--- /dev/null
+++ b/lib/libtermlib/mkcaps.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+#
+# $OpenBSD: mkcaps.sh,v 1.1 1996/05/31 05:40:02 tholo Exp $
+#
+# Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by SigmaSoft, Th. Lockert.
+# 4. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+cat $1
+awk -- '
+$1 == "bool" {
+ printf "#define\t%-30s\t(cur_term->bools[%d])\n", $2, boolcnt++
+ }
+$1 == "num" {
+ printf "#define\t%-30s\t(cur_term->nums[%d])\n", $2, numcnt++
+ }
+$1 == "str" {
+ printf "#define\t%-30s\t(cur_term->strs[%d])\n", $2, strcnt++
+ }
+
+END {
+ printf "\n#define\t_tBoolCnt\t%d\n", boolcnt
+ printf "#define\t_tNumCnt\t%d\n", numcnt
+ printf "#define\t_tStrCnt\t%d\n", strcnt
+ }
+' < $2
+cat $3
+
+exit 0
diff --git a/lib/libtermlib/mkinfo.c b/lib/libtermlib/mkinfo.c
new file mode 100644
index 00000000000..acb019d45de
--- /dev/null
+++ b/lib/libtermlib/mkinfo.c
@@ -0,0 +1,269 @@
+/* $OpenBSD: mkinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: mkinfo.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+#include "term.private.h"
+
+int main __P((int, char *[]));
+int caporder __P((const void *, const void *));
+int infoorder __P((const void *, const void *));
+
+struct caps {
+ int type;
+ int index;
+ char *name;
+ char *info;
+ char *cap;
+};
+
+/*
+ * Create sorted capability lists and other data files needed
+ * for the terminfo library
+ */
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char *line, *type, *name, *info, *cap;
+ int numbool, numnum, numstr;
+ int binbool, binnum, binstr;
+ int i, maxcaps, numcaps;
+ struct caps *cp;
+ size_t len;
+ FILE *fp;
+
+ if (argc != 2)
+ errx(1, "Usage: mkinfo Capabilities");
+ if ((fp = fopen(argv[1], "r")) == NULL)
+ err(1, "Could not open '%s' for read", argv[1]);
+ numbool = numnum = numstr = numcaps = 0;
+ binbool = binnum = binstr = -1;
+ cp = calloc(sizeof(struct caps), maxcaps = 32);
+ while ((line = fgetln(fp, &len)) != NULL && len > 0) {
+ if (line[len - 1] != '\n') {
+ warnx("Last input line bad");
+ continue;
+ }
+ line[len - 1] = '\0';
+ if (strncmp(line, "#endbinary", 10) == 0) {
+ binbool = numbool;
+ binnum = numnum;
+ binstr = numstr;
+ }
+ if (line[0] == '\0' || line[0] == '#')
+ continue;
+ if ((type = strtok(line, " \t")) == NULL) {
+ warnx("Bad input line");
+ continue;
+ }
+ if ((name = strtok(NULL, " \t")) == NULL) {
+ warnx("Bad input line");
+ continue;
+ }
+ if ((info = strtok(NULL, " \t")) == NULL) {
+ warnx("Bad input line");
+ continue;
+ }
+ if ((cap = strtok(NULL, " \t")) == NULL) {
+ warnx("Bad input line");
+ continue;
+ }
+ if (strcmp(type, "bool") == 0) {
+ cp[numcaps].type = TYPE_BOOL;
+ cp[numcaps].index = numbool++;
+ }
+ else if (strcmp(type, "num") == 0) {
+ cp[numcaps].type = TYPE_NUM;
+ cp[numcaps].index = numnum++;
+ }
+ else if (strcmp(type, "str") == 0) {
+ cp[numcaps].type = TYPE_STR;
+ cp[numcaps].index = numstr++;
+ }
+ else {
+ warnx("Bad type '%s' encountered", type);
+ continue;
+ }
+ cp[numcaps].name = strdup(name);
+ cp[numcaps].info = strdup(info);
+ cp[numcaps++].cap = strdup(cap);
+ if (numcaps == maxcaps) {
+ maxcaps <<= 1;
+ if ((cp = realloc(cp, maxcaps * sizeof(struct caps))) == NULL)
+ errx(1, "Out of memory");
+ }
+ }
+ fclose(fp);
+
+ if ((fp = fopen("boolnames.c", "w")) == NULL)
+ err(1, "Could not open 'boolnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const boolnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_BOOL)
+ fprintf(fp, "\t\"%s\",\n", cp[i].name);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("boolcodes.c", "w")) == NULL)
+ err(1, "Could not open 'boolcodes.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const boolcodes[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_BOOL)
+ fprintf(fp, "\t\"%s\",\n", cp[i].info);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("boolfnames.c", "w")) == NULL)
+ err(1, "Could not open 'boolfnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const boolfnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_BOOL)
+ fprintf(fp, "\t\"%s\",\n", cp[i].cap);
+ fprintf(fp, "};\n");
+ fclose(fp);
+
+ if ((fp = fopen("numnames.c", "w")) == NULL)
+ err(1, "Could not open 'numnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const numnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_NUM)
+ fprintf(fp, "\t\"%s\",\n", cp[i].name);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("numcodes.c", "w")) == NULL)
+ err(1, "Could not open 'numcodes.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const numcodes[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_NUM)
+ fprintf(fp, "\t\"%s\",\n", cp[i].info);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("numfnames.c", "w")) == NULL)
+ err(1, "Could not open 'numfnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const numfnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_NUM)
+ fprintf(fp, "\t\"%s\",\n", cp[i].cap);
+ fprintf(fp, "};\n");
+ fclose(fp);
+
+ if ((fp = fopen("strnames.c", "w")) == NULL)
+ err(1, "Could not open 'strnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const strnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_STR)
+ fprintf(fp, "\t\"%s\",\n", cp[i].name);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("strcodes.c", "w")) == NULL)
+ err(1, "Could not open 'strcodes.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const strcodes[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_STR)
+ fprintf(fp, "\t\"%s\",\n", cp[i].info);
+ fprintf(fp, "};\n");
+ fclose(fp);
+ if ((fp = fopen("strfnames.c", "w")) == NULL)
+ err(1, "Could not open 'strfnames.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "const char * const strfnames[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ if (cp[i].type == TYPE_STR)
+ fprintf(fp, "\t\"%s\",\n", cp[i].cap);
+ fprintf(fp, "};\n");
+ fclose(fp);
+
+ qsort(cp, numcaps, sizeof(struct caps), caporder);
+ if ((fp = fopen("captoidx.c", "w")) == NULL)
+ err(1, "Could not open 'captoidx.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "#include <stdlib.h>\n\n");
+ fprintf(fp, "#include \"term.private.h\"\n\n");
+ fprintf(fp, "const struct xtoidx _ti_captoidx[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ fprintf(fp, "\t{ \"%s\",\t%d,\t%d },\n", cp[i].cap, cp[i].index, cp[i].type);
+ fprintf(fp, "};\n\n");
+ fprintf(fp, "size_t _ti_numcaps = %d;\n", numcaps);
+ fclose(fp);
+
+ qsort(cp, numcaps, sizeof(struct caps), infoorder);
+ if ((fp = fopen("infotoidx.c", "w")) == NULL)
+ err(1, "Could not open 'infotoidx.c' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "#include <stdlib.h>\n\n");
+ fprintf(fp, "#include \"term.private.h\"\n\n");
+ fprintf(fp, "const struct xtoidx _ti_infotoidx[] = {\n");
+ for (i = 0; i < numcaps; i++)
+ fprintf(fp, "\t{ \"%s\",\t%d,\t%d },\n", cp[i].info, cp[i].index, cp[i].type);
+ fprintf(fp, "};\n\n");
+ fprintf(fp, "size_t _ti_numinfos = %d;\n", numcaps);
+ fclose(fp);
+
+ if ((fp = fopen("binaries.h", "w")) == NULL)
+ err(1, "Could not open 'binaries.h' for writing");
+ fprintf(fp, "/* This file automatically generated. Do not edit. */\n\n");
+ fprintf(fp, "#define BIN_BOOL_CNT\t%d\n", binbool);
+ fprintf(fp, "#define BIN_NUM_CNT\t%d\n", binnum);
+ fprintf(fp, "#define BIN_STR_CNT\t%d\n", binstr);
+ fclose(fp);
+ exit(0);
+}
+
+int
+caporder(p1, p2)
+ const void *p1;
+ const void *p2;
+{
+ return strcmp(((struct caps *)p1)->cap, ((struct caps *)p2)->cap);
+}
+
+int
+infoorder(p1, p2)
+ const void *p1;
+ const void *p2;
+{
+ return strcmp(((struct caps *)p1)->info, ((struct caps *)p2)->info);
+}
diff --git a/lib/libtermlib/mvcur.c b/lib/libtermlib/mvcur.c
new file mode 100644
index 00000000000..b18fc29d68a
--- /dev/null
+++ b/lib/libtermlib/mvcur.c
@@ -0,0 +1,111 @@
+/* $OpenBSD: mvcur.c,v 1.1 1996/05/31 05:40:01 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: mvcur.c,v 1.1 1996/05/31 05:40:01 tholo Exp $";
+#endif
+
+#include <string.h>
+#include "term.h"
+
+/*
+ * Optimized cursor movement, assume cursor is currently
+ * located at (oldx,oldy), output what is needed for the
+ * cursor to be relocated to (newx,newy)
+ */
+int
+mvcur(oldy, oldx, newy, newx)
+ int oldy;
+ int oldx;
+ int newy;
+ int newx;
+{
+ int l, c;
+ char *p;
+
+ if (newx >= columns) {
+ newy += newx / columns;
+ newx %= columns;
+ }
+ if (oldx >= columns) {
+ l = (oldx + 1) / columns;
+ oldy += l;
+ oldx %= columns;
+ if (!auto_right_margin) {
+ while (l > 0) {
+ if (rawmode())
+ if (carriage_return != NULL)
+ tputs(carriage_return, 0, _ti_outc);
+ else
+ _ti_outc('\r');
+ if (linefeed_if_not_lf != NULL)
+ tputs(linefeed_if_not_lf, 0, _ti_outc);
+ else
+ _ti_outc('\n');
+ l--;
+ }
+ oldx = 0;
+ }
+ if (oldy >= lines - 1) {
+ newy -= oldy - (lines - 1);
+ oldy = lines - 1;
+ }
+ }
+ if (newy >= lines) {
+ l = newy;
+ newy = lines - 1;
+ if (oldy < lines - 1) {
+ c = newx;
+ if (cursor_address == NULL)
+ newx = 0;
+ mvcur(oldy, oldx, newy, newx);
+ newx = c;
+ }
+ while (l >= lines) {
+ if (linefeed_if_not_lf != NULL)
+ tputs(linefeed_if_not_lf, 0, _ti_outc);
+ else
+ _ti_outc('\n');
+ l--;
+ oldx = 0;
+ }
+ }
+ if (newy < oldy && !(cursor_address != NULL || cursor_up != NULL))
+ newy = oldy;
+ if (cursor_address != NULL) {
+ p = tparm(cursor_address, newx, newy);
+ tputs(p, 0, _ti_outc);
+ }
+ else
+ return ERR;
+ return OK;
+}
diff --git a/lib/libtermlib/outc.c b/lib/libtermlib/outc.c
new file mode 100644
index 00000000000..e4d0f2af9bc
--- /dev/null
+++ b/lib/libtermlib/outc.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: outc.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: outc.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdio.h>
+#include "term.h"
+#include "term.private.h"
+
+/*
+ * Character output routine suitable for use as argument to
+ * tputs() and vidputs() routines
+ *
+ * Always uses standard out as output
+ */
+int
+_ti_outc(c)
+ int c;
+{
+ putc(c, stdout);
+ if (ferror(stdout))
+ return ERR;
+ return OK;
+}
diff --git a/lib/libtermlib/pathnames.h b/lib/libtermlib/pathnames.h
new file mode 100644
index 00000000000..e8a0f4c225d
--- /dev/null
+++ b/lib/libtermlib/pathnames.h
@@ -0,0 +1,33 @@
+/* $OpenBSD: pathnames.h,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _PATH_DEF ".termcap /usr/share/misc/termcap"
diff --git a/lib/libtermlib/putp.c b/lib/libtermlib/putp.c
new file mode 100644
index 00000000000..e8ee8ce9fe8
--- /dev/null
+++ b/lib/libtermlib/putp.c
@@ -0,0 +1,51 @@
+/* $OpenBSD: putp.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: putp.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+#undef putp
+
+/*
+ * Simple wrapper for the most common usage of tputs()
+ */
+int
+putp(str)
+ const char *str;
+{
+ return tputs(str, 1, _ti_outc);
+}
diff --git a/lib/libtermlib/reset_prog_mode.c b/lib/libtermlib/reset_prog_mode.c
new file mode 100644
index 00000000000..4094b97166e
--- /dev/null
+++ b/lib/libtermlib/reset_prog_mode.c
@@ -0,0 +1,48 @@
+/* $OpenBSD: reset_prog_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: reset_prog_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "term.h"
+
+/*
+ * Reset program mode as previously saved with def_prog_mode()
+ */
+int
+reset_prog_mode()
+{
+ return (tcsetattr(cur_term->fd, TCSADRAIN, &cur_term->pmode) == 0) ? OK : ERR;
+}
diff --git a/lib/libtermlib/reset_shell_mode.c b/lib/libtermlib/reset_shell_mode.c
new file mode 100644
index 00000000000..a903464792e
--- /dev/null
+++ b/lib/libtermlib/reset_shell_mode.c
@@ -0,0 +1,48 @@
+/* $OpenBSD: reset_shell_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: reset_shell_mode.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "term.h"
+
+/*
+ * Reset shell mode as previously saved with def_shell_mode()
+ */
+int
+reset_shell_mode()
+{
+ return (tcsetattr(cur_term->fd, TCSADRAIN, &cur_term->smode) == 0) ? OK : ERR;
+}
diff --git a/lib/libtermlib/restartterm.c b/lib/libtermlib/restartterm.c
new file mode 100644
index 00000000000..4c9801632e5
--- /dev/null
+++ b/lib/libtermlib/restartterm.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: restartterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: restartterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include "term.h"
+
+/*
+ * Reinitialize terminal setup after a restart, eg. with the use
+ * of undump
+ *
+ * The terminal and speed may have changed, but it is assumed that
+ * the size of the terminal remain constant
+ */
+int
+restartterm(name, fd, errret)
+ const char *name;
+ int fd;
+ int *errret;
+{
+ struct termios pmode, smode;
+ int r, l, c;
+
+ pmode = cur_term->pmode;
+ smode = cur_term->smode;
+ l = lines;
+ c = columns;
+ r = setupterm(name, fd, errret);
+ cfsetspeed(&pmode, cur_term->baudrate);
+ cfsetspeed(&smode, cur_term->baudrate);
+ cur_term->pmode = pmode;
+ cur_term->smode = smode;
+ lines = l;
+ columns = c;
+ return r;
+}
diff --git a/lib/libtermlib/set_curterm.c b/lib/libtermlib/set_curterm.c
new file mode 100644
index 00000000000..4e67496cab0
--- /dev/null
+++ b/lib/libtermlib/set_curterm.c
@@ -0,0 +1,51 @@
+/* $OpenBSD: set_curterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: set_curterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include "term.h"
+
+/*
+ * Set the current terminal description being used. Return
+ * the one that was in use prior to us being called
+ */
+TERMINAL *
+set_curterm(term)
+ TERMINAL *term;
+{
+ TERMINAL *oterm = cur_term;
+
+ cur_term = term;
+ return oterm;
+}
diff --git a/lib/libtermlib/setterm.c b/lib/libtermlib/setterm.c
new file mode 100644
index 00000000000..d54eef2247c
--- /dev/null
+++ b/lib/libtermlib/setterm.c
@@ -0,0 +1,50 @@
+/* $OpenBSD: setterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: setterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+
+#undef setterm
+
+/*
+ * Compatibility routine; just calls setupterm()
+ */
+int
+setterm(name)
+ const char *name;
+{
+ return setupterm(name, 1, NULL);
+}
diff --git a/lib/libtermlib/setupterm.c b/lib/libtermlib/setupterm.c
new file mode 100644
index 00000000000..d1da3c58b76
--- /dev/null
+++ b/lib/libtermlib/setupterm.c
@@ -0,0 +1,82 @@
+/* $OpenBSD: setupterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: setupterm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include "term.h"
+#include "term.private.h"
+
+extern char *_ti_buf;
+
+/*
+ * Called to set up a terminal description for the named
+ * terminal. If no terminal is named, attempt to use the
+ * one named in the TERM environment variable
+ *
+ * If an error is encountered, return it in *errstat if
+ * set. If not set, abort with an error message
+ */
+int
+setupterm(name, fd, errstat)
+ const char *name;
+ int fd;
+ int *errstat;
+{
+ int ret;
+
+ if (name == NULL)
+ name = getenv("TERM");
+ _ti_buf = NULL;
+ if (cur_term != NULL)
+ del_curterm(cur_term);
+ if ((cur_term = calloc(sizeof(TERMINAL), 1)) == NULL)
+ errx(1, "No memory for terminal description");
+ if (fd == STDOUT_FILENO && !isatty(fd))
+ fd = STDERR_FILENO;
+ cur_term->fd = fd;
+ ret = _ti_getterm(name);
+ if (errstat == NULL && ret < 1) {
+ if (ret < 0)
+ errx(1, "Terminal description database could not be found");
+ else
+ errx(1, "Terminal type not found");
+ }
+ else if (errstat != NULL)
+ *errstat = (ret == 1) ? OK : ERR;
+ (void) _ti_tty_init();
+ return ret == 1 ? OK : ERR;
+}
diff --git a/lib/libtermlib/shlib_version b/lib/libtermlib/shlib_version
new file mode 100644
index 00000000000..1edea46de91
--- /dev/null
+++ b/lib/libtermlib/shlib_version
@@ -0,0 +1,2 @@
+major=1
+minor=0
diff --git a/lib/libtermlib/term.h.head b/lib/libtermlib/term.h.head
new file mode 100644
index 00000000000..16b457ca301
--- /dev/null
+++ b/lib/libtermlib/term.h.head
@@ -0,0 +1,38 @@
+/* $OpenBSD: term.h.head,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _TERM_H_
+#define _TERM_H_
+
+#include <termios.h>
+#include <sys/ioctl.h>
+
diff --git a/lib/libtermlib/term.h.tail b/lib/libtermlib/term.h.tail
new file mode 100644
index 00000000000..d3724d4d811
--- /dev/null
+++ b/lib/libtermlib/term.h.tail
@@ -0,0 +1,124 @@
+
+/* $OpenBSD: term.h.tail,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ */
+
+typedef struct _terminal {
+ int fd;
+ speed_t baudrate;
+ struct termios pmode;
+ struct termios smode;
+ char *name;
+ char bools[_tBoolCnt];
+ short nums[_tNumCnt];
+ char *strs[_tStrCnt];
+} TERMINAL;
+
+#define Filedes fd
+#define Ottyb smode
+#define Nttyb pmode
+#define TTY struct termios
+
+#ifndef _CHTYPE_T_
+#define _CHTYPE_T_ unsigned long
+typedef _CHTYPE_T_ chtype;
+#endif
+
+#undef fixterm
+#undef putp
+#undef resetterm
+#undef setterm
+#undef vidattr
+
+__BEGIN_DECLS
+extern const char * const boolnames[];
+extern const char * const boolcodes[];
+extern const char * const boolfnames[];
+extern const char * const numnames[];
+extern const char * const numcodes[];
+extern const char * const numfnames[];
+extern const char * const strnames[];
+extern const char * const strcodes[];
+extern const char * const strfnames[];
+
+extern int LINES;
+extern int COLS;
+extern int TABSIZE;
+extern TERMINAL *cur_term;
+
+int def_prog_mode __P((void));
+int def_shell_mode __P((void));
+int del_curterm __P((TERMINAL *));
+int mvcur __P((int, int, int, int));
+int putp __P((const char *));
+int reset_prog_mode __P((void));
+int reset_shell_mode __P((void));
+int restartterm __P((const char *, int, int *));
+int setupterm __P((const char *, int, int *));
+int setterm __P((const char *));
+TERMINAL *set_curterm __P((TERMINAL *));
+int tigetflag __P((const char *));
+int tigetnum __P((const char *));
+char *tigetstr __P((const char *));
+char *tparm __P((const char *, ...));
+int tputs __P((const char *, int, int (*)(int)));
+int tgetent __P((char *, const char *));
+int tgetflag __P((const char *));
+int tgetnum __P((const char *));
+char *tgetstr __P((const char *, char **));
+char *tgoto __P((const char *, int, int));
+void use_env __P((int));
+int vidattr __P((chtype));
+int vidputs __P((chtype, int (*)(int)));
+
+int _ti_outc __P((int));
+__END_DECLS
+
+#define fixterm() reset_prog_mode()
+#define putp(s) tputs(s, 1, _ti_outc)
+#define resetterm() reset_shell_mode()
+#define setterm(term) setupterm(term, 1, (int *)0)
+#define vidattr(s) vidputs(s, _ti_outc)
+
+#ifndef OK
+#define OK (0)
+#endif /* OK */
+
+#ifndef ERR
+#define ERR (-1)
+#endif /* ERR */
+
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#ifndef A_ATTRIBUTES
+#define A_ATTRIBUTES 0xffffff00
+#define A_NORMAL 0x00000000
+#define A_STANDOUT 0x00010000
+#define A_UNDERLINE 0x00020000
+#define A_REVERSE 0x00040000
+#define A_BLINK 0x00080000
+#define A_DIM 0x00100000
+#define A_BOLD 0x00200000
+#define A_ALTCHARSET 0x00400000
+#define A_INVIS 0x00800000
+#define A_PROTECT 0x01000000
+#define A_HORIZONTAL 0x02000000
+#define A_LEFT 0x04000000
+#define A_LOW 0x08000000
+#define A_RIGHT 0x10000000
+#define A_TOP 0x20000000
+#define A_VERTICAL 0x40000000
+#define A_CHARTEXT 0x000000ff
+#define A_COLOR 0x0000ff00
+#endif
+
+#endif /* _TERM_H_ */
diff --git a/lib/libtermlib/term.private.h b/lib/libtermlib/term.private.h
new file mode 100644
index 00000000000..3cd828c3ca5
--- /dev/null
+++ b/lib/libtermlib/term.private.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: term.private.h,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+struct xtoidx {
+ const char *name;
+ int idx;
+ int type;
+};
+
+struct _terminal;
+
+#define TYPE_BOOL 0
+#define TYPE_NUM 1
+#define TYPE_STR 2
+
+__BEGIN_DECLS
+extern const struct xtoidx _ti_captoidx[];
+extern const struct xtoidx _ti_infotoidx[];
+extern size_t _ti_numcaps;
+extern size_t _ti_numinfos;
+
+struct xtoidx *_ti_findcap __P((const char *));
+struct xtoidx *_ti_findinfo __P((const char *));
+int _ti_getterm __P((const char *));
+int _ti_tty_init __P((void));
+char *_ti_captoinfo __P((const char *));
+void _ti_fillcap __P((struct _terminal *));
+__END_DECLS
diff --git a/lib/libtermlib/tgetent.c b/lib/libtermlib/tgetent.c
new file mode 100644
index 00000000000..3d46c50167c
--- /dev/null
+++ b/lib/libtermlib/tgetent.c
@@ -0,0 +1,62 @@
+/* $OpenBSD: tgetent.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tgetent.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include "term.h"
+#include "term.private.h"
+
+extern char *_ti_buf;
+
+int
+tgetent(bp, name)
+ char *bp;
+ const char *name;
+{
+ _ti_buf = bp;
+ if (cur_term != NULL)
+ del_curterm(cur_term);
+ cur_term = calloc(sizeof(TERMINAL), 1);
+ if ((cur_term = calloc(sizeof(TERMINAL), 1)) == NULL)
+ errx(1, "No memory for terminal description");
+ if (isatty(STDOUT_FILENO))
+ cur_term->fd = STDOUT_FILENO;
+ else
+ cur_term->fd = STDERR_FILENO;
+ (void)_ti_tty_init();
+ return _ti_getterm(name);
+}
diff --git a/lib/libtermlib/tgetflag.c b/lib/libtermlib/tgetflag.c
new file mode 100644
index 00000000000..0be4e6e9fae
--- /dev/null
+++ b/lib/libtermlib/tgetflag.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: tgetflag.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tgetflag.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+int
+tgetflag(entry)
+ const char *entry;
+{
+ struct xtoidx *p = _ti_findcap(entry);
+
+ if (p != NULL && p->type != TYPE_BOOL)
+ return -1;
+ if (p == NULL)
+ return 0;
+ return cur_term->bools[p->idx];
+}
diff --git a/lib/libtermlib/tgetnum.c b/lib/libtermlib/tgetnum.c
new file mode 100644
index 00000000000..3029c2ce344
--- /dev/null
+++ b/lib/libtermlib/tgetnum.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: tgetnum.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tgetnum.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+int
+tgetnum(entry)
+ const char *entry;
+{
+ struct xtoidx *p = _ti_findcap(entry);
+
+ if (p != NULL && p->type != TYPE_NUM)
+ return -2;
+ if (p == NULL)
+ return -1;
+ return cur_term->nums[p->idx];
+}
diff --git a/lib/libtermlib/tgetstr.c b/lib/libtermlib/tgetstr.c
new file mode 100644
index 00000000000..be832d0e45c
--- /dev/null
+++ b/lib/libtermlib/tgetstr.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: tgetstr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tgetstr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <string.h>
+#include "term.h"
+#include "term.private.h"
+
+char *
+tgetstr(entry, area)
+ const char *entry;
+ char **area;
+{
+ struct xtoidx *p = _ti_findcap(entry);
+ char *s;
+
+ if (p != NULL && p->type != TYPE_STR)
+ return NULL;
+ if (p == NULL)
+ return NULL;
+ if ((s = cur_term->strs[p->idx]) == NULL)
+ return NULL;
+ strcpy(*area, s);
+ *area += strlen(s) + 1;
+ return s;
+}
diff --git a/lib/libtermlib/tgoto.c b/lib/libtermlib/tgoto.c
new file mode 100644
index 00000000000..b497f5da07e
--- /dev/null
+++ b/lib/libtermlib/tgoto.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: tgoto.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tgoto.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "term.h"
+
+char *
+tgoto(CM, col, line)
+ const char *CM;
+ int col, line;
+{
+ return tparm(CM, col, line);
+}
diff --git a/lib/libtermlib/tigetflag.c b/lib/libtermlib/tigetflag.c
new file mode 100644
index 00000000000..85fffa45319
--- /dev/null
+++ b/lib/libtermlib/tigetflag.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: tigetflag.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tigetflag.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+int
+tigetflag(entry)
+ const char *entry;
+{
+ struct xtoidx *p = _ti_findinfo(entry);
+
+ if (p != NULL && p->type != TYPE_BOOL)
+ return -1;
+ if (p == NULL)
+ return 0;
+ return cur_term->bools[p->idx];
+}
diff --git a/lib/libtermlib/tigetnum.c b/lib/libtermlib/tigetnum.c
new file mode 100644
index 00000000000..b5826378bb6
--- /dev/null
+++ b/lib/libtermlib/tigetnum.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: tigetnum.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tigetnum.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+int
+tigetnum(entry)
+ const char *entry;
+{
+ struct xtoidx *p = _ti_findinfo(entry);
+
+ if (p != NULL && p->type != TYPE_NUM)
+ return -2;
+ if (p == NULL)
+ return -1;
+ return cur_term->nums[p->idx];
+}
diff --git a/lib/libtermlib/tigetstr.c b/lib/libtermlib/tigetstr.c
new file mode 100644
index 00000000000..699d2e4191e
--- /dev/null
+++ b/lib/libtermlib/tigetstr.c
@@ -0,0 +1,52 @@
+/* $OpenBSD: tigetstr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tigetstr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+#include "term.private.h"
+
+char *
+tigetstr(entry)
+ const char *entry;
+{
+ struct xtoidx *p = _ti_findinfo(entry);
+
+ if (p != NULL && p->type != TYPE_STR)
+ return (char *)-1;
+ if (p == NULL)
+ return NULL;
+ return cur_term->strs[p->idx];
+}
diff --git a/lib/libtermlib/tparm.c b/lib/libtermlib/tparm.c
new file mode 100644
index 00000000000..f803e23661f
--- /dev/null
+++ b/lib/libtermlib/tparm.c
@@ -0,0 +1,362 @@
+/* $OpenBSD: tparm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tparm.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <string.h>
+#include <ctype.h>
+
+#ifdef MAX
+#undef MAX
+#endif
+
+#define MAX(a, b) ((a) < (b) ? (b) : (a))
+
+#define STKSIZ 32
+
+static __inline void push __P((int));
+static __inline int popnum __P((void));
+static __inline char *popstr __P((void));
+
+static char *_tparm __P((const char *, char *, size_t, va_list));
+
+static union {
+ unsigned int num;
+ char *str;
+} stack[STKSIZ];
+
+static int stackidx;
+
+static __inline void
+push(value)
+ int value;
+{
+ if (stackidx < STKSIZ)
+ stack[stackidx++].num = value;
+}
+
+static __inline int
+popnum()
+{
+ return stackidx > 0 ? stack[--stackidx].num : 0;
+}
+
+static __inline char *
+popstr()
+{
+ return stackidx > 0 ? stack[--stackidx].str : NULL;
+}
+
+static char *
+_tparm(str, buf, len, ap)
+ const char *str;
+ char *buf;
+ size_t len;
+ va_list ap;
+{
+ int param[10], variable[26];
+ int pops, num, i, level, incr;
+ const char *p;
+ char *bufp;
+
+ if (str == NULL)
+ return NULL;
+
+ for (p = str, pops = 0, num = 0, incr = 0; *p != '\0'; p++)
+ if (*p == '%' && *(p + 1) != '\0') {
+ switch (p[1]) {
+ case '%':
+ p++;
+ break;
+ case 'i':
+ if (pops < 2)
+ pops = 2;
+ incr++;
+ break;
+ case 'p':
+ p++;
+ if (isdigit(p[1])) {
+ int n = p[1] - '0';
+
+ if (n > pops)
+ pops = n;
+ }
+ break;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case 'c':
+ case 'd':
+ case 's':
+ num++;
+ break;
+ }
+ }
+
+ for (i = 0; i < MAX(pops, num); i++)
+ param[i] = va_arg(ap, int); /* XXX arg size might be different than int */
+
+ if (pops == 0)
+ for (i = pops = num; i > 0; i--)
+ push(param[i - 1]);
+
+ stackidx = 0;
+ bufp = buf;
+
+ while (*str) {
+ if (*str != '%')
+ *bufp++ = *str;
+ else {
+ switch (*++str) {
+ case '%':
+ *bufp++ = '%';
+ break;
+ case 'd':
+ sprintf(bufp, "%d", popnum());
+ bufp += strlen(bufp);
+ break;
+ case '0':
+ str++;
+ len = *str & 0xFF;
+ if (len == '2' || len == '3') {
+ if (*++str == 'd') {
+ if (len == '2')
+ sprintf(bufp, "%02d", popnum());
+ else
+ sprintf(bufp, "%03d", popnum());
+ bufp += strlen(bufp);
+ }
+ else if (*str == 'x') {
+ if (len == '2')
+ sprintf(bufp, "%02x", popnum());
+ else
+ sprintf(bufp, "%03x", popnum());
+ bufp += strlen(bufp);
+ }
+ }
+ break;
+ case '2':
+ if (*++str == 'd') {
+ sprintf(bufp, "%2d", popnum());
+ bufp += strlen(bufp);
+ }
+ else if (*str == 'x') {
+ sprintf(bufp, "%2x", popnum());
+ bufp += strlen(bufp);
+ }
+ break;
+ case '3':
+ if (*++str == 'd') {
+ sprintf(bufp, "%3d", popnum());
+ bufp += strlen(bufp);
+ }
+ else if (*str == 'x') {
+ sprintf(bufp, "%3x", popnum());
+ bufp += strlen(bufp);
+ }
+ break;
+ case 'c':
+ *bufp++ = (char)popnum();
+ break;
+ case 's':
+ strcpy(bufp, popstr());
+ bufp += strlen(bufp);
+ break;
+ case 'p':
+ str++;
+ if (isdigit(*str))
+ push(param[*str - '1']);
+ break;
+ case 'P':
+ str++;
+ if (islower(*str))
+ variable[*str - 'a'] = popnum();
+ break;
+ case 'g':
+ str++;
+ if (islower(*str))
+ push(variable[*str - 'a']);
+ break;
+ case '\'':
+ push(*++str & 0xFF);
+ str++;
+ break;
+ case '{':
+ num = 0;
+ str++;
+ while (isdigit(*str))
+ num = num * 10 + *str++ - '0';
+ push(num);
+ break;
+ case '+':
+ push(popnum() + popnum());
+ break;
+ case '-':
+ num = popnum();
+ push(popnum() - num);
+ break;
+ case '*':
+ push(popnum() * popnum());
+ break;
+ case '/':
+ num = popnum();
+ push(popnum() / num);
+ break;
+ case 'm':
+ num = popnum();
+ push(popnum() % num);
+ break;
+ case 'A':
+ num = popnum();
+ push(popnum() && num);
+ break;
+ case 'O':
+ num = popnum();
+ push(popnum() || num);
+ break;
+ case '&':
+ push(popnum() & popnum());
+ break;
+ case '|':
+ push(popnum() | popnum());
+ break;
+ case '^':
+ push(popnum() ^ popnum());
+ break;
+ case '=':
+ push(popnum() == popnum());
+ break;
+ case '<':
+ push(popnum() > popnum());
+ break;
+ case '>':
+ push(popnum() < popnum());
+ break;
+ case '!':
+ push(!popnum());
+ break;
+ case '~':
+ push(~popnum());
+ break;
+ case 'i':
+ param[0]++;
+ param[1]++;
+ break;
+ case '?':
+ break;
+ case 't':
+ if (!popnum()) {
+ str++;
+ level = 0;
+ while (*str) {
+ if (*str == '%') {
+ if (*++str == '?')
+ level++;
+ else if (*str == ';') {
+ if (level > 0)
+ level--;
+ else
+ break;
+ }
+ else if (*str == 'e' && level == 0)
+ break;
+ }
+ if (*str)
+ str++;
+ }
+ }
+ break;
+ case 'e':
+ str++;
+ level = 0;
+ while (*str) {
+ if (*str == '%') {
+ if (*++str == '?')
+ level++;
+ else if (*str == ';') {
+ if (level > 0)
+ level--;
+ else
+ break;
+ }
+ else if (*str == 'e' && level == 0)
+ break;
+ }
+ if (*str)
+ str++;
+ }
+ break;
+ case ';':
+ break;
+ default:
+ break;
+ }
+ }
+ if (*str != '\0')
+ str++;
+ }
+
+ *bufp = '\0';
+ return(buf);
+}
+
+char *
+#if __STDC__
+tparm(const char *str, ...)
+#else
+tparm(va_alist)
+ va_dcl
+#endif
+{
+ static char buf[256];
+ va_list ap;
+ char *p;
+#if !__STDC__
+ const char *str;
+
+ va_start(ap);
+ str = va_arg(ap, const char *);
+#else
+ va_start(ap, str);
+#endif
+ p = _tparm(str, buf, sizeof(buf) - 1, ap);
+ va_end(ap);
+ return(p);
+}
diff --git a/lib/libtermlib/tputs.c b/lib/libtermlib/tputs.c
new file mode 100644
index 00000000000..d7fb0a7929a
--- /dev/null
+++ b/lib/libtermlib/tputs.c
@@ -0,0 +1,117 @@
+/* $OpenBSD: tputs.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tputs.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "term.h"
+
+extern char PC;
+
+#undef ospeed
+extern short ospeed;
+
+static short tmspc10[] = {
+ 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
+};
+
+int
+tputs(cp, count, outc)
+ const char *cp;
+ int count;
+ int (*outc) __P((int));
+{
+ register int i = 0;
+ register int mspc10;
+
+ if (cp == 0)
+ return ERR;
+
+ /*
+ * Convert the number representing the delay.
+ */
+ if (isdigit(*cp)) {
+ do
+ i = i * 10 + *cp++ - '0';
+ while (isdigit(*cp));
+ }
+ i *= 10;
+ if (*cp == '.') {
+ cp++;
+ if (isdigit(*cp))
+ i += *cp - '0';
+ /*
+ * Only one digit to the right of the decimal point.
+ */
+ while (isdigit(*cp))
+ cp++;
+ }
+
+ /*
+ * If the delay is followed by a `*', then
+ * multiply by the affected lines count.
+ */
+ if (*cp == '*')
+ cp++, i *= count;
+
+ /*
+ * The guts of the string.
+ */
+ while (*cp)
+ (*outc)(*cp++);
+
+ /*
+ * If no delay needed, or output speed is
+ * not comprehensible, then don't try to delay.
+ */
+ if (i == 0)
+ return OK;
+ if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
+ return OK;
+
+ /*
+ * Round up by a half a character frame,
+ * and then do the delay.
+ * Too bad there are no user program accessible programmed delays.
+ * Transmitting pad characters slows many
+ * terminals down and also loads the system.
+ */
+ mspc10 = tmspc10[ospeed];
+ i += mspc10 / 2;
+ for (i /= mspc10; i > 0; i--)
+ (*outc)(PC);
+ return OK;
+}
diff --git a/lib/libtermlib/tty_init.c b/lib/libtermlib/tty_init.c
new file mode 100644
index 00000000000..f9ef46b445b
--- /dev/null
+++ b/lib/libtermlib/tty_init.c
@@ -0,0 +1,68 @@
+/* $OpenBSD: tty_init.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: tty_init.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <termios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "term.h"
+#include "term.private.h"
+
+static unsigned int tspeed[] = {
+ B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800,
+ B2400, B4800, B9600, B19200, B38400
+};
+
+#undef ospeed
+short ospeed;
+
+/*
+ * Low lever terminal initialization; get current terminal parameters
+ * and save current speed in cur_term and ospeed
+ */
+int
+_ti_tty_init()
+{
+ struct termios ti;
+ int speed, i;
+
+ tcgetattr(cur_term->fd, &ti);
+ cur_term->baudrate = cfgetospeed(&ti);
+ speed = cur_term->baudrate;
+ for (i = 0; i < sizeof(tspeed) / sizeof(tspeed[0]) && speed > tspeed[i] ; i++)
+ ;
+ ospeed = i < sizeof(tspeed) / sizeof(tspeed[0]) ? i : 0;
+ return OK;
+}
diff --git a/lib/libtermlib/vidattr.c b/lib/libtermlib/vidattr.c
new file mode 100644
index 00000000000..fb54cc41529
--- /dev/null
+++ b/lib/libtermlib/vidattr.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: vidattr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: vidattr.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+
+#undef vidattr
+
+int
+vidattr(attrs)
+ chtype attrs;
+{
+ return vidputs(attrs, _ti_outc);
+}
diff --git a/lib/libtermlib/vidputs.c b/lib/libtermlib/vidputs.c
new file mode 100644
index 00000000000..2a932a125d5
--- /dev/null
+++ b/lib/libtermlib/vidputs.c
@@ -0,0 +1,126 @@
+/* $OpenBSD: vidputs.c,v 1.1 1996/05/31 05:40:02 tholo Exp $ */
+
+/*
+ * Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by SigmaSoft, Th. Lockert.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: vidputs.c,v 1.1 1996/05/31 05:40:02 tholo Exp $";
+#endif
+
+#include <stdlib.h>
+#include "term.h"
+
+int
+vidputs(attr, outc)
+ chtype attr;
+ int (*outc) __P((int));
+{
+ static chtype old_attr;
+ chtype attr_on, attr_off;
+
+ if (attr == old_attr)
+ return OK;
+
+ attr_on = (~attr & old_attr) & (chtype)(~A_COLOR);
+ attr_off = (attr & ~old_attr) & (chtype)(~A_COLOR);
+
+ if (attr == A_NORMAL) {
+ if ((old_attr & A_ALTCHARSET) && exit_alt_charset_mode != NULL) {
+ tputs(exit_alt_charset_mode, 1, outc);
+ old_attr &= ~A_ALTCHARSET;
+ }
+ if (old_attr)
+ tputs(exit_attribute_mode, 1, outc);
+ }
+ else if (set_attributes) {
+ if (attr_on || attr_off) {
+ tputs(tparm(set_attributes,
+ attr_on & A_STANDOUT,
+ attr_on & A_UNDERLINE,
+ attr_on & A_REVERSE,
+ attr_on & A_BLINK,
+ attr_on & A_DIM,
+ attr_on & A_BOLD,
+ attr_on & A_INVIS,
+ attr_on & A_PROTECT,
+ attr_on & A_ALTCHARSET),
+ 1, outc);
+ }
+ }
+ else {
+ if ((attr_off & A_ALTCHARSET) && exit_alt_charset_mode != NULL) {
+ tputs(exit_alt_charset_mode, 1, outc);
+ attr_off &= ~A_ALTCHARSET;
+ }
+ if ((attr_off & A_UNDERLINE) && exit_underline_mode != NULL) {
+ tputs(exit_underline_mode, 1, outc);
+ attr_off &= ~A_UNDERLINE;
+ }
+ if ((attr_off & A_STANDOUT) && exit_standout_mode != NULL) {
+ tputs(exit_standout_mode, 1, outc);
+ attr_off &= ~A_STANDOUT;
+ }
+ if (attr_off && exit_attribute_mode != NULL) {
+ tputs(exit_attribute_mode, 1, outc);
+ attr_on |= (attr & (chtype)(~A_COLOR));
+ }
+ if ((attr_on & A_ALTCHARSET) && enter_alt_charset_mode != NULL)
+ tputs(enter_alt_charset_mode, 1, outc);
+ if ((attr_on & A_BLINK) && enter_blink_mode != NULL)
+ tputs(enter_blink_mode, 1, outc);
+ if ((attr_on & A_BOLD) && enter_bold_mode != NULL)
+ tputs(enter_bold_mode, 1, outc);
+ if ((attr_on & A_DIM) && enter_dim_mode != NULL)
+ tputs(enter_dim_mode, 1, outc);
+ if ((attr_on & A_REVERSE) && enter_reverse_mode != NULL)
+ tputs(enter_reverse_mode, 1, outc);
+ if ((attr_on & A_STANDOUT) && enter_standout_mode != NULL)
+ tputs(enter_standout_mode, 1, outc);
+ if ((attr_on & A_PROTECT) && enter_protected_mode != NULL)
+ tputs(enter_protected_mode, 1, outc);
+ if ((attr_on & A_INVIS) && enter_secure_mode != NULL)
+ tputs(enter_secure_mode, 1, outc);
+ if ((attr_on & A_UNDERLINE) && enter_underline_mode != NULL)
+ tputs(enter_underline_mode, 1, outc);
+ if ((attr_on & A_HORIZONTAL) && enter_horizontal_hl_mode != NULL)
+ tputs(enter_horizontal_hl_mode, 1, outc);
+ if ((attr_on & A_LEFT) && enter_left_hl_mode != NULL)
+ tputs(enter_left_hl_mode, 1, outc);
+ if ((attr_on & A_LOW) && enter_low_hl_mode != NULL)
+ tputs(enter_low_hl_mode, 1, outc);
+ if ((attr_on & A_RIGHT) && enter_right_hl_mode != NULL)
+ tputs(enter_right_hl_mode, 1, outc);
+ if ((attr_on & A_TOP) && enter_top_hl_mode != NULL)
+ tputs(enter_top_hl_mode, 1, outc);
+ if ((attr_on & A_VERTICAL) && enter_vertical_hl_mode != NULL)
+ tputs(enter_vertical_hl_mode, 1, outc);
+ }
+ return ERR;
+}