ESPResSo 3.2.0-167-g2c9ead1-git
Extensible Simulation Package for Soft Matter Research
Defines | Functions
blockfile_tcl.c File Reference

Implements the blockfile command for writing Tcl-formatted data files. More...

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "parser.h"
#include "communication.h"
Include dependency graph for blockfile_tcl.c:

Go to the source code of this file.

Defines

#define MAXBLOCKTITLE   64
 The maximal size allowed for block titles.
#define DOUBLE_SPACE   32
 Used in the write commands as buffer size for sprintf.
#define DOUBLE_FORMAT   "%.10e"
#define INT_SPACE   32
 Used in the write commands as buffer size for sprintf.
Error return codes

All functions return non-negative values on success.

The following codes are issued on errors.

#define RETURN_CODE_EOF   -1
 end of file.
#define RETURN_CODE_ERROR   -2
 I/O error on the file or unexpected EOF.
#define RETURN_CODE_FILE_FORMAT   -3
 file format wrong

Functions

static int readchar (Tcl_Channel f)
static int writestring (Tcl_Channel f, char *s)
static int findNonWs (Tcl_Channel f)
static int readString (Tcl_Channel f, char *buffer, int size)
static int block_startread (Tcl_Channel f, char index[MAXBLOCKTITLE])
 read the title of a block.
static int block_continueread (Tcl_Channel f, int brace_count, char *data, int size, char spacer)
 read a portion of the data of a block.
static int block_writestart (Tcl_Channel f, char index[MAXBLOCKTITLE])
 write a start tag to the file f.
static int block_writeend (Tcl_Channel f)
 write a end tag to the file f.
int tclcommand_blockfile (ClientData data, Tcl_Interp *interp, int argc, char *argv[])

Detailed Description

Implements the blockfile command for writing Tcl-formatted data files.

Definition in file blockfile_tcl.c.


Define Documentation

#define DOUBLE_FORMAT   "%.10e"

Definition at line 57 of file blockfile_tcl.c.

#define DOUBLE_SPACE   32

Used in the write commands as buffer size for sprintf.

Possible incompatability. The current value allows for up to 20 digits precision

Definition at line 55 of file blockfile_tcl.c.

#define INT_SPACE   32

Used in the write commands as buffer size for sprintf.

Possible incompatability. The current value this allows up to 64 bit integers

Definition at line 61 of file blockfile_tcl.c.

#define MAXBLOCKTITLE   64

The maximal size allowed for block titles.

Definition at line 51 of file blockfile_tcl.c.

Referenced by tclcommand_blockfile().

#define RETURN_CODE_EOF   -1

end of file.

This will only be returned by block_startread if the file is read completely to allow convenient parsing through all blocks. All other functions will treat EOF as an error.

Definition at line 42 of file blockfile_tcl.c.

Referenced by block_startread(), findNonWs(), readString(), and tclcommand_blockfile().

#define RETURN_CODE_ERROR   -2

I/O error on the file or unexpected EOF.

Definition at line 44 of file blockfile_tcl.c.

Referenced by block_continueread(), block_startread(), block_writeend(), block_writestart(), findNonWs(), and readString().

#define RETURN_CODE_FILE_FORMAT   -3

file format wrong

Definition at line 46 of file blockfile_tcl.c.

Referenced by block_startread(), and tclcommand_blockfile().


Function Documentation

static int block_continueread ( Tcl_Channel  f,
int  brace_count,
char *  data,
int  size,
char  spacer 
) [static]

read a portion of the data of a block.

Parameters:
fthe file
brace_countthe number of open braces. If open_braces is one, reading terminates at the matching closing bracket, else open_braces-1 additional braces will be consumed.
datawhere to store the contained data
sizethe size of the buffer pointed to by "data".
spacerif this character is read and no brace is open, i. e. open_braces=1, reading also terminates. A spacer of 0 disables this feature. This can be used to read in for example space separated lists:
{demoblock 1 2 3}
Returns:
returns the number of open braces or RETURN_CODE_EOF or RETURN_CODE_ERROR. The number of open_braces will be non-zero if the data space was exhausted.

Definition at line 180 of file blockfile_tcl.c.

References i, readchar(), and RETURN_CODE_ERROR.

Referenced by tclcommand_blockfile().

static int block_startread ( Tcl_Channel  f,
char  index[MAXBLOCKTITLE] 
) [static]

read the title of a block.

Parameters:
fthe file
indexwhere to store the index if round
Returns:
the number of open braces on success (1 if data follows or 0 if no data was contained in the block) or RETURN_CODE_EOF or RETURN_CODE_ERROR or RETURN_CODE_FILE_FORMAT if no "{" is found. In that case index contains the offending character.

Definition at line 134 of file blockfile_tcl.c.

References findNonWs(), readString(), RETURN_CODE_EOF, RETURN_CODE_ERROR, and RETURN_CODE_FILE_FORMAT.

Referenced by tclcommand_blockfile().

static int block_writeend ( Tcl_Channel  f) [static]

write a end tag to the file f.

Parameters:
fthe file
Returns:
0 on success or RETURN_CODE_ERROR

Definition at line 244 of file blockfile_tcl.c.

References RETURN_CODE_ERROR, and writestring().

Referenced by tclcommand_blockfile().

static int block_writestart ( Tcl_Channel  f,
char  index[MAXBLOCKTITLE] 
) [static]

write a start tag to the file f.

Parameters:
fthe file
indexthe tag to write (if index is a string longer than MAXBLOCKTITLE, an error is returned.
Returns:
0 on success or RETURN_CODE_ERROR

Definition at line 229 of file blockfile_tcl.c.

References RETURN_CODE_ERROR, and writestring().

Referenced by tclcommand_blockfile().

static int findNonWs ( Tcl_Channel  f) [static]

Definition at line 78 of file blockfile_tcl.c.

References readchar(), RETURN_CODE_EOF, and RETURN_CODE_ERROR.

Referenced by block_startread(), and readString().

static int readchar ( Tcl_Channel  f) [static]

Definition at line 63 of file blockfile_tcl.c.

Referenced by block_continueread(), findNonWs(), and readString().

static int readString ( Tcl_Channel  f,
char *  buffer,
int  size 
) [static]

Definition at line 97 of file blockfile_tcl.c.

References findNonWs(), i, readchar(), RETURN_CODE_EOF, and RETURN_CODE_ERROR.

Referenced by block_startread().

int tclcommand_blockfile ( ClientData  data,
Tcl_Interp *  interp,
int  argc,
char *  argv[] 
)
static int writestring ( Tcl_Channel  f,
char *  s 
) [static]

Definition at line 72 of file blockfile_tcl.c.

Referenced by block_writeend(), and block_writestart().