SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
[abcde]
[1.03]
[%]
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
[abcde]
[1.03]
[%]




[
abcde
]n[
1.03
]n[
%
]n




[       ...   L151   fwrite(start,   1,   fmt   - start, stdout);
abcde   ...   L289   PF(start, p);   =>   L87   (void)fputs(b, stdout);
]n[    ...   L151   fwrite(start,   1,   fmt   - start, stdout);
1.03    ...   L318   PF(start, p);   =>   L87   (void)fputs(b, stdout);
]n[    ...   L151   fwrite(start,   1,   fmt   - start, stdout);
%%      ...   L154   putchar('%');
]n     ...   L151   fwrite(start,   1, fmt - start, stdout);
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');
155                    fmt += 2;
156               } else {
157                    fmt = doformat(fmt, &rval);
158                    if (fmt == NULL)
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');
155                    fmt += 2;
156               } else {
157                    fmt = doformat(fmt, &rval);
158                    if (fmt == NULL)
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153
154
                       /* %% prints a % */
                       putchar('%');
                                                                            [%s]n[%2.2f]n[%%]n
155                    fmt += 2;
156               } else {
157
158
                       fmt = doformat(fmt, &rval);
                       if (fmt == NULL)
                                                                            21
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;
163           } else                                                         [%s]n
164               fmt++;
165       }                                                                  [%2.2f]n
166
167       if (end == 1) {                                                    [%%]n
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);                                                18
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;                                                      static char **gargv;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');

                                                                                 “abcde”
155                    fmt += 2;
156               } else {
157                    fmt = doformat(fmt, &rval);
158                    if (fmt == NULL)
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');
155                    fmt += 2;
156               } else {
157                    fmt = doformat(fmt, &rval);
158                    if (fmt == NULL)
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');
155                    fmt += 2;
156               } else {
157                    fmt = doformat(fmt, &rval);
158                    if (fmt == NULL)
159
160
                           return (1);
                       end = 0;
                                                                                start:char *
161
162
                  }
                  start = fmt;
                                                                            [%s]n[%2.2f]n[%%]n
163           } else
164               fmt++;
165       }                                                                      fmt:char *
166
167       if (end == 1) {                                                   [%s]n[%2.2f]n[%%]n
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {
148       start = fmt;
149       while (fmt < format + len) {                                            start:char *
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);                      [%s]n[%2.2f]n[%%]n
152               if (fmt[1] == '%') {
153                    /* %% prints a % */
154                    putchar('%');
155                    fmt += 2;
156
157
                  } else {
                       fmt = doformat(fmt, &rval);
                                                                                   fmt:char *
158                    if (fmt == NULL)                                       [%s]n[%2.2f]n[%%]n
159                        return (1);
160                    end = 0;
161               }
162               start = fmt;                                                  fmt - start == 1
163           } else
164               fmt++;
165       }
166                                                                         fwrite(
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);                “[%s]n[%2.2f]n[%%]n”,
169
170       }
              return (1);
                                                                             1, 1, stdout
171
172
          fwrite(start, 1, fmt - start, stdout);
          if (chopped || !*gargv)
                                                                            );
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;                                                      => “[“
176       end = 1;
177   }
178   /* NOTREACHED */
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {                                                                  fmt:char *
148       start = fmt;
149       while (fmt < format + len) {                                       [%s]n[%2.2f]n[%%]n
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */                                  L157
154                    putchar('%');
155                    fmt += 2;                                              fmt = doformat(
156               } else {
157                    fmt = doformat(fmt, &rval);                                fmt, &rval
158                    if (fmt == NULL)
159                        return (1);                                        );
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";
186     static const char skip2[] = "0123456789";                 %hogehoge
191     fmt = start + 1;
192     /* skip to field width */
193     fmt += strspn(fmt, skip1);
194     if (*fmt == '*') {
195         if (getint(&fieldwidth))
196              return (NULL);
197         havewidth = 1;
198         ++fmt;
199     } else {
200         havewidth = 0;
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {
209             if (getint(&precision))
210                  return (NULL);
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216             /* skip to conversion char */
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";
186     static const char skip2[] = "0123456789";

191     fmt = start + 1;
192     /* skip to field width */                                     start:char *
193     fmt += strspn(fmt, skip1);
194     if (*fmt == '*') {                                        [%s]n[%2.2f]n[%%]n
195         if (getint(&fieldwidth))
196              return (NULL);
197         havewidth = 1;
198         ++fmt;                                                     fmt:char *
199
200
        } else {
            havewidth = 0;
                                                                  [%s]n[%2.2f]n[%%]n
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {
209             if (getint(&precision))
210                  return (NULL);
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216             /* skip to conversion char */
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
                                                 convch:char == ‘s’
247     convch = *fmt;
248     nextch = *++fmt;                         nextch:char == ‘]’
249     *fmt = '0';

250     switch (convch) {
251     case 'b': {                                  fmt:char *
252         size_t len;
253         char *p;                           [%s0n[%2.2f]n[%%]n
254         int getout;
255

285     case 's': {
                                                    start:char *
286
287
            const char *p;                     [%s0n[%2.2f]n[%%]n
288         p = getstr();
289         PF(start, p);
290         break;
291     }
[




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {

247     convch = *fmt;
248     nextch = *++fmt;
249     *fmt = '0';

250     switch (convch) {
251     case 'b': {
252         size_t len;
253         char *p;
254         int getout;
255

285     case 's': {
286         const char *p;
287
288         p = getstr();
289         PF(start, p);
290         break;
291     }             442    static const char *
                      443    getstr(void)
                      444    {
                      445        if (!*gargv)
                      446            return ("");
                      447        return (*gargv++);
                      448    }
[abcde




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {

247     convch = *fmt;
248     nextch = *++fmt;
249     *fmt = '0';

250
251
        switch (convch) {
        case 'b': {
                                       [%s0n[%2.2f]n[%%]n
252         size_t len;
253         char *p;
254         int getout;
255

285     case 's': {
286         const char *p;
287                                                 “abcde”
288         p = getstr();
289         PF(start, p);
290         break;           75 #define PF(f, func) do { 
291     }                    76     char *b = NULL; 
                             77     if (havewidth) 
                             78         if (haveprec) 
                             79             (void)asprintf(&b, f, fieldwidth, precision, func); 
                             80         else 
                             81             (void)asprintf(&b, f, fieldwidth, func); 
                             82     else if (haveprec) 
                             83         (void)asprintf(&b, f, precision, func); 
                             84     else 
                             85         (void)asprintf(&b, f, func); 
                             86     if (b) { 
                             87
                             88
                                        (void)fputs(b, stdout); 
                                        free(b);                                            [abcde
                             89     } 
                             90 } while (0)
[abcde




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
                                                         nextch:char == ‘]’
285     case 's': {
286         const char *p;
287
288         p = getstr();                                    fmt:char *
289         PF(start, p);
290         break;                                     [%s0n[%2.2f]n[%%]n
291     }
                                                               ! ! !
330     *fmt = nextch;
331     return (fmt);                                  [%s]n[%2.2f]n[%%]n
332 }


157                      fmt = doformat(fmt, &rval);
158                      if (fmt == NULL)
159                          return (1);               [%s]n[%2.2f]n[%%]n
160                      end = 0;
161                }
162                start = fmt;
                                                          !   !            !   !


                                                            fmt:char *
                                                       [%s]n[%2.2f]n[%%]n
                                                           start:char *
                                                       [%s]n[%2.2f]n[%%]n
[abcde]
                                                                [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
149     while (fmt < format + len) {
150         if (fmt[0] == '%') {
151             fwrite(start, 1, fmt - start, stdout);
152             if (fmt[1] == '%') {
153                 /* %% prints a % */                       fmt:char *
154
155
                    putchar('%');
                    fmt += 2;
                                                         [%s]n[%2.2f]n[%%]n
156             } else {
157                 fmt = doformat(fmt, &rval);
158
159
                    if (fmt == NULL)
                         return (1);
                                                             start:char *
160                 end = 0;                             [%s]n[%2.2f]n[%%]n
161             }
162             start = fmt;
163         } else
164             fmt++;                                   fwrite(
165     }
                                                            start, // ]n[%2...
                                                            1,     // 1
                                                            fmt - start, // 3
                                                            stdout
                                                         );

                                                         => “]n[“
[abcde]
                                                                                   [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
143   fmt = format = *argv;
144   chopped = escape(fmt, 1, &len);      /* backslash interpretation */
145   rval = end = 0;
146   gargv = ++argv;
147   for (;;) {                                                                  fmt:char *
148       start = fmt;
149       while (fmt < format + len) {                                       [%s]n[%2.2f]n[%%]n
150           if (fmt[0] == '%') {
151               fwrite(start, 1, fmt - start, stdout);
152               if (fmt[1] == '%') {
153                    /* %% prints a % */                                  L157
154                    putchar('%');
155                    fmt += 2;                                              fmt = doformat(
156               } else {
157                    fmt = doformat(fmt, &rval);                                fmt, &rval
158                    if (fmt == NULL)
159                        return (1);                                        );
160                    end = 0;
161               }
162               start = fmt;
163           } else
164               fmt++;
165       }
166
167       if (end == 1) {
168           warnx1("missing format character", NULL, NULL);
169           return (1);
170       }
171       fwrite(start, 1, fmt - start, stdout);
172       if (chopped || !*gargv)
173           return (rval);
174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }
178   /* NOTREACHED */
[abcde]
                                                                        [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)                                  start:char *
184 {
185     static const char skip1[] = "#'-+ 0";                     [%s]n[%2.2f]n[%%]n
186     static const char skip2[] = "0123456789";

191     fmt = start + 1;
192     /* skip to field width */                                      fmt:char *
193
194
        fmt += strspn(fmt, skip1);
        if (*fmt == '*') {
                                                                  [%s]n[%2.2f]n[%%]n
195         if (getint(&fieldwidth))
196              return (NULL);
197         havewidth = 1;
198         ++fmt;
199     } else {
200         havewidth = 0;
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {
209             if (getint(&precision))
210                  return (NULL);
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216             /* skip to conversion char */
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[abcde]
                                                                        [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";                          fmt:char *
186     static const char skip2[] = "0123456789";
                                                                  [%s]n[%2.2f]n[%%]n
191     fmt = start + 1;
192     /* skip to field width */
193     fmt += strspn(fmt, skip1);
194     if (*fmt == '*') {
195         if (getint(&fieldwidth))                                skip1 [#’-+ 0]
196              return (NULL);
197         havewidth = 1;
198         ++fmt;
199     } else {
200         havewidth = 0;
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {
209             if (getint(&precision))
210                  return (NULL);
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216             /* skip to conversion char */
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[abcde]
                                                                        [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";
186     static const char skip2[] = "0123456789";

191     fmt = start + 1;                                                fmt:char*
192     /* skip to field width */
193     fmt += strspn(fmt, skip1);                                [%s]n[%2.2f]n[%%]n
194     if (*fmt == '*') {
195         if (getint(&fieldwidth))
196              return (NULL);
197         havewidth = 1;
198         ++fmt;
199     } else {
200         havewidth = 0;
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {                                          fmt:char*
209             if (getint(&precision))
210                  return (NULL);                               [%s]n[%2.2f]n[%%]n
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216             /* skip to conversion char */
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[abcde]
                                                                        [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";
186     static const char skip2[] = "0123456789";

191     fmt = start + 1;
192     /* skip to field width */
193     fmt += strspn(fmt, skip1);
194     if (*fmt == '*') {
195         if (getint(&fieldwidth))
196              return (NULL);
197
198
            havewidth = 1;
            ++fmt;
                                                                        fmt:char*
199
200
        } else {
            havewidth = 0;
                                                                  [%s]n[%2.2f]n[%%]n
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);
204     }
205     if (*fmt == '.') {
206         /* precision present? */
207         ++fmt;
208
209
            if (*fmt == '*') {
                if (getint(&precision))
                                                                        fmt:char*
210                  return (NULL);                               [%s]n[%2.2f]n[%%]n
211             haveprec = 1;
212             ++fmt;
213         } else {
214             haveprec = 0;
215
216
217
                /* skip to conversion char */
                fmt += strspn(fmt, skip2);
                                                                       fmt:start*
218         }                                                     [%s]n[%2.2f]n[%%]n
219     } else
220         haveprec = 0;
[abcde]
                                                                        [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
185     static const char skip1[] = "#'-+ 0";
186     static const char skip2[] = "0123456789";

191     fmt = start + 1;
192     /* skip to field width */
193     fmt += strspn(fmt, skip1);
194     if (*fmt == '*') {
195         if (getint(&fieldwidth))
196              return (NULL);
197         havewidth = 1;
198         ++fmt;
199     } else {
200         havewidth = 0;
201
202         /* skip to possible '.', get following precision */
203         fmt += strspn(fmt, skip2);                                  fmt:char*
204     }
205     if (*fmt == '.') {                                        [%s]n[%2.2f]n[%%]n
206         /* precision present? */
207         ++fmt;
208         if (*fmt == '*') {
209             if (getint(&precision))
210                  return (NULL);
211             haveprec = 1;
212             ++fmt;
213
214
            } else {
                haveprec = 0;
                                                                        fmt:char*
215
216             /* skip to conversion char */
                                                                  [%s]n[%2.2f]n[%%]n
217             fmt += strspn(fmt, skip2);
218         }
219     } else
220         haveprec = 0;
[abcde]
                                                      [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
                                                 convch:char == ‘f’
247     convch = *fmt;
248     nextch = *++fmt;                         nextch:char == ‘]’
249     *fmt = '0';

250     switch (convch) {
251     case 'b': {                                  fmt:char *
252         size_t len;
253         char *p;                           [%s]n[%2.2f0n[%%]n
254         int getout;
255

285     case 's': {
                                                    start:char *
286
287
            const char *p;                     [%s0n[%2.2f0n[%%]n
288         p = getstr();
289         PF(start, p);
290         break;
291     }
[abcde]
                                                                                   [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {

247     convch = *fmt;
248     nextch = *++fmt;
249     *fmt = '0';

250     switch (convch) {
251     case 'b': {
252         size_t len;
253         char *p;
254         int getout;
255

309     case    'e': case 'E':
310     case    'f': case 'F':
311     case    'g': case 'G':
312     case    'a': case 'A': {
313            long double p;
314
315            if (getfloating(&p, mod_ldbl))
316                 *rval = 1;
317            if (mod_ldbl)
318                 PF(start, p);
319            else
320                 PF(start, (double)p);
321            break;                     507 static int
322     }                                 508 getfloating(long double *dp, int
                                          mod_ldbl)
                                          509 {
                                          510     char *ep;
                                          511     int rval;
                                          512

                                          526         *dp = strtod(*gargv, &ep);
[abcde]
                                                                                               [1.03




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {

247     convch = *fmt;
248     nextch = *++fmt;
249     *fmt = '0';
                                   [%s]n[%2.2f0n[%%]n
250     switch (convch) {
251     case 'b': {
252         size_t len;
253         char *p;
254         int getout;
255

309
310
        case
        case
                'e': case 'E':
                'f': case 'F':
                                                1.034
311     case    'g': case 'G':
312     case    'a': case 'A': {
313            long double p;                     75 #define PF(f, func) do { 
314                                               76     char *b = NULL; 
315            if (getfloating(&p, mod_ldbl))     77     if (havewidth) 
316                 *rval = 1;                    78         if (haveprec) 
317            if (mod_ldbl)                      79             (void)asprintf(&b, f, fieldwidth, precision, func); 
318                 PF(start, p);                 80         else 
319            else                               81             (void)asprintf(&b, f, fieldwidth, func); 
320                 PF(start, (double)p);         82     else if (haveprec) 
321            break;                             83         (void)asprintf(&b, f, precision, func); 
322     }                                         84     else 
                                                  85         (void)asprintf(&b, f, func); 
                                                  86     if (b) { 
                                                  87         (void)fputs(b, stdout); 
                                                  88         free(b); 
                                                  89     } 
                                                  90 } while (0)
[abcde]
                                                                   [1.03




$ printf "[%s]n[%2.2f]n[%%]n" abcdf 1.034
182 static char *
183 doformat(char *start, int *rval)
184 {
                                                          nextch:char == ‘]’
309     case    'e': case 'E':
310     case    'f': case 'F':
311     case    'g': case 'G':
312     case    'a': case 'A': {                              fmt:char *
313            long double p;
314                                                     [%s]n[%2.2f0n[%%]n
315            if (getfloating(&p, mod_ldbl))
316                 *rval = 1;                                  ! ! !
317            if (mod_ldbl)
318                 PF(start, p);                       [%s]n[%2.2f]n[%%]n
319            else
320                 PF(start, (double)p);
321            break;
322     }
330     *fmt = nextch;
331     return (fmt);                                   [%s]n[%2.2f]n[%%]n
332 }


157
158
                          fmt = doformat(fmt, &rval);
                          if (fmt == NULL)
                                                           !   !             !   !
159                           return (1);
160                       end = 0;
161                   }
162                   start = fmt;                           fmt:char *
                                                        [%s]n[%2.2f]n[%%]n
                                                            start:char *
                                                        [%s]n[%2.2f]n[%%]n
[abcde]
                                                                [1.03]
                                                                [




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
149     while (fmt < format + len) {
150         if (fmt[0] == '%') {
151             fwrite(start, 1, fmt - start, stdout);
152             if (fmt[1] == '%') {
153                 /* %% prints a % */                       fmt:char *
154
155
                    putchar('%');
                    fmt += 2;
                                                         [%s]n[%2.2f]n[%%]n
156             } else {
157                 fmt = doformat(fmt, &rval);
158
159
                    if (fmt == NULL)
                         return (1);
                                                                  fm
160                 end = 0;                             [%s]n[%2.2f]n[%%]n
161             }
162             start = fmt;
163         } else
164             fmt++;                                   fwrite(
165     }
                                                            start, // ]n[%%...
                                                            1,     // 1
                                                            fmt - start, // 3
                                                            stdout
                                                         );

                                                         => “]n[“
[abcde]
                                                               [1.03]
                                                               [%




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
149     while (fmt < format + len) {
150         if (fmt[0] == '%') {
151             fwrite(start, 1, fmt - start, stdout);
152             if (fmt[1] == '%') {
153                 /* %% prints a % */
154                 putchar('%');
155                 fmt += 2;
156             } else {
157                 fmt = doformat(fmt, &rval);               fmt:char *
158                 if (fmt == NULL)
159                      return (1);                     [%s]n[%2.2f]n[%%]n
160                 end = 0;
161             }
162
163
                start = fmt;
            } else
                                                             start:char *
164
165     }
                fmt++;
                                                         [%s]n[%2.2f]n[%%]n
[abcde]
                                                                [1.03]
                                                                [%]




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
149     while (fmt < format + len) {
150         if (fmt[0] == '%') {
151             fwrite(start, 1, fmt - start, stdout);
152             if (fmt[1] == '%') {
153                 /* %% prints a % */
154                 putchar('%');
155                 fmt += 2;
156             } else {
157                 fmt = doformat(fmt, &rval);                fmt:char *
158                 if (fmt == NULL)
159                      return (1);                     [%s]n[%2.2f]n[%%]n?
160                 end = 0;
161             }
162
163
                start = fmt;
            } else
                                                             start:char *
164
165     }
                fmt++;
                                                         [%s]n[%2.2f]n[%%]n
171     fwrite(start, 1, fmt - start, stdout);
172     if (chopped || !*gargv)
173         return (rval);
[abcde]
                                                         [1.03]
                                                         [%]




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034
149     while (fmt < format + len) {
150         if (fmt[0] == '%') {
151             fwrite(start, 1, fmt - start, stdout);
152             if (fmt[1] == '%') {
153                 /* %% prints a % */
154                 putchar('%');
155                 fmt += 2;
156             } else {
157                 fmt = doformat(fmt, &rval);
158                 if (fmt == NULL)
159                      return (1);
160                 end = 0;
161             }
162             start = fmt;
163         } else
164             fmt++;
165     }
                                                               0
171     fwrite(start, 1, fmt - start, stdout);
172     if (chopped || !*gargv)
173         return (rval);
$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034




147   for (;;) {
148       start = fmt;

174       /* Restart at the beginning of the format string. */
175       fmt = format;
176       end = 1;
177   }




$ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 fghij 23.4
[abcde]
1.03
[fghij]
23.40
177     }
178     /* NOTREACHED */
179 }
Printf

Contenu connexe

En vedette

A áfrica dos grandes reinos
A áfrica dos grandes reinosA áfrica dos grandes reinos
A áfrica dos grandes reinos
Íris Ferreira
 
จินตนาการ[1]..
จินตนาการ[1]..จินตนาการ[1]..
จินตนาการ[1]..
tutorok
 
Navegando En El Pasado
Navegando En El PasadoNavegando En El Pasado
Navegando En El Pasado
GIOVANI CASTRO
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browser
jy03845581
 
Prova 7ºanos 1ºbi silvana
Prova 7ºanos 1ºbi   silvanaProva 7ºanos 1ºbi   silvana
Prova 7ºanos 1ºbi silvana
Íris Ferreira
 
مشروع القانون الأساسي للقضاة
مشروع القانون الأساسي للقضاةمشروع القانون الأساسي للقضاة
مشروع القانون الأساسي للقضاة
Amir Jeddi
 
Prova 9ºanos 1 bi silvana 2014
Prova 9ºanos 1 bi   silvana 2014Prova 9ºanos 1 bi   silvana 2014
Prova 9ºanos 1 bi silvana 2014
Íris Ferreira
 

En vedette (20)

мастер класс
мастер классмастер класс
мастер класс
 
EXAMEN DE COMPUTACION
EXAMEN DE COMPUTACIONEXAMEN DE COMPUTACION
EXAMEN DE COMPUTACION
 
A áfrica dos grandes reinos
A áfrica dos grandes reinosA áfrica dos grandes reinos
A áfrica dos grandes reinos
 
Potafos cana
Potafos canaPotafos cana
Potafos cana
 
จินตนาการ[1]..
จินตนาการ[1]..จินตนาการ[1]..
จินตนาการ[1]..
 
Navegando En El Pasado
Navegando En El PasadoNavegando En El Pasado
Navegando En El Pasado
 
ALV HC Keramikos 8-sep-2011
ALV HC Keramikos 8-sep-2011ALV HC Keramikos 8-sep-2011
ALV HC Keramikos 8-sep-2011
 
Offerme2 好康通活動平台介紹
Offerme2 好康通活動平台介紹Offerme2 好康通活動平台介紹
Offerme2 好康通活動平台介紹
 
Decreto%20230 2007%20 Ensenanzas%20 Primaria
Decreto%20230 2007%20 Ensenanzas%20 PrimariaDecreto%20230 2007%20 Ensenanzas%20 Primaria
Decreto%20230 2007%20 Ensenanzas%20 Primaria
 
20110906オープニングダイアログ
20110906オープニングダイアログ20110906オープニングダイアログ
20110906オープニングダイアログ
 
Didática dinâmica: componente para a aprendizagem ativa
Didática dinâmica: componente para a aprendizagem ativaDidática dinâmica: componente para a aprendizagem ativa
Didática dinâmica: componente para a aprendizagem ativa
 
Inside the-browser
Inside the-browserInside the-browser
Inside the-browser
 
Prova 7ºanos 1ºbi silvana
Prova 7ºanos 1ºbi   silvanaProva 7ºanos 1ºbi   silvana
Prova 7ºanos 1ºbi silvana
 
บทที่๘
บทที่๘บทที่๘
บทที่๘
 
Arte
ArteArte
Arte
 
مشروع القانون الأساسي للقضاة
مشروع القانون الأساسي للقضاةمشروع القانون الأساسي للقضاة
مشروع القانون الأساسي للقضاة
 
Matjames srv gild-2
Matjames srv gild-2Matjames srv gild-2
Matjames srv gild-2
 
祝大家 中秋節快樂
祝大家 中秋節快樂祝大家 中秋節快樂
祝大家 中秋節快樂
 
Gestiones de utilidad publica
Gestiones de utilidad publicaGestiones de utilidad publica
Gestiones de utilidad publica
 
Prova 9ºanos 1 bi silvana 2014
Prova 9ºanos 1 bi   silvana 2014Prova 9ºanos 1 bi   silvana 2014
Prova 9ºanos 1 bi silvana 2014
 

Plus de akitsukada

データベース・リファクタリング読書会第四回オープニング
データベース・リファクタリング読書会第四回オープニングデータベース・リファクタリング読書会第四回オープニング
データベース・リファクタリング読書会第四回オープニング
akitsukada
 
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
akitsukada
 

Plus de akitsukada (20)

Solutions Architect, Exciting Career for Engineers
Solutions Architect, Exciting Career for EngineersSolutions Architect, Exciting Career for Engineers
Solutions Architect, Exciting Career for Engineers
 
Morning Session - AWS Serverless Ways
Morning Session - AWS Serverless WaysMorning Session - AWS Serverless Ways
Morning Session - AWS Serverless Ways
 
AWS Introduction for Startups
AWS Introduction for StartupsAWS Introduction for Startups
AWS Introduction for Startups
 
Real-time Chat Backend on AWS IoT 20160422
Real-time Chat Backend on AWS IoT 20160422Real-time Chat Backend on AWS IoT 20160422
Real-time Chat Backend on AWS IoT 20160422
 
Amazon Cognito Deep Dive @ JAWS DAYS 2016
Amazon Cognito Deep Dive @ JAWS DAYS 2016Amazon Cognito Deep Dive @ JAWS DAYS 2016
Amazon Cognito Deep Dive @ JAWS DAYS 2016
 
AWS Mobile Maniacs
AWS Mobile ManiacsAWS Mobile Maniacs
AWS Mobile Maniacs
 
My Startup Learnings (短縮版)
My Startup Learnings (短縮版)My Startup Learnings (短縮版)
My Startup Learnings (短縮版)
 
CTO Night & Day Morning Session "スタートアップCTOならおさえておきたいAWS基本構成"
CTO Night & Day Morning Session "スタートアップCTOならおさえておきたいAWS基本構成"CTO Night & Day Morning Session "スタートアップCTOならおさえておきたいAWS基本構成"
CTO Night & Day Morning Session "スタートアップCTOならおさえておきたいAWS基本構成"
 
CTO Night & Day Morning Session "Auto Scaling & Spot Instances Deep Dive"
CTO Night & Day Morning Session "Auto Scaling & Spot Instances Deep Dive"CTO Night & Day Morning Session "Auto Scaling & Spot Instances Deep Dive"
CTO Night & Day Morning Session "Auto Scaling & Spot Instances Deep Dive"
 
AWS for Startups 2016 (2015/12/02版)
AWS for Startups 2016 (2015/12/02版)AWS for Startups 2016 (2015/12/02版)
AWS for Startups 2016 (2015/12/02版)
 
Awsjpcasestudies
AwsjpcasestudiesAwsjpcasestudies
Awsjpcasestudies
 
Mobile Hubで変わる、アプリ開発最前線
Mobile Hubで変わる、アプリ開発最前線Mobile Hubで変わる、アプリ開発最前線
Mobile Hubで変わる、アプリ開発最前線
 
Auto Scaling x Spot Instances によるスケーラビリティと コストカット
Auto Scaling x Spot Instances によるスケーラビリティと コストカットAuto Scaling x Spot Instances によるスケーラビリティと コストカット
Auto Scaling x Spot Instances によるスケーラビリティと コストカット
 
20140807 AWS Startup Tech Meetup
20140807 AWS Startup Tech Meetup20140807 AWS Startup Tech Meetup
20140807 AWS Startup Tech Meetup
 
Little tips ios
Little tips iosLittle tips ios
Little tips ios
 
データベース・リファクタリング読書会第四回オープニング
データベース・リファクタリング読書会第四回オープニングデータベース・リファクタリング読書会第四回オープニング
データベース・リファクタリング読書会第四回オープニング
 
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
みゆっき☆Think#10 チーム開発〜脱ぼっちマインド〜
 
With git
With gitWith git
With git
 
Find(ラスト)
Find(ラスト)Find(ラスト)
Find(ラスト)
 
Find(1)
Find(1)Find(1)
Find(1)
 

Dernier

Dernier (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Printf

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 [abcde] [1.03] [%]
  • 10. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 [abcde] [1.03] [%] [ abcde ]n[ 1.03 ]n[ % ]n [ ... L151 fwrite(start, 1, fmt - start, stdout); abcde ... L289 PF(start, p); => L87 (void)fputs(b, stdout); ]n[ ... L151 fwrite(start, 1, fmt - start, stdout); 1.03 ... L318 PF(start, p); => L87 (void)fputs(b, stdout); ]n[ ... L151 fwrite(start, 1, fmt - start, stdout); %% ... L154 putchar('%'); ]n ... L151 fwrite(start, 1, fmt - start, stdout);
  • 11. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 12. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 13. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 154 /* %% prints a % */ putchar('%'); [%s]n[%2.2f]n[%%]n 155 fmt += 2; 156 } else { 157 158 fmt = doformat(fmt, &rval); if (fmt == NULL) 21 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else [%s]n 164 fmt++; 165 } [%2.2f]n 166 167 if (end == 1) { [%%]n 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 18 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 14. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; static char **gargv; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); “abcde” 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 15. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 16. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 160 return (1); end = 0; start:char * 161 162 } start = fmt; [%s]n[%2.2f]n[%%]n 163 } else 164 fmt++; 165 } fmt:char * 166 167 if (end == 1) { [%s]n[%2.2f]n[%%]n 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 17. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { 148 start = fmt; 149 while (fmt < format + len) { start:char * 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); [%s]n[%2.2f]n[%%]n 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 157 } else { fmt = doformat(fmt, &rval); fmt:char * 158 if (fmt == NULL) [%s]n[%2.2f]n[%%]n 159 return (1); 160 end = 0; 161 } 162 start = fmt; fmt - start == 1 163 } else 164 fmt++; 165 } 166 fwrite( 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); “[%s]n[%2.2f]n[%%]n”, 169 170 } return (1); 1, 1, stdout 171 172 fwrite(start, 1, fmt - start, stdout); if (chopped || !*gargv) ); 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; => “[“ 176 end = 1; 177 } 178 /* NOTREACHED */
  • 18. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { fmt:char * 148 start = fmt; 149 while (fmt < format + len) { [%s]n[%2.2f]n[%%]n 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ L157 154 putchar('%'); 155 fmt += 2; fmt = doformat( 156 } else { 157 fmt = doformat(fmt, &rval); fmt, &rval 158 if (fmt == NULL) 159 return (1); ); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 19. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; 186 static const char skip2[] = "0123456789"; %hogehoge 191 fmt = start + 1; 192 /* skip to field width */ 193 fmt += strspn(fmt, skip1); 194 if (*fmt == '*') { 195 if (getint(&fieldwidth)) 196 return (NULL); 197 havewidth = 1; 198 ++fmt; 199 } else { 200 havewidth = 0; 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { 209 if (getint(&precision)) 210 return (NULL); 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 /* skip to conversion char */ 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 20. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; 186 static const char skip2[] = "0123456789"; 191 fmt = start + 1; 192 /* skip to field width */ start:char * 193 fmt += strspn(fmt, skip1); 194 if (*fmt == '*') { [%s]n[%2.2f]n[%%]n 195 if (getint(&fieldwidth)) 196 return (NULL); 197 havewidth = 1; 198 ++fmt; fmt:char * 199 200 } else { havewidth = 0; [%s]n[%2.2f]n[%%]n 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { 209 if (getint(&precision)) 210 return (NULL); 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 /* skip to conversion char */ 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 21. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { convch:char == ‘s’ 247 convch = *fmt; 248 nextch = *++fmt; nextch:char == ‘]’ 249 *fmt = '0'; 250 switch (convch) { 251 case 'b': { fmt:char * 252 size_t len; 253 char *p; [%s0n[%2.2f]n[%%]n 254 int getout; 255 285 case 's': { start:char * 286 287 const char *p; [%s0n[%2.2f]n[%%]n 288 p = getstr(); 289 PF(start, p); 290 break; 291 }
  • 22. [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 247 convch = *fmt; 248 nextch = *++fmt; 249 *fmt = '0'; 250 switch (convch) { 251 case 'b': { 252 size_t len; 253 char *p; 254 int getout; 255 285 case 's': { 286 const char *p; 287 288 p = getstr(); 289 PF(start, p); 290 break; 291 } 442 static const char * 443 getstr(void) 444 { 445 if (!*gargv) 446 return (""); 447 return (*gargv++); 448 }
  • 23. [abcde $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 247 convch = *fmt; 248 nextch = *++fmt; 249 *fmt = '0'; 250 251 switch (convch) { case 'b': { [%s0n[%2.2f]n[%%]n 252 size_t len; 253 char *p; 254 int getout; 255 285 case 's': { 286 const char *p; 287 “abcde” 288 p = getstr(); 289 PF(start, p); 290 break; 75 #define PF(f, func) do { 291 } 76 char *b = NULL; 77 if (havewidth) 78 if (haveprec) 79 (void)asprintf(&b, f, fieldwidth, precision, func); 80 else 81 (void)asprintf(&b, f, fieldwidth, func); 82 else if (haveprec) 83 (void)asprintf(&b, f, precision, func); 84 else 85 (void)asprintf(&b, f, func); 86 if (b) { 87 88 (void)fputs(b, stdout); free(b); [abcde 89 } 90 } while (0)
  • 24. [abcde $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { nextch:char == ‘]’ 285 case 's': { 286 const char *p; 287 288 p = getstr(); fmt:char * 289 PF(start, p); 290 break; [%s0n[%2.2f]n[%%]n 291 } ! ! ! 330 *fmt = nextch; 331 return (fmt); [%s]n[%2.2f]n[%%]n 332 } 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); [%s]n[%2.2f]n[%%]n 160 end = 0; 161 } 162 start = fmt; ! ! ! ! fmt:char * [%s]n[%2.2f]n[%%]n start:char * [%s]n[%2.2f]n[%%]n
  • 25. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ fmt:char * 154 155 putchar('%'); fmt += 2; [%s]n[%2.2f]n[%%]n 156 } else { 157 fmt = doformat(fmt, &rval); 158 159 if (fmt == NULL) return (1); start:char * 160 end = 0; [%s]n[%2.2f]n[%%]n 161 } 162 start = fmt; 163 } else 164 fmt++; fwrite( 165 } start, // ]n[%2... 1, // 1 fmt - start, // 3 stdout ); => “]n[“
  • 26. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 143 fmt = format = *argv; 144 chopped = escape(fmt, 1, &len); /* backslash interpretation */ 145 rval = end = 0; 146 gargv = ++argv; 147 for (;;) { fmt:char * 148 start = fmt; 149 while (fmt < format + len) { [%s]n[%2.2f]n[%%]n 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ L157 154 putchar('%'); 155 fmt += 2; fmt = doformat( 156 } else { 157 fmt = doformat(fmt, &rval); fmt, &rval 158 if (fmt == NULL) 159 return (1); ); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 166 167 if (end == 1) { 168 warnx1("missing format character", NULL, NULL); 169 return (1); 170 } 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval); 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } 178 /* NOTREACHED */
  • 27. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) start:char * 184 { 185 static const char skip1[] = "#'-+ 0"; [%s]n[%2.2f]n[%%]n 186 static const char skip2[] = "0123456789"; 191 fmt = start + 1; 192 /* skip to field width */ fmt:char * 193 194 fmt += strspn(fmt, skip1); if (*fmt == '*') { [%s]n[%2.2f]n[%%]n 195 if (getint(&fieldwidth)) 196 return (NULL); 197 havewidth = 1; 198 ++fmt; 199 } else { 200 havewidth = 0; 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { 209 if (getint(&precision)) 210 return (NULL); 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 /* skip to conversion char */ 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 28. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; fmt:char * 186 static const char skip2[] = "0123456789"; [%s]n[%2.2f]n[%%]n 191 fmt = start + 1; 192 /* skip to field width */ 193 fmt += strspn(fmt, skip1); 194 if (*fmt == '*') { 195 if (getint(&fieldwidth)) skip1 [#’-+ 0] 196 return (NULL); 197 havewidth = 1; 198 ++fmt; 199 } else { 200 havewidth = 0; 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { 209 if (getint(&precision)) 210 return (NULL); 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 /* skip to conversion char */ 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 29. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; 186 static const char skip2[] = "0123456789"; 191 fmt = start + 1; fmt:char* 192 /* skip to field width */ 193 fmt += strspn(fmt, skip1); [%s]n[%2.2f]n[%%]n 194 if (*fmt == '*') { 195 if (getint(&fieldwidth)) 196 return (NULL); 197 havewidth = 1; 198 ++fmt; 199 } else { 200 havewidth = 0; 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { fmt:char* 209 if (getint(&precision)) 210 return (NULL); [%s]n[%2.2f]n[%%]n 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 /* skip to conversion char */ 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 30. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; 186 static const char skip2[] = "0123456789"; 191 fmt = start + 1; 192 /* skip to field width */ 193 fmt += strspn(fmt, skip1); 194 if (*fmt == '*') { 195 if (getint(&fieldwidth)) 196 return (NULL); 197 198 havewidth = 1; ++fmt; fmt:char* 199 200 } else { havewidth = 0; [%s]n[%2.2f]n[%%]n 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); 204 } 205 if (*fmt == '.') { 206 /* precision present? */ 207 ++fmt; 208 209 if (*fmt == '*') { if (getint(&precision)) fmt:char* 210 return (NULL); [%s]n[%2.2f]n[%%]n 211 haveprec = 1; 212 ++fmt; 213 } else { 214 haveprec = 0; 215 216 217 /* skip to conversion char */ fmt += strspn(fmt, skip2); fmt:start* 218 } [%s]n[%2.2f]n[%%]n 219 } else 220 haveprec = 0;
  • 31. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 185 static const char skip1[] = "#'-+ 0"; 186 static const char skip2[] = "0123456789"; 191 fmt = start + 1; 192 /* skip to field width */ 193 fmt += strspn(fmt, skip1); 194 if (*fmt == '*') { 195 if (getint(&fieldwidth)) 196 return (NULL); 197 havewidth = 1; 198 ++fmt; 199 } else { 200 havewidth = 0; 201 202 /* skip to possible '.', get following precision */ 203 fmt += strspn(fmt, skip2); fmt:char* 204 } 205 if (*fmt == '.') { [%s]n[%2.2f]n[%%]n 206 /* precision present? */ 207 ++fmt; 208 if (*fmt == '*') { 209 if (getint(&precision)) 210 return (NULL); 211 haveprec = 1; 212 ++fmt; 213 214 } else { haveprec = 0; fmt:char* 215 216 /* skip to conversion char */ [%s]n[%2.2f]n[%%]n 217 fmt += strspn(fmt, skip2); 218 } 219 } else 220 haveprec = 0;
  • 32. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { convch:char == ‘f’ 247 convch = *fmt; 248 nextch = *++fmt; nextch:char == ‘]’ 249 *fmt = '0'; 250 switch (convch) { 251 case 'b': { fmt:char * 252 size_t len; 253 char *p; [%s]n[%2.2f0n[%%]n 254 int getout; 255 285 case 's': { start:char * 286 287 const char *p; [%s0n[%2.2f0n[%%]n 288 p = getstr(); 289 PF(start, p); 290 break; 291 }
  • 33. [abcde] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 247 convch = *fmt; 248 nextch = *++fmt; 249 *fmt = '0'; 250 switch (convch) { 251 case 'b': { 252 size_t len; 253 char *p; 254 int getout; 255 309 case 'e': case 'E': 310 case 'f': case 'F': 311 case 'g': case 'G': 312 case 'a': case 'A': { 313 long double p; 314 315 if (getfloating(&p, mod_ldbl)) 316 *rval = 1; 317 if (mod_ldbl) 318 PF(start, p); 319 else 320 PF(start, (double)p); 321 break; 507 static int 322 } 508 getfloating(long double *dp, int mod_ldbl) 509 { 510 char *ep; 511 int rval; 512 526 *dp = strtod(*gargv, &ep);
  • 34. [abcde] [1.03 $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { 247 convch = *fmt; 248 nextch = *++fmt; 249 *fmt = '0'; [%s]n[%2.2f0n[%%]n 250 switch (convch) { 251 case 'b': { 252 size_t len; 253 char *p; 254 int getout; 255 309 310 case case 'e': case 'E': 'f': case 'F': 1.034 311 case 'g': case 'G': 312 case 'a': case 'A': { 313 long double p; 75 #define PF(f, func) do { 314 76 char *b = NULL; 315 if (getfloating(&p, mod_ldbl)) 77 if (havewidth) 316 *rval = 1; 78 if (haveprec) 317 if (mod_ldbl) 79 (void)asprintf(&b, f, fieldwidth, precision, func); 318 PF(start, p); 80 else 319 else 81 (void)asprintf(&b, f, fieldwidth, func); 320 PF(start, (double)p); 82 else if (haveprec) 321 break; 83 (void)asprintf(&b, f, precision, func); 322 } 84 else 85 (void)asprintf(&b, f, func); 86 if (b) { 87 (void)fputs(b, stdout); 88 free(b); 89 } 90 } while (0)
  • 35. [abcde] [1.03 $ printf "[%s]n[%2.2f]n[%%]n" abcdf 1.034 182 static char * 183 doformat(char *start, int *rval) 184 { nextch:char == ‘]’ 309 case 'e': case 'E': 310 case 'f': case 'F': 311 case 'g': case 'G': 312 case 'a': case 'A': { fmt:char * 313 long double p; 314 [%s]n[%2.2f0n[%%]n 315 if (getfloating(&p, mod_ldbl)) 316 *rval = 1; ! ! ! 317 if (mod_ldbl) 318 PF(start, p); [%s]n[%2.2f]n[%%]n 319 else 320 PF(start, (double)p); 321 break; 322 } 330 *fmt = nextch; 331 return (fmt); [%s]n[%2.2f]n[%%]n 332 } 157 158 fmt = doformat(fmt, &rval); if (fmt == NULL) ! ! ! ! 159 return (1); 160 end = 0; 161 } 162 start = fmt; fmt:char * [%s]n[%2.2f]n[%%]n start:char * [%s]n[%2.2f]n[%%]n
  • 36. [abcde] [1.03] [ $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ fmt:char * 154 155 putchar('%'); fmt += 2; [%s]n[%2.2f]n[%%]n 156 } else { 157 fmt = doformat(fmt, &rval); 158 159 if (fmt == NULL) return (1); fm 160 end = 0; [%s]n[%2.2f]n[%%]n 161 } 162 start = fmt; 163 } else 164 fmt++; fwrite( 165 } start, // ]n[%%... 1, // 1 fmt - start, // 3 stdout ); => “]n[“
  • 37. [abcde] [1.03] [% $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); fmt:char * 158 if (fmt == NULL) 159 return (1); [%s]n[%2.2f]n[%%]n 160 end = 0; 161 } 162 163 start = fmt; } else start:char * 164 165 } fmt++; [%s]n[%2.2f]n[%%]n
  • 38. [abcde] [1.03] [%] $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); fmt:char * 158 if (fmt == NULL) 159 return (1); [%s]n[%2.2f]n[%%]n? 160 end = 0; 161 } 162 163 start = fmt; } else start:char * 164 165 } fmt++; [%s]n[%2.2f]n[%%]n 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval);
  • 39. [abcde] [1.03] [%] $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 149 while (fmt < format + len) { 150 if (fmt[0] == '%') { 151 fwrite(start, 1, fmt - start, stdout); 152 if (fmt[1] == '%') { 153 /* %% prints a % */ 154 putchar('%'); 155 fmt += 2; 156 } else { 157 fmt = doformat(fmt, &rval); 158 if (fmt == NULL) 159 return (1); 160 end = 0; 161 } 162 start = fmt; 163 } else 164 fmt++; 165 } 0 171 fwrite(start, 1, fmt - start, stdout); 172 if (chopped || !*gargv) 173 return (rval);
  • 40. $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 147 for (;;) { 148 start = fmt; 174 /* Restart at the beginning of the format string. */ 175 fmt = format; 176 end = 1; 177 } $ printf "[%s]n[%2.2f]n[%%]n" abcde 1.034 fghij 23.4 [abcde] 1.03 [fghij] 23.40
  • 41. 177 } 178 /* NOTREACHED */ 179 }