link_fieldtype(FIELDTYPE *type1, FIELDTYPE *type2) { FIELDTYPE *nftyp = (FIELDTYPE *)0; T((T_CALLED("link_fieldtype(%p,%p)"), type1, type2)); if (type1 && type2) { nftyp = typeMalloc(FIELDTYPE, 1); if (nftyp) { T((T_CREATE("fieldtype %p"), nftyp)); *nftyp = *_nc_Default_FieldType; nftyp->status |= _LINKED_TYPE; if ((type1->status & _HAS_ARGS) || (type2->status & _HAS_ARGS)) nftyp->status |= _HAS_ARGS; if ((type1->status & _HAS_CHOICE) || (type2->status & _HAS_CHOICE)) nftyp->status |= _HAS_CHOICE; nftyp->left = type1; nftyp->right = type2; type1->ref++; type2->ref++; } else { SET_ERROR(E_SYSTEM_ERROR); } } else { SET_ERROR(E_BAD_ARGUMENT); } returnFieldType(nftyp); }
NCURSES_SP_NAME(new_form) (NCURSES_SP_DCLx FIELD **fields) { int err = E_SYSTEM_ERROR; FORM *form = (FORM *)0; T((T_CALLED("new_form(%p,%p)"), (void *)SP_PARM, (void *)fields)); if (IsValidScreen(SP_PARM)) { form = typeMalloc(FORM, 1); if (form) { T((T_CREATE("form %p"), (void *)form)); *form = *_nc_Default_Form; /* This ensures win and sub are always non-null, so we can derive always the SCREEN that this form is running on. */ form->win = StdScreen(SP_PARM); form->sub = StdScreen(SP_PARM); if ((err = Associate_Fields(form, fields)) != E_OK) { free_form(form); form = (FORM *)0; } } } if (!form) SET_ERROR(err); returnForm(form); }
new_fieldtype(bool (*const field_check) (FIELD *, const void *), bool (*const char_check) (int, const void *)) { FIELDTYPE *nftyp = (FIELDTYPE *)0; T((T_CALLED("new_fieldtype(%p,%p)"), field_check, char_check)); if ((field_check) || (char_check)) { nftyp = typeMalloc(FIELDTYPE, 1); if (nftyp) { T((T_CREATE("fieldtype %p"), nftyp)); *nftyp = default_fieldtype; nftyp->fcheck = field_check; nftyp->ccheck = char_check; } else { SET_ERROR(E_SYSTEM_ERROR); } } else { SET_ERROR(E_BAD_ARGUMENT); } returnFieldType(nftyp); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Make_Enum_Type( va_list * ap ) | | Description : Allocate structure for enumeration type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Make_Enum_Type(va_list *ap) { enumARG *argp = typeMalloc(enumARG, 1); if (argp) { int cnt = 0; char **kp = (char **)0; int ccase, cunique; T((T_CREATE("enumARG %p"), argp)); argp->kwds = va_arg(*ap, char **); ccase = va_arg(*ap, int); cunique = va_arg(*ap, int); argp->checkcase = ccase ? TRUE : FALSE; argp->checkunique = cunique ? TRUE : FALSE; kp = argp->kwds; while (kp && (*kp++)) cnt++; argp->count = cnt; } return (void *)argp; }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Generic_This_Type(void * arg) | | Description : Allocate structure for numeric type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Generic_This_Type(void *arg) { thisARG *argn = (thisARG *) 0; thisPARM *args = (thisPARM *) arg; if (args) { argn = typeMalloc(thisARG, 1); if (argn) { T((T_CREATE("thisARG %p"), (void *)argn)); argn->precision = args->precision; argn->low = args->low; argn->high = args->high; #if HAVE_LOCALE_H argn->L = localeconv(); #else argn->L = NULL; #endif } } return (void *)argn; }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Make_This_Type(va_list *ap) | | Description : Allocate structure for alphanumeric type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Make_This_Type(va_list *ap) { thisARG *argp = typeMalloc(thisARG, 1); if (argp) { T((T_CREATE("thisARG %p"), argp)); argp->width = va_arg(*ap, int); } return ((void *)argp); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Make_This_Type( va_list * ap ) | | Description : Allocate structure for integer type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Make_This_Type(va_list *ap) { thisARG *argp = typeMalloc(thisARG, 1); if (argp) { T((T_CREATE("thisARG %p"), argp)); argp->precision = va_arg(*ap, int); argp->low = va_arg(*ap, long); argp->high = va_arg(*ap, long); } return (void *)argp; }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Copy_ThisType(const void *argp) | | Description : Copy structure for alphanumeric type argument. | | Return Values : Pointer to argument structure or NULL on error. +--------------------------------------------------------------------------*/ static void * Copy_This_Type(const void *argp) { const thisARG *ap = (const thisARG *)argp; thisARG *result = typeMalloc(thisARG, 1); if (result) { T((T_CREATE("thisARG %p"), result)); *result = *ap; } return ((void *)result); }
dup_field(FIELD *field, int frow, int fcol) { FIELD *New_Field = (FIELD *)0; int err = E_BAD_ARGUMENT; T((T_CALLED("dup_field(%p,%d,%d)"), (void *)field, frow, fcol)); if (field && (frow >= 0) && (fcol >= 0) && ((err = E_SYSTEM_ERROR) != 0) && /* trick : this resets the default error */ (New_Field = typeMalloc(FIELD, 1))) { T((T_CREATE("field %p"), (void *)New_Field)); *New_Field = *_nc_Default_Field; New_Field->frow = (short) frow; New_Field->fcol = (short) fcol; New_Field->link = New_Field; New_Field->rows = field->rows; New_Field->cols = field->cols; New_Field->nrow = field->nrow; New_Field->drows = field->drows; New_Field->dcols = field->dcols; New_Field->maxgrow = field->maxgrow; New_Field->nbuf = field->nbuf; New_Field->just = field->just; New_Field->fore = field->fore; New_Field->back = field->back; New_Field->pad = field->pad; New_Field->opts = field->opts; New_Field->usrptr = field->usrptr; if (_nc_Copy_Type(New_Field, field)) { size_t i, len; len = Total_Buffer_Size(New_Field); if ((New_Field->buf = (FIELD_CELL *)malloc(len))) { for (i = 0; i < len; ++i) New_Field->buf[i] = field->buf[i]; returnField(New_Field); } } } if (New_Field) free_field(New_Field); SET_ERROR(err); returnField((FIELD *)0); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Make_RegularExpression_Type(va_list * ap) | | Description : Allocate structure for regex type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Make_RegularExpression_Type(va_list *ap) { #if HAVE_REGEX_H_FUNCS char *rx = va_arg(*ap, char *); RegExp_Arg *preg; preg = typeMalloc(RegExp_Arg, 1); if (preg) { T((T_CREATE("RegExp_Arg %p"), preg)); if (((preg->pRegExp = typeMalloc(regex_t, 1)) != 0) && !regcomp(preg->pRegExp, rx, (REG_EXTENDED | REG_NOSUB | REG_NEWLINE))) { T((T_CREATE("regex_t %p"), preg->pRegExp)); preg->refCount = typeMalloc(unsigned long, 1); *(preg->refCount) = 1; } else { if (preg->pRegExp)
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Copy_This_Type(const void * argp) | | Description : Copy structure for integer type argument. | | Return Values : Pointer to argument structure or NULL on error. +--------------------------------------------------------------------------*/ static void * Copy_This_Type(const void *argp) { const thisARG *ap = (const thisARG *)argp; thisARG *result = (thisARG *) 0; if (argp) { result = (thisARG *) malloc(sizeof(thisARG)); if (result) { T((T_CREATE("thisARG %p"), result)); *result = *ap; } } return (void *)result; }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Generic_This_Type(va_list *ap) | | Description : Allocate structure for alpha type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Generic_This_Type(void *arg) { thisARG *argp = (thisARG *) 0; if (arg) { argp = typeMalloc(thisARG, 1); if (argp) { T((T_CREATE("thisARG %p"), (void *)argp)); argp->width = *((int *)arg); } } return ((void *)argp); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Copy_Enum_Type( const void * argp ) | | Description : Copy structure for enumeration type argument. | | Return Values : Pointer to argument structure or NULL on error. +--------------------------------------------------------------------------*/ static void * Copy_Enum_Type(const void *argp) { enumARG *result = (enumARG *)0; if (argp) { const enumARG *ap = (const enumARG *)argp; result = typeMalloc(enumARG, 1); if (result) { T((T_CREATE("enumARG %p"), result)); *result = *ap; } } return (void *)result; }
new_form(FIELD **fields) { int err = E_SYSTEM_ERROR; FORM *form = typeMalloc(FORM, 1); T((T_CALLED("new_form(%p)"), fields)); if (form) { T((T_CREATE("form %p"), form)); *form = *_nc_Default_Form; if ((err = Associate_Fields(form, fields)) != E_OK) { free_form(form); form = (FORM *)0; } } if (!form) SET_ERROR(err); returnForm(form); }
new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf) { static const FIELD_CELL blank = BLANK; static const FIELD_CELL zeros = ZEROS; FIELD *New_Field = (FIELD *)0; int err = E_BAD_ARGUMENT; T((T_CALLED("new_field(%d,%d,%d,%d,%d,%d)"), rows, cols, frow, fcol, nrow, nbuf)); if (rows > 0 && cols > 0 && frow >= 0 && fcol >= 0 && nrow >= 0 && nbuf >= 0 && ((err = E_SYSTEM_ERROR) != 0) && /* trick: this resets the default error */ (New_Field = (FIELD *)malloc(sizeof(FIELD))) != 0) { T((T_CREATE("field %p"), New_Field)); *New_Field = default_field; New_Field->rows = rows; New_Field->cols = cols; New_Field->drows = rows + nrow; New_Field->dcols = cols; New_Field->frow = frow; New_Field->fcol = fcol; New_Field->nrow = nrow; New_Field->nbuf = nbuf; New_Field->link = New_Field; #if USE_WIDEC_SUPPORT New_Field->working = newpad(1, Buffer_Length(New_Field) + 1); New_Field->expanded = (char **)calloc(1 + (unsigned)rows, sizeof(char *)); #endif if (_nc_Copy_Type(New_Field, &default_field)) { size_t len; len = Total_Buffer_Size(New_Field); if ((New_Field->buf = (FIELD_CELL *)malloc(len))) { /* Prefill buffers with blanks and insert terminating zeroes between buffers */ int i, j; int cells = Buffer_Length(New_Field); for (i = 0; i <= New_Field->nbuf; i++) { FIELD_CELL *buffer = &(New_Field->buf[(cells + 1) * i]); for (j = 0; j < cells; ++j) { buffer[j] = blank; } buffer[j] = zeros; } returnField(New_Field); } } } if (New_Field) free_field(New_Field); SET_ERROR(err); returnField((FIELD *)0); }
int setupterm(const char *tname, int Filedes, int *errret) { struct term *term_ptr; int status; T((T_CALLED("setupterm(\"%s\",%d,%p)"), tname, Filedes, errret)); if (tname == 0) { tname = getenv("TERM"); if (tname == 0 || *tname == '\0') { ret_error0(-1, "TERM environment variable not set.\n"); } } if (strlen(tname) > MAX_NAME_SIZE) { ret_error(-1, "TERM environment must be <= %d characters.\n", MAX_NAME_SIZE); } T(("your terminal name is %s", tname)); term_ptr = typeCalloc(TERMINAL, 1); if (term_ptr == 0) { ret_error0(-1, "Not enough memory to create terminal structure.\n") ; } #if USE_DATABASE status = grab_entry(tname, &term_ptr->type); #else status = 0; #endif /* try fallback list if entry on disk */ if (status != 1) { const TERMTYPE *fallback = _nc_fallback(tname); if (fallback) { memcpy(&term_ptr->type, fallback, sizeof(TERMTYPE)); status = 1; } } if (status == -1) { ret_error0(-1, "terminals database is inaccessible\n"); } else if (status == 0) { ret_error(0, "'%s': unknown terminal type.\n", tname); } set_curterm(term_ptr); if (command_character && getenv("CC")) do_prototype(); strlcpy(ttytype, cur_term->type.term_names, NAMESIZE); /* * Allow output redirection. This is what SVr3 does. * If stdout is directed to a file, screen updates go * to standard error. */ if (Filedes == STDOUT_FILENO && !isatty(Filedes)) Filedes = STDERR_FILENO; cur_term->Filedes = Filedes; _nc_get_screensize(&LINES, &COLS); if (errret) *errret = 1; T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS)); if (generic_type) { ret_error(0, "'%s': I need something more specific.\n", tname); } if (hard_copy) { ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname); } returnCode(OK); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static int Connect_Fields(FORM *form, FIELD **fields) | | Description : Set association between form and array of fields. | | Return Values : E_OK - no error | E_CONNECTED - a field is already connected | E_BAD_ARGUMENT - Invalid form pointer or field array | E_SYSTEM_ERROR - not enough memory +--------------------------------------------------------------------------*/ static int Connect_Fields(FORM *form, FIELD **fields) { int field_cnt, j; int page_nr; int maximum_row_in_field, maximum_col_in_field; _PAGE *pg; T((T_CALLED("Connect_Fields(%p,%p)"), (void *)form, (void *)fields)); assert(form); form->field = fields; form->maxfield = 0; form->maxpage = 0; if (!fields) RETURN(E_OK); page_nr = 0; /* store formpointer in fields and count pages */ for (field_cnt = 0; fields[field_cnt]; field_cnt++) { if (fields[field_cnt]->form) RETURN(E_CONNECTED); if (field_cnt == 0 || (fields[field_cnt]->status & _NEWPAGE)) page_nr++; fields[field_cnt]->form = form; } if (field_cnt == 0 || (short)field_cnt < 0) RETURN(E_BAD_ARGUMENT); /* allocate page structures */ if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0) { T((T_CREATE("_PAGE %p"), (void *)pg)); form->page = pg; } else RETURN(E_SYSTEM_ERROR); /* Cycle through fields and calculate page boundaries as well as size of the form */ for (j = 0; j < field_cnt; j++) { if (j == 0) pg->pmin = (short) j; else { if (fields[j]->status & _NEWPAGE) { pg->pmax = (short) (j - 1); pg++; pg->pmin = (short) j; } } maximum_row_in_field = fields[j]->frow + fields[j]->rows; maximum_col_in_field = fields[j]->fcol + fields[j]->cols; if (form->rows < maximum_row_in_field) form->rows = (short) maximum_row_in_field; if (form->cols < maximum_col_in_field) form->cols = (short) maximum_col_in_field; } pg->pmax = (short) (field_cnt - 1); form->maxfield = (short) field_cnt; form->maxpage = (short) page_nr; /* Sort fields on form pages */ for (page_nr = 0; page_nr < form->maxpage; page_nr++) { FIELD *fld = (FIELD *)0; for (j = form->page[page_nr].pmin; j <= form->page[page_nr].pmax; j++) { fields[j]->index = (short) j; fields[j]->page = (short) page_nr; fld = Insert_Field_By_Position(fields[j], fld); } if (fld) { form->page[page_nr].smin = fld->index; form->page[page_nr].smax = fld->sprev->index; } else { form->page[page_nr].smin = 0; form->page[page_nr].smax = 0; } } RETURN(E_OK); }