Ejemplo n.º 1
0
corto_int16 corto_ser_initAny(corto_walk_opt* s, corto_value* v, void* userData) {
    corto_any *ptr = corto_value_ptrof(v);
    CORTO_UNUSED(s);
    CORTO_UNUSED(userData);
    ptr->owner = TRUE;
    return 0;
}
Ejemplo n.º 2
0
Archivo: os.c Proyecto: cortoproject/os
int osMain(int argc, char* argv[]) {
/* $begin(main) */
    /* Insert code that must be run when component is loaded */
    CORTO_UNUSED(argc);
    CORTO_UNUSED(argv);
    return 0;
/* $end */
}
Ejemplo n.º 3
0
corto_err corto_logv(corto_err kind, unsigned int level, char* fmt, va_list arg, FILE* f) {
    char buff[CORTO_MAX_LOG + 1];
    size_t n = 0;
    corto_string alloc = NULL;
    corto_string msg = buff;
    va_list argcpy;
    va_copy(argcpy, arg); /* Make copy of arglist in
                           * case vsnprintf needs to be called twice */

    CORTO_UNUSED(level);

    if ((n = (vsnprintf(buff, CORTO_MAX_LOG, fmt, arg) + 1)) > CORTO_MAX_LOG) {
        alloc = corto_alloc(n + 2);
        vsnprintf(alloc, n, fmt, argcpy);
        msg = alloc;
    }

    n = strlen(msg);

    strcat(msg, "\n");
    n++;

    if (f == stderr) {
        fprintf(f,  "%s%s%s", RED, msg, NORMAL);
    } else {
        fprintf(f, "%s", msg);
    }

    if (alloc) {
        corto_dealloc(alloc);
    }

    return kind;
}
Ejemplo n.º 4
0
corto_int16 _md_DocDefine(md_Doc _this, corto_object o, corto_uint8 level, corto_string niceName) {
    CORTO_UNUSED(_this);
    corto_setref(&((md_Doc)_this)->o, o);
    ((md_Doc)_this)->level = level;
    corto_setstr(&((md_Doc)_this)->niceName, niceName);
    return corto_define(_this);
}
Ejemplo n.º 5
0
/* Build a project */
corto_int16 cortotool_build(int argc, char *argv[]) {
    corto_int8 ret = 0;
    corto_ll silent, mute, coverage, optimize, dirs, release, debug;

    CORTO_UNUSED(argc);

    corto_argdata *data = corto_argparse(
                              argv,
    (corto_argdata[]) {
        {"$0", NULL, NULL}, /* Ignore first argument */
        {"--silent", &silent, NULL},
        {"--mute", &mute, NULL},
        {"--coverage", &coverage, NULL},
        {"--optimize", &optimize, NULL},
        {"--release", &release, NULL},
        {"--debug", &debug, NULL},
        {"*", &dirs, NULL},
        {NULL}
    }
                          );

    ret = cortotool_runcmd(
              dirs,
              (char*[])
    {
        "rake",
        coverage ? "coverage=true" : "coverage=false",
        optimize ? "optimize=true" : "optimize=false",
        release ? "target=release" : "target=debug",
        NULL
    }, silent != NULL, mute != NULL);
Ejemplo n.º 6
0
md_Doc _md_DocAssign(md_Doc _this, corto_object o, corto_uint8 level, corto_string niceName) {
    CORTO_UNUSED(_this);
    corto_setref(&((md_Doc)_this)->o, o);
    ((md_Doc)_this)->level = level;
    corto_setstr(&((md_Doc)_this)->niceName, niceName);
    return _this;
}
Ejemplo n.º 7
0
static corto_int16 corto_ser_reference(corto_walk_opt* s, corto_value *info, void *userData) {
    corto_compare_ser_t *data = userData;
    void *this = corto_value_ptrof(info);
    void *value = (void*)((corto_word)corto_value_ptrof(&data->value) + ((corto_word)this - (corto_word)data->base));
    CORTO_UNUSED(s);

    if (*(corto_object*)this != *(corto_object*)value) {
        data->result = CORTO_NEQ;
    } else {
        data->result = CORTO_EQ;
    }

    return data->result != CORTO_EQ;
}
Ejemplo n.º 8
0
static int corto_selectHasNext(corto_iter *iter) {
	corto_selectData *data = corto_selectDataGet();
	CORTO_UNUSED(iter);

	if (!data->next) {
		if (corto_selectRun(data)) {
			goto error;
		}
	}

	return data->next != NULL;
error:
	return -1;
}
Ejemplo n.º 9
0
static corto_int16 json_deserBoolean(void* o, corto_primitive t, JSON_Value *v)
{
    CORTO_UNUSED(t);

    if (json_value_get_type(v) != JSONBoolean) {
        corto_seterr("expected boolean, got %s", json_valueTypeToString(v));
        goto error;
    }

    *(corto_bool *)o = json_value_get_boolean(v);

    return 0;
error:
    return -1;
}
Ejemplo n.º 10
0
static corto_int16 json_deserText(void* p, corto_primitive t, JSON_Value *v)
{
    const char *s = json_value_get_string(v);
    CORTO_UNUSED(t);

    if (json_value_get_type(v) != JSONString) {
        corto_seterr("expected string, got %s", json_valueTypeToString(v));
        goto error;
    }

    corto_setstr(p, (corto_string)s);

    return 0;
error:
    return -1;
}
Ejemplo n.º 11
0
static corto_int16 json_deserConstant(void* p, corto_primitive t, JSON_Value *v)
{
    const char *s = json_value_get_string(v);
    CORTO_UNUSED(t);

    if (json_value_get_type(v) != JSONString) {
        corto_seterr("expected string, got %s", json_valueTypeToString(v));
        goto error;
    }

    if (corto_convert(corto_string_o, (corto_string*)&s, t, p)) {
        goto error;
    }

    return 0;
error:
    return -1;
}
Ejemplo n.º 12
0
corto_int16 _md_DocUpdate(md_Doc _this, corto_object o, corto_uint8 level, corto_string niceName) {
    CORTO_UNUSED(_this);
    if (!corto_updateBegin(_this)) {
        if ((corto_typeof(corto_typeof(_this)) == (corto_type)corto_target_o) && !corto_owned(_this)) {
            corto_setref(&((md_Doc)((md_Doc)CORTO_OFFSET(_this, ((corto_type)md_Doc_o)->size)))->o, o);
            ((md_Doc)((md_Doc)CORTO_OFFSET(_this, ((corto_type)md_Doc_o)->size)))->level = level;
            corto_setstr(&((md_Doc)((md_Doc)CORTO_OFFSET(_this, ((corto_type)md_Doc_o)->size)))->niceName, niceName);
        } else {
            corto_setref(&((md_Doc)_this)->o, o);
            ((md_Doc)_this)->level = level;
            corto_setstr(&((md_Doc)_this)->niceName, niceName);
        }
        corto_updateEnd(_this);
    } else {
        return -1;
    }
    return 0;
}
Ejemplo n.º 13
0
corto_int16 _corto_native_type__update(corto_native_type _this, const char * name, bool is_ptr) {
    CORTO_UNUSED(_this);
    if (!corto_update_begin(_this)) {
        if ((corto_typeof(corto_typeof(_this)) == (corto_type)corto_target_o) && !corto_owned(_this)) {
            corto_set_str(&((corto_native_type)((corto_native_type)CORTO_OFFSET(_this, ((corto_type)corto_native_type_o)->size)))->name, name);
            ((corto_native_type)((corto_native_type)CORTO_OFFSET(_this, ((corto_type)corto_native_type_o)->size)))->is_ptr = is_ptr;
        } else {
            corto_set_str(&((corto_native_type)_this)->name, name);
            ((corto_native_type)_this)->is_ptr = is_ptr;
        }
        if (corto_update_end(_this)) {
            return -1;
        }
    } else {
        return -1;
    }
    return 0;
}
Ejemplo n.º 14
0
static corto_uint32 corto_buffer_strcpy(
    char *dst,
    char *src,
    corto_int32 len,
    void *userData)
{
    char *ptr, ch, *bptr = dst;
    CORTO_UNUSED(userData);

    /* Prevent doing both a strcpy and a strlen */
    for(ptr = src; (ch = *ptr); ptr++) {
        if ((ptr - src) < len) {
            *(bptr++) = ch;
        }
    }

    return ptr - src;
}
Ejemplo n.º 15
0
/* Add indexInfo to indextable for each primitive */
static corto_int16 corto_string_deserBuildIndexPrimitive(corto_walk_opt* s, corto_value* v, void* userData) {
    corto_string_deser_t* data;
    struct corto_string_deserIndexInfo *newInfo;
    corto_member m;

    CORTO_UNUSED(s);

    data = userData;

    /* Lookup member */
    m = v->is.member.t;

    /* Create new info-object */
    newInfo = corto_alloc(sizeof(struct corto_string_deserIndexInfo));
    newInfo->m = m;
    newInfo->type = m->type;
    newInfo->parsed = FALSE;

    /* Insert indexInfo into index */
    corto_string_deserIndexInsert(data, newInfo);

    return 0;
}
Ejemplo n.º 16
0
corto_int16 corto_select(corto_object scope, corto_string expr, corto_iter *iter_out) {
	corto_selectData *data = corto_selectDataGet();
	CORTO_UNUSED(scope);

	strcpy(data->expr, expr);

	iter_out->hasNext = corto_selectHasNext;
	iter_out->next = corto_selectNext;

	if (corto_selectParse(data)) {
		corto_seterr("select '%s' failed: %s", expr, corto_lasterr());
		goto error;
	}

	if (corto_selectValidate(data)) {
		corto_seterr("select '%s' failed: %s", expr, corto_lasterr());
		goto error;
	}

	return 0;
error:
	return -1;
}
Ejemplo n.º 17
0
int tc_lookupAllWalk(corto_object o, void *ctx) {
    CORTO_UNUSED(ctx);
    corto_id id;
    corto_object r;

    corto_path(id, NULL, o, "/");
    r = corto_lookup(NULL, id);

    /* Set errormessage to ease debugging */
    if (!r) corto_seterr("failed to lookup %s", id);
    test_assert(r != NULL);
    test_assert(r == o);
    corto_release(r);

    corto_objectseq scope = corto_scopeClaim(o);
    int i;
    for (i = 0; i < scope.length; i ++) {
        tc_lookupAllWalk(scope.buffer[i], NULL);
    }
    corto_scopeRelease(scope);

    return 1;
}
Ejemplo n.º 18
0
int corto_mount_alignSubscriptionsAction(
  corto_object e,
  corto_object instance,
  void *userData)
{
    corto_mount this = userData;
    corto_iter it;
    corto_subscriber s = e;

    CORTO_UNUSED(instance);

    corto_select(s->query.select)
      .from(s->query.from)
      .type(s->query.type)
      .mount(this)
      .subscribe(&it);

    /* Visit all objects to find all subscriptions */
    while (corto_iter_hasNext(&it)) {
        corto_iter_next(&it);
    }

    return 1;
}
Ejemplo n.º 19
0
int cortomain(int argc, char *argv[]) {
    CORTO_UNUSED(argc);
    CORTO_UNUSED(argv);
    return 0;
}
Ejemplo n.º 20
0
corto_int16 cortotool_publish(int argc, char *argv[]) {
    corto_ll silent, mute, notag, dirs, majorarg, minorarg, patcharg;
    corto_uint32 major = 0, minor = 0, patch = 0;

    CORTO_UNUSED(argc);

    corto_argdata *data = corto_argparse(
      argv,
      (corto_argdata[]){
        {"$0", NULL, NULL}, /* Ignore 'publish' argument */
        {"--silent", &silent, NULL},
        {"--mute", &mute, NULL},
        {"--notag", &notag, NULL},
        {"$?*", &dirs, NULL},
        {"$+major", &majorarg, NULL},
        {"$|minor", &minorarg, NULL},
        {"$|patch", &patcharg, NULL},
        {NULL}
      }
    );

    if (!data) {
        corto_error("corto: %s", corto_lasterr());
        goto error;
    }

    if (dirs) {
        corto_string dir = corto_llGet(dirs, 0);
        if (corto_chdir(dir)) {
            corto_error("corto: %s", corto_lasterr());
            goto error;
        }
    }


    if (!corto_fileTest("./.corto")) {
        corto_error("corto: invalid project directory");
        goto error;
    }

    if (!notag) {
        corto_error(
            "corto: tagging of repository not yet supported "
            "(use --notag to just increase version)");
        goto error;
    }

    corto_string version = corto_fileLoad(".corto/version.txt");

    /* Patch version */
    if (version) {
        char *v = version;

        /* Parse major version */
        char *ptr = strchr(version, '.');
        if (ptr) {
            *ptr = '\0';
            major = atoi(v);
            v = ptr + 1;
        }

        /* Parse minor version */
        ptr = strchr(v, '.');
        if (ptr) {
            *ptr = '\0';
            minor = atoi(v);
            v = ptr + 1;
        }

        /* Parse patch version */
        patch = atoi(v);
    }

    if (majorarg) {
        major++;
    }
    if (minorarg) {
        minor++;
    }
    if (patcharg) {
        patch++;
    }

    FILE *f = fopen(".corto/version.txt", "w");
    if (!f) {
        corto_error("failed to open '.corto/version.txt' (check permissions)");
        goto error;
    }

    fprintf(f, "%u.%u.%u\n", major, minor, patch);
    fclose(f);

    corto_argclean(data);
    corto_dealloc(version);

    if (!silent) {
        corto_print("corto: version updated to %u.%u.%u", major, minor, patch);
    }

    return 0;
error:
    return -1;
}
Ejemplo n.º 21
0
/* Parse string */
static corto_string corto_string_deserParse(
    corto_string str,
    struct corto_string_deserIndexInfo* info,
    corto_string_deser_t* data)
{
    corto_char ch;
    corto_char *ptr, *bptr, *nonWs;
    corto_char buffer[CORTO_STRING_DESER_TOKEN_MAX]; /* TODO: dangerous in a recursive function */
    corto_bool proceed, excess;
    struct corto_string_deserIndexInfo* memberInfo;

    CORTO_UNUSED(info);

    ptr = str;
    bptr = buffer;
    nonWs = bptr;
    proceed = TRUE;
    excess = FALSE;
    memberInfo = NULL;

    if (info) {
        memberInfo = corto_string_deserIndexNext(data);
    }

    /* If ptr == NULL, an error has occurred. If proceed == FALSE, this function
     * has finished processing the current value. */
    while(ptr && (ch = *ptr) && proceed) {
        switch(ch) {
        case '=': /* Explicit member assignment */
            excess = FALSE;
            if (buffer == bptr) {
                corto_seterr("missing member identifier");
                goto error;
            } else {
                *nonWs = '\0';
                memberInfo = corto_string_deserIndexLookup(buffer, data);
                bptr = buffer;
                nonWs = bptr;
                if (!memberInfo) {
                    corto_seterr("member '%s' not found in type '%s'", buffer, corto_fullpath(NULL, data->type));
                    goto error;
                }
                break;
            }

        case '{': /* Scope open */
            if (bptr == buffer) {
                if (!(ptr = corto_string_deserParseScope(
                    ptr,
                    memberInfo,
                    data))) {
                    goto error;
                }
            } else {
                *bptr = '\0';
                if (!(ptr = corto_string_parseAnonymous(
                    ptr,
                    buffer,
                    memberInfo,
                    data))) {
                    goto error;
                }
                bptr = buffer;
            }
            break;

        case '}': /* Scope close and end of value */
            if (buffer != bptr) {
                *nonWs = '\0';
                if (memberInfo && (data->type->kind != CORTO_PRIMITIVE)) {
                    if (corto_string_deserParseValue(buffer, memberInfo, data)) {
                        goto error;
                    }
                    bptr = buffer;
                    nonWs = bptr;
                }
            }
            proceed = FALSE;
            ptr--;
            break;

        case '(':
            /* If a value is being parsed, the '(' is part of an argument list.
             * Parse up until the matching ')' */
            if (bptr != buffer) {
                char *start = ptr;

                /* Parse until matching '} */
                do {
                    *bptr = ch;
                    bptr++;
                    ptr++;
                } while((ch = *ptr) && (ch == ')'));

                ptr--;
                nonWs = bptr;

                /* ptr must always end with a '}' */
                if (*ptr != ')') {
                    corto_seterr("missing ')' at '%s' (%s)", start, ptr);
                    goto error;
                }
            }


        case '"':
            if (!(ptr = corto_string_deserParseString(ptr, buffer, &bptr))) {
                goto error;
            }
            nonWs = bptr;
            ptr--;
            break;
        case '\'':
            if (!(ptr = corto_string_deserParseCharacter(ptr+1, buffer))) {
                goto error;
            }
            *(++bptr) = '\0';
            nonWs = bptr;
            break;

        case '\n':
        case '\t':
        case ' ':
            if (bptr != buffer) {
                *bptr = ch;
                bptr++;
            }
            break;

        case ',': /* End of value */
            if (buffer != bptr) {
                *nonWs = '\0';
                if (corto_string_deserParseValue(buffer, memberInfo ? memberInfo : info, data)) {
                    goto error;
                }
                bptr = buffer;
                nonWs = bptr;
            }

            /* If memberInfo contains a member, get next member, otherwise it contains
             * an element. The same information applies to each element therefore it is only present
             * once in the index. */
            if (memberInfo) {
                if (memberInfo->m) {
                    memberInfo = corto_string_deserIndexNext(data);
                    if (!memberInfo) {
                        excess = TRUE;
                    }
                }
                data->current++;
            } else {
                /* A comma without memberInfo means that a discriminator of a
                 * union was parsed */
                proceed = FALSE;
            }
            break;
        default:
            *bptr = ch;
            bptr++;
            nonWs = bptr;
            break;
        }
        if (ptr && *ptr) ptr++;
    }

    if (bptr != buffer) {
        struct corto_string_deserIndexInfo info;
        *nonWs = '\0';
        info.type = data->type;
        info.parsed = FALSE;
        info.m = NULL;
        if (corto_string_deserParseValue(buffer, &info, data)) {
            goto error;
        }
    }

    if (excess) {
        corto_seterr("excess elements in string");
        goto error;
    }

    return ptr;
error:
    return NULL;
}
Ejemplo n.º 22
0
/* This function prevents doing unwanted deepwalks of types */
static corto_int16 corto_string_deserBuildIndexDummy(corto_walk_opt* s, corto_value* v, void* userData) {
    CORTO_UNUSED(s);
    CORTO_UNUSED(v);
    CORTO_UNUSED(userData);
    return 0;
}
Ejemplo n.º 23
0
/* Free nodes from index */
int corto_string_deserWalkIndex(void* o, void* ctx) {
    CORTO_UNUSED(ctx);
    corto_dealloc(o);
    return 1;
}
Ejemplo n.º 24
0
corto_string corto_string_deser(corto_string str, corto_string_deser_t* data) {
    CORTO_UNUSED(str);
    CORTO_UNUSED(data);
    return NULL;
}
Ejemplo n.º 25
0
static corto_int16 corto_ser_primitive(corto_walk_opt* s, corto_value *info, void *userData) {
    corto_equalityKind result = CORTO_EQ;
    corto_compare_ser_t *data = userData;
    corto_type type = corto_value_typeof(info);
    void *this = corto_value_ptrof(info);
    void *value = (void*)((corto_word)corto_value_ptrof(&data->value) + ((corto_word)this - (corto_word)data->base));

    CORTO_UNUSED(s);

    switch(corto_primitive(type)->kind) {
    case CORTO_BOOLEAN:
        result = CORTO_COMPARE(corto_bool, this, value);
        break;
    case CORTO_CHARACTER:
        result = CORTO_COMPARE(corto_char, this, value);
        break;
    case CORTO_INTEGER:
    case CORTO_ENUM:
        switch(corto_primitive(type)->width) {
        case CORTO_WIDTH_8:
            result = CORTO_COMPARE(corto_int8, this, value);
            break;
        case CORTO_WIDTH_16:
            result = CORTO_COMPARE(corto_int16, this, value);
            break;
        case CORTO_WIDTH_32:
            result = CORTO_COMPARE(corto_int32, this, value);
            break;
        case CORTO_WIDTH_64:
            result = CORTO_COMPARE(corto_int64, this, value);
            break;
        case CORTO_WIDTH_WORD:
            result = CORTO_COMPARE(intptr_t, this, value);
            break;
        }
        break;
    case CORTO_BINARY:
    case CORTO_UINTEGER:
    case CORTO_BITMASK:
        switch(corto_primitive(type)->width) {
        case CORTO_WIDTH_8:
            result = CORTO_COMPARE(corto_uint8, this, value);
            break;
        case CORTO_WIDTH_16:
            result = CORTO_COMPARE(corto_uint16, this, value);
            break;
        case CORTO_WIDTH_32:
            result = CORTO_COMPARE(corto_uint32, this, value);
            break;
        case CORTO_WIDTH_64:
            result = CORTO_COMPARE(corto_uint64, this, value);
            break;
        case CORTO_WIDTH_WORD:
            result = CORTO_COMPARE(uintptr_t, this, value);
            break;
        }
        break;
    case CORTO_FLOAT:
        switch(corto_primitive(type)->width) {
        case CORTO_WIDTH_32:
            result = CORTO_COMPARE(corto_float32, this, value);
            break;
        case CORTO_WIDTH_64:
            result = CORTO_COMPARE(corto_float64, this, value);
            break;
        default:
            break;
        }
        break;
    case CORTO_TEXT: {
        corto_string thisStr = *(corto_string*)this;
        corto_string valueStr = *(corto_string*)value;
        if (thisStr && valueStr) {
            result = strcmp(thisStr, valueStr);
            if (result < 0) {
                result = CORTO_LT;
            } else if (result > 0) {
                result = CORTO_GT;
            }
        } else {
            if (thisStr == valueStr) {
                result = CORTO_EQ;
            } else {
                result = thisStr ? CORTO_GT : CORTO_LT;
            }
        }
        break;
    }
    }

    data->result = result;

    return data->result != CORTO_EQ;
}
Ejemplo n.º 26
0
char* corto_utoa(unsigned int num, char* buff) {
    CORTO_UNUSED(num);
    CORTO_UNUSED(buff);
    return NULL;
}
Ejemplo n.º 27
0
corto_int16 cortotool_commit(int argc, char* argv[]) {
	CORTO_UNUSED(argc);
	CORTO_UNUSED(argv);
	printf("corto: not yet supported\n");
	return -1;
}
Ejemplo n.º 28
0
char* corto_ftoa(float num, char* buff) {
    CORTO_UNUSED(num);
    CORTO_UNUSED(buff);
    return NULL;
}
Ejemplo n.º 29
0
static corto_bool corto_iterator_next_map(void* iterator) {
    CORTO_UNUSED(iterator);
    // TODO implement
    return 1;
}
Ejemplo n.º 30
0
/*
 * An adapter on top of corto_loadLibrary to fit the corto_loadAction signature.
 */
int corto_loadLibraryAction(corto_string file, int argc, char* argv[], void *data) {
    CORTO_UNUSED(data);
    return corto_loadLibrary(file, FALSE, NULL, argc, argv);
}