P04 Modularisieren von C Code: update code to new Praktika description

This commit is contained in:
huno
2022-02-22 23:44:39 +01:00
parent e205764c6d
commit 287351d945
7 changed files with 59 additions and 87 deletions
@@ -1,16 +0,0 @@
/* ----------------------------------------------------------------------------
* -- _____ ______ _____ -
* -- |_ _| | ____|/ ____| -
* -- | | _ __ | |__ | (___ Institute of Embedded Systems -
* -- | | | '_ \| __| \___ \ Zuercher Hochschule Winterthur -
* -- _| |_| | | | |____ ____) | (University of Applied Sciences) -
* -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
* ----------------------------------------------------------------------------
*/
/**
* @file
* @brief Lab implementation
*/
// begin students to add code for task 4.2
// end students to add code
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include "read.h"
#include "rectang.h"
#include "trace.h"
/// max side length
#define MAX_NUMBER 1000
@@ -135,36 +135,6 @@ static void test_not_right_angled(void)
assert_lines(OUTFILE, out_txt, sizeof(out_txt)/sizeof(*out_txt));
}
static void test_trace(void)
{
// arrange
const char *err_txt[] = {
"TRACE: main()\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: rectangular(3, 4, 6)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: rectangular(5, 4, 4)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: rectangular(3, 5, 5)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: getInt(1000)\n",
"TRACE: rectangular(33, 43, 55)\n",
"TRACE: getInt(1000)\n",
};
// act
int exit_code = system(XSTR(TARGET) " 1>" OUTFILE " 2>" ERRFILE " <" INFILE_NOT_RIGHT_ANGLED);
// assert
CU_ASSERT_EQUAL(exit_code, 0);
assert_lines(ERRFILE, err_txt, sizeof(err_txt)/sizeof(*err_txt));
}
static void test_error(void)
{
// arrange
@@ -199,7 +169,6 @@ int main(void)
TestMainBasic("Triangle", setup, teardown
, test_right_angled
, test_not_right_angled
, test_trace
, test_error
);
}
@@ -1,19 +1,18 @@
/**
* @file
* @brief Access to the GCC produced dependency data (via gcc -H command line option).
* @brief Access to the GCC produced dependency data (via -H command line option).
*/
// begin of include guard
// BEGIN-STUDENTS-TO-ADD-CODE
#ifndef _DATA_H_
#define _DATA_H_
// END-STUDENTS-TO-ADD-CODE
// includes which are needed in this header file
// BEGIN-STUDENTS-TO-ADD-CODE
#include <stddef.h>
// END-STUDENTS-TO-ADD-CODE
@@ -22,17 +21,22 @@
* @brief Directory container for file entries of the dependency file.
*/
// BEGIN-STUDENTS-TO-ADD-CODE
typedef struct {
const char *name; ///< @brief the path name of the directory as given by the GCC produced dependency file.
} dir_t;
// END-STUDENTS-TO-ADD-CODE
/**
* @brief File container for the file entries of the dependency file.
*/
// BEGIN-STUDENTS-TO-ADD-CODE
typedef struct {
const char *name; ///< @brief The base name of the file from the GGC produced dependency file (i.e. the plain name, without any directory path).
size_t dir; ///< @brief The index of the directory entry which represents the path as given by the dependency file.
size_t level; ///< @brief The level as read out from the dependecy file.
} file_t;
// END-STUDENTS-TO-ADD-CODE
@@ -41,8 +45,12 @@
* @brief Overall container for all directories and all files from the dependency file.
*/
// BEGIN-STUDENTS-TO-ADD-CODE
typedef struct {
size_t n_dirs; ///< @brief The number of valid entries in the dirs list.
dir_t *dirs; ///< @brief The list of directories.
size_t n_files; ///< @brief The number of valid entries in the files list.
file_t *files; ///< @brief The list of files from the dependency file (the sequence is relevant to determine the dependencies).
} data_t;
// END-STUDENTS-TO-ADD-CODE
@@ -53,14 +61,12 @@
* @return The container of the read data from stdin. See the documentation on gcc -H for details on the dependencies, etc.
*/
// BEGIN-STUDENTS-TO-ADD-CODE
const data_t data_read_all(const char *root);
// END-STUDENTS-TO-ADD-CODE
// end of include guard
// BEGIN-STUDENTS-TO-ADD-CODE
#endif // _DATA_H_
// END-STUDENTS-TO-ADD-CODE
@@ -36,12 +36,11 @@ static size_t dependencies(file_t files[], size_t len, size_t curr)
if (files[file].level == level + 1) {
// Write to stdout " file -> include;\n" where file and include are the DOT node names of the respective files
// BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(files[curr]);
printf(" -> ");
print_node(files[file]);
printf(";\n");
// END-STUDENTS-TO-ADD-CODE
file = dependencies(files, len, file);
} else {
@@ -62,11 +61,9 @@ void output_dot(const data_t data)
for (size_t file = 0; file < data.n_files; file++) {
// Write to stdout " file [label=\"name\"];\n" where file is the DOT node name and name is the file name
// BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(data.files[file]);
printf(" [label=\"%s\"];\n", data.files[file].name);
// END-STUDENTS-TO-ADD-CODE
}
// directory clusters
@@ -77,11 +74,9 @@ void output_dot(const data_t data)
if (data.files[file].dir == dir) {
// Write to stdout " file;\n" where file is the DOT node name
// BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(data.files[file]);
printf(";\n");
// END-STUDENTS-TO-ADD-CODE
}
}
@@ -4,9 +4,17 @@
*/
// define proper header file here, with include gaurd, etc.
// BEGIN-STUDENTS-TO-ADD-CODE
#ifndef _OUTPUT_H_
#define _OUTPUT_H_
#include "data.h"
/**
* @brief Produces DOT output of the dependencies given in data.
* @param data [IN] Container of the dependenciy data.
*/
void output_dot(const data_t data);
#endif // _OUTPUT_H_
// END-STUDENTS-TO-ADD-CODE