gawk: Extension Exercises
16.10 Exercises
===============
1. Add functions to implement system calls such as 'chown()',
'chmod()', and 'umask()' to the file operations extension presented
in Internal File Ops.
2. Write an input parser that prints a prompt if the input is a from a
"terminal" device. You can use the 'isatty()' function to tell if
the input file is a terminal. (Hint: this function is usually
expensive to call; try to call it just once.) The content of the
prompt should come from a variable settable by 'awk'-level code.
You can write the prompt to standard error. However, for best
results, open a new file descriptor (or file pointer) on '/dev/tty'
and print the prompt there, in case standard error has been
redirected.
Why is standard error a better choice than standard output for
writing the prompt? Which reading mechanism should you replace,
the one to get a record, or the one to read raw bytes?
3. (Hard.) How would you provide namespaces in 'gawk', so that the
names of functions in different extensions don't conflict with each
other? If you come up with a really good scheme, contact the
'gawk' maintainer to tell him about it.
4. Write a wrapper script that provides an interface similar to 'sed
-i' for the "inplace" extension presented in Extension Sample
Inplace.