/** * Tests the accessor size determiner. */ void test_accessor_size_determiner() { log_terminated_message((void*) INFORMATION_LEVEL_LOG_MODEL, (void*) L"Test accessor size determiner."); // The character abstraction (type) size. int cs = *NUMBER_0_INTEGER_MEMORY_MODEL; // The double abstraction (type) size. int ds = *NUMBER_0_INTEGER_MEMORY_MODEL; // The integer abstraction (type) size. int is = *NUMBER_0_INTEGER_MEMORY_MODEL; // The pointer abstraction (type) size. int ps = *NUMBER_0_INTEGER_MEMORY_MODEL; // The unsigned long abstraction (type) size. int uls = *NUMBER_0_INTEGER_MEMORY_MODEL; // The wide character abstraction (type) size. int wcs = *NUMBER_0_INTEGER_MEMORY_MODEL; // Determine size. determine_size((void*) &cs, (void*) CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); determine_size((void*) &ds, (void*) DOUBLE_PRIMITIVE_MEMORY_ABSTRACTION); determine_size((void*) &is, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); determine_size((void*) &ps, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); determine_size((void*) &uls, (void*) UNSIGNED_LONG_PRIMITIVE_MEMORY_ABSTRACTION); determine_size((void*) &wcs, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION); fwprintf(stdout, L"Type size character: %i\n", cs); fwprintf(stdout, L"Type size double: %i\n", ds); fwprintf(stdout, L"Type size integer: %i\n", is); fwprintf(stdout, L"Type size pointer: %i\n", ps); fwprintf(stdout, L"Type size unsigned long: %i\n", uls); fwprintf(stdout, L"Type size wide character: %i\n", wcs); }
/** * Replaces the array elements. * * @param p0 the destination array * @param p1 the source elements * @param p2 the source elements count * @param p3 the destination array index * @param p4 the primitive abstraction */ void replace_array(void* p0, void* p1, void* p2, void* p3, void* p4) { if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* sc = (int*) p2; if (p0 != *NULL_POINTER_MEMORY_MODEL) { log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Replace array elements."); // The destination offset. int dos = *NUMBER_0_INTEGER_MEMORY_MODEL; // Determine abstraction (type) size. determine_size((void*) &dos, p4); // Calculate memory area (destination offset). multiply_with_integer((void*) &dos, p3, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); // The destination. // CAUTION! It HAS TO BE initialised with p0, // since an offset is added to it below. void* d = p0; // Add offset to destination. add_integer((void*) &d, (void*) &dos, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION); // The loop variable. int j = *NUMBER_0_INTEGER_MEMORY_MODEL; while (*NUMBER_1_INTEGER_MEMORY_MODEL) { if (j >= *sc) { break; } assign_with_offset(d, p1, (void*) &j, p4); j++; } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not replace array elements. The array is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not replace array elements. The elements count is null."); } }
int main(){ printf("test"); int size = determine_size(); FILE *fp; char line[128]; int current = 0; int c =0; _node nodes[size]; fp = popen("ps -aef", "r"); fgets(line, sizeof(line), fp); while(fgets(line, sizeof(line), fp) && c < size){ char *token = strtok(line, " "); _node* n = &nodes[current]; int c = 0; while( token != NULL){ if(c == 0){ n->pid = atoi(token); } if(c == 1){ n->ppid = atoi(token); } if(c == 8){ strncpy(n->command, token, sizeof(token)); // n->command = tokline[8]; } token = strtok(NULL, " "); c++; } current++; } make_tree(nodes, size, 0, 0); return 0; }
/** * Reallocates the array. * * @param p0 the array (Hand over as reference!) * @param p1 the count * @param p2 the size * @param p3 the abstraction */ void reallocate_array(void* p0, void* p1, void* p2, void* p3) { if (p2 != *NULL_POINTER_MEMORY_MODEL) { int* s = (int*) p2; if (p1 != *NULL_POINTER_MEMORY_MODEL) { int* c = (int*) p1; if (p0 != *NULL_POINTER_MEMORY_MODEL) { void** a = (void**) p0; log_terminated_message((void*) DEBUG_LEVEL_LOG_MODEL, (void*) L"Reallocate array."); // The memory area. int ma = *NUMBER_0_INTEGER_MEMORY_MODEL; // Determine abstraction (type) size. determine_size((void*) &ma, p3); // Calculate memory area. multiply_with_integer((void*) &ma, p2, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); if (ma > *NUMBER_0_INTEGER_MEMORY_MODEL) { // // CAUTION! The memory area (new array size) // MUST NOT be zero or smaller! // If it were equal to zero, then the "realloc" // function call would be equivalent to "free" -- // an unwanted side effect that would destroy // allocated memory areas and lead to errors. // Therefore, that case is excluded by this condition. // // Create a new array with extended size. // // Since the space after the end of the block may be in use, // realloc may find it necessary to copy the block to a // new address where more free space is available. // The value of realloc is the new address of the block. // If the block needs to be moved, realloc copies the old contents. // // CAUTION! The "ma" variable MAY NOT be casted to "size_t", // because it is NOT a pointer, but an integer value! *a = realloc(*a, ma); if (*s > *c) { // CAUTION! If count and size are equal, then nothing // is to be done. // CAUTION! Do NOT change this value if the size is // smaller than the count, because this will result // in a negative value and cause the new array elements // pointer further below to cross the array's boundary! // The NEW memory area to be initialised. int nma = *NUMBER_0_INTEGER_MEMORY_MODEL; // Calculate extra array size, which is the given array size // reduced by the existing element count. int es = *s - *c; // Determine abstraction (type) size. determine_size((void*) &nma, p3); // Calculate new memory area. multiply_with_integer((void*) &nma, (void*) &es, (void*) INTEGER_PRIMITIVE_MEMORY_ABSTRACTION); // The new array elements. void* na = *a + (ma - nma); // Initialise ONLY NEW array elements (new memory area) // with null pointer. Leave existing elements untouched. memset(na, *NUMBER_0_INTEGER_MEMORY_MODEL, nma); } } else { log_terminated_message((void*) WARNING_LEVEL_LOG_MODEL, (void*) L"Could not reallocate array. The memory area is not greater than zero."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not reallocate array. The array is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not reallocate array. The count is null."); } } else { log_terminated_message((void*) ERROR_LEVEL_LOG_MODEL, (void*) L"Could not reallocate array. The size is null."); } }