Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13080
Added Files: file_status.c file_status-help.pd gid0x2d0x3egroup_name.c gid0x2d0x3egroup_name-help.pd Log Message: added more file-based classes; file_status needs to output timestamp info too
--- NEW FILE: gid0x2d0x3egroup_name-help.pd --- #N canvas 378 215 466 316 10; #X obj 94 157 gid->group_name; #X obj 98 60 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 500 1; #X floatatom 95 83 5 0 0 0 Group_ID - -; #X symbolatom 94 207 0 0 0 0 Group_Name - -; #X text 52 40 convert group GID number to group name symbol; #X obj 106 188 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X text 68 255 outputs a blank symbol if no match; #X msg 194 138 10; #X msg 112 106 bang; #X text 209 158 <-- set by argument or cold inlet; #X text 148 105 output current; #X connect 0 0 3 0; #X connect 0 0 5 0; #X connect 1 0 2 0; #X connect 2 0 0 0; #X connect 7 0 0 1; #X connect 8 0 0 0;
--- NEW FILE: gid0x2d0x3egroup_name.c --- /* --------------------------------------------------------------------------*/ /* */ /* converts a GID number to a group name symbol */ /* Written by Hans-Christoph Steiner hans@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> #include <lm.h> #else #include <stdlib.h> #include <grp.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 gid0x2d0x3egroup_name_instance_count;
#define DEBUG(x) //#define DEBUG(x) x
/*------------------------------------------------------------------------------ * CLASS DEF */ static t_class *gid0x2d0x3egroup_name_class;
typedef struct _gid0x2d0x3egroup_name { t_object x_obj; t_float x_gid; t_outlet *x_data_outlet; // t_outlet *x_status_outlet; } t_gid0x2d0x3egroup_name;
/*------------------------------------------------------------------------------ * IMPLEMENTATION */
static void gid0x2d0x3egroup_name_output(t_gid0x2d0x3egroup_name* x) { DEBUG(post("gid0x2d0x3egroup_name_output");); struct group *group_pointer;
#ifdef _WIN32 /* TODO: implement for Windows! */ #else { group_pointer = getgrgid((gid_t)x->x_gid); if( group_pointer != NULL ) outlet_symbol(x->x_data_outlet, gensym(group_pointer->gr_name)); else /* output blank symbol if no match */ outlet_symbol(x->x_data_outlet, &s_); } #endif /* _WIN32 */ }
static void gid0x2d0x3egroup_name_set(t_gid0x2d0x3egroup_name* x, t_float f) { DEBUG(post("gid0x2d0x3egroup_name_set");); x->x_gid = f; }
static void gid0x2d0x3egroup_name_float(t_gid0x2d0x3egroup_name *x, t_float f) { gid0x2d0x3egroup_name_set(x,f); gid0x2d0x3egroup_name_output(x); }
static void *gid0x2d0x3egroup_name_new(t_float f) { DEBUG(post("gid0x2d0x3egroup_name_new"););
t_gid0x2d0x3egroup_name *x = (t_gid0x2d0x3egroup_name *)pd_new(gid0x2d0x3egroup_name_class);
if(!gid0x2d0x3egroup_name_instance_count) { post("[gid->group_name] %s",version); post("\twritten by Hans-Christoph Steiner hans@at.or.at"); post("\tcompiled on "__DATE__" at "__TIME__ " "); } gid0x2d0x3egroup_name_instance_count++;
floatinlet_new(&x->x_obj, &x->x_gid); x->x_data_outlet = outlet_new(&x->x_obj, 0); // x->x_status_outlet = outlet_new(&x->x_obj, 0);
gid0x2d0x3egroup_name_set(x,f);
return (x); }
void gid0x2d0x3egroup_name_free(void) { #ifdef _WIN32 #else endgrent(); #endif /* _WIN32 */ }
void gid0x2d0x3egroup_name_setup(void) { DEBUG(post("gid0x2d0x3egroup_name_setup");); gid0x2d0x3egroup_name_class = class_new(gensym("gid->group_name"), (t_newmethod)gid0x2d0x3egroup_name_new, 0, sizeof(t_gid0x2d0x3egroup_name), 0, A_DEFFLOAT, 0); /* add inlet datatype methods */ class_addbang(gid0x2d0x3egroup_name_class, (t_method) gid0x2d0x3egroup_name_output); class_addfloat(gid0x2d0x3egroup_name_class, (t_method) gid0x2d0x3egroup_name_float); /* add inlet message methods */ class_addmethod(gid0x2d0x3egroup_name_class, (t_method) gid0x2d0x3egroup_name_set,gensym("set"), A_DEFSYM, 0); }
--- NEW FILE: file_status-help.pd --- #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;
--- NEW FILE: file_status.c --- /* --------------------------------------------------------------------------*/ /* */ /* object for getting file type (dir, link, exe, etc) using a filename */ /* Written by Hans-Christoph Steiner hans@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 file_status_instance_count;
#define DEBUG(x) //#define DEBUG(x) x
/*------------------------------------------------------------------------------ * CLASS DEF */ static t_class *file_status_class;
typedef struct _file_status { t_object x_obj; t_symbol *x_filename; t_outlet *x_data_outlet; t_outlet *x_status_outlet; } t_file_status;
/*------------------------------------------------------------------------------ * IMPLEMENTATION */
static void file_status_output_error(t_file_status *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); SETSYMBOL(output_atoms, gensym("access")); break; case EIO: error("[file_status]: 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", x->x_filename->s_name); SETSYMBOL(output_atoms, gensym("loop")); break; case ENAMETOOLONG: error("[file_status]: 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); SETSYMBOL(output_atoms, gensym("does_not_exist")); break; case ENOTDIR: error("[file_status]: 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", 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); SETSYMBOL(output_atoms, gensym("fault")); break; case EINVAL: error("[file_status]: 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_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 file_status_output(t_file_status* x) { DEBUG(post("file_status_output");); struct stat stat_buffer; int result; t_atom output_atoms[7];
#ifdef _WIN32 result = _stat(x->x_filename, &stat_buffer); #else result = stat(x->x_filename->s_name, &stat_buffer); #endif /* _WIN32 */ if(result != 0) { file_status_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); } }
static void file_status_set(t_file_status* x, t_symbol *s) { DEBUG(post("file_status_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 file_status_symbol(t_file_status *x, t_symbol *s) { file_status_set(x,s); file_status_output(x); }
static void *file_status_new(t_symbol *s) { DEBUG(post("file_status_new"););
t_file_status *x = (t_file_status *)pd_new(file_status_class);
if(!file_status_instance_count) { post("[file_status] %s",version); post("\twritten by Hans-Christoph Steiner hans@at.or.at"); post("\tcompiled on "__DATE__" at "__TIME__ " "); } file_status_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 file_status_setup(void) { DEBUG(post("file_status_setup");); file_status_class = class_new(gensym("file_status"), (t_newmethod)file_status_new, 0, sizeof(t_file_status), 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); /* add inlet message methods */ class_addmethod(file_status_class,(t_method) file_status_set,gensym("set"), A_DEFSYM, 0); }