/******************************************************************** * $Author: jgoerzen $ * $Revision: 1.3 $ * $Date: 2001/01/17 21:48:05 $ * $Source: /var/cvs/gopher/gopher/form.c,v $ * $State: Exp $ * * Paul Lindner, University of Minnesota CIS. * * Copyright 1991, 92, 93, 94 by the Regents of the University of Minnesota * see the file "Copyright" in the distribution for conditions of use. ********************************************************************* * MODULE: form.c * Form definition and management functions ********************************************************************* * Revision History: * $Log: form.c,v $ * Revision 1.3 2001/01/17 21:48:05 jgoerzen * Many fixes and tune-ups. Now compiles cleanly with -Wall -Werror! * * Revision 1.2 2001/01/03 22:28:24 s2mdalle * Code cleanups, compiler warning fixes * * Revision 1.1.1.1 2000/08/19 00:28:56 jgoerzen * Import from UMN Gopher 2.3.1 after GPLization * * Revision 3.9 1995/11/03 21:18:17 lindner * ANSIfication * * Revision 3.8 1995/05/01 03:42:48 lindner * Fixes for NetBSD * * Revision 3.7 1994/07/03 23:10:57 lindner * fix forms.. * * Revision 3.6 1994/05/19 14:07:24 lindner * use fast malloc on VMS VAXC * * Revision 3.5 1994/04/01 02:24:56 lindner * Fix return types * * Revision 3.4 1994/03/08 15:55:05 lindner * gcc -Wall fixes * * Revision 3.3 1994/03/04 23:39:50 lindner * Fix for log entries * * Revision 3.2 1994/03/04 23:36:32 lindner * bug fixes. * * Revision 3.1 1994/02/20 16:15:44 lindner * New form definition and management functions * * *********************************************************************/ #include "form.h" #include "String.h" #include "GSgopherobj.h" #include "BLblock.h" #include "Malloc.h" #include "CURcurses.h" #include "gopher.h" /** Make a new item... **/ ITEM * ITEMnew(void) { ITEM *temp; temp = (ITEM*) malloc(sizeof(ITEM)); temp->type = ITEM_UNINIT; temp->label = STRnew(); temp->response = STRnew(); temp->chooseitem = -1; temp->choices = STAnew(3); return(temp); } /* * Clear out a specific item */ void ITEMinit(ITEM *item) { item->type = ITEM_UNINIT; STRinit(item->label); STRinit(item->response); STAinit(item->choices); item->chooseitem=0; } /* * Copy an item */ ITEM* ITEMcpy(ITEM *dest, ITEM *orig) { dest->type = orig->type; STRset(dest->label, STRget(orig->label)); STRset(dest->response, STRget(orig->response)); dest->chooseitem = orig->chooseitem; STAcpy(dest->choices, orig->choices); return(dest); } /* * Nuke a defined ITEM */ void ITEMdestroy(ITEM *item) { STRdestroy(item->label); STRdestroy(item->response); STAdestroy(item->choices); free(item); } /* * Add an item to the list of choices.. */ void ITEMpushChoice(ITEM *item, char *choice) { String *str; str = STRnew(); STRset(str, choice); STApush(item->choices, str); STRdestroy(str); } /************************************************************************* * Form definition routines.. Pretty swanky.. */ FORM* FORMfromASK(GopherObj *gs) { int Asknum; Blockobj *bl; char askline[256]; char *defaultval; #if 0 int i; char ** responses = NULL; ITEM *item; #endif /* 0 */ FORM *form; GSgetginfo(gs, TRUE); bl = GSfindBlock(gs, "ASK"); if (bl == NULL) return(NULL); form = FORMnew(BLgetNumLines(bl)); for (Asknum=0; Asknum maxpromptwidth) maxpromptwidth = strlen(ITEMgetPrompt(item)); } if (totalprompts != 0 && (totalprompts % pagesize) == 0) numforms ++; } if (numforms > 1) numprompts = pagesize; else numprompts = totalprompts; if (numprompts == 0) { return(-1); } maxlength -= (maxpromptwidth+1); tempwin = newwin(6 + numprompts, COLS-2, (LINES-(6+numprompts))/2,1); CURwenter(cur,tempwin); while (currentform < numforms) { if (currentform == (numforms-1)) { numprompts = totalprompts - (pagesize * currentform); } else { numprompts = pagesize ; } wstandend(tempwin); CURbox(cur,tempwin, 6+numprompts, COLS-2); currentfield = 0; /*** Add the window title, centered ***/ if (Wintitle != NULL) { /** Trim window title to fit in the window **/ if (strlen(Wintitle) > COLS-2) { strncpy(TrimmedTitle, Wintitle, COLS-2); TrimmedTitle[COLS-5] = '.'; TrimmedTitle[COLS-4] = '.'; TrimmedTitle[COLS-3] = '.'; TrimmedTitle[COLS-2] = '\0'; } else strcpy(TrimmedTitle, Wintitle); /** Put the title, bold **/ wmove(tempwin, 0,(COLS -2 - strlen(TrimmedTitle))/2); wstandout(tempwin); waddstr(tempwin, TrimmedTitle); wstandend(tempwin); } /** Add the prompts and typing area **/ for (i=0; i