// Obtain file path from URI specified as file:///bla/bla/bla... // If no 'file:' prefix is found, return the input string as is FXString fileFromURI(FXString uri) { if(comparecase("file:",uri,5)==0) { if(uri[5]==PATHSEPCHAR && uri[6]==PATHSEPCHAR) return uri.mid(7,uri.length()-7); return uri.mid(5,uri.length()-5); } return uri; }
void CCLCFox::unlockWithPass(FXString tktstr) { /* char val[sizeof(id) + CCLC_MD5_DIGEST_LENGTH * sizeof(FXuchar)]; FXuchar digest[CCLC_MD5_DIGEST_LENGTH]; CCLC_MD5((FXuchar*)(password.text()),password.length(),digest); ((FXuint*)val)[0] = CCLC_htonl(id);*/ // memcpy(((FXuint*)val)+1,digest,CCLC_MD5_DIGEST_LENGTH); if (tktstr.length() > MAX_INP_SIZE) tktstr.trunc(MAX_INP_SIZE); CCLC_send_cmd(CC_TICKETLOGIN, tktstr.text(),tktstr.length()); }
// Get height of multi-line label FXint FXLabel::labelHeight(const FXString& text) const { register FXint beg,end; register FXint th=0; beg=0; do{ end=beg; while(end<text.length() && text[end]!='\n') end++; th+=font->getFontHeight(); beg=end+1; } while(end<text.length()); return th; }
// Get width of multi-line label FXint FXLabel::labelWidth(const FXString& text) const { register FXint beg,end; register FXint w,tw=0; beg=0; do{ end=beg; while(end<text.length() && text[end]!='\n') end++; if((w=font->getTextWidth(&text[beg],end-beg))>tw) tw=w; beg=end+1; } while(end<text.length()); return tw; }
void endPage() { pageStarted = false; flushSegment(); // build actual text object; +3 is for "ET\n" // PDF1.4Ref(p38) EOL marker preceding endstream not counted char *textObj = new char[pageData.length() + 100]; // concatenate stream within the text object sprintf(textObj, "<</Length %d>>\nstream\n%s" "ET\nendstream\n", static_cast<int>(pageData.length() - 1 + 3), pageData.text()); oT->add(textObj); delete []textObj; }
static void gmsplit(const FXString & in,FXStringList & output) { FXint s=0; FXint e=0; FXint n=0; const FXchar sep=','; while(s<in.length()) { // trim leading white space while(in[s]==' ') s++; e=s; // find end while(in[e]!=sep && in[e]!='\0') e++; n=e+1; e=e-1; // trim end while(e>=s && in[e]==' ') e--; if (e>=s) { output.no(output.no()+1); output[output.no()-1].assign(&in[s],(e-s)+1); } s=n; } }
void ap_parse_pls(const FXString & data,FXStringList & mrl) { FXint start=0,end=0,pos,next; for (FXint i=0;i<data.length();i++) { if (data[i]=='\n') { end=i; next=i+1; /// Skip white space while(start<end && Ascii::isSpace(data[start])) start++; /// Skip white space while(end>start && Ascii::isSpace(data[end])) end--; /// Parse the actual line. if ((end-start)>6) { if (compare(&data[start],"File",4)==0) { pos = data.find('=',start+4); if (pos==-1) continue; pos++; if (end-pos>0) { mrl.append(data.mid(pos,1+end-pos)); } } } start=next; } } }
// Run ctags in each source directory void TagParserBase::ReadClasses() { CmdIO cmdio(mainwin); CmdStr cmd=CtagsCmd(); FXString currdir=FXSystem::getCurrentDirectory(); FXRex rx("\\.(c|cc|cpp|cxx|h|hh|hpp|hxx)$",FXRex::IgnoreCase); for (FXint i=0; i<DirList().no(); i++) { const FXString dir=DirList().at(i)->dirname(); if (dir.empty()) { continue; } if (FXSystem::setCurrentDirectory(dir)) { FXDir de(dir); if (de.isOpen()) { FXString fn; while (de.next(fn)) { if (FXStat::isFile(fn) && (rx.search(fn,0,fn.length())>=0)) { cmd+=fn.text(); } } de.close(); current_filename=FXString::null; cmdio.setUserData((void*)(FXival)i); cmdio.lines(cmd.text(),this,ID_READ_ALL_FILES_LINES); } } } FXSystem::setCurrentDirectory(currdir); }
FXString MFXUtils::getTitleText(const FXString &appname, FXString filename) throw() { if (filename.length()==0) { return appname; } return getDocumentName(filename) + " - " + appname; }
// Open directory to path, return true if ok. FXbool FXDir::open(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); wcsncat(buffer,TEXT("\\*"),MAXPATHLEN); #else FXchar buffer[MAXPATHLEN]; strncpy(buffer,path.text(),MAXPATHLEN); strncat(buffer,"\\*",MAXPATHLEN); #endif ((SPACE*)space)->handle=FindFirstFile(buffer,&((SPACE*)space)->result); if(((SPACE*)space)->handle!=INVALID_HANDLE_VALUE){ ((SPACE*)space)->first=true; return true; } #else ((SPACE*)space)->handle=opendir(path.text()); if(((SPACE*)space)->handle!=NULL){ return true; } #endif } return false; }
// Look for line number after filename in the form of FILE.EXT:NNN static void ParseLineNumberFromFilename(FXString &filename, FXString &line) { #ifdef WIN32 // Ignore colon in drive spec on WIN32 FXint colons=filename.contains(':'); if (FXPath::isAbsolute(filename)) { if (colons>1) { line=filename.section(':',2); filename=filename.section(':',0,2); } } else { if (colons>0) { line=filename.section(':',1) ; filename=filename.section(':',0); } } #else if (filename.contains(':')) { line=filename.section(':',1) ; filename=filename.section(':',0); } #endif for (FXint i=0; i<line.length(); i++) { if (!Ascii::isDigit(line[i])) { // If it's not all digits, forget it. line=FXString::null; break; } } }
void HttpInput::icy_parse(const FXString & str) { FXString title = str.after('=').before(';'); if (title.length()) { MetaInfo* meta = new MetaInfo(); meta->title = title; input->post(meta); } }
// Rename directory FXbool FXDir::rename(const FXString& srcpath,const FXString& dstpath){ if(srcpath!=dstpath){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[MAXPATHLEN],newname[MAXPATHLEN]; utf2ncs(oldname,MAXPATHLEN,srcpath.text(),srcpath.length()+1); utf2ncs(newname,MAXPATHLEN,dstpath.text(),dstpath.length()+1); return ::MoveFileExW(oldname,newname,MOVEFILE_REPLACE_EXISTING)!=0; #else return ::MoveFileExA(srcpath.text(),dstpath.text(),MOVEFILE_REPLACE_EXISTING)!=0; #endif #else return ::rename(srcpath.text(),dstpath.text())==0; #endif } return false; }
// Link file bool FXFile::link(const FXString& oldfile,const FXString& newfile){ if(newfile!=oldfile){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[1024],newname[1024]; utf2ncs(oldname,oldfile.text(),oldfile.length()+1); utf2ncs(newname,newfile.text(),newfile.length()+1); return MyCreateHardLink(newname,oldname,NULL)!=0; #else return MyCreateHardLink(newfile.text(),oldfile.text(),NULL)!=0; #endif #else return ::link(oldfile.text(),newfile.text())==0; #endif } return false; }
// Rename file bool FXFile::rename(const FXString& srcfile,const FXString& dstfile){ if(srcfile!=dstfile){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[1024],newname[1024]; utf2ncs(oldname,srcfile.text(),srcfile.length()+1); utf2ncs(newname,dstfile.text(),dstfile.length()+1); return ::MoveFileExW(oldname,newname,MOVEFILE_REPLACE_EXISTING)!=0; #else return ::MoveFileExA(srcfile.text(),dstfile.text(),MOVEFILE_REPLACE_EXISTING)!=0; #endif #else return ::rename(srcfile.text(),dstfile.text())==0; #endif } return false; }
// Return true if files are identical bool FXFile::identical(const FXString& file1,const FXString& file2){ if(file1!=file2){ #ifdef WIN32 BY_HANDLE_FILE_INFORMATION info1,info2; HANDLE hFile1,hFile2; bool same=false; #ifdef UNICODE FXnchar name1[1024],name2[1024]; utf2ncs(name1,file1.text(),file1.length()+1); utf2ncs(name2,file2.text(),file2.length()+1); hFile1=::CreateFile(name1,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile1!=INVALID_HANDLE_VALUE){ hFile2=::CreateFile(name2,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile2!=INVALID_HANDLE_VALUE){ if(::GetFileInformationByHandle(hFile1,&info1) && ::GetFileInformationByHandle(hFile2,&info2)){ same=(info1.nFileIndexLow==info2.nFileIndexLow && info1.nFileIndexHigh==info2.nFileIndexHigh && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber); } ::CloseHandle(hFile2); } ::CloseHandle(hFile1); } return same; #else hFile1=::CreateFile(file1.text(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile1!=INVALID_HANDLE_VALUE){ hFile2=::CreateFile(file2.text(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile2!=INVALID_HANDLE_VALUE){ if(::GetFileInformationByHandle(hFile1,&info1) && ::GetFileInformationByHandle(hFile2,&info2)){ same=(info1.nFileIndexLow==info2.nFileIndexLow && info1.nFileIndexHigh==info2.nFileIndexHigh && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber); } ::CloseHandle(hFile2); } ::CloseHandle(hFile1); } return same; #endif #else struct stat stat1,stat2; return !::lstat(file1.text(),&stat1) && !::lstat(file2.text(),&stat2) && stat1.st_ino==stat2.st_ino && stat1.st_dev==stat2.st_dev; #endif } return true; }
void CCLCFox::unlockWithPass(FXString login,FXString password) { if (login.length() > MAX_INP_SIZE) login.trunc(MAX_INP_SIZE); const char *login_name = login.text(); char val[strlen(login_name) * sizeof(char) + 1 + CCLC_MD5_DIGEST_LENGTH * sizeof(FXuchar)]; FXuchar digest[CCLC_MD5_DIGEST_LENGTH]; CCLC_MD5((FXuchar*)(password.text()),password.length(),digest); memcpy(val,login_name,strlen(login_name) + 1); memcpy(val + strlen(login_name) + 1,digest,CCLC_MD5_DIGEST_LENGTH); CCLC_send_cmd(CC_MEMBERLOGINWITHNAME,val,sizeof(val) * sizeof(char)); if (!strncmp(login_name, _("administrator"), 13)){ if (checkPass((char *)password.text(), password.length())) unlockScreen(); //unlock all the same } }
void CCLCFox::unlockWithPass(int id,FXString password) { char val[sizeof(id) + CCLC_MD5_DIGEST_LENGTH * sizeof(FXuchar)]; FXuchar digest[CCLC_MD5_DIGEST_LENGTH]; CCLC_MD5((FXuchar*)(password.text()),password.length(),digest); ((FXuint*)val)[0] = CCLC_htonl(id); memcpy(((FXuint*)val)+1,digest,CCLC_MD5_DIGEST_LENGTH); CCLC_send_cmd(CC_MEMBERLOGIN,val,sizeof(val) * sizeof(char)); }
FXString MFXUtils::assureExtension(const FXString &filename, const FXString &defaultExtension) throw() { FXString ext = FXPath::extension(filename); if (ext=="") { if (filename.rfind('.')==filename.length()-1) { return filename + defaultExtension; } return filename + "." + defaultExtension; } return filename; }
// Draw multi-line label, with underline for hotkey void FXLabel::drawLabel(FXDCWindow& dc,const FXString& text,FXint hot,FXint tx,FXint ty,FXint tw,FXint){ register FXint beg,end; register FXint xx,yy; yy=ty+font->getFontAscent(); beg=0; do{ end=beg; while(end<text.length() && text[end]!='\n') end++; if(options&JUSTIFY_LEFT) xx=tx; else if(options&JUSTIFY_RIGHT) xx=tx+tw-font->getTextWidth(&text[beg],end-beg); else xx=tx+(tw-font->getTextWidth(&text[beg],end-beg))/2; dc.drawText(xx,yy,&text[beg],end-beg); if(beg<=hot && hot<end){ dc.fillRectangle(xx+font->getTextWidth(&text[beg],hot-beg),yy+1,font->getTextWidth(&text[hot],wclen(&text[hot])),1); } yy+=font->getFontHeight(); beg=end+1; } while(end<text.length()); }
long FXLinkLabel::onLeftBtnPress(FXObject*,FXSelector,void*) { FXString link = getTipText(); if (link.length()) { getApp()->beginWaitCursor(); if (fxexecute(link)) getApp()->addTimeout(this,ID_TIMER,2000); // 2 seconds of way cursor else { getApp()->endWaitCursor(); getApp()->beep(); } } return 1; }
// Convert utf8 characters at src to multi-byte string FXString FXTextCodec::utf2mb(const FXchar* src,FXint nsrc) const { register FXint len; if(src && 0<nsrc){ if((len=utf2mblen(src,nsrc))>0){ FXString result; result.length(len); if(utf2mb(&result[0],len,src,nsrc)>0){ return result; } } } return FXString::null; }
FXbool ID3V2::parse_text(FXint encoding,const FXchar * buffer,FXint length,FXString & text){ switch(encoding) { case ISO_8859_1 : { FX88591Codec codec; FXint n = codec.mb2utflen(buffer,length); if (n>0) { text.length(n); codec.mb2utf(text.text(),text.length(),buffer,length); } } break; case UTF16_BOM : { FXUTF16Codec codec; FXint n = codec.mb2utflen(buffer,length); if (n>0) { text.length(n); codec.mb2utf(text.text(),text.length(),buffer,length); } } break; case UTF16 : { FXUTF16BECodec codec; FXint n = codec.mb2utflen(buffer,length); if (n>0) { text.length(n); codec.mb2utf(text.text(),text.length(),buffer,length); } } break; case UTF8 : { FXUTF8Codec codec; FXint n = codec.mb2utflen(buffer,length); if (n>0) { text.length(n); codec.mb2utf(text.text(),text.length(),buffer,length); } } break; default: return false; } return true; }
// Construct a dialog box with an optional check box HistInputDialog::HistInputDialog(FXWindow* w,FXString inp,FXString message,FXString title,FXString label,FXIcon *ic, FXuint browse, FXbool option, FXString optiontext): DialogBox(w,title,DECOR_TITLE|DECOR_BORDER|DECOR_STRETCHABLE) { // Browse type flag browsetype=browse; // Buttons buttons=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X,0,0,0,0,10,10,5,5); // Accept new FXButton(buttons,_("&Accept"),NULL,this,ID_ACCEPT,FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT,0,0,0,0,20,20); // Cancel new FXButton(buttons,_("&Cancel"),NULL,this,ID_CANCEL,FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT,0,0,0,0,20,20); // Separator new FXHorizontalSeparator(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|SEPARATOR_GROOVE); // Optional check box checkbutton=new FXHorizontalFrame(this,JUSTIFY_RIGHT|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X,0,0,0,0,10,10,0,0); if (option) new FXCheckButton(checkbutton,optiontext,this,ID_TOGGLE_OPTION); // Vertical frame FXVerticalFrame *contents=new FXVerticalFrame(this,LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y); // Icon and first line FXMatrix *matrix1 = new FXMatrix(contents,2,MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y); new FXLabel(matrix1,"",ic,LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW); new FXLabel(matrix1,message,NULL,JUSTIFY_LEFT|LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW); new FXLabel(matrix1,label,NULL,LAYOUT_RIGHT|LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW); // Label and input field (combo box) FXMatrix *matrix2 = new FXMatrix(contents,3,MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y); new FXLabel(matrix2,label,NULL,LAYOUT_LEFT|LAYOUT_CENTER_Y|LAYOUT_FILL_ROW); input = new ComboBox(matrix2,40,NULL,0,COMBOBOX_INSERT_LAST|LAYOUT_CENTER_Y|LAYOUT_CENTER_X|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|LAYOUT_FILL_X); input->setNumVisible(5); input->setText(inp); new FXButton(matrix2,_("\tSelect destination..."),filedialogicon,this,ID_BROWSE_PATH,FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT|LAYOUT_CENTER_Y,0,0,0,0,20,20); if (!isUtf8(message.text(),message.length())) new FXLabel(contents,_("=> Warning: file name is not UTF-8 encoded!"),NULL,LAYOUT_LEFT|LAYOUT_CENTER_Y|LAYOUT_FILL_ROW); // Initial directory for browsing FXString homelocation=getenv("HOME"); if(homelocation=="") homelocation=ROOTDIR; initialdir=homelocation; }
FXint fxexecute(FXString link) { #ifdef WIN32 FXString quoted = FXPath::enquote(link); FXint ret = (int)ShellExecute(NULL,"open",quoted.text(),NULL,NULL,SW_SHOW) > 32; return ret; #else FXString ext = FXPath::extension(link); FXString list; if (comparecase(link.section(':',0), "http")==0 || comparecase(link.section(':',0), "ftp")==0 || comparecase(ext, "htm")==0 || comparecase(ext, "html")==0 || comparecase(ext, "php")==0 || comparecase(ext, "asp")==0) list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx"; else if (comparecase(ext, "pdf")==0) list = "acroread\tkghostview\tgpdf\txpdf"; if (list.length()) { FXString software; FXint index=0; FXString path = FXSystem::getExecPath(); software = list.section("\t",index); while (!software.empty()) { software = FXPath::search(path, software); if (software.length()) return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ", software.text(),link.text()).text())>0?0:1; index++; software = list.section("\t",index); } } else if (FXStat::isExecutable(link)) return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0:1; return 0; #endif }
void flushSegment() { if (segment.length() > 0) { if (justWhiteSpace) { // optimise styleCurrent = stylePrev; } else { pageData += segStyle; } pageData += "("; pageData += segment; pageData += ")Tj\n"; } segment.clear(); *segStyle = '\0'; justWhiteSpace = true; }
// Remove a file bool FXFile::remove(const FXString& file){ if(!file.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[1024]; utf2ncs(buffer,file.text(),file.length()+1); return ::DeleteFileW(buffer)!=0; #else return ::DeleteFileA(file.text())!=0; #endif #else return ::unlink(file.text())==0; #endif } return false; }
// Create new directory FXbool FXDir::create(const FXString& path,FXuint perm){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); return CreateDirectoryW(buffer,NULL)!=0; #else return CreateDirectoryA(path.text(),NULL)!=0; #endif #else return ::mkdir(path.text(),perm)==0; #endif } return false; }
// Change current directory FXbool FXSystem::setCurrentDirectory(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE TCHAR buffer[MAXPATHLEN]; utf2ncs(buffer,path.text(),path.length()+1); return SetCurrentDirectory(buffer); #else return SetCurrentDirectory(path.text()); #endif #else return chdir(path.text())==0; #endif } return FALSE; }
// Remove directory FXbool FXDir::remove(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); return RemoveDirectoryW(buffer)!=0; #else return RemoveDirectoryA(path.text())!=0; #endif #else return ::rmdir(path.text())==0; #endif } return false; }