-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathName.java
More file actions
856 lines (783 loc) · 23.5 KB
/
Copy pathName.java
File metadata and controls
856 lines (783 loc) · 23.5 KB
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
package org.xbill.DNS;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
/**
* A representation of a domain name. It may either be absolute (fully qualified) or relative.
*
* @author Brian Wellington
*/
@Slf4j
public class Name implements Comparable<Name>, Serializable {
private static final long serialVersionUID = -6036624806201621219L;
private static final int LABEL_NORMAL = 0;
private static final int LABEL_COMPRESSION = 0xC0;
private static final int LABEL_MASK = 0xC0;
/* The name data */
private byte[] name;
/* Effectively an 8 byte array, where the bytes store per-label offsets. */
private long offsets;
/* Precomputed hashcode. */
private transient int hashcode;
/* The number of labels in this name. */
private int labels;
private static final byte[] emptyLabel = new byte[] {(byte) 0};
private static final byte[] wildLabel = new byte[] {(byte) 1, (byte) '*'};
/** The root name */
public static final Name root;
/** The root name */
public static final Name empty;
/** The maximum length of a Name */
private static final int MAXNAME = 255;
/** The maximum length of a label a Name */
private static final int MAXLABEL = 63;
/** The maximum number of cached offsets, the first offset (always zero) is not stored. */
private static final int MAXOFFSETS = 9;
/* Used to efficiently convert bytes to lowercase */
private static final byte[] lowercase = new byte[256];
/* Used in wildcard names. */
private static final Name wild;
static {
for (int i = 0; i < lowercase.length; i++) {
if (i < 'A' || i > 'Z') {
lowercase[i] = (byte) i;
} else {
lowercase[i] = (byte) (i - 'A' + 'a');
}
}
root = new Name();
root.name = emptyLabel;
root.labels = 1;
empty = new Name();
empty.name = new byte[0];
wild = new Name();
wild.name = wildLabel;
wild.labels = 1;
}
private Name() {}
private void setOffset(int n, int offset) {
if (n == 0 || n >= MAXOFFSETS) {
return;
}
int shift = 8 * (n - 1);
offsets &= ~(0xFFL << shift);
offsets |= (long) offset << shift;
}
private int offset(int n) {
if (n == 0) {
return 0;
}
if (n < 1 || n >= labels) {
throw new IllegalArgumentException("label out of range");
}
if (n < MAXOFFSETS) {
int shift = 8 * (n - 1);
return (int) (offsets >>> shift) & 0xFF;
} else {
int pos = (int) (offsets >>> (8 * (MAXOFFSETS - 2))) & 0xFF;
for (int i = MAXOFFSETS - 1; i < n; i++) {
pos += name[pos] + 1;
}
return pos;
}
}
private static void copy(Name src, Name dst) {
dst.name = src.name;
dst.offsets = src.offsets;
dst.labels = src.labels;
}
private void append(byte[] array, int arrayOffset, int numLabels) throws NameTooLongException {
int length = name == null ? 0 : name.length;
int appendLength = 0;
for (int i = 0, pos = arrayOffset; i < numLabels; i++) {
// add one byte for the label length
int len = array[pos] + 1;
pos += len;
appendLength += len;
}
int newlength = length + appendLength;
if (newlength > MAXNAME) {
throw new NameTooLongException();
}
byte[] newname;
if (name != null) {
newname = Arrays.copyOf(name, newlength);
} else {
newname = new byte[newlength];
}
System.arraycopy(array, arrayOffset, newname, length, appendLength);
name = newname;
for (int i = 0, pos = length; i < numLabels && i < MAXOFFSETS; i++) {
setOffset(labels + i, pos);
pos += newname[pos] + 1;
}
labels += numLabels;
}
private void append(char[] label, int len) throws NameTooLongException {
int destPos = prepareAppend(len);
for (int i = 0; i < len; i++) {
name[destPos + i] = (byte) label[i];
}
}
private int prepareAppend(int len) throws NameTooLongException {
int length = name == null ? 0 : name.length;
// add one byte for the label length
int newlength = length + 1 + len;
if (newlength > MAXNAME) {
throw new NameTooLongException();
}
byte[] newname;
if (name != null) {
newname = Arrays.copyOf(name, newlength);
} else {
newname = new byte[newlength];
}
newname[length] = (byte) len;
name = newname;
setOffset(labels, length);
labels++;
return length + 1;
}
private void appendFromString(String fullName, char[] label, int length)
throws TextParseException {
try {
append(label, length);
} catch (NameTooLongException e) {
throw new TextParseException(fullName, "Name too long", e);
}
}
private void appendFromString(String fullName, byte[] label, int n) throws TextParseException {
try {
append(label, 0, n);
} catch (NameTooLongException e) {
throw new TextParseException(fullName, "Name too long");
}
}
/**
* Create a new name from a string and an origin. This does not automatically make the name
* absolute; it will be absolute if it has a trailing dot or an absolute origin is appended.
*
* @param s The string to be converted
* @param origin If the name is not absolute, the origin to be appended.
* @throws TextParseException The name is invalid.
*/
public Name(String s, Name origin) throws TextParseException {
switch (s) {
case "":
throw new TextParseException("empty name");
case "@":
if (origin == null) {
copy(empty, this);
} else {
copy(origin, this);
}
return;
case ".": // full stop
copy(root, this);
return;
}
int labelstart = -1;
int pos = 0;
char[] label = new char[MAXLABEL];
boolean escaped = false;
int digits = 0;
int intval = 0;
boolean absolute = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 0xff) {
throw new TextParseException(s, "Illegal character in name");
}
if (escaped) {
if (c >= '0' && c <= '9' && digits < 3) {
digits++;
intval *= 10;
intval += c - '0';
if (intval > 255) {
throw new TextParseException(s, "bad escape");
}
if (digits < 3) {
continue;
}
c = (char) intval;
} else if (digits > 0 && digits < 3) {
throw new TextParseException(s, "bad escape");
}
if (pos >= MAXLABEL) {
throw new TextParseException(s, "label too long");
}
labelstart = pos;
label[pos++] = c;
escaped = false;
} else if (c == '\\') {
escaped = true;
digits = 0;
intval = 0;
} else if (c == '.') {
if (labelstart == -1) {
throw new TextParseException(s, "invalid empty label");
}
appendFromString(s, label, pos);
labelstart = -1;
pos = 0;
} else {
if (labelstart == -1) {
labelstart = i;
}
if (pos >= MAXLABEL) {
throw new TextParseException(s, "label too long");
}
label[pos++] = c;
}
}
if (digits > 0 && digits < 3 || escaped) {
throw new TextParseException(s, "bad escape");
}
if (labelstart == -1) {
appendFromString(s, emptyLabel, 1);
absolute = true;
} else {
appendFromString(s, label, pos);
}
if (origin != null && !absolute) {
absolute = origin.isAbsolute();
appendFromString(s, origin.name, origin.labels);
}
// A relative name that is MAXNAME octets long is a strange and wonderful thing.
// Not technically in violation, but it can not be used for queries as it needs
// to be made absolute by appending at the very least the empty label at the
// end, which there is no room for. To make life easier for everyone, let's only
// allow Names that are MAXNAME long if they are absolute.
if (!absolute && length() == MAXNAME) {
throw new TextParseException(s, "Name too long");
}
}
/**
* Create a new name from a string. This does not automatically make the name absolute; it will be
* absolute if it has a trailing dot.
*
* @param s The string to be converted
* @throws TextParseException The name is invalid.
*/
public Name(String s) throws TextParseException {
this(s, null);
}
/**
* Create a new name from a string and an origin. This does not automatically make the name
* absolute; it will be absolute if it has a trailing dot or an absolute origin is appended. This
* is identical to the constructor, except that it will avoid creating new objects in some cases.
*
* @param s The string to be converted
* @param origin If the name is not absolute, the origin to be appended.
* @throws TextParseException The name is invalid.
*/
public static Name fromString(String s, Name origin) throws TextParseException {
if (s.equals("@")) {
return origin != null ? origin : empty;
} else if (s.equals(".")) {
return root;
}
return new Name(s, origin);
}
/**
* Create a new name from a string. This does not automatically make the name absolute; it will be
* absolute if it has a trailing dot. This is identical to the constructor, except that it will
* avoid creating new objects in some cases.
*
* @param s The string to be converted
* @throws TextParseException The name is invalid.
*/
public static Name fromString(String s) throws TextParseException {
return fromString(s, null);
}
/**
* Create a new name from a constant string. This should only be used when the name is known to be
* good - that is, when it is constant.
*
* @param s The string to be converted
* @throws IllegalArgumentException The name is invalid.
*/
public static Name fromConstantString(String s) {
try {
return fromString(s, null);
} catch (TextParseException e) {
throw new IllegalArgumentException("Invalid name '" + s + "'");
}
}
/**
* Create a new name from DNS a wire format message
*
* @param in A stream containing the DNS message which is currently positioned at the start of the
* name to be read.
*/
public Name(DNSInput in) throws WireParseException {
int len;
int pos;
boolean done = false;
byte[] label = new byte[MAXLABEL + 1];
boolean savedState = false;
while (!done) {
len = in.readU8();
switch (len & LABEL_MASK) {
case LABEL_NORMAL:
if (len == 0) {
append(emptyLabel, 0, 1);
done = true;
} else {
label[0] = (byte) len;
in.readByteArray(label, 1, len);
append(label, 0, 1);
}
break;
case LABEL_COMPRESSION:
pos = in.readU8();
pos += (len & ~LABEL_MASK) << 8;
log.trace("currently {}, pointer to {}", in.current(), pos);
if (pos >= in.current() - 2) {
throw new WireParseException("bad compression");
}
if (!savedState) {
in.save();
savedState = true;
}
in.jump(pos);
log.trace("current name '{}', seeking to {}", this, pos);
break;
default:
throw new WireParseException("bad label type");
}
}
if (savedState) {
in.restore();
}
}
/**
* Create a new name from DNS wire format
*
* @param b A byte array containing the wire format of the name.
*/
public Name(byte[] b) throws IOException {
this(new DNSInput(b));
}
/**
* Create a new name by removing labels from the beginning of an existing Name
*
* @param src An existing Name
* @param n The number of labels to remove from the beginning in the copy
*/
public Name(Name src, int n) {
if (n > src.labels) {
throw new IllegalArgumentException("attempted to remove too many labels");
}
if (n == src.labels) {
copy(empty, this);
return;
}
labels = src.labels - n;
name = Arrays.copyOfRange(src.name, src.offset(n), src.name.length);
int strippedBytes = src.offset(n);
for (int i = 1; i < MAXOFFSETS && i < labels; i++) {
setOffset(i, src.offset(i + n) - strippedBytes);
}
}
/**
* Creates a new name by concatenating two existing names. If the {@code prefix} name is absolute
* {@code prefix} is returned unmodified.
*
* @param prefix The prefix name. Must be relative.
* @param suffix The suffix name.
* @return The concatenated name.
* @throws NameTooLongException The name is too long.
*/
public static Name concatenate(Name prefix, Name suffix) throws NameTooLongException {
if (prefix.isAbsolute()) {
return prefix;
}
Name newname = new Name();
newname.append(prefix.name, 0, prefix.labels);
newname.append(suffix.name, 0, suffix.labels);
return newname;
}
/**
* If this name is a subdomain of origin, return a new name relative to origin with the same
* value. Otherwise, return the existing name.
*
* @param origin The origin to remove.
* @return The possibly relativized name.
*/
public Name relativize(Name origin) {
if (origin == null || !subdomain(origin)) {
return this;
}
Name newname = new Name();
int length = length() - origin.length();
newname.labels = labels - origin.labels;
newname.offsets = offsets;
newname.name = new byte[length];
System.arraycopy(name, 0, newname.name, 0, length);
return newname;
}
/**
* Generates a new Name with the first n labels replaced by a wildcard
*
* @return The wildcard name
*/
public Name wild(int n) {
if (n < 1) {
throw new IllegalArgumentException("must replace 1 or more labels");
}
try {
Name newname = new Name();
copy(wild, newname);
newname.append(name, offset(n), labels - n);
return newname;
} catch (NameTooLongException e) {
throw new IllegalStateException("Name.wild: concatenate failed");
}
}
/**
* Returns a canonicalized version of the Name (all lowercase). This may be the same name, if the
* input Name is already canonical.
*/
public Name canonicalize() {
boolean canonical = true;
for (byte b : name) {
if (lowercase[b & 0xFF] != b) {
canonical = false;
break;
}
}
if (canonical) {
return this;
}
Name newname = new Name();
newname.offsets = offsets;
newname.labels = labels;
newname.name = new byte[length()];
for (int i = 0; i < newname.name.length; i++) {
newname.name[i] = lowercase[name[i] & 0xFF];
}
return newname;
}
/**
* Generates a new Name to be used when following a DNAME.
*
* @param dname The DNAME record to follow.
* @return The constructed name or {@code null} if this Name is not a subdomain of the {@code
* dname} name.
* @throws NameTooLongException The resulting name is too long.
*/
public Name fromDNAME(DNAMERecord dname) throws NameTooLongException {
Name dnameowner = dname.getName();
Name dnametarget = dname.getTarget();
if (!subdomain(dnameowner)) {
return null;
}
int plabels = labels - dnameowner.labels;
int plength = length() - dnameowner.length();
int dlabels = dnametarget.labels;
int dlength = dnametarget.length();
if (plength + dlength > MAXNAME) {
throw new NameTooLongException();
}
Name newname = new Name();
newname.labels = plabels + dlabels;
newname.name = Arrays.copyOf(name, plength + dlength);
System.arraycopy(dnametarget.name, 0, newname.name, plength, dlength);
for (int i = 0, pos = 0; i < MAXOFFSETS && i < plabels + dlabels; i++) {
newname.setOffset(i, pos);
pos += newname.name[pos] + 1;
}
return newname;
}
/** Is this name a wildcard? */
public boolean isWild() {
if (labels == 0) {
return false;
}
return name[0] == (byte) 1 && name[1] == (byte) '*';
}
/** Is this name absolute? */
public boolean isAbsolute() {
if (labels == 0) {
return false;
}
return name[offset(labels - 1)] == 0;
}
/** The length of the name (in bytes). */
public short length() {
if (labels == 0) {
return 0;
}
return (short) (name.length);
}
/** The number of labels in the name. */
public int labels() {
return labels;
}
/** Returns {@code true} if this {@link Name} a subdomain of {@code domain}. */
public boolean subdomain(Name domain) {
int dlabels = domain.labels;
if (dlabels > labels) {
return false;
}
if (dlabels == labels) {
return equals(domain);
}
return domain.equals(name, offset(labels - dlabels));
}
private String byteString(byte[] array, int pos) {
StringBuilder sb = new StringBuilder();
int len = array[pos++];
for (int i = pos; i < pos + len; i++) {
int b = array[i] & 0xFF;
if (b <= 0x20 || b >= 0x7f) {
sb.append('\\');
if (b < 10) {
sb.append("00");
} else if (b < 100) {
sb.append('0');
}
sb.append(b);
} else if (b == '"' || b == '(' || b == ')' || b == '.' || b == ';' || b == '\\' || b == '@'
|| b == '$') {
sb.append('\\');
sb.append((char) b);
} else {
sb.append((char) b);
}
}
return sb.toString();
}
/**
* Convert a Name to a String
*
* @param omitFinalDot If true, and the name is absolute, omit the final dot.
* @return The representation of this name as a (printable) String.
*/
public String toString(boolean omitFinalDot) {
if (labels == 0) {
return "@";
} else if (labels == 1 && name[0] == 0) {
return ".";
}
StringBuilder sb = new StringBuilder();
for (int label = 0, pos = 0; label < labels; label++) {
int len = name[pos];
if (len == 0) {
if (!omitFinalDot) {
sb.append('.');
}
break;
}
if (label > 0) {
sb.append('.');
}
sb.append(byteString(name, pos));
pos += 1 + len;
}
return sb.toString();
}
/**
* Convert a Name to a String
*
* @return The representation of this name as a (printable) String.
*/
@Override
public String toString() {
return toString(false);
}
/**
* Retrieve the nth label of a Name. This makes a copy of the label; changing this does not change
* the Name. The returned byte array includes the label length as the first byte.
*
* @param n The label to be retrieved. The first label is 0.
*/
public byte[] getLabel(int n) {
int pos = offset(n);
byte len = (byte) (name[pos] + 1);
return Arrays.copyOfRange(name, pos, pos + len);
}
/**
* Convert the nth label in a Name to a String
*
* @param n The label to be converted to a (printable) String. The first label is 0.
*/
public String getLabelString(int n) {
int pos = offset(n);
return byteString(name, pos);
}
/**
* Emit a Name in DNS wire format
*
* @param out The output stream containing the DNS message.
* @param c The compression context, or null of no compression is desired.
* @throws IllegalArgumentException The name is not absolute.
*/
public void toWire(DNSOutput out, Compression c) {
if (!isAbsolute()) {
throw new IllegalArgumentException("toWire() called on non-absolute name");
}
for (int i = 0; i < labels - 1; i++) {
Name tname;
if (i == 0) {
tname = this;
} else {
tname = new Name(this, i);
}
int pos = -1;
if (c != null) {
pos = c.get(tname);
}
if (pos >= 0) {
pos |= LABEL_MASK << 8;
out.writeU16(pos);
return;
} else {
if (c != null) {
c.add(out.current(), tname);
}
int off = offset(i);
out.writeByteArray(name, off, name[off] + 1);
}
}
out.writeU8(0);
}
/**
* Emit a Name in DNS wire format
*
* @throws IllegalArgumentException The name is not absolute.
*/
public byte[] toWire() {
DNSOutput out = new DNSOutput();
toWire(out, null);
return out.toByteArray();
}
/**
* Emit a Name in canonical DNS wire format (all lowercase)
*
* @param out The output stream to which the message is written.
*/
public void toWireCanonical(DNSOutput out) {
byte[] b = toWireCanonical();
out.writeByteArray(b);
}
/**
* Emit a Name in canonical DNS wire format (all lowercase)
*
* @return The canonical form of the name.
*/
public byte[] toWireCanonical() {
if (labels == 0) {
return new byte[0];
}
byte[] b = new byte[name.length];
for (int i = 0, spos = 0, dpos = 0; i < labels; i++) {
int len = name[spos];
b[dpos++] = name[spos++];
for (int j = 0; j < len; j++) {
b[dpos++] = lowercase[name[spos++] & 0xFF];
}
}
return b;
}
/**
* Emit a Name in DNS wire format
*
* @param out The output stream containing the DNS message.
* @param c The compression context, or null of no compression is desired.
* @param canonical If true, emit the name in canonicalized form (all lowercase).
* @throws IllegalArgumentException The name is not absolute.
*/
public void toWire(DNSOutput out, Compression c, boolean canonical) {
if (canonical) {
toWireCanonical(out);
} else {
toWire(out, c);
}
}
private boolean equals(byte[] b, int bpos) {
for (int i = 0, pos = 0; i < labels; i++) {
if (name[pos] != b[bpos]) {
return false;
}
int len = name[pos++];
bpos++;
for (int j = 0; j < len; j++) {
if (lowercase[name[pos++] & 0xFF] != lowercase[b[bpos++] & 0xFF]) {
return false;
}
}
}
return true;
}
/** Are these two Names equivalent? */
@Override
public boolean equals(Object arg) {
if (arg == this) {
return true;
}
if (!(arg instanceof Name)) {
return false;
}
Name other = (Name) arg;
if (other.labels != labels) {
return false;
}
if (other.hashCode() != hashCode()) {
return false;
}
return equals(other.name, 0);
}
/** Computes a hashcode based on the value */
@Override
public int hashCode() {
if (hashcode != 0) {
return hashcode;
}
int code = 0;
for (int i = offset(0); i < name.length; i++) {
code += (code << 3) + (lowercase[name[i] & 0xFF] & 0xFF);
}
hashcode = code;
return hashcode;
}
/**
* Compares this Name to another Object.
*
* @param arg The name to be compared.
* @return The value 0 if the argument is a name equivalent to this name; a value less than 0 if
* the argument is less than this name in the canonical ordering, and a value greater than 0
* if the argument is greater than this name in the canonical ordering.
* @throws ClassCastException if the argument is not a Name.
*/
@Override
public int compareTo(Name arg) {
if (this == arg) {
return 0;
}
int alabels = arg.labels;
int compares = Math.min(labels, alabels);
for (int i = 1; i <= compares; i++) {
int start = offset(labels - i);
int astart = arg.offset(alabels - i);
int length = name[start];
int alength = arg.name[astart];
for (int j = 0; j < length && j < alength; j++) {
int n =
(lowercase[name[j + start + 1] & 0xFF] & 0xFF)
- (lowercase[arg.name[j + astart + 1] & 0xFF] & 0xFF);
if (n != 0) {
return n;
}
}
if (length != alength) {
return length - alength;
}
}
return labels - alabels;
}
}