P04 Modularisieren von C Code: update code to new Praktika description
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user