/** * Tests the character array with multiple elements. */ void test_character_array_multiple_elements() { log_write_terminated_message((void*) stdout, L"Test character array multiple elements:\n"); // The destination array. void* d = *NULL_POINTER_MEMORY_MODEL; int ds = *NUMBER_22_INTEGER_MEMORY_MODEL; // Create destination array. allocate_array((void*) &d, (void*) &ds, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // The source array. wchar_t a[] = {L'T', L'h', L'i', L's', L' ', L'i', L's', L' ', L'a', L' ', L't', L'e', L's', L't', L'.', L'\n', L'\0'}; wchar_t* s = a; int ssa[] = {17}; int* ss = ssa; // The destination index to which to copy the source array. //?? overwrite_array(d, (void*) s, (void*) ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The source array for overwriting. wchar_t oa[] = {L'o', L'v', L'e', L'r', L'w', L'r', L'i', L't', L't', L'e', L'n', L'.', L'\n', L'\0'}; wchar_t* os = oa; int ossa[] = {14}; int* oss = ossa; //?? overwrite_array(d, (void*) os, (void*) oss, (void*) NUMBER_8_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The remove index. int ri = *NUMBER_12_INTEGER_MEMORY_MODEL; remove_array_elements(d, (void*) &ds, (void*) &ri, (void*) NUMBER_7_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The new array size to cut off remaining elements, // including two places for new line '\n' and c string termination '\0'. int ns = *NUMBER_15_INTEGER_MEMORY_MODEL; reallocate_array((void*) &d, (void*) &ns, (void*) &ns, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) d); // The result array. void* r = *NULL_POINTER_MEMORY_MODEL; // Test getting a reference. get_array_elements((void*) &r, d, (void*) NUMBER_8_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); log_write_terminated_message((void*) stdout, (wchar_t*) r); // Destroy destination array. deallocate_array((void*) &d, (void*) &ns, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Encodes the character vector model and creates an ascii character byte stream from it. * * @param p0 the destination (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source * @param p4 the source count */ void encode_ascii_character_vector(void* p0, void* p1, void* p2, void* p3, void* p4) { if (p4 != *NULL_POINTER_MEMORY_MODEL) { int* sc = (int*) p4; if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* ds = (int*) p2; if (p1 != *NULL_POINTER_MEMORY_MODEL) { int* dc = (int*) p1; if (p0 != *NULL_POINTER_MEMORY_MODEL) { void** d = (void**) p0; log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Encode ascii character vector."); if ((*dc + *sc) >= *ds) { // The new destination character vector size. // CAUTION! Add constant in case *dc is zero! *ds = (*dc * *ARRAY_REALLOCATION_FACTOR) + *sc; // Reallocate destination character vector. reallocate_array(p0, p1, p2, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } // Set source into destination character vector. overwrite_array(p0, p3, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, p4, p1, (void*) VALUE_PRIMITIVE_MEMORY_NAME, p1, p2); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not encode ascii character vector. The destination is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not encode ascii character vector. The destination count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not encode ascii character vector. The destination size is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not encode ascii character vector. The source count is null."); } }
/** * @name read_line: * Read a line portably, relying only upon the C library's * `getc` standard I/O function. This should work on any * platform that has a standard I/O (stdio) implementation. */ char *read_line(FILE *stream, boolean_t *eof) { int c; unsigned int i = 0; size_t size = read_line_size_start; char *rv = allocate_array(sizeof(char), size, 1); for (;;) { if (!size || i >= size) { if ((size *= 8) >= read_line_size_maximum) { goto allocation_error; } if (!(rv = reallocate_array(rv, sizeof(char), size, 1))) { goto allocation_error; } } c = getc(stream); if (c == '\n') { break; } else if (c == EOF) { *eof = TRUE; break; } rv[i++] = c; } rv[i] = '\0'; return rv; allocation_error: if (rv) { free(rv); } return NULL; }
struct Buf * buf_append(struct Buf *buf, const void *ptr, int n_elem) { int n_alloc = 0; if (!ptr || n_elem == 0) return buf; /* May need to alloc more. */ if (n_elem + buf->nelts > buf->nmax) { /* exact amount needed... */ n_alloc = (n_elem + buf->nelts) * buf->elt_size; /* ...plus some extra */ if (((n_alloc * buf->elt_size) % 512) != 0 && buf->elt_size < 512) n_alloc += (512 - ((n_alloc * buf->elt_size) % 512)) / buf->elt_size; if (!buf->elts) buf->elts = allocate_array(n_alloc, buf->elt_size); else buf->elts = reallocate_array(buf->elts, n_alloc, buf->elt_size); buf->nmax = n_alloc; } memcpy((char *) buf->elts + buf->nelts * buf->elt_size, ptr, n_elem * buf->elt_size); buf->nelts += n_elem; return buf; }
/** * @name parsed_json_to_arguments: */ boolean_t parsed_json_to_arguments(parsed_json_t *p, int *argc, char **argv[], int *err) { int n = 0; char **rv = NULL; unsigned int size = 0; jsmntok_t *tokens = p->tokens; json_validation_state_t state = START; boolean_t matched_keys[] = { FALSE, FALSE }; unsigned int object_size = 0, array_size = 0; #define return_validation_error(e) \ do { *err = (e); goto validation_error; } while (0) #define token_lookahead(i, c) \ (((i) + (c)) < p->nr_tokens && \ !jsmn_token_is_invalid(tokens + (i) + (c)) ? \ (tokens + (i) + (c)) : NULL) /* For every token */ for (unsigned int i = 0; i < p->nr_tokens; ++i) { jsmntok_t *t = &tokens[i]; if (matched_keys[0] && matched_keys[1]) { state = SUCCESS; break; } if (jsmn_token_is_invalid(t)) { break; } if (!size || n >= size) { /* Increase size by a few orders of magnitude */ size = (size ? size * 8 : json_argument_list_start); /* Increase size, then check against memory limit */ if (size > json_argument_list_maximum) { return_validation_error(V_ERR_MEM_LIMIT); } /* Enlarge array of argument pointers */ if (!(rv = (char **) reallocate_array(rv, sizeof(char *), size, 1))) { return_validation_error(V_ERR_MEM_ALLOC); } } switch (state) { case START: { if (t->type != JSMN_OBJECT) { return_validation_error(V_ERR_ROOT_TYPE); } if (t->size % 2 != 0) { return_validation_error(V_ERR_PROPS_ODD); } object_size = t->size; state = IN_ROOT_OBJECT; break; } case IN_ROOT_OBJECT: { if (object_size <= 0) { break; } if (t->type != JSMN_STRING) { return_validation_error(V_ERR_PROPS_TYPE); } char *s = jsmn_stringify_token(p->json, t); if (!(t = token_lookahead(i, 1))) { return_validation_error(V_ERR_PROPS_ODD); } if (strcmp(s, "command") == 0) { if (t->type != JSMN_STRING) { return_validation_error(V_ERR_CMD_TYPE); } rv[0] = jsmn_stringify_token(p->json, t); matched_keys[0] = TRUE; } else if (strcmp(s, "arguments") == 0) { if (t->type != JSMN_ARRAY && t->type != JSMN_OBJECT) { return_validation_error(V_ERR_ARGS_TYPE); } /* Handle empty arrays */ jsmntok_t *tt = token_lookahead(i, 2); if (!tt || t->size <= 0) { matched_keys[1] = TRUE; } else { state = IN_ARGUMENTS_ARRAY; } /* Enter array */ array_size = t->size; } /* To walk the stair / steps in pairs */ object_size -= 2; i++; break; } case IN_ARGUMENTS_ARRAY: { if (t->type != JSMN_PRIMITIVE && t->type != JSMN_STRING) { return_validation_error(V_ERR_ARG_TYPE); } char *s = jsmn_stringify_token(p->json, t); /* Require that primitives are numeric */ if (t->type == JSMN_PRIMITIVE && (!s || !isdigit(s[0]))) { return_validation_error(V_ERR_ARGS_NUMERIC); } rv[++n] = s; if (--array_size <= 0) { matched_keys[1] = TRUE; state = IN_ROOT_OBJECT; } break; } case SUCCESS: { goto successful; } default: { return_validation_error(V_ERR_UNKNOWN); break; } } } if (state != SUCCESS) { return_validation_error(V_ERR_PROPS_MISSING); } /* Victory */ successful: /* Null-terminate */ rv[n + 1] = NULL; /* Return values */ *argv = rv; *argc = n + 1; /* Success */ return TRUE; /* Non-victory */ validation_error: if (rv) { free(rv); } return FALSE; }
/** * @name parse_json: */ parsed_json_t *parse_json(char *json) { parsed_json_t *rv = (parsed_json_t *) allocate(sizeof(parsed_json_t)); if (!rv) { return NULL; } rv->json = json; rv->tokens = NULL; rv->nr_tokens = 0; unsigned int n = json_parser_tokens_start; for (;;) { /* Check against upper limit */ if (n > json_parser_tokens_maximum) { goto allocation_error; } jsmn_init(&rv->parser); rv->tokens = reallocate_array(rv->tokens, sizeof(jsmntok_t), n, 0); if (!rv->tokens) { goto allocation_error; } /* Set all tokens to invalid */ for (unsigned int i = 0; i < n; ++i) { jsmn_mark_token_invalid(&rv->tokens[i]); } /* Parse */ jsmnerr_t result = jsmn_parse(&rv->parser, json, rv->tokens, n); /* Not enough room to parse the full string? * Increase the available token space by a couple (base two) * orders of magnitude, then go around, reallocate, and retry. */ if (result == JSMN_ERROR_NOMEM) { n *= 4; continue; } if (result < 0) { goto allocation_error; } /* Parsed successfully */ rv->nr_tokens = n; break; } /* Success */ return rv; /* Error: * Clean up the `rv` structure and its members. */ allocation_error: if (rv->tokens) { free(rv->tokens); } free(rv); return NULL; }
/** * Reallocates the model. * * @param p0 the model (Hand over as reference!) * @param p1 the model count * @param p2 the model size * @param p3 the abstraction * @param p4 the abstraction count */ void reallocate(void* p0, void* p1, void* p2, void* p3, void* p4) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Reallocate."); // The comparison result. int r = *NUMBER_0_INTEGER_MEMORY_MODEL; if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) CHARACTER_MEMORY_ABSTRACTION, (void*) CHARACTER_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) COMPOUND_MEMORY_ABSTRACTION, (void*) COMPOUND_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_compound(p0, p1, p2); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) DOUBLE_MEMORY_ABSTRACTION, (void*) DOUBLE_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) DOUBLE_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) ENCAPSULATED_KNOWLEDGE_PATH_MEMORY_ABSTRACTION, (void*) ENCAPSULATED_KNOWLEDGE_PATH_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) KNOWLEDGE_PATH_MEMORY_ABSTRACTION, (void*) KNOWLEDGE_PATH_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) OPERATION_MEMORY_ABSTRACTION, (void*) OPERATION_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) POINTER_MEMORY_ABSTRACTION, (void*) POINTER_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) SIGNAL_MEMORY_MEMORY_ABSTRACTION, (void*) SIGNAL_MEMORY_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_signal_memory(p0, p1, p2); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) UNSIGNED_LONG_MEMORY_ABSTRACTION, (void*) UNSIGNED_LONG_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) UNSIGNED_LONG_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_equal_arrays((void*) &r, p3, p4, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION_COUNT, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { reallocate_array(p0, p1, p2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { log_terminated_message((void*) WARNING_LEVEL_LOG_MODEL, (void*) L"Could not reallocate. The abstraction is unknown."); } }
/** * Optionalises the log file option. * * @param p0 the log file (Hand over as reference!) * @param p1 the log file name * @param p2 the log file name count */ void optionalise_log_file(void* p0, void* p1, void* p2) { if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* nc = (int*) p2; if (p0 != *NULL_POINTER_MEMORY_MODEL) { FILE** f = (FILE**) p0; // CAUTION! DO NOT use logging functionality here! // The logger will not work before its options are set. // Comment out this function call to avoid disturbing messages at system startup! // log_write_terminated_message((void*) stdout, L"Debug: Optionalise log file.\n"); // The terminated file name as character array. void* t = *NULL_POINTER_MEMORY_MODEL; void* tc = *NULL_POINTER_MEMORY_MODEL; void* ts = *NULL_POINTER_MEMORY_MODEL; // // CAUTION! Do NOT use a wide character array here! // // The glibc file stream functions expect standard (multibyte) character arrays. // // Allocate terminated file name as multibyte character array. allocate_model((void*) &t, (void*) &tc, (void*) &ts, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) CHARACTER_MEMORY_ABSTRACTION, (void*) CHARACTER_MEMORY_ABSTRACTION_COUNT); // Encode wide character option into multibyte character array. encode_utf_8_unicode_character_vector((void*) &t, tc, ts, p1, p2); if (*((int*) ts) <= *((int*) tc)) { // Increase character array size to have place for the termination character. ts = tc + *NUMBER_1_INTEGER_MEMORY_MODEL; // Reallocate terminated file name as multibyte character array. reallocate_array((void*) &t, tc, ts, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } // Add null termination character to terminated file name. replace_array(t, (void*) NULL_CONTROL_ASCII_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, tc, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Increase terminated file name count. (*((int*) tc))++; // Open log file for writing only. // If the file already exists, it is truncated to zero length. // Otherwise a new file is created. // // FILE objects are allocated and managed internally by the input/ output // library functions. The library creates objects of type FILE. // Programs should deal only with pointers to these objects (FILE* values), // rather than the objects themselves. *f = fopen((char*) t, "w"); if (*f != *NULL_POINTER_MEMORY_MODEL) { // The file owner. int o = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // The file group. int g = *NUMBER_MINUS_1_INTEGER_MEMORY_MODEL; // Set file owner. chown((char*) t, o, g); // The file access rights. //?? TODO: When trying to cross-compile cyboi for windows, //?? the two S_IRGRP and S_IWGRP were not recognised by mingw. int r = S_IRUSR | S_IWUSR; //?? | S_IRGRP | S_IWGRP; // Set file access rights. chmod((char*) t, r); } else { // CAUTION! DO NOT use logging functionality here! // The logger will not work before its options are set. log_write_terminated_message((void*) stdout, L"Error: Could not optionalise log file. An error occured when trying to open or create the file for writing.\n"); } // Deallocate terminated file name as multibyte character array. deallocate_model((void*) &t, (void*) &tc, (void*) &ts, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) CHARACTER_MEMORY_ABSTRACTION, (void*) CHARACTER_MEMORY_ABSTRACTION_COUNT); } else { // CAUTION! DO NOT use logging functionality here! // The logger will not work before its options are set. log_write_terminated_message((void*) stdout, L"Error: Could not optionalise log file. The file descriptor is null.\n"); } } else { // CAUTION! DO NOT use logging functionality here! // The logger will not work before its options are set. log_write_terminated_message((void*) stdout, L"Error: Could not optionalise log file. The file name count is null.\n"); } }
/** * Gets the host address. * * @param p0 the ipv4 or ipv6 host address, depending on the address namespace (Hand over as reference!) * @param p1 the address model * @param p2 the address model count * @param p3 the address namespace */ void startup_socket_get_host_address(void* p0, void* p1, void* p2, void* p3) { if (p3 != *NULL_POINTER_MEMORY_MODEL) { int* an = (int*) p3; if (p0 != *NULL_POINTER_MEMORY_MODEL) { struct in_addr* a4 = (struct in_addr*) *NULL_POINTER_MEMORY_MODEL; struct in6_addr* a6 = (struct in6_addr*) *NULL_POINTER_MEMORY_MODEL; if (*an == AF_INET) { a4 = (struct in_addr*) p0; } else if (*an == AF_INET6) { a6 = (struct in6_addr*) p0; } log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Startup socket get host address."); // The comparison result. int r = *NUMBER_0_INTEGER_MEMORY_MODEL; if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_integer_equal((void*) &r, p1, (void*) LOOPBACK_ADDRESS_CYBOL_MODEL); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { if (*an == AF_INET) { (*a4).s_addr = INADDR_LOOPBACK; } else if (*an == AF_INET6) { *a6 = in6addr_loopback; } } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { compare_integer_equal((void*) &r, p1, (void*) ANY_ADDRESS_CYBOL_MODEL); if (r != *NUMBER_0_INTEGER_MEMORY_MODEL) { if (*an == AF_INET) { (*a4).s_addr = INADDR_ANY; } else if (*an == AF_INET6) { *a6 = in6addr_any; } } } if (r == *NUMBER_0_INTEGER_MEMORY_MODEL) { // If none of the above address models was found, then the given // address is supposed to be the host address directly. // The terminated address model. void* s = *NULL_POINTER_MEMORY_MODEL; void* sc = *NULL_POINTER_MEMORY_MODEL; void* ss = *NULL_POINTER_MEMORY_MODEL; // Allocate terminated address model. allocate_model((void*) &s, (void*) &sc, (void*) &ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) CHARACTER_MEMORY_ABSTRACTION, (void*) CHARACTER_MEMORY_ABSTRACTION_COUNT); // Encode wide character name into multibyte character array. encode_utf_8_unicode_character_vector((void*) &s, sc, ss, p1, p2); if (*((int*) ss) <= *((int*) sc)) { // Increase character array size to have place for the termination character. *((int*) ss) = *((int*) sc) + *NUMBER_1_INTEGER_MEMORY_MODEL; // Reallocate terminated file name as multibyte character array. reallocate_array((void*) &s, sc, ss, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); } // Add null termination character to terminated file name. overwrite_array((void*) &s, (void*) NULL_CONTROL_ASCII_CHARACTER_CODE_MODEL, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, sc, (void*) VALUE_PRIMITIVE_MEMORY_NAME, sc, ss); // Convert uint16_t integer hostshort from host byte order // to network byte order. inet_pton(*an, (char*) s, p0); // Deallocate terminated address model. deallocate_model((void*) &s, (void*) &sc, (void*) &ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) CHARACTER_MEMORY_ABSTRACTION, (void*) CHARACTER_MEMORY_ABSTRACTION_COUNT); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not get startup socket host address. The host address is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not get startup socket host address. The address namespace is null."); } }
/** * @param classRecord Record for method class. * @param methodRecord Calle's method record. * @param retAddr What the PC should be upon return. * @return true iff the stack frame was pushed. */ boolean dispatch_special (MethodRecord *methodRecord, byte *retAddr) { #if DEBUG_METHODS int debug_ctr; #endif StackFrame *stackFrame; byte newStackFrameIndex; #if DEBUG_BYTECODE printf ("\n------ dispatch special - %d ------------------\n\n", methodRecord->signatureId); #endif #if DEBUG_METHODS printf ("dispatch_special: %d, %d\n", (int) methodRecord, (int) retAddr); printf ("-- signature id = %d\n", methodRecord->signatureId); printf ("-- code offset = %d\n", methodRecord->codeOffset); printf ("-- flags = %d\n", methodRecord->mflags); printf ("-- num params = %d\n", methodRecord->numParameters); printf ("-- stack ptr = %d\n", (int) get_stack_ptr()); printf ("-- max stack ptr= %d\n", (int) (currentThread->stackArray + (get_array_size(currentThread->stackArray))*2)); #endif pop_words (methodRecord->numParameters); pc = retAddr; if (is_native (methodRecord)) { #if DEBUG_METHODS printf ("-- native\n"); #endif dispatch_native (methodRecord->signatureId, get_stack_ptr() + 1); // Stack frame not pushed return false; } newStackFrameIndex = currentThread->stackFrameArraySize; if (newStackFrameIndex >= get_array_length((Object *) word2ptr (currentThread->stackFrameArray))) { #if !FIXED_STACK_SIZE // int len = get_array_length((Object *) word2ptr (currentThread->stackFrameArray)); int newlen = get_array_length((Object *) word2ptr (currentThread->stackFrameArray)) * 3 / 2; JINT newStackFrameArray = JNULL; // Stack frames are indexed by a byte value so limit the size. if (newlen <= 255) { // increase the stack frame size newStackFrameArray = ptr2word(reallocate_array(word2ptr(currentThread->stackFrameArray), newlen)); } // If can't allocate new stack, give in! if (newStackFrameArray == JNULL) { #endif throw_exception (stackOverflowError); return false; #if !FIXED_STACK_SIZE } // Assign new array currentThread->stackFrameArray = newStackFrameArray; #endif } if (newStackFrameIndex == 0) { // Assign NEW stack frame stackFrame = stackframe_array(); } else { #if DEBUG_METHODS for (debug_ctr = 0; debug_ctr < methodRecord->numParameters; debug_ctr++) printf ("-- param[%d] = %ld\n", debug_ctr, (long) get_stack_ptr()[debug_ctr+1]); #endif // Save OLD stackFrame state stackFrame = stackframe_array() + (newStackFrameIndex - 1); update_stack_frame (stackFrame); // Push NEW stack frame stackFrame++; } // Increment size of stack frame array currentThread->stackFrameArraySize++; // Initialize rest of new stack frame stackFrame->methodRecord = methodRecord; stackFrame->monitor = null; stackFrame->localsBase = get_stack_ptr() + 1; // Initialize auxiliary global variables (registers) pc = get_code_ptr(methodRecord); #if DEBUG_METHODS printf ("pc set to 0x%X\n", (int) pc); #endif init_sp (stackFrame, methodRecord); update_constant_registers (stackFrame); //printf ("m %d stack = %d\n", (int) methodRecord->signatureId, (int) (localsBase - stack_array())); // Check for stack overflow // (stackTop + methodRecord->maxOperands) >= (stack_array() + STACK_SIZE); if (is_stack_overflow (methodRecord)) { #if !FIXED_STACK_SIZE StackFrame *stackBase; int i; // Need at least this many bytes // int len = (int)(stackTop + methodRecord->maxOperands) - (int)(stack_array()) - HEADER_SIZE; // Need to compute new array size (as distinct from number of bytes in array). int newlen = (((int)(stackTop + methodRecord->maxOperands) - (int)(stack_array()) - HEADER_SIZE + 1) / 4) * 3 / 2; JINT newStackArray = ptr2word(reallocate_array(word2ptr(currentThread->stackArray), newlen)); // If can't allocate new stack, give in! if (newStackArray == JNULL) { #endif throw_exception (stackOverflowError); return false; #if !FIXED_STACK_SIZE } // Adjust pointers. newlen = newStackArray - currentThread->stackArray; stackBase = stackframe_array(); stackTop = word2ptr(ptr2word(stackTop) + newlen); localsBase = word2ptr(ptr2word(localsBase) + newlen); #if DEBUG_MEMORY printf("thread=%d, stackTop(%d), localsBase(%d)=%d\n", currentThread->threadId, (int)stackTop, (int)localsBase, (int)(*localsBase)); #endif for (i=currentThread->stackFrameArraySize-1; i >= 0; i--) { stackBase[i].localsBase = word2ptr(ptr2word(stackBase[i].localsBase) + newlen); stackBase[i].stackTop = word2ptr(ptr2word(stackBase[i].stackTop) + newlen); #if DEBUG_MEMORY printf("stackBase[%d].localsBase(%d) = %d\n", i, (int)stackBase[i].localsBase, (int)(*stackBase[i].localsBase)); #endif } // Assign new array currentThread->stackArray = newStackArray; #endif } return true; }
/** * Appends the compound element by name with suffix. * * The name suffix starts with "_$", e.g.: * part_$0 * part_$1 * channel_$2 * abstraction_$0 * * @param p0 the compound model * @param p1 the compound model count * @param p2 the compound model size * @param p3 the name (Hand over as reference!) * @param p4 the name count * @param p5 the name size * @param p6 the abstraction * @param p7 the abstraction count * @param p8 the abstraction size * @param p9 the model * @param p10 the model count * @param p11 the model size * @param p12 the details * @param p13 the details count * @param p14 the details size */ void append_compound_element_by_name_with_suffix(void* p0, void* p1, void* p2, void* p3, void* p4, void* p5, void* p6, void* p7, void* p8, void* p9, void* p10, void* p11, void* p12, void* p13, void* p14) { if (p5 != *NULL_POINTER_MEMORY_MODEL) { int* ns = (int*) p5; if (p4 != *NULL_POINTER_MEMORY_MODEL) { int* nc = (int*) p4; if (p3 != *NULL_POINTER_MEMORY_MODEL) { void** n = (void**) p3; log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Append compound element by name with suffix."); // The name suffix. void* s = *NULL_POINTER_MEMORY_MODEL; void* sc = *NULL_POINTER_MEMORY_MODEL; void* ss = *NULL_POINTER_MEMORY_MODEL; //?? fwprintf(stdout, L"TEST append compound element 0 p1 dc: %i\n", *((int*) p1)); // Allocate name suffix as wide character array. allocate_model((void*) &s, (void*) &sc, (void*) &ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION_COUNT); //?? fwprintf(stdout, L"TEST append compound element 1 ss: %i\n", *((int*) ss)); //?? fwprintf(stdout, L"TEST append compound element 1 sc: %i\n", *((int*) sc)); //?? fwprintf(stdout, L"TEST append compound element 1 s: %ls\n", (wchar_t*) s); // Use compound count as index to create the element name suffix, // because the element is appended at the end of the compound container. // The suffix integer is encoded into a wide character array. encode((void*) &s, sc, ss, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, p1, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, *NULL_POINTER_MEMORY_MODEL, (void*) INTEGER_MEMORY_ABSTRACTION, (void*) INTEGER_MEMORY_ABSTRACTION_COUNT); //?? fwprintf(stdout, L"TEST append compound element 2 ss: %i\n", *((int*) ss)); //?? fwprintf(stdout, L"TEST append compound element 2 sc: %i\n", *((int*) sc)); //?? fwprintf(stdout, L"TEST append compound element 2 s: %ls\n", (wchar_t*) s); // Resize name. if ((*nc + *LIST_SEPARATOR_CYBOL_NAME_COUNT + *((int*) sc)) >= *ns) { // The new name character vector size. // CAUTION! Append constant in case *nc is zero! *ns = (*nc * *ARRAY_REALLOCATION_FACTOR) + *LIST_SEPARATOR_CYBOL_NAME_COUNT + *((int*) sc); //?? fwprintf(stdout, L"TEST append compound element 2 ns pre: %i\n", *ns); // Reallocate name character vector. reallocate_array(p3, p4, p5, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); //?? fwprintf(stdout, L"TEST append compound element 2 ns post: %i\n", *ns); } //?? fwprintf(stdout, L"TEST append compound element 3 ss: %i\n", *((int*) ss)); //?? fwprintf(stdout, L"TEST append compound element 3 sc: %i\n", *((int*) sc)); //?? fwprintf(stdout, L"TEST append compound element 3 s: %ls\n", (wchar_t*) s); // The element name already contains the element base name. // Append list element separator characters "_$" to element name. // Use name count as index to append the new characters. replace_array(*n, (void*) LIST_SEPARATOR_CYBOL_NAME, (void*) LIST_SEPARATOR_CYBOL_NAME_COUNT, p4, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); *nc = *nc + *LIST_SEPARATOR_CYBOL_NAME_COUNT; //?? fwprintf(stdout, L"TEST append compound element 4 ns: %i\n", *ns); //?? fwprintf(stdout, L"TEST append compound element 4 nc: %i\n", *nc); //?? fwprintf(stdout, L"TEST append compound element 4 n: %ls\n", (wchar_t*) *n); // Set new element name by appending the index determined above. // Use name count as index to append the new characters. replace_array(*n, s, sc, p4, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); *nc = *nc + *((int*) sc); //?? fwprintf(stdout, L"TEST append compound element 5 ns: %i\n", *ns); //?? fwprintf(stdout, L"TEST append compound element 5 nc: %i\n", *nc); //?? fwprintf(stdout, L"TEST append compound element 5 n: %ls\n", (wchar_t*) *n); // Deallocate name suffix as wide character array. deallocate_model((void*) &s, (void*) &sc, (void*) &ss, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION, (void*) WIDE_CHARACTER_MEMORY_ABSTRACTION_COUNT); //?? fwprintf(stdout, L"TEST append compound element 6 ns: %i\n", *ns); //?? fwprintf(stdout, L"TEST append compound element 6 nc: %i\n", *nc); //?? fwprintf(stdout, L"TEST append compound element 6 n: %ls\n", (wchar_t*) *n); //?? fwprintf(stdout, L"TEST append compound element 7 p2: %i\n", p2); //?? fwprintf(stdout, L"TEST append compound element 7 *p2: %i\n", *((int*) p2)); //?? fwprintf(stdout, L"TEST append compound element 7 p1: %i\n", p1); //?? fwprintf(stdout, L"TEST append compound element 7 *p1: %i\n", *((int*) p1)); //?? fwprintf(stdout, L"TEST append compound element 7 p0: %i\n", p0); append_compound_element_by_name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); //?? fwprintf(stdout, L"TEST append compound element 8 p2: %i\n", *((int*) p2)); //?? fwprintf(stdout, L"TEST append compound element 8 p1: %i\n", *((int*) p1)); //?? fwprintf(stdout, L"TEST append compound element 8 p0: %i\n", p0); //?? fwprintf(stdout, L"TEST append compound element 9 ns: %i\n", *ns); //?? fwprintf(stdout, L"TEST append compound element 9 nc: %i\n", *nc); //?? fwprintf(stdout, L"TEST append compound element 9 n: %ls\n", (wchar_t*) *n); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not append compound element by name with suffix. The name is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not append compound element by name with suffix. The name count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not append compound element by name with suffix. The name size is null."); } }
/** * Builds a list name. * * Expected parameters: * - ?? (required): ?? (description) * * @param p0 the parameters * @param p1 the parameters count * @param p2 the knowledge memory * @param p3 the knowledge memory count * @param p4 the knowledge memory size */ void memorise_building(void* p0, void* p1, void* p2, void* p3, void* p4) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Build list name."); // The basisname name, abstraction, model, details. void** bnn = NULL_POINTER_MEMORY_MODEL; void** bnnc = NULL_POINTER_MEMORY_MODEL; void** bnns = NULL_POINTER_MEMORY_MODEL; void** bna = NULL_POINTER_MEMORY_MODEL; void** bnac = NULL_POINTER_MEMORY_MODEL; void** bnas = NULL_POINTER_MEMORY_MODEL; void** bnm = NULL_POINTER_MEMORY_MODEL; void** bnmc = NULL_POINTER_MEMORY_MODEL; void** bnms = NULL_POINTER_MEMORY_MODEL; void** bnd = NULL_POINTER_MEMORY_MODEL; void** bndc = NULL_POINTER_MEMORY_MODEL; void** bnds = NULL_POINTER_MEMORY_MODEL; // The index name, abstraction, model, details. void** idxn = NULL_POINTER_MEMORY_MODEL; void** idxnc = NULL_POINTER_MEMORY_MODEL; void** idxns = NULL_POINTER_MEMORY_MODEL; void** idxa = NULL_POINTER_MEMORY_MODEL; void** idxac = NULL_POINTER_MEMORY_MODEL; void** idxas = NULL_POINTER_MEMORY_MODEL; void** idxm = NULL_POINTER_MEMORY_MODEL; void** idxmc = NULL_POINTER_MEMORY_MODEL; void** idxms = NULL_POINTER_MEMORY_MODEL; void** idxd = NULL_POINTER_MEMORY_MODEL; void** idxdc = NULL_POINTER_MEMORY_MODEL; void** idxds = NULL_POINTER_MEMORY_MODEL; // The result name, abstraction, model, details. void** resn = NULL_POINTER_MEMORY_MODEL; void** resnc = NULL_POINTER_MEMORY_MODEL; void** resns = NULL_POINTER_MEMORY_MODEL; void** resa = NULL_POINTER_MEMORY_MODEL; void** resac = NULL_POINTER_MEMORY_MODEL; void** resas = NULL_POINTER_MEMORY_MODEL; void** resm = NULL_POINTER_MEMORY_MODEL; void** resmc = NULL_POINTER_MEMORY_MODEL; void** resms = NULL_POINTER_MEMORY_MODEL; void** resd = NULL_POINTER_MEMORY_MODEL; void** resdc = NULL_POINTER_MEMORY_MODEL; void** resds = NULL_POINTER_MEMORY_MODEL; // get the basisname get_universal_compound_element_by_name( (void*) &bnn, (void*) &bnnc, (void*) &bnns, (void*) &bna, (void*) &bnac, (void*) &bnas, (void*) &bnm, (void*) &bnmc, (void*) &bnms, (void*) &bnd, (void*) &bndc, (void*) &bnds, p0, p1, (void*) BASE_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) BASE_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); // get the index get_universal_compound_element_by_name( (void*) &idxn, (void*) &idxnc, (void*) &idxns, (void*) &idxa, (void*) &idxac, (void*) &idxas, (void*) &idxm, (void*) &idxmc, (void*) &idxms, (void*) &idxd, (void*) &idxdc, (void*) &idxds, p0, p1, (void*) INDEX_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) INDEX_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); // get the result get_universal_compound_element_by_name( (void*) &resn, (void*) &resnc, (void*) &resns, (void*) &resa, (void*) &resac, (void*) &resas, (void*) &resm, (void*) &resmc, (void*) &resms, (void*) &resd, (void*) &resdc, (void*) &resds, p0, p1, (void*) COMPOSITION_BUILD_FLOW_OPERATION_CYBOL_NAME, (void*) COMPOSITION_BUILD_FLOW_OPERATION_CYBOL_NAME_COUNT, p2, p3); //check the abstraction for the operation element int comp_res1 = *NUMBER_0_INTEGER_MEMORY_MODEL; int comp_res2 = *NUMBER_0_INTEGER_MEMORY_MODEL; int comp_res3 = *NUMBER_0_INTEGER_MEMORY_MODEL; // Create compare string. wchar_t* int_string = *NULL_POINTER_MEMORY_MODEL; // todo Konstante noch definieren int int_string_count = *NUMBER_0_INTEGER_MEMORY_MODEL; int int_string_size = *NUMBER_10_INTEGER_MEMORY_MODEL; allocate_array((void*) &int_string, (void*) &int_string_size, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); int_string_count = swprintf(int_string, int_string_size, L"%i", *((int*) *idxm)); // destination size *(int*)*resms = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT + int_string_count; *(int*)*resmc = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT + int_string_count; // Reallocate result array. reallocate_array(resm, *resms, *resms, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Set result array. replace_array(*resm, *bnm, *bnmc, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); replace_array(*resm, LIST_SEPARATOR_CYBOL_NAME, LIST_SEPARATOR_CYBOL_NAME_COUNT, *bnmc, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); int temp_index = *((int*) *bnmc) + *LIST_SEPARATOR_CYBOL_NAME_COUNT; replace_array(*resm, int_string, &int_string_count, &temp_index, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Destroy int_string array. deallocate_array((void*) &int_string, (void*) &int_string_size, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); }
/** * Decodes the percent-encoded character array into a non-percent-encoded character array. * * All percent-encoded (escaped) characters are resolved, * no matter whether or not they are reserved characters * according to the URI specification. * * @param p0 the destination character array (Hand over as reference!) * @param p1 the destination character array count * @param p2 the destination character array size * @param p3 the percent-encoded source character array * @param p4 the percent-encoded source character array count */ void decode_percent_encoding_vector(void* p0, void* p1, void* p2, void* p3, void* p4) { if (p4 != *NULL_POINTER_MEMORY_MODEL) { int* sc = (int*) p4; if (p3 != *NULL_POINTER_MEMORY_MODEL) { char* s = (char*) p3; if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* ds = (int*) p2; if (p1 != *NULL_POINTER_MEMORY_MODEL) { int* dc = (int*) p1; if (p0 != *NULL_POINTER_MEMORY_MODEL) { char** d = (char**) p0; if (*dc >= *NUMBER_0_INTEGER_MEMORY_MODEL) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Decode percent-encoding vector."); // // CAUTION! Do NOT operate with WIDE CHARACTERS here! // The percent-encoding is based upon ASCII characters with just one byte! // // Adjust destination character vector size. // // Whilst a percent-encoded character is represented by 3 Byte // (one for the % sign and two for the hexadecimal digits), // the corresponding decoded ASCII character needs just 1 Byte. // // Therefore, the destination size is set to the source count, // since it can never be larger. *ds = *dc + *sc; // Reallocate destination character vector. reallocate_array(p0, p1, p2, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // CAUTION! Hand over p3 as reference. decode_percent_encoding_vector_element(p0, p1, p2, (void*) &p3, p4); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The destination count is negative."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The destination is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The destination count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The destination size is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The source is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode percent-encoding vector. The source count is null."); } }
/** * Decodes an (external) UTF-8 Unicode multibyte character stream into an (internal) UTF-32 Unicode wide character vector. * * @param p0 the destination wide character array (Hand over as reference!) * @param p1 the destination wide character array count * @param p2 the destination wide character array size * @param p3 the source UTF-8 Unicode multibyte character stream * @param p4 the source UTF-8 Unicode multibyte character stream count */ void decode_utf_8_unicode_character_vector(void* p0, void* p1, void* p2, void* p3, void* p4) { if (p4 != *NULL_POINTER_MEMORY_MODEL) { int* sc = (int*) p4; if (p3 != *NULL_POINTER_MEMORY_MODEL) { char* s = (char*) p3; if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* ds = (int*) p2; if (p1 != *NULL_POINTER_MEMORY_MODEL) { int* dc = (int*) p1; if (p0 != *NULL_POINTER_MEMORY_MODEL) { wchar_t** d = (wchar_t**) p0; if (*dc >= *NUMBER_0_INTEGER_MEMORY_MODEL) { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Decode UTF-8 Unicode character vector."); // The new destination wide character vector size. // // CAUTION! The "worst case" is assumed, i.e. that each source character // represents an ascii character encoded by utf-8 with ONE single byte. // Therefore, the destination size is adjusted accordingly. // In case not all source characters are ascii characters -- even better, // since then more than just one source character were used for encoding, // and the destination wide character array will have LESS entries (count) // than the destination size that was set before. // In this case, the destination size will be too big, but can be reduced // to the actual destination count below, if so wanted. *ds = *dc + (*sc * *NUMBER_1_INTEGER_MEMORY_MODEL); // Reallocate destination wide character vector. reallocate_array(p0, p1, p2, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); // Set locale. // // Possible locales are: LANG, LC_CTYPE, ..., LC_ALL // where LANG has the lowest and LC_ALL the highest priority. // That is, if LC_ALL is specified, it overwrites e.g. the LC_CTYPE setting. // If no value "" is given, the default will be used. // Note, that LC_CTYPE suffices for the purpose of character conversion, // since it is the category that applies to classification and conversion // of characters, and to multibyte and wide characters. // // CAUTION! This setting is necessary for UTF-8 Unicode character conversion // with restartable multibyte conversion functions like "mbsnrtowcs" // and "wcsnrtombs" to work correctly. // The return value is not used; this is a global setting. char* loc = setlocale(LC_CTYPE, ""); // The state of the conversion. // // Certain character sets use a stateful encoding. // That is, the encoded values depend in some way // on the previous bytes in the text. // // Since the conversion functions allow converting a text // in more than one step, there must be a way to pass this // information from one call of the functions to another. // // A variable of type mbstate_t can contain all the // information about the shift state needed from one call // to a conversion function to another. //?? mbstate_t st; // Clear the whole conversion state variable. // // There is no specific function or initializer to put the // state object in any specific state. The rules are that // the object should always represent the initial state // before the first use and this is achieved here. //?? memreplace((void*) &st, '\0', *MULTIBYTE_CHARACTER_STATE_CONVERSION_TYPE_SIZE); // Initialise error number. // It is a global variable/ function and other operations // may have set some value that is not wanted here. // // CAUTION! Initialise the error number BEFORE calling the function // that might cause an error. errno = *NUMBER_0_INTEGER_MEMORY_MODEL; // Converts the multibyte character string into a wide character string. // // Returns the number of wide characters converted. //?? int n = mbsnrtowcs(*d, &s, *sc, *ds, &st); int n = mbsnrtowcs(*d, (const char**) &s, *sc, *ds, *NULL_POINTER_MEMORY_MODEL); if (n >= *NUMBER_0_INTEGER_MEMORY_MODEL) { // Increment destination count by the number of wide characters converted. *dc = *dc + n; } else { if (errno == EILSEQ) { fwprintf(stdout, L"TEST ERROR EILSEQ errno: %i\n", errno); log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The input string contains an invalid multibyte sequence."); } else { fwprintf(stdout, L"TEST ERROR UNKNOWN errno: %i\n", errno); log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. An unknown error occured."); } } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The destination count is negative."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The destination is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The destination count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The destination size is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The source is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not decode utf-8 unicode character stream. The source count is null."); } }
/** * Copies a boolean. * * @param p0 the destination (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source * @param p4 the source count */ void memorise_copying_boolean(void* p0, void* p1, void* p2, void* p3, void* p4) { if (p4 != *NULL_POINTER_MEMORY_MODEL) { int* sc = (int*) p4; if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* ds = (int*) p2; if (p1 != *NULL_POINTER_MEMORY_MODEL) { int* dc = (int*) p1; if (p0 != *NULL_POINTER_MEMORY_MODEL) { void** d = (void**) p0; log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Copy boolean."); // CAUTION! The destination array needs to be resized not only // if the source array is greater, but also if it is smaller! // If this is not done, false results may occur. // Example: A colour gets copied from source to destination. // The source colour is "red" with a count of 3. // The destination colour is "green" with a count of 5. // If the source colour gets copied to the destination, // the resulting destination array is "reden" with a count of 5. // This colour value does not exist and will cause errors! // Therefore, the destination array count and size ALWAYS // have to be adapted to the source array count and size. // If this had been done in the example, the resulting // destination array would have been "red" with a count of 3, // which is correct. // CAUTION! Do NOT use < or > here, for the reasons explained above! if (*sc != *dc) { // Set destination count and size. *dc = *sc; *ds = *dc; reallocate_array(p0, p1, p2, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); } replace_array(*d, p3, p4, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not copy boolean. The destination is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not copy boolean. The destination count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not copy boolean. The destination size is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not copy boolean. The source count is null."); } }