// 19990508 Busy Boxed! Dave Cinege
-#include "internal.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
-#include <getopt.h>
-#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
-#include <libintl.h>
+#include <assert.h>
+#include "busybox.h"
#ifndef S_IFMT
-# define S_IFMT 0170000
+static const int S_IFMT = 0170000;
#endif
#if !defined(S_ISBLK) && defined(S_IFBLK)
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define IN_CTYPE_DOMAIN(c) 1
-#ifdef isblank
-# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
-#else
-# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
-#endif
-#ifdef isgraph
-# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
-#else
-# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
-#endif
-
-#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
-#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
-#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
-#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
-#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
-#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
-#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
-#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+#define ISDIGIT(c) (((unsigned char) (c)) - '0' <= 9)
#define isodigit(c) ((c) >= '0' && (c) <= '7')
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
static int print_formatted __P((char *format, int argc, char **argv));
static long xstrtol __P((char *s));
static unsigned long xstrtoul __P((char *s));
-static void print_direc
-__P(
-
- (char *start, size_t length, int field_width, int precision,
- char *argument));
+static void print_direc __P( (char *start, size_t length,
+ int field_width, int precision, char *argument));
static void print_esc_char __P((int c));
static void print_esc_string __P((char *str));
-static void verify __P((char *s, char *end));
/* The value to return to the calling program. */
static int exit_status;
-static const char printf_usage[] = "printf FORMAT [ARGUMENT...]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
- "\nFormats and prints ARGUMENT(s) according to FORMAT,\n"
- "Where FORMAT controls the output exactly as in C printf.\n"
-#endif
- ;
-
int printf_main(int argc, char **argv)
{
char *format;
exit_status = 0;
if (argc <= 1 || **(argv + 1) == '-') {
- usage(printf_usage);
+ bb_show_usage();
}
format = argv[1];
fprintf(stderr, "excess args ignored");
*/
- exit(exit_status);
+ return(exit_status);
}
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
free(p);
}
-static unsigned long xstrtoul(char *s)
+static unsigned long xstrtoul(char *arg)
{
- char *end;
- unsigned long val;
+ unsigned long result;
+ char *endptr;
+ //int errno_save = errno;
+
+ assert(arg!=NULL);
errno = 0;
- val = strtoul(s, &end, 0);
- verify(s, end);
- return val;
+ result = strtoul(arg, &endptr, 10);
+ if (errno != 0 || *endptr!='\0' || endptr==arg)
+ fprintf(stderr, "%s", arg);
+ //errno = errno_save;
+ return result;
}
-static long xstrtol(char *s)
+static long xstrtol(char *arg)
{
- char *end;
- long val;
+ long result;
+ char *endptr;
+ //int errno_save = errno;
+
+ assert(arg!=NULL);
errno = 0;
- val = strtol(s, &end, 0);
- verify(s, end);
- return val;
+ result = strtoul(arg, &endptr, 10);
+ if (errno != 0 || *endptr!='\0' || endptr==arg)
+ fprintf(stderr, "%s", arg);
+ //errno = errno_save;
+ return result;
}
-static double xstrtod(char *s)
+static double xstrtod(char *arg)
{
- char *end;
- double val;
+ double result;
+ char *endptr;
+ //int errno_save = errno;
+
+ assert(arg!=NULL);
errno = 0;
- val = strtod(s, &end);
- verify(s, end);
- return val;
+ result = strtod(arg, &endptr);
+ if (errno != 0 || *endptr!='\0' || endptr==arg)
+ fprintf(stderr, "%s", arg);
+ //errno = errno_save;
+ return result;
}
-static void verify(char *s, char *end)
-{
- if (errno) {
- fprintf(stderr, "%s", s);
- exit_status = 1;
- } else if (*end) {
- /*
- if (s == end)
- fprintf(stderr, "%s: expected numeric", s);
- else
- fprintf(stderr, "%s: not completely converted", s);
- */
- exit_status = 1;
- }
-}