djones@megatest.UUCP (Dave Jones) (11/09/88)
Posting-number: Volume 5, Issue 40 Submitted-by: "Dave Jones" <djones@megatest.UUCP> Archive-name: c.s.nawk [Assembler-dependent (Suns) and wants "new awk". ++bsa] In 1985, Mssrs. A, W, and K upgraded the programming language AWK, creating "new awk", or as it is called in BSD-land, "nawk". I like it. The three acromymic gentlemen have a new book out called _The_AWK_Programming_Language_ but don't try to use the book if you don't have nawk. If your awk is not nawk, and you don't have nawk as nawk -- got that? -- then you can get nawk by modeming up 201-522-6900 and logging in as "guest". Or so says the book, at least. I haven't tried it. Ah yes. This program. It merges related .c and .s files, turning the lines of the .c file into line-numbered comments in the assembly language output. I think it is pretty nifty, compact, and elegant. But then, I wrote it, so maybe I'm just vain. Nahhhhh. It runs under Sun3-OS, and I would guess that it would run on any BSD 4.2-derived system. I don't know enough about the other Unix flavors to speculate on where else it might work. Depends on arcane matters such and .stab directives, -g options, and the syntax of assembly language comments. Enjoy. -- snip -- snip -- snip -- snip -- snip -- snip -- snip -- snip -- snip #! /bin/sh # This file was wrapped with "dummyshar". "sh" this file to extract. # Contents: c.s.nawk echo extracting 'c.s.nawk' if test -f 'c.s.nawk' -a -z "$1"; then echo Not overwriting 'c.s.nawk'; else sed 's/^X//' << \EOF > 'c.s.nawk' X X# This nawk program is called "c.s.nawk". X# X# Use it to merge related .c and .s files, turning lines from the X# .c file into line-numbered comments in the assembly language code. X# X# Usage: X# X# cc -g -S foo.c X# nawk -f c.s.nawk foo.c foo.s > foo.c.s X# X# X XBEGIN { X X do { X if(!c_eof && !have_c_line) { X c_eof = (( getline c_line < ARGV[1] ) != 1 ) X c_line_num++ X have_c_line = 1 X } X X if(!s_eof && !have_s_line) { X s_eof = (( getline s_line < ARGV[2] ) != 1) X if(!s_eof && (match(s_line, /^\t.stabn\t0104/) != 0)){ X split(s_line,A,",") X s_line_num = A[3] X } X have_s_line = 1 X } X X if(!c_eof && ((c_line_num <= s_line_num) || s_eof )) { X have_c_line = 0 X printf "|$ %4.4d %s\n", c_line_num, c_line X }else{ X if(!s_eof) { X have_s_line = 0 X if(match(s_line, /^\t.stab/) == 0) X printf "%s\n", s_line X } X } X X }while( !s_eof || !c_eof ) X X X} # END EOF chars=`wc -c < 'c.s.nawk'` if test $chars != 937; then echo 'c.s.nawk' is $chars characters, should be 937 characters!; fi exit 0