Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.144.105.101
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/root/proc/self/root/usr/share/doc/re2c/examples/c/conditions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/root/proc/self/root/usr/share/doc/re2c/examples/c/conditions/parse_u32_blocks.c
/* Generated by re2c */
// re2c $INPUT -o $OUTPUT -i
#include <stdint.h>
#include <limits.h>
#include <assert.h>

static const uint64_t ERROR = UINT64_MAX;

template<int BASE> static void add(uint64_t &u, char d) {
    u = u * BASE + d;
    if (u > UINT32_MAX) u = ERROR;
}

static uint64_t parse_u32(const char *s) {
    const char *YYCURSOR = s, *YYMARKER;
    uint64_t u = 0;

    
{
	char yych;
	yych = *YYCURSOR;
	switch (yych) {
		case '0': goto yy2;
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9': goto yy4;
		default: goto yy1;
	}
yy1:
	++YYCURSOR;
	{ return ERROR; }
yy2:
	yych = *(YYMARKER = ++YYCURSOR);
	switch (yych) {
		case 'B':
		case 'b': goto yy5;
		case 'X':
		case 'x': goto yy7;
		default: goto yy3;
	}
yy3:
	{ goto oct; }
yy4:
	++YYCURSOR;
	YYCURSOR -= 1;
	{ goto dec; }
yy5:
	yych = *++YYCURSOR;
	switch (yych) {
		case '0':
		case '1': goto yy8;
		default: goto yy6;
	}
yy6:
	YYCURSOR = YYMARKER;
	goto yy3;
yy7:
	yych = *++YYCURSOR;
	switch (yych) {
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f': goto yy9;
		default: goto yy6;
	}
yy8:
	++YYCURSOR;
	YYCURSOR -= 1;
	{ goto bin; }
yy9:
	++YYCURSOR;
	YYCURSOR -= 1;
	{ goto hex; }
}

bin:
    
{
	char yych;
	yych = *YYCURSOR;
	switch (yych) {
		case 0x00: goto yy11;
		case '0':
		case '1': goto yy13;
		default: goto yy12;
	}
yy11:
	++YYCURSOR;
	{ return u; }
yy12:
	++YYCURSOR;
	{ return ERROR; }
yy13:
	++YYCURSOR;
	{ add<2>(u, YYCURSOR[-1] - '0'); goto bin; }
}

oct:
    
{
	char yych;
	yych = *YYCURSOR;
	switch (yych) {
		case 0x00: goto yy15;
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7': goto yy17;
		default: goto yy16;
	}
yy15:
	++YYCURSOR;
	{ return u; }
yy16:
	++YYCURSOR;
	{ return ERROR; }
yy17:
	++YYCURSOR;
	{ add<8>(u, YYCURSOR[-1] - '0'); goto oct; }
}

dec:
    
{
	char yych;
	yych = *YYCURSOR;
	switch (yych) {
		case 0x00: goto yy19;
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9': goto yy21;
		default: goto yy20;
	}
yy19:
	++YYCURSOR;
	{ return u; }
yy20:
	++YYCURSOR;
	{ return ERROR; }
yy21:
	++YYCURSOR;
	{ add<10>(u, YYCURSOR[-1] - '0'); goto dec; }
}

hex:
    
{
	char yych;
	yych = *YYCURSOR;
	switch (yych) {
		case 0x00: goto yy23;
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9': goto yy25;
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F': goto yy26;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f': goto yy27;
		default: goto yy24;
	}
yy23:
	++YYCURSOR;
	{ return u; }
yy24:
	++YYCURSOR;
	{ return ERROR; }
yy25:
	++YYCURSOR;
	{ add<16>(u, YYCURSOR[-1] - '0');      goto hex; }
yy26:
	++YYCURSOR;
	{ add<16>(u, YYCURSOR[-1] - 'A' + 10); goto hex; }
yy27:
	++YYCURSOR;
	{ add<16>(u, YYCURSOR[-1] - 'a' + 10); goto hex; }
}

}

int main() {
    assert(parse_u32("") == ERROR);
    assert(parse_u32("1234567890") == 1234567890);
    assert(parse_u32("0b1101") == 13);
    assert(parse_u32("0x7Fe") == 2046);
    assert(parse_u32("0644") == 420);
    assert(parse_u32("9999999999") == ERROR);
    return 0;
}

Anon7 - 2022
AnonSec Team