\doxysection{cerr.\+c}
\label{cerr_8c_source}\index{src/cerr.c@{src/cerr.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}cerr.h"{}}}
\DoxyCodeLine{00002\ }
\DoxyCodeLine{00003\ \textcolor{keywordtype}{void}\ cerr\_init()}
\DoxyCodeLine{00004\ \{}
\DoxyCodeLine{00005\ \ \ \ \ cerr\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(CERR),\ \textcolor{stringliteral}{"{}cerr"{}});}
\DoxyCodeLine{00006\ \ \ \ \ cerr-\/>num\ =\ 0;}
\DoxyCodeLine{00007\ \}}
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ CERR\ *cerr\ =\ NULL;}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ CERRLIST\ *cerrlist\ =\ NULL;}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \textcolor{keywordtype}{void}\ addcerrlist(\textcolor{keywordtype}{int}\ cerrc,\ CERR\ cerrv[])}
\DoxyCodeLine{00014\ \{}
\DoxyCodeLine{00015\ \ \ \ \ CERRLIST\ *stat\ =\ NULL;}
\DoxyCodeLine{00016\ \ \ \ \ CERRLIST\ *p\ =\ NULL;}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ \ \ \ \ assert(cerrc\ >\ 0\ \&\&\ cerrv\ !=\ NULL);}
\DoxyCodeLine{00019\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ cerrc;\ i++)\ \{}
\DoxyCodeLine{00020\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(p\ ==\ NULL)\ \{}
\DoxyCodeLine{00021\ \ \ \ \ \ \ \ \ \ \ \ \ stat\ =\ p\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(CERRLIST),\ \textcolor{stringliteral}{"{}cerrlist"{}});}
\DoxyCodeLine{00022\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00023\ \ \ \ \ \ \ \ \ \ \ \ \ p\ =\ p-\/>next\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(CERRLIST),\ \textcolor{stringliteral}{"{}cerrlist-\/>next"{}});}
\DoxyCodeLine{00024\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00025\ \ \ \ \ \ \ \ \ p-\/>cerr\ =\ \&cerrv[i];}
\DoxyCodeLine{00026\ \ \ \ \ \ \ \ \ p-\/>next\ =\ NULL;}
\DoxyCodeLine{00027\ \ \ \ \ \}}
\DoxyCodeLine{00028\ \ \ \ \ p-\/>next\ =\ cerrlist;}
\DoxyCodeLine{00029\ \ \ \ \ cerrlist\ =\ stat;}
\DoxyCodeLine{00030\ \}}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \textcolor{keywordtype}{void}\ printcerrlist()}
\DoxyCodeLine{00033\ \{}
\DoxyCodeLine{00034\ \ \ \ \ CERRLIST\ *p\ =\ NULL;}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keywordflow}{if}(cerrlist\ ==\ NULL)\ \{}
\DoxyCodeLine{00037\ \ \ \ \ \ \ \ \ puts(\textcolor{stringliteral}{"{}error\ list\ is\ null."{}});}
\DoxyCodeLine{00038\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00039\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ cerrlist;\ p\ !=\ NULL;\ p\ =\ p-\/>next)\ \{}
\DoxyCodeLine{00040\ \ \ \ \ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\%d:\ \%s\(\backslash\)n"{}},\ p-\/>cerr-\/>num,\ p-\/>cerr-\/>msg);}
\DoxyCodeLine{00041\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00042\ \ \ \ \ \}}
\DoxyCodeLine{00043\ \}}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ \textcolor{keywordtype}{void}\ setcerr(\textcolor{keywordtype}{int}\ num,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str)}
\DoxyCodeLine{00046\ \{}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{comment}{/*\ 現在のエラー番号を設定\ \ */}}
\DoxyCodeLine{00048\ \ \ \ \ cerr-\/>num\ =\ num;}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{comment}{/*\ 現在のエラーメッセージを設定\ */}}
\DoxyCodeLine{00050\ \ \ \ \ cerr-\/>msg\ =\ malloc\_chk(CERRMSGSIZE\ +\ 1,\ \textcolor{stringliteral}{"{}cerr.msg"{}});}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keywordflow}{if}(0\ <\ strlen(str)\ \&\&\ strlen(str)\ <=\ CERRSTRSIZE)\ \{}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ sprintf(cerr-\/>msg,\ \textcolor{stringliteral}{"{}\%s:\ \%s"{}},\ str,\ getcerrmsg(cerr-\/>num));}
\DoxyCodeLine{00053\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ strcpy(cerr-\/>msg,\ getcerrmsg(cerr-\/>num));}
\DoxyCodeLine{00055\ \ \ \ \ \}}
\DoxyCodeLine{00056\ \}}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{keywordtype}{char}\ *getcerrmsg(\textcolor{keywordtype}{int}\ num)}
\DoxyCodeLine{00059\ \{}
\DoxyCodeLine{00060\ \ \ \ \ CERRLIST\ *p\ =\ NULL;}
\DoxyCodeLine{00061\ \ \ \ \ \textcolor{keywordtype}{char}\ *msg\ =\ \textcolor{stringliteral}{"{}unknown\ error"{}};}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ cerrlist;\ p\ !=\ NULL;\ p\ =\ p-\/>next)\ \{}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(num\ ==\ p-\/>cerr-\/>num)\ \{}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \ \ \ \ msg\ =\ p-\/>cerr-\/>msg;}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00068\ \ \ \ \ \}}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keywordflow}{return}\ msg;}
\DoxyCodeLine{00070\ \}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \textcolor{keywordtype}{void}\ freecerr()}
\DoxyCodeLine{00073\ \{}
\DoxyCodeLine{00074\ \ \ \ \ CERRLIST\ *p\ =\ NULL;}
\DoxyCodeLine{00075\ \ \ \ \ CERRLIST\ *q\ =\ NULL;}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{comment}{/*\ 現在のエラーメッセージを解放\ */}}
\DoxyCodeLine{00078\ \ \ \ \ FREE(cerr-\/>msg);}
\DoxyCodeLine{00079\ \ \ \ \ \textcolor{comment}{/*\ 現在のエラーを解放\ */}}
\DoxyCodeLine{00080\ \ \ \ \ FREE(cerr);}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{comment}{/*\ エラーリストを解放\ */}}
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ cerrlist;\ p\ !=\ NULL;\ p\ =\ q)\ \{}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ q\ =\ p-\/>next;}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ FREE(p);}
\DoxyCodeLine{00085\ \ \ \ \ \}}
\DoxyCodeLine{00086\ \}}
\end{DoxyCode}