TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Frank Adam
date: 1996-04-10 00:46:00
subject: [1/6] Formlib

>>> Part 1 of 6...

/* Form.c by Frank Adam, 1996.
** Anyone care for a form handling routine ? here it is.
** It's pretty easy to follow even without docs,so i didn't make any:)
** Compiled on TC2, but should work on others without too many mods.
** Any comments,suggestions welcome, just remember this is a public echo:)
** Keymapping and some other stuff is designed for a project of mine , so 
** it may not please some ppls brainbuds, but feel free to change them. 
** Sorry about the rather compacted code, but it grew a bit big. */
*/

#include "form.h"

#define TEST
#ifdef TEST

struct form *Ftest;
char *titles[] = {" Name :","Age :","Addr
1:","Addr 2:","Phone :"};
int fx[] = {10,60,10,10,10};
int fy[] = {10,10,12,14,16};
int fl[] = {20,3,40,40,18};
int ft[] = {FSTRING,FDIGIT,FSTRING,FSTRING,FNUMERIC};
char *help[] = {
  "Enter your name (ascii)",
  "Enter your age (digits)",
  "Enter your street address (ascii)",
  "Enter your locality (ascii)",
  "Enter your phone number (XXX)XXXX-XXXX (numeric)"
  };

main()
{
 int fail = 0,change = FORMFALSE,i;

 fail = init_form(Ftest,"MY FORM",WHITE,RED,CYAN,BLACK,5);
 if(fail == FORMNOMEM) return 1;
 fail = init_form_fields(Ftest,titles,BLACK,RED,WHITE,LIGHTGRAY,&fx[0],
    &fy[0],&fl[0],&ft[0]);
 if(fail == FORMNOMEM) return 1;
 fail = init_form_help(Ftest,help,5,22,BLACK,LIGHTGREEN);
 if(fail == FORMNOMEM) return 1;

 form_show(Ftest);                 /* Let's see the form */
 change = get_form_input(Ftest,0); /* Start editing... */
 fast_clrscr(); fast_gotoxy(1,1);
 printf("FTEST :");
 if(change == FORMTRUE) /* if the data was changed in the form */
 {
  for(i = 0;imaxfields;i++)
printf("\n%s",get_FORM_data(Ftest,i));
  }
 else printf("Nothing entered");

formfree(Ftest); /* Only important if your programs use memory :) */
return 0;
}
#endif

int init_form(struct form* &f_f,char* title,int tfore,int tback,int ffore,
       int fback,int numfields)
{
 f_f = (struct form*) calloc(sizeof(struct form),1);
 if(!f_f) return FORMNOMEM;

 f_f->formtitle = (char*) malloc(strlen(title)+1);
 if(!f_f->formtitle) return FORMNOMEM;
 strcpy(f_f->formtitle,title);
 f_f->formattrib = fast_setattrib(ffore,fback);
 f_f->titattrib = fast_setattrib(tfore,tback);
 f_f->havedata = FORMFALSE;
 f_f->maxfields = numfields;
 return FORMTRUE;
}

int init_form_fields (struct form* f_f,char **titles,int tfore,int tback,
       int ffore,int fback,int fx[],int fy[],int fl[],
       int tp[] )
{
 int count = 0;

 f_f->fieldtitattrib = fast_setattrib(tfore,tback);
 f_f->fieldattrib = fast_setattrib(ffore,fback);
 while(count maxfields)
 {
   f_f->fieldx[count] = fx[count];
   f_f->fieldy[count] = fy[count];
   f_f->fieldlen[count] = fl[count];
   f_f->fieldtype[count] = tp[count];
  f_f->fieldtitles[count] = (char*) malloc(strlen(titles[count])+1);
  if(!f_f->fieldtitles[count]) return FORMNOMEM;
  strcpy(f_f->fieldtitles[count],titles[count]);
  f_f->data[count] = (char*) malloc(fl[count]+1);
  if(!f_f->fieldtitles[count]) return FORMNOMEM;
  sprintf(f_f->data[count],"%*c",fl[count],' ');
  count++;
  }
return FORMTRUE;
}

int init_form_help(struct form* f_f,char **htxt,int hx,int hy,
     int hfore,int hback)
{
 int count = 0;
 while(count maxfields)
 {
  f_f->helptext[count] = (char*) malloc(strlen(htxt[count])+1);
  if(!f_f->helptext[count]) return FORMNOMEM;
  strcpy(f_f->helptext[count],htxt[count]);
  count++;
  }
 f_f->helpx = hx;
 f_f->helpy = hy;
 f_f->helpattrib = fast_setattrib(hfore,hback);
return FORMTRUE;
}

void form_show(struct form* f_f)
{
 int count = 0;int tempx,tempy;char temptitle[80];
 Attrib = f_f->formattrib;
 fast_clrscr();
 if(f_f->formtitle)
 {

 >>> Continued to next message...
___ Blue Wave/DOS v2.21

--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)
SEEN-BY: 50/99 78/0 620/243 623/630 632/349 635/503 544 727 711/401 409 410
SEEN-BY: 711/413 430 808 809 932 934 712/515 713/888 714/906 800/1 7877/2809
@PATH: 635/544 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.