void GMSourceView::init() { loadSettings("window"); clear(); listsources(); FXString key = getApp()->reg().readStringEntry("window","source-list-current",""); if (!key.empty()){ FXTreeItem * item = sourcelist->getFirstItem(); while(item){ GMSource * src = static_cast<GMSource*>(item->getData()); if (src->settingKey()==key) { sourcelist->setCurrentItem(item); break; } item=item->getBelow(); } } if (sourcelist->getCurrentItem()==nullptr && sourcelist->getFirstItem()) sourcelist->setCurrentItem(sourcelist->getFirstItem()); source=static_cast<GMSource*>(sourcelist->getItemData(sourcelist->getCurrentItem())); GMPlayerManager::instance()->getTrackView()->init(source); }
void ID3V2::parse_comment_frame(FXint framesize) { FXString key,field; const FXuchar & encoding = buffer[p]; const FXchar* textstart = (const FXchar*)(buffer+p+4); const FXint textlength = framesize - 4; if (encoding==UTF16_BOM || encoding==UTF16) { FXint ksize = strwlen(textstart,textlength); FXint vsize = strwlen(textstart+ksize+2,textlength-ksize-2); parse_text(encoding,textstart,ksize,key); parse_text(encoding,textstart+ksize+2,vsize,field); } else { FXint ksize = strnlen(textstart,textlength); FXint vsize = strnlen(textstart+ksize+1,textlength-ksize-1); parse_text(encoding,textstart,ksize,key); parse_text(encoding,textstart+ksize+1,vsize,field); } FXString comment = key + " " + field; if (comment.find("iTunSMPB")>=0) { comment.simplify().scan("iTunSMPB %*x %hx %hx %lx",&padstart,&padend,&length); GM_DEBUG_PRINT("[id3v2] found iTunSMPB (padding %d %d, length %ld)\n",padstart,padend,length); } }
long fx_numeric_field::change_on_digit(int sign) { FXString txt = getText(); int pos = getCursorPos(); int pow_exp, dot_pos; int norm = get_normalized_int (txt.text(), pow_exp, dot_pos); if (dot_pos < 0) return 0; int pos_exp = dot_pos - pos; if (pos_exp < 0) pos_exp ++; int inc_abs = ipow10 (pos_exp + pow_exp); norm += sign * inc_abs; FXString new_txt = denormalize (norm, pow_exp, dot_pos); int new_pos = dot_pos - pos_exp; if (pos_exp < 0) new_pos ++; setText(new_txt); setCursorPos(new_pos); if (target) target->tryHandle(this, FXSEL(SEL_CHANGED,message), (void*)new_txt.text()); return 1; }
long GNETLSEditorFrame::onCmdPhaseEdit(FXObject*, FXSelector, void* ptr) { /* @note: there is a bug when copying/pasting rows: when this handler is * called the value of the cell is not yet updated. This means you have to * click inside the cell and hit enter to actually update the value */ FXTablePos* tp = (FXTablePos*)ptr; FXString value = myPhaseTable->getItemText(tp->row, tp->col); if (tp->col == 0) { // duration edited if (GNEAttributeCarrier::canParse<SUMOReal>(value.text())) { SUMOTime duration = getSUMOTime(value); if (duration > 0) { myEditedDef->getLogic()->setPhaseDuration(tp->row, duration); myHaveModifications = true; updateCycleDuration(); return 1; } } // input error, reset value myPhaseTable->setItemText(tp->row, 0, toString(STEPS2TIME(getPhases()[tp->row].duration)).c_str()); } else { // state edited try { // insert phase with new step and delete the old phase myEditedDef->getLogic()->addStep(getPhases()[tp->row].duration, value.text(), tp->row); myEditedDef->getLogic()->deletePhase(tp->row + 1); myHaveModifications = true; onCmdPhaseSwitch(0, 0, 0); } catch (ProcessError) { // input error, reset value myPhaseTable->setItemText(tp->row, 1, getPhases()[tp->row].state.c_str()); } } return 1; }
// Convert the deletion date to the number of seconds since the epoch // The string representing the deletion date must be in the format YYYY-MM-DDThh:mm:ss long deltime(FXString delstr) { // Decompose the date into year, month, day, hour, minutes and seconds FXString year=delstr.mid(0,4); FXString mon=delstr.mid(5,2); FXString mday=delstr.mid(8,2); FXString hour=delstr.mid(11,2); FXString min=delstr.mid(14,2); FXString sec=delstr.mid(17,2); // Convert date using mktime() tm tmval; tmval.tm_sec=atoi(sec.text()); tmval.tm_min=atoi(min.text()); tmval.tm_hour=atoi(hour.text()); tmval.tm_mday=atoi(mday.text()); tmval.tm_mon=atoi(mon.text()); tmval.tm_year=atoi(year.text())-1900; tmval.tm_isdst=0; long t=(long)mktime(&tmval); // If conversion failed, return 0 if (t<0) t=0; return t; }
void PlaybackWindow::setPlaybackPacketsProcessed(unsigned int packets) { FXString s; s.format("Processed %u of %u", packets_processed, total_packets); processedLabel->setText(s); }
void InputThread::ctrl_open_input(const FXString & uri) { GM_DEBUG_PRINT("[input] ctrl_open_input %s\n",uri.text()); if (uri.empty()) { goto failed; } /// Open Input input=open_input(uri); if (input==NULL) { engine->post(new ErrorMessage(FXString::value("Unable to open %s",uri.text()))); goto failed; } reader = open_reader(); if (reader==NULL) { engine->post(new ErrorMessage(FXString::value("No input plugin available for %s",uri.text()))); goto failed; } if (!reader->init(input)) { engine->post(new ErrorMessage(FXString::value("Failed to initialize plugin"))); goto failed; } streamid++; set_state(StateProcessing,true); return; failed: ctrl_close_input(); set_state(StateIdle,true); }
bool checkPass(char *pass, int plen) { char pstr[64]; FILE *fp; FXString pname; pname = FXSystem::getHomeDirectory() + "/.mkahawa/mkahawa.inf"; fp = fopen(pname.text(), "r"); if (fp){ FXuchar digest[CCLC_MD5_DIGEST_LENGTH]; CCLC_MD5((FXuchar*)(pass), plen, digest); fread(pstr, CCLC_MD5_DIGEST_LENGTH, 1, fp); if (plen > CCLC_MD5_DIGEST_LENGTH) plen = CCLC_MD5_DIGEST_LENGTH; if (!memcmp(pstr, digest, plen)) return TRUE; fclose(fp); #ifdef DEBUG_PASS printf("Realpass Hash: "); print_hash((unsigned char *)digest, CCLC_MD5_DIGEST_LENGTH); printf("\n"); printf("Testpass Hash: "); print_hash((unsigned char *)pstr, CCLC_MD5_DIGEST_LENGTH); printf("\n"); #endif } return FALSE; }
void GenesisFrame::setOverrideOptions(void) { if (m_useOverride->getCheck()) { if (m_overrideGenesis->getCheck()) m_commandLineHandler->addOption("--gen"); if (m_overrideHeaderSize->getCheck()) { char option[80]; FXString text = m_overrideHeaderSizeText->getText(); sprintf(option, "--hdn=%s", text.text()); m_commandLineHandler->addOption(option); } if (m_overrideHeader->getCheck()) m_commandLineHandler->addOption("--hd"); if (m_overrideNoHeader->getCheck()) m_commandLineHandler->addOption("--nhd"); if (m_overrideNotSplit->getCheck()) m_commandLineHandler->addOption("--ns"); if (m_overrideInterleaved->getCheck()) m_commandLineHandler->addOption("--int"); if (m_overrideInterleaved2->getCheck()) m_commandLineHandler->addOption("--int2"); if (m_overrideNotInterleaved->getCheck()) m_commandLineHandler->addOption("--nint"); } }
// 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); }
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; } } }
// Strip pattern from text if present FXString FXFileSelector::patternFromText(const FXString& pattern){ FXint beg,end; end=pattern.rfind(')'); // Search from the end so we can allow ( ) in the pattern name itself beg=pattern.rfind('(',end-1); if(0<=beg && beg<end) return pattern.mid(beg+1,end-beg-1); return pattern; }
// 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; }
// Go to next directory entry and return its name FXbool FXDir::next(FXString& name){ if(isOpen()){ #ifdef WIN32 if(((SPACE*)space)->first || FindNextFile(((SPACE*)space)->handle,&((SPACE*)space)->result)){ ((SPACE*)space)->first=false; name.assign(((SPACE*)space)->result.cFileName); return true; } #else #if defined(FOX_THREAD_SAFE) && !defined(__FreeBSD__) && !defined(__OpenBSD__) if(!readdir_r(((SPACE*)space)->handle,&((SPACE*)space)->result,&((SPACE*)space)->dp) && ((SPACE*)space)->dp){ name.assign(((SPACE*)space)->dp->d_name); return true; } #else if((((SPACE*)space)->dp=readdir(((SPACE*)space)->handle))!=NULL){ name.assign(((SPACE*)space)->dp->d_name); return true; } #endif #endif } name.clear(); return false; }
static void update_textfield(fx_numeric_field *tf, fx_disp_window *disp_win, int param_id) { FXString vstr; double *pvalue = disp_win->map_parameter(param_id); vstr.format("%g", *pvalue); tf->setText(vstr); }
/* Fox doesn't automatically handle MS-Windows shortcut files, so... Iterate through each filename in the file dialog's getFilenames() list, if any of them are shortcut (*.lnk) files, dereference the link and make the string point to the "real" disk file. If we have multiple files, remove any links that point to a directory. But if we only have one string in the list, and the string is a link pointing to a directory, we will dereference it so the dialog can change into that folder. */ static void FixupShortcuts(FXWindow*w, FXString* filenames) { if (!filenames) return; FXString* fn; FXString* tail=filenames; FXuint count=0; for (fn=filenames; !fn->empty(); fn++) { if (IsLinkExt(*fn)) { char*tmp=NULL; if (ReadShortcut(&tmp, fn->text())) { *fn=tmp; } else { FXMessageBox::error(w,MBOX_OK,_("Error in shortcut"),"%s\n%s",fn->text(),tmp); } free(tmp); } tail=fn; count++; } if (count>1) { for (fn=filenames; !fn->empty(); fn++) { if (FXStat::isDirectory(*fn)) { *fn=tail->text(); *tail=""; tail--; } } } }
long GenesisFrame::onName(FXObject *a_src, FXSelector, void *) { if (m_commandLineHandler->busy()) return 1; char *name, option[80]; FXString text; if (a_src == m_changeForeignName) text = m_foreignName->getText(); else text = m_JapaneseName->getText(); name = (char *) text.text(); if (!name[0]) // don't use trim() -- name may start/end with space { FXMessageBox::warning(this, MBOX_OK, "No name specified", "Please specify a name"); return 1; } if (strlen(name) >= 80) name[80 - 1] = 0; // it would be 100% correct if we used two hyphens for -n2 #ifdef __unix__ sprintf(option, "-n%s=%s", a_src == m_changeJapaneseName ? "2" : "", name); #else sprintf(option, "-n%s=\"%s\"", a_src == m_changeJapaneseName ? "2" : "", name); #endif m_commandLineHandler->setOption(option, true); setOverrideOptions(); m_commandLineHandler->run(); return 1; }
long setAdminPass(char *pass, int plen) { FXString path = FXSystem::getHomeDirectory() + "/.mkahawa"; FXString fname = "mkahawa.inf"; #ifdef DEBUG_PASS printf("setAdminPass(): pass = %s\n", pass); #endif if (!FXStat::exists(path)) if (!FXDir::create(path, FXIO::OwnerFull)) return 0; path += "/" + fname; if (!FXStat::exists(path)) if (!FXFile::create(path,FXIO::OwnerFull)) return 0; FILE *fp = fopen(path.text(), "w"); if (fp){ FXuchar digest[CCLC_MD5_DIGEST_LENGTH]; memset(digest, 0, CCLC_MD5_DIGEST_LENGTH); CCLC_MD5((FXuchar*)(pass), plen, digest); fwrite(digest, CCLC_MD5_DIGEST_LENGTH , 1, fp); #ifdef DEBUG_PASS printf("setAdminPass()\n"); printf("Testpass Hash: "); print_hash((unsigned char *)digest, CCLC_MD5_DIGEST_LENGTH); printf("\n"); #endif fclose(fp); } return 1; }
long GenesisFrame::onReceive(FXObject *, FXSelector, void *) { if (m_commandLineHandler->busy()) return 1; FXString text = FileDialog::getSaveFilename(this, "Specify file name to write to", "dummy"); char *filename = (char *) text.text(); if (!filename[0]) return 1; else if (FXStat::exists(filename)) { FXMessageBox::warning(this, MBOX_OK, "File already exists", "Please specify a different file name"); return 1; } setTransferOption(false); setOverrideOptions(); char *ptr; #ifdef __unix__ ptr = filename; #else { char option[FILENAME_MAX + 3]; sprintf(option, "\"%s\"", filename); ptr = option; } #endif m_commandLineHandler->addOption(ptr); m_commandLineHandler->run(); return 1; }
// Parse emacs modeline FXbool Modeline::parseEmacsModeline(const FXchar* s){ FXString key; FXString val; while(*s!='\0'){ while(*s==';' || *s=='\t' || *s==' ') s++; if(*s=='\0' || (*s=='-' && *(s+1)=='*' && *(s+2)=='-')) break; key=FXString::null; val=FXString::null; while(*s!='\0' && *s!=':' && *s!=';' && *s!='\t' && *s!=' '){ key+=*s++; } while(*s=='\t' || *s==' ') s++; if(*s=='\0') break; if(*s!=':') continue; s++; while(*s=='\t' || *s==' ') s++; if(*s=='\0') break; while(*s!='\0' && *s!=';' && *s!='\t' && *s!=' '){ val+=*s++; } if(comparecase(key,"Mode")==0){ setLanguage(val); } else if(key=="tab-width"){ setTabWidth(val.toInt()); } else if(key=="indent-tabs-mode"){ setTabMode(val=="nil"); } else if(key=="autowrap"){ setWrapMode(val!="nil"); } } return true; }
static void requote(FXString&s) { s.substitute("\\", "\\\\", true); s.substitute("\n", "\\n", true); s.substitute("\r", "\\r", true); s.substitute("\"", "\\\"", true); }
// Get home directory for a given user FXString FXSystem::getUserDirectory(const FXString& user){ #ifndef WIN32 #if defined(FOX_THREAD_SAFE) && !defined(__FreeBSD__) && !defined(__OpenBSD__) struct passwd pwdresult,*pwd; char buffer[1024]; if(user.empty()){ register const FXchar* str; if((str=getenv("HOME"))!=NULL) return str; if((str=getenv("USER"))!=NULL || (str=getenv("LOGNAME"))!=NULL){ if(getpwnam_r(str,&pwdresult,buffer,sizeof(buffer),&pwd)==0 && pwd) return pwd->pw_dir; } if(getpwuid_r(getuid(),&pwdresult,buffer,sizeof(buffer),&pwd)==0 && pwd) return pwd->pw_dir; return PATHSEPSTRING; } if(getpwnam_r(user.text(),&pwdresult,buffer,sizeof(buffer),&pwd)==0 && pwd) return pwd->pw_dir; return PATHSEPSTRING; #else register struct passwd *pwd; if(user.empty()){ register const FXchar* str; if((str=getenv("HOME"))!=NULL) return str; if((str=getenv("USER"))!=NULL || (str=getenv("LOGNAME"))!=NULL){ if((pwd=getpwnam(str))!=NULL) return pwd->pw_dir; } if((pwd=getpwuid(getuid()))!=NULL) return pwd->pw_dir; return PATHSEPSTRING; } if((pwd=getpwnam(user.text()))!=NULL) return pwd->pw_dir; return PATHSEPSTRING; #endif #else if(user.empty()){ register const FXchar *str1,*str2; FXchar home[MAXPATHLEN]; DWORD size=MAXPATHLEN; HKEY hKey; LONG result; if((str1=getenv("USERPROFILE"))!=NULL) return str1; // Daniël Hörchner <*****@*****.**> if((str1=getenv("HOME"))!=NULL) return str1; if((str2=getenv("HOMEPATH"))!=NULL){ // This should be good for WinNT, Win2K according to MSDN if((str1=getenv("HOMEDRIVE"))==NULL) str1="c:"; strncpy(home,str1,MAXPATHLEN); strncat(home,str2,MAXPATHLEN); return home; } // FXchar buffer[MAX_PATH] // if(SHGetFolderPath(NULL,CSIDL_PERSONAL|CSIDL_FLAG_CREATE,NULL,O,buffer)==S_OK){ // return buffer; // } if(RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",0,KEY_READ,&hKey)==ERROR_SUCCESS){ result=RegQueryValueExA(hKey,"Personal",NULL,NULL,(LPBYTE)home,&size); // Change "Personal" to "Desktop" if you want... RegCloseKey(hKey); if(result==ERROR_SUCCESS) return home; } return "c:" PATHSEPSTRING; } return "c:" PATHSEPSTRING; #endif }
// Symbolic Link file bool FXFile::symlink(const FXString& oldfile,const FXString& newfile){ if(newfile!=oldfile){ #ifndef WIN32 return ::symlink(oldfile.text(),newfile.text())==0; #endif } return false; }
// Remove anything containing a colon : from the beginning of the string. // Returns number of colons removed. FXint TagParserBase::StripNamespace(FXString &s) { FXint rv=s.contains(':'); if (rv) { s.erase(0,s.rfind(':')+1); } return rv; }
// Return list of patterns FXString FXFileSelector::getPatternList() const { FXString pat; for(FXint i=0; i<filefilter->getNumItems(); i++){ if(!pat.empty()) pat+='\n'; pat+=filefilter->getItemText(i); } return pat; }
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); } }
// Return true if files are identical // Compare file names and inodes for case insensitive filesystems FXbool identical(const FXString& file1,const FXString& file2) { if(file1!=file2) { struct stat linfo1, linfo2; return !::lstatrep(file1.text(),&linfo1) && !::lstatrep(file2.text(),&linfo2) && linfo1.st_ino==linfo2.st_ino && linfo1.st_dev==linfo2.st_dev; } return TRUE; }
long fit_panel::on_cmd_spectral_range(FXObject *, FXSelector, void*) { FXString s = m_wl_entry->getText(); if(update_spectral_range(s.text())) { return 1; } return 0; }
FXFileAssoc* findFileBinding(const FXString& pathname){ FXString ext = FXPath::extension(pathname); if (!ext.empty()) { FXFileAssoc * record = NULL; if ((record = bindings[ext])!=NULL) return record; if ((record = bindings[ext.lower()])!=NULL) return record; } return bindings[defaultFileBinding]; }
// Copy ordinary file static FXbool copyfile (const FXString & oldfile, const FXString & newfile, thread_elem * te) { unsigned char buffer[4096]; struct stat status; long nread, nwritten; int src, dst; FXbool ok = FALSE; if ((src = open (oldfile.text (), O_RDONLY)) >= 0) { if (::stat (oldfile.text (), &status) == 0) { te->act_file_name = oldfile.text (); te->act_file_size = 1; te->file_size = status.st_size; if ((dst = open (newfile.text (), O_WRONLY | O_CREAT | O_TRUNC, status.st_mode)) >= 0) { while (1) { nread = fullread (src, buffer, sizeof (buffer)); if (nread < 0) goto err; if (nread == 0) break; if (te->cancel == true) { fxmessage ("CANCEL CANCEL CANCEL CANCEL !!!\n\n\n\n\n"); close (dst); close (src); return FALSE; } te->act_file_size += nread; te->act_total_size += nread; nwritten = fullwrite (dst, buffer, nread); if (nwritten < 0) goto err; } ok = TRUE; err:close (dst); } } close (src); } return ok; }