annotate src/termlib.c @ 2689:26fb122355d4 v7.3.107

updated for version 7.3.107 Problem: Year number for :undolist can be confused with month or day. Solution: Change "%y" to "%Y".
author Bram Moolenaar <bram@vim.org>
date Sat, 22 Jan 2011 21:25:11 +0100
parents 82b5078be2dd
children 8bd38abda314
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * The following software is (C) 1984 Peter da Silva, the Mad Australian, in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 * the public domain. It may be re-distributed for any purpose with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * inclusion of this notice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 /* Modified by Bram Moolenaar for use with VIM - Vi Improved. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 /* A few bugs removed by Olaf 'Rhialto' Seibert. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 7
diff changeset
11 /* TERMLIB: Terminal independent database. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "termlib.pro"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #if !defined(AMIGA) && !defined(VMS) && !defined(MACOS) && !defined(RISCOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 # include <sgtty.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 static int getent __ARGS((char *, char *, FILE *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 static int nextent __ARGS((char *, FILE *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 static int _match __ARGS((char *, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 static char *_addfmt __ARGS((char *, char *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 static char *_find __ARGS((char *, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 * Global variables for termlib
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 char *tent; /* Pointer to terminal entry, set by tgetent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 char PC = 0; /* Pad character, default NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 char *UP = 0, *BC = 0; /* Pointers to UP and BC strings from database */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 short ospeed; /* Baud rate (1-16, 1=300, 16=19200), as in stty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 * Module: tgetent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 * Purpose: Get termcap entry for <term> into buffer at <tbuf>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 * Calling conventions: char tbuf[TBUFSZ+], term=canonical name for terminal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 * Returned values: 1 = success, -1 = can't open file,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 * 0 = can't find terminal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 * Notes:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 * - Should probably supply static buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 * - Uses environment variables "TERM" and "TERMCAP". If TERM = term (that is,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 * if the argument matches the environment) then it looks at TERMCAP.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 * - If TERMCAP begins with a slash, then it assumes this is the file to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 * search rather than /etc/termcap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 * - If TERMCAP does not begin with a slash, and it matches TERM, then this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 * used as the entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 * - This could be simplified considerably for non-UNIX systems.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 #ifndef TERMCAPFILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 # ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 # define TERMCAPFILE "s:termcap"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 # ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 # define TERMCAPFILE "VIMRUNTIME:termcap"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 # define TERMCAPFILE "/etc/termcap"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 tgetent(tbuf, term)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 char *tbuf; /* Buffer to hold termcap entry, TBUFSZ bytes max */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 char *term; /* Name of terminal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 char tcbuf[32]; /* Temp buffer to handle */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 char *tcptr = tcbuf; /* extended entries */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 char *tcap = TERMCAPFILE; /* Default termcap file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 char *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 FILE *termcap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 int retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 if ((tmp = (char *)mch_getenv((char_u *)"TERMCAP")) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 if (*tmp == '/') /* TERMCAP = name of termcap file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 tcap = tmp ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 #if defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 /* Convert /usr/share/lib/termcap to usr:share/lib/termcap */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 tcap++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 tmp = strchr(tcap, '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if (tmp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 *tmp = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 else /* TERMCAP = termcap entry itself */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 int tlen = strlen(term);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 while (*tmp && *tmp != ':') /* Check if TERM matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 char *nexttmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 while (*tmp == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 tmp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 nexttmp = _find(tmp, ":|"); /* Rhialto */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 if (tmp+tlen == nexttmp && _match(tmp, term) == tlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 strcpy(tbuf, tmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 tent = tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 tmp = nexttmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 if (!(termcap = mch_fopen(tcap, "r")))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 strcpy(tbuf, tcap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 while (getent(tbuf + len, term, termcap, TBUFSZ - len))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 tcptr = tcbuf; /* Rhialto */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 if ((term = tgetstr("tc", &tcptr))) /* extended entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 rewind(termcap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 len = strlen(tbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 retval = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 tent = tbuf; /* reset it back to the beginning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 fclose(termcap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 getent(tbuf, term, termcap, buflen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 char *tbuf, *term;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 FILE *termcap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 int buflen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 char *tptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 int tlen = strlen(term);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 while (nextent(tbuf, termcap, buflen)) /* For each possible entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 tptr = tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 while (*tptr && *tptr != ':') /* : terminates name field */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 char *nexttptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 7
diff changeset
158 while (*tptr == '|') /* | separates names */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 tptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 nexttptr = _find(tptr, ":|"); /* Rhialto */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 if (tptr + tlen == nexttptr &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 _match(tptr, term) == tlen) /* FOUND! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 tent = tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 else /* Look for next name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 tptr = nexttptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 nextent(tbuf, termcap, buflen) /* Read 1 entry from TERMCAP file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 char *tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 FILE *termcap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 int buflen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 char *lbuf = tbuf; /* lbuf=line buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 /* read lines straight into buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 while (lbuf < tbuf+buflen && /* There's room and */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 fgets(lbuf, (int)(tbuf+buflen-lbuf), termcap)) /* another line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 int llen = strlen(lbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 if (*lbuf == '#') /* eat comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 if (lbuf[-1] == ':' && /* and whitespace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 lbuf[0] == '\t' &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 lbuf[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 {
1621
82b5078be2dd updated for version 7.2a
vimboss
parents: 1341
diff changeset
194 STRMOVE(lbuf, lbuf + 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 llen -= 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 if (lbuf[llen-2] == '\\') /* and continuations */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 lbuf += llen-2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 lbuf[llen-1]=0; /* no continuation, return */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 return 0; /* ran into end of file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 * Module: tgetflag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 * Purpose: returns flag true or false as to the existence of a given entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 * used with 'bs', 'am', etc...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 * Calling conventions: id is the 2 character capability id.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 * Returned values: 1 for success, 0 for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 tgetflag(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 char *id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 char buf[256], *ptr = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 return tgetstr(id, &ptr) ? 1 : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 * Module: tgetnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 * Purpose: get numeric value such as 'li' or 'co' from termcap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 * Calling conventions: id = 2 character id.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 * Returned values: -1 for failure, else numerical value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 tgetnum(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 char *id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 char *ptr, buf[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 ptr = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 if (tgetstr(id, &ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 return atoi(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 * Module: tgetstr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 * Purpose: get terminal capability string from database.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 * Calling conventions: id is the two character capability id.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 * (*buf) points into a hold buffer for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 * id. the capability is copied into the buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 * and (*buf) is advanced to point to the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 * free byte in the buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 * Returned values: 0 = no such entry, otherwise returns original
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 * (*buf) (now a pointer to the string).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 * Notes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 * It also decodes certain escape sequences in the buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 * they should be obvious from the code:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 * \E = escape.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 * \n, \r, \t, \f, \b match the 'c' escapes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 * ^x matches control-x (^@...^_).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 * \nnn matches nnn octal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 * \x, where x is anything else, matches x. I differ
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 * from the standard library here, in that I allow ^: to match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 * :.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 tgetstr(id, buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 char *id, **buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 int len = strlen(id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 char *tmp=tent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 char *hold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 do {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 tmp = _find(tmp, ":"); /* For each field */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 while (*tmp == ':') /* skip empty fields */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 tmp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 if (!*tmp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 if (_match(id, tmp) == len) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 tmp += len; /* find '=' '@' or '#' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 if (*tmp == '@') /* :xx@: entry for tc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 return 0; /* deleted entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 hold= *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 while (*++tmp && *tmp != ':') { /* not at end of field */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 switch(*tmp) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 case '\\': /* Expand escapes here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 switch(*++tmp) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 case 0: /* ignore backslashes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 tmp--; /* at end of entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 break; /* shouldn't happen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 case 'e':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 case 'E': /* ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 *(*buf)++ = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 case 'n': /* \n */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 *(*buf)++ = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 case 'r': /* \r */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 *(*buf)++ = '\r';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 case 't': /* \t */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 *(*buf)++ = '\t';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 case 'b': /* \b */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 *(*buf)++ = '\b';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 case 'f': /* \f */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 *(*buf)++ = '\f';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 case '0': /* \nnn */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 case '9':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 **buf = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 /* get up to three digits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 for (i = 0; i < 3 && VIM_ISDIGIT(*tmp); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 **buf = **buf * 8 + *tmp++ - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 (*buf)++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 tmp--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 default: /* \x, for all other x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 *(*buf)++= *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 case '^': /* control characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 ++tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 *(*buf)++ = Ctrl_chr(*tmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 *(*buf)++ = *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 *(*buf)++ = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 return hold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 } while (*tmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 * Module: tgoto
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 * Purpose: decode cm cursor motion string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 * Calling conventions: cm is cursor motion string. line, col, are the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 * desired destination.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 * Returned values: a string pointing to the decoded string, or "OOPS" if it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 * cannot be decoded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 * Notes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 * The accepted escapes are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * %d as in printf, 0 origin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * %2, %3 like %02d, %03d in printf.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 * %. like %c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 * %+x adds <x> to value, then %.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 * %>xy if value>x, adds y. No output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 * %i increments line& col, no output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 * %r reverses order of line&col. No output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 * %% prints as a single %.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 * %n exclusive or row & col with 0140.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 * %B BCD, no output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 * %D reverse coding (x-2*(x%16)), no output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 tgoto(cm, col, line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 char *cm; /* cm string, from termcap */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 int col, /* column, x position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 line; /* line, y position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 char gx, gy, /* x, y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 *ptr, /* pointer in 'cm' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 reverse = 0, /* reverse flag */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 *bufp, /* pointer in returned string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 addup = 0, /* add upline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 addbak = 0, /* add backup */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 static char buffer[32];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 if (!cm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 return "OOPS"; /* Kludge, but standard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 bufp = buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 ptr = cm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 while (*ptr) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 if ((c = *ptr++) != '%') { /* normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 *bufp++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 } else { /* % escape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 switch(c = *ptr++) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 case 'd': /* decimal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 bufp = _addfmt(bufp, "%d", line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 line = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 case '2': /* 2 digit decimal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 bufp = _addfmt(bufp, "%02d", line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 line = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 case '3': /* 3 digit decimal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 bufp = _addfmt(bufp, "%03d", line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 line = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 case '>': /* %>xy: if >x, add y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 gx = *ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 gy = *ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 if (col>gx) col += gy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 if (line>gx) line += gy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 case '+': /* %+c: add c */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 line += *ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 case '.': /* print x/y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 if (line == '\t' || /* these are */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 line == '\n' || /* chars that */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 line == '\004' || /* UNIX hates */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 line == '\0') {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 line++; /* so go to next pos */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 if (reverse == (line == col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 addup=1; /* and mark UP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 addbak=1; /* or BC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 *bufp++=line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 line = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 case 'r': /* r: reverse */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 gx = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 line = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 col = gx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 reverse = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 case 'i': /* increment (1-origin screen) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 line++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 case '%': /* %%=% literally */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 *bufp++='%';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 case 'n': /* magic DM2500 code */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 line ^= 0140;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 col ^= 0140;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 case 'B': /* bcd encoding */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 line = line/10<<4+line%10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 col = col/10<<4+col%10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 case 'D': /* magic Delta Data code */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 line = line-2*(line&15);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 col = col-2*(col&15);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 default: /* Unknown escape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 return "OOPS";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 if (addup) /* add upline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 if (UP) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 ptr=UP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 while (VIM_ISDIGIT(*ptr) || *ptr == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 if (*ptr == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 while (*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 *bufp++ = *ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 if (addbak) /* add backspace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 if (BC) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 ptr=BC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 while (VIM_ISDIGIT(*ptr) || *ptr == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 if (*ptr == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 while (*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 *bufp++ = *ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 *bufp++='\b';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 *bufp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 return(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 * Module: tputs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 * Purpose: decode padding information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 * Calling conventions: cp = string to be padded, affcnt = # of items affected
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 * (lines, characters, whatever), outc = routine to output 1 character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 * Returned values: none
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 * Notes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 * cp has padding information ahead of it, in the form
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 * nnnTEXT or nnn*TEXT. nnn is the number of milliseconds to delay,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 * and may be a decimal (nnn.mmm). If the asterisk is given, then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 * the delay is multiplied by afcnt. The delay is produced by outputting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 * a number of nulls (or other padding char) after printing the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 * TEXT.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 long _bauds[16]={
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 0, 50, 75, 110,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 134, 150, 200, 300,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 600, 1200, 1800, 2400,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 4800, 9600, 19200, 19200 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 tputs(cp, affcnt, outc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 char *cp; /* string to print */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 int affcnt; /* Number of lines affected */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 void (*outc) __ARGS((unsigned int));/* routine to output 1 character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 long frac, /* 10^(#digits after decimal point) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 counter, /* digits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 atol __ARGS((const char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 if (VIM_ISDIGIT(*cp)) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 counter = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 frac = 1000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 while (VIM_ISDIGIT(*cp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 counter = counter * 10L + (long)(*cp++ - '0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 if (*cp == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 while (VIM_ISDIGIT(*++cp)) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 counter = counter * 10L + (long)(*cp++ - '0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 frac = frac * 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 if (*cp!='*') { /* multiply by affected lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 if (affcnt>1) affcnt = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 cp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 /* Calculate number of characters for padding counter/frac ms delay */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 if (ospeed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 counter = (counter * _bauds[ospeed] * (long)affcnt) / frac;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 while (*cp) /* output string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 (*outc)(*cp++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 if (ospeed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 while (counter--) /* followed by pad characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 (*outc)(PC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 while (*cp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 (*outc)(*cp++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 * Module: tutil.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 * Purpose: Utility routines for TERMLIB functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 _match(s1, s2) /* returns length of text common to s1 and s2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 char *s1, *s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 int i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 while (s1[i] && s1[i] == s2[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 * finds next c in s that's a member of set, returns pointer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 _find(s, set)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 char *s, *set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 for(; *s; s++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 char *ptr = set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 while (*ptr && *s != *ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 ptr++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 if (*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 * add val to buf according to format fmt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 _addfmt(buf, fmt, val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 char *buf, *fmt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 int val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 sprintf(buf, fmt, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 while (*buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 buf++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 }