lsflib/src/tokenizer.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 28 May 2009 16:51:26 +0200
changeset 95 d2a071bd1a60
parent 77 49e0babccb23
child 121 fef2ccfa7b12
permissions -rw-r--r--
java disassembler jdisa disassembles a given java class file and shows the bytecode instructions. it does not currently output the same as javap -c <file>... committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * lsflib/src/tokenizer.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>

#include <lsf.h>

Node *tokenizer (FILE * f, const char *delim)
{

    /*
     * the main routine of the tokenizer
     *
     */
    Node *aktuell, *begin;

    char line[LINE_LENGTH];
    char *token;

    int tokens;

    *line = tokens = 0;

    aktuell = begin = addnode (NULL, "NULL");

    while ((fgets (line, LINE_LENGTH, f)) != NULL) {
        token = strtok (line, delim);
        while (token) {
            aktuell = addnode (aktuell, token);
            token = strtok (NULL, delim);
        }
        *line = 0;
    }

    rewind (f);

    aktuell = begin->next;
    free (begin->data);
    free (begin);

    return aktuell;
}