Пример #1
0
void saveConfigWithType(int configType) {
    //This doesn't actually need to log the type
    //It's only here because there's a weird bug with saving the config,
    //which adding a log seems to resolve
    logTextP("Saving config", "/c.txt", false);

    configData *data = configDataForType(configType);
    if (!data) {
        return;
    }

    //Start size at zero bytes
    int size = 0;

    //For each config entry, add the size of the value, key and delimeters to the overall file size
    int i;
    for (i=0; i<data->numConfigEntries; i++) {
        size += strlen(data->keys[i]);
        size += strlen(data->values[i]);
        size += 2;
    }

    //Create a string big enough to accomodate all of the keys, values and delimeters
    char out[size];

    strcpy(out, "");

    //For each config entry, add its key, value and delimeters to the output string
    for (i=0; i<data->numConfigEntries; i++) {
        strncat(out, data->keys[i], strlen(data->keys[i]));
        strncat(out, "=", 1);
        strncat(out, data->values[i], strlen(data->values[i]));
        strncat(out, "|", 1);
    }


//    logInt(configType, "Saving config with type");

    char * configPath = configPathForType(configType);
    if (configPath == NULL) {
        return;
    }

    //Open the config file path for writing and save the output string to it
    FILE* fp = fopen( configPath, "w" );
    if (fp != NULL) {
        fputs(out, fp);
    }

    fclose(fp);
    free(configPath);
}
Пример #2
0
void logText(char *text) {
    char const * path = "sdmc:/log.txt";
    logTextP(text, path);
}
Пример #3
0
void logIntP(int i, char * label, char const * path) {
    char s[strlen(label)+8];
    sprintf(s, "%s: %d", label, i);
    logTextP(s, path);
}