summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2018-09-29 14:57:23 +0200
committerpgen <p.gen.progs@gmail.com>2018-10-01 19:36:56 +0200
commit54a29e1c65c17851cff2dfcae6a7540c4d64f125 (patch)
tree2eda10cf03d52837b8b9a0e37425877263606c46
parent79ddfc36120edfedf8c7c2ea6ce4eff05fac4fb6 (diff)
Create fgetc.[ch]
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in5
-rw-r--r--fgetc.c37
-rw-r--r--fgetc.h10
-rw-r--r--smenu.c36
5 files changed, 52 insertions, 38 deletions
diff --git a/Makefile.am b/Makefile.am
index a4de103..3a1536a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
bin_PROGRAMS = smenu
smenu_SOURCES = smenu.c smenu.h ptrlist.c ptrlist.h xmalloc.c xmalloc.h \
- index.c index.h utf8.c utf8.h
+ index.c index.h utf8.c utf8.h fgetc.c fgetc.h
dist_man_MANS = smenu.1
EXTRA_DIST = smenu.spec.in smenu.spec ChangeLog build.sh version \
COPYRIGHT LICENSE.rst README.rst examples build-aux tests
diff --git a/Makefile.in b/Makefile.in
index c95646b..a3bc94c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -103,7 +103,7 @@ CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_smenu_OBJECTS = smenu.$(OBJEXT) ptrlist.$(OBJEXT) xmalloc.$(OBJEXT) \
- index.$(OBJEXT) utf8.$(OBJEXT)
+ index.$(OBJEXT) utf8.$(OBJEXT) fgetc.$(OBJEXT)
smenu_OBJECTS = $(am_smenu_OBJECTS)
smenu_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@)
@@ -307,7 +307,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
smenu_SOURCES = smenu.c smenu.h ptrlist.c ptrlist.h xmalloc.c xmalloc.h \
- index.c index.h utf8.c utf8.h
+ index.c index.h utf8.c utf8.h fgetc.c fgetc.h
dist_man_MANS = smenu.1
EXTRA_DIST = smenu.spec.in smenu.spec ChangeLog build.sh version \
@@ -422,6 +422,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fgetc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/index.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptrlist.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smenu.Po@am__quote@
diff --git a/fgetc.c b/fgetc.c
new file mode 100644
index 0000000..4aaffeb
--- /dev/null
+++ b/fgetc.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include "fgetc.h"
+
+/* ************************************************************************ */
+/* Custom fgetc/ungetc implementation able to unget more than one character */
+/* ************************************************************************ */
+
+enum
+{
+ GETC_BUFF_SIZE = 16
+};
+
+static char getc_buffer[GETC_BUFF_SIZE] = { '\0' };
+
+static long next_buffer_pos = 0; /* next free position in the getc buffer */
+
+/* ====================================== */
+/* Get a (possibly pushed-back) character */
+/* ====================================== */
+int
+my_fgetc(FILE * input)
+{
+ return (next_buffer_pos > 0) ? getc_buffer[--next_buffer_pos] : fgetc(input);
+}
+
+/* ============================ */
+/* Push character back on input */
+/* ============================ */
+void
+my_ungetc(int c)
+{
+ if (next_buffer_pos >= GETC_BUFF_SIZE)
+ fprintf(stderr, "Error: cannot push back more than %d characters\n",
+ GETC_BUFF_SIZE);
+ else
+ getc_buffer[next_buffer_pos++] = c;
+}
diff --git a/fgetc.h b/fgetc.h
new file mode 100644
index 0000000..72e9cfa
--- /dev/null
+++ b/fgetc.h
@@ -0,0 +1,10 @@
+#ifndef FGETC_H
+#define FGETC_H
+
+int
+my_fgetc(FILE * input);
+
+void
+my_ungetc(int c);
+
+#endif
diff --git a/smenu.c b/smenu.c
index 9e247d3..526af2d 100644
--- a/smenu.c
+++ b/smenu.c
@@ -42,6 +42,7 @@
#include "ptrlist.h"
#include "index.h"
#include "utf8.h"
+#include "fgetc.h"
#include "smenu.h"
/* **************** */
@@ -122,41 +123,6 @@ char * timeout_seconds; /* string containing the number of remaining *
* seconds. */
int quiet_timeout = 0; /* 1 when we want no message to be displayed. */
-/* ************************************************************************ */
-/* Custom fgetc/ungetc implementation able to unget more than one character */
-/* ************************************************************************ */
-
-enum
-{
- GETC_BUFF_SIZE = 16
-};
-
-static char getc_buffer[GETC_BUFF_SIZE] = { '\0' };
-
-static long next_buffer_pos = 0; /* next free position in the getc buffer */
-
-/* ====================================== */
-/* Get a (possibly pushed-back) character */
-/* ====================================== */
-int
-my_fgetc(FILE * input)
-{
- return (next_buffer_pos > 0) ? getc_buffer[--next_buffer_pos] : fgetc(input);
-}
-
-/* ============================ */
-/* Push character back on input */
-/* ============================ */
-void
-my_ungetc(int c)
-{
- if (next_buffer_pos >= GETC_BUFF_SIZE)
- fprintf(stderr, "Error: cannot push back more than %d characters\n",
- GETC_BUFF_SIZE);
- else
- getc_buffer[next_buffer_pos++] = c;
-}
-
/* ************** */
/* Help functions */
/* ************** */