| [1530] | 1 | /* $Id: strspn-1.c 1530 2004-09-28 02:56:29Z bird $ */
 | 
|---|
 | 2 | /** @file
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  * strspn() test for /bin/stat problem.
 | 
|---|
 | 5 |  *
 | 
|---|
 | 6 |  * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  * This file is part of InnoTek LIBC.
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  * InnoTek LIBC is free software; you can redistribute it and/or modify
 | 
|---|
 | 12 |  * it under the terms of the GNU Lesser General Public License as published
 | 
|---|
 | 13 |  * by the Free Software Foundation; either version 2 of the License, or
 | 
|---|
 | 14 |  * (at your option) any later version.
 | 
|---|
 | 15 |  *
 | 
|---|
 | 16 |  * InnoTek LIBC is distributed in the hope that it will be useful,
 | 
|---|
 | 17 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 18 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 19 |  * GNU Lesser General Public License for more details.
 | 
|---|
 | 20 |  *
 | 
|---|
 | 21 |  * You should have received a copy of the GNU Lesser General Public License
 | 
|---|
 | 22 |  * along with InnoTek LIBC; if not, write to the Free Software
 | 
|---|
 | 23 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  */
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | #include <stdio.h>
 | 
|---|
 | 28 | #include <string.h>
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | int main(int argc, char **argv)
 | 
|---|
 | 33 | {
 | 
|---|
 | 34 |     char dest[256];
 | 
|---|
 | 35 |     char *b = strdup(
 | 
|---|
 | 36 |       "  File: %N\n"
 | 
|---|
 | 37 |       "  Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
 | 
|---|
 | 38 |       "Device: %Dh/%dd\tInode: %-10i  Links: %h\n"
 | 
|---|
 | 39 |       "Access: (%04a/%10.10A)  Uid: (%5u/%8U)   Gid: (%5g/%8G)\n"
 | 
|---|
 | 40 |       "Access: %x\n" "Modify: %y\n" "Change: %z");
 | 
|---|
 | 41 |     while (b)
 | 
|---|
 | 42 |       {
 | 
|---|
 | 43 |         char *p = strchr (b, '%');
 | 
|---|
 | 44 |         if (p != NULL)
 | 
|---|
 | 45 |           {
 | 
|---|
 | 46 |             size_t len;
 | 
|---|
 | 47 |             *p++ = '\0';
 | 
|---|
 | 48 |             fputs (b, stdout);
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 |             len = strspn (p, "#-+.I 0123456789");
 | 
|---|
 | 51 |             dest[0] = '%';
 | 
|---|
 | 52 |             memcpy (dest + 1, p, len);
 | 
|---|
 | 53 |             dest[1 + len] = 0;
 | 
|---|
 | 54 |             p += len;
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |             b = p + 1;
 | 
|---|
 | 57 |             switch (*p)
 | 
|---|
 | 58 |               {
 | 
|---|
 | 59 |               case '\0':
 | 
|---|
 | 60 |                 b = NULL;
 | 
|---|
 | 61 |                 /* fall through */
 | 
|---|
 | 62 |               case '%':
 | 
|---|
 | 63 |                 putchar ('%');
 | 
|---|
 | 64 |                 break;
 | 
|---|
 | 65 |               default:
 | 
|---|
 | 66 |                 //print_func (dest, *p, filename, data);
 | 
|---|
 | 67 |                 break;
 | 
|---|
 | 68 |               }
 | 
|---|
 | 69 |           }
 | 
|---|
 | 70 |         else
 | 
|---|
 | 71 |           {
 | 
|---|
 | 72 |             fputs (b, stdout);
 | 
|---|
 | 73 |             b = NULL;
 | 
|---|
 | 74 |           }
 | 
|---|
 | 75 |       }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |     return 0;
 | 
|---|
 | 78 | }
 | 
|---|