コード例 #1
0
ファイル: cx_string.c プロジェクト: uonyx/now360
cxu32 cx_str_explode (char **dst, cxu32 dstSize, const char *src, char delimiter)
{
    CX_ASSERT (dst);
    CX_ASSERT (src);

    cxu32 count = 0;

    const char *start = src;
    const char *found = strchr (start, delimiter);

    while (found)
    {
        CX_ASSERT (count < dstSize);

        dst [count++] = cx_strdup (start, found - start);

        start = found + 1;

        found = strchr (start, delimiter);
    }

    CX_ASSERT (count < dstSize);

    if (*start != '\0')
    {
        dst [count++] = cx_strdup (start, strlen (start));
    }

    return count;
}
コード例 #2
0
ファイル: cx_type.c プロジェクト: jeffplourde/cortex
/* ::cortex::lang::type::relname(object from) */
cx_string cx_type_relname(cx_any _this, cx_object from) {
/* $begin(::cortex::lang::type::relname) */
    cx_string result = NULL;
    cx_id id;

    if (_this.value) {
        result = cx_strdup(cx_relname(from, _this.value, id));
    } else {
        result = cx_strdup("null");
    }

    return result;
/* $end */
}
コード例 #3
0
ファイル: cx_type.c プロジェクト: jeffplourde/cortex
/* ::cortex::lang::type::fullname() */
cx_string cx_type_fullname(cx_any _this) {
/* $begin(::cortex::lang::type::fullname) */
    cx_string result = NULL;

    if (_this.value) {
        cx_id id;
        result = cx_strdup(cx_fullname(_this.value, id));
    } else {
        result = cx_strdup("null");
    }

    return result;
/* $end */
}
コード例 #4
0
ファイル: json.c プロジェクト: jeffplourde/cortex
/* agreed not to change anything except the first argument of the signature */
static cx_bool cx_ser_appendstrbuff(cx_json_ser_t* data, char* str) {
    if (!data->ptr) {
        data->ptr = data->buffer;
    }
    if (!data->ptr) {
        data->buffer = cx_strdup(str);
        data->ptr = data->buffer;
    } else {
        cx_uint32 length, bufferLength;

        if (!data->length) {
            data->buffer = cx_realloc(data->buffer, strlen(data->buffer) + strlen(str) + 1);
            data->ptr = data->buffer;
        }

        length = strlen(str);
        bufferLength = strlen(data->buffer);

        if (data->maxlength && ((bufferLength + length) >= data->maxlength)) {
            strncat(data->ptr, str, data->maxlength - bufferLength);
            goto maxreached;
        } else {
            strcat(data->ptr, str);
        }
    }

    return TRUE;
maxreached:
    return FALSE;
}
コード例 #5
0
ファイル: cx_type.c プロジェクト: jeffplourde/cortex
/* ::cortex::lang::type::nameof() */
cx_string cx_type_nameof(cx_any _this) {
/* $begin(::cortex::lang::type::nameof) */
    cx_string result = NULL;

    if (_this.value) {
        result = cx_nameof(_this.value);
        if(result) {
            result = cx_strdup(result);
        }
    } else {
        result = cx_strdup("null");
    }

    return result;
/* $end */
}
コード例 #6
0
ファイル: ic_accumulator.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::accumulator::construct() */
cx_int16 ic_accumulator_construct(ic_accumulator _this) {
/* $begin(::cortex::ic::accumulator::construct) */
    char name[15];
    ic_storage(_this)->kind = IC_ACCUMULATOR;
    sprintf(name, "#%d", ic_program_getAccId(ic_program_get()));
    ic_storage(_this)->name = cx_strdup(name);

    ic_scope_addStorage(ic_program_get()->scope, ic_storage(_this));

    return ic_storage_construct(ic_storage(_this));
/* $end */
}
コード例 #7
0
ファイル: cx_err.c プロジェクト: jeffplourde/cortex
static void cx_setLasterror(char* err) {
    cx_errThreadData* data;

    data = cx_getThreadData();
    if (!data->echo && (data->count < MAX_ERRORS)) {
        if (data->lastError[data->count]) {
            cx_dealloc(data->lastError[data->count]);
        }
        data->lastError[data->count] = cx_strdup(err);
        data->count++;
    }
}
コード例 #8
0
ファイル: cx_type.c プロジェクト: jeffplourde/cortex
/* ::cortex::lang::type::toString() */
cx_string cx_type_toString(cx_any _this) {
/* $begin(::cortex::lang::type::toString) */
    cx_value value;
    cx_string result;

    if (_this.value) {
        if (_this.type->reference) {
            cx_valueObjectInit(&value, _this.value);
        } else {
            cx_valueValueInit(&value, NULL, _this.type, _this.value);
        }
        result = cx_valueToString(&value, 0);
    } else {
        result = cx_strdup("null");
    }

    return result;
/* $end */
}
コード例 #9
0
ファイル: ic_element.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::element::construct() */
cx_int16 ic_element_construct(ic_element _this) {
/* $begin(::cortex::ic::element::construct) */
    cx_id name;
    cx_collection type = cx_collection(_this->base->type);

    ic_storage(_this)->kind = IC_ELEMENT;
    cx_set(&ic_storage(_this)->type, type->elementType);
    cx_set(&ic_storage(_this)->base, _this->base);
    ic_storage(_this)->isReference = type->elementType->reference;

    if (_this->index) {
        cx_string elemStr = ic_node_str(_this->index, NULL);
        sprintf(name, "%s[%s]", _this->base->name, elemStr);
        cx_dealloc(elemStr);
    } else {
        sprintf(name, "*%s", _this->base->name);
    }

    ic_storage(_this)->name = cx_strdup(name);

    return ic_storage_construct(ic_storage(_this));

/* $end */
}
コード例 #10
0
ファイル: cx_function.c プロジェクト: jeffplourde/cortex
/* ::cortex::lang::function::stringToParameterSeq(string name,object scope) */
cx_parameterSeq cx_function_stringToParameterSeq(cx_string name, cx_object scope) {
/* $begin(::cortex::lang::function::stringToParameterSeq) */
    cx_parameterSeq result = {0, NULL};

    cx_char* ptr;

    ptr = strchr(name, '(');
    if (!ptr) {
        cx_error("missing argumentlist in name for signature '%s'", name);
        goto error;
    }
    ptr++;

    /* Check if function has arguments */
    if (*ptr != ')') {
        cx_int32 count = 0, i = 0;
        cx_id id;
        int flags = 0;

        /* Count number of parameters for function */
        count = cx_signatureParamCount(name);
        if (count == -1) {
            goto error;
        }

        /* Allocate size for parameters */
        result.length = count;
        result.buffer = cx_malloc(sizeof(cx_parameter) * count);
        memset(result.buffer, 0, sizeof(cx_parameter) * count);

        /* Parse arguments */
        for(i=0; i<count; i++) {
            if (cx_signatureParamType(name, i, id, &flags)) {
                cx_error("error occurred while parsing type of parameter '%d' for signature '%s'", i, name);
                goto error;
            }

            /* Set reference */
            result.buffer[i].passByReference = (flags & CX_PARAMETER_REFERENCE) != 0;

            /* Assign type */
            result.buffer[i].type = cx_resolve_ext(NULL, scope, id, FALSE, "Resolve parameter-type for function");
            if (!result.buffer[i].type) {
                cx_error("type '%s' of parameter %d in signature %s not found", id, i, name);
                goto error;
            }

            /* Validate whether reference is not redundantly applied */
            if (result.buffer[i].passByReference && result.buffer[i].type->reference) {
                cx_id id;
                cx_error("redundant '&' qualifier for parameter %d, type '%s' is already a reference",
                    i, cx_fullname(result.buffer[i].type, id));
                goto error;
            }

            /* Parse name */
            if (cx_signatureParamName(name, i, id)) {
                cx_error("error occurred while parsing name of argument '%s' for signature '%s'", name);
                goto error;
            }

            result.buffer[i].name = cx_strdup(id);
        }
    }

    return result;
error:
    result.length = -1;
    cx_dealloc(result.buffer);
    result.buffer = NULL;
    return result;
/* $end */
}