The qDecoder Project

qAwk.c File Reference

File & String Tokenizing API. More…


Functions

FILE * qAwkOpen (char *filepath)
 Open file for tokenizing.
int qAwkNext (FILE *fp, char array[][1024], char delim)
 Read one line from opened file pointer to tokenize.
bool qAwkClose (FILE *fp)
 Close opened FILE pointer.
int qAwkStr (char array[][1024], char *str, char delim)
 String Tokenizer.


Detailed Description

File & String Tokenizing API.

Plays a similar function to the AWK command of UNIX systems.

   char array[7][1024];
   qAwkOpen("/etc/passwd", ':');
   for( ; qAwkNext(array) > 0; ) printf("ID=%s, NAME=%sn", array[0], array[4]);
   qAwkClose();
   [Sample /etc/passwd]
   qdecoder:x:1001:1000:The qDecoder Project:/home/qdecoder:/bin/csh
   wolkykim:x:1002:1000:Seung-young Kim:/home/wolkykim:/bin/csh
   ziom:x:1003:1000:Ziom Corporation:/home/kikuchi:/bin/csh
   [Output]
   ID=qdecoder, NAME=The qDecoder Project
   ID=wolkykim, NAME=Seung-young Kim
   ID=ziom, NAME=Ziom Corporation

Note:
Maximum token length(not a line or file length) is fixed to 1023(1024-1).
   token1|token2...(length over 1023)...|tokenN
token1 and tokenN is ok. But token2 will be stored only first 1023 bytes.

Function Documentation

FILE* qAwkOpen ( char *  filepath  ) 

Open file for tokenizing.

Parameters:
filepath file path to open
Returns:
file pointer. in case of failure, returns NULL.

int qAwkNext ( FILE *  fp,
char  array[][1024],
char  delim 
)

Read one line from opened file pointer to tokenize.

Parameters:
fp file pointer which is retruned by qAwkOpen()
array splitted tokens will be stored here
delim delimeter
Returns:
the number of parsed(stored in array) tokens. otherwise(end of file or something), returns -1.

bool qAwkClose ( FILE *  fp  ) 

Close opened FILE pointer.

Parameters:
fp file pointer which is retruned by qAwkOpen()
Returns:
in case of success, returns true. otherwise false.

int qAwkStr ( char  array[][1024],
char *  str,
char  delim 
)

String Tokenizer.

Parameters:
array splitted tokens will be stored here
str string to tokenize
delim delimeter
Returns:
returns the number of parsed(stored in array) tokens.


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]