/* * Copyright 2010 Adrian Thurston */ /* This file is part of Colm. * * Colm 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; either version 2 of the License, or * (at your option) any later version. * * Colm is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Colm; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "fsmrun2.h" #include "pdarun2.h" #include "input.h" void listPrepend( List *list, ListEl *new_el) { listAddBefore(list, list->head, new_el); } void listAppend( List *list, ListEl *new_el) { listAddAfter(list, list->tail, new_el); } ListEl *listDetach( List *list, ListEl *el ); ListEl *listDetachFirst(List *list ) { return listDetach(list, list->head); } ListEl *listDetachLast(List *list ) { return listDetach(list, list->tail); } long listLength(List *list) { return list->listLen; } void initFsmRun( FsmRun *fsmRun, Program *prg ) { fsmRun->prg = prg; fsmRun->tables = prg->rtd->fsmTables; fsmRun->runBuf = 0; fsmRun->haveDataOf = 0; fsmRun->curStream = 0; /* Run buffers need to stick around because * token strings point into them. */ fsmRun->runBuf = newRunBuf(); fsmRun->runBuf->next = 0; fsmRun->p = fsmRun->pe = fsmRun->runBuf->data; fsmRun->peof = 0; } /* Keep the position up to date after consuming text. */ void updatePosition( InputStream *inputStream, const char *data, long length ) { int i; if ( !inputStream->handlesLine ) { for ( i = 0; i < length; i++ ) { if ( data[i] != '\n' ) inputStream->column += 1; else { inputStream->line += 1; inputStream->column = 1; } } } inputStream->byte += length; } /* Keep the position up to date after sending back text. */ void undoPosition( InputStream *inputStream, const char *data, long length ) { /* FIXME: this needs to fetch the position information from the parsed * token and restore based on that.. */ int i; if ( !inputStream->handlesLine ) { for ( i = 0; i < length; i++ ) { if ( data[i] == '\n' ) inputStream->line -= 1; } } inputStream->byte -= length; }