linestream.h File Reference

#include "format.h"

Go to the source code of this file.

Data Structures

struct  _lineStreamStruct_
 LineStream. More...

Defines

#define ls_destroy(this1)   (ls_destroy_func(this1),this1=NULL)
 Destroy a line stream.

Typedefs

typedef struct _lineStreamStruct_LineStream
 LineStream.

Functions

void ls_back (LineStream this1, int lineCnt)
 Push back 'lineCnt' lines.
void ls_bufferSet (LineStream this1, int lineCnt)
 Set how many lines the linestream should buffer.
void ls_cat (LineStream this1, char *filename)
 Redirect a linestream.
LineStream ls_createFromBuffer (char *buffer)
 Creates a line stream from a buffer.
LineStream ls_createFromFile (char *fn)
 Creates a line stream from a file.
LineStream ls_createFromPipe (char *command)
 Creates a line stream from a pipe.
void ls_destroy_func (LineStream this1)
 Destroys a line stream object after closing the file or pipe if they are still open (stream not read to the end) or after destroying the word iterator if the stream was over a buffer.
int ls_isEof (LineStream this1)
 Determine the state of a line stream.
int ls_lineCountGet (LineStream this1)
 Returns the number of the current line.
char * ls_nextLine (LineStream this1)
 Get the next line from a line stream object.
int ls_skipStatusGet (LineStream this1)
 Skips remainder of line stream and returns exit status which only meaningful when created from a pipe - exit status for file and buffer will always be 0.


Detailed Description

Author:
Adapted by Lukas Habegger (lukas.habegger@yale.edu)

Definition in file linestream.h.


Define Documentation

#define ls_destroy ( this1   )     (ls_destroy_func(this1),this1=NULL)

Destroy a line stream.

See also:
ls_destroy_func()

Definition at line 70 of file linestream.h.


Function Documentation

void ls_back ( LineStream  this1,
int  lineCnt 
)

Push back 'lineCnt' lines.

Parameters:
[in] this1 A line stream
[in] lineCnt How many lines should ls_nextLine() repeat (currently, only lineCnt==1 is supported)
Precondition:
ls_bufferSet() was called.
Postcondition:
Next call to ls_nextLine() will return the same line again

Definition at line 331 of file linestream.c.

void ls_bufferSet ( LineStream  this1,
int  lineCnt 
)

Set how many lines the linestream should buffer.

Parameters:
[in] this1 A line stream
[in] lineCnt How many lines should ls_nextLine() repeat (currently, only lineCnt==1 is supported)
Precondition:
ls_create*
Postcondition:
ls_back() will work

Definition at line 351 of file linestream.c.

void ls_cat ( LineStream  this1,
char *  filename 
)

Redirect a linestream.

Parameters:
[in] this1 A line stream created by one of ls_create*()
[in] filename Name of file to write lines to; special cases: '-' means stdout, NULL means /dev/null (discard)
Postcondition:
this1 contains no more lines; file 'filename' contains the contents of 'this1'

Definition at line 414 of file linestream.c.

LineStream ls_createFromBuffer ( char *  buffer  ) 

Creates a line stream from a buffer.

Parameters:
[in] buffer A buffer pointer, must not be NULL
Returns:
A line stream object
Note:
The buffer will be destroyed after using ls_nextLine (newline characters are replaced by null-termination characters). Work on a copy of the buffer if you want to use it again.

Definition at line 190 of file linestream.c.

LineStream ls_createFromFile ( char *  fn  ) 

Creates a line stream from a file.

Parameters:
[in] fn File name ("-" means stdin)
Returns:
A line stream object, NULL if file could not been opened; to learn details call warnReport() from module log.c

Definition at line 69 of file linestream.c.

LineStream ls_createFromPipe ( char *  command  ) 

Creates a line stream from a pipe.

Example: ls_createFromPipe ("zcat test.dat.Z");

Parameters:
[in] command As it would be written on the command line
Returns:
A line stream object, NULL if the pipe could not been opened
Postcondition:
warnCount(NULL,NULL) !=0 if problem occured

Definition at line 132 of file linestream.c.

void ls_destroy_func ( LineStream  this1  ) 

Destroys a line stream object after closing the file or pipe if they are still open (stream not read to the end) or after destroying the word iterator if the stream was over a buffer.

Parameters:
[in] this1 A line stream
Note:
Do not call this function, but use the macro ls_destroy

Definition at line 249 of file linestream.c.

int ls_isEof ( LineStream  this1  ) 

Determine the state of a line stream.

Parameters:
[in] this1 A line stream
Returns:
0 if there are more lines retrievable by ls_nextLine(). 1 if line stream is at end i.e. ls_nextLine() has returned NULL and must not be called anymore.

Definition at line 445 of file linestream.c.

int ls_lineCountGet ( LineStream  this1  ) 

Returns the number of the current line.

Parameters:
[in] this1 A line stream

Definition at line 368 of file linestream.c.

char* ls_nextLine ( LineStream  this1  ) 

Get the next line from a line stream object.

This function is called from the application programs independently whether the stream is from a file, pipe or buffer

Parameters:
[in] this1 A line stream
Returns:
A line without trailing newlines if there is still a line, else NULL
Note:
The memory returned belongs to this routine; it may be read and written to, but not free'd or realloc'd by the user of this routine; it stays stable until the next call ls_nextLine(this1).

Definition at line 295 of file linestream.c.

int ls_skipStatusGet ( LineStream  this1  ) 

Skips remainder of line stream and returns exit status which only meaningful when created from a pipe - exit status for file and buffer will always be 0.

Parameters:
[in] this1 A line stream
Returns:
If 'this1' was created by ls_createFromPipe(command),the exit status of 'command' is returned; else 0
Postcondition:
line stream is read to its end - ls_nextLine() must not be called anymore.
Note:
For reasons of efficiency, skip does not actually read the linestream therefore ls_lineCountGet() will not return the correct line number after this function has been called.

Definition at line 384 of file linestream.c.


Generated on Fri Aug 7 15:46:43 2009 for BIOS by  doxygen 1.5.7.1