1 #include <../../nrnconf.h>
5 #if defined(HAVE_UNISTD_H)
16 #include <IV-look/dialogs.h>
17 #include <InterViews/session.h>
18 #include <InterViews/display.h>
19 #include <InterViews/style.h>
96 if (err && errno == 29) {
120 int i = fscanf(f->
file(),
"%s",
buf);
123 return double(strlen(
buf));
133 FILE* fw = f->
file();
136 return double(strlen(
buf));
144 return double(f->
mktemp());
149 return double(f->
unlink());
154 return double(f->
eof());
175 return (
const char**) ps;
181 *ps = (
char*) f->
dir();
182 return (
const char**) ps;
196 char *
type, *
banner, *filter, *bopen, *cancel;
198 const char* path =
".";
232 n =
long(
chkarg(1, 1., 2.e18));
255 base = int(
chkarg(2, 0., 2.));
321 void OcFile::binary_mode() {
322 if (
file() && !binary_) {
323 if (ftell(
file()) != 0) {
325 ":can switch to dos binary file mode only at beginning of file.\n\
326 Use File.seek(0) after opening or use a binary style read/write as first\n\
329 setmode(fileno(
file()), O_BINARY);
355 return ungetc(
c,
file()) == EOF;
378 const char* cancel) {
382 Style* style =
new Style(Session::instance()->style());
387 style->attribute(
"caption",
banner);
393 style->attribute(
"filter",
"true");
394 style->attribute(
"filterPattern", filter);
399 style->attribute(
"open", bopen);
401 }
else if (
type[0] ==
'w') {
402 style->attribute(
"open",
"Save");
406 style->attribute(
"cancel", cancel);
412 style->attribute(
"caption",
"File write");
415 style->attribute(
"caption",
"File append");
418 style->attribute(
"caption",
"File read");
421 style->attribute(
"caption",
"Directory open");
424 style->attribute(
"caption",
"File name only");
439 style->attribute(
"choose_directory",
"on");
445 fc_ = DialogKit::instance()->file_chooser(path, style);
467 hoc_execerror(
"First call to file_chooser must at least specify r or w", 0);
470 Display* d = Session::instance()->default_display();
482 while (
fc_->post_at_aligned(x, y, ax, ay)) {
483 switch (chooser_type_) {
486 open(
fc_->selected()->string(),
"w");
492 open(
fc_->selected()->string(),
"a");
499 open(
fc_->selected()->string(),
"r");
526 if (_stat(path.c_str(), &
info) != 0) {
529 return (
info.st_mode & _S_IFDIR) != 0;
532 if (stat(path.c_str(), &
info) != 0) {
535 return (
info.st_mode & S_IFDIR) != 0;
541 int ret = _mkdir(path.c_str());
544 int ret = mkdir(path.c_str(), mode);
553 int pos = path.find_last_of(
'/');
554 if (pos == std::string::npos)
556 pos = path.find_last_of(
'\\');
557 if (pos == std::string::npos)
565 return 0 == _mkdir(path.c_str());
567 return 0 == mkdir(path.c_str(), mode);
void set_name(const char *s)
void print(const char *s)
bool file_chooser_popup()
void file_chooser_style(const char *type, const char *path, const char *banner=NULL, const char *filter=NULL, const char *accept=NULL, const char *cancel=NULL)
bool open(const char *filename, const char *type)
virtual void unref() const
void class2oc(const char *, ctor_f *cons, dtor_f *destruct, Member_func *, Member_ret_obj_func *, Member_ret_str_func *)
HocReturnType hoc_return_type_code
double chkarg(int, double low, double high)
std::FILE * hoc_obj_file_arg(int i)
void hoc_assign_str(char **cpp, const char *buf)
const char * expand_env_var(const char *s)
void check_obj_type(Object *obj, const char *type_name)
char ** hoc_temp_charptr(void)
double * hoc_pgetarg(int narg)
void hoc_sprint1(char **ppbuf, int argn)
Symbol * hoc_lookup(const char *)
char ** hoc_pgargstr(int narg)
#define TRY_GUI_REDIRECT_METHOD_ACTUAL_DOUBLE(name, sym, v)
char * fgets_unlimited(HocStr *s, NrnFILEWrap *f)
Object ** hoc_objgetarg(int)
void hoc_execerror(const char *s1, const char *s2)
int const size_t const size_t n
static double f_printf(void *v)
static double f_scanstr(void *v)
static const char ** f_get_name(void *v)
static double f_chooser(void *v)
static double f_scanvar(void *v)
static double f_is_open(void *v)
static double f_unlink(void *v)
bool makePath(const std::string &path)
static double f_vwrite(void *v)
static double f_close(void *v)
static Symbol * file_class_sym_
char * ivoc_get_temp_file()
static double f_ropen(void *v)
bool isDirExist(const std::string &path)
static double f_seek(void *v)
static double f_wopen(void *v)
static double f_eof(void *v)
static void * f_cons(Object *)
static double f_aopen(void *v)
static int ivoc_unlink(const char *)
static double f_tell(void *v)
static const char ** f_dir(void *v)
static double f_flush(void *v)
static void f_destruct(void *v)
static double f_vread(void *v)
static double f_gets(void *v)
static Member_ret_str_func f_retstr_members[]
static double f_mktemp(void *v)
#define BinaryMode(ocfile)
bool nrn_spec_dialog_pos(Coord &x, Coord &y)
true if Style 'dialog_spec_position: on' and fills x,y with dialog_left_position and dialog_bottom_po...
bool ok_to_write(const String &, Window *w=NULL)
bool ok_to_read(const String &, Window *w=NULL)