[aklug] Re: Question about C Argument Syntax

From: Michael Fowler <michael@shoebox.net>
Date: Wed May 20 2009 - 15:47:18 AKDT

On Sat, May 16, 2009 at 03:57:42PM -0800, Christopher Howard wrote:
> Quick question for the C gurus among you: I need to write a wrapper
> function around the mvprintw function, like so:
>
> int smvprintw( ? )
> {
> // Do various checks/modifications on the first two arguments (int y,
> int x) first,
> // and then
> return mvprintw ( ? );
> }
>
> How should I write the args for smvprintw so that I can pass all the
> data correctly to mvprintw, and also do my checks on the first two args?

I'm pretty sure you're simply not going to be able to call mvprintw()
directly with a vararg wrapper. You would need to use the provided
vw_printw to wrap your function. For example:

    #include <curses.h>
    #include <stdarg.h>
    #include <unistd.h>

    int my_mvprintw(int x, int y, const char *fmt, ...)
    {
        va_list ap;
        va_start(ap, fmt);

        move(x+10, y+10);

        return vw_printw(stdscr, fmt, ap);
    }

    int main(int argc, char **argv)
    {
        initscr();
        cbreak();
        noecho();
        nonl();
        intrflush(stdscr, FALSE);
        keypad(stdscr, TRUE);

        addstr("This is a test.");

        if (argc == 3) {
            my_mvprintw(2, 2, "%s: %s", argv[1], argv[2]);
        } else {
            addstr(" No arguments given.");
        }

        refresh();

        sleep(-1);
        endwin();
        return 0;
    }

--
Michael Fowler
www.shoebox.net
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed May 20 15:47:32 2009

This archive was generated by hypermail 2.1.8 : Wed May 20 2009 - 15:47:32 AKDT