#include <stdio.h>
#include <stdlib.h>
typedef void effector(int);
typedef struct transition transition;
struct transition {
int state;
effector *effect;
};
enum sigil { Letter, Slash, Star, EndOfFile, Squote, Dquote, Bslash };
typedef enum sigil sigil;
sigil sigilify(int c) {
switch (c) {
case '/': return Slash;
case '*': return Star;
case EOF: return EndOfFile;
case '\'': return Squote;
case '"': return Dquote;
case '\\': return Bslash;
default: return Letter;
}
}
void nothing (int c) { }
void halt
(int c
) { exit(EXIT_SUCCESS
); }
#define T(state, sigil) (((state) << 4) | sigil)
int main() {
transition state = { 0, emit };
transition table[] = {
[T(0, Slash)] = { 1, nothing },
[T(0, Letter)] = { 0, emit },
[T(0, Star)] = { 0, emit },
[T(0, EndOfFile)] = { 0, halt },
[T(0, Squote)] = { 6, emit },
[T(0, Dquote)] = { 4, emit },
[T(0, Bslash)] = { 0, emit },
[T(1, Slash)] = { 0, slash },
[T(1, Letter)] = { 0, slash },
[T(1, Star)] = { 2, nothing },
[T(1, EndOfFile)] = { 0, halt },
[T(1, Squote)] = { 0, slash },
[T(1, Dquote)] = { 0, slash },
[T(1, Bslash)] = { 0, slash },
[T(2, Slash)] = { 2, nothing },
[T(2, Letter)] = { 2, nothing},
[T(2, Star)] = { 3, nothing },
[T(2, EndOfFile)] = { 0, halt },
[T(2, Squote)] = { 2, nothing },
[T(2, Dquote)] = { 2, nothing },
[T(2, Bslash)] = { 2, nothing },
[T(3, Slash)] = { 0, nothing },
[T(3, Letter)] = { 2, nothing },
[T(3, Star)] = { 2, nothing },
[T(3, EndOfFile)] = { 0, halt },
[T(3, Squote)] = { 2, nothing },
[T(3, Dquote)] = { 2, nothing },
[T(3, Bslash)] = { 2, nothing },
[T(4, Slash)] = { 4, emit },
[T(4, Letter)] = { 4, emit },
[T(4, Star)] = { 4, emit },
[T(4, EndOfFile)] = { 0, halt },
[T(4, Squote)] = { 4, emit },
[T(4, Dquote)] = { 0, emit },
[T(4, Bslash)] = { 5, emit },
[T(5, Slash)] = { 4, emit },
[T(5, Letter)] = { 4, emit },
[T(5, Star)] = { 4, emit },
[T(5, EndOfFile)] = { 0, halt },
[T(5, Squote)] = { 4, emit },
[T(5, Dquote)] = { 4, emit },
[T(5, Bslash)] = { 4, emit},
[T(6, Slash)] = { 8, emit },
[T(6, Letter)] = { 8, emit },
[T(6, Star)] = { 8, emit },
[T(6, EndOfFile)] = { 0, halt },
[T(6, Squote)] = { 8, emit },
[T(6, Dquote)] = { 8, emit },
[T(6, Bslash)] = { 7, emit },
[T(7, Slash)] = { 8, emit },
[T(7, Letter)] = { 8, emit },
[T(7, Star)] = { 8, emit },
[T(7, EndOfFile)] = { 8, emit },
[T(7, Squote)] = { 8, emit },
[T(7, Dquote)] = { 8, emit },
[T(7, Bslash)] = { 8, emit },
[T(8, Slash)] = { 0, emit },
[T(8, Letter)] = { 0, emit },
[T(8, Star)] = { 0, emit },
[T(8, EndOfFile)] = { 0, halt },
[T(8, Squote)] = { 0, emit },
[T(8, Dquote)] = { 0, emit },
[T(8, Bslash)] = { 0, emit },
};
for (;;) {
(state = table[T(state.state, sigilify(c))]).effect(c);
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgdm9pZCBlZmZlY3RvcihpbnQpOwp0eXBlZGVmIHN0cnVjdCB0cmFuc2l0aW9uIHRyYW5zaXRpb247CnN0cnVjdCB0cmFuc2l0aW9uIHsKICBpbnQgc3RhdGU7CiAgZWZmZWN0b3IgKmVmZmVjdDsKfTsKCmVudW0gc2lnaWwgeyBMZXR0ZXIsIFNsYXNoLCBTdGFyLCBFbmRPZkZpbGUsIFNxdW90ZSwgRHF1b3RlLCBCc2xhc2ggfTsKdHlwZWRlZiBlbnVtIHNpZ2lsIHNpZ2lsOwoKc2lnaWwgc2lnaWxpZnkoaW50IGMpIHsKICBzd2l0Y2ggKGMpIHsKICAgIGNhc2UgJy8nOiAgcmV0dXJuIFNsYXNoOwogICAgY2FzZSAnKic6ICByZXR1cm4gU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