/* * --- SDE-COPYRIGHT-NOTE-BEGIN --- * This copyright note is auto-generated by ./scripts/Create-CopyPatch. * * Filename: package/.../sam/sam/tokenize.c * Copyright (C) 2006 The T2 SDE Project * * More information can be found in the files COPYING and README. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. A copy of the * GNU General Public License can be found in the file COPYING. * --- SDE-COPYRIGHT-NOTE-END --- */ #include #include #include static size_t decode(char *buf, size_t len) { /* TODO: escape sequence decoding */ return len; } static int sam_tokenize (lua_State *L) { size_t slen; const char *s; /* = luaL_checklstring(L, 1, &slen); */ char *buf; /* escape sequence decoding buffer */ #define NONE ((size_t) -1) size_t pos = NONE; /* token start index */ size_t p; /* current buffer position */ char last = ' '; /* last parsed char */ #define TRUE (~0) #define FALSE 0 struct { int esc; /* last character was \ */ int quote; /* we are in a quotation */ } flag = { FALSE, FALSE }; size_t t = 1; /* raw table index */ /* check function arguments */ if (lua_isnil(L,1)) return 0; s = luaL_checklstring(L, 1, &slen); /* buffer for decoding escape sequences */ buf = malloc(slen); /* create table containg the tokens (retval) */ lua_newtable(L); /* loop over string */ for(p=0; p