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

This commit is contained in:
huno 2022-02-22 23:31:47 +01:00
parent e205764c6d
commit 287351d945
7 changed files with 59 additions and 87 deletions

View File

@ -336,12 +336,16 @@ Ergänzungen durch
Die Umsetzung der obigen Änderungen sind erfolgreich, wenn Sie Die Umsetzung der obigen Änderungen sind erfolgreich, wenn Sie
folgende Shell Command Line erfolgreich ausführen können und in folgende Shell Command Line erfolgreich ausführen können und in
Firefox die Abhängigkeiten der C-Files von den Inclu-de Files Firefox die Abhängigkeiten der C-Files von den Include Files
dargestellt wird. dargestellt wird.
`make dep-clean dep && firefox src/*.png.` `make dep-clean dep && firefox src/*.png.`
### 4.2 Resultate analysieren und erklären
* Analysieren Sie die in der vorherigen Aufgabe erstellten grafischen Darstellungen.
* Erklären Sie was dargestellt wird und stellen Sie den Bezug zum zugehörigen C-Code her.
(04_grading)= (04_grading)=
@ -490,7 +494,7 @@ Es gibt als Teil dieses Tool-Sets verschiedene Übersetzer. Der hier
verwendete ist der Basis-übersetzer: `dot`. verwendete ist der Basis-übersetzer: `dot`.
Das `dot`-File Format kennt viele Möglichkeiten die Knoten und Kanten Das `dot`-File Format kennt viele Möglichkeiten die Knoten und Kanten
eines Graphen und de-ren Anordnung anzugeben. eines Graphen und deren Anordnung anzugeben.
Der Vorteil eines solchen Tool-Sets ist, dass man den Inhalt (den Der Vorteil eines solchen Tool-Sets ist, dass man den Inhalt (den
Graphen) einfach definieren kann und sich nicht um das komplexe Graphen) einfach definieren kann und sich nicht um das komplexe
@ -511,7 +515,7 @@ digraph G {
} }
subgraph cluster_c1 { subgraph cluster_c1 {
label="others"; style=filled; col-or=lightgrey; label="others"; style=filled; color=lightgrey;
{ B; C; rank=same; } { B; C; rank=same; }
} }
@ -521,6 +525,13 @@ digraph G {
} }
``` ```
```{eval-rst}
.. figure:: bsp_dot.png
:width: 210px
:name: bsp_dot
:align: center
```
#### 6.2.3 png File #### 6.2.3 png File
@ -529,4 +540,4 @@ Format. Es wird oft in Web Pages verwendet.
___ ___
Version: 15.02.2022 Version: 22.02.2022

View File

@ -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

View File

@ -15,7 +15,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "read.h" #include "read.h"
#include "rectang.h" #include "rectang.h"
#include "trace.h"
/// max side length /// max side length
#define MAX_NUMBER 1000 #define MAX_NUMBER 1000

View File

@ -135,36 +135,6 @@ static void test_not_right_angled(void)
assert_lines(OUTFILE, out_txt, sizeof(out_txt)/sizeof(*out_txt)); 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) static void test_error(void)
{ {
// arrange // arrange
@ -199,7 +169,6 @@ int main(void)
TestMainBasic("Triangle", setup, teardown TestMainBasic("Triangle", setup, teardown
, test_right_angled , test_right_angled
, test_not_right_angled , test_not_right_angled
, test_trace
, test_error , test_error
); );
} }

View File

@ -1,19 +1,18 @@
/** /**
* @file * @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 of include guard
// BEGIN-STUDENTS-TO-ADD-CODE // BEGIN-STUDENTS-TO-ADD-CODE
#ifndef _DATA_H_
#define _DATA_H_
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
// includes which are needed in this header file // includes which are needed in this header file
// BEGIN-STUDENTS-TO-ADD-CODE // BEGIN-STUDENTS-TO-ADD-CODE
#include <stddef.h>
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
@ -22,17 +21,22 @@
* @brief Directory container for file entries of the dependency file. * @brief Directory container for file entries of the dependency file.
*/ */
// BEGIN-STUDENTS-TO-ADD-CODE // 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 // END-STUDENTS-TO-ADD-CODE
/** /**
* @brief File container for the file entries of the dependency file. * @brief File container for the file entries of the dependency file.
*/ */
// BEGIN-STUDENTS-TO-ADD-CODE // 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 // END-STUDENTS-TO-ADD-CODE
@ -41,8 +45,12 @@
* @brief Overall container for all directories and all files from the dependency file. * @brief Overall container for all directories and all files from the dependency file.
*/ */
// BEGIN-STUDENTS-TO-ADD-CODE // 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 // 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. * @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 // BEGIN-STUDENTS-TO-ADD-CODE
const data_t data_read_all(const char *root);
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
// end of include guard // end of include guard
// BEGIN-STUDENTS-TO-ADD-CODE // BEGIN-STUDENTS-TO-ADD-CODE
#endif // _DATA_H_
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE

View File

@ -36,12 +36,11 @@ static size_t dependencies(file_t files[], size_t len, size_t curr)
if (files[file].level == level + 1) { 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 // Write to stdout " file -> include;\n" where file and include are the DOT node names of the respective files
// BEGIN-STUDENTS-TO-ADD-CODE // BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(files[curr]);
printf(" -> ");
print_node(files[file]);
printf(";\n");
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
file = dependencies(files, len, file); file = dependencies(files, len, file);
} else { } else {
@ -62,11 +61,9 @@ void output_dot(const data_t data)
for (size_t file = 0; file < data.n_files; file++) { 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 // 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 // BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(data.files[file]);
printf(" [label=\"%s\"];\n", data.files[file].name);
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
} }
// directory clusters // directory clusters
@ -77,11 +74,9 @@ void output_dot(const data_t data)
if (data.files[file].dir == dir) { if (data.files[file].dir == dir) {
// Write to stdout " file;\n" where file is the DOT node name // Write to stdout " file;\n" where file is the DOT node name
// BEGIN-STUDENTS-TO-ADD-CODE // BEGIN-STUDENTS-TO-ADD-CODE
printf(" ");
print_node(data.files[file]);
printf(";\n");
// END-STUDENTS-TO-ADD-CODE // END-STUDENTS-TO-ADD-CODE
} }
} }

View File

@ -4,9 +4,17 @@
*/ */
// define proper header file here, with include gaurd, etc. // define proper header file here, with include gaurd, etc.
// BEGIN-STUDENTS-TO-ADD-CODE // 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 // END-STUDENTS-TO-ADD-CODE