[PD-cvs] externals/hcs stat.c, NONE, 1.1 stat-help.pd, NONE, 1.1 file_type-help.pd, NONE, 1.1 file_type.pd, NONE, 1.1 file_status-help.pd, 1.1, NONE file_status.c, 1.1, NONE
Hans-Christoph Steiner
eighthave at users.sourceforge.net
Tue Jun 13 00:46:29 CEST 2006
- Previous message: [PD-cvs] externals/hcs group.c, 1.1, 1.2 group-help.pd, 1.1, 1.2 group_name0x2d0x3egid.pd, 1.1, 1.2
- Next message: [PD-cvs] externals/hcs stat.c,1.1,1.2 stat-help.pd,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/pure-data/externals/hcs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12731
Added Files:
stat.c stat-help.pd file_type-help.pd file_type.pd
Removed Files:
file_status-help.pd file_status.c
Log Message:
changed [file_status] to [stat] since that's all it does; got [stat] working, still need to get error messages to work properly; created file_type Pd object
--- file_status-help.pd DELETED ---
--- NEW FILE: file_type.pd ---
#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;
--- NEW FILE: file_type-help.pd ---
#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;
--- NEW FILE: stat.c ---
/* --------------------------------------------------------------------------*/
/* */
/* object for getting file type (dir, link, exe, etc) using a filename */
/* Written by Hans-Christoph Steiner <hans at at.or.at> */
/* */
/* Copyright (c) 2006 Hans-Christoph Steiner */
/* */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version 2 */
/* of the License, or (at your option) any later version. */
/* */
/* See file LICENSE for further informations on licensing terms. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software Foundation, */
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* */
/* --------------------------------------------------------------------------*/
#include <m_pd.h>
#ifdef _WIN32
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
#else
#include <stdlib.h>
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
static char *version = "$Revision: 1.1 $";
t_int stat_instance_count;
#define DEBUG(x)
//#define DEBUG(x) x
/*------------------------------------------------------------------------------
* CLASS DEF
*/
static t_class *stat_class;
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_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 stat_output_error(t_stat *x, int error_number)
{
t_atom output_atoms[2];
switch(error_number)
{
case EACCES:
error("[stat]: access denied: %s", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("access"));
break;
case EIO:
error("[stat]: An error occured while reading %s",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("io"));
break;
case ELOOP:
error("[stat]: A loop exists in symbolic links in %s",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("loop"));
break;
case ENAMETOOLONG:
error("[stat]: The filename %s is too long",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("name_too_long"));
break;
case ENOENT:
error("[stat]: %s does not exist", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("does_not_exist"));
break;
case ENOTDIR:
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("[stat]: %s caused overflow in stat struct",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("overflow"));
break;
case EFAULT:
error("[stat]: fault in stat struct (%s)", x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("fault"));
break;
case EINVAL:
error("[stat]: invalid argument to stat() (%s)",
x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("invalid"));
break;
default:
error("[stat]: unknown error %d: %s",
error_number, x->x_filename->s_name);
SETSYMBOL(output_atoms, gensym("unknown"));
}
SETSYMBOL(output_atoms + 2, x->x_filename);
outlet_anything(x->x_status_outlet, gensym("error"), 2, output_atoms);
}
static void stat_output(t_stat* x)
{
DEBUG(post("stat_output"););
struct stat stat_buffer;
int result;
#ifdef _WIN32
result = _stat(x->x_filename, &stat_buffer);
#else
result = stat(x->x_filename->s_name, &stat_buffer);
#endif /* _WIN32 */
if(result != 0)
{
stat_output_error(x, result);
}
else
{
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 stat_set(t_stat* x, t_symbol *s)
{
DEBUG(post("stat_set"););
#ifdef _WIN32
char string_buffer[MAX_PATH];
ExpandEnvironmentStrings(s->s_name, string_buffer, MAX_PATH);
x->x_filename = gensym(string_buffer);
#else
x->x_filename = s;
#endif
}
static void stat_symbol(t_stat *x, t_symbol *s)
{
stat_set(x,s);
stat_output(x);
}
static void *stat_new(t_symbol *s)
{
DEBUG(post("stat_new"););
t_stat *x = (t_stat *)pd_new(stat_class);
if(!stat_instance_count)
{
post("[stat] %s",version);
post("\twritten by Hans-Christoph Steiner <hans at at.or.at>");
post("\tcompiled on "__DATE__" at "__TIME__ " ");
}
stat_instance_count++;
symbolinlet_new(&x->x_obj, &x->x_filename);
x->x_data_outlet = outlet_new(&x->x_obj, 0);
x->x_status_outlet = outlet_new(&x->x_obj, 0);
/* set to the value from the object argument, if that exists */
if (s != &s_)
{
x->x_filename = s;
}
else
{
x->x_filename = canvas_getcurrentdir();
post("setting pattern to default: %s",x->x_filename->s_name);
}
return (x);
}
void stat_setup(void)
{
DEBUG(post("stat_setup"););
stat_class = class_new(gensym("stat"),
(t_newmethod)stat_new,
0,
sizeof(t_stat),
0,
A_DEFSYM,
0);
/* add inlet datatype methods */
class_addbang(stat_class,(t_method) stat_output);
class_addsymbol(stat_class,(t_method) stat_symbol);
/* add inlet message methods */
class_addmethod(stat_class,(t_method) stat_set,gensym("set"),
A_DEFSYM, 0);
}
--- NEW FILE: stat-help.pd ---
#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;
--- file_status.c DELETED ---
- Previous message: [PD-cvs] externals/hcs group.c, 1.1, 1.2 group-help.pd, 1.1, 1.2 group_name0x2d0x3egid.pd, 1.1, 1.2
- Next message: [PD-cvs] externals/hcs stat.c,1.1,1.2 stat-help.pd,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Pd-cvs
mailing list