redrust 0.1.1

redrust is a port of the popular Redis database system written in Rust programming language. This port aims to provide all the features of Redis while taking advantage of the Rust language's safety, speed, and modern language features.
Documentation
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
extern crate c2rust_bitfields;
extern crate libc;
extern crate core;
extern "C" {
    pub type _IO_wide_data;
    pub type _IO_codecvt;
    pub type _IO_marker;
    pub type redisAsyncContext;
    pub type sockaddr;
    static mut stdin: *mut FILE;
    static mut stderr: *mut FILE;
    fn fprintf(_: *mut FILE, _: *const libc::c_char, _: ...) -> libc::c_int;
    fn perror(__s: *const libc::c_char);
    fn fileno(__stream: *mut FILE) -> libc::c_int;
    fn hi_sdsclear(s: hisds);
    fn hi_sdsnewlen(init: *const libc::c_void, initlen: size_t) -> hisds;
    fn hi_sdsnew(init: *const libc::c_char) -> hisds;
    fn hi_sdsempty() -> hisds;
    fn hi_sdsfree(s: hisds);
    fn hi_sdscatlen(s: hisds, t: *const libc::c_void, len: size_t) -> hisds;
    fn hi_sdscatprintf(s: hisds, fmt: *const libc::c_char, _: ...) -> hisds;
    fn hi_sdsrange(s: hisds, start: ssize_t, end: ssize_t) -> libc::c_int;
    fn hi_sdsfreesplitres(tokens: *mut hisds, count: libc::c_int);
    fn hi_sdssplitargs(line: *const libc::c_char, argc: *mut libc::c_int) -> *mut hisds;
    fn hi_sds_malloc(size: size_t) -> *mut libc::c_void;
    fn hi_sds_free(ptr: *mut libc::c_void);
    fn redisBufferWrite(c: *mut redisContext, done: *mut libc::c_int) -> libc::c_int;
    fn strtol(
        _: *const libc::c_char,
        _: *mut *mut libc::c_char,
        _: libc::c_int,
    ) -> libc::c_long;
    fn exit(_: libc::c_int) -> !;
    fn __errno_location() -> *mut libc::c_int;
    fn read(__fd: libc::c_int, __buf: *mut libc::c_void, __nbytes: size_t) -> ssize_t;
    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
    fn strncasecmp(
        __s1: *const libc::c_char,
        __s2: *const libc::c_char,
        __n: size_t,
    ) -> libc::c_int;
    fn __ctype_b_loc() -> *mut *const libc::c_ushort;
    fn __ctype_tolower_loc() -> *mut *const __int32_t;
}
pub type size_t = libc::c_ulong;
pub type __uint8_t = libc::c_uchar;
pub type __uint16_t = libc::c_ushort;
pub type __int32_t = libc::c_int;
pub type __uint32_t = libc::c_uint;
pub type __uint64_t = libc::c_ulong;
pub type __off_t = libc::c_long;
pub type __off64_t = libc::c_long;
pub type __time_t = libc::c_long;
pub type __suseconds_t = libc::c_long;
pub type __ssize_t = libc::c_long;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
    pub _flags: libc::c_int,
    pub _IO_read_ptr: *mut libc::c_char,
    pub _IO_read_end: *mut libc::c_char,
    pub _IO_read_base: *mut libc::c_char,
    pub _IO_write_base: *mut libc::c_char,
    pub _IO_write_ptr: *mut libc::c_char,
    pub _IO_write_end: *mut libc::c_char,
    pub _IO_buf_base: *mut libc::c_char,
    pub _IO_buf_end: *mut libc::c_char,
    pub _IO_save_base: *mut libc::c_char,
    pub _IO_backup_base: *mut libc::c_char,
    pub _IO_save_end: *mut libc::c_char,
    pub _markers: *mut _IO_marker,
    pub _chain: *mut _IO_FILE,
    pub _fileno: libc::c_int,
    pub _flags2: libc::c_int,
    pub _old_offset: __off_t,
    pub _cur_column: libc::c_ushort,
    pub _vtable_offset: libc::c_schar,
    pub _shortbuf: [libc::c_char; 1],
    pub _lock: *mut libc::c_void,
    pub _offset: __off64_t,
    pub _codecvt: *mut _IO_codecvt,
    pub _wide_data: *mut _IO_wide_data,
    pub _freeres_list: *mut _IO_FILE,
    pub _freeres_buf: *mut libc::c_void,
    pub __pad5: size_t,
    pub _mode: libc::c_int,
    pub _unused2: [libc::c_char; 20],
}
pub type _IO_lock_t = ();
pub type FILE = _IO_FILE;
pub type ssize_t = __ssize_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct redisReadTask {
    pub type_0: libc::c_int,
    pub elements: libc::c_longlong,
    pub idx: libc::c_int,
    pub obj: *mut libc::c_void,
    pub parent: *mut redisReadTask,
    pub privdata: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct redisReplyObjectFunctions {
    pub createString: Option::<
        unsafe extern "C" fn(
            *const redisReadTask,
            *mut libc::c_char,
            size_t,
        ) -> *mut libc::c_void,
    >,
    pub createArray: Option::<
        unsafe extern "C" fn(*const redisReadTask, size_t) -> *mut libc::c_void,
    >,
    pub createInteger: Option::<
        unsafe extern "C" fn(*const redisReadTask, libc::c_longlong) -> *mut libc::c_void,
    >,
    pub createDouble: Option::<
        unsafe extern "C" fn(
            *const redisReadTask,
            libc::c_double,
            *mut libc::c_char,
            size_t,
        ) -> *mut libc::c_void,
    >,
    pub createNil: Option::<
        unsafe extern "C" fn(*const redisReadTask) -> *mut libc::c_void,
    >,
    pub createBool: Option::<
        unsafe extern "C" fn(*const redisReadTask, libc::c_int) -> *mut libc::c_void,
    >,
    pub freeObject: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct redisReader {
    pub err: libc::c_int,
    pub errstr: [libc::c_char; 128],
    pub buf: *mut libc::c_char,
    pub pos: size_t,
    pub len: size_t,
    pub maxbuf: size_t,
    pub maxelements: libc::c_longlong,
    pub task: *mut *mut redisReadTask,
    pub tasks: libc::c_int,
    pub ridx: libc::c_int,
    pub reply: *mut libc::c_void,
    pub fn_0: *mut redisReplyObjectFunctions,
    pub privdata: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type uint8_t = __uint8_t;
pub type uint16_t = __uint16_t;
pub type uint32_t = __uint32_t;
pub type uint64_t = __uint64_t;
pub type hisds = *mut libc::c_char;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct hisdshdr8 {
    pub len: uint8_t,
    pub alloc: uint8_t,
    pub flags: libc::c_uchar,
    pub buf: [libc::c_char; 0],
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct hisdshdr16 {
    pub len: uint16_t,
    pub alloc: uint16_t,
    pub flags: libc::c_uchar,
    pub buf: [libc::c_char; 0],
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct hisdshdr32 {
    pub len: uint32_t,
    pub alloc: uint32_t,
    pub flags: libc::c_uchar,
    pub buf: [libc::c_char; 0],
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct hisdshdr64 {
    pub len: uint64_t,
    pub alloc: uint64_t,
    pub flags: libc::c_uchar,
    pub buf: [libc::c_char; 0],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct redisContext {
    pub funcs: *const redisContextFuncs,
    pub err: libc::c_int,
    pub errstr: [libc::c_char; 128],
    pub fd: redisFD,
    pub flags: libc::c_int,
    pub obuf: *mut libc::c_char,
    pub reader: *mut redisReader,
    pub connection_type: redisConnectionType,
    pub connect_timeout: *mut timeval,
    pub command_timeout: *mut timeval,
    pub tcp: C2RustUnnamed_0,
    pub unix_sock: C2RustUnnamed,
    pub saddr: *mut sockaddr,
    pub addrlen: size_t,
    pub privdata: *mut libc::c_void,
    pub free_privdata: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
    pub privctx: *mut libc::c_void,
    pub push_cb: Option::<redisPushFn>,
}
pub type redisPushFn = unsafe extern "C" fn(*mut libc::c_void, *mut libc::c_void) -> ();
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed {
    pub path: *mut libc::c_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub host: *mut libc::c_char,
    pub source_addr: *mut libc::c_char,
    pub port: libc::c_int,
}
pub type redisConnectionType = libc::c_uint;
pub const REDIS_CONN_USERFD: redisConnectionType = 2;
pub const REDIS_CONN_UNIX: redisConnectionType = 1;
pub const REDIS_CONN_TCP: redisConnectionType = 0;
pub type redisFD = libc::c_int;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct redisContextFuncs {
    pub free_privctx: Option::<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
    pub async_read: Option::<unsafe extern "C" fn(*mut redisAsyncContext) -> ()>,
    pub async_write: Option::<unsafe extern "C" fn(*mut redisAsyncContext) -> ()>,
    pub read: Option::<
        unsafe extern "C" fn(*mut redisContext, *mut libc::c_char, size_t) -> ssize_t,
    >,
    pub write: Option::<unsafe extern "C" fn(*mut redisContext) -> ssize_t>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cliSSLconfig {
    pub sni: *mut libc::c_char,
    pub cacert: *mut libc::c_char,
    pub cacertdir: *mut libc::c_char,
    pub skip_cert_verify: libc::c_int,
    pub cert: *mut libc::c_char,
    pub key: *mut libc::c_char,
    pub ciphers: *mut libc::c_char,
    pub ciphersuites: *mut libc::c_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cliConnInfo {
    pub hostip: *mut libc::c_char,
    pub hostport: libc::c_int,
    pub input_dbnum: libc::c_int,
    pub auth: *mut libc::c_char,
    pub user: *mut libc::c_char,
}
pub const _ISdigit: C2RustUnnamed_1 = 2048;
pub type C2RustUnnamed_1 = libc::c_uint;
pub const _ISalnum: C2RustUnnamed_1 = 8;
pub const _ISpunct: C2RustUnnamed_1 = 4;
pub const _IScntrl: C2RustUnnamed_1 = 2;
pub const _ISblank: C2RustUnnamed_1 = 1;
pub const _ISgraph: C2RustUnnamed_1 = 32768;
pub const _ISprint: C2RustUnnamed_1 = 16384;
pub const _ISspace: C2RustUnnamed_1 = 8192;
pub const _ISxdigit: C2RustUnnamed_1 = 4096;
pub const _ISalpha: C2RustUnnamed_1 = 1024;
pub const _ISlower: C2RustUnnamed_1 = 512;
pub const _ISupper: C2RustUnnamed_1 = 256;
#[inline]
unsafe extern "C" fn hi_sdslen(s: hisds) -> size_t {
    let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
        as libc::c_uchar;
    match flags as libc::c_int & 7 as libc::c_int {
        0 => return (flags as libc::c_int >> 3 as libc::c_int) as size_t,
        1 => {
            return (*(s
                .offset(-(core::mem::size_of::<hisdshdr8>() as libc::c_ulong as isize))
                as *mut hisdshdr8))
                .len as size_t;
        }
        2 => {
            return (*(s
                .offset(
                    -(core::mem::size_of::<hisdshdr16>() as libc::c_ulong as isize),
                ) as *mut hisdshdr16))
                .len as size_t;
        }
        3 => {
            return (*(s
                .offset(
                    -(core::mem::size_of::<hisdshdr32>() as libc::c_ulong as isize),
                ) as *mut hisdshdr32))
                .len as size_t;
        }
        4 => {
            return (*(s
                .offset(
                    -(core::mem::size_of::<hisdshdr64>() as libc::c_ulong as isize),
                ) as *mut hisdshdr64))
                .len;
        }
        _ => {}
    }
    return 0 as libc::c_int as size_t;
}
#[inline]
unsafe extern "C" fn atoi(mut __nptr: *const libc::c_char) -> libc::c_int {
    return strtol(
        __nptr,
        0 as *mut libc::c_void as *mut *mut libc::c_char,
        10 as libc::c_int,
    ) as libc::c_int;
}
#[inline]
unsafe extern "C" fn tolower(mut __c: libc::c_int) -> libc::c_int {
    return if __c >= -(128 as libc::c_int) && __c < 256 as libc::c_int {
        *(*__ctype_tolower_loc()).offset(__c as isize)
    } else {
        __c
    };
}
#[no_mangle]
pub unsafe extern "C" fn cliSecureConnection(
    mut c: *mut redisContext,
    mut config: cliSSLconfig,
    mut err: *mut *const libc::c_char,
) -> libc::c_int {
    return 0 as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cliWriteConn(
    mut c: *mut redisContext,
    mut buf: *const libc::c_char,
    mut buf_len: size_t,
) -> ssize_t {
    let mut done: libc::c_int = 0 as libc::c_int;
    (*c).obuf = hi_sdscatlen((*c).obuf, buf as *const libc::c_void, buf_len);
    if redisBufferWrite(c, &mut done) == -(1 as libc::c_int) {
        if (*c).flags & 0x1 as libc::c_int == 0 {
            *__errno_location() = 11 as libc::c_int;
        }
        if hi_sdslen((*c).obuf) > buf_len {
            hi_sdsrange(
                (*c).obuf,
                0 as libc::c_int as ssize_t,
                buf_len.wrapping_add(1 as libc::c_int as libc::c_ulong).wrapping_neg()
                    as ssize_t,
            );
        } else {
            hi_sdsclear((*c).obuf);
        }
        return -(1 as libc::c_int) as ssize_t;
    }
    if done != 0 {
        hi_sdsclear((*c).obuf);
        return buf_len as ssize_t;
    }
    if hi_sdslen((*c).obuf) > buf_len {
        hi_sdsrange(
            (*c).obuf,
            0 as libc::c_int as ssize_t,
            buf_len.wrapping_add(1 as libc::c_int as libc::c_ulong).wrapping_neg()
                as ssize_t,
        );
        return 0 as libc::c_int as ssize_t;
    }
    let mut left: size_t = hi_sdslen((*c).obuf);
    hi_sdsclear((*c).obuf);
    return buf_len.wrapping_sub(left) as ssize_t;
}
#[no_mangle]
pub unsafe extern "C" fn cliSecureInit() -> libc::c_int {
    return 0 as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn readArgFromStdin() -> hisds {
    let mut buf: [libc::c_char; 1024] = [0; 1024];
    let mut arg: hisds = hi_sdsempty();
    loop {
        let mut nread: libc::c_int = read(
            fileno(stdin),
            buf.as_mut_ptr() as *mut libc::c_void,
            1024 as libc::c_int as size_t,
        ) as libc::c_int;
        if nread == 0 as libc::c_int {
            break;
        }
        if nread == -(1 as libc::c_int) {
            perror(b"Reading from standard input\0" as *const u8 as *const libc::c_char);
            exit(1 as libc::c_int);
        }
        arg = hi_sdscatlen(
            arg,
            buf.as_mut_ptr() as *const libc::c_void,
            nread as size_t,
        );
    }
    return arg;
}
#[no_mangle]
pub unsafe extern "C" fn getSdsArrayFromArgv(
    mut argc: libc::c_int,
    mut argv: *mut *mut libc::c_char,
    mut quoted: libc::c_int,
) -> *mut hisds {
    let mut res: *mut hisds = hi_sds_malloc(
        (core::mem::size_of::<hisds>() as libc::c_ulong)
            .wrapping_mul(argc as libc::c_ulong),
    ) as *mut hisds;
    let mut j: libc::c_int = 0 as libc::c_int;
    while j < argc {
        if quoted != 0 {
            let mut unquoted: hisds = unquoteCString(*argv.offset(j as isize));
            if unquoted.is_null() {
                loop {
                    j -= 1;
                    if !(j >= 0 as libc::c_int) {
                        break;
                    }
                    hi_sdsfree(*res.offset(j as isize));
                }
                hi_sds_free(res as *mut libc::c_void);
                return 0 as *mut hisds;
            }
            let ref mut fresh0 = *res.offset(j as isize);
            *fresh0 = unquoted;
        } else {
            let ref mut fresh1 = *res.offset(j as isize);
            *fresh1 = hi_sdsnew(*argv.offset(j as isize));
        }
        j += 1;
    }
    return res;
}
#[no_mangle]
pub unsafe extern "C" fn unquoteCString(mut str: *mut libc::c_char) -> hisds {
    let mut count: libc::c_int = 0;
    let mut unquoted: *mut hisds = hi_sdssplitargs(str, &mut count);
    let mut res: hisds = 0 as hisds;
    if !unquoted.is_null() && count == 1 as libc::c_int {
        res = *unquoted.offset(0 as libc::c_int as isize);
        let ref mut fresh2 = *unquoted.offset(0 as libc::c_int as isize);
        *fresh2 = 0 as hisds;
    }
    if !unquoted.is_null() {
        hi_sdsfreesplitres(unquoted, count);
    }
    return res;
}
unsafe extern "C" fn percentDecode(
    mut pe: *const libc::c_char,
    mut len: size_t,
) -> hisds {
    let mut end: *const libc::c_char = pe.offset(len as isize);
    let mut ret: hisds = hi_sdsempty();
    let mut curr: *const libc::c_char = pe;
    while curr < end {
        if *curr as libc::c_int == '%' as i32 {
            if (end.offset_from(curr) as libc::c_long) < 2 as libc::c_int as libc::c_long
            {
                fprintf(
                    stderr,
                    b"Incomplete URI encoding\n\0" as *const u8 as *const libc::c_char,
                );
                exit(1 as libc::c_int);
            }
            let mut h: libc::c_char = ({
                let mut __res: libc::c_int = 0;
                if core::mem::size_of::<libc::c_char>() as libc::c_ulong
                    > 1 as libc::c_int as libc::c_ulong
                {
                    if 0 != 0 {
                        curr = curr.offset(1);
                        let mut __c: libc::c_int = *curr as libc::c_int;
                        __res = if __c < -(128 as libc::c_int)
                            || __c > 255 as libc::c_int
                        {
                            __c
                        } else {
                            *(*__ctype_tolower_loc()).offset(__c as isize)
                        };
                    } else {
                        curr = curr.offset(1);
                        __res = tolower(*curr as libc::c_int);
                    }
                } else {
                    curr = curr.offset(1);
                    __res = *(*__ctype_tolower_loc())
                        .offset(*curr as libc::c_int as isize);
                }
                __res
            }) as libc::c_char;
            let mut l: libc::c_char = ({
                let mut __res: libc::c_int = 0;
                if core::mem::size_of::<libc::c_char>() as libc::c_ulong
                    > 1 as libc::c_int as libc::c_ulong
                {
                    if 0 != 0 {
                        curr = curr.offset(1);
                        let mut __c: libc::c_int = *curr as libc::c_int;
                        __res = if __c < -(128 as libc::c_int)
                            || __c > 255 as libc::c_int
                        {
                            __c
                        } else {
                            *(*__ctype_tolower_loc()).offset(__c as isize)
                        };
                    } else {
                        curr = curr.offset(1);
                        __res = tolower(*curr as libc::c_int);
                    }
                } else {
                    curr = curr.offset(1);
                    __res = *(*__ctype_tolower_loc())
                        .offset(*curr as libc::c_int as isize);
                }
                __res
            }) as libc::c_char;
            if !(*(*__ctype_b_loc()).offset(h as libc::c_int as isize) as libc::c_int
                & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0
                || h as libc::c_int >= 'a' as i32 && h as libc::c_int <= 'f' as i32)
                || !(*(*__ctype_b_loc()).offset(l as libc::c_int as isize) as libc::c_int
                    & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0
                    || l as libc::c_int >= 'a' as i32 && l as libc::c_int <= 'f' as i32)
            {
                fprintf(
                    stderr,
                    b"Illegal character in URI encoding\n\0" as *const u8
                        as *const libc::c_char,
                );
                exit(1 as libc::c_int);
            }
            let mut c: libc::c_char = (((if *(*__ctype_b_loc())
                .offset(h as libc::c_int as isize) as libc::c_int
                & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0
            {
                h as libc::c_int - '0' as i32
            } else {
                h as libc::c_int - 'a' as i32 + 10 as libc::c_int
            }) << 4 as libc::c_int)
                + (if *(*__ctype_b_loc()).offset(l as libc::c_int as isize)
                    as libc::c_int
                    & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0
                {
                    l as libc::c_int - '0' as i32
                } else {
                    l as libc::c_int - 'a' as i32 + 10 as libc::c_int
                })) as libc::c_char;
            ret = hi_sdscatlen(
                ret,
                &mut c as *mut libc::c_char as *const libc::c_void,
                1 as libc::c_int as size_t,
            );
            curr = curr.offset(1);
        } else {
            let fresh3 = curr;
            curr = curr.offset(1);
            ret = hi_sdscatlen(
                ret,
                fresh3 as *const libc::c_void,
                1 as libc::c_int as size_t,
            );
        }
    }
    return ret;
}
#[no_mangle]
pub unsafe extern "C" fn parseRedisUri(
    mut uri: *const libc::c_char,
    mut tool_name: *const libc::c_char,
    mut connInfo: *mut cliConnInfo,
    mut tls_flag: *mut libc::c_int,
) {
    let mut scheme: *const libc::c_char = b"redis://\0" as *const u8
        as *const libc::c_char;
    let mut tlsscheme: *const libc::c_char = b"rediss://\0" as *const u8
        as *const libc::c_char;
    let mut curr: *const libc::c_char = uri;
    let mut end: *const libc::c_char = uri.offset(strlen(uri) as isize);
    let mut userinfo: *const libc::c_char = 0 as *const libc::c_char;
    let mut username: *const libc::c_char = 0 as *const libc::c_char;
    let mut port: *const libc::c_char = 0 as *const libc::c_char;
    let mut host: *const libc::c_char = 0 as *const libc::c_char;
    let mut path: *const libc::c_char = 0 as *const libc::c_char;
    if strncasecmp(tlsscheme, curr, strlen(tlsscheme)) == 0 {
        fprintf(
            stderr,
            b"rediss:// is only supported when %s is compiled with OpenSSL\n\0"
                as *const u8 as *const libc::c_char,
            tool_name,
        );
        exit(1 as libc::c_int);
    } else {
        if strncasecmp(scheme, curr, strlen(scheme)) == 0 {
            curr = curr.offset(strlen(scheme) as isize);
        } else {
            fprintf(
                stderr,
                b"Invalid URI scheme\n\0" as *const u8 as *const libc::c_char,
            );
            exit(1 as libc::c_int);
        }
    }
    if curr == end {
        return;
    }
    userinfo = strchr(curr, '@' as i32);
    if !userinfo.is_null() {
        username = strchr(curr, ':' as i32);
        if !username.is_null() && username < userinfo {
            (*connInfo)
                .user = percentDecode(
                curr,
                username.offset_from(curr) as libc::c_long as size_t,
            );
            curr = username.offset(1 as libc::c_int as isize);
        }
        (*connInfo)
            .auth = percentDecode(
            curr,
            userinfo.offset_from(curr) as libc::c_long as size_t,
        );
        curr = userinfo.offset(1 as libc::c_int as isize);
    }
    if curr == end {
        return;
    }
    path = strchr(curr, '/' as i32);
    if *curr as libc::c_int != '/' as i32 {
        host = if !path.is_null() {
            path.offset(-(1 as libc::c_int as isize))
        } else {
            end
        };
        port = strchr(curr, ':' as i32);
        if !port.is_null() {
            (*connInfo).hostport = atoi(port.offset(1 as libc::c_int as isize));
            host = port.offset(-(1 as libc::c_int as isize));
        }
        hi_sdsfree((*connInfo).hostip);
        (*connInfo)
            .hostip = hi_sdsnewlen(
            curr as *const libc::c_void,
            (host.offset_from(curr) as libc::c_long + 1 as libc::c_int as libc::c_long)
                as size_t,
        );
    }
    curr = if !path.is_null() { path.offset(1 as libc::c_int as isize) } else { end };
    if curr == end {
        return;
    }
    (*connInfo).input_dbnum = atoi(curr);
}
#[no_mangle]
pub unsafe extern "C" fn freeCliConnInfo(mut connInfo: cliConnInfo) {
    if !(connInfo.hostip).is_null() {
        hi_sdsfree(connInfo.hostip);
    }
    if !(connInfo.auth).is_null() {
        hi_sdsfree(connInfo.auth);
    }
    if !(connInfo.user).is_null() {
        hi_sdsfree(connInfo.user);
    }
}
#[no_mangle]
pub unsafe extern "C" fn escapeJsonString(
    mut s: hisds,
    mut p: *const libc::c_char,
    mut len: size_t,
) -> hisds {
    s = hi_sdscatlen(
        s,
        b"\"\0" as *const u8 as *const libc::c_char as *const libc::c_void,
        1 as libc::c_int as size_t,
    );
    loop {
        let fresh4 = len;
        len = len.wrapping_sub(1);
        if !(fresh4 != 0) {
            break;
        }
        match *p as libc::c_int {
            92 | 34 => {
                s = hi_sdscatprintf(
                    s,
                    b"\\%c\0" as *const u8 as *const libc::c_char,
                    *p as libc::c_int,
                );
            }
            10 => {
                s = hi_sdscatlen(
                    s,
                    b"\\n\0" as *const u8 as *const libc::c_char as *const libc::c_void,
                    2 as libc::c_int as size_t,
                );
            }
            12 => {
                s = hi_sdscatlen(
                    s,
                    b"\\f\0" as *const u8 as *const libc::c_char as *const libc::c_void,
                    2 as libc::c_int as size_t,
                );
            }
            13 => {
                s = hi_sdscatlen(
                    s,
                    b"\\r\0" as *const u8 as *const libc::c_char as *const libc::c_void,
                    2 as libc::c_int as size_t,
                );
            }
            9 => {
                s = hi_sdscatlen(
                    s,
                    b"\\t\0" as *const u8 as *const libc::c_char as *const libc::c_void,
                    2 as libc::c_int as size_t,
                );
            }
            8 => {
                s = hi_sdscatlen(
                    s,
                    b"\\b\0" as *const u8 as *const libc::c_char as *const libc::c_void,
                    2 as libc::c_int as size_t,
                );
            }
            _ => {
                s = hi_sdscatprintf(
                    s,
                    if *(p as *mut libc::c_uchar) as libc::c_int <= 0x1f as libc::c_int {
                        b"\\u%04x\0" as *const u8 as *const libc::c_char
                    } else {
                        b"%c\0" as *const u8 as *const libc::c_char
                    },
                    *p as libc::c_int,
                );
            }
        }
        p = p.offset(1);
    }
    return hi_sdscatlen(
        s,
        b"\"\0" as *const u8 as *const libc::c_char as *const libc::c_void,
        1 as libc::c_int as size_t,
    );
}