comparison src/termlib.c @ 18814:7e7ec935e7c8 v8.1.2395

patch 8.1.2395: using old C style comments Commit: https://github.com/vim/vim/commit/0d6f5d9740dbad1b0207f3ab257de806169dd905 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 5 21:33:15 2019 +0100 patch 8.1.2395: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Dec 2019 21:45:04 +0100
parents 351cf7c67bbe
children 4c5eec1ef612
comparison
equal deleted inserted replaced
18813:89d78230790e 18814:7e7ec935e7c8
3 * The following software is (C) 1984 Peter da Silva, the Mad Australian, in 3 * The following software is (C) 1984 Peter da Silva, the Mad Australian, in
4 * the public domain. It may be re-distributed for any purpose with the 4 * the public domain. It may be re-distributed for any purpose with the
5 * inclusion of this notice. 5 * inclusion of this notice.
6 */ 6 */
7 7
8 /* Modified by Bram Moolenaar for use with VIM - Vi Improved. */ 8 // Modified by Bram Moolenaar for use with VIM - Vi Improved.
9 /* A few bugs removed by Olaf 'Rhialto' Seibert. */ 9 // A few bugs removed by Olaf 'Rhialto' Seibert.
10 10
11 /* TERMLIB: Terminal independent database. */ 11 // TERMLIB: Terminal independent database.
12 12
13 #include "vim.h" 13 #include "vim.h"
14 #include "termlib.pro" 14 #include "termlib.pro"
15 15
16 #if !defined(AMIGA) && !defined(VMS) 16 #if !defined(AMIGA) && !defined(VMS)
25 25
26 /* 26 /*
27 * Global variables for termlib 27 * Global variables for termlib
28 */ 28 */
29 29
30 char *tent; /* Pointer to terminal entry, set by tgetent */ 30 char *tent; // Pointer to terminal entry, set by tgetent
31 char PC = 0; /* Pad character, default NULL */ 31 char PC = 0; // Pad character, default NULL
32 char *UP = 0, *BC = 0; /* Pointers to UP and BC strings from database */ 32 char *UP = 0, *BC = 0; // Pointers to UP and BC strings from database
33 short ospeed; /* Baud rate (1-16, 1=300, 16=19200), as in stty */ 33 short ospeed; // Baud rate (1-16, 1=300, 16=19200), as in stty
34 34
35 /* 35 /*
36 * Module: tgetent 36 * Module: tgetent
37 * 37 *
38 * Purpose: Get termcap entry for <term> into buffer at <tbuf>. 38 * Purpose: Get termcap entry for <term> into buffer at <tbuf>.
65 # endif 65 # endif
66 #endif 66 #endif
67 67
68 int 68 int
69 tgetent( 69 tgetent(
70 char *tbuf, /* Buffer to hold termcap entry, TBUFSZ bytes max */ 70 char *tbuf, // Buffer to hold termcap entry, TBUFSZ bytes max
71 char *term) /* Name of terminal */ 71 char *term) // Name of terminal
72 { 72 {
73 char tcbuf[32]; /* Temp buffer to handle */ 73 char tcbuf[32]; // Temp buffer to handle
74 char *tcptr = tcbuf; /* extended entries */ 74 char *tcptr = tcbuf; // extended entries
75 char *tcap = TERMCAPFILE; /* Default termcap file */ 75 char *tcap = TERMCAPFILE; // Default termcap file
76 char *tmp; 76 char *tmp;
77 FILE *termcap; 77 FILE *termcap;
78 int retval = 0; 78 int retval = 0;
79 int len; 79 int len;
80 80
81 if ((tmp = (char *)mch_getenv((char_u *)"TERMCAP")) != NULL) 81 if ((tmp = (char *)mch_getenv((char_u *)"TERMCAP")) != NULL)
82 { 82 {
83 if (*tmp == '/') /* TERMCAP = name of termcap file */ 83 if (*tmp == '/') // TERMCAP = name of termcap file
84 { 84 {
85 tcap = tmp ; 85 tcap = tmp ;
86 #if defined(AMIGA) 86 #if defined(AMIGA)
87 /* Convert /usr/share/lib/termcap to usr:share/lib/termcap */ 87 // Convert /usr/share/lib/termcap to usr:share/lib/termcap
88 tcap++; 88 tcap++;
89 tmp = strchr(tcap, '/'); 89 tmp = strchr(tcap, '/');
90 if (tmp) 90 if (tmp)
91 *tmp = ':'; 91 *tmp = ':';
92 #endif 92 #endif
93 } 93 }
94 else /* TERMCAP = termcap entry itself */ 94 else // TERMCAP = termcap entry itself
95 { 95 {
96 int tlen = strlen(term); 96 int tlen = strlen(term);
97 97
98 while (*tmp && *tmp != ':') /* Check if TERM matches */ 98 while (*tmp && *tmp != ':') // Check if TERM matches
99 { 99 {
100 char *nexttmp; 100 char *nexttmp;
101 101
102 while (*tmp == '|') 102 while (*tmp == '|')
103 tmp++; 103 tmp++;
104 nexttmp = _find(tmp, ":|"); /* Rhialto */ 104 nexttmp = _find(tmp, ":|"); // Rhialto
105 if (tmp+tlen == nexttmp && _match(tmp, term) == tlen) 105 if (tmp+tlen == nexttmp && _match(tmp, term) == tlen)
106 { 106 {
107 strcpy(tbuf, tmp); 107 strcpy(tbuf, tmp);
108 tent = tbuf; 108 tent = tbuf;
109 return 1; 109 return 1;
120 } 120 }
121 121
122 len = 0; 122 len = 0;
123 while (getent(tbuf + len, term, termcap, TBUFSZ - len)) 123 while (getent(tbuf + len, term, termcap, TBUFSZ - len))
124 { 124 {
125 tcptr = tcbuf; /* Rhialto */ 125 tcptr = tcbuf; // Rhialto
126 if ((term = tgetstr("tc", &tcptr))) /* extended entry */ 126 if ((term = tgetstr("tc", &tcptr))) // extended entry
127 { 127 {
128 rewind(termcap); 128 rewind(termcap);
129 len = strlen(tbuf); 129 len = strlen(tbuf);
130 } 130 }
131 else 131 else
132 { 132 {
133 retval = 1; 133 retval = 1;
134 tent = tbuf; /* reset it back to the beginning */ 134 tent = tbuf; // reset it back to the beginning
135 break; 135 break;
136 } 136 }
137 } 137 }
138 fclose(termcap); 138 fclose(termcap);
139 return retval; 139 return retval;
143 getent(char *tbuf, char *term, FILE *termcap, int buflen) 143 getent(char *tbuf, char *term, FILE *termcap, int buflen)
144 { 144 {
145 char *tptr; 145 char *tptr;
146 int tlen = strlen(term); 146 int tlen = strlen(term);
147 147
148 while (nextent(tbuf, termcap, buflen)) /* For each possible entry */ 148 while (nextent(tbuf, termcap, buflen)) // For each possible entry
149 { 149 {
150 tptr = tbuf; 150 tptr = tbuf;
151 while (*tptr && *tptr != ':') /* : terminates name field */ 151 while (*tptr && *tptr != ':') // : terminates name field
152 { 152 {
153 char *nexttptr; 153 char *nexttptr;
154 154
155 while (*tptr == '|') /* | separates names */ 155 while (*tptr == '|') // | separates names
156 tptr++; 156 tptr++;
157 nexttptr = _find(tptr, ":|"); /* Rhialto */ 157 nexttptr = _find(tptr, ":|"); // Rhialto
158 if (tptr + tlen == nexttptr && 158 if (tptr + tlen == nexttptr &&
159 _match(tptr, term) == tlen) /* FOUND! */ 159 _match(tptr, term) == tlen) // FOUND!
160 { 160 {
161 tent = tbuf; 161 tent = tbuf;
162 return 1; 162 return 1;
163 } 163 }
164 else /* Look for next name */ 164 else // Look for next name
165 tptr = nexttptr; 165 tptr = nexttptr;
166 } 166 }
167 } 167 }
168 return 0; 168 return 0;
169 } 169 }
172 * Read 1 entry from TERMCAP file. 172 * Read 1 entry from TERMCAP file.
173 */ 173 */
174 static int 174 static int
175 nextent(char *tbuf, FILE *termcap, int buflen) 175 nextent(char *tbuf, FILE *termcap, int buflen)
176 { 176 {
177 char *lbuf = tbuf; /* lbuf=line buffer */ 177 char *lbuf = tbuf; // lbuf=line buffer
178 /* read lines straight into buffer */ 178 // read lines straight into buffer
179 179
180 while (lbuf < tbuf+buflen && /* There's room and */ 180 while (lbuf < tbuf+buflen && // There's room and
181 fgets(lbuf, (int)(tbuf+buflen-lbuf), termcap)) /* another line */ 181 fgets(lbuf, (int)(tbuf+buflen-lbuf), termcap)) // another line
182 { 182 {
183 int llen = strlen(lbuf); 183 int llen = strlen(lbuf);
184 184
185 if (*lbuf == '#') /* eat comments */ 185 if (*lbuf == '#') // eat comments
186 continue; 186 continue;
187 if (lbuf[-1] == ':' && /* and whitespace */ 187 if (lbuf[-1] == ':' && // and whitespace
188 lbuf[0] == '\t' && 188 lbuf[0] == '\t' &&
189 lbuf[1] == ':') 189 lbuf[1] == ':')
190 { 190 {
191 STRMOVE(lbuf, lbuf + 2); 191 STRMOVE(lbuf, lbuf + 2);
192 llen -= 2; 192 llen -= 2;
193 } 193 }
194 if (lbuf[llen-2] == '\\') /* and continuations */ 194 if (lbuf[llen-2] == '\\') // and continuations
195 lbuf += llen-2; 195 lbuf += llen-2;
196 else 196 else
197 { 197 {
198 lbuf[llen-1]=0; /* no continuation, return */ 198 lbuf[llen-1]=0; // no continuation, return
199 return 1; 199 return 1;
200 } 200 }
201 } 201 }
202 202
203 return 0; /* ran into end of file */ 203 return 0; // ran into end of file
204 } 204 }
205 205
206 /* 206 /*
207 * Module: tgetflag 207 * Module: tgetflag
208 * 208 *
278 char *tmp=tent; 278 char *tmp=tent;
279 char *hold; 279 char *hold;
280 int i; 280 int i;
281 281
282 do { 282 do {
283 tmp = _find(tmp, ":"); /* For each field */ 283 tmp = _find(tmp, ":"); // For each field
284 while (*tmp == ':') /* skip empty fields */ 284 while (*tmp == ':') // skip empty fields
285 tmp++; 285 tmp++;
286 if (!*tmp) 286 if (!*tmp)
287 break; 287 break;
288 288
289 if (_match(id, tmp) == len) { 289 if (_match(id, tmp) == len) {
290 tmp += len; /* find '=' '@' or '#' */ 290 tmp += len; // find '=' '@' or '#'
291 if (*tmp == '@') /* :xx@: entry for tc */ 291 if (*tmp == '@') // :xx@: entry for tc
292 return 0; /* deleted entry */ 292 return 0; // deleted entry
293 hold= *buf; 293 hold= *buf;
294 while (*++tmp && *tmp != ':') { /* not at end of field */ 294 while (*++tmp && *tmp != ':') { // not at end of field
295 switch(*tmp) { 295 switch(*tmp) {
296 case '\\': /* Expand escapes here */ 296 case '\\': // Expand escapes here
297 switch(*++tmp) { 297 switch(*++tmp) {
298 case 0: /* ignore backslashes */ 298 case 0: // ignore backslashes
299 tmp--; /* at end of entry */ 299 tmp--; // at end of entry
300 break; /* shouldn't happen */ 300 break; // shouldn't happen
301 case 'e': 301 case 'e':
302 case 'E': /* ESC */ 302 case 'E': // ESC
303 *(*buf)++ = ESC; 303 *(*buf)++ = ESC;
304 break; 304 break;
305 case 'n': /* \n */ 305 case 'n': // \n
306 *(*buf)++ = '\n'; 306 *(*buf)++ = '\n';
307 break; 307 break;
308 case 'r': /* \r */ 308 case 'r': // \r
309 *(*buf)++ = '\r'; 309 *(*buf)++ = '\r';
310 break; 310 break;
311 case 't': /* \t */ 311 case 't': // \t
312 *(*buf)++ = '\t'; 312 *(*buf)++ = '\t';
313 break; 313 break;
314 case 'b': /* \b */ 314 case 'b': // \b
315 *(*buf)++ = '\b'; 315 *(*buf)++ = '\b';
316 break; 316 break;
317 case 'f': /* \f */ 317 case 'f': // \f
318 *(*buf)++ = '\f'; 318 *(*buf)++ = '\f';
319 break; 319 break;
320 case '0': /* \nnn */ 320 case '0': // \nnn
321 case '1': 321 case '1':
322 case '2': 322 case '2':
323 case '3': 323 case '3':
324 case '4': 324 case '4':
325 case '5': 325 case '5':
326 case '6': 326 case '6':
327 case '7': 327 case '7':
328 case '8': 328 case '8':
329 case '9': 329 case '9':
330 **buf = 0; 330 **buf = 0;
331 /* get up to three digits */ 331 // get up to three digits
332 for (i = 0; i < 3 && VIM_ISDIGIT(*tmp); ++i) 332 for (i = 0; i < 3 && VIM_ISDIGIT(*tmp); ++i)
333 **buf = **buf * 8 + *tmp++ - '0'; 333 **buf = **buf * 8 + *tmp++ - '0';
334 (*buf)++; 334 (*buf)++;
335 tmp--; 335 tmp--;
336 break; 336 break;
337 default: /* \x, for all other x */ 337 default: // \x, for all other x
338 *(*buf)++= *tmp; 338 *(*buf)++= *tmp;
339 } 339 }
340 break; 340 break;
341 case '^': /* control characters */ 341 case '^': // control characters
342 ++tmp; 342 ++tmp;
343 *(*buf)++ = Ctrl_chr(*tmp); 343 *(*buf)++ = Ctrl_chr(*tmp);
344 break; 344 break;
345 default: 345 default:
346 *(*buf)++ = *tmp; 346 *(*buf)++ = *tmp;
380 * %D reverse coding (x-2*(x%16)), no output. 380 * %D reverse coding (x-2*(x%16)), no output.
381 */ 381 */
382 382
383 char * 383 char *
384 tgoto( 384 tgoto(
385 char *cm, /* cm string, from termcap */ 385 char *cm, // cm string, from termcap
386 int col, /* column, x position */ 386 int col, // column, x position
387 int line) /* line, y position */ 387 int line) // line, y position
388 { 388 {
389 char gx, gy, /* x, y */ 389 char gx, gy, // x, y
390 *ptr, /* pointer in 'cm' */ 390 *ptr, // pointer in 'cm'
391 reverse = 0, /* reverse flag */ 391 reverse = 0, // reverse flag
392 *bufp, /* pointer in returned string */ 392 *bufp, // pointer in returned string
393 addup = 0, /* add upline */ 393 addup = 0, // add upline
394 addbak = 0, /* add backup */ 394 addbak = 0, // add backup
395 c; 395 c;
396 static char buffer[32]; 396 static char buffer[32];
397 397
398 if (!cm) 398 if (!cm)
399 return "OOPS"; /* Kludge, but standard */ 399 return "OOPS"; // Kludge, but standard
400 400
401 bufp = buffer; 401 bufp = buffer;
402 ptr = cm; 402 ptr = cm;
403 403
404 while (*ptr) { 404 while (*ptr) {
405 if ((c = *ptr++) != '%') { /* normal char */ 405 if ((c = *ptr++) != '%') { // normal char
406 *bufp++ = c; 406 *bufp++ = c;
407 } else { /* % escape */ 407 } else { // % escape
408 switch(c = *ptr++) { 408 switch(c = *ptr++) {
409 case 'd': /* decimal */ 409 case 'd': // decimal
410 bufp = _addfmt(bufp, "%d", line); 410 bufp = _addfmt(bufp, "%d", line);
411 line = col; 411 line = col;
412 break; 412 break;
413 case '2': /* 2 digit decimal */ 413 case '2': // 2 digit decimal
414 bufp = _addfmt(bufp, "%02d", line); 414 bufp = _addfmt(bufp, "%02d", line);
415 line = col; 415 line = col;
416 break; 416 break;
417 case '3': /* 3 digit decimal */ 417 case '3': // 3 digit decimal
418 bufp = _addfmt(bufp, "%03d", line); 418 bufp = _addfmt(bufp, "%03d", line);
419 line = col; 419 line = col;
420 break; 420 break;
421 case '>': /* %>xy: if >x, add y */ 421 case '>': // %>xy: if >x, add y
422 gx = *ptr++; 422 gx = *ptr++;
423 gy = *ptr++; 423 gy = *ptr++;
424 if (col>gx) col += gy; 424 if (col>gx) col += gy;
425 if (line>gx) line += gy; 425 if (line>gx) line += gy;
426 break; 426 break;
427 case '+': /* %+c: add c */ 427 case '+': // %+c: add c
428 line += *ptr++; 428 line += *ptr++;
429 case '.': /* print x/y */ 429 case '.': // print x/y
430 if (line == '\t' || /* these are */ 430 if (line == '\t' || // these are
431 line == '\n' || /* chars that */ 431 line == '\n' || // chars that
432 line == '\004' || /* UNIX hates */ 432 line == '\004' || // UNIX hates
433 line == '\0') { 433 line == '\0') {
434 line++; /* so go to next pos */ 434 line++; // so go to next pos
435 if (reverse == (line == col)) 435 if (reverse == (line == col))
436 addup=1; /* and mark UP */ 436 addup=1; // and mark UP
437 else 437 else
438 addbak=1; /* or BC */ 438 addbak=1; // or BC
439 } 439 }
440 *bufp++=line; 440 *bufp++=line;
441 line = col; 441 line = col;
442 break; 442 break;
443 case 'r': /* r: reverse */ 443 case 'r': // r: reverse
444 gx = line; 444 gx = line;
445 line = col; 445 line = col;
446 col = gx; 446 col = gx;
447 reverse = 1; 447 reverse = 1;
448 break; 448 break;
449 case 'i': /* increment (1-origin screen) */ 449 case 'i': // increment (1-origin screen)
450 col++; 450 col++;
451 line++; 451 line++;
452 break; 452 break;
453 case '%': /* %%=% literally */ 453 case '%': // %%=% literally
454 *bufp++='%'; 454 *bufp++='%';
455 break; 455 break;
456 case 'n': /* magic DM2500 code */ 456 case 'n': // magic DM2500 code
457 line ^= 0140; 457 line ^= 0140;
458 col ^= 0140; 458 col ^= 0140;
459 break; 459 break;
460 case 'B': /* bcd encoding */ 460 case 'B': // bcd encoding
461 line = line/10<<4+line%10; 461 line = line/10<<4+line%10;
462 col = col/10<<4+col%10; 462 col = col/10<<4+col%10;
463 break; 463 break;
464 case 'D': /* magic Delta Data code */ 464 case 'D': // magic Delta Data code
465 line = line-2*(line&15); 465 line = line-2*(line&15);
466 col = col-2*(col&15); 466 col = col-2*(col&15);
467 break; 467 break;
468 default: /* Unknown escape */ 468 default: // Unknown escape
469 return "OOPS"; 469 return "OOPS";
470 } 470 }
471 } 471 }
472 } 472 }
473 473
474 if (addup) /* add upline */ 474 if (addup) // add upline
475 if (UP) { 475 if (UP) {
476 ptr=UP; 476 ptr=UP;
477 while (VIM_ISDIGIT(*ptr) || *ptr == '.') 477 while (VIM_ISDIGIT(*ptr) || *ptr == '.')
478 ptr++; 478 ptr++;
479 if (*ptr == '*') 479 if (*ptr == '*')
480 ptr++; 480 ptr++;
481 while (*ptr) 481 while (*ptr)
482 *bufp++ = *ptr++; 482 *bufp++ = *ptr++;
483 } 483 }
484 484
485 if (addbak) /* add backspace */ 485 if (addbak) // add backspace
486 if (BC) { 486 if (BC) {
487 ptr=BC; 487 ptr=BC;
488 while (VIM_ISDIGIT(*ptr) || *ptr == '.') 488 while (VIM_ISDIGIT(*ptr) || *ptr == '.')
489 ptr++; 489 ptr++;
490 if (*ptr == '*') 490 if (*ptr == '*')
526 600, 1200, 1800, 2400, 526 600, 1200, 1800, 2400,
527 4800, 9600, 19200, 19200 }; 527 4800, 9600, 19200, 19200 };
528 528
529 int 529 int
530 tputs( 530 tputs(
531 char *cp, /* string to print */ 531 char *cp, // string to print
532 int affcnt, /* Number of lines affected */ 532 int affcnt, // Number of lines affected
533 void (*outc)(unsigned int)) /* routine to output 1 character */ 533 void (*outc)(unsigned int)) // routine to output 1 character
534 { 534 {
535 long frac, /* 10^(#digits after decimal point) */ 535 long frac, // 10^(#digits after decimal point)
536 counter, /* digits */ 536 counter, // digits
537 atol(const char *); 537 atol(const char *);
538 538
539 if (VIM_ISDIGIT(*cp)) { 539 if (VIM_ISDIGIT(*cp)) {
540 counter = 0; 540 counter = 0;
541 frac = 1000; 541 frac = 1000;
544 if (*cp == '.') 544 if (*cp == '.')
545 while (VIM_ISDIGIT(*++cp)) { 545 while (VIM_ISDIGIT(*++cp)) {
546 counter = counter * 10L + (long)(*cp++ - '0'); 546 counter = counter * 10L + (long)(*cp++ - '0');
547 frac = frac * 10; 547 frac = frac * 10;
548 } 548 }
549 if (*cp!='*') { /* multiply by affected lines */ 549 if (*cp!='*') { // multiply by affected lines
550 if (affcnt>1) affcnt = 1; 550 if (affcnt>1) affcnt = 1;
551 } 551 }
552 else 552 else
553 cp++; 553 cp++;
554 554
555 /* Calculate number of characters for padding counter/frac ms delay */ 555 // Calculate number of characters for padding counter/frac ms delay
556 if (ospeed) 556 if (ospeed)
557 counter = (counter * _bauds[ospeed] * (long)affcnt) / frac; 557 counter = (counter * _bauds[ospeed] * (long)affcnt) / frac;
558 558
559 while (*cp) /* output string */ 559 while (*cp) // output string
560 (*outc)(*cp++); 560 (*outc)(*cp++);
561 if (ospeed) 561 if (ospeed)
562 while (counter--) /* followed by pad characters */ 562 while (counter--) // followed by pad characters
563 (*outc)(PC); 563 (*outc)(PC);
564 } 564 }
565 else 565 else
566 while (*cp) 566 while (*cp)
567 (*outc)(*cp++); 567 (*outc)(*cp++);