Exemple #1
0
static void
fill_in_array(awk_value_t *new_array)
{
	awk_array_t a_cookie;
	awk_value_t index, value;

	a_cookie = create_array();

	(void) make_const_string("hello", 5, & index);
	(void) make_const_string("world", 5, & value);
	if (! set_array_element(a_cookie, & index, & value)) {
		printf("fill_in_array:%d: set_array_element failed\n", __LINE__);
		return;
	}

	(void) make_const_string("answer", 6, & index);
	(void) make_number(42.0, & value);
	if (! set_array_element(a_cookie, & index, & value)) {
		printf("fill_in_array:%d: set_array_element failed\n", __LINE__);
		return;
	}

	new_array->val_type = AWK_ARRAY;
	new_array->array_cookie = a_cookie;
}
/**
 * Shows the message on screen.
 *
 * @param p0 the message
 * @param p1 the message size
 */
void show_message(void* p0, void* p1) {

    if (p1 != NULL_POINTER) {

        int* s = (int*) p1;

        // The log message.
        char* m = CHARACTER_NULL_POINTER;
        // The log size, including two places for new line and
        // string termination.
        int ls = *s + 2;

        create_array((void*) &m, (void*) &CHARACTER_ARRAY, (void*) &ls);

        // The destination index to which to copy the source array.
        int i = 0;
        char n = '\n';
        int ni = *s;
        char t = '\0';
        int ti = *s + 1;

        set_array_elements((void*) &m, (void*) &CHARACTER_ARRAY, (void*) &i, p0, p1);
        set_array_element((void*) &m, (void*) &CHARACTER_ARRAY, (void*) &ni, (void*) &n);
        set_array_element((void*) &m, (void*) &CHARACTER_ARRAY, (void*) &ti, (void*) &t);

        fputs(m, stdout);

        destroy_array((void*) &m, (void*) &CHARACTER_ARRAY, (void*) &ls);

    } else {

        fputs("Error: Could not show message. The message size is null.\n", stdout);
    }
}
/**
 * Initializes the vector.
 *
 * @param p0 the transient model
 * @param p1 the persistent model
 * @param p2 the persistent model size
 */
void initialize_vector(void* p0, const void* p1, const void* p2) {

    log_message((void*) &INFO_LOG_LEVEL, (void*) &"Initialize vector.");

    // Read input stream and transform to vector.
//??    fscanf(p1, %d, &(m->x));
//??    fscanf(p1, %d, &(m->y));
//??    fscanf(p1, %d, &(m->z));

    // Initialize elements.
    int z = 0;
    int y = 0;
    int x = 0;

    // Set elements.
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &X_INDEX, (void*) &x);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &Y_INDEX, (void*) &y);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &Z_INDEX, (void*) &z);

/*??
    int i1 = s.indexOf(",");

    if (i1 != -1) {

        char[] x = s.substring(0, i1);
        char[] yz = s.substring(i1 + 1);
        int i2 = yz.indexOf(",");

        if (i2 != -1) {

            char[] y = yz.substring(0, i2);
            char[] z = yz.substring(i2 + 1);

            p.x = java.lang.Integer.parseInt(x);
            p.y = java.lang.Integer.parseInt(y);
            p.z = java.lang.Integer.parseInt(z);

        } else {

            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not create vector. The vector does not contain a z coordinate.");
        }

    } else {

        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not create vector. The vector does not contain an y coordinate.");
    }
*/
}
Exemple #4
0
static awk_value_t *
do_pg_fieldsbyname(int nargs, awk_value_t *result)
{
  PGresult *res;
  awk_value_t array;
  int nf;
  int col;

  if (do_lint && (nargs > 2))
    lintwarn(ext_id, _("pg_fieldsbyname: called with too many arguments"));

  if (!(res = find_handle(results, 0))) {
    set_ERRNO(_("pg_fieldsbyname called with unknown result handle"));
    RET_NUM(-1);
  }

  if (!get_argument(1, AWK_ARRAY, &array)) {
    set_ERRNO(_("pg_fieldsbyname 2nd argument must be an array"));
    RET_NUM(-1);
  }
  clear_array(array.array_cookie);

  nf = PQnfields(res);
  for (col = 0; col < nf; col++) {
    char *fname;
    awk_value_t idx, val;

    fname = PQfname(res, col);
    set_array_element(array.array_cookie,
		      make_string_malloc(fname, strlen(fname), &idx),
		      make_number(col, &val));
  }
  RET_NUM(nf);
}
Exemple #5
0
int set_array_element_object(jsobjtype array, int idx, jsobjtype child)
{
	char buf[32];
	if (whichproc == 'j')
		return set_array_element_object_nat(array, idx, child);
	sprintf(buf, "%p", child);
	return set_array_element(array, idx, buf, EJ_PROP_OBJECT);
}				/* set_array_element_object */
Exemple #6
0
static void
array_set(awk_array_t array, const char *sub, awk_value_t *value)
{
	awk_value_t index;

	set_array_element(array,
			make_const_string(sub, strlen(sub), & index),
			value);

}
Exemple #7
0
static awk_value_t *
do_pg_getrowbyname(int nargs, awk_value_t *result)
{
  PGresult *res;
  awk_value_t array;
  awk_value_t rowarg;
  int row;
  int nf;
  int found;
  int col;

  if (do_lint && (nargs > 3))
    lintwarn(ext_id, _("pg_getrowbyname: called with too many arguments"));

  if (!(res = find_handle(results, 0))) {
    set_ERRNO(_("pg_getrowbyname called with unknown result handle"));
    RET_NUM(-1);
  }

  if (!get_argument(1, AWK_NUMBER, &rowarg)) {
    set_ERRNO(_("pg_getrowbyname: 2nd argument must be a row number"));
    RET_NUM(-1);
  }
  row = rowarg.num_value;

  if ((row < 0) || (row >= PQntuples(res))) {
    set_ERRNO(_("pg_getrowbyname: 2nd argument row_number is out of range"));
    RET_NUM(-1);
  }

  if (!get_argument(2, AWK_ARRAY, &array)) {
    set_ERRNO(_("pg_getrowbyname 3rd argument must be an array"));
    RET_NUM(-1);
  }
  clear_array(array.array_cookie);

  found = 0;
  nf = PQnfields(res);
  for (col = 0; col < nf; col++) {
    if (!PQgetisnull(res, row, col)) {
      char *fname;
      char *val;
      awk_value_t idx, value;

      fname = PQfname(res, col);
      val = PQgetvalue(res, row, col);
      set_array_element(array.array_cookie,
      			make_string_malloc(fname, strlen(fname), &idx),
			make_string_malloc(val, strlen(val), &value));
      found++;
    }
  }
  RET_NUM(found);
}
Exemple #8
0
static void
fill_path_element(awk_array_t element_array, const char *path)
{
	awk_value_t index, value;

	(void) make_const_string("path", 4, & index);
	(void) make_const_string(path, strlen(path), & value);
	if (! set_array_element(element_array, & index, & value)) {
		warning(ext_id, _("fill_path_element: could not set element"));
		fts_errors++;
	}
}
/**
 * Removes the signal.
 *
 * @param p0 the signal memory
 * @param p1 the index
 */
void remove_signal(void* p0, const void* p1) {

    if (p1 != NULL_POINTER) {

        int* i = (int*) p1;

        if (*i >= 0) {

            // Initialize elements.
            int s = 0;
            int c = 0;
            void* sig = NULL_POINTER;
            void* p = NULL_POINTER;
            void* a = NULL_POINTER;
            void* as = NULL_POINTER;

            // Get elements.
            get_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_SIZE_INDEX, (void*) &s);
            get_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_COUNT_INDEX, (void*) &c);
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &SIGNALS_INDEX, (void*) &sig);
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &PRIORITIES_INDEX, (void*) &p);
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_INDEX, (void*) &a);
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_SIZES_INDEX, (void*) &as);

            if (*i < c) {

                // Remove signal.
                remove_array_element((void*) &sig, (void*) &POINTER_ARRAY, (void*) &c, p1);
                remove_array_element((void*) &p, (void*) &INTEGER_ARRAY, (void*) &c, p1);
                remove_array_element((void*) &a, (void*) &POINTER_ARRAY, (void*) &c, p1);
                remove_array_element((void*) &as, (void*) &INTEGER_ARRAY, (void*) &c, p1);

                // Decrement count.
                c--;

                // Set count.
                set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_COUNT_INDEX, (void*) &c);

            } else {

                log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not remove signal. The index exceeds the count.");
            }

        } else {

            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not remove signal. The index is negativ.");
        }

    } else {

        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not remove signal. The index is null.");
    }
}
/**
 * Creates the signal memory.
 *
 * @param p0 the signal memory
 */
void create_signal_memory(void* p0) {

    log_message((void*) &INFO_LOG_LEVEL, (void*) &"Create signal memory.");

    // Create signal memory.
    create_array(p0, (void*) &POINTER_ARRAY, (void*) &SIGNAL_MEMORY_COUNT);

    // Initialize elements.
    int s = 0;
    int c = 0;
    void* sig = NULL_POINTER;
    void* p = NULL_POINTER;
    void* a = NULL_POINTER;
    void* as = NULL_POINTER;

    // Create elements.
    create_array((void*) &sig, (void*) &POINTER_ARRAY, (void*) &s);
    create_array((void*) &p, (void*) &INTEGER_ARRAY, (void*) &s);
    create_array((void*) &a, (void*) &POINTER_ARRAY, (void*) &s);
    create_array((void*) &as, (void*) &INTEGER_ARRAY, (void*) &s);

    // Set elements in ascending order.
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_SIZE_INDEX, (void*) &s);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_COUNT_INDEX, (void*) &c);
    set_array_element(p0, (void*) &POINTER_ARRAY, (void*) &SIGNALS_INDEX, (void*) &sig);
    set_array_element(p0, (void*) &POINTER_ARRAY, (void*) &PRIORITIES_INDEX, (void*) &p);
    set_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_INDEX, (void*) &a);
    set_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_SIZES_INDEX, (void*) &as);
}
Exemple #11
0
static void
fill_error_element(awk_array_t element_array, const int errcode)
{
	awk_value_t index, value;
	const char *err = strerror(errcode);

	(void) make_const_string("error", 5, & index);
	(void) make_const_string(err, strlen(err), & value);
	if (! set_array_element(element_array, & index, & value)) {
		warning(ext_id, _("fill_error_element: could not set element"));
		fts_errors++;
	}
}
Exemple #12
0
jsobjtype instantiate_array_element(jsobjtype array, int idx,
				    const char *classname)
{
	jsobjtype p = 0;
	if (whichproc == 'j')
		return instantiate_array_element_nat(array, idx, classname);
	set_array_element(array, idx, classname, EJ_PROP_INSTANCE);
	if (!propval)
		return p;
	sscanf(propval, "%p", &p);
	nzFree(propval);
	propval = 0;
	return p;
}				/* instantiate_array_element */
Exemple #13
0
static void
fill_stat_element(awk_array_t element_array, const char *name, struct stat *sbuf)
{
	awk_value_t index, value;
	awk_array_t stat_array;

	stat_array = create_array();
	if (stat_array == NULL) {
		warning(ext_id, _("fill_stat_element: could not create array"));
		fts_errors++;
		return;
	}
	fill_stat_array(name, stat_array, sbuf);
	(void) make_const_string("stat", 4, & index);
	value.val_type = AWK_ARRAY;
	value.array_cookie = stat_array;
	if (! set_array_element(element_array, & index, & value)) {
		warning(ext_id, _("fill_stat_element: could not set element"));
		fts_errors++;
	}
}
/**
 * Initializes the time.
 *
 * @param p0 the transient model
 * @param p1 the persistent model
 * @param p2 the persistent model size
 */
void initialize_time(void* p0, const void* p1, const void* p2) {

    log_message((void*) &INFO_LOG_LEVEL, (void*) &"Initialize time.");

//??    fscanf(p1, %d, &(m->value));

    // Initialize elements.
    int s = 0;
    int min = 0;
    int h = 0;
    int d = 0;
    int m = 0;
    int y = 0;

    // Set elements.
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &YEAR_INDEX, (void*) &y);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &MONTH_INDEX, (void*) &m);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &DAY_INDEX, (void*) &d);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &HOUR_INDEX, (void*) &h);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &MINUTE_INDEX, (void*) &min);
    set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SECOND_INDEX, (void*) &s);
}
Exemple #15
0
/**
 * Reads file.
 *
 * @param p0 the array
 * @param p1 the array count
 * @param p2 the array size
 * @param p3 the file name
 * @param p4 the file name count
 */
void read_file(void* p0, void* p1, void* p2, const void* p3, const void* p4) {

    if (p4 != NULL_POINTER) {

        int* nc = (int*) p4;

        if (p3 != NULL_POINTER) {

            void** n = (void**) p3;

            if (p2 != NULL_POINTER) {

                int* as = (int*) p2;

                if (p1 != NULL_POINTER) {

                    int* ac = (int*) p1;

                    // Initialize terminated file name and its size.
                    char* tn = CHARACTER_NULL_POINTER;
                    int tns = *nc + 1;

                    // Create terminated file name.
                    create_array((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &tns);

                    // Initialize destination array index.
                    int i = 0;

                    // Set terminated file name by first copying the actual name and then
                    // adding the null termination character.
                    set_array_elements((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &i, p3, p4);
                    set_array_element((void*) &tn, (void*) &CHARACTER_ARRAY, p4, (void*) &NULL_CHARACTER);

    fprintf(stderr, "read file name: %s\n", tn);
    fprintf(stderr, "read file name size: %i\n", tns);

                    // Open file.
                    // CAUTION! The file name cannot be handed over as is.
                    // CYBOI strings are NOT terminated with the null character '\0'.
                    // Since 'fopen' expects a null terminated string, the termination character
                    // must be added to the string before that is used to open the file.
                    FILE* f = fopen(tn, "r");

                    if (f != NULL_POINTER) {

                        // Read first character.
                        char c = fgetc(f);

                        while (1) {

                            if (c == EOF) {

                                break;
                            }

                            if (*ac == *as) {

                                // Increase size.
                                *as = *as * FILE_RESIZE_FACTOR + 1;

                                // Resize array.
                                resize_array(p0, (void*) &CHARACTER_ARRAY, p2);
                            }

                            if (*ac < *as) {

                                // Set character in destination array.
                                // The array count serves as index for setting the character.
                                set_array_element(p0, (void*) &CHARACTER_ARRAY, p1, (void*) &c);

                                // Increase array count.
                                (*ac)++;

                            } else {

//??                                log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The index exceeds the array size.");
                            }

                            // Read next character.
                            c = fgetc(f);
                        }

                        // Close file.
                        fclose(f);

                        // Destroy terminated file name.
                        destroy_array((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &tns);

                    } else {

//??                        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file is null.");
                    }

                } else {

//??                    log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The array count is null.");
                }

            } else {

//??                log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The array size is null.");
            }

        } else {

//??            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file name is null.");
        }

    } else {

//??        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file name count is null.");
    }
}
Exemple #16
0
static awk_value_t *
try_modify_environ(int nargs, awk_value_t *result)
{
	awk_value_t value, index, newvalue;
	awk_flat_array_t *flat_array;
	awk_array_t environ_array;
	size_t count;
	int i;

	assert(result != NULL);
	make_number(0.0, result);

	if (nargs != 0) {
		printf("try_modify_environ: nargs not right (%d should be 0)\n", nargs);
		goto out;
	}

	/* get ENVIRON array */
	if (sym_lookup("ENVIRON", AWK_ARRAY, & value))
		printf("try_modify_environ: sym_lookup of ENVIRON passed\n");
	else {
		printf("try_modify_environ: sym_lookup of ENVIRON failed\n");
		goto out;
	}

	environ_array = value.array_cookie;
	if (! get_element_count(environ_array, & count)) {
		printf("try_modify_environ: get_element_count failed\n");
		goto out;
	}

	/* setting an array element should fail */
	(void) make_const_string("testext2", 8, & index);
	(void) make_const_string("a value", 7, & value);
	if (set_array_element(environ_array, & index, & newvalue)) {
		printf("try_modify_environ: set_array_element of ENVIRON passed\n");
	} else {
		printf("try_modify_environ: set_array_element of ENVIRON failed\n");
		gawk_free(index.str_value.str);
		gawk_free(value.str_value.str);
	}

	if (! flatten_array(environ_array, & flat_array)) {
		printf("try_modify_environ: could not flatten array\n");
		goto out;
	}

	if (flat_array->count != count) {
		printf("try_modify_environ: flat_array->count (%lu) != count (%lu)\n",
				(unsigned long) flat_array->count,
				(unsigned long) count);
		goto out;
	}

	for (i = 0; i < flat_array->count; i++) {
		/* don't print */
	/*
		printf("\t%s[\"%.*s\"] = %s\n",
			name,
			(int) flat_array->elements[i].index.str_value.len,
			flat_array->elements[i].index.str_value.str,
			valrep2str(& flat_array->elements[i].value));
	*/
		if (strcmp("testext", flat_array->elements[i].index.str_value.str) == 0) {
			flat_array->elements[i].flags |= AWK_ELEMENT_DELETE;
			printf("try_modify_environ: marking element \"%s\" for deletion\n",
				flat_array->elements[i].index.str_value.str);
		}
	}

	if (! release_flattened_array(environ_array, flat_array)) {
		printf("try_modify_environ: could not release flattened array\n");
		goto out;
	}

	make_number(1.0, result);
out:
	return result;
}
Exemple #17
0
static void
process(FTS *heirarchy, awk_array_t destarray, int seedot)
{
	FTSENT *fentry;
	awk_value_t index, value;
	awk_array_t element_array, newdir_array, dot_array;
	int bad_ret = 0;

	/* path is full path,  pathlen is length thereof */
	/* name is name in directory, namelen is length thereof */
	while ((fentry = fts_read(heirarchy)) != NULL) {
		bad_ret = 0;

		switch (fentry->fts_info) {
		case FTS_D:
			/* directory */
			/* create array to hold entries */
			newdir_array = create_array();
			if (newdir_array == NULL) {
				warning(ext_id, _("fts-process: could not create array"));
				fts_errors++;
				break;
			}

			/* store new directory in its parent directory */
			(void) make_const_string(fentry->fts_name, fentry->fts_namelen, & index);
			value.val_type = AWK_ARRAY;
			value.array_cookie = newdir_array;
			if (! set_array_element(destarray, & index, & value)) {
				warning(ext_id, _("fts-process: could not set element"));
				fts_errors++;
				break;
			}
			newdir_array = value.array_cookie;

			/* push current directory */
			stack_push(destarray);

			/* new directory becomes current */
			destarray = newdir_array;
			break;

		case FTS_DNR:
		case FTS_DC:
		case FTS_ERR:
		case FTS_NS:
			/* error */
			bad_ret = 1;
			/* fall through */

		case FTS_NSOK:
		case FTS_SL:
		case FTS_SLNONE:
		case FTS_F:
		case FTS_DOT:
			/* if see dot, skip "." */
			if (seedot && strcmp(fentry->fts_name, ".") == 0)
				break;

			/*
			 * File case.
			 * destarray is the directory we're reading.
			 * step 1: create new empty array
			 */
			element_array = create_array();
			if (element_array == NULL) {
				warning(ext_id, _("fts-process: could not create array"));
				fts_errors++;
				break;
			}

			/* step 2: add element array to parent array */
			(void) make_const_string(fentry->fts_name, fentry->fts_namelen, & index);
			value.val_type = AWK_ARRAY;
			value.array_cookie = element_array;
			if (! set_array_element(destarray, & index, & value)) {
				warning(ext_id, _("fts-process: could not set element"));
				fts_errors++;
				break;
			}

			/* step 3: fill in path, stat, error elements */
			fill_default_elements(element_array, fentry, bad_ret);
			break;

		case FTS_DP:
			/* create "." subarray */
			dot_array = create_array();

			/* add it to parent */
			(void) make_const_string(".", 1, & index);
			value.val_type = AWK_ARRAY;
			value.array_cookie = dot_array;
			if (! set_array_element(destarray, & index, & value)) {
				warning(ext_id, _("fts-process: could not set element"));
				fts_errors++;
				break;
			}

			/* fill it in with path, stat, error elements */
			fill_default_elements(dot_array, fentry, bad_ret);

			/* now pop the parent directory off the stack */
			if (! stack_empty()) {
				/* pop stack */
				destarray = stack_pop();
			}

			break;

		case FTS_DEFAULT:
			/* nothing to do */
			break;
		}
	}
}
/**
 * Sets the signal.
 *
 * @param p0 the signal memory
 * @param p1 the signal
 * @param p2 the priority
 * @param p3 the abstraction
 * @param p4 the abstraction size
 */
void set_signal(void* p0, const void* p1, const void* p2, const void* p3, const void* p4) {

    // Initialize elements.
    int s = 0;
    int c = 0;
    void* sig = NULL_POINTER;
    void* p = NULL_POINTER;
    void* a = NULL_POINTER;
    void* as = NULL_POINTER;

    // Get elements.
    get_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_SIZE_INDEX, (void*) &s);
    get_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_COUNT_INDEX, (void*) &c);
    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &SIGNALS_INDEX, (void*) &sig);
    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &PRIORITIES_INDEX, (void*) &p);
    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_INDEX, (void*) &a);
    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_SIZES_INDEX, (void*) &as);

    // The index.
    int i = c;

    if (i >= 0) {

        if (i == s) {

            // Increase size.
            s = s * 2 + 1;

            // Resize elements.
            resize_array((void*) &sig, (void*) &POINTER_ARRAY, (void*) &s);
            resize_array((void*) &p, (void*) &INTEGER_ARRAY, (void*) &s);
            resize_array((void*) &a, (void*) &POINTER_ARRAY, (void*) &s);
            resize_array((void*) &as, (void*) &INTEGER_ARRAY, (void*) &s);

            // Set array size which is equal for all arrays.
            set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_SIZE_INDEX, (void*) &s);
        }

        if (i < s) {

            // Set signal.
            set_array_element((void*) &sig, (void*) &POINTER_ARRAY, (void*) &i, p1);
            set_array_element((void*) &p, (void*) &INTEGER_ARRAY, (void*) &i, p2);
            set_array_element((void*) &a, (void*) &POINTER_ARRAY, (void*) &i, p3);
            set_array_element((void*) &as, (void*) &INTEGER_ARRAY, (void*) &i, p4);

            // Increment count.
            c++;

            // Set count.
            set_array_element(p0, (void*) &INTEGER_ARRAY, (void*) &SIGNALS_COUNT_INDEX, (void*) &c);

        } else {

            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set signal. The index exceeds the size.");
        }

    } else {

        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set signal. The index is negativ.");
    }
}
/**
 * Sets the compound element by index.
 *
 * @param p0 the compound
 * @param p1 the compound count
 * @param p2 the compound size
 * @param p3 the index
 * @param p4 the name
 * @param p5 the name count
 * @param p6 the name size
 * @param p7 the abstraction
 * @param p8 the abstraction count
 * @param p9 the abstraction size
 * @param p10 the model
 * @param p11 the model count
 * @param p12 the model size
 * @param p13 the details
 * @param p14 the details count
 * @param p15 the details size
 */
void set_compound_element_by_index(void* p0, void* p1, void* p2,
    const void* p3,
    const void* p4, const void* p5, const void* p6,
    const void* p7, const void* p8, const void* p9,
    const void* p10, const void* p11, const void* p12,
    const void* p13, const void* p14, const void* p15) {

    if (p3 != NULL_POINTER) {

        int* i = (int*) p3;

        if (p2 != NULL_POINTER) {

            int* cs = (int*) p2;

            if (p1 != NULL_POINTER) {

                int* cc = (int*) p1;

                if (*i >= 0) {

//??                    log_message((void*) &INFO_LOG_LEVEL, (void*) &"Set compound element by index.");

                    // The names, models, abstractions, details.
                    void* n = NULL_POINTER;
                    void* nc = NULL_POINTER;
                    void* ns = NULL_POINTER;
                    void* a = NULL_POINTER;
                    void* ac = NULL_POINTER;
                    void* as = NULL_POINTER;
                    void* m = NULL_POINTER;
                    void* mc = NULL_POINTER;
                    void* ms = NULL_POINTER;
                    void* d = NULL_POINTER;
                    void* dc = NULL_POINTER;
                    void* ds = NULL_POINTER;

                    // Get names, models, abstractions, details.
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &NAMES_INDEX, (void*) &n);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &NAMES_COUNTS_INDEX, (void*) &nc);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &NAMES_SIZES_INDEX, (void*) &ns);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_INDEX, (void*) &a);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_COUNTS_INDEX, (void*) &ac);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &ABSTRACTIONS_SIZES_INDEX, (void*) &as);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &MODELS_INDEX, (void*) &m);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &MODELS_COUNTS_INDEX, (void*) &mc);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &MODELS_SIZES_INDEX, (void*) &ms);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &DETAILS_INDEX, (void*) &d);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &DETAILS_COUNTS_INDEX, (void*) &dc);
                    get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &DETAILS_SIZES_INDEX, (void*) &ds);

                    if (*i == *cs) {

                        // Increase size.
                        *cs = (*cs * COMPOUND_RESIZE_FACTOR) + 1;

                        // Resize names, models, abstractions, details.
                        resize_array((void*) &n, (void*) &POINTER_ARRAY, p2);
                        resize_array((void*) &nc, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &ns, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &a, (void*) &POINTER_ARRAY, p2);
                        resize_array((void*) &ac, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &as, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &m, (void*) &POINTER_ARRAY, p2);
                        resize_array((void*) &mc, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &ms, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &d, (void*) &POINTER_ARRAY, p2);
                        resize_array((void*) &dc, (void*) &INTEGER_ARRAY, p2);
                        resize_array((void*) &ds, (void*) &INTEGER_ARRAY, p2);
                    }

                    if (*i < *cs) {

                        // Set name, model, abstraction, details.
                        set_array_element((void*) &n, (void*) &POINTER_ARRAY, p3, p4);
                        set_array_element((void*) &nc, (void*) &INTEGER_ARRAY, p3, p5);
                        set_array_element((void*) &ns, (void*) &INTEGER_ARRAY, p3, p6);
                        set_array_element((void*) &a, (void*) &POINTER_ARRAY, p3, p7);
                        set_array_element((void*) &ac, (void*) &INTEGER_ARRAY, p3, p8);
                        set_array_element((void*) &as, (void*) &INTEGER_ARRAY, p3, p9);
                        set_array_element((void*) &m, (void*) &POINTER_ARRAY, p3, p10);
                        set_array_element((void*) &mc, (void*) &INTEGER_ARRAY, p3, p11);
                        set_array_element((void*) &ms, (void*) &INTEGER_ARRAY, p3, p12);
                        set_array_element((void*) &d, (void*) &POINTER_ARRAY, p3, p13);
                        set_array_element((void*) &dc, (void*) &INTEGER_ARRAY, p3, p14);
                        set_array_element((void*) &ds, (void*) &INTEGER_ARRAY, p3, p15);

                        // Increment count.
                        (*cc)++;

                    } else {

//??                        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set compound element by index. The index exceeds the size.");
                    }

                } else {

//??                    log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set compound element by index. The index is negativ.");
                }

            } else {

//??                log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set compound element by index. The count is null.");
            }

        } else {

//??            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set compound element by index. The size is null.");
        }

    } else {

//??        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not set compound element by index. The index is null.");
    }
}
Exemple #20
0
/**
 * Tests the character array with a single element.
 */
void test_character_array_single_element() {

    // Character array.
    fputs("Character array:\n", stdout);

    void* ca = NULL_POINTER;
    int cas = 5;
    create_array((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &cas);

    int ca1i = 0;
    char ca1 = 'a';
    int ca2i = 1;
    char ca2 = 'b';
    int ca3i = 2;
    char ca3 = 'c';
    int ca4i = 3;
    char ca4 = '\n';
    int ca5i = 4;
    char ca5 = '\0';

    set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca1i, (void*) &ca1);
    set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca2i, (void*) &ca2);
    set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca3i, (void*) &ca3);
    set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca4i, (void*) &ca4);
    set_array_element((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &ca5i, (void*) &ca5);

    // Print out array contents.
    fputs((char*) ca, stdout);

    int i = 0;
    char* catest = CHARACTER_NULL_POINTER;

    while (1) {

        if (i >= cas) {

            break;
        }

        catest = (char*) (ca + i);
        fprintf(stderr, "ca: %c\n", *catest);

        i++;
    }

    destroy_array((void*) &ca, (void*) &CHARACTER_ARRAY, (void*) &cas);

    // Integer array.
    fputs("Integer array:\n", stdout);

    void* ia = NULL_POINTER;
    int ias = 5 * INTEGER_PRIMITIVE_SIZE;
    create_array((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ias);

    int ia1i = 0 * INTEGER_PRIMITIVE_SIZE;
    int ia1 = 9;
    int ia2i = 1 * INTEGER_PRIMITIVE_SIZE;
    int ia2 = 8;
    int ia3i = 2 * INTEGER_PRIMITIVE_SIZE;
    int ia3 = 7;
    int ia4i = 3 * INTEGER_PRIMITIVE_SIZE;
    int ia4 = 6;
    int ia5i = 4 * INTEGER_PRIMITIVE_SIZE;
    int ia5 = 5;

    set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia1i, (void*) &ia1);
    set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia2i, (void*) &ia2);
    set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia3i, (void*) &ia3);
    set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia4i, (void*) &ia4);
    set_array_element((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ia5i, (void*) &ia5);

    // Print out array contents.
    int j = 0;
    int* iatest = INTEGER_NULL_POINTER;

    while (1) {

        if (j * INTEGER_PRIMITIVE_SIZE >= ias) {

            break;
        }

        iatest = (int*) (ia + j * INTEGER_PRIMITIVE_SIZE);
        fprintf(stderr, "ia: %d\n", *iatest);

        j++;
    }

    destroy_array((void*) &ia, (void*) &INTEGER_ARRAY, (void*) &ias);

    //
    // Caution! In any case consider the size of the type, for all array!
    // Example: index * INTEGER_PRIMITIVE_SIZE
    //
}
Exemple #21
0
/*
BEGIN {
	n = split("one two three four five six", test_array2)
	ret = test_array_elem(test_array2, "3")
	printf("test_array_elem() returned %d, test_array2[3] = %g\n", ret, test_array2[3])
	if ("5" in test_array2)
		printf("error: test_array_elem() did not remove element \"5\"\n")
	else
		printf("test_array_elem() did remove element \"5\"\n")
	if ("7" in test_array2)
		printf("test_array_elem() added element \"7\" --> %s\n", test_array2[7])
	else
		printf("test_array_elem() did not add element \"7\"\n")
	if ("subarray" in test_array2) {
		if (isarray(test_array2["subarray"])) {
			for (i in test_array2["subarray"])
				printf("test_array2[\"subarray\"][\"%s\"] = %s\n",
					i, test_array2["subarray"][i])
		} else
			printf("test_array_elem() added element \"subarray\" as scalar\n")
	} else
		printf("test_array_elem() did not add element \"subarray\"\n")
	print ""
}
*/
static awk_value_t *
test_array_elem(int nargs, awk_value_t *result)
{
	awk_value_t array, index, index2, value;

	make_number(0.0, result);	/* default return until full success */

	assert(result != NULL);

	if (nargs != 2) {
		printf("test_array_elem: nargs not right (%d should be 2)\n", nargs);
		goto out;
	}

	/* look up an array element and print the value */
	if (! get_argument(0, AWK_ARRAY, & array)) {
		printf("test_array_elem: get_argument 0 (array) failed\n");
		goto out;
	}
	if (! get_argument(1, AWK_STRING, & index)) {
		printf("test_array_elem: get_argument 1 (index) failed\n");
		goto out;
	}
	(void) make_const_string(index.str_value.str, index.str_value.len, & index2);
	if (! get_array_element(array.array_cookie, & index2, AWK_UNDEFINED, & value)) {
		printf("test_array_elem: get_array_element failed\n");
		goto out;
	}
	printf("test_array_elem: a[\"%.*s\"] = %s\n",
			(int) index.str_value.len,
			index.str_value.str,
			valrep2str(& value));

	/* change the element - "3" */
	(void) make_number(42.0, & value);
	(void) make_const_string(index.str_value.str, index.str_value.len, & index2);
	if (! set_array_element(array.array_cookie, & index2, & value)) {
		printf("test_array_elem: set_array_element failed\n");
		goto out;
	}

	/* delete another element - "5" */
	(void) make_const_string("5", 1, & index);
	if (! del_array_element(array.array_cookie, & index)) {
		printf("test_array_elem: del_array_element failed\n");
		goto out;
	}

	/* add a new element - "7" */
	(void) make_const_string("7", 1, & index);
	(void) make_const_string("seven", 5, & value);
	if (! set_array_element(array.array_cookie, & index, & value)) {
		printf("test_array_elem: set_array_element failed\n");
		goto out;
	}

	/* add a subarray */
	(void) make_const_string("subarray", 8, & index);
	fill_in_array(& value);
	if (! set_array_element(array.array_cookie, & index, & value)) {
		printf("test_array_elem: set_array_element (subarray) failed\n");
		goto out;
	}

	/* change and deletion should be reflected in awk script */
	make_number(1.0, result);
out:
	return result;
}