Quoting Kevin Cozens <[email protected]>:
> [email protected] wrote:
>> Script-fu does not provide a way to create subdirectories
>
> This came up in #gimp recently. It would be a useful addition to Script-Fu.
> This could be done by adding a "dir-create" function to the ftx extension
> used by the TinyScheme portion of Script-Fu. If a directory creation
> function is added then another function to add would be "dir-exists?".
Before I responded to the original post, I attempted to create just
such a function by modifying 'dir-open-stream'. I came up with the
following code but couldn't figure out how to build it out-of-tree in
a way the original poster could use without recompiling his GIMP (the
#include of scheme.h and scheme-private.h were basically where I
bogged down).
It should be trivial to add such a function to GIT tree. A file copy
function might also be useful (since file extensions are not always
available to indicate the type and copying text files using
read-char/write-char is slow and apparently unreliable).
pointer foreign_dircreate(scheme *sc, pointer args)
{
pointer first_arg;
char *dirpath;
GDir *dir;
if (args == sc->NIL)
return sc->F;
first_arg = sc->vptr->pair_car(args);
if (!sc->vptr->is_string(first_arg))
return sc->F;
dirpath = sc->vptr->string_value(first_arg);
dirpath = g_filename_from_utf8 (dirpath, -1, NULL, NULL, NULL);
dir = g_mkdir(dirpath, 0700);
if (dir != 0)
return sc->F;
/* Stuffing a pointer in a long may not always be portable ~~~~~ */
return (sc->vptr->mk_integer(sc, (long) dir));
}
/* This function gets called when TinyScheme is loading the extension */
void init_dircreate (scheme *sc)
{
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-create"),
sc->vptr->mk_foreign_func(sc, foreign_dircreate));
}
_______________________________________________
Gimp-developer mailing list
[email protected]
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer