The qDecoder Project

qUtil.c File Reference

Miscellaneous utilities API. More...


Defines

#define SED_INCLUDE_START   "<!--#include file=\""
#define SED_INCLUDE_END   "\"-->"

Functions

int qCountRead (const char *filepath)
 Read counter(integer) from file with advisory file locking.
bool qCountSave (const char *filepath, int number)
 Save counter(integer) to file with advisory file locking.
int qCountUpdate (const char *filepath, int number)
 Increases(or decrease) the counter value as much as specified number with advisory file locking.
bool qSedStr (Q_ENTRY *entry, const char *srcstr, FILE *fpout)
 Perform text transformations on input string.
bool qSedFile (Q_ENTRY *entry, const char *filepath, FILE *fpout)
 Perform text transformations on input file.


Detailed Description

Miscellaneous utilities API.


Function Documentation

int qCountRead ( const char *  filepath  ) 

Read counter(integer) from file with advisory file locking.

Parameters:
filepath file path
Returns:
counter value readed from file. in case of failure, returns 0.
   qCountSave("number.dat", 75);
   int count = qCountRead("number.dat");

   ---- number.dat ----
   75
   --------------------

bool qCountSave ( const char *  filepath,
int  number 
)

Save counter(integer) to file with advisory file locking.

Parameters:
filepath file path
number counter integer value
Returns:
true if successful, otherwise returns false.
Note:
   qCountSave("number.dat", 75);

int qCountUpdate ( const char *  filepath,
int  number 
)

Increases(or decrease) the counter value as much as specified number with advisory file locking.

Parameters:
filepath file path
number how much increase or decrease
Returns:
updated counter value. in case of failure, returns 0.
Note:
   int count;
   count = qCountUpdate("number.dat", -3);

bool qSedStr ( Q_ENTRY entry,
const char *  srcstr,
FILE *  fpout 
)

Perform text transformations on input string.

Parameters:
entry arguments to be transformed
srcstr source string
fpout output stream
Returns:
true if successful, otherwise returns false.
   Q_ENTRY *args = qEntry();
   args = args->putStr(args, "${NAME}", "The qDecoder Project");
   args = args->putStr(args, "${HOBBY}", "Open Source Project");
   qSedStr(args, "Your name is ${NAME} and hobby is ${HOBBY}.", stdout);
   args->free(args);

bool qSedFile ( Q_ENTRY entry,
const char *  filepath,
FILE *  fpout 
)

Perform text transformations on input file.

Parameters:
entry arguments to be transformed
filepath socket descriptor
fpout output stream
Returns:
true if successful, otherwise returns false.
   <!--#include file="streamedit-header.html.in"-->
   <p>Hi <b>${NAME}</b>.
   <p>You got a really cool hobby.
   <br>I'm sure that your hobby, <b>${HOBBY}</b>, can give you more fun in your life time.
   <p>Bye :)
   <!--#include file="streamedit-tailer.html.in"-->

   Q_ENTRY *args = qEntry();
   args = args->putStr(args, "${NAME}", "The qDecoder Project");
   args = args->putStr(args, "${HOBBY}", "Open Source Project");
   qSedFile(args, "streamedit.html.in", stdout);
   args->free(args);


Copyright (c) 2008 The qDecoder Project