root/doc_inner/doxygen/latex/label_8c_source.tex

/* [<][>][^][v][top][bottom][index][help] */
\doxysection{label.\+c}
\label{label_8c_source}\index{src/label.c@{src/label.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}assemble.h"{}}}
\DoxyCodeLine{00002\ }
\DoxyCodeLine{00010\ HKEY\ *label\_hashkey(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *value);}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00020\ \textcolor{keywordtype}{unsigned}\ labelhash(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *prog,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *label);}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00030\ \textcolor{keywordtype}{int}\ compare\_adr(\textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *a,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *b);}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00035\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ labelcnt\ =\ 0;}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00040\ \textcolor{keyword}{static}\ LABELTAB\ *labels[LABELTABSIZE];}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00045\ \textcolor{keyword}{static}\ CERR\ cerr\_label[]\ =\ \{}
\DoxyCodeLine{00046\ \ \ \ \ \{\ 101,\ \textcolor{stringliteral}{"{}label\ already\ defined"{}}\ \},}
\DoxyCodeLine{00047\ \ \ \ \ \{\ 102,\ \textcolor{stringliteral}{"{}label\ table\ is\ full"{}}\ \},}
\DoxyCodeLine{00048\ \ \ \ \ \{\ 103,\ \textcolor{stringliteral}{"{}label\ not\ found"{}}\ \},}
\DoxyCodeLine{00049\ \};}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ HKEY\ *label\_hashkey(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *value)\ \{}
\DoxyCodeLine{00052\ \ \ \ \ HKEY\ *key\ =\ NULL;}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ \ \ \ \ key\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(HKEY),\ \textcolor{stringliteral}{"{}label\_hashkey"{}});}
\DoxyCodeLine{00055\ \ \ \ \ key-\/>type\ =\ CHARS;}
\DoxyCodeLine{00056\ \ \ \ \ key-\/>val.s\ =\ strdup\_chk(value,\ \textcolor{stringliteral}{"{}label\_hashkey-\/>value"{}});}
\DoxyCodeLine{00057\ \ \ \ \ \textcolor{keywordflow}{return}\ key;}
\DoxyCodeLine{00058\ \}}
\DoxyCodeLine{00059\ }
\DoxyCodeLine{00060\ \textcolor{keywordtype}{unsigned}\ labelhash(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *prog,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *label)}
\DoxyCodeLine{00061\ \{}
\DoxyCodeLine{00062\ \ \ \ \ HKEY\ *keys[2]\ =\ \{NULL\};}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keywordtype}{int}\ i\ =\ 0;}
\DoxyCodeLine{00064\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ h\ =\ 0;}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keywordflow}{if}(prog[0])\ \{}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ keys[i++]\ =\ label\_hashkey(prog);}
\DoxyCodeLine{00068\ \ \ \ \ \}}
\DoxyCodeLine{00069\ \ \ \ \ keys[i]\ =\ label\_hashkey(label);}
\DoxyCodeLine{00070\ \ \ \ \ h\ =\ hash(i+1,\ keys,\ LABELTABSIZE);}
\DoxyCodeLine{00071\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ j\ =\ 0;\ j\ <\ i\ +\ 1;\ j++)\ \{}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ FREE(keys[j]-\/>val.s);}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ FREE(keys[j]);}
\DoxyCodeLine{00074\ \ \ \ \ \}}
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keywordflow}{return}\ h;}
\DoxyCodeLine{00076\ \}}
\DoxyCodeLine{00077\ }
\DoxyCodeLine{00078\ \textcolor{keywordtype}{int}\ compare\_adr(\textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *a,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *b)}
\DoxyCodeLine{00079\ \{}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordflow}{return}\ (**(LABELARRAY\ **)a).adr\ -\/\ (**(LABELARRAY\ **)b).adr;}
\DoxyCodeLine{00081\ \}}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \textcolor{comment}{/*\ assemble.hで定義された関数群\ */}}
\DoxyCodeLine{00084\ \textcolor{keywordtype}{void}\ addcerrlist\_label()}
\DoxyCodeLine{00085\ \{}
\DoxyCodeLine{00086\ \ \ \ \ addcerrlist(ARRAYSIZE(cerr\_label),\ cerr\_label);}
\DoxyCodeLine{00087\ \}}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ WORD\ getlabel(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *prog,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *label)}
\DoxyCodeLine{00090\ \{}
\DoxyCodeLine{00091\ \ \ \ \ assert(prog\ !=\ NULL\ \&\&\ label\ !=\ NULL);}
\DoxyCodeLine{00092\ \ \ \ \ LABELTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00093\ \ \ \ \ LABELARRAY\ *l\ =\ NULL;}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ labels[labelhash(prog,\ label)];\ p\ !=\ NULL;\ p\ =\ p-\/>next)\ \{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ l\ =\ p-\/>label;}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}((!prog[0]\ ||\ (strcmp(prog,\ l-\/>prog)\ ==\ 0))\ \&\&}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ \ strcmp(label,\ l-\/>label)\ ==\ 0)}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ l-\/>adr;}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00102\ \ \ \ \ \}}
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{keywordflow}{return}\ 0xFFFF;}
\DoxyCodeLine{00104\ \}}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ \textcolor{keywordtype}{bool}\ addlabel(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *prog,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *label,\ WORD\ adr)}
\DoxyCodeLine{00107\ \{}
\DoxyCodeLine{00108\ \ \ \ \ assert(label\ !=\ NULL);}
\DoxyCodeLine{00109\ \ \ \ \ LABELTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00110\ \ \ \ \ LABELARRAY\ *l\ =\ NULL;}
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ h\ =\ 0;}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{comment}{/*\ 登録されたラベルを検索。すでに登録されている場合はエラー発生\ */}}
\DoxyCodeLine{00114\ \ \ \ \ \textcolor{keywordflow}{if}(getlabel(prog,\ label)\ !=\ 0xFFFF)\ \{}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ setcerr(101,\ label);\ \ \ \ \textcolor{comment}{/*\ label\ already\ defined\ */}}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
\DoxyCodeLine{00117\ \ \ \ \ \}}
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{comment}{/*\ メモリを確保\ */}}
\DoxyCodeLine{00119\ \ \ \ \ p\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(LABELTAB),\ \textcolor{stringliteral}{"{}labels.next"{}});}
\DoxyCodeLine{00120\ \ \ \ \ l\ =\ p-\/>label\ =\ malloc\_chk(\textcolor{keyword}{sizeof}(LABELARRAY),\ \textcolor{stringliteral}{"{}labels.label"{}});}
\DoxyCodeLine{00121\ \ \ \ \ \textcolor{comment}{/*\ プログラム名を設定\ */}}
\DoxyCodeLine{00122\ \ \ \ \ l-\/>prog\ =\ strdup\_chk(prog,\ \textcolor{stringliteral}{"{}label.prog"{}});}
\DoxyCodeLine{00123\ \ \ \ \ \textcolor{comment}{/*\ ラベルを設定\ */}}
\DoxyCodeLine{00124\ \ \ \ \ l-\/>label\ =\ strdup\_chk(label,\ \textcolor{stringliteral}{"{}label.label"{}});}
\DoxyCodeLine{00125\ \ \ \ \ \textcolor{comment}{/*\ アドレスを設定\ */}}
\DoxyCodeLine{00126\ \ \ \ \ l-\/>adr\ =\ adr;}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{comment}{/*\ ラベル数を設定\ */}}
\DoxyCodeLine{00128\ \ \ \ \ labelcnt++;}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{comment}{/*\ ハッシュ表へ追加\ */}}
\DoxyCodeLine{00130\ \ \ \ \ p-\/>next\ =\ labels[h\ =\ labelhash(prog,\ label)];}
\DoxyCodeLine{00131\ \ \ \ \ labels[h]\ =\ p;}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00133\ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \textcolor{keywordtype}{void}\ printlabel()}
\DoxyCodeLine{00136\ \{}
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{keywordtype}{int}\ s\ =\ 0;}
\DoxyCodeLine{00138\ \ \ \ \ LABELTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00139\ \ \ \ \ LABELARRAY\ **l\ =\ \{NULL\};}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \ \ \ \ l\ =\ calloc\_chk(labelcnt,\ \textcolor{keyword}{sizeof}(LABELARRAY\ **),\ \textcolor{stringliteral}{"{}labels"{}});}
\DoxyCodeLine{00142\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ LABELTABSIZE;\ i++)\ \{}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ labels[i];\ p\ !=\ NULL;\ p\ =\ p-\/>next)\ \{}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ assert(p-\/>label\ !=\ NULL);}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \ \ \ \ l[s++]\ =\ p-\/>label;}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00147\ \ \ \ \ \}}
\DoxyCodeLine{00148\ \ \ \ \ qsort(l,\ s,\ \textcolor{keyword}{sizeof}(*l),\ compare\_adr);}
\DoxyCodeLine{00149\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ s;\ i++)\ \{}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(l[i]-\/>prog[0])\ \{}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\%s."{}},\ l[i]-\/>prog);}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\%s\ -\/-\/-\/>\ \#\%04X\(\backslash\)n"{}},\ l[i]-\/>label,\ l[i]-\/>adr);}
\DoxyCodeLine{00154\ \ \ \ \ \}}
\DoxyCodeLine{00155\ \ \ \ \ FREE(l);}
\DoxyCodeLine{00156\ \}}
\DoxyCodeLine{00157\ }
\DoxyCodeLine{00158\ \textcolor{keywordtype}{void}\ freelabel()}
\DoxyCodeLine{00159\ \{}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{00161\ \ \ \ \ LABELTAB\ *p\ =\ NULL;}
\DoxyCodeLine{00162\ \ \ \ \ LABELTAB\ *q\ =\ NULL;}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{keywordflow}{for}(i\ =\ 0;\ i\ <\ LABELTABSIZE;\ i++)\ \{}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}(p\ =\ labels[i];\ p\ !=\ NULL;\ p\ =\ q)\ \{}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \ \ \ \ q\ =\ p-\/>next;}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \ \ \ \ FREE(p-\/>label-\/>prog);}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \ \ \ \ FREE(p-\/>label-\/>label);}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ \ \ \ \ FREE(p-\/>label);}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \ \ \ \ FREE(p);}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ labels[i]\ =\ NULL;}
\DoxyCodeLine{00173\ \ \ \ \ \}}
\DoxyCodeLine{00174\ \}}

\end{DoxyCode}

/* [<][>][^][v][top][bottom][index][help] */