long dummy_rename (MAILSTREAM *stream,char *old,char *newname) { struct stat sbuf; char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN]; long ret = NIL; /* no trailing \ allowed */ if (!dummy_file (oldname,old) || !(s = dummy_file (mbx,newname)) || ((s = strrchr (s,'\\')) && !s[1])) { sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",old,newname); mm_log (mbx,ERROR); return NIL; } /* found superior to destination name? */ if (s && (s != mbx) && ((mbx[1] != ':') || (s != mbx + 2))) { c = s[1]; /* remember character after delimiter */ *s = s[1] = '\0'; /* tie off name at delimiter */ /* name doesn't exist, create it */ if (stat (mbx,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) { *s = '\\'; /* restore delimiter */ if (!dummy_create (stream,mbx)) return NIL; } else *s = '\\'; /* restore delimiter */ s[1] = c; /* restore character after delimiter */ } /* rename of non-ex INBOX creates dest */ if (!compare_cstring (old,"INBOX") && stat (oldname,&sbuf)) return dummy_create (NIL,mbx); if (rename (oldname,mbx)) { sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",old,newname, strerror (errno)); mm_log (tmp,ERROR); return NIL; } return LONGT; /* return success */ }
long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data) { struct stat sbuf; int fd = -1; int e; char tmp[MAILTMPLEN]; MAILSTREAM *ts = default_proto (T); if (compare_cstring (mailbox,"INBOX") && dummy_file (tmp,mailbox) && ((fd = open (tmp,O_RDONLY,NIL)) < 0)) { if ((e = errno) == ENOENT) /* failed, was it no such file? */ mm_notify (stream,"[TRYCREATE] Must create mailbox before append", (long) NIL); sprintf (tmp,"%.80s: %.80s",strerror (e),mailbox); mm_log (tmp,ERROR); /* pass up error */ return NIL; /* always fails */ } if (fd >= 0) { /* found file? */ fstat (fd,&sbuf); /* get its size */ close (fd); /* toss out the fd */ if (sbuf.st_size) ts = NIL; /* non-empty file? */ } if (ts) return (*ts->dtb->append) (stream,mailbox,af,data); sprintf (tmp,"Indeterminate mailbox format: %.80s",mailbox); mm_log (tmp,ERROR); return NIL; }
MAILSTREAM *dummy_open (MAILSTREAM *stream) { int fd; char err[MAILTMPLEN],tmp[MAILTMPLEN]; struct stat sbuf; /* OP_PROTOTYPE call */ if (!stream) return &dummyproto; err[0] = '\0'; /* no error message yet */ /* can we open the file? */ if (!dummy_file (tmp,stream->mailbox)) sprintf (err,"Can't open this name: %.80s",stream->mailbox); else if ((fd = open (tmp,O_RDONLY,NIL)) < 0) { /* no, error unless INBOX */ if (compare_cstring (stream->mailbox,"INBOX")) sprintf (err,"%.80s: %.80s",strerror (errno),stream->mailbox); } else { /* file had better be empty then */ fstat (fd,&sbuf); /* sniff at its size */ close (fd); if (sbuf.st_size) /* bogus format if non-empty */ sprintf (err,"%.80s (file %.80s) is not in valid mailbox format", stream->mailbox,tmp); } if (err[0]) { /* if an error happened */ mm_log (err,stream->silent ? WARN : ERROR); return NIL; } else if (!stream->silent) { /* only if silence not requested */ mail_exists (stream,0); /* say there are 0 messages */ mail_recent (stream,0); /* and certainly no recent ones! */ stream->uid_validity = time (0); } stream->inbox = T; /* note that it's an INBOX */ return stream; /* return success */ }
long dummy_listed (MAILSTREAM *stream,char delimiter,char *name, long attributes,char *contents) { struct stat sbuf; int fd; long csiz,ssiz,bsiz; char *s,*buf,tmp[MAILTMPLEN]; if (contents) { /* want to search contents? */ /* forget it if can't select or open */ if ((attributes & LATT_NOSELECT) || !(csiz = strlen (contents)) || !(s = dummy_file (tmp,name)) || stat (s,&sbuf) || (csiz > sbuf.st_size) || ((fd = open (tmp,O_RDONLY,NIL)) < 0)) return T; /* get buffer including slop */ buf = (char *) fs_get (BUFSIZE + (ssiz = 4 * ((csiz / 4) + 1)) + 1); memset (buf,'\0',ssiz); /* no slop area the first time */ while (sbuf.st_size) { /* until end of file */ read (fd,buf+ssiz,bsiz = min (sbuf.st_size,BUFSIZE)); if (search ((unsigned char *) buf,bsiz+ssiz, (unsigned char *) contents,csiz)) break; memcpy (buf,buf+BUFSIZE,ssiz); sbuf.st_size -= bsiz; /* note that we read that much */ } fs_give ((void **) &buf); /* flush buffer */ close (fd); /* finished with file */ if (!sbuf.st_size) return T;/* not found */ } /* notify main program */ mm_list (stream,delimiter,name,attributes); return T; }
long dummy_create (MAILSTREAM *stream,char *mailbox) { char tmp[MAILTMPLEN]; if (compare_cstring (mailbox,"INBOX") && dummy_file (tmp,mailbox)) return dummy_create_path (stream,tmp,NIL); sprintf (tmp,"Can't create %.80s: invalid name",mailbox); mm_log (tmp,ERROR); return NIL; }
long dummy_delete (MAILSTREAM *stream,char *mailbox) { struct stat sbuf; char *s,tmp[MAILTMPLEN]; if (!(s = dummy_file (tmp,mailbox))) { sprintf (tmp,"Can't delete - invalid name: %.80s",s); mm_log (tmp,ERROR); } /* no trailing \ */ if ((s = strrchr (tmp,'\\')) && !s[1]) *s = '\0'; if (stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) == S_IFDIR) ? rmdir (tmp) : unlink (tmp)) { sprintf (tmp,"Can't delete mailbox %.80s: %.80s",mailbox,strerror (errno)); mm_log (tmp,ERROR); return NIL; } return T; /* return success */ }
long dummy_listed (MAILSTREAM *stream,char delimiter,char *name, long attributes,char *contents) { struct stat sbuf; struct _finddata_t f; int fd,nochild; long fhandle,csiz,ssiz,bsiz; char *s,*buf,tmp[MAILTMPLEN]; /* if not \NoInferiors */ if (!(attributes & LATT_NOINFERIORS) && mailboxdir (tmp,name,NIL) && strcat (tmp,(tmp[strlen (tmp) -1] == '\\') ? "*.*" : "\\*.*") && ((fhandle = _findfirst (tmp,&f)) >= 0)) { nochild = T; do if ((f.name[0] != '.') || (f.name[1] && ((f.name[1] != '.') || f.name[2]))) nochild = NIL; while (nochild && !_findnext (fhandle,&f)); attributes |= nochild ? LATT_HASNOCHILDREN : LATT_HASCHILDREN; _findclose (fhandle); /* all done, flush directory */ } if (contents) { /* want to search contents? */ /* forget it if can't select or open */ if ((attributes & LATT_NOSELECT) || !(csiz = strlen (contents)) || !(s = dummy_file (tmp,name)) || stat (s,&sbuf) || (csiz > sbuf.st_size) || ((fd = open (tmp,O_RDONLY,NIL)) < 0)) return T; /* get buffer including slop */ buf = (char *) fs_get (BUFSIZE + (ssiz = 4 * ((csiz / 4) + 1)) + 1); memset (buf,'\0',ssiz); /* no slop area the first time */ while (sbuf.st_size) { /* until end of file */ read (fd,buf+ssiz,bsiz = min (sbuf.st_size,BUFSIZE)); if (search ((unsigned char *) buf,bsiz+ssiz, (unsigned char *) contents,csiz)) break; memcpy (buf,buf+BUFSIZE,ssiz); sbuf.st_size -= bsiz; /* note that we read that much */ } fs_give ((void **) &buf); /* flush buffer */ close (fd); /* finished with file */ if (!sbuf.st_size) return T;/* not found */ } /* notify main program */ mm_list (stream,delimiter,name,attributes); return T; }
void xlGridCanvasPictures::LoadImage() { wxFileName dummy_file(PictureName); // prompt for new filename wxFileDialog fd(this, "Choose Image File to Load:", dummy_file.GetPath(), wxEmptyString, strSupportedImageTypes, wxFD_OPEN); int result = fd.ShowModal(); wxString new_filename = fd.GetPath(); if( result == wxID_CANCEL || new_filename == "" ) { return; } PictureName = new_filename; UpdateRenderedImage(); mModified = true; NewPictureName = PictureName; LoadAndProcessImage(); }
/// Return the filename of the next output file. std::string PollOutputFile::GetNextFileName(int &run_num_, std::string prefix, std::string output_directory, bool continueRun /*=false*/) { std::stringstream filename; filename << output_directory << prefix << "_" << std::setfill('0') << std::setw(3) << run_num_; if(output_format == 0){ filename << ".ldf"; } else if(output_format == 1){ filename << ".pld"; } std::ifstream dummy_file(filename.str().c_str()); int suffix = 0; while (dummy_file.is_open()) { dummy_file.close(); filename.str(""); if(continueRun){ filename << output_directory << prefix << "_" << std::setfill('0') << std::setw(3) << run_num_ << "-" << ++suffix; } else{ filename << output_directory << prefix << "_" << std::setfill('0') << std::setw(3) << ++run_num_; } if(output_format == 0){ filename << ".ldf"; } else if(output_format == 1){ filename << ".pld"; } dummy_file.open(filename.str().c_str()); } dummy_file.close(); return filename.str(); }