\doxysection{src/utils.c File Reference} \hypertarget{utils_8c}{}\label{utils_8c}\index{src/utils.c@{src/utils.c}} Primitives utilitaires pour la manipulation, le reformatage et la résolution canonique des chemins de fichiers. {\ttfamily \#include "{}utils.\+h"{}}\newline Include dependency graph for utils.\+c\+: % FIG 0 \doxysubsubsection*{Functions} \begin{DoxyCompactItemize} \item void \mbox{\hyperlink{utils_8c_ab69c307e63e50216d3883ff4a95b99ff}{format\+\_\+path}} (char \texorpdfstring{$\ast$}{*}dest, char \texorpdfstring{$\ast$}{*}src, int dest\+\_\+len) \begin{DoxyCompactList}\small\item\em Formate un chemin source (src) pour s\textquotesingle{}assurer qu\textquotesingle{}il devienne un chemin absolu exploitable. \end{DoxyCompactList}\item int \mbox{\hyperlink{utils_8c_ac66022e5495a0feb8b41f0dfb9ba0ab7}{get\+\_\+name\+\_\+and\+\_\+parent\+\_\+path\+\_\+by\+\_\+absolute\+\_\+path}} (char \texorpdfstring{$\ast$}{*}path, char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}parent\+\_\+path, char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}name) \begin{DoxyCompactList}\small\item\em Extrait séparément le chemin du dossier parent et le nom d\textquotesingle{}un fichier à partir d\textquotesingle{}un chemin absolu. \end{DoxyCompactList}\item int \mbox{\hyperlink{utils_8c_a25cbf6325c786277edbc6bd9a107b461}{get\+\_\+dirname\+\_\+and\+\_\+parent\+\_\+path\+\_\+by\+\_\+absolute\+\_\+path}} (char \texorpdfstring{$\ast$}{*}dirpath, char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}parent\+\_\+path, char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}dirname) \begin{DoxyCompactList}\small\item\em Extrait séparément le chemin du dossier parent et le nom d\textquotesingle{}un répertoire à partir d\textquotesingle{}un chemin absolu. \end{DoxyCompactList}\item void \mbox{\hyperlink{utils_8c_a68fcd11496e85e696054f27ea8be892a}{canonicalize\+\_\+path}} (char \texorpdfstring{$\ast$}{*}path) \begin{DoxyCompactList}\small\item\em Canonicalise un chemin absolu en résolvant les expressions de navigation relative "{}."{} et "{}.."{}. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection{Detailed Description} Primitives utilitaires pour la manipulation, le reformatage et la résolution canonique des chemins de fichiers. Ce fichier rassemble les fonctions de manipulation de chaînes dédiées à la gestion des chemins. Il prend en charge la conversion des chemins relatifs en chemins absolus, l\textquotesingle{}extraction des couples (Dossier parent, Cible) et l\textquotesingle{}évaluation des segments de navigation relative ("{}."{} et "{}.."{}). \doxysubsection{Function Documentation} \Hypertarget{utils_8c_a68fcd11496e85e696054f27ea8be892a}\label{utils_8c_a68fcd11496e85e696054f27ea8be892a} \index{utils.c@{utils.c}!canonicalize\_path@{canonicalize\_path}} \index{canonicalize\_path@{canonicalize\_path}!utils.c@{utils.c}} \doxysubsubsection{\texorpdfstring{canonicalize\_path()}{canonicalize\_path()}} {\footnotesize\ttfamily void canonicalize\+\_\+path (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{path }\end{DoxyParamCaption})} Canonicalise un chemin absolu en résolvant les expressions de navigation relative "{}."{} et "{}.."{}. Cette fonction nettoie le chemin en appliquant un algorithme de pile (Stack) \+: \begin{DoxyItemize} \item Divise le chemin en tokens séparés par des \textquotesingle{}/\textquotesingle{}. \item Chaque dossier classique est empilé. \item Un élément "{}."{} est simplement ignoré. \item Un élément "{}.."{} dépile l\textquotesingle{}élément supérieur (remonte d\textquotesingle{}un niveau), sans descendre en dessous de la racine. Le chemin d\textquotesingle{}origine est ensuite réécrit proprement sous sa forme absolue finale aplatie. \end{DoxyItemize} \begin{DoxyParams}{Parameters} {\em path} & Pointeur vers la chaîne contenant le chemin à simplifier. Modifié directement en place. \\ \hline \end{DoxyParams} \Hypertarget{utils_8c_ab69c307e63e50216d3883ff4a95b99ff}\label{utils_8c_ab69c307e63e50216d3883ff4a95b99ff} \index{utils.c@{utils.c}!format\_path@{format\_path}} \index{format\_path@{format\_path}!utils.c@{utils.c}} \doxysubsubsection{\texorpdfstring{format\_path()}{format\_path()}} {\footnotesize\ttfamily void format\+\_\+path (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{dest, }\item[{char \texorpdfstring{$\ast$}{*}}]{src, }\item[{int}]{dest\+\_\+len }\end{DoxyParamCaption})} Formate un chemin source (src) pour s\textquotesingle{}assurer qu\textquotesingle{}il devienne un chemin absolu exploitable. \begin{DoxyItemize} \item Si le chemin source est vide, NULL ou égal à "{}/"{}, la destination reçoit "{}/"{}. \item Si le chemin source est déjà absolu (commence par \textquotesingle{}/\textquotesingle{}), il est copié tel quel. \item Si le chemin est relatif, la fonction récupère le répertoire de travail actuel ("{}\+PWD"{}) via l\textquotesingle{}environnement pour reconstruire le chemin absolu équivalent sous la forme {\ttfamily PWD/src}. \end{DoxyItemize} \begin{DoxyParams}{Parameters} {\em dest} & Tampon de destination devant recevoir le chemin absolu formaté. \\ \hline {\em src} & Chaîne de caractères du chemin d\textquotesingle{}origine (relatif ou absolu). \\ \hline {\em dest\+\_\+len} & Taille maximale allouée pour le tampon de destination (évite les dépassements). \\ \hline \end{DoxyParams} \Hypertarget{utils_8c_a25cbf6325c786277edbc6bd9a107b461}\label{utils_8c_a25cbf6325c786277edbc6bd9a107b461} \index{utils.c@{utils.c}!get\_dirname\_and\_parent\_path\_by\_absolute\_path@{get\_dirname\_and\_parent\_path\_by\_absolute\_path}} \index{get\_dirname\_and\_parent\_path\_by\_absolute\_path@{get\_dirname\_and\_parent\_path\_by\_absolute\_path}!utils.c@{utils.c}} \doxysubsubsection{\texorpdfstring{get\_dirname\_and\_parent\_path\_by\_absolute\_path()}{get\_dirname\_and\_parent\_path\_by\_absolute\_path()}} {\footnotesize\ttfamily int get\+\_\+dirname\+\_\+and\+\_\+parent\+\_\+path\+\_\+by\+\_\+absolute\+\_\+path (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{dirpath, }\item[{char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}}]{parent\+\_\+path, }\item[{char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}}]{dirname }\end{DoxyParamCaption})} Extrait séparément le chemin du dossier parent et le nom d\textquotesingle{}un répertoire à partir d\textquotesingle{}un chemin absolu. \begin{DoxyNote}{Note} Cette fonction applique le même algorithme binaire de découpage que \end{DoxyNote} \begin{DoxySeeAlso}{See also} \doxylink{utils_8c_ac66022e5495a0feb8b41f0dfb9ba0ab7}{get\+\_\+name\+\_\+and\+\_\+parent\+\_\+path\+\_\+by\+\_\+absolute\+\_\+path}, mais s\textquotesingle{}applique sémantiquement aux répertoires. \end{DoxySeeAlso} \begin{DoxyParams}{Parameters} {\em dirpath} & Le chemin absolu du répertoire à traiter. \\ \hline {\em parent\+\_\+path} & Pointeur de sortie vers la chaîne allouée du dossier parent. \\ \hline {\em dirname} & Pointeur de sortie vers la chaîne allouée du nom du répertoire ciblé. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 si l\textquotesingle{}entrée est NULL ou vide. \end{DoxyReturn} \Hypertarget{utils_8c_ac66022e5495a0feb8b41f0dfb9ba0ab7}\label{utils_8c_ac66022e5495a0feb8b41f0dfb9ba0ab7} \index{utils.c@{utils.c}!get\_name\_and\_parent\_path\_by\_absolute\_path@{get\_name\_and\_parent\_path\_by\_absolute\_path}} \index{get\_name\_and\_parent\_path\_by\_absolute\_path@{get\_name\_and\_parent\_path\_by\_absolute\_path}!utils.c@{utils.c}} \doxysubsubsection{\texorpdfstring{get\_name\_and\_parent\_path\_by\_absolute\_path()}{get\_name\_and\_parent\_path\_by\_absolute\_path()}} {\footnotesize\ttfamily int get\+\_\+name\+\_\+and\+\_\+parent\+\_\+path\+\_\+by\+\_\+absolute\+\_\+path (\begin{DoxyParamCaption}\item[{char \texorpdfstring{$\ast$}{*}}]{path, }\item[{char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}}]{parent\+\_\+path, }\item[{char \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}}]{name }\end{DoxyParamCaption})} Extrait séparément le chemin du dossier parent et le nom d\textquotesingle{}un fichier à partir d\textquotesingle{}un chemin absolu. La fonction isole le dernier segment du chemin en recherchant le dernier caractère \textquotesingle{}/\textquotesingle{}. \begin{DoxyItemize} \item Si aucun \textquotesingle{}/\textquotesingle{} n\textquotesingle{}est trouvé, le répertoire parent est défini sur le "{}\+PWD"{} actuel et le nom correspond au chemin brut. \item Si le chemin se termine par un \textquotesingle{}/\textquotesingle{} optionnel, ce dernier est temporairement tronqué pour éviter une fausse interprétation. \end{DoxyItemize} \begin{DoxyNote}{Note} Les deux pointeurs de sortie {\ttfamily parent\+\_\+path} et {\ttfamily name} reçoivent des chaînes allouées dynamiquement par {\ttfamily strdup()}. Elles doivent être libérées par l\textquotesingle{}appelant. \end{DoxyNote} \begin{DoxyParams}{Parameters} {\em path} & Le chemin absolu d\textquotesingle{}origine à analyser. \\ \hline {\em parent\+\_\+path} & Pointeur de sortie qui recevra l\textquotesingle{}adresse du chemin du dossier parent alloué. \\ \hline {\em name} & Pointeur de sortie qui recevra l\textquotesingle{}adresse du nom isolé du fichier alloué. \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} int 0 en cas de succès, -\/1 si le paramètre path est invalide (NULL ou vide). \end{DoxyReturn}