C++ (Cpp) snprintf Examples

C++ (Cpp) snprintf - 30 examples found. These are the top rated real world C++ (Cpp) examples of snprintf extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void dt_image_path_append_version(int imgid, char *pathname, const int len)
{
    // get duplicate suffix
    int version = 0;
    sqlite3_stmt *stmt;
    DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                "select count(id) from images where filename in "
                                "(select filename from images where id = ?1) and film_id in "
                                "(select film_id from images where id = ?1) and id < ?1",
                                -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
    if(sqlite3_step(stmt) == SQLITE_ROW)
        version = sqlite3_column_int(stmt, 0);
    sqlite3_finalize(stmt);
    if(version != 0)
    {
        // add version information:
        char *filename = g_strdup(pathname);

        char *c = pathname + strlen(pathname);
        while(*c != '.' && c > pathname) c--;
        snprintf(c, pathname + len - c, "_%02d", version);
        char *c2 = filename + strlen(filename);
        while(*c2 != '.' && c2 > filename) c2--;
        snprintf(c+3, pathname + len - c - 3, "%s", c2);
        g_free(filename);
    }
}
Example #2
0
size_t AbstractPath::initRols(const char* inifile)
{
    assert(inifile);
    IniFile ini;
    ini.open(inifile);
    char tmp[64];
    RoleEntity role;
    for(int i=1; i<=MAX_ROLES; ++i) {
        snprintf(tmp, sizeof(tmp)-1, "local%d", i);
        role.m_local  = ini.readString("APC", tmp, "");
        snprintf(tmp, sizeof(tmp)-1, "import%d", i);
        role.m_import = ini.readString("APC", tmp, "");
        snprintf(tmp, sizeof(tmp)-1, "export%d", i);
        role.m_export = ini.readString("APC", tmp, "");
        if(role.m_local.empty())
        {
            continue;
        }
        else
        {
            m_rols.push_back(role);
        }
    }
    return m_rols.size();
}
Example #3
0
/**\brief Generate an XMLNode of this PlayerInfo
 * \param[in] componentName This should always be "player".
 * \return A new XML node that represents the PlayerInfo.
 */
xmlNodePtr PlayerInfo::ToXMLNode(string componentName) {
    char buff[256];
    char *timestamp;
    xmlNodePtr section = xmlNewNode(NULL, BAD_CAST componentName.c_str());

    xmlNewChild(section, NULL, BAD_CAST "name", BAD_CAST name.c_str() );
    xmlNewChild(section, NULL, BAD_CAST "file", BAD_CAST file.c_str() );
    if( (avatar != NULL) && (avatar->GetPath() != "") ) {
        xmlNewChild(section, NULL, BAD_CAST "avatar", BAD_CAST avatar->GetPath().c_str() );
    }

    xmlNewChild(section, NULL, BAD_CAST "simulation", BAD_CAST simulation.c_str() );
    snprintf(buff, sizeof(buff), "%d", seed );
    xmlNewChild(section, NULL, BAD_CAST "seed", BAD_CAST buff );

    // Last Load Time
    snprintf(buff, sizeof(buff), "%d", (int)lastLoadTime );
    xmlNewChild(section, NULL, BAD_CAST "lastLoadTime", BAD_CAST buff );

    // Save a Human readable comment to explain the Last Load time
    strcpy( buff, "Last Load: " );
    timestamp = ctime( &lastLoadTime );
    timestamp[strlen(timestamp)-1] = '\0';
    xmlAddChild( section, xmlNewComment( BAD_CAST timestamp));

    return section;
}
Example #4
0
static void
initFiles(void)
{
    char buf[BUFSIZ];

    snprintf(buf,BUFSIZ,"%s%s_%d.json", dirpath, prefix, queryid);
    tachojson= fopen(buf,"w");
    if( tachojson == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d_mal.csv",dirpath, prefix, queryid);
    tachomal= fopen(buf,"w");
    if( tachomal == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d_stmt.csv", dirpath, prefix, queryid);
    tachostmt= fopen(buf,"w");
    if( tachostmt == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d.trace", dirpath, prefix, queryid);
    tachotrace= fopen(buf,"w");
    if( tachotrace == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
}
Example #5
0
/******************* print functions **********************/
void printMsParamArray(msParamArray_t *msParamArray, char *buf2) {
    char buf3[MAX_NAME_LEN];
    sprintf(buf2, "len: %d\n", msParamArray->len);
    int i;
    for(i=0; i<msParamArray->len; i++) {
        msParam_t *mP = msParamArray->msParam[i];
        if(i!=0)strncat(buf2, ",", MAX_NAME_LEN - strlen(buf2));
        strncat(buf2, mP->label, MAX_NAME_LEN - strlen(buf2));
        strncat(buf2, "=", MAX_NAME_LEN - strlen(buf2));
        if(mP->inOutStruct == NULL) {
            strncat(buf2, "<null>", MAX_NAME_LEN - strlen(buf2));
        } else {
            if (strcmp(mP->type, DOUBLE_MS_T) == 0) { /* if the parameter is an integer */
                snprintf(buf3, MAX_NAME_LEN, "%f:",*(double *)mP->inOutStruct);
            } else if (strcmp(mP->type, INT_MS_T) == 0) { /* if the parameter is an integer */
                snprintf(buf3, MAX_NAME_LEN, "%d:",*(int *)mP->inOutStruct);
            } else if (strcmp(mP->type, STR_MS_T) == 0) { /* if the parameter is a string */
                snprintf(buf3, MAX_NAME_LEN, "%s:",(char *)mP->inOutStruct);
            } else if(strcmp(mP->type, DATETIME_MS_T) == 0) {
                snprintf(buf3, MAX_NAME_LEN, "%ld:",(long)*(time_t *)mP->inOutStruct);
            } else {
                snprintf(buf3, MAX_NAME_LEN, "<value>:");
            }
            strncat(buf2, buf3, MAX_NAME_LEN - strlen(buf2));
            strncat(buf2, mP->type, MAX_NAME_LEN - strlen(buf2));
        }
    }
    return;
}
static int
_evas_gl_shader_file_check(const char *bin_shader_dir, char *bin_shader_file, int dir_num)
{
    char before_name[PATH_MAX];
    char after_name[PATH_MAX];
    int new_path_len = 0;
    int i = 0, j = 0;

    char *vendor = NULL;
    char *driver = NULL;
    char *version = NULL;

    vendor = (char *)glGetString(GL_VENDOR);
    driver = (char *)glGetString(GL_RENDERER);
    version = (char *)glGetString(GL_VERSION);

    new_path_len = snprintf(before_name, sizeof(before_name), "%s::%s::%s::%s::binary_shader.eet", vendor, version, driver, MODULE_ARCH);

    /* remove '/' from file name */
    for (i = 0; i < new_path_len; i++)
    {
        if (before_name[i] != '/')
        {
            after_name[j] = before_name[i];
            j++;
        }
    }
    after_name[j] = 0;

    snprintf(bin_shader_file, dir_num, "%s/%s", bin_shader_dir, after_name);

    return _evas_gl_shader_file_exists(bin_shader_file);
}