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