fixed the location of SIGPIPE change in bin/hawk.c
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c9829f8f1e
commit
616fe96150
20
README.md
20
README.md
@ -650,9 +650,15 @@ for (index in array) {
|
||||
|
||||
Hawk also supports the `break` and `continue` statements, which work the same way as in awk and other programming languages. The `break` statement is used to exit a loop prematurely, while `continue` skips the remaining statements in the current iteration and moves to the next iteration.
|
||||
|
||||
TODO:
|
||||
`return`
|
||||
`exit`
|
||||
`nextfile`
|
||||
`nextofile`
|
||||
|
||||
Here are some examples demonstrating the usage of control structures in Hawk.
|
||||
|
||||
1. Check if a number is even or odd
|
||||
- Check if a number is even or odd
|
||||
```awk
|
||||
{
|
||||
if ($1 % 2 == 0) {
|
||||
@ -663,7 +669,7 @@ Here are some examples demonstrating the usage of control structures in Hawk.
|
||||
}
|
||||
```
|
||||
|
||||
2. Print the first 10 even numbers
|
||||
- Print the first 10 even numbers
|
||||
```awk
|
||||
BEGIN {
|
||||
i = 0
|
||||
@ -678,7 +684,7 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
3. Prompt the user for a positive number
|
||||
- Prompt the user for a positive number
|
||||
```awk
|
||||
BEGIN {
|
||||
do {
|
||||
@ -689,7 +695,7 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
4. Print the multiplication table
|
||||
- Print the multiplication table
|
||||
```awk
|
||||
BEGIN {
|
||||
for (i = 1; i <= 10; i++) {
|
||||
@ -701,7 +707,7 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
5. Print only the even numbers from 1 to 16
|
||||
- Print only the even numbers from 1 to 16
|
||||
```awk
|
||||
BEGIN {
|
||||
for (i = 1; i <= 20; i++) {
|
||||
@ -716,7 +722,7 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
6. Count the frequency of words in a file
|
||||
- Count the frequency of words in a file
|
||||
```awk
|
||||
{
|
||||
n = split($0, words, /[^[:alnum:]_]+/)
|
||||
@ -736,7 +742,7 @@ The syntax and behavior of these structures are largely consistent with awk, mak
|
||||
|
||||
## Function
|
||||
|
||||
Hawk supports user-defined functions, which are a powerful feature for modularizing and reusing code. The syntax and behavior of functions in Hawk are largely similar to those in awk, making it easy for awk users to leverage their existing knowledge of functions when working with Hawk. By using functions, you can break down your code into modular, reusable components, promoting code organization and maintainability.
|
||||
Hawk supports user-defined functions, enabling developers to break down complex logic into modular component for reuse. Hawk also provides a wide range of built-in functions that extend its capabilities for various tasks, such as string manipulation, array handling, and more.
|
||||
|
||||
To define a function in Hawk, you use the function keyword followed by the function name and a set of parentheses to enclose the optional function parameters:
|
||||
|
||||
|
24
bin/hawk.c
24
bin/hawk.c
@ -290,6 +290,20 @@ static void do_nothing (int unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void set_intr_pipe (void)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE)
|
||||
set_signal_handler (SIGPIPE, do_nothing, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void unset_intr_pipe (void)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE)
|
||||
unset_signal_handler (SIGPIPE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void set_intr_run (void)
|
||||
{
|
||||
#if defined(SIGTERM)
|
||||
@ -301,9 +315,6 @@ static void set_intr_run (void)
|
||||
#if defined(SIGINT)
|
||||
set_signal_handler (SIGINT, stop_run, 0);
|
||||
#endif
|
||||
#if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE)
|
||||
set_signal_handler (SIGPIPE, do_nothing, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void unset_intr_run (void)
|
||||
@ -317,9 +328,6 @@ static void unset_intr_run (void)
|
||||
#if defined(SIGINT)
|
||||
unset_signal_handler (SIGINT);
|
||||
#endif
|
||||
#if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) && defined(SIGPIPE)
|
||||
unset_signal_handler (SIGPIPE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static hawk_htb_walk_t print_awk_value (hawk_htb_t* map, hawk_htb_pair_t* pair, void* arg)
|
||||
@ -1170,6 +1178,8 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
|
||||
mmgr = &xma_mmgr;
|
||||
}
|
||||
|
||||
set_intr_pipe();
|
||||
|
||||
hawk = hawk_openstdwithmmgr(mmgr, 0, hawk_get_cmgr_by_id(HAWK_CMGR_UTF8), HAWK_NULL);
|
||||
if (HAWK_UNLIKELY(!hawk))
|
||||
{
|
||||
@ -1307,6 +1317,8 @@ oops:
|
||||
if (rtx) hawk_rtx_close (rtx);
|
||||
if (hawk) hawk_close (hawk);
|
||||
|
||||
unset_intr_pipe ();
|
||||
|
||||
if (xma_mmgr.ctx)
|
||||
{
|
||||
if (app_debug) hawk_xma_dump (xma_mmgr.ctx, xma_dumper_without_hawk, HAWK_NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user