a4_0011
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
* acl4のページ0011
-(by [[K]], 2026.02.11)
** (1)
#if (a_Version >= 1)
#define Preprocessor_SourceFile a_Pr...
#define Preprocessor_SourceFile_ini a_Pr...
#define Preprocessor_SourceFile_din a_Pr...
#define Preprocessor_SourceFile_read a_Pr...
#define Preprocessor_SourceFile_gets a_Pr...
#define Preprocessor_SourceFiles a_Pr...
#define Preprocessor_SourceFiles_ini a_Pr...
#define Preprocessor_SourceFiles_din a_Pr...
#define Preprocessor_SourceFiles_addFile a_Pr...
#define Preprocessor_SourceFiles_addBuf a_Pr...
#define Preprocessor_SourceFiles_getSf a_Pr...
#define Preprocessor_SourceFiles_gets a_Pr...
#define Preprocessor_isDirective a_Pr...
#endif
a_class(a_Preprocessor_SourceFile) {
a_VecChr src[1], path[1];
intptr_t lin;
char *s;
};
a_static void a_Preprocessor_SourceFile_ini(a_Preprocess...
{
a_VecChr_ini4(w->src, w->path, 0, 0);
w->lin = 0;
}
a_static void a_Preprocessor_SourceFile_din(a_Preprocess...
{
a_VecChr_din4(w->src, w->path, 0, 0);
}
a_static intptr_t a_Preprocessor_SourceFile_read(a_Prepr...
{
intptr_t i = 0;
a_VecChr_puts(w->path, path, path + n);
if (n >= 7 && strncmp(path, "inline:", 7) == 0) {
a_VecChr_puts(w->src, &path[7], path + n);
a_VecChr_convEsc(w->src);
} else {
i = a_VecChr_readFileAll(w->src, w->path->p);
a_VecChr_eraseCr(w->src);
}
if (i >= 0) { i = w->src->n; w->s = w->src->p; }
return i;
}
a_static void a_Preprocessor_SourceFile_gets(a_Preproces...
{
w->s = a_VecChr_gets(lin, w->s, w->src->p + w->src->...
if (lin->n > 0) w->lin++;
}
a_class(a_Preprocessor_SourceFiles) {
a_VecChr buf[1], stk[1];
char *s;
};
a_static void a_Preprocessor_SourceFiles_ini(a_Preproces...
{
a_VecChr_ini4(w->buf, w->stk, 0, 0);
a_VecChr_reserve0(w->buf);
w->s = w->buf->p;
}
a_static void a_Preprocessor_SourceFiles_din(a_Preproces...
{
intptr_t i, n = w->stk->n / (sizeof (a_Preprocessor_...
a_Preprocessor_SourceFile **p = (a_Preprocessor_Sour...
for (i = 0; i < n; i++) {
a_Preprocessor_SourceFile_din(p[i]);
a_free(_arg_ p[i], sizeof (a_Preprocessor_Sourc...
}
a_VecChr_din4(w->buf, w->stk, 0, 0);
}
a_static intptr_t a_Preprocessor_SourceFiles_addFile(a_P...
{
a_Preprocessor_SourceFile *p = a_malloc(_arg_ sizeo...
a_Preprocessor_SourceFile_ini(p);
intptr_t i = a_Preprocessor_SourceFile_read(p, path,...
if (i > 0) {
a_Preprocessor_SourceFile **pp = a_VecChr_stkAdd...
*pp = p;
} else {
a_Preprocessor_SourceFile_din(p);
a_free(_arg_ p, sizeof (a_Preprocessor_SourceFi...
}
return i;
}
a_static void a_Preprocessor_SourceFiles_addBuf(a_Prepro...
{
a_VecChr_replace(w->buf, 0, w->s - w->buf->p, s, n);
w->s = w->buf->p;
}
a_static a_Preprocessor_SourceFile *a_Preprocessor_Sourc...
{
if (w->stk->n == 0) return NULL;
return *(a_Preprocessor_SourceFile **) (w->stk->p + ...
}
a_static void a_Preprocessor_SourceFiles_gets(a_Preproce...
{
w->s = a_VecChr_gets(lin, w->s, w->buf->p + w->buf->...
if (lin->n == 0) {
while (w->stk->n > 0) {
a_Preprocessor_SourceFile *sf = a_Preprocess...
a_Preprocessor_SourceFile_gets(sf, lin);
if (lin->n > 0) break;
w->stk->n -= sizeof (a_Preprocessor_SourceFi...
a_Preprocessor_SourceFile_din(sf);
a_free(_arg_ sf, sizeof (a_Preprocessor_Sou...
}
}
}
a_static int a_Preprocessor_isDirective(const char *s, c...
{
while (s < s1 && *(const unsigned char *) s <= ' ') ...
return (s < s1 && *s == '#');
}
** (2) 説明
-Preprocessor_SourceFile と Preprocessor_SourceFiles は、...
-Preprocessor_SourceFile は、1つのファイルだけを管理する...
-Preprocessor_SourceFiles は、内部に Preprocessor_SourceF...
-読み込みの際は常にスタックトップのファイルから1行ずつ取...
-スタックトップのファイルを読みつくしてしまったら、スタッ...
-ただし Preprocessor_SourceFiles はこのスタック以外にもバ...
-もしバッファが空ではないときは、ファイルからではなくバッ...
** (3)
-このページにはサンプルプログラムがありません。
-これらを使って、 [[a4_0013]] でプリプロセッサを作ります。
** (99) 更新履歴
-2026.02.11(水) 初版
終了行:
* acl4のページ0011
-(by [[K]], 2026.02.11)
** (1)
#if (a_Version >= 1)
#define Preprocessor_SourceFile a_Pr...
#define Preprocessor_SourceFile_ini a_Pr...
#define Preprocessor_SourceFile_din a_Pr...
#define Preprocessor_SourceFile_read a_Pr...
#define Preprocessor_SourceFile_gets a_Pr...
#define Preprocessor_SourceFiles a_Pr...
#define Preprocessor_SourceFiles_ini a_Pr...
#define Preprocessor_SourceFiles_din a_Pr...
#define Preprocessor_SourceFiles_addFile a_Pr...
#define Preprocessor_SourceFiles_addBuf a_Pr...
#define Preprocessor_SourceFiles_getSf a_Pr...
#define Preprocessor_SourceFiles_gets a_Pr...
#define Preprocessor_isDirective a_Pr...
#endif
a_class(a_Preprocessor_SourceFile) {
a_VecChr src[1], path[1];
intptr_t lin;
char *s;
};
a_static void a_Preprocessor_SourceFile_ini(a_Preprocess...
{
a_VecChr_ini4(w->src, w->path, 0, 0);
w->lin = 0;
}
a_static void a_Preprocessor_SourceFile_din(a_Preprocess...
{
a_VecChr_din4(w->src, w->path, 0, 0);
}
a_static intptr_t a_Preprocessor_SourceFile_read(a_Prepr...
{
intptr_t i = 0;
a_VecChr_puts(w->path, path, path + n);
if (n >= 7 && strncmp(path, "inline:", 7) == 0) {
a_VecChr_puts(w->src, &path[7], path + n);
a_VecChr_convEsc(w->src);
} else {
i = a_VecChr_readFileAll(w->src, w->path->p);
a_VecChr_eraseCr(w->src);
}
if (i >= 0) { i = w->src->n; w->s = w->src->p; }
return i;
}
a_static void a_Preprocessor_SourceFile_gets(a_Preproces...
{
w->s = a_VecChr_gets(lin, w->s, w->src->p + w->src->...
if (lin->n > 0) w->lin++;
}
a_class(a_Preprocessor_SourceFiles) {
a_VecChr buf[1], stk[1];
char *s;
};
a_static void a_Preprocessor_SourceFiles_ini(a_Preproces...
{
a_VecChr_ini4(w->buf, w->stk, 0, 0);
a_VecChr_reserve0(w->buf);
w->s = w->buf->p;
}
a_static void a_Preprocessor_SourceFiles_din(a_Preproces...
{
intptr_t i, n = w->stk->n / (sizeof (a_Preprocessor_...
a_Preprocessor_SourceFile **p = (a_Preprocessor_Sour...
for (i = 0; i < n; i++) {
a_Preprocessor_SourceFile_din(p[i]);
a_free(_arg_ p[i], sizeof (a_Preprocessor_Sourc...
}
a_VecChr_din4(w->buf, w->stk, 0, 0);
}
a_static intptr_t a_Preprocessor_SourceFiles_addFile(a_P...
{
a_Preprocessor_SourceFile *p = a_malloc(_arg_ sizeo...
a_Preprocessor_SourceFile_ini(p);
intptr_t i = a_Preprocessor_SourceFile_read(p, path,...
if (i > 0) {
a_Preprocessor_SourceFile **pp = a_VecChr_stkAdd...
*pp = p;
} else {
a_Preprocessor_SourceFile_din(p);
a_free(_arg_ p, sizeof (a_Preprocessor_SourceFi...
}
return i;
}
a_static void a_Preprocessor_SourceFiles_addBuf(a_Prepro...
{
a_VecChr_replace(w->buf, 0, w->s - w->buf->p, s, n);
w->s = w->buf->p;
}
a_static a_Preprocessor_SourceFile *a_Preprocessor_Sourc...
{
if (w->stk->n == 0) return NULL;
return *(a_Preprocessor_SourceFile **) (w->stk->p + ...
}
a_static void a_Preprocessor_SourceFiles_gets(a_Preproce...
{
w->s = a_VecChr_gets(lin, w->s, w->buf->p + w->buf->...
if (lin->n == 0) {
while (w->stk->n > 0) {
a_Preprocessor_SourceFile *sf = a_Preprocess...
a_Preprocessor_SourceFile_gets(sf, lin);
if (lin->n > 0) break;
w->stk->n -= sizeof (a_Preprocessor_SourceFi...
a_Preprocessor_SourceFile_din(sf);
a_free(_arg_ sf, sizeof (a_Preprocessor_Sou...
}
}
}
a_static int a_Preprocessor_isDirective(const char *s, c...
{
while (s < s1 && *(const unsigned char *) s <= ' ') ...
return (s < s1 && *s == '#');
}
** (2) 説明
-Preprocessor_SourceFile と Preprocessor_SourceFiles は、...
-Preprocessor_SourceFile は、1つのファイルだけを管理する...
-Preprocessor_SourceFiles は、内部に Preprocessor_SourceF...
-読み込みの際は常にスタックトップのファイルから1行ずつ取...
-スタックトップのファイルを読みつくしてしまったら、スタッ...
-ただし Preprocessor_SourceFiles はこのスタック以外にもバ...
-もしバッファが空ではないときは、ファイルからではなくバッ...
** (3)
-このページにはサンプルプログラムがありません。
-これらを使って、 [[a4_0013]] でプリプロセッサを作ります。
** (99) 更新履歴
-2026.02.11(水) 初版
ページ名: