Skip to content

Commit caa7bf7

Browse files
committed
1.5.14: replace endianness-check.sh to endianness.c
1 parent f518857 commit caa7bf7

File tree

8 files changed

+85
-62
lines changed

8 files changed

+85
-62
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
opuscomment
22
tests/
3-
endianness.c
43
*.o
54
nls/*/opuscomment.cat

src/Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ CFLAGS=-D_POSIX_C_SOURCE=200809L -DNLS
1111
LDFLAGS=-logg -lm -lpthread
1212
SRCS=put-tags.c parse-tags.c read.c read-flac.c ocutil.c retrieve-tags.c select-codec.c
1313
SRCP=opuspic2tag.c picture.c
14-
CONFSRCS=endianness.c error.c main.c
14+
CONFSRCS=endianness.c error.c opuscomment.c
1515
HEADERS=global.h ocutil.h limit.h error.h iconv-impl.h
16-
ERRORDEFS=errordef/opus.tab errordef/main.tab
16+
ERRORDEFS=errordef/opus.tab errordef/opuscomment.tab
1717
OBJS=$(SRCS:.c=.o) $(CONFSRCS:.c=.o)
1818
OBJP=$(SRCP:.c=.o)
1919
RM = rm -f
@@ -35,14 +35,11 @@ opuspic2tag: $(OBJP)
3535
$(SRCS): $(HEADERS)
3636
@touch $@
3737

38-
endianness.c: endianness-check.sh
39-
./$< > $@
40-
4138
error.c: $(ERRORDEFS) $(HEADERS)
4239
@touch $@
4340

44-
main.c: $(HEADERS) version.h
41+
opuscomment.c: $(HEADERS) version.h
4542
@touch $@
4643

4744
clean:
48-
$(RM) endianness.c opuscomment opuspic2tag $(OBJS) $(OBJP) 2>/dev/null || :
45+
$(RM) opuscomment opuspic2tag $(OBJS) $(OBJP) 2>/dev/null || :

src/endianness-check.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/endianness.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <stdint.h>
2+
int endian_test()
3+
{
4+
uint32_t sample = {0x01020304};
5+
uint8_t *test = (uint8_t *)&sample;
6+
if (test[0] == 4)
7+
return -1;
8+
else if (test[0] == 1)
9+
return 1;
10+
else
11+
return 0;
12+
}
13+
14+
uint16_t oi16(uint16_t i)
15+
{
16+
int et = endian_test();
17+
if (et == -1)
18+
return i;
19+
else if (et == 1)
20+
return (i << 8 | i >> 8);
21+
else
22+
{
23+
uint8_t *val = (uint8_t *)&i;
24+
uint8_t out[2];
25+
out[0] = val[0];
26+
out[1] = val[1];
27+
return *(uint16_t*)out;
28+
}
29+
}
30+
uint32_t oi32(uint32_t i)
31+
{
32+
int et = endian_test();
33+
if (et == -1)
34+
return i;
35+
else if (et == 1)
36+
return (i << 24
37+
| (i & (255ULL << 8)) << 8
38+
| (i & (255ULL << 16)) >> 8
39+
| i >> 24);
40+
else
41+
{
42+
uint8_t *val = (uint8_t *)&i;
43+
uint8_t out[4];
44+
out[0] = val[0];
45+
out[1] = val[1];
46+
out[2] = val[2];
47+
out[3] = val[3];
48+
return *(uint32_t*)out;
49+
}
50+
}
51+
uint64_t oi64(uint64_t i)
52+
{
53+
int et = endian_test();
54+
if (et == -1)
55+
return i;
56+
else if (et == 1)
57+
return (i << 56
58+
| (i & (255ULL << 8)) << 40
59+
| (i & (255ULL << 16)) >> 24
60+
| (i & (255ULL << 24)) >> 8
61+
| (i & (255ULL << 32)) >> 8
62+
| (i & (255ULL << 40)) >> 24
63+
| (i & (255ULL << 48)) >> 40
64+
| i >> 56);
65+
else
66+
{
67+
uint8_t *val = (uint8_t *)&i;
68+
uint8_t out[8];
69+
out[0] = val[0];
70+
out[1] = val[1];
71+
out[2] = val[2];
72+
out[3] = val[3];
73+
out[4] = val[4];
74+
out[5] = val[5];
75+
out[6] = val[6];
76+
out[7] = val[7];
77+
return *(uint64_t*)out;
78+
}
79+
}

src/error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ noreturn void mainerror(int e, ...) {
1414
errorprefix();
1515
char const *msg[] = {
1616
#define LIST(I, E, S) S,
17-
#include "errordef/main.tab"
17+
#include "errordef/opuscomment.tab"
1818
#undef LIST
1919
};
2020
vfprintf(stderr, catgets(catd, 2, e, msg[e]), ap);

src/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum err_opus_ {
1616

1717
enum err_main_ {
1818
#define LIST(I, E, S) err_main_##E = I,
19-
#include "errordef/main.tab"
19+
#include "errordef/opuscomment.tab"
2020
#undef LIST
2121
};
2222

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)