1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#!/usr/local/bin/icmake -qi
/*
Example of the Icmake 'stat()' function. This simple makefile prints
something of a directory listing.
For installation: see the sample file 'tolower'.
*/
int stringlength (string s)
{
int
len;
len = 0;
while (element (len, s))
len++;
return (len);
}
void showatt (string file, list statbuf)
{
int
i,
att;
string
size;
printf (" ");
att = (int) element (0, statbuf);
if (att & S_IFDIR)
printf ("d");
else
printf ("-");
if (att & S_IFCHR)
printf ("c");
else
printf ("-");
if (att & S_IFREG)
printf ("f");
else
printf ("-");
if (att & S_IREAD)
printf ("r");
else
printf ("-");
if (att & S_IWRITE)
printf ("w");
else
printf ("-");
if (att & S_IEXEC)
printf ("x");
else
printf ("-");
size = element (1, statbuf);
printf (" " , size, " ");
for (i = stringlength (size); i < 10; i++)
printf (" ");
printf (file, "\n");
}
void show (string filemask)
{
list
statbuf,
files;
string
file;
int
i;
printf ("\n", filemask, ": ");
if (! (files = makelist (O_ALL, filemask)) )
{
printf ("not found\n");
return;
}
printf ("\n");
for (i = 0; i < sizeof (files); i++)
{
file = element (i, files);
if (! (statbuf = stat (P_NOCHECK, file)))
printf (" can't stat ", file, "\n");
else
showatt (file, statbuf);
}
}
void main (int argc, list argv)
{
int
i;
if (argc == 1)
show ("*");
else
for (i = 1; i < sizeof (argv); i++)
show (element (i, argv));
exit (0);
}
|