2 * print -- loadable ksh-93 style print builtin
19 #include "bashgetopt.h"
26 static int printargs ();
30 extern char *this_command_name
;
32 static char *print_doc
[] = {
33 "Output the arguments. The -f option means to use the argument as a",
34 "format string as would be supplied to printf(1). The rest of the",
35 "options are as in ksh.",
39 struct builtin print_struct
= {
44 "print [-Rnprs] [-u unit] [-f format] [arguments]",
49 #define ISOPTION(s, c) (s[0] == '-' && s[2] == '\0' && s[1] == c)
56 int c
, r
, nflag
, raw
, ofd
, sflag
;
58 char **v
, *pfmt
, *arg
;
61 nflag
= raw
= sflag
= 0;
65 reset_internal_getopt ();
66 while ((c
= internal_getopt (list
, "Rnprsu:f:")) != -1)
73 if (loptend
&& ISOPTION (loptend
->word
->word
, 'n'))
75 loptend
= loptend
->next
;
91 if (all_digits (list_optarg
) && legal_number (list_optarg
, &lfd
) && lfd
== (int)lfd
)
95 for (l
= list
; l
->next
&& l
->next
!= lcurrent
; l
= l
->next
);
96 lcurrent
= loptend
= l
;
112 ofp
= (ofd
== 1) ? stdout
: fdopen (dup (ofd
), "w");
119 w
= make_word (pfmt
);
120 nlist
= make_word_list (w
, list
);
121 r
= printf_builtin (nlist
);
122 nlist
->next
= (WORD_LIST
*)NULL
;
123 dispose_words (nlist
);
129 for (l
= list
; l
; l
= l
->next
)
131 fprintf (ofp
, "%s", l
->word
->word
);
141 r
= printargs (list
, ofp
);
150 printargs (list
, ofp
)
158 for (sawc
= 0, l
= list
; l
; l
= l
->next
)
160 ostr
= ansicstr (l
->word
->word
, strlen (l
->word
->word
), 0, &sawc
, (int *)0);
161 fprintf (ofp
, "%s", ostr
);