added -v var=val to cmd/awk/awk.c

This commit is contained in:
2009-06-21 06:47:34 +00:00
parent cf606b6819
commit e66a372119
10 changed files with 348 additions and 346 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 204 2009-06-18 12:08:06Z hyunghwan.chung $
* $Id: Awk.hpp 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -462,6 +462,7 @@ public:
ERR_BLKEND = QSE_AWK_EBLKEND,
ERR_DUPBEG = QSE_AWK_EDUPBEG,
ERR_DUPEND = QSE_AWK_EDUPEND,
ERR_KWRED = QSE_AWK_EKWRED,
ERR_FNCRED = QSE_AWK_EFNCRED,
ERR_FUNRED = QSE_AWK_EFUNRED,
ERR_GBLRED = QSE_AWK_EGBLRED,

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 204 2009-06-18 12:08:06Z hyunghwan.chung $
* $Id: awk.h 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -495,6 +495,7 @@ enum qse_awk_errnum_t
QSE_AWK_EBLKEND, /* END requires an action block */
QSE_AWK_EDUPBEG, /* duplicate BEGIN */
QSE_AWK_EDUPEND, /* duplicate END */
QSE_AWK_EKWRED, /* keyword redefined */
QSE_AWK_EFNCRED, /* intrinsic function redefined */
QSE_AWK_EFUNRED, /* function redefined */
QSE_AWK_EGBLRED, /* global variable redefined */
@ -1026,78 +1027,59 @@ void qse_awk_clrfnc (
/*****/
/****f* AWK/qse_awk_parse
* NAME
* qse_awk_parse - parse source code
* SYNOPSIS
/**
* The qse_awk_parse() function parses the source script.
* @return 0 on success, -1 on failure.
*/
int qse_awk_parse (
qse_awk_t* awk,
qse_awk_sio_t* sio
qse_awk_t* awk, /**< an awk object */
qse_awk_sio_t* sio /**< source stream I/O handler */
);
/******/
/****f* AWK/qse_awk_alloc
* NAME
* qse_awk_alloc - allocate dynamic memory
* RETURN
* the pointer to the memory space allocated on success, QSE_NULL on failure
* SYNOPSIS
/**
* The qse_awk_alloc() function allocates dynamic memory.
* @return a pointer to memory space allocated on success, QSE_NULL on failure
*/
void* qse_awk_alloc (
qse_awk_t* awk /* the pointer to a qse_awk_t instance */,
qse_size_t size /* the size of memory to allocate in bytes */
qse_awk_t* awk, /**< an awk object */
qse_size_t size /**< size of memory to allocate in bytes */
);
/******/
/****f* AWK/qse_awk_free
* NAME
* qse_awk_free - free dynamic memory
* SYNOPSIS
/**
* The qse_awk_free() function frees dynamic memory allocated.
*/
void qse_awk_free (
qse_awk_t* awk /* the pointer to a qse_awk_t instance */,
void* ptr /* the pointer to the memory space to free */
qse_awk_t* awk, /**< an awk object */
void* ptr /**< memory space to free */
);
/******/
/****f* AWK/qse_awk_strdup
* NAME
* qse_awk_strdup - duplicate a null-terminated string
* DESCRIPTION
* The qse_awk_strdup() function is used to duplicate a string using
* the memory manager used by the associated qse_awk_t instance.
* The new string should be freed using the qse_awk_free() function.
* RETURN
* The qse_awk_strdup() function returns the pointer to a new string which
* is a duplicate of the string s. It returns QSE_NULL on failure.
* SYNOPSIS
/**
* The qse_awk_strdup() function is used to duplicate a string using
* the memory manager used by the associated qse_awk_t instance.
* The new string should be freed using the qse_awk_free() function.
*
* @return a pointer to a new string duplicated of @a s on success,
* QSE_NULL on failure.
*/
qse_char_t* qse_awk_strdup (
qse_awk_t* awk /* the pointer to a qse_awk_t instance */,
const qse_char_t* str /* the pointer to a string */
qse_awk_t* awk, /**< an awk object */
const qse_char_t* str /**< a string pointer */
);
/******/
/****f* AWK/qse_awk_strxdup
* NAME
* qse_awk_strxdup - duplicate a length-delimited string
* DESCRIPTION
* The qse_awk_strxdup() function is used to duplicate a string whose length
* is as long as len characters using the memory manager used by the
* qse_awk_t instance. The new string should be freed using the qse_awk_free()
* function.
* RETURN
* The qse_awk_strxdup() function returns the pointer to a new string which
* is a duplicate of the string s on success. It returns QSE_NULL on failure.
* SYNOPSIS
/**
* The qse_awk_strxdup() function is used to duplicate a string whose length
* is as long as len characters using the memory manager used by the
* qse_awk_t instance. The new string should be freed using the qse_awk_free()
* function.
*
* @return a pointer to a new string duplicated of @a s on success,
* QSE_NULL on failure.
*/
qse_char_t* qse_awk_strxdup (
qse_awk_t* awk,
const qse_char_t* str,
qse_size_t len
qse_awk_t* awk, /**< an awk object */
const qse_char_t* str, /**< a string pointer */
qse_size_t len /**< the number of character in a string */
);
/******/
qse_long_t qse_awk_strxtolong (
qse_awk_t* awk,
@ -1476,6 +1458,12 @@ qse_awk_val_t* qse_awk_rtx_makestrval2 (
qse_size_t len2
);
qse_awk_val_t* qse_awk_rtx_makenstrval (
qse_awk_rtx_t* rtx,
const qse_char_t* str,
qse_size_t len
);
qse_awk_val_t* qse_awk_rtx_makerexval (
qse_awk_rtx_t* rtx,
const qse_char_t* buf,

View File

@ -1,5 +1,5 @@
/*
* $Id: std.h 196 2009-06-11 07:44:44Z hyunghwan.chung $
* $Id: std.h 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,9 +22,15 @@
#include <qse/awk/awk.h>
/** @file
* Standard AWK Interpreter
* This file defines functions and data types that help you create
* an awk interpreter with less effort. It is designed to be as close
* to conventional awk implementations as possible.
*
* The source script handler does not evaluate a file name of the "var=val"
* form as an assignment expression. Instead, it just treats it as a
* normal file name.
*
* @todo
* - console name handling an empty string("") and assignment (v=yyyy)
* - StdAwk ARGV and console name handling
*/
@ -121,8 +127,8 @@ int qse_awk_parsestd (
/**
* The qse_awk_rtx_openstd() function creates a standard runtime context.
* The caller should keep the contents of icf and ocf valid throughout
* the lifetime of the runtime context created. The runtime context
* The caller should keep the contents of @a icf and @a ocf valid throughout
* the lifetime of the runtime context created.
*/
qse_awk_rtx_t* qse_awk_rtx_openstd (
qse_awk_t* awk,
@ -132,15 +138,12 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
const qse_char_t*const* ocf
);
/****f* AWK/qse_awk_rtx_getxtnstd
* NAME
* qse_awk_rtx_getxtnstd - get the pointer to extension space
* SYNOPSIS
/**
* The qse_awk_rtx_getxtnstd() gets the pointer to extension space.
*/
void* qse_awk_rtx_getxtnstd (
qse_awk_rtx_t* rtx
);
/******/
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h 101 2009-03-15 14:36:05Z hyunghwan.chung $
* $Id: map.h 205 2009-06-20 12:47:34Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,13 +22,9 @@
#include <qse/types.h>
#include <qse/macros.h>
/****o* Common/Hash Map
* DESCRIPTION
* A hash map maintains buckets for key/value pairs with the same key hash
* chained under the same bucket.
*
* #include <qse/cmn/map.h>
******
/**@file
* A hash map maintains buckets for key/value pairs with the same key hash
* chained under the same bucket.
*/
/* values that can be returned by qse_map_walker_t */
@ -49,29 +45,23 @@ typedef struct qse_map_pair_t qse_map_pair_t;
typedef enum qse_map_walk_t qse_map_walk_t;
typedef enum qse_map_id_t qse_map_id_t;
/****t* Common/qse_map_copier_t
* NAME
* qse_map_copier_t - define a pair contruction callback
* SYNOPSIS
/**
* The qse_map_copier_t type defines a pair contruction callback
*/
typedef void* (*qse_map_copier_t) (
qse_map_t* map /* a map */,
void* dptr /* the pointer to a key or a value */,
qse_size_t dlen /* the length of a key or a value */
);
/******/
/****t* Common/qse_map_freeer_t
* NAME
* qse_map_freeer_t - define a key/value destruction callback
* SYNOPSIS
/**
* The qse_map_freeer_t defines a key/value destruction callback
*/
typedef void (*qse_map_freeer_t) (
qse_map_t* map /* a map */,
void* dptr /* the pointer to a key or a value */,
qse_size_t dlen /* the length of a key or a value */
);
/******/
/* key hasher */
typedef qse_size_t (*qse_map_hasher_t) (
@ -80,108 +70,70 @@ typedef qse_size_t (*qse_map_hasher_t) (
qse_size_t klen /* the length of a key in bytes */
);
/****t* Common/qse_map_comper_t
* NAME
* qse_map_comper_t - define a key comparator
/**
* The qse_map_comper_t type defines a key comparator that is called when
* the map needs to compare keys. A map is created with a default comparator
* which performs bitwise comparison between two keys.
*
* DESCRIPTION
* The qse_map_comper_t type defines a key comparator that is called when
* the map needs to compare keys. A map is created with a default comparator
* which performs bitwise comparison between two keys.
*
* The comparator should return 0 if the keys are the same and a non-zero
* integer otherwise.
*
* SYNOPSIS
* The comparator should return 0 if the keys are the same and a non-zero
* integer otherwise.
*/
typedef int (*qse_map_comper_t) (
qse_map_t* map /* a map */,
const void* kptr1 /* the pointer to a key */,
qse_size_t klen1 /* the length of a key */,
const void* kptr2 /* the pointer to a key */,
qse_size_t klen2 /* the length of a key */
qse_map_t* map, /**< a map */
const void* kptr1, /**< the pointer to a key */
qse_size_t klen1, /**< the length of a key */
const void* kptr2, /**< the pointer to a key */
qse_size_t klen2 /**< the length of a key */
);
/******/
/****t* Common/qse_map_keeper_t
* NAME
* qse_map_keeper_t - define a value keeper
*
* DESCRIPTION
* The qse_map_keeper_t type defines a value keeper that is called when
* a value is retained in the context that it should be destroyed because
* it is identical to a new value. Two values are identical if their beginning
* pointers and their lengths are equal.
*
* SYNOPSIS
/**
* The qse_map_keeper_t type defines a value keeper that is called when
* a value is retained in the context that it should be destroyed because
* it is identical to a new value. Two values are identical if their beginning
* pointers and their lengths are equal.
*/
typedef void (*qse_map_keeper_t) (
qse_map_t* map /* a map */,
void* vptr /* the pointer to a value */,
qse_size_t vlen /* the length of a value */
qse_map_t* map, /**< a map */
void* vptr, /**< value pointer */
qse_size_t vlen /**< value length */
);
/******/
/****t* Common/qse_map_sizer_t
* NAME
* qse_map_sizer_t - define a bucket size calculator
*
* DESCRIPTION
* The qse_map_sizer_T type defines a bucket size claculator that is called
* when a map should resize the bucket. The current bucket size +1 is passed
* as the hint.
*
* SYNOPSIS
/**
* The qse_map_sizer_T type defines a bucket size claculator that is called
* when a map should resize the bucket. The current bucket size +1 is passed
* as the hint.
*/
typedef qse_size_t (*qse_map_sizer_t) (
qse_map_t* map, /* a map */
qse_size_t hint /* a sizing hint */
qse_map_t* map, /**< a map */
qse_size_t hint /**< a sizing hint */
);
/******/
/****t* Common/qse_map_walker_t
* NAME
* qse_map_walker_t - define a pair visitor
*
* SYNOPSIS
/**
* The qse_map_walker_t defines a pair visitor.
*/
typedef qse_map_walk_t (*qse_map_walker_t) (
qse_map_t* map /* a map */,
qse_map_pair_t* pair /* the pointer to a key/value pair */,
void* arg /* the pointer to user-defined data */
qse_map_t* map, /**< a map */
qse_map_pair_t* pair, /**< the pointer to a key/value pair */
void* arg /**< the pointer to user-defined data */
);
/******/
/****s* Common/qse_map_pair_t
* NAME
* qse_map_pair_t - define a pair
*
* DESCRIPTION
* A pair is composed of a key and a value. It maintains pointers to the
* beginning of a key and a value plus their length. The length is scaled
* down with the scale factor specified in an owning map. Use macros defined
* in the SEE ALSO section below to access individual fields.
*
* SEE ALSO
* QSE_MAP_KPTR, QSE_MAP_KLEN, QSE_MAP_VPTR, QSE_MAP_VLEN
*
* SYNOPSIS
/**
* The qse_map_pair_t type defines a map pair. A pair is composed of a key
* and a value. It maintains pointers to the beginning of a key and a value
* plus their length. The length is scaled down with the scale factor
* specified in an owning map. Use macros defined in the
*/
struct qse_map_pair_t
{
void* kptr; /* the pointer to a key */
qse_size_t klen; /* the length of a key */
void* vptr; /* the pointer to a value */
qse_size_t vlen; /* the length of a value */
qse_map_pair_t* next; /* the next pair under the same slot */
void* kptr; /**< the pointer to a key */
qse_size_t klen; /**< the length of a key */
void* vptr; /**< the pointer to a value */
qse_size_t vlen; /**< the length of a value */
qse_map_pair_t* next; /**< the next pair under the same slot */
};
/*****/
/****s* Common/qse_map_t
* NAME
* qse_map_t - define a hash map
*
* SYNOPSIS
/**
* The qse_map_t type defines a hash map.
*/
struct qse_map_t
{
@ -201,7 +153,6 @@ struct qse_map_t
qse_size_t threshold;
qse_map_pair_t** bucket;
};
/******/
#define QSE_MAP_COPIER_SIMPLE ((qse_map_copier_t)1)
#define QSE_MAP_COPIER_INLINE ((qse_map_copier_t)2)