[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

vim tricks for constructing header files

luserXtrog

5/16/2011 10:13:00 PM

I've just cobbled together a few tricks that save a bunch of
keystrokes when generating the .h file from a freshly written
..c file.

A freshly written .c file:
1
2 #include "m.h"
3 #include "ob.h"
4
5 object consarr(mfile *mem, unsigned sz) {
6 unsigned ent = mtalloc(mem, sz * sizeof(object));
7 return (object){ .tag = arraytype, .sz = sz, .ent = ent, .off
= 0};
8 }
9
10 void arrput(mfile *mem, object a, integer i, object o) {
11 put(mem, a.comp_.ent, a.comp_.off + i, sizeof(object), &o);
12 }
13
14 object arrget(mfile *mem, object a, integer i) {
15 object o;
16 get(mem, a.comp_.ent, a.comp_.off + i, sizeof(object), &o);
17 return o;
18 }
19
"ar.c" 19L, 472C written

then switch to new file
:e ar.h
load previous file
:r #
trim headers
d}
replace function body with semicolon
j$c%;ESC
reposition, repeat change
jj$.
again
jj.
et voila:

1
2 object consarr(mfile *mem, unsigned sz);
3
4 void arrput(mfile *mem, object a, integer i, object o);
5
6 object arrget(mfile *mem, object a, integer i);
7
"ar.h" 7L, 149C written

3 Answers

Rui Maciel

5/17/2011 12:14:00 AM

0

luser- -droog wrote:

> then switch to new file
> :e ar.h
> load previous file
> :r #
> trim headers
> d}
> replace function body with semicolon
> j$c%;ESC
> reposition, repeat change
> jj$.
> again
> jj.
> et voila:

You can go a step further and record a macro with that list of commands or
map a specific keyboard shortcut to that script.


Rui Maciel

luserXtrog

5/17/2011 4:42:00 AM

0

On May 16, 7:14 pm, Rui Maciel <rui.mac...@gmail.com> wrote:
> luser- -droog wrote:
> > then switch to new file
> > :e ar.h
> > load previous file
> > :r #
> > trim headers
> > d}
> > replace function body with semicolon
> > j$c%;ESC
> > reposition, repeat change
> > jj$.
> > again
> > jj.
> > et voila:
>
> You can go a step further and record a macro with that list of commands or
> map a specific keyboard shortcut to that script.
>
> Rui Maciel

I fear that's where the diminishing returns begin.
Even with this example an extra $ is required if the
new prototype is longer than the previous.

And, of course, you want to delete any static declarations
or "not-quite-ready" parts; so I think interactive is still
the way to go.

I suppose more powerful tools require some sort of "mark-up" to
designate
exported functions which amounts to manual control and extra
gobbldegook
in the source.

Old Wolf

5/18/2011 10:58:00 PM

0

On May 17, 10:12 am, luser- -droog <mijo...@yahoo.com> wrote:
> I've just cobbled together a few tricks that save a bunch of
> keystrokes when generating the .h file from a freshly written
> .c file.

Have to say that I always write the .h file first.

Define and document the interface between units first,
and implement it later -- good design IMHO.

Then all you have to do is copy the .h file to the .c file
and change semicolons to curly braces.