Sigrid Solveig Haflínudóttirwip Plan 9 port8024a895 years agoHistory
86 lines · 1.6 KB · C
RawDownload
#include "util.h" #include <stdlib.h>#include <stdio.h>#include <string.h> /*Copyright (c) 2013-2021 Devine Lu Linvega2018 web port by rezmason2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for anypurpose with or without fee is hereby granted, provided that the abovecopyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE.*/ FuncWrapper *wrapFunction(void (*f)(void)){	FuncWrapper *func = malloc(sizeof(FuncWrapper));	func->f = f;	return func;} char *concat(const char *s1, const char *s2){	char *result = malloc(strlen(s1) + strlen(s2) + 1);	strcpy(result, s1);	strcat(result, s2);	return result;} char *duplicate(const char *s){	char *result = malloc(strlen(s) + 1);	strcpy(result, s);	return result;} intisMatch(char *c, const char *candidates){	int i;	for(i = 0; candidates[i] != 0; i++)		if(*c == candidates[i])			return 1;	return 0;} /* a homemade strtok_r, just like mom used to make */char *getNextToken(char *s, const char *delim, char **save){	char *start, *end;	if(s == NULL) {		s = *save;	}	if(s == NULL) {		return NULL;	} 	start = s;	while(*start != 0 && isMatch(start, delim)) {		start++; /* skip past the first delimiters */	}	if(*start == 0) {		/* there is no token in the buffer */		*save = NULL;		return NULL;	} 	end = start;	while(*end != 0 && !isMatch(end, delim)) {		end++; /* skip past the non-delimiters */	}	s = (*end != 0) ? end + 1 : NULL; /* save what comes after the end */	*end = 0;	*save = s; 	return start;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t