-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
81 lines (68 loc) · 1.4 KB
/
test.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* mini-scanf - Minimal scanf() implementation for embedded projects.
* Copyright (c) 2023 Aleksej Muratov
*/
#include "c_scan.h"
// test only
#include <stdio.h> // TEST only
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <errno.h>
int getch()
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~ICANON;
//if(echo != 0)
//newt.c_lflag &= ECHO;
//else
newt.c_lflag &= ~ECHO;
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
#define TEXT "-9 5 20 asd- en d$"
#define SCANF "%d %*d %2u %c %s %[^$]"
#define SCANA &d, &u, &c, s, ss
#define PRINTF "D=%d U=%d C=%c S=%s SS=%s R=%d\n\r"
#define PRINTA d, u, c, s, ss, ret
int main(int argc, char* argv[])
{
char buff[100] = TEXT;
char s[100];
char ss[100];
char c;
int d;
unsigned u;
int ret;
char buf;
#ifdef C_SSCANF
printf("in: %s\n\r", buff);
#endif
printf("imp: ");
#ifdef C_SSCANF
ret = c_sscanf(buff, SCANF, SCANA);
#else
ret = c_scanf(SCANF, SCANA);
buf=c_getch();
#endif
printf(PRINTF, PRINTA);
#ifndef C_SSCANF
printf(" next=d%d(%c)\n\r", buf,buf);
#endif
printf("ref: ");
#ifdef C_SSCANF
ret = sscanf(buff, SCANF, SCANA);
#else
ret = scanf(SCANF, SCANA);
buf=c_getch();
#endif
printf(PRINTF, PRINTA);
#ifndef C_SSCANF
printf(" next=d%d(%c)\n\r", buf,buf);
#endif
}