aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file_status-help.pd46
-rw-r--r--file_type-help.pd30
-rw-r--r--file_type.pd46
-rw-r--r--stat-help.pd82
-rw-r--r--stat.c (renamed from file_status.c)168
5 files changed, 279 insertions, 93 deletions
diff --git a/file_status-help.pd b/file_status-help.pd
deleted file mode 100644
index 76321fe..0000000
--- a/file_status-help.pd
+++ /dev/null
@@ -1,46 +0,0 @@
-#N canvas 167 231 605 454 10;
-#X msg 114 53 bang;
-#X text 156 53 run on current folder;
-#X obj 91 147 file_status;
-#X obj 90 226 unpack symbol float float float float float float float
-;
-#X symbolatom 91 414 0 0 0 3 filename - -;
-#X floatatom 145 359 0 0 0 3 hard_links - -;
-#X floatatom 199 340 0 0 0 3 User_ID - -;
-#X floatatom 253 323 0 0 0 3 Group_ID - -;
-#X floatatom 309 309 0 0 0 3 Device_ID - -;
-#X obj 12 188 print data;
-#X obj 163 174 route error;
-#X symbolatom 163 199 0 0 0 0 error - -;
-#X floatatom 360 288 0 0 0 3 File_Size - -;
-#X floatatom 416 267 0 0 0 3 Blocks_Allocated - -;
-#X floatatom 470 247 0 0 0 3 Block_Size - -;
-#X msg 127 79 symbol /tmp/;
-#X msg 138 103 symbol /tmp/test.txt;
-#X obj 79 8 bng 15 250 50 0 empty empty empty 0 -6 0 8 -24198 -1 -1
-;
-#X obj 79 26 openpanel;
-#X text 151 16 try it on any file (it doesn't change anything \, just
-reads data from the file system).;
-#X text 174 144 <-- set filename by cold inlet or object argument;
-#X obj 252 360 gid->group_name;
-#X symbolatom 252 379 0 0 0 3 group_name - -;
-#X connect 0 0 2 0;
-#X connect 2 0 3 0;
-#X connect 2 0 9 0;
-#X connect 2 1 10 0;
-#X connect 3 0 4 0;
-#X connect 3 1 5 0;
-#X connect 3 2 6 0;
-#X connect 3 3 7 0;
-#X connect 3 4 8 0;
-#X connect 3 5 12 0;
-#X connect 3 6 13 0;
-#X connect 3 7 14 0;
-#X connect 7 0 21 0;
-#X connect 10 0 11 0;
-#X connect 15 0 2 0;
-#X connect 16 0 2 0;
-#X connect 17 0 18 0;
-#X connect 18 0 2 0;
-#X connect 21 0 22 0;
diff --git a/file_type-help.pd b/file_type-help.pd
new file mode 100644
index 0000000..57e1f7b
--- /dev/null
+++ b/file_type-help.pd
@@ -0,0 +1,30 @@
+#N canvas 434 28 454 304 10;
+#X obj 180 210 file_type;
+#X obj 181 41 bng 15 250 50 0 empty empty empty 0 -6 0 8 -24198 -1
+-1;
+#X obj 181 59 openpanel;
+#X msg 203 118 symbol /usr/bin/gcc;
+#X obj 239 235 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 258 236 bang if no match;
+#X msg 206 142 symbol /dev/tty;
+#X obj 181 96 symbol;
+#X msg 141 76 bang;
+#X symbolatom 179 262 0 0 0 0 file_type - -;
+#X obj 207 185 folder_list;
+#X msg 207 166 symbol /tmp/ssh-*/agent.*;
+#X msg 83 148 symbol /usr;
+#X msg 25 129 symbol /tmp;
+#X text 16 10 find the file type of a file;
+#X connect 0 0 9 0;
+#X connect 0 1 4 0;
+#X connect 1 0 2 0;
+#X connect 2 0 7 0;
+#X connect 3 0 0 0;
+#X connect 6 0 0 0;
+#X connect 7 0 0 0;
+#X connect 8 0 7 0;
+#X connect 10 0 0 0;
+#X connect 11 0 10 0;
+#X connect 12 0 0 0;
+#X connect 13 0 0 0;
diff --git a/file_type.pd b/file_type.pd
new file mode 100644
index 0000000..80a6d6c
--- /dev/null
+++ b/file_type.pd
@@ -0,0 +1,46 @@
+#N canvas 15 102 585 375 10;
+#X obj 28 8 inlet;
+#X obj 29 34 stat;
+#X obj 29 65 list;
+#X obj 29 85 list split 2;
+#X obj 29 105 list split 1;
+#X msg 10 235 fifo;
+#X obj 197 312 symbol;
+#X obj 197 333 outlet;
+#X msg 47 235 character;
+#X msg 121 235 folder;
+#X msg 175 235 block;
+#X msg 226 235 file;
+#X msg 268 235 symlink;
+#X msg 329 235 socket;
+#X msg 384 235 whiteout;
+#X obj 442 325 outlet;
+#X text 433 342 bang if no match;
+#X obj 69 140 & 61440;
+#X obj 35 178 route 4096 8192 16384 24576 32768 40960 49152 57344;
+#X obj 394 205 print [file_type]_ERROR;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 1 15 0;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X connect 4 1 17 0;
+#X connect 5 0 6 0;
+#X connect 6 0 7 0;
+#X connect 8 0 6 0;
+#X connect 9 0 6 0;
+#X connect 10 0 6 0;
+#X connect 11 0 6 0;
+#X connect 12 0 6 0;
+#X connect 13 0 6 0;
+#X connect 14 0 6 0;
+#X connect 17 0 18 0;
+#X connect 18 0 5 0;
+#X connect 18 1 8 0;
+#X connect 18 2 9 0;
+#X connect 18 3 10 0;
+#X connect 18 4 11 0;
+#X connect 18 5 12 0;
+#X connect 18 6 13 0;
+#X connect 18 7 14 0;
+#X connect 18 8 19 0;
diff --git a/stat-help.pd b/stat-help.pd
new file mode 100644
index 0000000..b508018
--- /dev/null
+++ b/stat-help.pd
@@ -0,0 +1,82 @@
+#N canvas 59 135 710 533 10;
+#X msg 114 53 bang;
+#X text 156 53 run on current folder;
+#X symbolatom 6 490 0 0 0 3 filename - -;
+#X floatatom 29 385 0 0 0 3 file_mode - -;
+#X floatatom 175 385 0 0 0 3 User_ID - -;
+#X floatatom 271 385 0 0 0 3 Group_ID - -;
+#X floatatom 338 385 0 0 0 3 Device_ID - -;
+#X obj 5 107 print data;
+#X obj 163 165 route error;
+#X symbolatom 163 201 0 0 0 0 error - -;
+#X floatatom 419 385 0 0 0 3 File_Size - -;
+#X floatatom 480 363 0 0 0 3 Blocks_Allocated - -;
+#X floatatom 537 338 0 0 0 3 preferred_block_size - -;
+#X obj 79 8 bng 15 250 50 0 empty empty empty 0 -6 0 8 -24198 -1 -1
+;
+#X obj 79 26 openpanel;
+#X text 151 16 try it on any file (it doesn't change anything \, just
+reads data from the file system).;
+#X text 127 146 <-- set filename by cold inlet or object argument;
+#X obj 270 425 gid->group_name;
+#X symbolatom 270 454 0 0 0 3 group_name - -;
+#X obj 163 183 symbol;
+#X msg 127 79 symbol /tmp/this_file_doesn't_exist;
+#X text 244 186 errors are reported in Pd space;
+#X floatatom 98 385 0 0 0 3 hard_links - -;
+#X symbolatom 174 454 0 0 0 3 group_name - -;
+#X obj 174 425 uid->username;
+#X obj 91 147 stat;
+#X obj 77 203 list;
+#X obj 77 223 list split 9;
+#X obj 9 282 unpack symbol float float float float float float float
+float;
+#N canvas 0 22 458 308 time 0;
+#X obj 136 34 inlet;
+#X floatatom 19 193 6 0 0 3 days - -;
+#X floatatom 66 193 6 0 0 3 seconds - -;
+#X text 26 223 last access;
+#X floatatom 158 192 6 0 0 3 days - -;
+#X floatatom 205 192 6 0 0 3 seconds - -;
+#X text 144 220 last modification;
+#X floatatom 305 194 6 0 0 3 days - -;
+#X floatatom 352 194 6 0 0 3 seconds - -;
+#X text 290 222 last status change;
+#X obj 49 137 unpack float float float float float float;
+#X connect 0 0 10 0;
+#X connect 10 0 1 0;
+#X connect 10 1 2 0;
+#X connect 10 2 4 0;
+#X connect 10 3 5 0;
+#X connect 10 4 7 0;
+#X connect 10 5 8 0;
+#X restore 116 253 pd time stamps;
+#X msg 138 103 symbol /usr/bin/gcc;
+#X text 226 251 <-- open this to see the timestamps;
+#X connect 0 0 25 0;
+#X connect 4 0 24 0;
+#X connect 5 0 17 0;
+#X connect 8 0 19 0;
+#X connect 13 0 14 0;
+#X connect 14 0 25 0;
+#X connect 17 0 18 0;
+#X connect 19 0 9 0;
+#X connect 20 0 25 0;
+#X connect 24 0 23 0;
+#X connect 25 0 7 0;
+#X connect 25 0 26 0;
+#X connect 25 0 28 0;
+#X connect 25 1 8 0;
+#X connect 26 0 27 0;
+#X connect 27 0 28 0;
+#X connect 27 1 29 0;
+#X connect 28 0 2 0;
+#X connect 28 1 3 0;
+#X connect 28 2 22 0;
+#X connect 28 3 4 0;
+#X connect 28 4 5 0;
+#X connect 28 5 6 0;
+#X connect 28 6 10 0;
+#X connect 28 7 11 0;
+#X connect 28 8 12 0;
+#X connect 30 0 25 0;
diff --git a/file_status.c b/stat.c
index 89780e1..54452b1 100644
--- a/file_status.c
+++ b/stat.c
@@ -40,7 +40,7 @@
static char *version = "$Revision: 1.1 $";
-t_int file_status_instance_count;
+t_int stat_instance_count;
#define DEBUG(x)
//#define DEBUG(x) x
@@ -48,68 +48,118 @@ t_int file_status_instance_count;
/*------------------------------------------------------------------------------
* CLASS DEF
*/
-static t_class *file_status_class;
+static t_class *stat_class;
-typedef struct _file_status {
+typedef struct _stat {
t_object x_obj;
t_symbol *x_filename;
+/* output */
+ t_atom *output; // holder for a list of atoms to be outputted
+ t_int output_count; // number of atoms in in x->output
t_outlet *x_data_outlet;
t_outlet *x_status_outlet;
-} t_file_status;
+} t_stat;
+
+
+
+/*------------------------------------------------------------------------------
+ * SUPPORT FUNCTIONS
+ */
+
+/* add one new atom to the list to be outputted */
+static void add_atom_to_output(t_stat *x, t_atom *new_atom)
+{
+ t_atom *new_atom_list;
+
+ new_atom_list = (t_atom *)getbytes((x->output_count + 1) * sizeof(t_atom));
+ memcpy(new_atom_list, x->output, x->output_count * sizeof(t_atom));
+ freebytes(x->output, x->output_count * sizeof(t_atom));
+ x->output = new_atom_list;
+ memcpy(x->output + x->output_count, new_atom, sizeof(t_atom));
+ ++(x->output_count);
+}
+
+/*
+static void add_symbol_to_output(t_stat *x, t_symbol *s)
+{
+ t_atom *temp_atom = getbytes(sizeof(t_atom));
+ SETSYMBOL(temp_atom, s);
+ add_atom_to_output(x,temp_atom);
+ freebytes(temp_atom,sizeof(t_atom));
+}
+*/
+
+static void add_float_to_output(t_stat *x, t_float f)
+{
+ t_atom *temp_atom = getbytes(sizeof(t_atom));
+ SETFLOAT(temp_atom, f);
+ add_atom_to_output(x,temp_atom);
+ freebytes(temp_atom,sizeof(t_atom));
+}
+
+static void reset_output(t_stat *x)
+{
+ if(x->output)
+ {
+ freebytes(x->output, x->output_count * sizeof(t_atom));
+ x->output = NULL;
+ x->output_count = 0;
+ }
+}
/*------------------------------------------------------------------------------
* IMPLEMENTATION
*/
-static void file_status_output_error(t_file_status *x, int error_number)
+static void stat_output_error(t_stat *x, int error_number)
{
t_atom output_atoms[2];
switch(error_number)
{
case EACCES:
- error("[file_status]: access denied: %s", x->x_filename->s_name);
+ error("[stat]: access denied: %s", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("access"));
break;
case EIO:
- error("[file_status]: An error occured while reading %s",
+ error("[stat]: An error occured while reading %s",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("io"));
break;
case ELOOP:
- error("[file_status]: A loop exists in symbolic links in %s",
+ error("[stat]: A loop exists in symbolic links in %s",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("loop"));
break;
case ENAMETOOLONG:
- error("[file_status]: The filename %s is too long",
+ error("[stat]: The filename %s is too long",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("name_too_long"));
break;
case ENOENT:
- error("[file_status]: %s does not exist", x->x_filename->s_name);
+ error("[stat]: %s does not exist", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("does_not_exist"));
break;
case ENOTDIR:
- error("[file_status]: A component of %s is not a existing folder",
+ error("[stat]: A component of %s is not a existing folder",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("not_folder"));
break;
case EOVERFLOW:
- error("[file_status]: %s caused overflow in stat struct",
+ error("[stat]: %s caused overflow in stat struct",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("overflow"));
break;
case EFAULT:
- error("[file_status]: fault in stat struct (%s)", x->x_filename->s_name);
+ error("[stat]: fault in stat struct (%s)", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("fault"));
break;
case EINVAL:
- error("[file_status]: invalid argument to stat() (%s)",
+ error("[stat]: invalid argument to stat() (%s)",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("invalid"));
break;
default:
- error("[file_status]: unknown error %d: %s",
+ error("[stat]: unknown error %d: %s",
error_number, x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("unknown"));
}
@@ -117,12 +167,11 @@ static void file_status_output_error(t_file_status *x, int error_number)
outlet_anything(x->x_status_outlet, gensym("error"), 2, output_atoms);
}
-static void file_status_output(t_file_status* x)
+static void stat_output(t_stat* x)
{
- DEBUG(post("file_status_output"););
+ DEBUG(post("stat_output"););
struct stat stat_buffer;
int result;
- t_atom output_atoms[7];
#ifdef _WIN32
result = _stat(x->x_filename, &stat_buffer);
@@ -131,26 +180,51 @@ static void file_status_output(t_file_status* x)
#endif /* _WIN32 */
if(result != 0)
{
- file_status_output_error(x, result);
+ stat_output_error(x, result);
}
else
{
- /* TODO: output time stamps, in which format? */
- SETFLOAT(output_atoms, (t_float) stat_buffer.st_nlink);
- SETFLOAT(output_atoms + 1, (t_float) stat_buffer.st_uid);
- SETFLOAT(output_atoms + 2, (t_float) stat_buffer.st_gid);
- SETFLOAT(output_atoms + 3, (t_float) stat_buffer.st_rdev);
- SETFLOAT(output_atoms + 4, (t_float) stat_buffer.st_size);
- SETFLOAT(output_atoms + 5, (t_float) stat_buffer.st_blocks);
- SETFLOAT(output_atoms + 6, (t_float) stat_buffer.st_blksize);
- outlet_anything(x->x_data_outlet,x->x_filename,7,output_atoms);
+ reset_output(x);
+ post("");
+ add_float_to_output(x, (t_float) stat_buffer.st_mode);
+ add_float_to_output(x, (t_float) stat_buffer.st_nlink);
+ add_float_to_output(x, (t_float) stat_buffer.st_uid);
+ add_float_to_output(x, (t_float) stat_buffer.st_gid);
+ add_float_to_output(x, (t_float) stat_buffer.st_rdev);
+ add_float_to_output(x, (t_float) stat_buffer.st_size);
+ add_float_to_output(x, (t_float) stat_buffer.st_blocks);
+ add_float_to_output(x, (t_float) stat_buffer.st_blksize);
+ /* 86400 seconds == 24 hours == 1 day */
+#ifdef _POSIX_C_SOURCE
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_atimespec.tv_sec / 86400));
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_atimespec.tv_sec % 86400));
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_mtimespec.tv_sec / 86400));
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_mtimespec.tv_sec % 86400));
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_ctimespec.tv_sec / 86400));
+ add_float_to_output(x,
+ (t_float) (stat_buffer.st_ctimespec.tv_sec % 86400));
+#else
+ add_float_to_output(x, (t_float) (stat_buffer.st_atime / 86400));
+ add_float_to_output(x, (t_float) (stat_buffer.st_atime % 86400));
+ add_float_to_output(x, (t_float) (stat_buffer.st_mtime / 86400));
+ add_float_to_output(x, (t_float) (stat_buffer.st_mtime % 86400));
+ add_float_to_output(x, (t_float) (stat_buffer.st_ctime / 86400));
+ add_float_to_output(x, (t_float) (stat_buffer.st_ctime % 86400));
+#endif /* _POSIX_C_SOURCE */
+ outlet_anything(x->x_data_outlet,x->x_filename,
+ x->output_count,x->output);
}
}
-static void file_status_set(t_file_status* x, t_symbol *s)
+static void stat_set(t_stat* x, t_symbol *s)
{
- DEBUG(post("file_status_set"););
+ DEBUG(post("stat_set"););
#ifdef _WIN32
char string_buffer[MAX_PATH];
ExpandEnvironmentStrings(s->s_name, string_buffer, MAX_PATH);
@@ -161,26 +235,26 @@ static void file_status_set(t_file_status* x, t_symbol *s)
}
-static void file_status_symbol(t_file_status *x, t_symbol *s)
+static void stat_symbol(t_stat *x, t_symbol *s)
{
- file_status_set(x,s);
- file_status_output(x);
+ stat_set(x,s);
+ stat_output(x);
}
-static void *file_status_new(t_symbol *s)
+static void *stat_new(t_symbol *s)
{
- DEBUG(post("file_status_new"););
+ DEBUG(post("stat_new"););
- t_file_status *x = (t_file_status *)pd_new(file_status_class);
+ t_stat *x = (t_stat *)pd_new(stat_class);
- if(!file_status_instance_count)
+ if(!stat_instance_count)
{
- post("[file_status] %s",version);
+ post("[stat] %s",version);
post("\twritten by Hans-Christoph Steiner <hans@at.or.at>");
post("\tcompiled on "__DATE__" at "__TIME__ " ");
}
- file_status_instance_count++;
+ stat_instance_count++;
symbolinlet_new(&x->x_obj, &x->x_filename);
@@ -201,22 +275,22 @@ static void *file_status_new(t_symbol *s)
return (x);
}
-void file_status_setup(void)
+void stat_setup(void)
{
- DEBUG(post("file_status_setup"););
- file_status_class = class_new(gensym("file_status"),
- (t_newmethod)file_status_new,
+ DEBUG(post("stat_setup"););
+ stat_class = class_new(gensym("stat"),
+ (t_newmethod)stat_new,
0,
- sizeof(t_file_status),
+ sizeof(t_stat),
0,
A_DEFSYM,
0);
/* add inlet datatype methods */
- class_addbang(file_status_class,(t_method) file_status_output);
- class_addsymbol(file_status_class,(t_method) file_status_symbol);
+ class_addbang(stat_class,(t_method) stat_output);
+ class_addsymbol(stat_class,(t_method) stat_symbol);
/* add inlet message methods */
- class_addmethod(file_status_class,(t_method) file_status_set,gensym("set"),
+ class_addmethod(stat_class,(t_method) stat_set,gensym("set"),
A_DEFSYM, 0);
}