input schema
In any programming language, it is possible to specify schemata that how to code common programming tasks. The following is a schema for reading material from a file and processing it

dountilstop :-
  (X = stop, !

In this case, the code reads data, a term at a time, from the current input stream. To make that input stream a file called, say, inputdata, you would invoke the code as follows:

?- see('inputdata'), dountilstop, seen.

The call to fail is there to force backtracking. The call to repeat is there to force the code to endlessly repeat - that is, until something terminates the backtracking. This "something" is the cut after X = stop - if the term read is the atom stop, the goal X = stop succeeds, the cut is executed, and the rule terminates.

To use the schema, replace the read operation with the one you want (might be getc or ratom or …), replace the call to process with a call to a procedure that does whatever you want to do to the data, and you're in business. Actually - you'll probably find a few other adjustments are needed, but at least you're on the right track.

See also read, repeat, see, seen, ; (or), and fail.