🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1810

gcgets - Turbo C fun. to read strings in grafix

#1810
From: Steve Resnick
Date: Wed, 08 Aug 1990 00:32
91 lines
2888 bytes
For those of you who requested my post of gcgets, here it is!
Bear in mind this was written for a specific application and there
are some short-comings to it, but the general idea is expressed.

   -------<Cut Here>---------------------------------<Cut Here>--------------
/* gcgets (C) Copyright 1990 Steve Resnick
*/
gcgets(int Xstart, int Ystart, char * buffer, int size)
{
	char *tmp, *start;
	char CurBuf[512];
	int i, c, x, y, Hue, curx, cury;
	x = Xstart; y = Ystart;
	curx = x; cury = y+(textheight("[")-2);
	if ((tmp = calloc(size,1)) == NULL)
	{
		restorecrtmode();
		perror("Cannot allocate memory for console I/O!");
		exit(0);
	}
	start = tmp;
	for ( i = 0; i < (size - 1); )
	{
		Hue = getcolor();
		setcolor(8);
		getimage(curx,cury,curx+10,cury,CurBuf);
		line(curx,cury,curx+10,cury);
		c = getch();
		putimage(curx,cury,CurBuf,COPY_PUT);
		setcolor(Hue);
		switch(c)
		{
			case 0 :
				getch();
				break ;
			case 27:
				*buffer = 0;
				free(start);
				return(0);
			case 13:
				strncpy(buffer,start,size);
				free(start);
				return(strlen(buffer));
			case  8:
				if ((tmp - 1) >= start)
				{
					x-=8;
					setcolor(CYAN);
					gprintf(x,y,"[");
					setcolor(15);
					i-- ;
					*tmp-- = 0;
					*tmp = 0;
				}
				else
				{
					sound(2500);
					delay(10);
					nosound();
				}
				break ;
			default :		
				gprintf(x,y,"%c",c);
				x+=8;
				*tmp++ = c;
				i ++ ;
		}
		curx =  Xstart + textwidth(start);
	}
	strncpy(buffer,start,size);
	free(start);
	return(strlen(buffer));
}
/* This was taken and hacked from the BGIDEMO program */
int gprintf( int xloc, int yloc, char *fmt, ... )
{
  va_list  argptr;			/* Argument list pointer	*/
  char str[140];			/* Buffer to build sting into	*/
  int cnt;				/* Result of SPRINTF for return */
  va_start( argptr, format );		/* Initialize va_ functions	*/
  cnt = vsprintf( str, fmt, argptr );	/* prints string to buffer	*/
  outtextxy( xloc, yloc, str );		/* Send string in graphics mode */
  va_end( argptr );			/* Close va_ functions		*/
  return( cnt );			/* Return the conversion count	*/
}

-- 
----------------------------------------------------------------------------
steve.resnick@f105.n143.z1@FIDONET.ORG #include<std_disclaimer.h>
Flames, grammar errors, spelling errrors >/dev/nul
----------------------------------------------------------------------------
Technical Details
Message-ID: <1990Aug8.003246.26901@Octopus.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!decwrl!nsc!pyramid!octopus!stever

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!decwrl!nsc!pyramid!octopus!stever
From: stever@Octopus.COM (Steve Resnick )
Newsgroups: comp.os.msdos.programmer
Subject: gcgets - Turbo C fun. to read strings in grafix
Message-ID: <1990Aug8.003246.26901@Octopus.COM>
Date: 8 Aug 90 00:32:46 GMT
Reply-To: stever@octopus.COM (Steve Resnick )
Organization: Octopus Enterprises, Cupertino CA
Lines: 91