555 lines
37 KiB
HTML
555 lines
37 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
<meta content="metadata description" lang="en" name="description" xml:lang="en" />
|
||
<meta content="description des métadonnées" lang="fr" name="description" xml:lang="fr" />
|
||
<meta content="Sphinx, MyST" name="keywords" />
|
||
<meta content="en_US" property="og:locale" />
|
||
|
||
<title>04 - Modularisieren von C Code — SNP Labs documentation</title>
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
|
||
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="05 - Arrays/Strings/TicTacToe" href="../P05_TicTacToe/README.html" />
|
||
<link rel="prev" title="03 - Bit Operationen, Struct, Typedef" href="../P03_Bit_Operation_struct_typedef/README.html" />
|
||
|
||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||
|
||
</head><body>
|
||
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
|
||
|
||
<div class="body" role="main">
|
||
|
||
<section class="tex2jax_ignore mathjax_ignore" id="modularisieren-von-c-code">
|
||
<h1>04 - Modularisieren von C Code<a class="headerlink" href="#modularisieren-von-c-code" title="Permalink to this headline">¶</a></h1>
|
||
<p><img alt="" src="../_images/modularisieren_von_c_code.JPG" /></p>
|
||
<hr class="docutils" />
|
||
<section id="ubersicht">
|
||
<h2>1. Übersicht<a class="headerlink" href="#ubersicht" title="Permalink to this headline">¶</a></h2>
|
||
<p>In diesem Praktikum üben Sie modulare Programmierung indem Sie ein
|
||
Java Programm (bestehend aus drei Java Files) in ein entsprechendes C
|
||
Programm aus drei Modulen (aus je einem Header- und Implementations-
|
||
File) übersetzen. Sie passen das Makefile so an, dass die
|
||
entsprechenden Module mit kompiliert werden.</p>
|
||
<p>In der zweiten Aufgabe erstellen Sie Makefile Regeln für die drei
|
||
Schritte von den C Source Files zur graphischen Darstellung der
|
||
Abhängigkeiten.</p>
|
||
<p><img alt="" src="../_images/uebersicht.png" /></p>
|
||
<p>Im Anhang ist eine Übersicht über die verwendeten File Formate gegeben.</p>
|
||
</section>
|
||
<section id="lernziele">
|
||
<h2>2. Lernziele<a class="headerlink" href="#lernziele" title="Permalink to this headline">¶</a></h2>
|
||
<p>In diesem Praktikum lernen Sie die Handgriffe um ein Programm zu modularisieren, d.h. in mehrere Module aufzuteilen.</p>
|
||
<ul class="simple">
|
||
<li><p>Sie wissen, dass ein Modul aus einem C-File und einem passenden
|
||
H-File besteht.</p></li>
|
||
<li><p>Sie können Header Files korrekt strukturieren.</p></li>
|
||
<li><p>Sie deklarieren im Header-File die öffentlichen Typen und Funktionen
|
||
eines Moduls.</p></li>
|
||
<li><p>Sie wissen wie <strong>Include Guards</strong> anzuwenden sind.</p></li>
|
||
<li><p>Sie können Module im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> zur Kompilation hinzufügen.</p></li>
|
||
<li><p>Sie können <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> Regeln schreiben.</p></li>
|
||
</ul>
|
||
<p>Die Bewertung dieses Praktikums ist am Ende angegeben.</p>
|
||
<p>Erweitern Sie die vorgegebenen Code Gerüste, welche im <code class="docutils literal notranslate"><span class="pre">git</span></code>
|
||
Repository <code class="docutils literal notranslate"><span class="pre">snp-lab-code</span></code> verfügbar sind.</p>
|
||
</section>
|
||
<section id="aufgabe-1-modularisieren">
|
||
<h2>3. Aufgabe 1: Modularisieren<a class="headerlink" href="#aufgabe-1-modularisieren" title="Permalink to this headline">¶</a></h2>
|
||
<p>Das zu ergänzende Programm dep2dot hat folgende Funktionalität:</p>
|
||
<p>Ergänzen Sie in <strong><code class="docutils literal notranslate"><span class="pre">modularize/src</span></code></strong> den Code in <strong><code class="docutils literal notranslate"><span class="pre">triangle.c</span></code></strong>,
|
||
<strong><code class="docutils literal notranslate"><span class="pre">read.h</span></code></strong>, <strong><code class="docutils literal notranslate"><span class="pre">read.c</span></code></strong>, <strong><code class="docutils literal notranslate"><span class="pre">rectang.h</span></code></strong> und <strong><code class="docutils literal notranslate"><span class="pre">rectang.c</span></code></strong> so
|
||
dass die Tests erfolgreich durchlaufen. Die C Implementation soll
|
||
dieselbe Funktionalität haben wie die gegebenen Java Files. Lehnen Sie
|
||
sich so nahe wie möglich an die Java Files an.</p>
|
||
<ol class="arabic simple">
|
||
<li><p>In den Header-Files implementieren Sie den Include-Guard und
|
||
deklarieren Sie die öffentlichen Funktionen und gegebenenfalls
|
||
<strong><code class="docutils literal notranslate"><span class="pre">#define</span></code></strong>.</p></li>
|
||
<li><p>In den Implementations-Files implementieren Sie die Funktionen.</p></li>
|
||
</ol>
|
||
<p>Die drei Java Files liegen in <strong><code class="docutils literal notranslate"><span class="pre">modularize/java</span></code></strong>.</p>
|
||
<section id="tipps">
|
||
<h3>Tipps<a class="headerlink" href="#tipps" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Implementieren Sie die Symbole welche vollständig in Grossbuchstaben
|
||
geschrieben sind als <strong><code class="docutils literal notranslate"><span class="pre">#define</span></code></strong>.</p></li>
|
||
<li><p><strong><code class="docutils literal notranslate"><span class="pre">EOF</span></code></strong> kommt schon aus <strong><code class="docutils literal notranslate"><span class="pre">stdio.h</span></code></strong> und sollte deshalb nicht
|
||
mehr definiert werden.</p></li>
|
||
<li><p>Jene <strong><code class="docutils literal notranslate"><span class="pre">#define</span></code></strong> welche von andern Modulen verwendet werden
|
||
kommen ins Header-File, die andern ins Implementations-File.</p></li>
|
||
<li><p>Ein Grossteil des Java Codes aus den Methoden Bodies kann
|
||
eins-zu-eins in C übernommen werden. Listen Sie auf welche
|
||
Unterschiede es gibt:</p></li>
|
||
</ul>
|
||
<table>
|
||
<style>
|
||
table, th, td {
|
||
border: 1px solid black;
|
||
border-collapse: collapse;
|
||
}
|
||
table th:first-of-type {
|
||
width: 50%;
|
||
}
|
||
table th:nth-of-type(2) {
|
||
width: 50%;
|
||
}
|
||
</style>
|
||
<tr><th>Java</th><th>C</th></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">boolean</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kc">true</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kc">false</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span>System.out.print(…)
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span>System.out.println(…)
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">System</span><span class="p">.</span><span class="na">in</span><span class="p">.</span><span class="na">read</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span><span class="o">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">byte</span><span class="o">[</span><span class="n">BUFFERSIZE</span><span class="o">]</span><span class="p">;</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span>public class rectang {
|
||
public boolean Rectangular(…)
|
||
{ … }
|
||
}
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">read</span> <span class="p">{</span>
|
||
<span class="kd">public</span> <span class="kt">int</span> <span class="nf">getInt</span><span class="p">(...)</span>
|
||
<span class="kd">throws</span> <span class="n">java</span><span class="p">.</span><span class="na">io</span><span class="p">.</span><span class="na">IOException</span>
|
||
<span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kd">class</span> <span class="nc">triangle</span> <span class="p">{</span>
|
||
<span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span>
|
||
<span class="kd">throws</span> <span class="n">java</span><span class="p">.</span><span class="na">io</span><span class="p">.</span><span class="na">IOException</span>
|
||
<span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">read</span> <span class="n">ReadInt</span> <span class="o">=</span> <span class="k">new</span> <span class="n">read</span><span class="p">();</span>
|
||
<span class="p">...</span>
|
||
<span class="n">word</span> <span class="o">=</span> <span class="n">ReadInt</span><span class="p">.</span><span class="na">getInt</span><span class="p">(</span><span class="n">MAX_NUMBER</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">rectang</span> <span class="n">Rect</span> <span class="o">=</span> <span class="k">new</span> <span class="n">rectang</span><span class="p">();</span>
|
||
<span class="p">...</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="n">Rect</span><span class="p">.</span><span class="na">Rectangular</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="o">==</span> <span class="kc">true</span><span class="p">)</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
<tr><td>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span>
|
||
<span class="s2">"-> Dreieck "</span> <span class="o">+</span> <span class="n">a</span> <span class="o">+</span> <span class="s2">"-"</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="s2">"-"</span> <span class="o">+</span> <span class="n">c</span>
|
||
<span class="o">+</span> <span class="s2">" ist rechtwinklig"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</td><td></td></tr>
|
||
</table>
|
||
</section>
|
||
</section>
|
||
<section id="aufgabe-2-makefile-regeln">
|
||
<h2>4. Aufgabe 2: Makefile Regeln<a class="headerlink" href="#aufgabe-2-makefile-regeln" title="Permalink to this headline">¶</a></h2>
|
||
<p>Die folgenden drei Schritte erstellen von einem C Source File eine
|
||
graphische Darstellung der Abhängigkeiten:</p>
|
||
<ol class="arabic simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">gcc</span> <span class="pre">...</span> <span class="pre">-H</span> <span class="pre">..</span> <span class="pre">file.c</span> <span class="pre">...</span> <span class="pre">2></span> <span class="pre">file.dep</span></code> (Regeln im Makefile bereits vorhanden)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">dep2dot</span> <span class="pre">file.c</span> <span class="pre"><file.dep</span> <span class="pre">>file.dot</span></code> (in dieser Aufgabe zu erstellen)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">dot</span> <span class="pre">-Tpng</span> <span class="pre">file.dot</span> <span class="pre">>file.png</span></code> (in dieser Aufgabe zu erstellen)</p></li>
|
||
</ol>
|
||
<p>Sie sollen für die Compiler-ähnlichen Programme <code class="docutils literal notranslate"><span class="pre">dep2dot</span></code> und <code class="docutils literal notranslate"><span class="pre">dot</span></code>
|
||
Makefile Regeln schreiben.</p>
|
||
<p><img alt="" src="../_images/uebersicht.png" /></p>
|
||
<p>Das Programm <code class="docutils literal notranslate"><span class="pre">dep2dot</span></code> hat folgende Funktionalität:</p>
|
||
<ol class="arabic simple">
|
||
<li><p>Es liest von <code class="docutils literal notranslate"><span class="pre">stdin</span></code> die vom Compiler generierten
|
||
Abhängigkeits-Daten in Form des <code class="docutils literal notranslate"><span class="pre">dep</span></code> Formates ein.</p></li>
|
||
<li><p>Das erste und einzige Command Line Argument gibt das File an für
|
||
welches die von <code class="docutils literal notranslate"><span class="pre">stdin</span></code> gelesenen Abhängigkeiten gelten.</p></li>
|
||
<li><p>Auf <code class="docutils literal notranslate"><span class="pre">stdout</span></code> werden die Abhängigkeiten von <code class="docutils literal notranslate"><span class="pre">stdin</span></code> übersetzt als
|
||
<code class="docutils literal notranslate"><span class="pre">dot</span></code>-File Format ausgegeben.</p></li>
|
||
</ol>
|
||
<p>Das Programm <code class="docutils literal notranslate"><span class="pre">dot</span></code> hat folgende Funktionalität:</p>
|
||
<ol class="arabic simple">
|
||
<li><p>Es liest die textuelle Beschreibung eines Graphen aus der
|
||
übergebenen Datei (erstes Argument) ein.</p></li>
|
||
<li><p>Auf <code class="docutils literal notranslate"><span class="pre">stdout</span></code> wird die grafische Darstellung der Beschreibung der
|
||
Eingabe-Datei im <code class="docutils literal notranslate"><span class="pre">png</span></code>-File Format ausgegeben.</p></li>
|
||
</ol>
|
||
<p>Das <code class="docutils literal notranslate"><span class="pre">dep</span></code>-Format und das <code class="docutils literal notranslate"><span class="pre">dot</span></code>-Format sind im Anhang beschrieben.</p>
|
||
<p>Sie können die Funktionalität des Programms <code class="docutils literal notranslate"><span class="pre">dep2dot</span></code> kennen lernen,
|
||
indem Sie folgende Zeilen auf der Bash Shell ausführen. Das
|
||
<code class="docutils literal notranslate"><span class="pre">dep.input</span></code> File ist Teil der automatisierten Test Suite im
|
||
Verzeichnis <code class="docutils literal notranslate"><span class="pre">tests</span></code>:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>bin/dep2dot dir/file <tests/dep.input >dep.dot
|
||
dot -Tpng dep.dot >dep.png
|
||
firefox dep.png
|
||
</pre></div>
|
||
</div>
|
||
<p>Als Resultat sollte Firefox folgende Graphik darstellen:</p>
|
||
<p><img alt="" src="../_images/dep_dot.png" /></p>
|
||
<p>Definieren Sie im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> Regeln, welche die einzelnen Schritte von
|
||
den Source Files zu den <code class="docutils literal notranslate"><span class="pre">png</span></code> Files ausführen.</p>
|
||
<p>Prüfen Sie schliesslich die Umsetzung Aufgabe mittels <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">dep-clean</span> <span class="pre">dep</span> <span class="pre">&&</span> <span class="pre">firefox</span> <span class="pre">src/*.png.</span></code></p>
|
||
<section id="neue-regeln-hinzufugen">
|
||
<h3>4.1 Neue Regeln hinzufügen<a class="headerlink" href="#neue-regeln-hinzufugen" title="Permalink to this headline">¶</a></h3>
|
||
<p>Führen Sie im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> an den angegebenen Stellen folgende
|
||
Ergänzungen durch</p>
|
||
<ul class="simple">
|
||
<li><p>definieren Sie eine Variable <code class="docutils literal notranslate"><span class="pre">DEPFILES</span></code> deren Inhalt die Liste alle
|
||
Einträge der Variable <code class="docutils literal notranslate"><span class="pre">SOURCES</span></code> ist, wobei bei allen die Endung <code class="docutils literal notranslate"><span class="pre">.c</span></code>
|
||
durch die Endung <code class="docutils literal notranslate"><span class="pre">.c.png</span></code> ersetzt ist</p></li>
|
||
<li><p>fügen Sie zum <code class="docutils literal notranslate"><span class="pre">Pseudo-Target</span> <span class="pre">.PHONEY</span></code> das Target <code class="docutils literal notranslate"><span class="pre">dep</span></code> dazu – dies
|
||
besagt, dass das später folgenden Target <code class="docutils literal notranslate"><span class="pre">dep</span></code> nicht ein File
|
||
repräsentiert (ohne dieses Setting würde make gegebenenfalls nach
|
||
einem File mit Namen <code class="docutils literal notranslate"><span class="pre">dep</span></code> suchen um zu entscheiden ob es
|
||
inkrementell gebildet werden muss)</p></li>
|
||
<li><p>schreiben Sie das Target <code class="docutils literal notranslate"><span class="pre">dep</span></code> gemäss der Beschreibung im Makefile</p></li>
|
||
<li><p>schreiben Sie die Suffix Regel für die Übersetzung von <code class="docutils literal notranslate"><span class="pre">.png</span> <span class="pre"><-</span> <span class="pre">.dot</span></code> gemäss Vorgabe im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> (als Inspiration, siehe auch die
|
||
<code class="docutils literal notranslate"><span class="pre">%.c.dep:</span> <span class="pre">%.c</span></code> Suffix Regel weiter unten im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code>) – erklären
|
||
Sie was die Regel macht</p></li>
|
||
<li><p>schreiben Sie die Suffix Regel für die Übersetzung von<code class="docutils literal notranslate"> <span class="pre">.dot</span> <span class="pre"><-</span> <span class="pre">.dep</span></code> gemäss Vorgabe im <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> – erklären Sie was die Regel
|
||
macht</p></li>
|
||
</ul>
|
||
<p>Die Umsetzung der obigen Änderungen sind erfolgreich, wenn Sie
|
||
folgende Shell Command Line erfolgreich ausführen können und in
|
||
Firefox die Abhängigkeiten der C-Files von den Include Files
|
||
dargestellt wird.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">dep-clean</span> <span class="pre">dep</span> <span class="pre">&&</span> <span class="pre">firefox</span> <span class="pre">src/*.png.</span></code></p>
|
||
</section>
|
||
<section id="resultate-analysieren-und-erklaren">
|
||
<h3>4.2 Resultate analysieren und erklären<a class="headerlink" href="#resultate-analysieren-und-erklaren" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Analysieren Sie die in der vorherigen Aufgabe erstellten grafischen Darstellungen.</p></li>
|
||
<li><p>Erklären Sie was dargestellt wird und stellen Sie den Bezug zum zugehörigen C-Code her.</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<hr class="docutils" />
|
||
<section id="bewertung">
|
||
<h2>5. Bewertung<a class="headerlink" href="#bewertung" title="Permalink to this headline">¶</a></h2>
|
||
<p>Die gegebenenfalls gestellten Theorieaufgaben und der funktionierende Programmcode müssen der Praktikumsbetreuung gezeigt werden. Die Lösungen müssen mündlich erklärt werden.</p>
|
||
<table class="colwidths-auto docutils align-default">
|
||
<thead>
|
||
<tr class="row-odd"><th class="text-left head"><p>Aufgabe</p></th>
|
||
<th class="text-left head"><p>Kriterium</p></th>
|
||
<th class="text-left head"><p>Punkte</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td class="text-left"><p>1</p></td>
|
||
<td class="text-left"><p>Sie können das funktionierende Programm inklusive funktionierende Tests demonstrieren und erklären.</p></td>
|
||
<td class="text-left"><p></p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td class="text-left"><p>1</p></td>
|
||
<td class="text-left"><p>Module einbinden, Header Files schreiben</p></td>
|
||
<td class="text-left"><p>2</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td class="text-left"><p>2</p></td>
|
||
<td class="text-left"><p>Sie können das funktionierende Makefile demonstrieren und erklären.</p></td>
|
||
<td class="text-left"><p></p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td class="text-left"><p>2</p></td>
|
||
<td class="text-left"><p>Neue Regeln hinzufügen</p></td>
|
||
<td class="text-left"><p>2</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
<hr class="docutils" />
|
||
<section id="anhang">
|
||
<h2>6. Anhang<a class="headerlink" href="#anhang" title="Permalink to this headline">¶</a></h2>
|
||
<section id="verwendete-zusatzliche-sprach-elemente">
|
||
<h3>6.1 Verwendete zusätzliche Sprach Elemente<a class="headerlink" href="#verwendete-zusatzliche-sprach-elemente" title="Permalink to this headline">¶</a></h3>
|
||
<p><strong>Sprach Element</strong></p>
|
||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"v=%d"</span><span class="p">,</span><span class="w"> </span><span class="n">v</span><span class="p">)</span><span class="w"></span>
|
||
</pre></div>
|
||
</div>
|
||
<p><strong>Beschreibung</strong></p>
|
||
<p>Formatierte Ausgabe auf den Standard Error Stream. Siehe <em><strong>man 3
|
||
stderr</strong></em> und <em><strong>man 3 fprintf</strong></em>.</p>
|
||
</section>
|
||
<section id="verarbeitung-und-verwendete-file-formate-a-name-file-formats-a">
|
||
<h3>6.2 Verarbeitung und verwendete File Formate <a name="file_formats"></a><a class="headerlink" href="#verarbeitung-und-verwendete-file-formate-a-name-file-formats-a" title="Permalink to this headline">¶</a></h3>
|
||
<p>Das Programm in diesem Praktikum ist Teil für die graphische
|
||
Darstellung von <code class="docutils literal notranslate"><span class="pre">#include</span></code> File Abhängigkeit von C Files.</p>
|
||
<p>Den ersten Schritt für die Darstellung der <code class="docutils literal notranslate"><span class="pre">#include</span></code> File
|
||
Abhängigkeiten bietet der Compiler. Der Compiler kann mittels der <code class="docutils literal notranslate"><span class="pre">-H</span></code>
|
||
Command Line Option auf <code class="docutils literal notranslate"><span class="pre">stderr</span></code> ein Text File generieren, welches die
|
||
tatsächlich verwendeten Header Files auflistet. Zusätzlich wird im
|
||
Resultat die Verschachtelungstiefe der Includes angegeben.</p>
|
||
<p>Im zweiten Schritt übersetzt das Programm (<code class="docutils literal notranslate"><span class="pre">dep2dot</span></code>) dieses
|
||
Praktikums solche Dependency Files (<code class="docutils literal notranslate"><span class="pre">dep</span></code>) in eine Text Repräsentation
|
||
der Abhängigkeiten (<code class="docutils literal notranslate"><span class="pre">dot</span></code>) welche in graphische Darstel-lung (<code class="docutils literal notranslate"><span class="pre">png</span></code>)
|
||
übersetzt werden kann.</p>
|
||
<p>Als Tool zur Übersetzung der <code class="docutils literal notranslate"><span class="pre">dot</span></code> Files in das <code class="docutils literal notranslate"><span class="pre">png</span></code> Format dient das
|
||
<code class="docutils literal notranslate"><span class="pre">dot</span></code> Tool. Dieses Tool muss gegebenenfalls installiert werden:</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">sudo</span> <span class="pre">apt</span> <span class="pre">install</span> <span class="pre">graphviz</span></code></p>
|
||
<p>Die <code class="docutils literal notranslate"><span class="pre">png</span></code> Files können dann z.B. in der Programm Dokumentation
|
||
integriert werden (Darstellung zu Test Zwecken z.B. mittels <code class="docutils literal notranslate"><span class="pre">firefox</span> <span class="pre">file.png</span></code>).</p>
|
||
<section id="dep-file">
|
||
<h4>6.2.1 dep File<a class="headerlink" href="#dep-file" title="Permalink to this headline">¶</a></h4>
|
||
<p>Siehe: <code class="docutils literal notranslate"><span class="pre">man</span> <span class="pre">gcc</span></code></p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>-H Print the name of each header file used, <span class="k">in</span> addition to other
|
||
normal activities. Each name is indented to show how deep <span class="k">in</span> the
|
||
<span class="c1">#include stack it is. [...]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Das File wird auf <code class="docutils literal notranslate"><span class="pre">stderr</span></code> ausgegeben.</p>
|
||
<p><strong>Beispiel File</strong> (für Abhängigkeiten des <code class="docutils literal notranslate"><span class="pre">main.c</span></code> Files des <code class="docutils literal notranslate"><span class="pre">dep2dot</span></code> Programms)</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>. /usr/include/stdio.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
|
||
... /usr/include/features.h
|
||
.... /usr/include/x86_64-linux-gnu/sys/cdefs.h
|
||
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
|
||
..... /usr/include/x86_64-linux-gnu/bits/long-double.h
|
||
.... /usr/include/x86_64-linux-gnu/gnu/stubs.h
|
||
..... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h
|
||
.. /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/types.h
|
||
... /usr/include/x86_64-linux-gnu/bits/wordsize.h
|
||
... /usr/include/x86_64-linux-gnu/bits/typesizes.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/types/__FILE.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/types/FILE.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/libio.h
|
||
... /usr/include/x86_64-linux-gnu/bits/_G_config.h
|
||
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
|
||
.... /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h
|
||
... /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/stdio_lim.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
|
||
. /usr/include/stdlib.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
|
||
.. /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/floatn.h
|
||
... /usr/include/x86_64-linux-gnu/bits/floatn-common.h
|
||
.... /usr/include/x86_64-linux-gnu/bits/long-double.h
|
||
.. /usr/include/x86_64-linux-gnu/bits/stdlib-float.h
|
||
. src/error.h
|
||
.. /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
|
||
. src/data.h
|
||
.. /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
|
||
. src/output.h
|
||
Multiple include guards may be useful <span class="k">for</span>:
|
||
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h
|
||
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h
|
||
/usr/include/x86_64-linux-gnu/bits/typesizes.h
|
||
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h
|
||
/usr/include/x86_64-linux-gnu/gnu/stubs.h
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="dot-file">
|
||
<h4>6.2.2 dot File<a class="headerlink" href="#dot-file" title="Permalink to this headline">¶</a></h4>
|
||
<p><strong>Graphviz</strong> ist ein mächtiges Tool-Set welches Graphen, definiert in
|
||
einem <code class="docutils literal notranslate"><span class="pre">dot</span></code>-Text File, automatisch anordnet und in <code class="docutils literal notranslate"><span class="pre">png</span></code>, <code class="docutils literal notranslate"><span class="pre">gif</span></code> und
|
||
andere Formate übersetzt.</p>
|
||
<p>Siehe die offizielle Web-Page
|
||
<a class="reference external" href="https://www.graphviz.org/">https://www.graphviz.org/</a>.</p>
|
||
<p>Es gibt als Teil dieses Tool-Sets verschiedene Übersetzer. Der hier
|
||
verwendete ist der Basis-übersetzer: <code class="docutils literal notranslate"><span class="pre">dot</span></code>.</p>
|
||
<p>Das <code class="docutils literal notranslate"><span class="pre">dot</span></code>-File Format kennt viele Möglichkeiten die Knoten und Kanten
|
||
eines Graphen und deren Anordnung anzugeben.</p>
|
||
<p>Der Vorteil eines solchen Tool-Sets ist, dass man den Inhalt (den
|
||
Graphen) einfach definieren kann und sich nicht um das komplexe
|
||
Problem der ansprechenden Visualisierung kümmern muss.</p>
|
||
<p><strong>Beispiel File</strong> (<code class="docutils literal notranslate"><span class="pre">dot</span> <span class="pre">-Tpng</span> <span class="pre">sample.dot</span> <span class="pre">></span> <span class="pre">sample.png</span></code>)</p>
|
||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="n">digraph</span><span class="w"> </span><span class="n">G</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="p">[</span><span class="n">shape</span><span class="o">=</span><span class="n">box</span><span class="p">]</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">[</span><span class="n">label</span><span class="o">=</span><span class="s">"a.c"</span><span class="p">];</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="p">[</span><span class="n">label</span><span class="o">=</span><span class="s">"a.h"</span><span class="p">];</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">C</span><span class="w"> </span><span class="p">[</span><span class="n">label</span><span class="o">=</span><span class="s">"b.h"</span><span class="p">];</span><span class="w"></span>
|
||
|
||
<span class="w"> </span><span class="n">subgraph</span><span class="w"> </span><span class="n">cluster_c0</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">label</span><span class="o">=</span><span class="s">"main"</span><span class="p">;</span><span class="w"> </span><span class="n">color</span><span class="o">=</span><span class="n">black</span><span class="p">;</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">A</span><span class="p">;</span><span class="w"></span>
|
||
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||
|
||
<span class="w"> </span><span class="n">subgraph</span><span class="w"> </span><span class="n">cluster_c1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">label</span><span class="o">=</span><span class="s">"others"</span><span class="p">;</span><span class="w"> </span><span class="n">style</span><span class="o">=</span><span class="n">filled</span><span class="p">;</span><span class="w"> </span><span class="n">color</span><span class="o">=</span><span class="n">lightgrey</span><span class="p">;</span><span class="w"></span>
|
||
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">B</span><span class="p">;</span><span class="w"> </span><span class="n">C</span><span class="p">;</span><span class="w"> </span><span class="n">rank</span><span class="o">=</span><span class="n">same</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||
|
||
<span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">B</span><span class="p">;</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">C</span><span class="p">;</span><span class="w"></span>
|
||
<span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">C</span><span class="p">;</span><span class="w"></span>
|
||
<span class="p">}</span><span class="w"></span>
|
||
</pre></div>
|
||
</div>
|
||
<p><img alt="" src="../_images/bsp_dot.png" /></p>
|
||
</section>
|
||
<section id="png-file">
|
||
<h4>6.2.3 png File<a class="headerlink" href="#png-file" title="Permalink to this headline">¶</a></h4>
|
||
<p>Das <code class="docutils literal notranslate"><span class="pre">png</span></code> Format ist ein verlustfrei komprimiertes Raster Graphik
|
||
Format. Es wird oft in Web Pages verwendet.</p>
|
||
<hr class="docutils" />
|
||
<p>Version: 22.02.2022</p>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo">
|
||
<a href="../index.html">
|
||
<img class="logo" src="../_static/logo.png" alt="Logo"/>
|
||
|
||
<h1 class="logo logo-name">SNP Labs</h1>
|
||
|
||
</a>
|
||
</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="../P01_Erste_Schritte_mit_C/README.html">01 - Erste Schritte mit C</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P02_Funktionen_Datentyp_enum/README.html">02: Funktionen, Datentyp “enum”</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P03_Bit_Operation_struct_typedef/README.html">03 - Bit Operationen, Struct, Typedef</a></li>
|
||
<li class="toctree-l1 current"><a class="current reference internal" href="#">04 - Modularisieren von C Code</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="#ubersicht">1. Übersicht</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#lernziele">2. Lernziele</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#aufgabe-1-modularisieren">3. Aufgabe 1: Modularisieren</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#tipps">Tipps</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#aufgabe-2-makefile-regeln">4. Aufgabe 2: Makefile Regeln</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#neue-regeln-hinzufugen">4.1 Neue Regeln hinzufügen</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#resultate-analysieren-und-erklaren">4.2 Resultate analysieren und erklären</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#bewertung">5. Bewertung</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#anhang">6. Anhang</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#verwendete-zusatzliche-sprach-elemente">6.1 Verwendete zusätzliche Sprach Elemente</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#verarbeitung-und-verwendete-file-formate-a-name-file-formats-a">6.2 Verarbeitung und verwendete File Formate <a name="file_formats"></a></a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#dep-file">6.2.1 dep File</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#dot-file">6.2.2 dot File</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#png-file">6.2.3 png File</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P05_TicTacToe/README.html">05 - Arrays/Strings/TicTacToe</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P06_Personen_Verwaltung_Linked_List/README.html">06 - Personen Verwaltung – Linked List</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P07_Prozesse_und_Threads/README.html">07 - Prozesse und Threads</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P08_Sync/README.html">08 - Synchronisationsprobleme</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P09_File_Operations/README.html">09 - File Operations</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../P10_IPC/README.html">10 - IPC</a></li>
|
||
</ul>
|
||
|
||
<div class="relations">
|
||
<h3>Related Topics</h3>
|
||
<ul>
|
||
<li><a href="../index.html">Documentation overview</a><ul>
|
||
<li>Previous: <a href="../P03_Bit_Operation_struct_typedef/README.html" title="previous chapter">03 - Bit Operationen, Struct, Typedef</a></li>
|
||
<li>Next: <a href="../P05_TicTacToe/README.html" title="next chapter">05 - Arrays/Strings/TicTacToe</a></li>
|
||
</ul></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="footer">
|
||
©2022, stsh.
|
||
|
||
|
|
||
Powered by <a href="http://sphinx-doc.org/">Sphinx 4.3.2</a>
|
||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
||
|
||
|
|
||
<a href="../_sources/P04_Modularisieren_von_C_Code/README.md.txt"
|
||
rel="nofollow">Page source</a>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |