X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=include%2Fcmem.h;h=2411980260f8bee8a1b8465830f7e612e6c75788;hp=a38c81d9bf0b1d822e9b116ccf62d81ee9faa7ee;hb=b3a2b67b19dd12e2e1e4bf633f83442df14374d2;hpb=7f7bde5dd1305cfc598fe09030c69aad0dc01368 diff --git a/include/cmem.h b/include/cmem.h index a38c81d..2411980 100644 --- a/include/cmem.h +++ b/include/cmem.h @@ -1,33 +1,97 @@ #ifndef YACASL2_CMEM_H_INCLUDED #define YACASL2_CMEM_H_INCLUDED + +#include #include +#include +#include +#include -/* - * 配列のサイズを返す +/** + * @brief 配列のサイズを返すマクロ */ #ifndef ARRAYSIZE #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0])) #endif /** - * mallocを実行し、0で初期化 + * @brief メモリを解放するマクロ + */ +#ifndef FREE +#define FREE(ptr) {free(ptr); ptr = NULL;} +#endif + +/** + * @brief mallocを実行し、0で初期化する + * * メモリを確保できない場合はエラーを出力して終了 + * + * @return なし + * + * @param size メモリーのサイズ + * @param tag エラーメッセージなどで表示されるタグ */ -void *malloc_chk(size_t size, char *tag); +void *malloc_chk(size_t size, const char *tag); /** - * callocを実行 + * @brief 領域の数とサイズを指定してメモリーを確保するcallocを実行する + * * メモリを確保できない場合はエラーを出力して終了 + * + * @return なし + * + * @param nmemb 領域の数 + * @param size 領域1個あたりのメモリーサイズ + * @param tag エラーメッセージなどで表示されるタグ + */ +void *calloc_chk(size_t nmemb, size_t size, const char *tag); + +/** + * @brief malloc_chkを実行してメモリを確保し、コピーした文字列を返す + * + * @return コピーした文字列 + * + * @param s 文字列 + * @param tag エラーメッセージなどで表示されるタグ + */ +char *strdup_chk(const char *s, const char *tag); + +/** + * @brief malloc_chkを実行してメモリを確保し、コピーした文字列の指定した長さの部分を返す + * + * @return コピーした文字列 + * + * @param s 文字列 + * @param len 文字列の長さ + * @param tag エラーメッセージなどで表示されるタグ */ -void *calloc_chk(size_t nmemb, size_t size, char *tag); +char *strndup_chk(const char *s, size_t len, const char *tag); /** - * malloc_chkを実行してメモリを確保し、コピーした文字列を返す + * @brief 文字列の末尾から、改行と空白とタブを削除する + * + * @return なし + * + * @param s 文字列 */ -char *strdup_chk(const char *s, char *tag); +void strip_end(char *s); /** - * メモリを解放 + * @brief 文字列から「'」以降の文字列をCASL IIのコメントとして削除する。「''」の場合は除く + * + * @return なし + * + * @param s 文字列 */ -void free_chk(void *ptr, char *tag); +void strip_casl2_comment(char *s); + +/** + * @brief 逆にした文字列を返す + * + * @return 逆にしたした文字列 + * + * @param s 文字列 + */ +char *strrev(const char *s); + #endif