File: getych.cpp

package info (click to toggle)
vfu 5.09-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,552 kB
  • sloc: cpp: 16,739; ansic: 2,605; perl: 678; makefile: 349; sh: 75
file content (64 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/****************************************************************************
 *
 *  Copyright (c) 2022 Vladi Belperchinov-Shabanski "Cade" 
 *  http://cade.noxrun.com/  <cade@noxrun.com> <cade@bis.bg> <cade@cpan.org>
 *
 *  SEE `README',`LICENSE' OR `COPYING' FILE FOR LICENSE AND OTHER DETAILS!
 *
 ****************************************************************************/

#include <stdio.h>
#include <wchar.h>
#include  <locale.h>
#include "unicon.h"

int main( int argc, char** argv )
{
  setlocale( LC_ALL, "" );
  con_init();
  wprintf( L"press CTRL+C to exit\n" );
  char s[6];
  wchar_t wc[6];
  while(4)
    {
    wc[0] = 0;
    int  z = 0;
    s[z] = 0;
    int ch = con_getch();
    if( ch < 255 )
      {
      int x = -1;
           if( (ch & 0x80) == 0x00 ) x = 0;
      else if( (ch & 0xE0) == 0xC0 ) x = 1;
      else if( (ch & 0xF0) == 0xE0 ) x = 2;
      else if( (ch & 0xF8) == 0xF0 ) x = 3;

      wprintf( L">> ch = %d %x  [%x][%x][%x][%x] x = %d\r\n", ch, ch, ch & 0x80, ch & 0xE0, ch & 0xF0, ch & 0xF8, x );

      s[z++] = ch;
      s[z] = 0;
      while( x > 0 )
        {
        ch = con_getch();
        wprintf( L" --- ch = %x, x = %d, z = %d\r\n", ch, x, z );
        if( (ch & 0xC0) != 0x80 )
          {
          wprintf( L" --- bad utf8 seq %x\r\n", ch );
          break;
          }
        s[z++] = ch;
        s[z] = 0;
        x--;
        }
      int r = mbtowc( wc, s, MB_CUR_MAX );
      wprintf( L" x = %d, r = %d, z = %d, wc = %lx\r\n", x, r, z, wc[0] );
      ch = 0;
      }
    
    if(wc[0]==3)break;
    wprintf( L" got control key %x and wide char %lx [%ls]\r\n\r\n\r\n\r\n", ch, wc[0], wc );
    }
  con_done();
}