mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
2
include/extern/getopt.h
vendored
2
include/extern/getopt.h
vendored
@@ -36,7 +36,7 @@ struct option {
|
|||||||
int val;
|
int val;
|
||||||
};
|
};
|
||||||
|
|
||||||
int getopt_long_only(int, char **, const char *, const struct option *, int *);
|
int musl_getopt_long_only(int, char **, const char *, const struct option *, int *);
|
||||||
|
|
||||||
#define no_argument 0
|
#define no_argument 0
|
||||||
#define required_argument 1
|
#define required_argument 1
|
||||||
|
|||||||
@@ -324,8 +324,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
newopt = CurrentOptions;
|
newopt = CurrentOptions;
|
||||||
|
|
||||||
while ((ch = getopt_long_only(argc, argv, optstring, longopts,
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
|
||||||
NULL)) != -1) {
|
NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(optarg) == 2) {
|
if (strlen(optarg) == 2) {
|
||||||
|
|||||||
20
src/extern/getopt.c
vendored
20
src/extern/getopt.c
vendored
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
int __optpos, __optreset;
|
int __optpos, __optreset;
|
||||||
|
|
||||||
void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
void musl__getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
||||||
{
|
{
|
||||||
FILE *f = stderr;
|
FILE *f = stderr;
|
||||||
(void)(fputs(a, f)>=0
|
(void)(fputs(a, f)>=0
|
||||||
@@ -52,9 +52,9 @@ static void permute(char **argv, int dest, int src)
|
|||||||
av[dest] = tmp;
|
av[dest] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
|
static int musl__getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
|
||||||
|
|
||||||
static int __getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl__getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
int ret, skipped, resumed;
|
int ret, skipped, resumed;
|
||||||
if (!optind || __optreset) {
|
if (!optind || __optreset) {
|
||||||
@@ -73,7 +73,7 @@ static int __getopt_long(int argc, char **argv, const char *optstring, const str
|
|||||||
optind = i;
|
optind = i;
|
||||||
}
|
}
|
||||||
resumed = optind;
|
resumed = optind;
|
||||||
ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
ret = musl__getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
||||||
if (resumed > skipped) {
|
if (resumed > skipped) {
|
||||||
int i, cnt = optind-resumed;
|
int i, cnt = optind-resumed;
|
||||||
for (i=0; i<cnt; i++)
|
for (i=0; i<cnt; i++)
|
||||||
@@ -83,7 +83,7 @@ static int __getopt_long(int argc, char **argv, const char *optstring, const str
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl__getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
optarg = 0;
|
optarg = 0;
|
||||||
if (longopts && argv[optind][0] == '-' &&
|
if (longopts && argv[optind][0] == '-' &&
|
||||||
@@ -128,7 +128,7 @@ static int __getopt_long_core(int argc, char **argv, const char *optstring, cons
|
|||||||
optopt = longopts[i].val;
|
optopt = longopts[i].val;
|
||||||
if (colon || !opterr)
|
if (colon || !opterr)
|
||||||
return '?';
|
return '?';
|
||||||
__getopt_msg(argv[0],
|
musl__getopt_msg(argv[0],
|
||||||
": option does not take an argument: ",
|
": option does not take an argument: ",
|
||||||
longopts[i].name,
|
longopts[i].name,
|
||||||
strlen(longopts[i].name));
|
strlen(longopts[i].name));
|
||||||
@@ -140,7 +140,7 @@ static int __getopt_long_core(int argc, char **argv, const char *optstring, cons
|
|||||||
optopt = longopts[i].val;
|
optopt = longopts[i].val;
|
||||||
if (colon) return ':';
|
if (colon) return ':';
|
||||||
if (!opterr) return '?';
|
if (!opterr) return '?';
|
||||||
__getopt_msg(argv[0],
|
musl__getopt_msg(argv[0],
|
||||||
": option requires an argument: ",
|
": option requires an argument: ",
|
||||||
longopts[i].name,
|
longopts[i].name,
|
||||||
strlen(longopts[i].name));
|
strlen(longopts[i].name));
|
||||||
@@ -158,7 +158,7 @@ static int __getopt_long_core(int argc, char **argv, const char *optstring, cons
|
|||||||
if (argv[optind][1] == '-') {
|
if (argv[optind][1] == '-') {
|
||||||
optopt = 0;
|
optopt = 0;
|
||||||
if (!colon && opterr)
|
if (!colon && opterr)
|
||||||
__getopt_msg(argv[0], cnt ?
|
musl__getopt_msg(argv[0], cnt ?
|
||||||
": option is ambiguous: " :
|
": option is ambiguous: " :
|
||||||
": unrecognized option: ",
|
": unrecognized option: ",
|
||||||
argv[optind]+2,
|
argv[optind]+2,
|
||||||
@@ -170,7 +170,7 @@ static int __getopt_long_core(int argc, char **argv, const char *optstring, cons
|
|||||||
return getopt(argc, argv, optstring);
|
return getopt(argc, argv, optstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
|
int musl_getopt_long_only(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx)
|
||||||
{
|
{
|
||||||
return __getopt_long(argc, argv, optstring, longopts, idx, 1);
|
return musl__getopt_long(argc, argv, optstring, longopts, idx, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ int main(int argc, char *argv[])
|
|||||||
int version = 0; /* mask ROM version number */
|
int version = 0; /* mask ROM version number */
|
||||||
int padvalue = 0; /* to pad the rom with if it changes size */
|
int padvalue = 0; /* to pad the rom with if it changes size */
|
||||||
|
|
||||||
while ((ch = getopt_long_only(argc, argv, optstring, longopts,
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
|
||||||
NULL)) != -1) {
|
NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'C':
|
case 'C':
|
||||||
coloronly = true;
|
coloronly = true;
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
depth = 2;
|
depth = 2;
|
||||||
|
|
||||||
while ((ch = getopt_long_only(argc, argv, optstring, longopts,
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts,
|
||||||
NULL)) != -1) {
|
NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'A':
|
case 'A':
|
||||||
opts.attrmapout = true;
|
opts.attrmapout = true;
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ int main(int argc, char *argv[])
|
|||||||
unsigned long value; /* For storing `strtoul`'s return value */
|
unsigned long value; /* For storing `strtoul`'s return value */
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
while ((optionChar = getopt_long_only(argc, argv, optstring, longopts,
|
while ((optionChar = musl_getopt_long_only(argc, argv, optstring,
|
||||||
NULL)) != -1) {
|
longopts, NULL)) != -1) {
|
||||||
switch (optionChar) {
|
switch (optionChar) {
|
||||||
case 'd':
|
case 'd':
|
||||||
isDmgMode = true;
|
isDmgMode = true;
|
||||||
|
|||||||
@@ -150,9 +150,8 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset,
|
|||||||
|
|
||||||
/* Output padding up to the next SECTION */
|
/* Output padding up to the next SECTION */
|
||||||
while (offset + baseOffset < section->org) {
|
while (offset + baseOffset < section->org) {
|
||||||
putc_unlocked(overlayFile ? getc_unlocked(overlayFile)
|
putc(overlayFile ? getc(overlayFile) : padValue,
|
||||||
: padValue,
|
outputFile);
|
||||||
outputFile);
|
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +161,7 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset,
|
|||||||
if (overlayFile) {
|
if (overlayFile) {
|
||||||
/* Skip bytes even with pipes */
|
/* Skip bytes even with pipes */
|
||||||
for (uint16_t i = 0; i < section->size; i++)
|
for (uint16_t i = 0; i < section->size; i++)
|
||||||
getc_unlocked(overlayFile);
|
getc(overlayFile);
|
||||||
}
|
}
|
||||||
offset += section->size;
|
offset += section->size;
|
||||||
|
|
||||||
@@ -170,9 +169,7 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (offset < size) {
|
while (offset < size) {
|
||||||
putc_unlocked(overlayFile ? getc_unlocked(overlayFile)
|
putc(overlayFile ? getc(overlayFile) : padValue, outputFile);
|
||||||
: padValue,
|
|
||||||
outputFile);
|
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,10 +185,6 @@ static void writeROM(void)
|
|||||||
checkOverlay();
|
checkOverlay();
|
||||||
|
|
||||||
if (outputFile) {
|
if (outputFile) {
|
||||||
flockfile(outputFile);
|
|
||||||
if (overlayFile)
|
|
||||||
flockfile(overlayFile);
|
|
||||||
|
|
||||||
if (sections[SECTTYPE_ROM0].nbBanks > 0)
|
if (sections[SECTTYPE_ROM0].nbBanks > 0)
|
||||||
writeBank(sections[SECTTYPE_ROM0].banks[0].sections,
|
writeBank(sections[SECTTYPE_ROM0].banks[0].sections,
|
||||||
0x0000, 0x4000);
|
0x0000, 0x4000);
|
||||||
@@ -199,10 +192,6 @@ static void writeROM(void)
|
|||||||
for (uint32_t i = 0 ; i < sections[SECTTYPE_ROMX].nbBanks; i++)
|
for (uint32_t i = 0 ; i < sections[SECTTYPE_ROMX].nbBanks; i++)
|
||||||
writeBank(sections[SECTTYPE_ROMX].banks[i].sections,
|
writeBank(sections[SECTTYPE_ROMX].banks[i].sections,
|
||||||
0x4000, 0x4000);
|
0x4000, 0x4000);
|
||||||
|
|
||||||
if (overlayFile)
|
|
||||||
funlockfile(overlayFile);
|
|
||||||
funlockfile(outputFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeFile(outputFile);
|
closeFile(outputFile);
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ static char const * const commands[] = {
|
|||||||
|
|
||||||
static int readChar(FILE *file)
|
static int readChar(FILE *file)
|
||||||
{
|
{
|
||||||
int curchar = getc_unlocked(file);
|
int curchar = getc(file);
|
||||||
|
|
||||||
if (curchar == EOF && ferror(file))
|
if (curchar == EOF && ferror(file))
|
||||||
err(1, "%s(%u): Unexpected error in %s", linkerScriptName,
|
err(1, "%s(%u): Unexpected error in %s", linkerScriptName,
|
||||||
|
|||||||
Reference in New Issue
Block a user