Skip to content

Commit

Permalink
messing around in libiberty
Browse files Browse the repository at this point in the history
Change-Id: I889f1bd0ce61e48fd90087ab65705bb4f58d3707
  • Loading branch information
cooljeanius committed Dec 9, 2024
1 parent 1bad634 commit b138af1
Show file tree
Hide file tree
Showing 8 changed files with 755 additions and 301 deletions.
2 changes: 2 additions & 0 deletions src/gdb/macosx/gdb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4976,6 +4976,7 @@
A56E59D61B210132005E1D43 /* stub-loader.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "stub-loader.c"; sourceTree = "<group>"; };
A56E59D81B210132005E1D43 /* testglue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = testglue.c; sourceTree = "<group>"; };
A56E59E51B210132005E1D43 /* unit.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unit.cc; sourceTree = "<group>"; };
A56FAF472D068CA8008EEFF0 /* maint-tool */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; path = "maint-tool"; sourceTree = "<group>"; };
A57C97E42043C71100D09754 /* tm-i386-next.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "tm-i386-next.h"; sourceTree = "<group>"; };
A57C980D2043C8BB00D09754 /* tm-obsd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "tm-obsd.h"; sourceTree = "<group>"; };
A57C980E2043C8BB00D09754 /* tm-ptx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "tm-ptx.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9411,6 +9412,7 @@
2609DE230E82C411008125DE /* insque.c */,
2609DE240E82C411008125DE /* lbasename.c */,
2609DE260E82C411008125DE /* lrealpath.c */,
A56FAF472D068CA8008EEFF0 /* maint-tool */,
2609DE280E82C411008125DE /* make-relative-prefix.c */,
2609DE290E82C411008125DE /* make-temp-file.c */,
A53AC2D51A40F312002F20B2 /* malloca.c */,
Expand Down
779 changes: 609 additions & 170 deletions src/libiberty/Makefile.in

Large diffs are not rendered by default.

134 changes: 71 additions & 63 deletions src/libiberty/_doprnt.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* _doprnt.c: Provide a version of _doprnt in terms of fprintf.
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Kaveh Ghazi <[email protected]> 3/29/98
* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
* Contributed by Kaveh Ghazi <[email protected]> 3/29/98 */
/*
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
Expand Down Expand Up @@ -45,7 +45,7 @@ Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
char buf[32]; \
ptr++; /* Go past the asterisk. */ \
*sptr = '\0'; /* NULL terminate sptr. */ \
sprintf(buf, "%d", value); \
snprintf(buf, sizeof(buf), "%d", value); \
strcat(sptr, buf); \
while (*sptr) sptr++; \
} while (0)
Expand Down Expand Up @@ -74,10 +74,11 @@ Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
} \
} while (0)

/* */
int
_doprnt (const char *format, va_list ap, FILE *stream)
_doprnt(const char *format, va_list ap, FILE *stream)
{
const char * ptr = format;
const char *ptr = format;
char specifier[128];
int total_printed = 0;

Expand All @@ -87,12 +88,12 @@ _doprnt (const char *format, va_list ap, FILE *stream)
PRINT_CHAR(*ptr);
else /* We got a format specifier! */
{
char * sptr = specifier;
char *sptr = specifier;
int wide_width = 0, short_width = 0;

*sptr++ = *ptr++; /* Copy the % and move forward. */

while (strchr ("-+ #0", *ptr)) /* Move past flags. */
while (strchr("-+ #0", *ptr)) /* Move past flags. */
*sptr++ = *ptr++;

if (*ptr == '*')
Expand All @@ -110,7 +111,7 @@ _doprnt (const char *format, va_list ap, FILE *stream)
while (ISDIGIT(*ptr)) /* Handle explicit numeric value. */
*sptr++ = *ptr++;
}
while (strchr ("hlL", *ptr))
while (strchr("hlL", *ptr))
{
switch (*ptr)
{
Expand Down Expand Up @@ -160,7 +161,7 @@ _doprnt (const char *format, va_list ap, FILE *stream)
PRINT_TYPE(long long);
#else
PRINT_TYPE(long); /* Fake it and hope for the best. */
#endif
#endif /* (__GNUC__ || HAVE_LONG_LONG) && !__STRICT_ANSI__ */
break;
} /* End of switch (wide_width) */
} /* End of else statement */
Expand All @@ -180,7 +181,7 @@ _doprnt (const char *format, va_list ap, FILE *stream)
PRINT_TYPE(long double);
#else
PRINT_TYPE(double); /* Fake it and hope for the best. */
#endif
#endif /* __GNUC__ || HAVE_LONG_DOUBLE */
}
}
break;
Expand All @@ -204,92 +205,99 @@ _doprnt (const char *format, va_list ap, FILE *stream)

#ifdef TEST

#include <math.h>
#ifndef M_PI
#define M_PI (3.1415926535897932385)
#endif
# include <math.h>
# ifndef M_PI
# define M_PI (3.1415926535897932385)
# endif /* !M_PI */

#define RESULT(x) do \
{ \
int i = (x); \
printf ("printed %d characters\n", i); \
printf("printed %d characters\n", i); \
fflush(stdin); \
} while (0)

static int checkit (const char * format, ...) ATTRIBUTE_PRINTF_1;
static int checkit(const char * format, ...) ATTRIBUTE_PRINTF_1;

static int
checkit (const char* format, ...)
checkit(const char* format, ...)
{
int result;
VA_OPEN (args, format);
VA_FIXEDARG (args, char *, format);
VA_OPEN(args, format);
VA_FIXEDARG(args, char *, format);

result = _doprnt (format, args, stdout);
VA_CLOSE (args);
result = _doprnt(format, args, stdout);
VA_CLOSE(args);

return result;
}

/* */
int
main (void)
main(void)
{
RESULT(checkit ("<%d>\n", 0x12345678));
RESULT(printf ("<%d>\n", 0x12345678));
RESULT(checkit("<%d>\n", 0x12345678));
RESULT(printf("<%d>\n", 0x12345678));

RESULT(checkit ("<%200d>\n", 5));
RESULT(printf ("<%200d>\n", 5));
RESULT(checkit("<%200d>\n", 5));
RESULT(printf("<%200d>\n", 5));

RESULT(checkit ("<%.300d>\n", 6));
RESULT(printf ("<%.300d>\n", 6));
RESULT(checkit("<%.300d>\n", 6));
RESULT(printf("<%.300d>\n", 6));

RESULT(checkit ("<%100.150d>\n", 7));
RESULT(printf ("<%100.150d>\n", 7));
RESULT(checkit("<%100.150d>\n", 7));
RESULT(printf("<%100.150d>\n", 7));

RESULT(checkit ("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
RESULT(checkit("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
777777777777777777333333333333366666666666622222222222777777777777733333"));
RESULT(printf ("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
RESULT(printf("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
777777777777777777333333333333366666666666622222222222777777777777733333"));

RESULT(checkit ("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));
RESULT(printf ("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));
RESULT(checkit("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));
RESULT(printf("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));

RESULT(checkit ("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));
RESULT(printf ("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));
RESULT(checkit("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));
RESULT(printf("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));

RESULT(checkit ("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));
RESULT(printf ("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));
RESULT(checkit("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));
RESULT(printf("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));

RESULT(checkit ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(checkit("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));

RESULT(checkit ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(checkit("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));

RESULT(checkit ("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123, (long)234, 345, 123456789, 456));
RESULT(printf ("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123, (long)234, 345, 123456789, 456));
RESULT(checkit("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123,
(long)234, 345, 123456789, 456));
RESULT(printf("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123,
(long)234, 345, 123456789, 456));

#if (defined(__GNUC__) || defined(HAVE_LONG_LONG)) && !defined(__STRICT_ANSI__)
RESULT(checkit ("Testing (lld) long long: <%d><%lld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(printf ("Testing (lld) long long: <%d><%lld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(checkit ("Testing (Ld) long long: <%d><%Ld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(printf ("Testing (Ld) long long: <%d><%Ld><%d>\n", 123, 234234234234234234LL, 345));
#endif
RESULT(checkit("Testing (lld) long long: <%d><%lld><%d>\n", 123,
234234234234234234LL, 345));
RESULT(printf("Testing (lld) long long: <%d><%lld><%d>\n", 123,
234234234234234234LL, 345));
RESULT(checkit("Testing (Ld) long long: <%d><%Ld><%d>\n", 123,
234234234234234234LL, 345));
RESULT(printf("Testing (Ld) long long: <%d><%Ld><%d>\n", 123,
234234234234234234LL, 345));
#endif /* (__GNUC__ || HAVE_LONG_LONG) && !__STRICT_ANSI__ */

#if defined(__GNUC__) || defined (HAVE_LONG_DOUBLE)
RESULT(checkit ("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
RESULT(printf ("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
#endif
RESULT(checkit("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
RESULT(printf("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
#endif /* __GNUC__ || HAVE_LONG_DOUBLE */

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions src/libiberty/argv.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* argv.c: Create and destroy argument vectors (argv's)
Copyright (C) 1992, 2001 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support
* Copyright (C) 1992, 2001 Free Software Foundation, Inc.
* Written by Fred Fish at Cygnus Support */
/*
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -542,6 +542,7 @@ static const char *const tests[] =
NULL
};

/* */
int
main(void)
{
Expand Down
Loading

0 comments on commit b138af1

Please sign in to comment.