fops.c

来自「这是一个C的源代码」· C语言 代码 · 共 47 行

C
47
字号
#include <assert.h>#include <stdio.h>#include "pbc_fops.h"#include "pbc_tracker.h"static int getc_from_buf (void *ctx);static int ungetc_into_buf (int c, void *ctx);static int getc_from_str (void *ctx);static int ungetc_into_str (int c, void *ctx);struct fetch_ops_s fops_buf = { getc_from_buf, ungetc_into_buf };struct fetch_ops_s fops_str = { getc_from_str, ungetc_into_str };static intgetc_from_buf (void *ctx){   assert (ctx);   tracker_t *t = (tracker_t *) ctx;   if (t->p == t->end) { return EOF; }   return *t->p++;}static intungetc_into_buf (int c, void *ctx){   assert (ctx);   tracker_t *t = (tracker_t *) ctx;   if (c == EOF) { return EOF; }   if (t->base == t->p) { return EOF; }   t->p--;   return c;}static intgetc_from_str (void *ctx){   assert (ctx);   return fgetc ((FILE *) ctx);}static intungetc_into_str (int c, void *ctx){   assert (ctx);   return ungetc (c, (FILE *) ctx);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?