Mercurial > emacs
annotate src/termcap.c @ 109165:750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
* alloc.c (overrun_check_malloc, overrun_check_realloc)
(overrun_check_free, xstrdup, allocate_string)
(allocate_string_data, compact_small_strings, Fmake_string)
(make_unibyte_string, make_multibyte_string)
(make_string_from_bytes, make_specified_string, make_float)
(Fcons, allocate_terminal, allocate_frame, make_pure_string)
(Fgarbage_collect): Replace bcopy, safe_bcopy, bzero, bcmp by
memcpy, memmove, memset, memcmp.
* atimer.c (start_atimer, set_alarm): Likewise.
* buffer.c (clone_per_buffer_values, report_overlay_modification)
(mmap_realloc, init_buffer_once): Likewise.
* callint.c (Fcall_interactively): Likewise.
* callproc.c (Fcall_process, Fcall_process_region, child_setup)
(getenv_internal_1): Likewise.
* casefiddle.c (casify_object): Likewise.
* ccl.c (ccl_driver): Likewise.
* character.c (str_as_multibyte, str_to_multibyte): Likewise.
* charset.c (load_charset_map_from_file)
(load_charset_map_from_file, load_charset_map_from_vector)
(Fdefine_charset_internal): Likewise.
* cm.c (Wcm_clear): Likewise.
* coding.c (decode_eol, decode_coding_object)
(Fset_coding_system_priority, make_subsidiaries): Likewise.
* data.c (Faset): Likewise.
* dired.c (directory_files_internal, file_name_completion_stat):
Likewise.
* dispnew.c (new_glyph_matrix, adjust_glyph_matrix)
(clear_glyph_row, copy_row_except_pointers)
(copy_glyph_row_contents, new_glyph_pool, realloc_glyph_pool)
(save_current_matrix, restore_current_matrix)
(build_frame_matrix_from_leaf_window, mirrored_line_dance)
(mirror_line_dance, scrolling_window): Likewise.
* doc.c (Fsnarf_documentation, Fsubstitute_command_keys):
Likewise.
* doprnt.c (doprnt): Likewise.
* editfns.c (Fuser_full_name, make_buffer_string_both)
(Fmessage_box, Fformat, Ftranspose_regions): Likewise.
* emacs.c (sort_args): Likewise.
* eval.c (Fapply, Ffuncall): Likewise.
* fileio.c (Ffile_name_directory, make_temp_name)
(Fexpand_file_name, search_embedded_absfilename)
(Fsubstitute_in_file_name, Ffile_symlink_p, Finsert_file_contents)
(auto_save_error): Likewise.
* fns.c (Fstring_equal, Fcopy_sequence, concat)
(string_to_multibyte, Fstring_as_unibyte, Fstring_as_multibyte)
(internal_equal, Fclear_string, larger_vector, copy_hash_table)
(Fmake_hash_table): Likewise.
* fringe.c (Fdefine_fringe_bitmap): Likewise.
* ftfont.c (ftfont_text_extents): Likewise.
* getloadavg.c (getloadavg): Likewise.
* image.c (define_image_type, make_image, make_image_cache)
(x_create_x_image_and_pixmap, xbm_image_p)
(w32_create_pixmap_from_bitmap_data, xbm_load, xpm_lookup_color)
(xpm_image_p, x_create_bitmap_from_xpm_data, xpm_load)
(init_color_table, x_build_heuristic_mask, pbm_image_p, pbm_load)
(png_image_p, png_read_from_memory, png_load, jpeg_image_p)
(tiff_image_p, tiff_read_from_memory, gif_image_p)
(gif_read_from_memory, gif_load, svg_image_p, gs_image_p):
Likewise.
* indent.c (scan_for_column, compute_motion): Likewise.
* insdel.c (gap_left, gap_right, make_gap_smaller, copy_text)
(insert_1_both, insert_from_gap, replace_range_2): Likewise.
* intervals.c (reproduce_tree, reproduce_tree_obj): Likewise.
* keyboard.c (echo_char, save_getcjmp, restore_getcjmp)
(kbd_buffer_store_event_hold, apply_modifiers_uncached)
(store_user_signal_events, menu_bar_items, tool_bar_items)
(process_tool_bar_item, append_tool_bar_item)
(read_char_minibuf_menu_prompt, read_key_sequence)
(Fread_key_sequence, Fread_key_sequence_vector, Frecent_keys):
Likewise.
* keymap.c (current_minor_maps, Fdescribe_buffer_bindings):
Likewise.
* lisp.h (STRING_COPYIN): Likewise.
* lread.c (Fload, read1, oblookup): Likewise.
* msdos.c (Frecent_doskeys): Likewise.
* nsfns.m (Fx_create_frame): Likewise.
* nsfont.m (nsfont_open, nsfont_text_extents, ns_glyph_metrics):
Likewise.
* nsimage.m (EmacsImage-initFromSkipXBM:width:height:)
(EmacsImage-initForXPMWithDepth:width:height:flip:length:):
Likewise.
* nsmenu.m (ns_update_menubar): Likewise.
* nsterm.m (ns_draw_fringe_bitmap, ns_term_init): Likewise.
* print.c (print_unwind, printchar, strout, print_string)
(print_error_message): Likewise.
* process.c (conv_lisp_to_sockaddr, set_socket_option)
(Fmake_network_process, Fnetwork_interface_list)
(Fnetwork_interface_info, read_process_output, Fprocess_send_eof)
(init_process): Likewise.
* ralloc.c (resize_bloc, r_alloc_sbrk, r_alloc_init): Likewise.
* regex.c (init_syntax_once, regex_compile, re_compile_fastmap):
Likewise.
* scroll.c (do_scrolling, do_direct_scrolling)
(scrolling_max_lines_saved): Likewise.
* search.c (search_buffer, wordify, Freplace_match): Likewise.
* sound.c (wav_init, au_init, Fplay_sound_internal): Likewise.
* syntax.c (skip_chars, skip_syntaxes): Likewise.
* sysdep.c (child_setup_tty, sys_subshell, emacs_get_tty)
(emacs_set_tty): Likewise.
* term.c (encode_terminal_code, calculate_costs)
(produce_special_glyphs, create_tty_output, init_tty, delete_tty):
Likewise.
* termcap.c (tgetst1, gobble_line): Likewise.
* termhooks.h (EVENT_INIT): Likewise.
* tparam.c (tparam1): Likewise.
* unexalpha.c (unexec): Likewise.
* unexec.c (write_segment): Likewise.
* unexmacosx.c (unexec_write_zero): Likewise.
* w32fns.c (w32_wnd_proc, Fx_create_frame, x_create_tip_frame)
(Fx_file_dialog, Fsystem_move_file_to_trash): Likewise.
* w32font.c (w32font_list_family, w32font_text_extents)
(w32font_list_internal, w32font_match_internal)
(w32font_open_internal, compute_metrics, Fx_select_font):
Likewise.
* w32menu.c (set_frame_menubar, add_menu_item)
(w32_menu_display_help, w32_free_submenu_strings): Likewise.
* w32term.c (XCreateGC, w32_initialize_display_info): Likewise.
* w32uniscribe.c (uniscribe_list_family): Likewise.
* w32xfns.c (get_next_msg, post_msg, prepend_msg): Likewise.
* window.c (make_window, replace_window, set_window_buffer)
(Fsplit_window): Likewise.
* xdisp.c (init_iterator, RECORD_OVERLAY_STRING, reseat_to_string)
(add_to_log, message3, x_consider_frame_title)
(append_space_for_newline, extend_face_to_end_of_line)
(decode_mode_spec_coding, init_glyph_string): Likewise.
* xfaces.c (x_create_gc, get_lface_attributes_no_remap)
(Finternal_copy_lisp_face, Finternal_merge_in_global_face)
(face_attr_equal_p, make_realized_face, make_face_cache)
(free_realized_faces, lookup_named_face, smaller_face)
(face_with_height, lookup_derived_face)
(x_supports_face_attributes_p, Finternal_set_font_selection_order)
(Finternal_set_font_selection_order, realize_default_face)
(compute_char_face, face_at_buffer_position)
(face_for_overlay_string, face_at_string_position, merge_faces):
Likewise.
* xfns.c (xic_create_fontsetname, Fx_create_frame)
(Fx_window_property, x_create_tip_frame)
(Fx_backspace_delete_keys_p): Likewise.
* xfont.c (xfont_list, xfont_match, xfont_list_family)
(xfont_text_extents): Likewise.
* xmenu.c (set_frame_menubar, xmenu_show): Likewise.
* xrdb.c (magic_file_p, x_get_resource): Likewise.
* xselect.c (x_queue_event, x_get_window_property)
(receive_incremental_selection): Likewise.
* xsmfns.c (x_session_check_input): Likewise.
* xterm.c (x_send_scroll_bar_event, SET_SAVED_MENU_EVENT)
(handle_one_xevent, x_check_errors, xim_initialize, x_term_init):
Likewise.
* character.h (BCOPY_SHORT): Removed.
* config.in: Regenerate.
* dispnew.c (safe_bcopy): Only define as dummy if PROFILING.
* emacs.c (main) [PROFILING]: Don't declare
dump_opcode_frequencies.
* lisp.h (safe_bcopy): Remove declaration.
(memset) [!HAVE_MEMSET]: Declare.
(memcpy) [!HAVE_MEMCPY]: Likewise.
(memmove) [!HAVE_MEMMOVE]: Likewise.
(memcmp) [!HAVE_MEMCMP]: Likewise.
* s/ms-w32.h (bzero, bcopy, bcmp, GAP_USE_BCOPY)
(BCOPY_UPWARD_SAFE, BCOPY_DOWNWARD_SAFE, HAVE_BCOPY, HAVE_BCMP):
Don't define.
(HAVE_MEMCMP, HAVE_MEMCPY, HAVE_MEMMOVE, HAVE_MEMSET): Define.
* s/msdos.h (GAP_USE_BCOPY, BCOPY_UPWARD_SAFE)
(BCOPY_DOWNWARD_SAFE): Don't define.
* sysdep.c (memset) [!HAVE_MEMSET]: Define.
(memcpy) [!HAVE_MEMCPY]: Define.
(memmove) [!HAVE_MEMMOVE]: Define.
(memcmp) [!HAVE_MEMCMP]: Define.
* config.nt (HAVE_BCOPY, HAVE_BCMP): Remove undefs.
(HAVE_MEMCPY, HAVE_MEMMOVE, HAVE_MEMSET, HAVE_MEMCMP): Add undefs.
* sed2v2.inp (HAVE_MEMCPY, HAVE_MEMSET): Edit to 1.
(HAVE_BZERO): Don't edit.
* lwlib.c (lwlib_memset, lwlib_bcopy): Remove.
(malloc_widget_value, free_widget_info, allocate_widget_instance)
(lw_separator_p): Replace lwlib_memset, lwlib_bcopy, bzero, bcmp by
memset, memcpy, memcmp.
* lwlib-utils.c (XtApplyToWidgets): Likewise.
* xlwmenu.c (XlwMenuInitialize): Likewise.
* lwlib.h (lwlib_bcopy): Remove declaration.
* ebrowse.c (add_sym, make_namespace): Replace bcopy, bzero by
memcpy, memmove, memset.
* pop.c (pop_retrieve, socket_connection, pop_getline): Likewise.
* CPP-DEFINES (BCOPY_DOWNWARD_SAFE, BCOPY_UPWARD_SAFE)
(GAP_USE_BCOPY, HAVE_BCMP, HAVE_BCOPY, bcmp, bcopy, bzero):
Remove.
* configure.in: Don't check for bcopy, bcmp, bzero. Don't include
<strings.h> and don't define bcopy, bzero, BCMP in config.h.
| author | Andreas Schwab <schwab@linux-m68k.org> |
|---|---|
| date | Thu, 08 Jul 2010 00:18:28 +0200 |
| parents | aec1143e8d85 |
| children | 76e072dbe342 |
| rev | line source |
|---|---|
| 7306 | 1 /* Work-alike for termcap, plus extra features. |
|
64770
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 2000, 2001, 2002, 2003, |
|
100960
69177b934405
Revert copyright year changes for files that are not part of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
100951
diff
changeset
|
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
| 7306 | 4 |
| 5 This program is free software; you can redistribute it and/or modify | |
| 6 it under the terms of the GNU General Public License as published by | |
| 7 the Free Software Foundation; either version 2, or (at your option) | |
| 8 any later version. | |
| 9 | |
| 10 This program is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 GNU General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU General Public License | |
| 16 along with this program; see the file COPYING. If not, write to | |
| 64084 | 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 Boston, MA 02110-1301, USA. */ | |
| 7306 | 19 |
| 20 /* Emacs config.h may rename various library functions such as malloc. */ | |
| 21 #ifdef HAVE_CONFIG_H | |
|
12994
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
22 #include <config.h> |
|
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
23 #endif |
| 7785 | 24 |
|
12994
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
25 #ifdef emacs |
| 7785 | 26 |
|
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100960
diff
changeset
|
27 #include <setjmp.h> |
|
29804
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
28 #include <lisp.h> /* xmalloc is here */ |
| 7785 | 29 /* Get the O_* definitions for open et al. */ |
| 30 #include <sys/file.h> | |
|
29804
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
31 #ifdef HAVE_FCNTL_H |
| 7785 | 32 #include <fcntl.h> |
| 33 #endif | |
|
29804
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
34 #ifdef HAVE_UNISTD_H |
|
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
35 #include <unistd.h> |
|
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
36 #endif |
| 7785 | 37 |
|
12994
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
38 #else /* not emacs */ |
| 7306 | 39 |
| 40 #ifdef STDC_HEADERS | |
| 41 #include <stdlib.h> | |
| 42 #include <string.h> | |
| 43 #else | |
| 44 char *getenv (); | |
| 45 char *malloc (); | |
| 46 char *realloc (); | |
| 47 #endif | |
| 48 | |
| 49 #ifdef HAVE_UNISTD_H | |
| 50 #include <unistd.h> | |
| 51 #endif | |
|
51400
6b26c71e351d
Use HAVE_FCNTL_H, not _POSIX_VERSION.
Dave Love <fx@gnu.org>
parents:
44890
diff
changeset
|
52 #ifdef HAVE_FCNTL_H |
| 7306 | 53 #include <fcntl.h> |
| 54 #endif | |
| 55 | |
|
12994
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
56 #endif /* not emacs */ |
| 7306 | 57 |
| 58 #ifndef NULL | |
| 59 #define NULL (char *) 0 | |
| 60 #endif | |
| 61 | |
| 7685 | 62 #ifndef O_RDONLY |
| 63 #define O_RDONLY 0 | |
| 64 #endif | |
| 65 | |
| 7306 | 66 /* BUFSIZE is the initial size allocated for the buffer |
| 67 for reading the termcap file. | |
| 68 It is not a limit. | |
| 69 Make it large normally for speed. | |
| 70 Make it variable when debugging, so can exercise | |
| 71 increasing the space dynamically. */ | |
| 72 | |
| 73 #ifndef BUFSIZE | |
| 74 #ifdef DEBUG | |
| 75 #define BUFSIZE bufsize | |
| 76 | |
| 77 int bufsize = 128; | |
| 78 #else | |
| 79 #define BUFSIZE 2048 | |
| 80 #endif | |
| 81 #endif | |
| 82 | |
|
12679
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
83 #ifndef TERMCAP_FILE |
|
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
84 #define TERMCAP_FILE "/etc/termcap" |
| 7306 | 85 #endif |
| 86 | |
| 87 #ifndef emacs | |
| 88 static void | |
| 89 memory_out () | |
| 90 { | |
| 91 write (2, "virtual memory exhausted\n", 25); | |
| 92 exit (1); | |
| 93 } | |
| 94 | |
| 95 static char * | |
| 96 xmalloc (size) | |
| 97 unsigned size; | |
| 98 { | |
| 99 register char *tem = malloc (size); | |
| 100 | |
| 101 if (!tem) | |
| 102 memory_out (); | |
| 103 return tem; | |
| 104 } | |
| 105 | |
| 106 static char * | |
| 107 xrealloc (ptr, size) | |
| 108 char *ptr; | |
| 109 unsigned size; | |
| 110 { | |
| 111 register char *tem = realloc (ptr, size); | |
| 112 | |
| 113 if (!tem) | |
| 114 memory_out (); | |
| 115 return tem; | |
| 116 } | |
| 117 #endif /* not emacs */ | |
| 118 | |
| 119 /* Looking up capabilities in the entry already found. */ | |
| 120 | |
| 121 /* The pointer to the data made by tgetent is left here | |
| 122 for tgetnum, tgetflag and tgetstr to find. */ | |
| 123 static char *term_entry; | |
| 124 | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
125 static char *tgetst1 (char *ptr, char **area); |
| 7306 | 126 |
| 127 /* Search entry BP for capability CAP. | |
| 128 Return a pointer to the capability (in BP) if found, | |
| 129 0 if not found. */ | |
| 130 | |
| 131 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
132 find_capability (register char *bp, register char *cap) |
| 7306 | 133 { |
| 134 for (; *bp; bp++) | |
| 135 if (bp[0] == ':' | |
| 136 && bp[1] == cap[0] | |
| 137 && bp[2] == cap[1]) | |
| 138 return &bp[4]; | |
| 139 return NULL; | |
| 140 } | |
| 141 | |
| 142 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
143 tgetnum (char *cap) |
| 7306 | 144 { |
| 145 register char *ptr = find_capability (term_entry, cap); | |
| 146 if (!ptr || ptr[-1] != '#') | |
| 147 return -1; | |
| 148 return atoi (ptr); | |
| 149 } | |
| 150 | |
| 151 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
152 tgetflag (char *cap) |
| 7306 | 153 { |
| 154 register char *ptr = find_capability (term_entry, cap); | |
| 155 return ptr && ptr[-1] == ':'; | |
| 156 } | |
| 157 | |
| 158 /* Look up a string-valued capability CAP. | |
| 159 If AREA is non-null, it points to a pointer to a block in which | |
| 160 to store the string. That pointer is advanced over the space used. | |
| 161 If AREA is null, space is allocated with `malloc'. */ | |
| 162 | |
| 163 char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
164 tgetstr (char *cap, char **area) |
| 7306 | 165 { |
| 166 register char *ptr = find_capability (term_entry, cap); | |
| 167 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) | |
| 168 return NULL; | |
| 169 return tgetst1 (ptr, area); | |
| 170 } | |
| 171 | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
172 #ifdef IS_EBCDIC_HOST |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
173 /* Table, indexed by a character in range 0200 to 0300 with 0200 subtracted, |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
174 gives meaning of character following \, or a space if no special meaning. |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
175 Sixteen characters per line within the string. */ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
176 |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
177 static const char esctab[] |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
178 = " \057\026 \047\014 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
179 \025 \015 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
180 \005 \013 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
181 "; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
182 #else |
| 7306 | 183 /* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted, |
| 184 gives meaning of character following \, or a space if no special meaning. | |
| 185 Eight characters per line within the string. */ | |
| 186 | |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
187 static const char esctab[] |
| 7306 | 188 = " \007\010 \033\014 \ |
| 189 \012 \ | |
| 190 \015 \011 \013 \ | |
| 191 "; | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
192 #endif |
| 7306 | 193 |
| 194 /* PTR points to a string value inside a termcap entry. | |
| 195 Copy that value, processing \ and ^ abbreviations, | |
| 196 into the block that *AREA points to, | |
| 197 or to newly allocated storage if AREA is NULL. | |
| 198 Return the address to which we copied the value, | |
| 199 or NULL if PTR is NULL. */ | |
| 200 | |
| 201 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
202 tgetst1 (char *ptr, char **area) |
| 7306 | 203 { |
| 204 register char *p, *r; | |
| 205 register int c; | |
| 206 register int size; | |
| 207 char *ret; | |
| 208 register int c1; | |
| 209 | |
| 210 if (!ptr) | |
| 211 return NULL; | |
| 212 | |
| 213 /* `ret' gets address of where to store the string. */ | |
| 214 if (!area) | |
| 215 { | |
| 216 /* Compute size of block needed (may overestimate). */ | |
| 217 p = ptr; | |
| 218 while ((c = *p++) && c != ':' && c != '\n') | |
| 219 ; | |
| 220 ret = (char *) xmalloc (p - ptr + 1); | |
| 221 } | |
| 222 else | |
| 223 ret = *area; | |
| 224 | |
| 225 /* Copy the string value, stopping at null or colon. | |
| 226 Also process ^ and \ abbreviations. */ | |
| 227 p = ptr; | |
| 228 r = ret; | |
| 229 while ((c = *p++) && c != ':' && c != '\n') | |
| 230 { | |
| 231 if (c == '^') | |
|
10186
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
232 { |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
233 c = *p++; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
234 if (c == '?') |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
235 c = 0177; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
236 else |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
237 c &= 037; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
238 } |
| 7306 | 239 else if (c == '\\') |
| 240 { | |
| 241 c = *p++; | |
| 242 if (c >= '0' && c <= '7') | |
| 243 { | |
| 244 c -= '0'; | |
| 245 size = 0; | |
| 246 | |
| 247 while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7') | |
| 248 { | |
| 249 c *= 8; | |
| 250 c += c1 - '0'; | |
| 251 p++; | |
| 252 } | |
| 253 } | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
254 #ifdef IS_EBCDIC_HOST |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
255 else if (c >= 0200 && c < 0360) |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
256 { |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
257 c1 = esctab[(c & ~0100) - 0200]; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
258 if (c1 != ' ') |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
259 c = c1; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
260 } |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
261 #else |
| 7306 | 262 else if (c >= 0100 && c < 0200) |
| 263 { | |
| 264 c1 = esctab[(c & ~040) - 0100]; | |
| 265 if (c1 != ' ') | |
| 266 c = c1; | |
| 267 } | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
268 #endif |
| 7306 | 269 } |
| 270 *r++ = c; | |
| 271 } | |
|
53306
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
272 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
273 /* Sometimes entries have "%pN" which means use parameter N in the |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
274 next %-substitution. If all such N are continuous in the range |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
275 [1,9] we can remove each "%pN" because they are redundant, thus |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
276 reducing bandwidth requirements. True, Emacs is well beyond the |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
277 days of 150baud teletypes, but some of its users aren't much so. |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
278 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
279 This pass could probably be integrated into the one above but |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
280 abbreviation expansion makes that effort a little more hairy than |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
281 its worth; this is cleaner. */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
282 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
283 register int last_p_param = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
284 int remove_p_params = 1; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
285 struct { char *beg; int len; } cut[11]; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
286 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
287 for (cut[0].beg = p = ret; p < r - 3; p++) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
288 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
289 if (!remove_p_params) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
290 break; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
291 if (*p == '%' && *(p + 1) == 'p') |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
292 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
293 if (*(p + 2) - '0' == 1 + last_p_param) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
294 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
295 cut[last_p_param].len = p - cut[last_p_param].beg; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
296 last_p_param++; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
297 p += 3; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
298 cut[last_p_param].beg = p; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
299 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
300 else /* not continuous: bail */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
301 remove_p_params = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
302 if (last_p_param > 10) /* too many: bail */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
303 remove_p_params = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
304 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
305 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
306 if (remove_p_params && last_p_param) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
307 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
308 register int i; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
309 char *wp; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
310 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
311 cut[last_p_param].len = r - cut[last_p_param].beg; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
312 for (i = 0, wp = ret; i <= last_p_param; wp += cut[i++].len) |
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
313 memcpy (wp, cut[i].beg, cut[i].len); |
|
53306
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
314 r = wp; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
315 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
316 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
317 |
| 7306 | 318 *r = '\0'; |
| 319 /* Update *AREA. */ | |
| 320 if (area) | |
| 321 *area = r + 1; | |
| 322 return ret; | |
| 323 } | |
| 324 | |
| 325 /* Outputting a string with padding. */ | |
| 326 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
327 #ifndef emacs |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
328 short ospeed; |
| 7306 | 329 /* If OSPEED is 0, we use this as the actual baud rate. */ |
| 330 int tputs_baud_rate; | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
331 #endif |
|
44890
01b93e5e53a7
Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
43713
diff
changeset
|
332 |
| 7306 | 333 char PC; |
| 334 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
335 #ifndef emacs |
| 7306 | 336 /* Actual baud rate if positive; |
| 337 - baud rate / 100 if negative. */ | |
| 338 | |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
339 static const int speeds[] = |
| 7306 | 340 { |
| 341 0, 50, 75, 110, 135, 150, -2, -3, -6, -12, | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
342 -18, -24, -48, -96, -192, -288, -384, -576, -1152 |
| 7306 | 343 }; |
| 344 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
345 #endif /* not emacs */ |
| 37864 | 346 |
| 7306 | 347 void |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
348 tputs (register char *str, int nlines, register int (*outfun) (/* ??? */)) |
| 7306 | 349 { |
| 350 register int padcount = 0; | |
| 351 register int speed; | |
| 352 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
353 #ifdef emacs |
|
43713
f92c4d87863a
Change defvar_int def and vars to use EMACS_INT instead of just int.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43674
diff
changeset
|
354 extern EMACS_INT baud_rate; |
| 7306 | 355 speed = baud_rate; |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
356 /* For quite high speeds, convert to the smaller |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
357 units to avoid overflow. */ |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
358 if (speed > 10000) |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
359 speed = - speed / 100; |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
360 #else |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
361 if (ospeed == 0) |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
362 speed = tputs_baud_rate; |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
363 else |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
364 speed = speeds[ospeed]; |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
365 #endif |
| 7306 | 366 |
| 367 if (!str) | |
| 368 return; | |
| 369 | |
| 370 while (*str >= '0' && *str <= '9') | |
| 371 { | |
| 372 padcount += *str++ - '0'; | |
| 373 padcount *= 10; | |
| 374 } | |
| 375 if (*str == '.') | |
| 376 { | |
| 377 str++; | |
| 378 padcount += *str++ - '0'; | |
| 379 } | |
| 380 if (*str == '*') | |
| 381 { | |
| 382 str++; | |
| 383 padcount *= nlines; | |
| 384 } | |
| 385 while (*str) | |
| 386 (*outfun) (*str++); | |
| 387 | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
388 /* PADCOUNT is now in units of tenths of msec. |
| 10753 | 389 SPEED is measured in characters per 10 seconds |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
390 or in characters per .1 seconds (if negative). |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
391 We use the smaller units for larger speeds to avoid overflow. */ |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
392 padcount *= speed; |
| 7306 | 393 padcount += 500; |
| 394 padcount /= 1000; | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
395 if (speed < 0) |
| 7306 | 396 padcount = -padcount; |
| 397 else | |
| 398 { | |
| 399 padcount += 50; | |
| 400 padcount /= 100; | |
| 401 } | |
| 402 | |
| 403 while (padcount-- > 0) | |
| 404 (*outfun) (PC); | |
| 405 } | |
| 406 | |
| 407 /* Finding the termcap entry in the termcap data base. */ | |
| 408 | |
|
22066
a09f2b697d0a
Renamed "struct buffer" to "struct termcap_buffer" to
Richard M. Stallman <rms@gnu.org>
parents:
14414
diff
changeset
|
409 struct termcap_buffer |
| 7306 | 410 { |
| 411 char *beg; | |
| 412 int size; | |
| 413 char *ptr; | |
| 414 int ateof; | |
| 415 int full; | |
| 416 }; | |
| 417 | |
| 418 /* Forward declarations of static functions. */ | |
| 419 | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
420 static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
421 static char *gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
422 static int compare_contin (register char *str1, register char *str2); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
423 static int name_match (char *line, char *name); |
| 7306 | 424 |
| 425 #ifdef MSDOS /* MW, May 1993 */ | |
| 426 static int | |
| 427 valid_filename_p (fn) | |
| 428 char *fn; | |
| 429 { | |
| 430 return *fn == '/' || fn[1] == ':'; | |
| 431 } | |
| 432 #else | |
| 433 #define valid_filename_p(fn) (*(fn) == '/') | |
| 434 #endif | |
| 435 | |
| 436 /* Find the termcap entry data for terminal type NAME | |
| 437 and store it in the block that BP points to. | |
| 438 Record its address for future use. | |
| 439 | |
| 440 If BP is null, space is dynamically allocated. | |
| 441 | |
| 442 Return -1 if there is some difficulty accessing the data base | |
| 443 of terminal types, | |
| 444 0 if the data base is accessible but the type NAME is not defined | |
| 445 in it, and some other value otherwise. */ | |
| 446 | |
| 447 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
448 tgetent (char *bp, char *name) |
| 7306 | 449 { |
| 450 register char *termcap_name; | |
| 451 register int fd; | |
|
22066
a09f2b697d0a
Renamed "struct buffer" to "struct termcap_buffer" to
Richard M. Stallman <rms@gnu.org>
parents:
14414
diff
changeset
|
452 struct termcap_buffer buf; |
| 7306 | 453 register char *bp1; |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
454 char *tc_search_point; |
| 7306 | 455 char *term; |
| 456 int malloc_size = 0; | |
| 457 register int c; | |
| 33616 | 458 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ |
| 7306 | 459 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */ |
| 460 int filep; | |
| 461 | |
| 462 #ifdef INTERNAL_TERMINAL | |
| 463 /* For the internal terminal we don't want to read any termcap file, | |
| 464 so fake it. */ | |
| 465 if (!strcmp (name, "internal")) | |
| 466 { | |
| 467 term = INTERNAL_TERMINAL; | |
| 468 if (!bp) | |
| 469 { | |
| 470 malloc_size = 1 + strlen (term); | |
| 471 bp = (char *) xmalloc (malloc_size); | |
| 472 } | |
| 473 strcpy (bp, term); | |
| 474 goto ret; | |
| 475 } | |
| 476 #endif /* INTERNAL_TERMINAL */ | |
| 477 | |
|
12907
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
478 /* For compatibility with programs like `less' that want to |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
479 put data in the termcap buffer themselves as a fallback. */ |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
480 if (bp) |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
481 term_entry = bp; |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
482 |
| 7306 | 483 termcap_name = getenv ("TERMCAP"); |
| 484 if (termcap_name && *termcap_name == '\0') | |
| 485 termcap_name = NULL; | |
| 486 #if defined (MSDOS) && !defined (TEST) | |
| 487 if (termcap_name && (*termcap_name == '\\' | |
| 488 || *termcap_name == '/' | |
| 489 || termcap_name[1] == ':')) | |
| 490 dostounix_filename(termcap_name); | |
| 491 #endif | |
| 492 | |
| 493 filep = termcap_name && valid_filename_p (termcap_name); | |
| 494 | |
| 495 /* If termcap_name is non-null and starts with / (in the un*x case, that is), | |
| 496 it is a file name to use instead of /etc/termcap. | |
| 497 If it is non-null and does not start with /, | |
| 498 it is the entry itself, but only if | |
| 499 the name the caller requested matches the TERM variable. */ | |
| 500 | |
| 501 if (termcap_name && !filep && !strcmp (name, getenv ("TERM"))) | |
| 502 { | |
| 503 indirect = tgetst1 (find_capability (termcap_name, "tc"), (char **) 0); | |
| 504 if (!indirect) | |
| 505 { | |
| 506 if (!bp) | |
| 507 bp = termcap_name; | |
| 508 else | |
| 509 strcpy (bp, termcap_name); | |
| 510 goto ret; | |
| 511 } | |
| 512 else | |
| 513 { /* It has tc=. Need to read /etc/termcap. */ | |
| 514 tcenv = termcap_name; | |
| 515 termcap_name = NULL; | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 if (!termcap_name || !filep) | |
|
12679
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
520 termcap_name = TERMCAP_FILE; |
| 7306 | 521 |
| 522 /* Here we know we must search a file and termcap_name has its name. */ | |
| 523 | |
| 524 #ifdef MSDOS | |
| 7685 | 525 fd = open (termcap_name, O_RDONLY|O_TEXT, 0); |
| 7306 | 526 #else |
| 7685 | 527 fd = open (termcap_name, O_RDONLY, 0); |
| 7306 | 528 #endif |
| 529 if (fd < 0) | |
| 530 return -1; | |
| 531 | |
| 532 buf.size = BUFSIZE; | |
| 533 /* Add 1 to size to ensure room for terminating null. */ | |
| 534 buf.beg = (char *) xmalloc (buf.size + 1); | |
| 535 term = indirect ? indirect : name; | |
| 536 | |
| 537 if (!bp) | |
| 538 { | |
| 539 malloc_size = indirect ? strlen (tcenv) + 1 : buf.size; | |
| 540 bp = (char *) xmalloc (malloc_size); | |
| 541 } | |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
542 tc_search_point = bp1 = bp; |
| 7306 | 543 |
| 544 if (indirect) | |
| 545 /* Copy the data from the environment variable. */ | |
| 546 { | |
| 547 strcpy (bp, tcenv); | |
| 548 bp1 += strlen (tcenv); | |
| 549 } | |
| 550 | |
| 551 while (term) | |
| 552 { | |
| 553 /* Scan the file, reading it via buf, till find start of main entry. */ | |
| 554 if (scan_file (term, fd, &buf) == 0) | |
| 555 { | |
| 556 close (fd); | |
| 557 free (buf.beg); | |
| 558 if (malloc_size) | |
| 559 free (bp); | |
| 560 return 0; | |
| 561 } | |
| 562 | |
| 563 /* Free old `term' if appropriate. */ | |
| 564 if (term != name) | |
| 565 free (term); | |
| 566 | |
| 567 /* If BP is malloc'd by us, make sure it is big enough. */ | |
| 568 if (malloc_size) | |
| 569 { | |
|
34358
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
570 int offset1 = bp1 - bp, offset2 = tc_search_point - bp; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
571 malloc_size = offset1 + buf.size; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
572 bp = termcap_name = (char *) xrealloc (bp, malloc_size); |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
573 bp1 = termcap_name + offset1; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
574 tc_search_point = termcap_name + offset2; |
| 7306 | 575 } |
| 576 | |
| 577 /* Copy the line of the entry from buf into bp. */ | |
| 578 termcap_name = buf.ptr; | |
| 579 while ((*bp1++ = c = *termcap_name++) && c != '\n') | |
| 580 /* Drop out any \ newline sequence. */ | |
| 581 if (c == '\\' && *termcap_name == '\n') | |
| 582 { | |
| 583 bp1--; | |
| 584 termcap_name++; | |
| 585 } | |
| 586 *bp1 = '\0'; | |
| 587 | |
| 588 /* Does this entry refer to another terminal type's entry? | |
| 589 If something is found, copy it into heap and null-terminate it. */ | |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
590 tc_search_point = find_capability (tc_search_point, "tc"); |
|
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
591 term = tgetst1 (tc_search_point, (char **) 0); |
| 7306 | 592 } |
| 593 | |
| 594 close (fd); | |
| 595 free (buf.beg); | |
| 596 | |
| 597 if (malloc_size) | |
| 598 bp = (char *) xrealloc (bp, bp1 - bp + 1); | |
| 599 | |
| 600 ret: | |
| 601 term_entry = bp; | |
| 602 return 1; | |
| 603 } | |
| 604 | |
| 605 /* Given file open on FD and buffer BUFP, | |
| 606 scan the file from the beginning until a line is found | |
| 607 that starts the entry for terminal type STR. | |
| 608 Return 1 if successful, with that line in BUFP, | |
| 609 or 0 if no entry is found in the file. */ | |
| 610 | |
| 611 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
612 scan_file (char *str, int fd, register struct termcap_buffer *bufp) |
| 7306 | 613 { |
| 614 register char *end; | |
| 615 | |
| 616 bufp->ptr = bufp->beg; | |
| 617 bufp->full = 0; | |
| 618 bufp->ateof = 0; | |
| 619 *bufp->ptr = '\0'; | |
| 620 | |
| 621 lseek (fd, 0L, 0); | |
| 622 | |
| 623 while (!bufp->ateof) | |
| 624 { | |
| 625 /* Read a line into the buffer. */ | |
| 626 end = NULL; | |
| 627 do | |
| 628 { | |
| 629 /* if it is continued, append another line to it, | |
| 630 until a non-continued line ends. */ | |
| 631 end = gobble_line (fd, bufp, end); | |
| 632 } | |
| 633 while (!bufp->ateof && end[-2] == '\\'); | |
| 634 | |
| 635 if (*bufp->ptr != '#' | |
| 636 && name_match (bufp->ptr, str)) | |
| 637 return 1; | |
| 638 | |
| 639 /* Discard the line just processed. */ | |
| 640 bufp->ptr = end; | |
| 641 } | |
| 642 return 0; | |
| 643 } | |
| 644 | |
| 645 /* Return nonzero if NAME is one of the names specified | |
| 646 by termcap entry LINE. */ | |
| 647 | |
| 648 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
649 name_match (char *line, char *name) |
| 7306 | 650 { |
| 651 register char *tem; | |
| 652 | |
| 653 if (!compare_contin (line, name)) | |
| 654 return 1; | |
| 655 /* This line starts an entry. Is it the right one? */ | |
| 656 for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++) | |
| 657 if (*tem == '|' && !compare_contin (tem + 1, name)) | |
| 658 return 1; | |
| 659 | |
| 660 return 0; | |
| 661 } | |
| 662 | |
| 663 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
664 compare_contin (register char *str1, register char *str2) |
| 7306 | 665 { |
| 666 register int c1, c2; | |
| 667 while (1) | |
| 668 { | |
| 669 c1 = *str1++; | |
| 670 c2 = *str2++; | |
| 671 while (c1 == '\\' && *str1 == '\n') | |
| 672 { | |
| 673 str1++; | |
| 674 while ((c1 = *str1++) == ' ' || c1 == '\t'); | |
| 675 } | |
| 676 if (c2 == '\0') | |
| 677 { | |
| 678 /* End of type being looked up. */ | |
| 679 if (c1 == '|' || c1 == ':') | |
| 680 /* If end of name in data base, we win. */ | |
| 681 return 0; | |
| 682 else | |
| 683 return 1; | |
| 684 } | |
| 685 else if (c1 != c2) | |
| 686 return 1; | |
| 687 } | |
| 688 } | |
| 689 | |
| 690 /* Make sure that the buffer <- BUFP contains a full line | |
| 691 of the file open on FD, starting at the place BUFP->ptr | |
| 692 points to. Can read more of the file, discard stuff before | |
| 693 BUFP->ptr, or make the buffer bigger. | |
| 694 | |
| 695 Return the pointer to after the newline ending the line, | |
| 696 or to the end of the file, if there is no newline to end it. | |
| 697 | |
| 698 Can also merge on continuation lines. If APPEND_END is | |
| 699 non-null, it points past the newline of a line that is | |
| 700 continued; we add another line onto it and regard the whole | |
| 701 thing as one line. The caller decides when a line is continued. */ | |
| 702 | |
| 703 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
704 gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) |
| 7306 | 705 { |
| 706 register char *end; | |
| 707 register int nread; | |
| 708 register char *buf = bufp->beg; | |
| 709 register char *tem; | |
| 710 | |
| 711 if (!append_end) | |
| 712 append_end = bufp->ptr; | |
| 713 | |
| 714 while (1) | |
| 715 { | |
| 716 end = append_end; | |
| 717 while (*end && *end != '\n') end++; | |
| 718 if (*end) | |
| 719 break; | |
| 720 if (bufp->ateof) | |
| 721 return buf + bufp->full; | |
| 722 if (bufp->ptr == buf) | |
| 723 { | |
| 724 if (bufp->full == bufp->size) | |
| 725 { | |
| 726 bufp->size *= 2; | |
| 727 /* Add 1 to size to ensure room for terminating null. */ | |
| 728 tem = (char *) xrealloc (buf, bufp->size + 1); | |
| 729 bufp->ptr = (bufp->ptr - buf) + tem; | |
| 730 append_end = (append_end - buf) + tem; | |
| 731 bufp->beg = buf = tem; | |
| 732 } | |
| 733 } | |
| 734 else | |
| 735 { | |
| 736 append_end -= bufp->ptr - buf; | |
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
737 memcpy (buf, bufp->ptr, bufp->full -= bufp->ptr - buf); |
| 7306 | 738 bufp->ptr = buf; |
| 739 } | |
| 740 if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full))) | |
| 741 bufp->ateof = 1; | |
| 742 bufp->full += nread; | |
| 743 buf[bufp->full] = '\0'; | |
| 744 } | |
| 745 return end + 1; | |
| 746 } | |
| 747 | |
| 748 #ifdef TEST | |
| 749 | |
| 750 #ifdef NULL | |
| 751 #undef NULL | |
| 752 #endif | |
| 753 | |
| 754 #include <stdio.h> | |
| 755 | |
| 756 main (argc, argv) | |
| 757 int argc; | |
| 758 char **argv; | |
| 759 { | |
| 760 char *term; | |
| 761 char *buf; | |
| 762 | |
| 763 term = argv[1]; | |
| 764 printf ("TERM: %s\n", term); | |
| 765 | |
| 766 buf = (char *) tgetent (0, term); | |
| 767 if ((int) buf <= 0) | |
| 768 { | |
| 769 printf ("No entry.\n"); | |
| 770 return 0; | |
| 771 } | |
| 772 | |
| 773 printf ("Entry: %s\n", buf); | |
| 774 | |
| 775 tprint ("cm"); | |
| 776 tprint ("AL"); | |
| 777 | |
| 778 printf ("co: %d\n", tgetnum ("co")); | |
| 779 printf ("am: %d\n", tgetflag ("am")); | |
| 780 } | |
| 781 | |
| 782 tprint (cap) | |
| 783 char *cap; | |
| 784 { | |
| 785 char *x = tgetstr (cap, 0); | |
| 786 register char *y; | |
| 787 | |
| 788 printf ("%s: ", cap); | |
| 789 if (x) | |
| 790 { | |
| 791 for (y = x; *y; y++) | |
| 792 if (*y <= ' ' || *y == 0177) | |
| 793 printf ("\\%0o", *y); | |
| 794 else | |
| 795 putchar (*y); | |
| 796 free (x); | |
| 797 } | |
| 798 else | |
| 799 printf ("none"); | |
| 800 putchar ('\n'); | |
| 801 } | |
| 802 | |
| 803 #endif /* TEST */ | |
| 52401 | 804 |
| 805 /* arch-tag: c2e8d427-2271-4fac-95fe-411857238b80 | |
| 806 (do not change this comment) */ |
