static gboolean read_proc(battery_priv *c, GString *path) { int len, lfcap, rcap; gchar *buf; gboolean ret, exist, charging; ENTER; len = path->len; g_string_append(path, "/info"); ret = g_file_get_contents(path->str, &buf, 0, NULL); DBG("reading %s %s\n", path->str, ret ? "ok" : "fail"); g_string_truncate(path, len); if (!ret) RET(FALSE); ret = get_token_eq(buf, "present:", "yes", &exist) && exist && get_token_int(buf, "last full capacity:", &lfcap); g_free(buf); if (!ret) RET(FALSE); g_string_append(path, "/state"); ret = g_file_get_contents(path->str, &buf, 0, NULL); DBG("reading %s %s\n", path->str, ret ? "ok" : "fail"); g_string_truncate(path, len); if (!ret) RET(FALSE); ret = get_token_eq(buf, "present:", "yes", &exist) && exist && get_token_int(buf, "remaining capacity:", &rcap) && get_token_eq(buf, "charging state:", "charging", &charging); g_free(buf); if (!ret) RET(FALSE); DBG("battery=%s\nlast full capacity=%d\nremaining capacity=%d\n" "charging=%d\n", path->str, lfcap, rcap, charging); if (!(lfcap >= rcap && lfcap > 0 && rcap >= 0)) RET(FALSE); c->exist = TRUE; c->charging = charging; c->level = (int) ((gfloat) rcap * 100 / (gfloat) lfcap); RET(TRUE); }
// =========================================================================== void receiver::OnLbnSelchangeGroups() // =========================================================================== { CString str,buf,name,fido; int sel; GET_SEL(m_groups); m_groups.GetText(sel,str); get_token(str,0,buf); m_edit_group.SetWindowText(buf); m_members.ResetContent(); for (int i=1;i<=get_token_int(str,1);i++) { get_token(str,i*2,name); get_token(str,i*2+1,fido); buf=name+"\t"+fido; m_members.AddString(buf); } m_edit_name.SetWindowText(""); m_edit_fido.SetWindowText(""); }