summaryrefslogtreecommitdiff
path: root/attocc.c
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-10-09 10:13:59 +0200
committermetamuffin <metamuffin@disroot.org>2024-10-09 10:13:59 +0200
commit7e89b781e7f1e8d7cedc20601642bec525200176 (patch)
treed5263e7cfe48b47e313ec6e99f1eaf3a10960778 /attocc.c
parent1109973fc1aae971439331c76eb46cbaf976690b (diff)
downloadattocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar
attocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar.bz2
attocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar.zst
fix strncmp
Diffstat (limited to 'attocc.c')
-rw-r--r--attocc.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/attocc.c b/attocc.c
index 1389f9d..bb6b248 100644
--- a/attocc.c
+++ b/attocc.c
@@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcntl.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,6 +27,8 @@
#define DEBUG
#endif
+#define TRAP kill(getpid(), SIGTRAP);
+
const int NUM_KEYWORDS = 32;
static char *KEYWORDS[] = {
"auto", "break", "case", "char", "const", "continue",
@@ -273,17 +276,19 @@ void *memcpy(void *dest, const void *src, unsigned long size) {
// not to specification but this program only needs to check equality
int strncmp(const char *a, const char *b, unsigned long len) {
- while (len--)
- if (*a++ != *b++)
- return 1;
+ while (len--) {
+ if (*a != *b)
+ return *a - *b;
+ a++;
+ b++;
+ }
return 0;
}
-
unsigned long strlen(const char *s) {
int len = 0;
while (*s++)
len++;
- return len - 1;
+ return len;
}
char *strdup(const char *s) {
int len = strlen(s);
@@ -316,7 +321,6 @@ struct token *tokenize(char *source) {
struct token *tokens = NULL;
while (*p) {
unsigned long remaining = end - p;
- printf("%li\n", p - source);
//* whitespace
if (p[0] == ' ' || p[0] == '\t' || p[0] == '\n') {