QString contact_profile::get_contact_name() const { if (!get_friendly().trimmed().isEmpty()) return get_friendly(); if (!get_displayid().trimmed().isEmpty()) return get_displayid(); if (!get_first_name().trimmed().isEmpty()) return get_first_name() + " " + get_last_name(); return get_aimid(); }
void Human::show() { cout << "--------------------------------------------------\n" << get_name() << " " << get_last_name() << " "; if (sex == 1) cout << "male "; else if (sex == 2) cout << "female "; cout << get_age() << "\n"; cout << "\n"; if (get_nfavorite_books() != 0) { cout << get_nfavorite_books() << " favorite books:\n"; for (int i = 0; i < get_nfavorite_books(); i++) cout << i + 1 << ". " << get_favorite_books()[i] << "\n"; cout << "\n"; } }
void *DataManager::do_dl_thread( void * parameter) { int i; char buf[128]; pthread_detach(pthread_self()); pthread_mutex_t mutex; pthread_mutex_init(&mutex,NULL); SongInfo *pSongs = SongRndList; int size = 0; while(1) { if(start_dl_flag && pDownList) { pSongs = pDownList; size = pSongs->size; for(i=0; i<size; i++) { if(restart_dl_flag) break; get_last_name(pSongs->location, buf); if(pSongs->album_logo) downloadSong(buf, pSongs->album_logo, FILE_TYPE_LOGO); if(strlen(pSongs->lyric) > 6) downloadSong(buf, pSongs->lyric, FILE_TYPE_LYRIC); pSongs++; } pthread_mutex_lock(&mutex); if(i == size) { // turn off dl flag, finished start_dl_flag = false; }else { printf("*** restart dl list\n"); restart_dl_flag = false; // already update the dl list, restart } pthread_mutex_unlock(&mutex); } sleep(1); } return NULL; }
static int process_file(const unsigned char *path) { FILE *in = 0; int err_count = 0; int i, is_first, col, state; if (current_file_path) { free(current_file_path); } current_file_path = get_last_name(path); lineno = -1; in = fopen(path, "r"); if (!in) { err("failed to open file"); return -1; } file_buf_u = 0; lineno = 0; while (read_line(in, &err_count) >= 0) { ++lineno; //if (line_buf_u <= 0) continue; while (line_buf_u > 0 && valid_space(line_buf[line_buf_u - 1])) { --line_buf_u; } line_buf[line_buf_u] = 0; //if (line_buf_u <= 0) continue; if (line_buf_u > 0 && line_buf[line_buf_u - 1] == '\t') { err("invalid TAB character at the end of line"); ++err_count; } else if (line_buf_u > 0 && line_buf[line_buf_u - 1] < ' ') { err("invalid control character at the end of line"); ++err_count; } while (line_buf_u > 0 && line_buf[line_buf_u - 1] <= ' ') { --line_buf_u; } line_buf[line_buf_u] = 0; //if (line_buf_u <= 0) continue; if (line_buf_u > max_line_length) { err("line length exceeds %d characters", max_line_length); ++err_count; } for (i = 0; i < line_buf_u; ++i) { if (disable_tabs && line_buf[i] == '\t') { err("invalid TAB character"); ++err_count; } else if (line_buf[i] < ' ' && line_buf[i] != '\t') { err("invalid control character"); ++err_count; line_buf[i] = ' '; } } if (file_buf_u + line_buf_u + 2 > file_buf_a) { if (file_buf_a <= 0) file_buf_a = 4096; while (file_buf_u + line_buf_u + 2 > file_buf_a) { file_buf_a *= 2; } file_buf = (unsigned char*) realloc(file_buf, file_buf_a); if (!file_buf) die("out of memory"); } memcpy(file_buf + file_buf_u, line_buf, line_buf_u); file_buf_u += line_buf_u; file_buf[file_buf_u++] = '\n'; file_buf[file_buf_u] = 0; /* pos = 0; i = 0; while (line_buf[i] && line_buf[i] <= ' ') { if (line_buf[i] == '\t') { ++i; // default tab is 8 characters pos = (pos + 8) & ~7; } else { ++i; ++pos; } } */ } // check for stray backslash at the end of line lineno = 1; for (i = 0; i < file_buf_u; ++i) { if (i >= 2 && file_buf[i] == '\n' && file_buf[i - 1] == '\\' && file_buf[i - 2] == '\\') { file_buf[i - 2] = ' '; file_buf[i - 1] = ' '; file_buf[i] = ' '; err("\\\\ at the end of line"); ++err_count; ++lineno; } else if (i >= 1 && file_buf[i] == '\n' && file_buf[i - 1] == '\\') { file_buf[i - 1] = ' '; err("stray \\ at the end of line"); ++err_count; ++lineno; } else if (file_buf[i] == '\n') { ++lineno; } } lineno = 1; is_first = 1; col = 0; state = STATE_NORMAL; for (i = 0; i < file_buf_u; ++i) { if (file_buf[i] == '\n') { ++lineno; is_first = 1; col = 0; if (state == STATE_LINE_COMMENT) { state = STATE_NORMAL; } else if (state == STATE_STRING) { err("invalid \\n character inside a string"); ++err_count; } else if (state == STATE_CHAR) { err("invalid \\n character inside a character"); ++err_count; } } else if (file_buf[i] == '\t') { col = (col + 8) & ~7; } else if (file_buf[i] <= ' ') { ++col; } else { if (state == STATE_NORMAL && is_first && col % base_indent != 0) { err("invalid indentation (%d)", col); ++err_count; } is_first = 0; if (file_buf[i] == '\\') { if (!file_buf[i + 1]) { err("stray \\ at the end of file"); ++err_count; ++col; } else { ++i; col += 2; } } else if (state == STATE_NORMAL && file_buf[i] == '/' && file_buf[i + 1] == '/') { state = STATE_LINE_COMMENT; col += 2; ++i; } else if (state == STATE_NORMAL && file_buf[i] == '/' && file_buf[i + 1] == '*') { state = STATE_COMMENT; col += 2; ++i; } else if (state == STATE_COMMENT && file_buf[i] == '*' && file_buf[i + 1] == '/') { state = STATE_NORMAL; col += 2; ++i; } else if (state == STATE_NORMAL && file_buf[i] == '\'') { state = STATE_CHAR; ++col; } else if (state == STATE_CHAR && file_buf[i] == '\'') { state = STATE_NORMAL; ++col; } else if (state == STATE_NORMAL && file_buf[i] == '\"') { state = STATE_STRING; ++col; } else if (state == STATE_STRING && file_buf[i] == '\"') { state = STATE_NORMAL; ++col; } else { ++col; } } } //fprintf(stdout, ">>%s<<\n", file_buf); fclose(in); in = 0; return -err_count; }