2 * print -- loadable ksh-93 style print builtin
6 Copyright (C) 1999-2009 Free Software Foundation, Inc.
8 This file is part of GNU Bash.
9 Bash is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Bash is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.
27 #include "bashtypes.h"
37 #include "bashgetopt.h"
46 static int printargs ();
50 extern char *this_command_name
;
52 static char *print_doc
[] = {
55 "Output the arguments. The -f option means to use the argument as a",
56 "format string as would be supplied to printf(1). The rest of the",
57 "options are as in ksh.",
61 struct builtin print_struct
= {
66 "print [-Rnprs] [-u unit] [-f format] [arguments]",
71 #define ISOPTION(s, c) (s[0] == '-' && s[2] == '\0' && s[1] == c)
78 int c
, r
, nflag
, raw
, ofd
, sflag
;
80 char **v
, *pfmt
, *arg
;
83 nflag
= raw
= sflag
= 0;
87 reset_internal_getopt ();
88 while ((c
= internal_getopt (list
, "Rnprsu:f:")) != -1)
95 if (loptend
&& ISOPTION (loptend
->word
->word
, 'n'))
97 loptend
= loptend
->next
;
113 if (all_digits (list_optarg
) && legal_number (list_optarg
, &lfd
) && lfd
== (int)lfd
)
117 for (l
= list
; l
->next
&& l
->next
!= lcurrent
; l
= l
->next
);
118 lcurrent
= loptend
= l
;
134 ofp
= (ofd
== 1) ? stdout
: fdopen (dup (ofd
), "w");
141 w
= make_word (pfmt
);
142 nlist
= make_word_list (w
, list
);
143 r
= printf_builtin (nlist
);
144 nlist
->next
= (WORD_LIST
*)NULL
;
145 dispose_words (nlist
);
151 for (l
= list
; l
; l
= l
->next
)
153 fprintf (ofp
, "%s", l
->word
->word
);
163 r
= printargs (list
, ofp
);
172 printargs (list
, ofp
)
180 for (sawc
= 0, l
= list
; l
; l
= l
->next
)
182 ostr
= ansicstr (l
->word
->word
, strlen (l
->word
->word
), 0, &sawc
, (int *)0);
183 fprintf (ofp
, "%s", ostr
);