All pastes #559006 Raw Edit

Anonymous

public c v1 · immutable
·published 2007-06-11 16:16 UTC
rendered paste body
#include <stdio.h>#include <conio.h>#include <stdlib.h>#define MAXNIV 7#define MAXOPC 15#define MAXNOM 9#define MAXLIT 41#define MAXCOM 81#define MENUINICIAL "MENU"#define NOMDEF "LOSMENUS.DAT"#define REVERSE 1#define NORMAL 0#define ARRIBA 72#define ABAJO 80#define ESCAPE 27#define ENTER 13#define ANORM 6#define AREVE 38#define ATITU 4char nomb[MAXNIV][MAXNOM];char opci[MAXNIV];char sele[MAXNIV];char lite[MAXNIV][MAXOPC][MAXLIT];char coma[MAXNIV][MAXOPC][MAXCOM];char sigmenu[MAXNOM];char buff[4096];int nivel;void dibuja_opcion(int n,int sel,int atr) {gotoxy(2,2+sel); textattr(atr==REVERSE?AREVE:ANORM);cprintf("%s",lite[n][sel]); textattr(ANORM);}void dibuja_menu(char *tit,int mx,int my,int an,int al,int n) { int i;window(mx,my,mx+an-1,my+al);textattr(ANORM); clrscr();gotoxy(1,1); putch('Ú'); for(i=2;i<an;i++) putch('Ä'); putch('¿');gotoxy(1,al); putch('À'); for(i=2;i<an;i++) putch('Ä'); putch('Ù');for(i=2;i<al;i++) {gotoxy(1,i); putch('³'); gotoxy(an,i); putch('³'); }gotoxy(2,1); textattr(ATITU); cprintf(" %s ",tit); textattr(ANORM);for(i=0;i<=opci[n];i++) dibuja_opcion(n,i,NORMAL); }int procesar_menu(int n) { int menuy,menux,ancho,alto,tec;menuy=n+1; menux=2*n+1; ancho=MAXLIT+2; alto=opci[n]+3;dibuja_menu(n?lite[n-1][sele[n-1]]:"Menu principal",menux,menuy,ancho,alto,n);for(;;) {dibuja_opcion(n,sele[n],REVERSE);tec=getch();if(tec==ESCAPE) { clrscr(); return(-1); }if(tec==ENTER) { if(coma[n][sele[n]][0]=='^') {		     strcpy(sigmenu,&coma[n][sele[n]][1]); return(1); }		     gettext(1,1,80,25,buff);		     system("CLS"); system(coma[n][sele[n]]);		     getch(); puttext(1,1,80,25,buff); continue; }if(tec!=ARRIBA&&tec!=ABAJO) continue;dibuja_opcion(n,sele[n],NORMAL);if(tec==ARRIBA) { sele[n]--; if(sele[n]<0) sele[n]=opci[n]; continue; }/* tec==ABAJO */  sele[n]++; if(sele[n]>opci[n]) sele[n]=0; }}int cargar_menu(char *menu) {FILE *fp; char linea[128]; int est=0,opc=0;if((fp=fopen(NOMDEF,"r"))==NULL) return(1);while(est!=9) {if(fgets(linea,100,fp)==NULL) { strcpy(linea,"@@"); est=8; }else linea[strlen(linea)-1]=0;switch(est) {case 0: if(linea[0]=='@')	if(!strcmp(menu,&linea[1])) { strcpy(nomb[nivel],menu); est=1; } break;case 1: if(linea[0]=='@') { est=8; break; }	strcpy(lite[nivel][opc],linea); strcpy(coma[nivel][opc],""); est=2; break;case 2: if(linea[0]=='@') { est=8; break; }	strcpy(coma[nivel][opc],linea); opc++;	if(opc==MAXOPC) est=8; else est=1; break;case 8: opci[nivel]=opc-1; sele[nivel]=0; est=9; }} fclose(fp); return(!opc); }void cuerpo_programa(char *menu) {int nivel_ant=-1; nivel=0; strcpy(sigmenu,menu);do {if(nivel>nivel_ant) if(cargar_menu(sigmenu)) { nivel--; continue; }nivel_ant=nivel; nivel+=procesar_menu(nivel);if(nivel==MAXNIV) { nivel--; /* OVERFLOW */ }} while(nivel>=0); }void pantalla_inicial() {window(1,1,80,25); textattr(ANORM); clrscr(); }main() {pantalla_inicial();cuerpo_programa(MENUINICIAL);return(0); }