CATALOGO/CSTRINGS.CPP
2021-09-03 17:43:05 +02:00

121 lines
3.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

///////////////////////////////////////////////////////////////////////////
///// Nombre: Cstrings.CPP ///
///// Modulo: Perteneciente a Catalogo.C ///
//// Descripci¢n: Utilidades para el manejo de Strings... ///
//// ///
//// Autor: Jos David Guilln Dominguez ///
//// Fecha: 20 - 07 - 1994 ///
//// ///
//// Compilador Borland C++ 3.0 ///
///////////////////////////////////////////////////////////////////////////
#include <graphics.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <stdio.h>
extern void Sound_SN(char headfile[]);
extern int sb; /* Indica si esta instalada la SB (def. NO) */
int InputCadenaG(char *s, int numalp, int lmax, int px, int py, int cc, int cf);
int InputCadenaG(char *s, int numalp, int lmax, int px, int py, int cc, int cf)
{
char buf[81]; // Buffer de linea
int ls; // longitud cadena
char *s1; // puntero a cadena inicial
int i, c, ok;
s1 = s; // inicio cadena
setcolor(cf); // pone color a 0 para borrar
for (i=0; i<lmax; i++) // limpia linea para imprimir
outtextxy( ( px + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
outtextxy( ( px ) * 8 - 7, py * 16 - 16, s );
ls = strlen ( s ); // Longitud de actual
if ( ls < lmax ) {
setcolor(4);
outtextxy( ( px + ls ) * 8 - 7, py * 16 - 16, "þ");
}
s += ls; // se coloca en el final
do{
c = getch(); // obtiene tecla
ok = ( c == 13 || c == 0); // 13 = INTRO || Especiales
if ( c == 8 && ls > 0 && !ok ) { // 8 = Back Space
ls--;
s--;
setcolor(cf);
outtextxy( (px + ls) * 8 - 7, py * 16 - 16, "Û");
if ( ls + 1 < lmax ) outtextxy( ( px + ls + 1 ) * 8 - 7, py * 16 - 16, "Û");
setcolor(4);
outtextxy( (px + ls) * 8 - 7, py * 16 - 16, "þ");
setcolor(cc);
} else {
if ( !numalp && c >= 32 && c <= 254 /* isprint(c) */ && ls < lmax) {
*s++ = c;
ls++;
*s = '\0'; // Cero final
setcolor(cf); // pone color a 0 para borrar
for (i=0; i<lmax; i++) // limpia linea para imprimir
outtextxy( ( px + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
outtextxy( (px) * 8 - 7, py * 16 - 16, s1 );
if ( ls < lmax ) {
setcolor(4);
outtextxy( ( px + ls ) * 8 - 7, py * 16 - 16, "þ");
}
} else {
if ( numalp && isdigit(c) && ls < lmax) {
*s++ = c;
ls++;
*s = '\0'; // Cero final
setcolor(cf); // pone color a 0 para borrar
for (i=0; i<lmax; i++) // limpia linea para imprimir
outtextxy( ( px + i ) * 8 - 7, py * 16 - 16, "Û");
setcolor(cc); // devuelve el color a su estado
outtextxy( (px) * 8 - 7, py * 16 - 16, s1 );
if ( ls < lmax ) {
setcolor(4);
outtextxy( ( px + ls ) * 8 - 7, py * 16 - 16, "þ");
}
} else if (!ok && sb) Sound_SN("catalog3");
}
}
}while(!ok);
*s = '\0';
while(kbhit()) getch(); // Vacia Buffer impidiendo falsas
// pulsaciones...
return ls;
}