supplement 2.31 → 2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/mkrf_conf +2 -2
- data/lib/supplement/locked.c +0 -19
- data/lib/supplement/terminal.c +6 -30
- data/lib/supplement.c +16 -43
- data/lib/supplement.h +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a7108dafb3707ef51a08d12ac718a6c00358bae7b3f98e32448886f8d9dd29b
|
|
4
|
+
data.tar.gz: d389cf607de0a21d6b4cd3a02550a25200f68205cbaad22ed442025123420bed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4006b5753eff8a4cce364b2e26a0717493948177e2476818113b7a62070fdf69ff71bc72105a14cf7d02a639471a282e99181e7f702f618678db63483dc7e1e
|
|
7
|
+
data.tar.gz: ae9e62b121909a5cdfb63abea92a3abd2ca71bf887a6364806dd2af55c7e44796bfcaa09cafb326f14f27ffa84332817630c8fb4aced20995220d4b43af0f5b5
|
data/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BSD-2-clause license, extended by language use conditions
|
|
2
2
|
|
|
3
|
-
Copyright (C) 2009-
|
|
3
|
+
Copyright (C) 2009-2026, Bertram Scharpf <software@bertram-scharpf.de>.
|
|
4
4
|
All rights reserved.
|
|
5
5
|
|
|
6
6
|
Redistribution and use in source and binary forms, with or without
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# supplement 2.
|
|
1
|
+
# supplement 2.32 -- Useful Ruby enhancements
|
|
2
2
|
|
|
3
3
|
Some simple Ruby extensions.
|
|
4
4
|
|
|
@@ -48,7 +48,7 @@ one of them to be included into the Ruby standard.
|
|
|
48
48
|
|
|
49
49
|
## Copyright
|
|
50
50
|
|
|
51
|
-
* (C) 2009-
|
|
51
|
+
* (C) 2009-2026 Bertram Scharpf <software@bertram-scharpf.de>
|
|
52
52
|
* License: [BSD-2-Clause+](./LICENSE)
|
|
53
53
|
* Repository: [ruby-supplement](https://github.com/BertramScharpf/ruby-supplement)
|
|
54
54
|
|
data/lib/mkrf_conf
CHANGED
data/lib/supplement/locked.c
CHANGED
|
@@ -28,29 +28,14 @@
|
|
|
28
28
|
VALUE
|
|
29
29
|
rb_locked_init( int argc, VALUE *argv, VALUE self)
|
|
30
30
|
{
|
|
31
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
32
|
-
rb_io_t *fptr;
|
|
33
|
-
#endif
|
|
34
31
|
struct timeval time;
|
|
35
32
|
int op;
|
|
36
33
|
|
|
37
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
38
|
-
GetOpenFile( self, fptr);
|
|
39
|
-
#endif
|
|
40
|
-
|
|
41
34
|
rb_call_super_kw(argc, argv, RB_PASS_CALLED_KEYWORDS);
|
|
42
35
|
|
|
43
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
44
|
-
op = fptr->mode & FMODE_WRITABLE ? LOCK_EX : LOCK_SH;
|
|
45
|
-
#else
|
|
46
36
|
op = rb_io_mode( self) & FMODE_WRITABLE ? LOCK_EX : LOCK_SH;
|
|
47
|
-
#endif
|
|
48
37
|
op |= LOCK_NB;
|
|
49
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
50
|
-
while (flock( fptr->fd, op) < 0) {
|
|
51
|
-
#else
|
|
52
38
|
while (flock( rb_io_descriptor( self), op) < 0) {
|
|
53
|
-
#endif
|
|
54
39
|
static ID id_lock_failed = 0;
|
|
55
40
|
|
|
56
41
|
switch (errno) {
|
|
@@ -72,11 +57,7 @@ rb_locked_init( int argc, VALUE *argv, VALUE self)
|
|
|
72
57
|
}
|
|
73
58
|
break;
|
|
74
59
|
default:
|
|
75
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
76
|
-
rb_sys_fail_str( fptr->pathv);
|
|
77
|
-
#else
|
|
78
60
|
rb_sys_fail_str( rb_io_path( self));
|
|
79
|
-
#endif
|
|
80
61
|
break;
|
|
81
62
|
}
|
|
82
63
|
}
|
data/lib/supplement/terminal.c
CHANGED
|
@@ -13,14 +13,6 @@ static VALUE io_unget( VALUE);
|
|
|
13
13
|
static VALUE io_reset( VALUE);
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
17
|
-
#define RB_FAIL_PATH( io, fptr) ((fptr)->pathv)
|
|
18
|
-
#define RB_IO_VAR( io, fptr) fptr
|
|
19
|
-
#else
|
|
20
|
-
#define RB_FAIL_PATH( io, fptr) rb_io_path( io)
|
|
21
|
-
#define RB_IO_VAR( io, fptr) io
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
16
|
/*
|
|
25
17
|
* call-seq:
|
|
26
18
|
* io.unget(str, ...) -> nil
|
|
@@ -33,28 +25,20 @@ static VALUE io_reset( VALUE);
|
|
|
33
25
|
VALUE
|
|
34
26
|
rb_io_unget( int argc, VALUE *argv, VALUE io)
|
|
35
27
|
{
|
|
36
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
37
|
-
rb_io_t *fptr;
|
|
38
|
-
#endif
|
|
39
28
|
int fd;
|
|
40
29
|
struct termios oldtio, newtio;
|
|
41
30
|
void *v[5];
|
|
42
31
|
|
|
43
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
44
|
-
GetOpenFile( io, fptr);
|
|
45
|
-
fd = fptr->fd;
|
|
46
|
-
#else
|
|
47
32
|
fd = rb_io_descriptor( io);
|
|
48
|
-
#endif
|
|
49
33
|
|
|
50
34
|
if (tcgetattr( fd, &oldtio) < 0)
|
|
51
|
-
rb_sys_fail_str(
|
|
35
|
+
rb_sys_fail_str( rb_io_path( io));
|
|
52
36
|
newtio = oldtio;
|
|
53
37
|
newtio.c_iflag &= ~ICRNL;
|
|
54
38
|
if (tcsetattr( fd, TCSANOW, &newtio) < 0)
|
|
55
|
-
rb_sys_fail_str(
|
|
39
|
+
rb_sys_fail_str( rb_io_path( io));
|
|
56
40
|
|
|
57
|
-
v[0] = &fd, v[1] = (void *)
|
|
41
|
+
v[0] = &fd, v[1] = (void *) io, v[2] = &oldtio,
|
|
58
42
|
v[3] = &argc, v[4] = (void *) argv;
|
|
59
43
|
return rb_ensure( io_unget, (VALUE) v, io_reset, (VALUE) v);
|
|
60
44
|
}
|
|
@@ -76,7 +60,7 @@ io_unget( VALUE v)
|
|
|
76
60
|
p = RSTRING_PTR(str);
|
|
77
61
|
for (i = RSTRING_LEN(str); i; --i, ++p)
|
|
78
62
|
if (ioctl( *(int *) vp[0], TIOCSTI, p) < 0)
|
|
79
|
-
rb_sys_fail_str(
|
|
63
|
+
rb_sys_fail_str( rb_io_path( (VALUE) vp[1]));
|
|
80
64
|
}
|
|
81
65
|
return Qnil;
|
|
82
66
|
}
|
|
@@ -87,7 +71,7 @@ io_reset( VALUE v)
|
|
|
87
71
|
void **vp = (void **) v;
|
|
88
72
|
|
|
89
73
|
if (tcsetattr( *(int *) vp[0], TCSANOW, (struct termios *) vp[2]) < 0)
|
|
90
|
-
rb_sys_fail_str(
|
|
74
|
+
rb_sys_fail_str( rb_io_path( (VALUE) vp[1]));
|
|
91
75
|
|
|
92
76
|
return Qnil;
|
|
93
77
|
}
|
|
@@ -105,22 +89,14 @@ io_reset( VALUE v)
|
|
|
105
89
|
VALUE
|
|
106
90
|
rb_io_wingeom( VALUE self)
|
|
107
91
|
{
|
|
108
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
109
|
-
rb_io_t *fptr;
|
|
110
|
-
#endif
|
|
111
92
|
int fd;
|
|
112
93
|
struct winsize w;
|
|
113
94
|
VALUE r;
|
|
114
95
|
|
|
115
|
-
#ifdef FEATURE_OLD_IO_FUNCTIONS
|
|
116
|
-
GetOpenFile( self, fptr);
|
|
117
|
-
fd = fptr->fd;
|
|
118
|
-
#else
|
|
119
96
|
fd = rb_io_descriptor( self);
|
|
120
|
-
#endif
|
|
121
97
|
|
|
122
98
|
if (ioctl( fd, TIOCGWINSZ, &w) < 0)
|
|
123
|
-
rb_sys_fail_str(
|
|
99
|
+
rb_sys_fail_str( rb_io_path( self));
|
|
124
100
|
r = rb_ary_new2( 4);
|
|
125
101
|
rb_ary_store( r, 0, INT2NUM( w.ws_col));
|
|
126
102
|
rb_ary_store( r, 1, INT2NUM( w.ws_row));
|
data/lib/supplement.c
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
static long supplement_args_len_default( int, VALUE *);
|
|
15
|
-
static void supplement_make_ellipse( void);
|
|
16
15
|
static void supplement_ary_assure_notempty( VALUE);
|
|
17
16
|
static VALUE supplement_index_blk( VALUE);
|
|
18
17
|
static VALUE supplement_index_ref( VALUE, VALUE);
|
|
@@ -21,8 +20,7 @@ static VALUE supplement_rindex_ref( VALUE, VALUE);
|
|
|
21
20
|
static VALUE supplement_do_unumask( VALUE);
|
|
22
21
|
|
|
23
22
|
|
|
24
|
-
static
|
|
25
|
-
static long supplement_len_ell = 0;
|
|
23
|
+
static const char *supplement_ellipse = "...";
|
|
26
24
|
|
|
27
25
|
static ID id_delete_at = 0;
|
|
28
26
|
static ID id_cmp = 0;
|
|
@@ -112,28 +110,6 @@ rb_krn_tap_bang( VALUE obj)
|
|
|
112
110
|
}
|
|
113
111
|
|
|
114
112
|
|
|
115
|
-
/*
|
|
116
|
-
* call-seq:
|
|
117
|
-
* with { |x| ... } -> obj
|
|
118
|
-
*
|
|
119
|
-
* Warning. This method will be removed. Use +Kernel#then+ instead.
|
|
120
|
-
*
|
|
121
|
-
* Yields +x+ to the block.
|
|
122
|
-
* The difference to +tap+ is that the block's result will be returned.
|
|
123
|
-
*
|
|
124
|
-
* Use this to narrow your namespace.
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
VALUE
|
|
129
|
-
rb_krn_with( VALUE obj)
|
|
130
|
-
{
|
|
131
|
-
rb_category_warning(RB_WARN_CATEGORY_DEPRECATED,
|
|
132
|
-
"Kernel#with will be removed from the supplement gem. Use Kernel#then instead.");
|
|
133
|
-
return rb_yield( obj);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
113
|
/*
|
|
138
114
|
* Document-class: Module
|
|
139
115
|
*/
|
|
@@ -413,15 +389,6 @@ supplement_args_len_default( int argc, VALUE *argv)
|
|
|
413
389
|
return r;
|
|
414
390
|
}
|
|
415
391
|
|
|
416
|
-
void
|
|
417
|
-
supplement_make_ellipse( void)
|
|
418
|
-
{
|
|
419
|
-
if (!NIL_P( supplement_ellipse))
|
|
420
|
-
return;
|
|
421
|
-
supplement_ellipse = rb_str_new2( "...");
|
|
422
|
-
supplement_len_ell = rb_str_strlen( supplement_ellipse);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
392
|
/*
|
|
426
393
|
* call-seq:
|
|
427
394
|
* axe( n = 80) -> str
|
|
@@ -445,12 +412,16 @@ rb_str_axe( int argc, VALUE *argv, VALUE str)
|
|
|
445
412
|
|
|
446
413
|
oldlen = rb_str_strlen( str);
|
|
447
414
|
if (newlen < oldlen) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
415
|
+
VALUE ell;
|
|
416
|
+
long le;
|
|
417
|
+
|
|
418
|
+
ell = rb_str_new2( supplement_ellipse);
|
|
419
|
+
le = rb_str_strlen( ell);
|
|
420
|
+
if (newlen >= le) {
|
|
421
|
+
ret = rb_str_substr( str, 0, newlen - le);
|
|
422
|
+
rb_str_append( ret, ell);
|
|
452
423
|
} else
|
|
453
|
-
ret = rb_str_substr(
|
|
424
|
+
ret = rb_str_substr( ell, 0, newlen);
|
|
454
425
|
} else
|
|
455
426
|
ret = str;
|
|
456
427
|
return ret;
|
|
@@ -484,12 +455,15 @@ rb_str_axe_bang( int argc, VALUE *argv, VALUE str)
|
|
|
484
455
|
|
|
485
456
|
oldlen = rb_str_strlen( str);
|
|
486
457
|
if (newlen < oldlen) {
|
|
458
|
+
VALUE ell;
|
|
459
|
+
long le;
|
|
487
460
|
long re;
|
|
488
461
|
|
|
489
462
|
rb_str_update( str, newlen, oldlen - newlen, rb_str_new( NULL, 0));
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
463
|
+
ell = rb_str_new2( supplement_ellipse);
|
|
464
|
+
le = rb_str_strlen( ell);
|
|
465
|
+
re = newlen < le ? newlen : le;
|
|
466
|
+
rb_str_update( str, newlen - re, re, rb_str_substr( ell, 0, re));
|
|
493
467
|
return str;
|
|
494
468
|
} else
|
|
495
469
|
return Qnil;
|
|
@@ -1227,7 +1201,6 @@ void Init_supplement( void)
|
|
|
1227
1201
|
rb_define_method( rb_cObject, "new_string", rb_obj_new_string, 0);
|
|
1228
1202
|
rb_define_method( rb_cObject, "nil_if", rb_obj_nil_if, 1);
|
|
1229
1203
|
rb_define_method( rb_mKernel, "tap!", rb_krn_tap_bang, 0);
|
|
1230
|
-
rb_define_method( rb_mKernel, "with", rb_krn_with, 0);
|
|
1231
1204
|
|
|
1232
1205
|
rb_define_method( rb_cModule, "plain_name", rb_module_plain_name, 0);
|
|
1233
1206
|
|
data/lib/supplement.h
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: supplement
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '2.
|
|
4
|
+
version: '2.32'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bertram Scharpf
|
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
81
81
|
requirements:
|
|
82
82
|
- - ">="
|
|
83
83
|
- !ruby/object:Gem::Version
|
|
84
|
-
version: 3.
|
|
84
|
+
version: 3.3.0
|
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - ">="
|