static int _set_where_with_info (const OlMusicInfo *info, char *where, size_t size) { ol_assert_ret (info->title != NULL, -1); ol_assert_ret (where != NULL, -1); int cnt = 0; if (info->title == NULL) { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, "title is NULL"); } else { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, "title = "); cnt += _copy_str (where + cnt, info->title, FIELD_BUFLEN - cnt); } if (info->artist == NULL) { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND artist is NULL"); } else { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND artist = "); cnt += _copy_str (where + cnt, info->artist, FIELD_BUFLEN - cnt); } if (info->album == NULL) { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND album is NULL"); } else { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND album = "); cnt += _copy_str (where + cnt, info->album, FIELD_BUFLEN - cnt); } if (info->uri == NULL) { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND uri is NULL"); } else { cnt += snprintf (where + cnt, FIELD_BUFLEN - cnt, " AND uri = "); cnt += _copy_str (where + cnt, info->uri, FIELD_BUFLEN - cnt); } return cnt; }
generic_info program::get_info(cl_uint param) const { switch ((cl_program_info)param) { case CL_PROGRAM_CONTEXT: return pyopencl_get_opaque_info(context, Program, this, param); case CL_PROGRAM_REFERENCE_COUNT: case CL_PROGRAM_NUM_DEVICES: return pyopencl_get_int_info(cl_uint, Program, this, param); case CL_PROGRAM_DEVICES: return pyopencl_get_opaque_array_info(device, Program, this, param); case CL_PROGRAM_SOURCE: return pyopencl_get_str_info(Program, this, param); case CL_PROGRAM_BINARY_SIZES: return pyopencl_get_array_info(size_t, Program, this, param); case CL_PROGRAM_BINARIES: { auto sizes = pyopencl_get_vec_info(size_t, Program, this, CL_PROGRAM_BINARY_SIZES); pyopencl_buf<char*> result_ptrs(sizes.len()); for (size_t i = 0;i < sizes.len();i++) { result_ptrs[i] = (char*)malloc(sizes[i]); } try { pyopencl_call_guarded(clGetProgramInfo, this, CL_PROGRAM_BINARIES, sizes.len() * sizeof(char*), result_ptrs.get(), nullptr); } catch (...) { for (size_t i = 0;i < sizes.len();i++) { free(result_ptrs[i]); } } pyopencl_buf<generic_info> gis(sizes.len()); for (size_t i = 0;i < sizes.len();i++) { gis[i].value = result_ptrs[i]; gis[i].dontfree = 0; gis[i].opaque_class = CLASS_NONE; gis[i].type = _copy_str(std::string("char[") + tostring(sizes[i]) + "]"); } return pyopencl_convert_array_info(generic_info, gis); } #if PYOPENCL_CL_VERSION >= 0x1020 case CL_PROGRAM_NUM_KERNELS: return pyopencl_get_int_info(size_t, Program, this, param); case CL_PROGRAM_KERNEL_NAMES: return pyopencl_get_str_info(Program, this, param); #endif default: throw clerror("Program.get_info", CL_INVALID_VALUE); } }
/* Creates a string pattern. * If casefold is non-zero, the pattern will match against casefolded strings */ static pattern_t * _str_pattern_create (const char *pattern, int casefold) { int i, prev, star; char *str = strdup (pattern); pattern_t *ret, *p; ret = p = calloc (1, sizeof (pattern_t)); /* Walk through the string, replacing '?' with '\0' * and splitting it on '*' */ for (star = prev = i = 0; str[i]; i++) { if (str[i] == '?') { str[i] = '\0'; star = 0; } else if (str[i] == '*') { /* Skip stars following stars */ if (!star) { str[i] = '\0'; p->next = calloc (1, sizeof (pattern_t)); _copy_str (str + prev, i - prev, p, casefold); p = p->next; star = 1; } prev = i + 1; } else { star = 0; } } /* Save the tail of the string */ p->next = NULL; _copy_str (str + prev, i - prev, p, casefold); free (str); return ret; }
String & String::operator += ( const char * s ) { if ( s ) { size_t len1 = strlen(s); if ( len1 < 1 ) { return *this; } size_t new_len = len1 + _str_len; new_len = (new_len > algo::_PSTRING_MAX_LEN ) ? algo::_PSTRING_MAX_LEN : new_len; char * buf = new char[new_len + 1]; if (_str_len && _str ) { memcpy(buf, _str, _str_len); } memcpy(buf + _str_len, s, len1); _copy_str( buf ); delete[] buf; } return * this; }
String::String( const String & str ) { _copy_str(str); }
String::String( const char * s ) { _copy_str(s); }
int ol_lrclib_assign_lyric (const OlMusicInfo *info, const char *lrcpath) { ol_log_func (); static char title_value[FIELD_BUFLEN] = ""; static char artist_value[FIELD_BUFLEN] = ""; static char album_value[FIELD_BUFLEN] = ""; static char uri_value[FIELD_BUFLEN] = ""; static char lrcpath_value[FIELD_BUFLEN] = ""; static char where[FIELD_BUFLEN] = ""; static char query[QUERY_BUFLEN] = ""; if (db == NULL) { ol_error ("LrcLib is no initialized."); return 0; } ol_assert_ret (info != NULL, 0); if (ol_music_info_get_title (info) == NULL && ol_music_info_get_uri (info) == NULL) { ol_error ("Require either title or uri be set."); return 0; } _copy_str (lrcpath_value, lrcpath, FIELD_BUFLEN); char *oldpath = NULL; int find_ret = -1; if (info->uri != NULL || (find_ret = ol_lrclib_find (info, &oldpath)) == 0) { _copy_str (title_value, info->title, FIELD_BUFLEN); _copy_str (artist_value, info->artist, FIELD_BUFLEN); _copy_str (album_value, info->album, FIELD_BUFLEN); _copy_str (uri_value, info->uri, FIELD_BUFLEN); snprintf (query, QUERY_BUFLEN, ASSIGN_LYRIC, title_value, artist_value, album_value, info->track_number, uri_value, lrcpath_value); ol_debugf ("query: %s\n", query); int code = sqlite3_exec (db, query, NULL, NULL, &errmsg); if (code != SQLITE_OK) { ol_errorf ("Assign Lyric Failed: %s\n", errmsg); sqlite3_free (errmsg); } return code == SQLITE_OK; } else { if (oldpath != NULL) g_free (oldpath); int retval = _set_where_with_info (info, where, FIELD_BUFLEN); if (retval == -1) return 0; snprintf (query, QUERY_BUFLEN, UPDATE_LYRIC, lrcpath_value, where); ol_debugf ("update query: %s\n", query); int code = sqlite3_exec (db, query, NULL, NULL, &errmsg); if (code != SQLITE_OK) { ol_errorf ("Update Lyric Failed %s\n", errmsg); sqlite3_free (errmsg); } return code == SQLITE_OK; } }