xtralib  0.1.0
A simple header-based drop-in library
io.h
Go to the documentation of this file.
1 
10 #ifndef __XTRA_IO_H__
11 #define __XTRA_IO_H__
12 
13 #include "common.h"
14 
15 #include <stdio.h>
16 #include <stdarg.h>
17 #include <stdint.h>
18 #include <stdlib.h>
19 #include <wchar.h>
20 #include <unistd.h>
21 #include <sys/shm.h>
22 #include <string.h>
23 #include <ctype.h>
24 
25 
26 #define ANSI_RED "\x1b[31m" // ANSI code used for color printing to stdout
27 #define ANSI_GREEN "\x1b[32m"
28 #define ANSI_YELLOW "\x1b[33m"
29 #define ANSI_BLUE "\x1b[34m"
30 #define ANSI_MAGENTA "\x1b[35m"
31 #define ANSI_CYAN "\x1b[36m"
32 #define ASNI_WHITE "\x1b[37m"
33 
34 #define ANSI_RESET "\x1b[0m" // ANSI reset needed to be called after color change
35 
36 #if defined(__GNUC__) || defined(__clang__)
37  #define CHECK_PRINTF_FMT(a, b) __attribute__ ((format (printf, a, b)))
38 #else
39  #define CHECK_PRINTF_FMT(...)
40 #endif
41 
42 
43 //#define cprintfb(fg, bg, format, ...) fprintf(stdout, fg bg format ANSI_RESET, \
44 // "\x1b[%dm\x1b[%dm%s%s", 30+fg, 40+bg,text,ANSI_RESET)
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 typedef uint8_t u8;
51 
52 
53 /* FILE HANDLING
54 =================*/
55 
56 
57 char fpeek(FILE *stream);
58 wchar_t fpeek_wc(FILE *stream);
59 
60 char fspeek(FILE *stream, long int offset, int position);
61 
62 int frpeek(FILE *stream, char c);
63 
64 int frdpeek(FILE *stream, char d) ;
65 
66 int fcounts(FILE *stream);
67 
68 int fcopy(FILE *dest, FILE *src);
69 
70 int fexists(const char *file);
71 
72 int fmove(const char *oldpath, char *newpath);
73 
74 
75 /* STDIN
76 ========*/
77 
78 void sgets(char* str, int n);
79 
80 bool promptYesOrNo(const char *question);
81 
82 
83 /* STDOUT
84 ==========*/
85 
86 // WIP
87 void printb(void const * const ptr);
88 
89 
90 CHECK_PRINTF_FMT(1, 2) void eprintf(const char *fmt, ...);
91 
92 CHECK_PRINTF_FMT(1, 3) void cprintf(const char * color, const char * fmt, ...);
93 
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif
int fcounts(FILE *stream)
Character count of current line of buffer.
Definition: io.c:105
int frpeek(FILE *stream, char c)
A recursive peek that goes to end of line or EOF to get # of occurences.
Definition: io.c:60
char fspeek(FILE *stream, long int offset, int position)
View a character at position without moving pointer; Peeks a seek.
Definition: io.c:41
int frdpeek(FILE *stream, char d)
A recursive peek that goes till the delimter d.
Definition: io.c:81
int fcopy(FILE *dest, FILE *src)
Copies data from src file tp dest file.
Definition: io.c:123
char fpeek(FILE *stream)
View the next character in stream, doesn't move pointer.
Definition: io.c:19
wchar_t fpeek_wc(FILE *stream)
Same as fpeek but for wchar_t.
Definition: io.c:30
New functions and types related to string and string manipulation.