-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoclib.c
44 lines (38 loc) · 1.16 KB
/
oclib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// $Id: oclib.c,v 1.75 2018-05-18 16:24:12-07 - - $
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define __OCLIB_C__
#include "oclib.h"
void* xcalloc (int nelem, int size) {
void* result = calloc (nelem, size);
assert (result != NULL);
return result;
}
char* scan (int (*skipover) (int), int (*stopat) (int)) {
int byte;
do {
byte = getchar();
if (byte == EOF) return NULL;
} while (skipover (byte));
static char buffer[0x10000];
char* end = buffer;
do {
*end++ = byte;
assert (end < &buffer[sizeof buffer]);
*end = '\0';
byte = getchar();
}while (byte != EOF && ! stopat (byte));
char* result = strdup (buffer);
assert (result != NULL);
return result;
}
static int isfalse (int byte) { (void) byte; return 0; }
static int isnl (int byte) { return byte == '\n'; }
void putint (int val) { printf ("%d", val); }
void putstr (const char* s) { printf ("%s", s); }
char* getword (void) { return scan (isspace, isspace); }
char* getln (void) { return scan (isfalse, isnl); }
void endl() { putchar ('\n'); }