2 * print -- loadable ksh-93 style print builtin
15 #include "bashgetopt.h"
22 static int printargs ();
26 extern char *this_command_name;
28 static char *print_doc[] = {
29 "Output the arguments. The -f option means to use the argument as a",
30 "format string as would be supplied to printf(1). The rest of the",
31 "options are as in ksh.",
35 struct builtin print_struct = {
40 "print [-Rnprs] [-u unit] [-f format] [arguments]",
45 #define ISOPTION(s, c) (s[0] == '-' && s[2] == '\0' && s[1] == c)
52 int c, r, nflag, raw, ofd, sflag;
53 char **v, *pfmt, *arg;
56 nflag = raw = sflag = 0;
60 reset_internal_getopt ();
61 while ((c = internal_getopt (list, "Rnprsu:f:")) != -1)
68 if (loptend && ISOPTION (loptend->word->word, 'n'))
70 loptend = loptend->next;
86 if (all_digits (list_optarg))
87 ofd = atoi (list_optarg);
90 for (l = list; l->next && l->next != lcurrent; l = l->next);
91 lcurrent = loptend = l;
107 ofp = (ofd == 1) ? stdout : fdopen (dup (ofd), "w");
114 w = make_word (pfmt);
115 nlist = make_word_list (w, list);
116 r = printf_builtin (nlist);
117 nlist->next = (WORD_LIST *)NULL;
118 dispose_words (nlist);
124 for (l = list; l; l = l->next)
126 fprintf (ofp, "%s", l->word->word);
136 r = printargs (list, ofp);
145 printargs (list, ofp)
153 for (sawc = 0, l = list; l; l = l->next)
155 ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, (int *)0);
156 fprintf (ofp, "%s", ostr);