Subject: HELP on INFORMIX 4GL & FORMS (termcap) From: Mike Aubury Date: Fri, 03 May 96 17:41:09 [...] I've only tested it under linux..... ---------------------CUT HERE ---------------------------------------- #include #include char getcc(char *dispstr,char *bf); char keycode[100][10]; FILE *fout; enum keys { PGUP, ENTER, PGDN, LEFT, RIGHT, UP, DOWN, F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20 ,F21,F22,F23, F24, INSERT,DELETE,HOME,END, KP0,KPDOT,KPENT,KP1,KP2,KP3,KP4,KP5,KP6,KP7,KP8,KP9 }; int minstr(char *bf,char ch); int xcol; int lines; main(int argc,char *argv[]) { int cnt1,cnt2; char a; if (argc!=2) { printf("Error: Usage %s new_tcap_file\n",argv[0]); exit(0); } fout=fopen(argv[1],"r"); if (fout!=0) { printf("File exists - better safe than sorry so exiting\n"); exit(0); } fclose(fout); fout=fopen(argv[1],"w"); /* Start of with the easy stuff */ printf("\n\nGen-Termcap (c) 1996 Aubit Computing Ltd\n"); printf("\nFor internal use only-may not be sold\n"); dispdisplay(); } char getcc(char *dispstr,char *bf) { char a; while (1) { if (a!=10 && a!=13) printf(dispstr); a=getc(stdin); if (a==10||a==13) continue; if (minstr(bf,a)) return a; printf("%c",7); if (strlen(dispstr)>0) printf("Invalid Reponse!(%d)\n",a); } } minstr(char *bf,char ch) { int cnt; for (cnt=0;cnt<=strlen(bf);cnt++) { if (bf[cnt]==ch) return 1; } return 0; } dispdisplay() { int a,b,c; int cnt; int pos1,pos2,pos3; char code1[4]; char code2[4]; char code3[4]; char teststr[4]; char yn; #define NUMCHARS 26+1 /* for the NULL */ char buff[NUMCHARS]={"abcdefghijklmnopqrstuvwxyz"}; char buffer[20000]; char str[80]; while(1) { printf("This program will now display a series of lines, you will have to enter\n"); printf("the three digit code at the top left,top right, and bottom left\n"); printf("Eg. if the following was your screen.\n"); printf("+-----------+\n"); printf("|aabaaciaada|\n"); printf("|aeaafaagaah|\n"); printf("|aaiaajaakaa|\n"); printf("|PROMPT: +\n"); printf("+-----------+\n"); printf("You would enter 'aab' for Top Left\n"); printf("You would enter 'ada' for Top Right\n"); printf("You would enter 'aai' for Bottom Right\n"); printf("Note:These would be entered as aab,ada,aai\n"); printf("Press any key to continue\n"); getc(stdin); cnt=0; for (a=0;a (eg, aab,ada,aai) :"); gtla(code1); gtla(code2); gtla(code3); yn=getcc("\nThese are the codes I have - proceed (Y/N/Abort)","YNyn"); getc(stdin); if (yn=='N' || yn=='n') {continue;} if (yn=='A' || yn=='a') {printf("Ok - aborting\n");exit(1);} pos1=-1; pos2=-1; pos3=-1; printf("Total of %d codes\n",cnt); for (a=0;a:",keycode[PGUP]); getkey("Press the PGDN key :",keycode[PGDN]); getkey("Press the LEFT key :",keycode[LEFT]); getkey("Press the RIGHT key :",keycode[RIGHT]); getkey("Press the UP key :",keycode[UP]); getkey("Press the DOWN key :",keycode[DOWN]); getkey("Press the INSERT key :",keycode[INSERT]); getkey("Press the HOME key :",keycode[HOME]); getkey("Press the END key :",keycode[END]); getkey("Press the DELETE (not backspace!) key :",keycode[DELETE]); printf("\n\n\nPlease make sure that Num Lock is OFF!!!\n\n\n"); /* getkey("Press the INS/0 (on numeric keypad) key :",keycode[KP0]); getkey("Press the DEL/. (on numeric keypad) key :",keycode[KPDOT]); getkey("Press the Enter (on numeric keypad) key :",keycode[KPENT]); getkey("Press the 1/End (on numeric keypad) key :",keycode[KP1]); getkey("Press the 2/Down (on numeric keypad) key :",keycode[KP2]); getkey("Press the 3/Pg Down (on numeric keypad) key :",keycode[KP3]); getkey("Press the 4/Left (on numeric keypad) key :",keycode[KP4]); getkey("Press the 5 (on numeric keypad) key :",keycode[KP5]); getkey("Press the 6/Right (on numeric keypad) key :",keycode[KP6]); getkey("Press the 7/Home (on numeric keypad) key :",keycode[KP7]); getkey("Press the 8/Up (on numeric keypad) key :",keycode[KP8]); getkey("Press the 9/PgUp (on numeric keypad) key :",keycode[KP9]); */ yn=getcc("Do you have more than 12 Function Keys ? (YN)","YyNn"); getc(stdin); for (a=1;a<=24;a++) { printf("Key : %d\n",a); if (a<=12 || yn=='Y' || yn=='y') sprintf(str,"Press the F%d key :",a); else sprintf(str,"Press the SHIFT-F%d key :",a-12); printf("************************************\n"); getkey(str,keycode[F1+a-1]); /*dodgey*/ } printf("OK\n"); getcc("Press Y to continue\n","yY"); printf("Writing definition\n"); fprintf(fout,"aubit|full_name|morename|evenmorename:\\\n"); fprintf(fout," co#%d:li#%d:\\\n",xcol,lines); fprintf(fout," do=%s:up=%s:le=%s:kr=%s:\\\n",keycode[DOWN],keycode[UP],keycode[LEFT], keycode[RIG HT]); fprintf(fout," kP=%s:kN=%s:kH=%s:@7=%s:\\\n",keycode[PGUP],keycode[PGDN],keycode[END] ,keycode [END]); fprintf(fout," K4=%s:K5=%s:k1=%s:K2=%s:\\\n",keycode[END],keycode[PGDN],keycode[HOME] ,keycode[ PGUP]); fprintf(fout," kI=%s:kD=%s:kh=%s:kl=%s:\\\n",keycode[INSERT],keycode[DELETE],keycode[ HOME],keyc ode[LEFT]); fprintf(fout," k1=%s:k2=%s:k3=%s:k4=%s:\\\n",keycode[F1],keycode[F2],keycode[F3],keyc ode[F4]); fprintf(fout," k5=%s:k6=%s:k7=%s:k8=%s:\\\n",keycode[F5],keycode[F6],keycode[F7],keyc ode[F8]); fprintf(fout," k9=%s:k0=%s:F1=%s:F2=%s:\\\n",keycode[F9],keycode[F10],keycode[F11],ke ycode[F12]); fprintf(fout," F3=%s:F4=%s:F5=%s:F6=%s:\\\n",keycode[F13],keycode[F14],keycode[F15],k eycode[F16]); fprintf(fout," F7=%s:F8=%s:F9=%s:FA=%s:\\\n",keycode[F17],keycode[F18],keycode[F19],k eycode[F20]); fprintf(fout," FB=%s:FC=%s:FD=%s:FE=%s:\\\n",keycode[F21],keycode[F22],keycode[F23],k eycode[F24] ); fclose(fout); printf("Done\n"); } gtla(char *buff) { int cnt=0; char buffer[80]; for (cnt=0;cnt<3;cnt++) {buffer[cnt]=getcc("","abcdefghijklmnopqrstuvwxyz");} buffer[3]=0; printf("[%s] ",buffer); strcpy(buff,buffer); } getkey(char *str,char *buff) { char b2[40]; printf("%s",str); b2[0]=0; b2[1]=0; b2[2]=0; b2[3]=0; b2[4]=0; b2[5]=0; b2[6]=0; b2[7]=0; b2[8]=0; b2[9]=0; gets(b2); tcapprint(buff,b2); /*printf("%x %x %x %x %x %x %x %x %x %x\n",b2[0],b2[1],b2[2],b2[3],b2[4],b2[5],b2[6],b2[7],b2[8],b2[9]);*/ } tcapprint(char *sbuff,char *buff) { int a; char b2[40]; b2[0]=0; sbuff[0]=0; if (strlen(buff)==0) sprintf(b2,"\\n"); for (a=0;a0 && buff[a]<=26) sprintf(b2,"^%c",buff[a]+'a'-1); if (buff[a]==27) sprintf(b2,"\\E"); if (buff[a]==0) sprintf(b2,"\\0"); if (b2[0]==0) sprintf(b2,"%c",buff[a]); strcat(sbuff,b2); b2[0]=0; } printf("%s\n",sbuff); } ------------------------------------AND HERE----------------------- -- Mike Aubury _\?/_ |O O| +----------oOOO-\_/-OOOo---------+-----------------------------+ | Heisenberg may have been here | mike@aubury.demon.co.uk | | | http://www.flash.net/~aubit | +--------------------------------+-----------------------------+