[long] Cannot compile my assignment: "(W) Too many arguments are specified for the macro 'move'. The extra arguments are ignored." and more



Hi all,

== Background info ==

I am good with Linux but an AIX and Unix C++ newbie. I am using the
relatively modern VisualAge C++ Professional 5 on ancient AIX. The
machine is old and there is no way I could get gcc onto it. uname -a
gives: AIX castor 3 4 000097764C00.

== Error messages ==

I am getting repeated errors like:

"/usr/vacpp/include/iosfwd", line 129.38: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/vector", line 164.31: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 287.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"a2main.cpp", line 314.11: 1540-0256 (S) A parameter of type "Field *"
cannot be initialized with an expression of type "TextField *".
"a2main.cpp", line 314.11: 1540-1205 (I) The error occurred while
converting to parameter 1 of "Screen::add(Field *, int)".
make: 1254-004 The error code from the last command is 1.

A compile log and a listing of my main source file is below. I have
also included several lines of /usr/vacpp/include/iosfwd, since the
file is mentioned early on in the error messages. Anyone have any idea
what is causing the error messages?

Thanks in advance,
--
Jason Spiro
Canada
jasonspiro4+moznews@xxxxxxxxx

== Begin compile log ==

In the directory /students/jspiro/t I type make, and it runs the
compiler and spits out the following options:

c++ -+ -qsrcmsg -g -lcurses -DNDEBUG -oa2main screen.cpp
a2main.cpp dtio.c

screen.cpp:
a2main.cpp:
"/usr/vacpp/include/iosfwd", line 129.38: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/iosfwd", line 179.38: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/iosfwd", line 219.38: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/vector", line 164.31: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 196.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 205.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 209.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 231.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 236.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 243.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 616.31: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 648.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 657.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 661.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 684.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 688.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 693.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/vector", line 719.36: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 248.21: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 249.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 251.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 255.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 258.24: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring", line 355.37: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 77.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 77.52: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 125.55: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 128.65: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 146.55: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 162.55: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 170.17: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 205.61: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 208.49: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 209.60: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 211.61: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 212.48: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 214.61: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 215.61: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 217.49: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 218.60: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 219.59: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 240.60: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 244.68: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 262.60: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 266.68: 1540-0816 (W) Too many
arguments are specified for the macro "move". The extra arguments are
ignored.
"/usr/include/curses.h", line 1068.9: 1540-0425 (I) "move" is defined
on line 1068 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 276.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/xstring.t", line 287.23: 1540-0816 (W) Too many
arguments are specified for the macro "erase". The extra arguments are
ignored.
"/usr/include/curses.h", line 1042.9: 1540-0425 (I) "erase" is defined
on line 1042 of "a2main.cpp".
"/usr/vacpp/include/iosfwd", line 129.20: 1540-0063 (S) The text
"stdscr" is unexpected.
"/usr/vacpp/include/iosfwd", line 179.20: 1540-0063 (S) The text
"stdscr" is unexpected.
"/usr/vacpp/include/iosfwd", line 219.20: 1540-0063 (S) The text
"stdscr" is unexpected.
"/usr/vacpp/include/xstring", line 248.15: 1540-0063 (S) The text
"stdscr" is unexpected.
"/usr/vacpp/include/vector", line 231.18: 1540-0063 (S) The text
"stdscr" is unexpected.
"/usr/vacpp/include/vector", line 684.18: 1540-0063 (S) The text
"stdscr" is unexpected.
"a2main.cpp", line 314.11: 1540-0256 (S) A parameter of type "Field *"
cannot be initialized with an expression of type "TextField *".
"a2main.cpp", line 314.11: 1540-1205 (I) The error occurred while
converting to parameter 1 of "Screen::add(Field *, int)".
"a2main.cpp", line 317.11: 1540-0256 (S) A parameter of type "Field *"
cannot be initialized with an expression of type "TextField *".
"a2main.cpp", line 317.11: 1540-1205 (I) The error occurred while
converting to parameter 1 of "Screen::add(Field *, int)".
dtio.c:
make: 1254-004 The error code from the last command is 1.

== End compile log ==

== Begin screen.cpp listing ==

/*
file: screen.cpp
date: february 28, 2006
author: danny abesdris and Jason Spiro
purpose: C++ Source file containing class definitions for
oop344 (WINTER 2006) assignment #2
*/









// see three-semicolon mark








#include "screen.h"
#include "dtio.h"

#include <cassert>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// note: makefile usually compiles dtio.c as C++ for better
typechecking
#ifndef USING_MAKEFILE

#define YDEBUG 1
extern "C" { // to allow the low-level C functions to be
compiled
#include "dtio.c" // by the C compiler only
}

#endif

#include <cstring>

//////////////////
// Button Class //
//////////////////

// initialization of static integer member
// (begin deprecated comment)
// using 10000 to avoid potential of conflict with other
// defined constants --prof
// (end deprecated comment)
int Button::_countbid = INITIAL_COUNTBID;

Button::Button(char *btname, char *cmd, char *errmsg, int row, int col,
int errnum, int terminating, Screen *scr,
int (*task)(char *, int, Screen *))
:
Field(btname, row, col, strlen(btname),
(scr && task) ? strlen(btname) : 0, strlen(btname) / 2,
0, 0) {
_cmd = memory(strlen(cmd) + 1);
strcpy(_cmd, cmd);
_err = memory(strlen(errmsg) + 1);
strcpy(_err, errmsg);
_errnum = errnum;
_scr = scr;
_task = task;
_bid = _countbid++;
_terminating = terminating;
}

int Button::edit() {
int key;
int taskretval;
// I'm commenting this line out since the lines below that use it are
// commented out too.
// Field *errfield;

dt_cursor(_row, _col + _start);
key = dt_getkey();
if (ENTER == key) {
taskretval = _task(_cmd, _bid, _scr);
// Why are these lines commented out? --jspiro
// if(!retval) {
// errfield = scr_->fieldptr(errnum_);
// strcpy(errfield->data( ),err_);
// errfield->draw( );
// }
}
return (_terminating && ENTER == key) ? -_bid : key;
}

Button::~Button() {
if(_cmd) {
delete[] _cmd;
}
if(_err) {
delete[] _err;
}
}

char *Button::data() {
return _cmd;
}

int Button::button_id() {
return _bid;
}

/////////////////
// Field Class //
/////////////////

int Field::_insert = 1; // this is how a static member variable
// is required to be initialized!!!
// it must be initialized with "global scope"

Field::Field(char *str, int row, int col, int flen,
int slen, int offset, int start, int ctype) {
_row = row;
_col = col;
_flen = flen;
_slen = slen;
_offset = offset;
_start = start;
_ctype = ctype;

int ssize;
ssize = (slen == 0) ? strlen(str) : _slen;
_str = new char[ssize + 1];
if(_str != NULL) {
strcpy(_str, str);
}
}

Field::~Field() {
if(_str != NULL) {
delete[] _str;
}
}

void Field::draw() const {
dt_draw(_str, _row, _col, _flen);
}

void Field::draw(int row, int col, int l, int h,
char edge, char top_btm, char ls_rs) const {

dt_box(row-1, col-1, l+1, h, edge, top_btm, ls_rs);
dt_draw(_str, row, col, l);
}

bool Field::editable() const {
bool rc = false;
if(_slen != 0)
rc = true;
return rc;
// OR... return _slen != 0;
}

int Field::edit() {
int keycode = NONE_YET;

if (editable()) {
keycode = dt_edit(_str, _slen, _row, _col, _flen, &_start,
&_offset, &_insert, _ctype);
}
else {
int keycode = NOT_APPLICABLE;
draw();
}
return keycode;
}

// All Fields share the same insert/overwrite mode
// (Hint: a static data member may be used to accomplish this
functionality).

char *Field::data() {
return _str;
}

char* Field::memory(int size) {
char *temp;
temp = new char[size];
if (temp == NULL) {
cout << "Error allocating (char *) memory of " << size
<< " bytes..." << endl;
exit(EXIT_FAILURE);
}
return temp;
}

/////////////////////
// TextField Class //
/////////////////////

// the TextField constructor sends data to the base class Field object,

// dynamically allocates memory for a 2D internal pointer char **_page,
and then
// fills '_page' with characters in the string 'page', but does not
incorporate
// the "word wrap" feature required for assignment #2
TextField::TextField(char *str, int row, int col, int width,
int box_h, char edge, char top_btm, char ls_rs)
:
// Initialize Field base class.
Field(str, row, col, width, 0, 0, 0, 0) {
_box_h = box_h;
_edge = edge;
_top_btm = top_btm;
_ls_rs = ls_rs;
_offset = 0;
/*
* Split the C string _str into multiple C++ strings in the variable
* vector<string> _page.
*/
int spos = 0;
// was: "while ('\0' != (_str + spos)) {" but that caused Valgrind
// to (rightly) complain.
while (!(spos > strlen(_str))) {
char *temp = (char *) malloc((width + 1) * sizeof(char));
memset(temp, '\0', width + 1);
int lesser = MIN(width, strlen(_str + spos));
temp = strncpy(temp, (_str + spos), (0 == width ? 0 : lesser));
//#define NONNEG(x) ((x) < 0 ? 0 : (x))
// temp = strncpy(temp, (_str + spos), NONNEG(MIN(width, strlen(_str +
spos)) - 1));
string widthchars = temp;
free(temp);

/*
* Word-wrap algorithm
*
* FIXME: the following algorithm is a complete hack. It works
* for the strings in the prof's test class, but I
* doubt it'd work for all (or even most) others.
* - What if there's a 1000-char word as either the
* first word in _str, or later on, or as the first
* word but with 1 or more spaces before it?
* - How does this deal with multiple spaces in
a row?
* - with Unix, DOS, or Mac newlines in
mid-buffer?
* - Shouldn't it wrap on dashes?
* The moral of the story is: Don't use this class
library.
* Use DOS pdcurses or Cygwin ncurses instead. They do
word
* wrap too.
*/
if (string::npos != widthchars.rfind(" ")) {
int truncate_to;
// should that be a > in the next line?
// or should I be adding some constant to one side?
// or is my whole approach wrong?
if (widthchars.length() == width) {
// the + 1 was inserted as a hack so that it'll
// copy 1 extra char so that there isn't a
// space on the left side of each row past
// the 1st
truncate_to = (widthchars.rfind(" ") + 1);
} else {
truncate_to = width;
}
// the 2nd param of resize says "pad with spaces if
// expanding the string".
widthchars.resize(truncate_to, ' ');
_page.push_back(widthchars);
spos += truncate_to;
}
#if 0 // It seems that now that I have made the while statement at the
top of
// the loop to be more accurate, this hack is no longer needed.
// FIXME: Utter and complete hack
if (0 == widthchars.length()) {
return;
}
#endif
}
}

TextField::~TextField() { // removing memory for the dynamically
allocated 2D array
//delete _page; // seems unnecessary now that _page is no longer a
pointer
// FIXME: free _str too? (probably can use code I had in this function
before)
// -> presumably the base destructor is automatically called and
frees it
}

void TextField::draw() const {
// draw a box as per spec:
// "'edge', 'top_btm', and 'ls_rs' are used to draw the bounding
// 'box' around the TextField (as in assignment #1)"
dt_box(_row - 1, _col - 1, _flen + 2, _box_h + 2, _edge, _top_btm,
_ls_rs);
#if 0
// for debugging purposes
dt_update();
abort();
#endif
#if 0
// Is it trying to draw too many rows?
int row_to_draw = 59;
string string_to_draw = this->_page[row_to_draw];
cout << string_to_draw;
abort();
#endif
for (int i = 0; i < this->_page.size(); i++) {
int row_to_draw = this->_offset + i;
//cerr<<row_to_draw;
//if (_page.size() - 1 == row_to_draw) {
// dummyfunction();
//}
string string_to_draw = this->_page[row_to_draw];
//cout << string_to_draw;
dt_draw(string_to_draw.c_str(), _row + i, _col, _flen);
// for debugging: cerr << i << ' ';
if (_box_h - 1 == i) {
break;
}
}
}

int TextField::edit() {
// Variable declaration section for below.
// holds the key the user types inside our loop
int key = NONE_YET;
// cursor row, decided on a relative basis (ie. not considering the
// value of _col)
int relpos = 0;
// should we exit the loop this time around? 0 = no, 1 = yes.
int exitloop = 0;

// for debugging: cout << _page[58];

do {
// If the cursor is not in the visible area, then change the
// visible area so that it will be.
while (relpos < this->_offset) {
_offset--;
}
while (relpos - _offset >= _box_h) {
_offset++;
}

// Once each iteration, refresh and set cursor.
this->draw();
dt_cursor(_row + relpos - _offset, _col);

assert(_row >= 0);
assert(_row <= dt_rows());

assert(_col >= 0);
assert(_col <= dt_cols());

// I choose not to support fields 0 rows tall
assert(_box_h >= 1);
// I do not check *for* developers that their fields will fit
onscreen.
// However, I make an easier check.
assert(_box_h <= dt_cols());

assert(relpos >= 0);

// Also assert the cursor is not past a null.
// THOUGHT: Doesn't strlen only count up to the first null?
assert(relpos <= _page.size() - 1);

assert(_offset >= 0);
assert(_offset <= _page.size() - 1);

assert("Why would key be 0? But, for some reason, it is." && 0 !=
key);

key = dt_getkey();

switch (key) {
case UP:
if (relpos > 0) {
relpos--;
} // FIXME_P3 else beep (here and also in case RIGHT and case BS)?
break;
case DOWN:
// Can we move the cursor?
// Let's say there are 3 rows, 0, 1, 2. So size() is 3.
// So if relpos is 2 (size - 1)
if (relpos < this->_page.size() - 1) {
relpos++;
}
break;
case HOME:
relpos = 0;
break;
case END:
relpos = _page.size() - 1;
break;
case PGUP:
// Note: All the code for this case is based on
// code from elsewhere in this edit() function.
// Step 1: Move cursor up until it is at the top
// of the visible area.
for (int loopsdone = 0; loopsdone < MAX_LOOPS; loopsdone++) {
// Hack: this "if" used to be a "while".
// There was no loop-breaking code wrapping this.
// I had planned have it avoid loop the right way.
if (!(relpos < _offset)) {
if (relpos > 0) {
relpos--;
}
}
}
// Step 2: Move cursor up "i" times, where i is the
// height of the TextField.
for (int i = 0; i < _box_h; i++) {
if (relpos > 0) {
relpos--;
}
}
// Step 3: If the cursor is not in the visible area, then change the

// visible area so that it will be.
while (relpos < this->_offset) {
_offset--;
}
while (relpos - _offset >= _box_h) {
_offset++;
}
// Step 4: Move cursor down until it is at the bottom
// of the visible area.
for (int loopsdone = 0; loopsdone < MAX_LOOPS; loopsdone++) {
// Hack: this "if" used to be a "while". See above.
// Note: The "- 1" bit is so that we don't go
// outside the visible area, but just to
// the bottom of it.
if (!(relpos - _offset >= _box_h - 1)) {
if (relpos < this->_page.size() - 1) {
relpos++;
}
}
}
break;
case PGDN:
// Note: All the code for this case is based on
// code from elsewhere in this edit() function.
// Step 1: Move cursor down until it is at the bottom
// of the visible area.
for (int loopsdone = 0; loopsdone < MAX_LOOPS; loopsdone++) {
// Hack: this "if" used to be a "while". See above.
if (!(relpos - _offset >= _box_h)) {
if (relpos < this->_page.size() - 1) {
relpos++;
}
}
}
// Step 2: Move cursor down "i" times, where i is the
// height of the TextField.
for (int i = 0; i < _box_h; i++) {
if (relpos < this->_page.size() - 1) {
relpos++;
}
}
// Step 3: If the cursor is not in the visible area, then change the

// visible area so that it will be.
while (relpos < this->_offset) {
_offset--;
}
while (relpos - _offset >= _box_h) {
_offset++;
}
// Step 4: Move cursor up until it is at the top
// of the visible area.
for (int loopsdone = 0; loopsdone < MAX_LOOPS; loopsdone++) {
// Hack: this "if" used to be a "while". See above.
// Note: The "- 1" bit is so that we don't go
// outside the visible area, but just to
// the bottom of it.
if (!(relpos - 1 < _offset)) {
if (relpos > 0) {
relpos--;
}
}
}
break;
// If any other key is typed:
default:
// Do nothing; the loop will end.
exitloop = 1;
break;
} // end switch
} while (0 == exitloop);

assert("Why would key be 0? But, for some reason, it is." && 0 !=
key);

return key;
}

bool TextField::editable() const {
return true;
}

char *TextField::data() {
return _str;
}

//////////////////
// Screen Class //
//////////////////

// Add a Field to a Screen.
// Returns the new Field's number, or returns TOO_MANY_FIELDS if
unsuccessful.
// Note: Field numbers are 1-based.
int Screen::add(Field *fp, int autodelete) {
// remove this line if you sometimes use values other than 1 to mean
'true':
assert(0 == autodelete || 1 == autodelete);

int retval;
if (_numfields < MAX_FIELDS) {
_numfields++;
_fields[_numfields] = fp;
_autodelete[_numfields] = autodelete;
retval = _numfields;
} else {
retval = TOO_MANY_FIELDS;
}
return retval;
}


// Display Field fnum, or clear screen and display all Fields on the
Screen if
// fnum is 0.
// Note: Field numbers are 1-based.
void Screen::display(int fnum) {
if (0 == fnum) {
dt_clear();
// This for loop is duplicated in the edit method below.
for (int i = 1; i <= _numfields; i++) {
_fields[i]->draw();
}
} else {
dummyfunction();
_fields[fnum]->draw();
}
}

/* int Screen::edit
* Displays all Field objects on the Screen and runs in a loop while we
allow the
* user to fill them in.
* Does this by calling edit() on the field that library user
specifies.
* Allows the user to move between fields in order with UP, DOWN, TAB,
and ENTER.
* Order is the order the fields were added in.
* This method returns in the following situations:
* - Enter key on the last field in the order. (We end and return
ENTER.)
* - a Field returns a negative integer (currently only happens on
Buttons for
* which ::terminating was set to true.) (We end and return the
Field's
* edit() function return value.)
* - the user presses any other special key defined in dtio.h. (We
end and
* return that key's value as defined in dtio.h.)
* - there are no editable fields. (We call dt_getkey() then return
its
* return value.)
* Args:
* - int *fnum: Complicated. See spec. In short: the field to initially
focus.
* - int clear: If true (which currently isn't the default argument),
clear the
* screen before doing anything.
*/
int Screen::edit(int *origfnum, int clear_flag) {
/*
* TODO: deal with:
* - assign a number to *fnum at end
*/

// API user: remove this line if you sometimes use values other than
// 1 to mean 'true':
assert(0 == clear_flag || 1 == clear_flag);

/* Clear screen if caller requested it.
* The spec did not specify this, but I am assuming a true value means

* clear.
*/
if (true == clear_flag) {
dt_clear();
}

/* Display all fields.
* This for loop is duplicated in the display method above.
*/
for (int i = 1; i <= _numfields; i++) {
_fields[i]->draw();
}

// If there are no fields...
if (0 == this->_numfields) {
return dt_getkey();
}

/*
* Begin dealing with the *origfnum value that was passed to us.
*/

int fnum;
// set fnum to *origfnum, or to 1 (first field) if origfnum is NULL
if (NULL != origfnum) {
fnum = *origfnum;
} else {
fnum = 1;
}

/*
* If fnum contains the number of a nonexistent field, fix fnum.
*/
if (fnum < 1) {
fnum = 1;
}
if (fnum > _numfields) {
fnum = _numfields;
}

/*
* Make sure fnum refers to a valid and editable field.
*/

bool hit_end = false;

// search forwards thru set of fields for an editable field
while (fnum <= _numfields && false ==
this->fieldptr(fnum)->editable()) {
fnum++;
}
if (fnum == _numfields + 1) {
// search hit end: try backwards search
hit_end = true;
}

if (hit_end) {
hit_end = false;
assert(_numfields + 1 == fnum);
fnum--; // make an adjustment b/c fnum > maxfields and would segfault
// search backwards thru set of fields for an editable field
while (fnum > 0 && false == this->fieldptr(fnum)->editable()) {
fnum--;
}
if (0 == fnum) {
// search hit end: there are no editable fields
hit_end = true;
}
}

if (hit_end) {
// no editable fields
return dt_getkey();
}

/*
* Allow user to fill in the fields.
*/
bool done = false;
int lastkey = NONE_YET;
int fldretval = NONE_YET; // return value from a field's edit()
function
int ourretval = NONE_YET;
while (false == done) {
Field *fp;
fp = this->fieldptr(fnum);
assert(false != fp->editable());
if (NULL == fp) {
cout << endl << "Computer error: Screen::fieldptr(ptr"
<< " to " << fnum << ") returned NULL " << endl
<< "at file " << __FILE__ << " line " << __LINE__
<< ". Exiting. Sorry." << endl;
exit(EXIT_FAILURE);
}

// bkpt
fldretval = fp->edit();
// bkpt

assert("I don't think this fldretval value should be possible:"
&& (0 != fldretval));

if (fldretval > 0) {
lastkey = fldretval;
} else {
ourretval = fldretval;
// necessary since otherwise ourretval could be
// overwritten:
break;
}

switch (lastkey) {
case UP:
// Search backwards thru set of fields for an editable field.
// This is the field that will be active on the next loop iteration.
do {
fnum--;
if (0 == fnum) {
fnum = _numfields; // wraparound if needed
}
} while (fnum > 0 && false == this->fieldptr(fnum)->editable());
break;
case ENTER:
if (fnum == _numfields) {
// leave the switch tree and the while loop surrounding it
ourretval = ENTER;
done = true;
break;
} else {
// fallthru to TAB
}
case DOWN: // fallthru to TAB
case TAB:
// Search forwards thru set of fields for an editable field.
// This is the field that will be active on the next loop iteration.
do {
fnum++;
if (fnum > _numfields) {
fnum = 1; // wraparound if needed
}
} while (fnum <= _numfields && false ==
this->fieldptr(fnum)->editable());
break;
default:
ourretval = lastkey;
done = true;
break;
} // switch
} // while
assert(ourretval != NONE_YET);
return ourretval;
}

Screen::Screen() {
_numfields = 0;

for(int i = 1; i <= MAX_FIELDS; i++) {
_autodelete[i] = 0;
// initialization to NULL helps detect invalid accesses to
// nonexistent Field objects earlier.
_fields[i] = NULL;
}
}

// Return a pointer to the nth field, or a null pointer if no such
field exists.
// Note: Field numbers are 1-based.
Field *Screen::fieldptr(int fnum) {
assert(fnum != 0);
if (fnum <= _numfields) {
return _fields[fnum];
} else {
return NULL;
}
}

#if 0

int* Screen::memoryi(int size) {
int *p;
p = new int[size];
if(p == NULL) {

cout << "Error allocating (int *)" <<
" memory of " << size << " elements..." << endl;
exit(1);
}
return p;
}

Field** Screen::memoryf(int size) {
Field **p;

p = new Field* [size];
if(p == NULL) {
cout << "Error allocating (Field *)" <<
" memory of " << size << " elements..." << endl;
exit(1);
}
return p;
}

int Screen::add(Field *fp, int autodelete) {
int retval = 0;
if (_numfields < _maxfields) {
_autodelete[_numfields] = autodelete;
_fields[_numfields] = fp;
_numfields++;
retval = _numfields;
}
return retval;
}

int Screen::edit(int *fpnum, int clear) {
int startfield;
int curr;
int endkey;
display(0);
_fields[3]->edit(); // calling Button's edit
return 0;
}

#endif

Screen::~Screen() {
for (int i = 1; i <= _numfields; i++) {
if (false != _autodelete[i]) {
delete _fields[i];
}
}
}

///////////
// Other //
///////////

int my_task(char *cmd, int n, Screen *p) {
dt_cursor(9, 12);
dt_putstring("displaying text on the same line as button");
return n;
}

#ifdef YDEBUG
// My debugger does not stop at breakpoints I define at certain points.
// But it always can stop on a call to dummyfunction(), so I just
// insert one there.
void dummyfunction(void) {
return;
}
#endif

== End screen.cpp listing ==

== Begin listing of lines 129-137 of /usr/vacpp/include/iosfwd, in case
it's useful ==

static _E *move(_E *_U, const _E *_V, size_t _N)
{_E *_Ans = _U;
if (_V < _U && _U < _V + _N)
for (_U += _N, _V += _N; 0 < _N; --_N)
assign(*--_U, *--_V);
else
for (; 0 < _N; --_N, ++_U, ++_V)
assign(*_U, *_V);
return (_Ans); }

== End listing of lines 129-137 of /usr/vacpp/include/iosfwd, in case
it's useful ==

Thanks again,
Jason

.


Loading