88 lines · 2.0 KB · C
RawDownload
#include "parse.h" #include <string.h>#include <stdio.h>#include <stdlib.h>#include "util.h"#include "datatypes.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.*/ #define testEnum(prefix, e) strcmp(name, #e) == 0 ? ((found = 1) && (*dest = prefix##e)) : 0; voidparseZone(Zone *dest, char *name){	int found = 0;	testEnum(ZONE_, NONE);	testEnum(ZONE_, ANTECHANNEL);	testEnum(ZONE_, CAPSULE);	testEnum(ZONE_, CIRCULAR);	testEnum(ZONE_, ENTENTE);	testEnum(ZONE_, FOREST);	testEnum(ZONE_, METAMONDST);	testEnum(ZONE_, NATANIEV);	testEnum(ZONE_, RAINRE);	testEnum(ZONE_, STONES);	testEnum(ZONE_, STUDIO);	testEnum(ZONE_, NETHER);	testEnum(ZONE_, TERMINAL);	if(!found) {		printf("Parse error: unknown zone %s\n", name);	}} voidparseMazeAxis(MazeAxis *dest, char *name){	int found = 0;	testEnum(MAZEAXIS_, X);	testEnum(MAZEAXIS_, Y);	if(!found) {		printf("Node data error: unknown mazeAxis %s\n", name);	}} voidparseOrientation(Orientation *dest, char *name){	int found = 0;	testEnum(ORIENTATION_, NORTH);	testEnum(ORIENTATION_, EAST);	testEnum(ORIENTATION_, SOUTH);	testEnum(ORIENTATION_, WEST);	strcmp(name, "STRAIGHT") == 0 ? ((found = 1) && (*dest = ORIENTATION_NONE)) : 0;	if(!found) {		printf("Node data error: unknown orientation %s\n", name);	}} static const char *lineDelim = "\n"; intgetNumLines(const char *s){	int count = 0;	char *lineSave = NULL;	char *line;	char *buf = malloc(strlen(s) + 1);	strcpy(buf, s);	line = getNextToken(buf, lineDelim, &lineSave);	while(line != NULL) {		count++;		line = getNextToken(NULL, lineDelim, &lineSave);	}	free(buf);	return count;}

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