Imported from ../bash-3.0.tar.gz.
[platform/upstream/bash.git] / examples / loadables / print.c
index 7144924..ad658a7 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * print -- loadable ksh-93 style print builtin
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include "bashtypes.h"
 
 #include <errno.h>
@@ -19,8 +27,6 @@ static int printargs ();
 
 static FILE *ofp;
 
-extern char *ansicstr ();
-
 extern char *this_command_name;
 
 static char *print_doc[] = {
@@ -48,6 +54,7 @@ print_builtin (list)
      WORD_LIST *list;
 {
   int c, r, nflag, raw, ofd, sflag;
+  intmax_t lfd;
   char **v, *pfmt, *arg;
   WORD_LIST *l;
 
@@ -81,8 +88,8 @@ print_builtin (list)
        case 'p':
          break;        /* NOP */
        case 'u':
-         if (all_digits (list_optarg))
-           ofd = atoi (list_optarg);
+         if (all_digits (list_optarg) && legal_number (list_optarg, &lfd) && lfd == (int)lfd)
+           ofd = lfd;
          else
            {
              for (l = list; l->next && l->next != lcurrent; l = l->next);
@@ -150,7 +157,7 @@ printargs (list, ofp)
 
   for (sawc = 0, l = list; l; l = l->next)
     {
-      ostr = ansicstr (l->word->word, strlen (l->word->word), &sawc, (int *)0);
+      ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, (int *)0);
       fprintf (ofp, "%s", ostr);
       free (ostr);
       if (sawc)
@@ -160,4 +167,3 @@ printargs (list, ofp)
     }
   return (1);
 }
-