From d577d991b97ae2b5ee1af23641bcffc3f83af5b2 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 4 Nov 2009 11:56:41 -0800 Subject: Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux. --- iup/src/iup_scanf.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100755 iup/src/iup_scanf.c (limited to 'iup/src/iup_scanf.c') diff --git a/iup/src/iup_scanf.c b/iup/src/iup_scanf.c new file mode 100755 index 0000000..f8ef97b --- /dev/null +++ b/iup/src/iup_scanf.c @@ -0,0 +1,200 @@ +/** \file + * \brief IupScanf implementation. + * + * See Copyright Notice in "iup.h" + */ + +#include +#include +#include +#include + +#include "iup.h" + +#include "iup_predial.h" +#include "iup_str.h" +#include "iup_assert.h" + + +#define ALLOC(n,t) ((t *)calloc((n),sizeof(t))) +#define REQUIRE(b) {if (!(b)) goto cleanup;} + +int IupScanf (const char *format, ...) +{ + int i; + int fields_out_count=(-1); /* return code if not error (error < 0) */ + int error=(-1); /* return code if error (error >= 0) */ + int fields_in_count; + int *width=NULL; + int *scroll=NULL; + char **prompt=NULL; + char **text=NULL; + char *title=NULL; + char *s=NULL; + char *s1=NULL; + char *outf=NULL; + va_list va; + + iupASSERT(format!=NULL); + if (!format) + return 0; + + fields_in_count=iupStrCountChar(format,'\n')-1; + REQUIRE(fields_in_count>0); + width=ALLOC(fields_in_count, int); + REQUIRE(width!=NULL); + scroll=ALLOC(fields_in_count, int); + REQUIRE(scroll!=NULL); + prompt=ALLOC(fields_in_count, char *); + REQUIRE(prompt!=NULL); + text=ALLOC(fields_in_count, char *); + REQUIRE(text!=NULL); + + va_start(va,format); + REQUIRE ((s1=s=(char *)iupStrDup(format)) != NULL); + title=iupStrCopyUntil(&s,'\n'); + REQUIRE(title!=NULL); + for (i=0; i0); + + fields_out_count=0; + va_start(va,format); + s=strchr(format,'\n')+1; + for (i=0; i