the function is really long so i will give you the highlights:
this is the main loop:
here i call the second function with the duplicate fp:
the get_token value function reads the text the same way the main loop does (using the read function) and at the end just before return it moves the fp one step back (using lseek).
After that the file pointer in the main loop won't move even as a result of read.