ref: 085e3595450d6652b62350621b470b26ae67b6de
dir: /flags.c/
#include <u.h> #include <libc.h> #include <bio.h> #include "dat.h" #include "fns.h" void setcharconversion(Term *); void setdebug(Term *); void setunknown(Term *); void setdoublequotes(Term *); static Rune *boundedvals[] = { [BoundedTrue] = L"true", [BoundedFalse] = L"false" }; static Rune *integerroundvals[] = { [IntegerRoundDown] = L"down", [IntegerRoundTowardZero] = L"toward_zero" }; static Rune *charconversionvals[] = { [CharConversionOn] = L"on", [CharConversionOff] = L"off" }; static Rune *debugvals[] = { [DebugOff] = L"off", [DebugOn] = L"on" }; static Rune *unknownvals[] = { [UnknownError] = L"error", [UnknownFail] = L"fail", [UnknownWarning] = L"warning" }; static Rune *doublequotesvals[] = { [DoubleQuotesChars] = L"chars", [DoubleQuotesCodes] = L"codes", [DoubleQuotesAtom] = L"atom" }; void initflags(void) { uvlong zero = 0; flagbounded = BoundedTrue; flagmaxinteger = (~zero)>>1; flagmininteger = flagmaxinteger+1; flagintegerroundingfunction = IntegerRoundDown; flagcharconversion = CharConversionOff; flagdebug = DebugOff; flagunknown = UnknownError; flagdoublequotes = DoubleQuotesChars; } void setflag(Rune *flag, Term *value) { if(runestrcmp(flag, L"char_conversion") == 0) setcharconversion(value); else if(runestrcmp(flag, L"debug") == 0) setdebug(value); else if(runestrcmp(flag, L"unknown") == 0) setunknown(value); else if(runestrcmp(flag, L"double_quotes") == 0) setdoublequotes(value); } Term * getallflags(void) { Term *boundedval = mkatom(boundedvals[flagbounded]); Term *maxintval = mkinteger(flagmaxinteger); Term *minintval = mkinteger(flagmininteger); Term *roundingval = mkatom(integerroundvals[flagintegerroundingfunction]); Term *charconvval = mkatom(charconversionvals[flagcharconversion]); Term *debugval = mkatom(debugvals[flagdebug]); Term *unknownval = mkatom(unknownvals[flagunknown]); Term *doublequotesval = mkatom(doublequotesvals[flagdoublequotes]); Term *boundedkey = mkatom(L"bounded"); boundedkey->next = boundedval; Term *maxintkey = mkatom(L"max_integer"); maxintkey->next = maxintval; Term *minintkey = mkatom(L"min_integer"); minintkey->next = minintval; Term *roundingkey = mkatom(L"integer_rounding_function"); roundingkey->next = roundingval; Term *charconvkey = mkatom(L"character_conversion"); charconvkey->next = charconvval; Term *debugkey = mkatom(L"debug"); debugkey->next = debugval; Term *unknownkey = mkatom(L"unknown"); unknownkey->next = unknownval; Term *doublequoteskey = mkatom(L"double_quotes"); doublequoteskey->next = doublequotesval; Term *boundedflag = mkcompound(L"flag", 2, boundedkey); Term *maxintflag = mkcompound(L"flag", 2, maxintkey); Term *minintflag = mkcompound(L"flag", 2, minintkey); Term *roundingflag = mkcompound(L"flag", 2, roundingkey); Term *charconvflag = mkcompound(L"flag", 2, charconvkey); Term *debugflag = mkcompound(L"flag", 2, debugkey); Term *unknownflag = mkcompound(L"flag", 2, unknownkey); Term *doublequotesflag = mkcompound(L"flag", 2, doublequoteskey); boundedflag->next = maxintflag; maxintflag->next = minintflag; minintflag->next = roundingflag; roundingflag->next = charconvflag; charconvflag->next = debugflag; debugflag->next = unknownflag; unknownflag->next = doublequotesflag; return boundedflag; } void setcharconversion(Term *value) { int max = 2; int i; for(i = 0; i < max; i++){ if(runestrcmp(value->text, charconversionvals[i]) == 0) flagcharconversion = i; } } void setdebug(Term *value) { int max = 2; int i; for(i = 0; i < max; i++){ if(runestrcmp(value->text, debugvals[i]) == 0) flagdebug = i; } } void setunknown(Term *value) { int max = 3; int i; for(i = 0; i < max; i++){ if(runestrcmp(value->text, unknownvals[i]) == 0) flagunknown = i; } } void setdoublequotes(Term *value) { int max = 3; int i; for(i = 0; i < max; i++){ if(runestrcmp(value->text, doublequotesvals[i]) == 0) flagdoublequotes = i; } }