Show HN: Cppawk


What is cppawk?

cppawk is a miniature shell script that is historical bask in awk. It invokes
the C preprocessor (GNU cpp) on the Awk code and calls see.

cppawk understands the basic Awk alternatives bask in -F and -v, and additionally
realize total cpp alternatives bask in -I and -Dmacro=price.

There could be a man web page with the total critical parts.

To illustrate, if we elaborate a file known as awkloop.h which has these contents

#elaborate awkloop(file)  for (; getline 
#elaborate nextrec        continue
#elaborate rule(cond)     if (cond)

Then this invent of code is conceivable:

#embody "awkloop.h"

contrivance vital()
  awkloop ("/proc/mounts") {
    rule ($3 != "ext4") { nextrec }
    rule ($2 == "/") { print $1 }


Now we beget implemented a facsimile of an Awk input scanning loop interior a contrivance
with moderately syntactic sugar.


  • Why no longer?

  • You perceive Awk. You perceive C preprocessing interior out. Now use two issues
    that you know, collectively, in glaring techniques.

  • Awks varied than GNU Awk beget downhearted reinforce for making a program out of
    quite a lot of recordsdata. No assemble meta-programming, or conditional alternative
    of code.

  • Totally different minor advantages: Awk has no feedback varied than from a #
    character to the tip of the line. You procure /... */ feedback
    with cppawk, and additionally #if 0#endif for immediate
    disabling code.

But GNU Awk has @embody?

  • GNU Awk’s @embody is no longer essentially a beefy preprocessor. There are no longer any conditional
    expressions, and no macros.

  • It is some distance best implemented in GNU Awk.

  • It provides no capacity to buy the total included output.

  • The capacity @embody searches for recordsdata is pass to cpp. GNU Awk’s
    embody search is driven by the AWKPATH variable which brings in the total
    disadvantages shared by shared by PATH-bask in variables. In distinction cpp
    implements the acquainted habits that an #embody "..." directive is
    resolved relative to the listing of the file which comprises that
    #embody directive. No configuration is required for a program to search out
    all of its included gadgets.

I use awk on embedded techniques with out a cpp!

Although packaged that implies, cppawk doesn’t beget to be historical as an interpreter
which preprocesses and runs the code. Preprocessed code will seemingly be captured with
the --prepro-best risk, and then transferred to a target system for
execution with its Awk.

Tip: it’ll be a edifying conception to tweak cppawk in say that it doesn’t elaborate the
__gawk__ symbol, in case your target system’s Awk is no longer essentially GNU Awk.


Read More



Fill your life with experiences so you always have a great story to tell
Get Connected!
One of the Biggest Social Platform for Entrepreneurs, College Students and all. Come and join our community. Expand your network and get to know new people!


No comments yet
Knowasiak We would like to show you notifications so you don't miss chats & status updates.
Allow Notifications