⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mains.c

📁 坦尼保姆
💻 C
📖 第 1 页 / 共 3 页
字号:
            if(cmdchar == '!') cmdchar = (symtab[symp].symsect <3) ? 'x' : 'd';}	 else { adre=dotlnarr[(PC)-1]; cmdchar = c; if(c=='\n') c = '?'; }/* Note: (PC)-1. The next instruction initial byte is fetched before the dump*/  if(cmdchar=='\n') cmdchar = 'S';   instrcount = 0X7fffffff; bprdepth = -1;   if(cmdchar == '!') cmdchar = (symtab[symp].symsect <3) ? 'x' : 'd';   if((cmdchar < 5) || (cmdchar > 126)) cmdchar =  'q' ;    switch(cmdchar) {	case 'q' : fprintf(stderr,"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); exit(0); break;	case 'r' : instrcount = 0X7fffffff; break;	case '-' : bprdepth = prdepth-1; break;	case '+' : bprdepth = prdepth+1; break;	case '=' : bprdepth = prdepth; stopvlag = 1; break;	case '!' : nulbp(adre); break;	case 'g' : /*sprintf(errbuf,"g %d",adre); erroutine();*/nulbp(adre); break;	case 0xc : 	case 'R' : refresh(); rdcmd();break;	case 'd' : if(symtab[symp].symsect > 2) dmpadr(adre); 			else {sprintf(errbuf,"Cannot dump this label");				erroutine();} dump(); break;	case 'b' : zetbp(lndotarr[adre]); rdcmd() ; break;	case 'c' : clearbp(lndotarr[adre]); rdcmd(); break;	case 'n' : nulbp(dotlnarr[lndotarr[dotlnarr[(PC-1)]+1]]); break;	case 'x' : case 'X': case '*': instrcount = adre; break;	default : stopvlag = 255;    } }rdstrg(){  int i,j,stradr,k,syk;  char *p,*q,c,cc;  i=0; p = cmdline; q = tringfield+90;  while(c = *p++) if (c=='!' || c == '/' || c == '+') break;		  else {i++; *q++ = c;}  if((c=='/') && (*p != '+')) *(--p) = '0';  *q = '\0';#ifdef DEBUGlogprint(); fprintf(LOG,"gelezen: string |%s|\n",tringfield+90);#endif  stradr = hashstring(tringfield+90); symp = symhash[stradr];  if(i>8) i=8; syk = -1;  while(symp != -1) {#ifdef DEBUGfprintf(LOG,"Vergeleken: string |%s| symtab |%s| symp %2d i %2d\n",tringfield+900,symtab[symp].symbol,symp,i);#endif    /*if(!strncmp(tringfield+90, symtab[symp].symbol,i)) { syk = symp; break;}    else {symp = symtab[symp].nextsym;}*/    if(!strncmp(tringfield+90, symtab[symp].symbol,i)) { syk = symp;      if(i==strlen(symtab[symp].symbol)) break; }    symp = symtab[symp].nextsym;  }  symp = syk;  /*april*/  if(symp < 0) {sprintf(errbuf,"No Match"); erroutine(); return(-1);}  for(k=0;k<18;k++) tringfield[k+90] = ' '; tringfield[98] = '+';  for(k=0;k<8;k++) if((cc = symtab[symp].symbol[k])>32) tringfield[k+90] = cc;	else break;#ifdef DEBUG fprintf(LOG,"tringfield: |%s|\n",tringfield+90); logprint();#endif  if(symtab[symp].symsect > 2) stradr = symtab[symp].symvalue;  else if(symtab[symp].symsect == 2) stradr = symtab[symp].lnr;  j = -1; if(c == '\0' || c=='!') {cmdchar = '!'; j=0; }  if(j) {    while(*p =='+' || *p == '\t' || *p == ' ') p++;    if(*p == '\0' || *p=='!') {cmdchar = '!'; j=0;}  }  if(j){    if(*p<'0'||*p>'9'){sprintf(errbuf,"cmd constant expected.");erroutine();	system("sleep 1");sprintf("%-55.55s","  ");return(-1);}    sscanf(p,"%d%1s",&j,&cmdchar);  }  if(symtab[symp].symsect == 2){if(cmdchar == '!') cmdchar = 'g'; sprintf(tringfield+99,"%2d",j);}  else  {if(cmdchar == '!')cmdchar = 'd'; sprintf(tringfield+99,"%-4d=%04x:",j,(stradr+j));}  return(stradr+j);}rdadr(){  int i;  sscanf(cmdline,"%d%1s",&i,&cmdchar);  if((cmdchar == '!') && (symtab[symp].symsect == 2)) cmdchar = 'g';  return(i);}rdcline(c){  char *p;  p = cmdline;  while(c != '\n') {if (c==EOF) break; *p++ = c; c = getchcmd();}  *p++ = '\0'; *p = '\0';  sprintf(window[14],"%-18.18s",cmdline);  p--; *p = '!';}winupdate(){ int i,j,k,l; char *p,*q; sprintf(window[0]+4,"%02x",cs&0Xffff); sprintf(window[0]+18,"%03x",ds&0Xffff); sprintf(window[1]+3,"%02x",ah); sprintf(window[1]+9,"%02x",al); sprintf(window[1]+15,"%6d",ax); sprintf(window[2]+3,"%02x",bh); sprintf(window[2]+9,"%02x",bl); sprintf(window[2]+15,"%6d",bx); sprintf(window[3]+3,"%02x",ch); sprintf(window[3]+9,"%02x",cl); sprintf(window[3]+15,"%6d",cx); sprintf(window[4]+3,"%02x",dh); sprintf(window[4]+9,"%02x",dl); sprintf(window[4]+15,"%6d",dx); sprintf(window[5]+4,"%04x",sp&0Xffff); sprintf(window[6]+4,"%04x",bp&0Xffff); sprintf(window[7]+4,"%04x",si&0Xffff); sprintf(window[8]+4,"%04x",di&0Xffff); sprintf(window[7]+13,"%04x:PC",(PC)-1);/* Note: (PC)-1. The next instruction initial byte is fetched before the dump*/ sprintf(window[8]+10,"           ");#ifdef DEBUG/*fprintf(stderr,"Tot hier dotlinarr %d PC %d\n",dotlnarr[(PC)-1],(PC)-1);*/fprintf(LOG,"Tot hier dotlinarr %d PC %d\n",dotlnarr[(PC)-1],(PC)-1);#endif  i = dotlnarr[(PC)-1]; j = lnsymarr[i];  if(j>nsymtab-3) {	fprintf(stderr,"\nNo BSS or no head label?\n",j,nsymtab-3,i);#ifdef DEBUG	fprintf(LOG,"Warning lnsymarr %d nsymtab %d entry %d\nNo BSS or no head label?\n",j,nsymtab-3,i);#endif	system("sleep 2"); refresh(); /*exit(1);*/  } sprintf(window[8]+10,"%s+%1d",symtab[j].symbol,i-symtab[j].lnr); window[6][12] = (ovf) ? 'v' : '-'; window[6][14] = (dirf) ? '<' : '>'; window[6][16] = (signf) ? 'n' : 'p'; window[6][18] = (zerof) ? 'z' : '-'; window[6][20] = (cf) ? 'c' : '-'; for(j=0;j<9;j++){	fseek(L,(int)lnfilarr[i+j-6],0); p=window[j]+32;gtabstr(48,p,L);} for(i=0;i<4;i++) for(j=0;j<58;j++) window[15-i][j+22] = outveld[i][j]; for(i=0;i<7;i++) sprintf(window[17+i],"%s",datadarr[i]);  l = prdepth; j= (maxsp-sp > 18) ? sp : maxsp-18; j &= 0xffff; p = m+j+(ss<<4);#ifdef DEBUG  fprintf(LOG,"maxsp %d sp %d bp %d sp %x bp %x j %d\n",maxsp,sp,bp,sp,bp,j);fflush (LOG);#endif for(i=0;i<9;i++) { if(j < sp) {p += 2; sprintf(window[i]+23,"      ");}    else {k = *p++ & 255; k |= ((*p++ & 255) << 8); 	if(j==sp) sprintf(window[i]+23,"=>%04x",k);	else sprintf(window[i]+23,"  %04x",k); 	if(j==prstckpos[l]) {window[i][23] = (char)(l+48); l--;}}    j+= 2;}  l = (prdepth>2)? prdepth-2 : 1;  for(i=12;i>9;i--) {  if(l>(int)prdepth) sprintf(window[i],"                   ");  else { j = stckprdepth[l]; k = lnsymarr[j]; 	sprintf(window[i],"%1d <= %-8s + %3d",l,symtab[k].symbol,		j - symtab[k].lnr);	} l++;    }    p = inbuf; q = window[11]+22; *q++ = 'I'; *q++ = ' ';    while (p<inbpu-85) p += 55;    while((j = (int)(*p)) != '\n'){ if(*p =='\0') break;	if((q >= window[11]+75) && (q<window[12])) {*q++ = ' '; *q++ = ' ';		*q++ = ' '; q = window[12]+24; window[12][22] = 'I';}	if(p == inbpu) { *q++ = '-'; *q++ = '>';}	if(j==0 || q>window[12]+75) break; if(j<' ') {*q++ = '^'; j += 64;} *q++ = j;        p++;    }    if(p == inbpu && *p == '\n' ) { *q++ = '-'; *q++ = '>';}    if((inbpu != inbpl) && (*p == '\n')) {*q++ = '\\'; *q++ = 'n';}    if(*(inbpu-1)== '\n') {*q++ = '\\'; *q++ = 'n'; *q++ = '-'; *q++ = '>';}    while(q<window[12]-1) *q++ = ' ';    if(q>window[12]) while(q<window[13]-1) *q++ = ' '; p = window[0]-1; for(i=0;i<1944;i++) if(!(*(++p))) *p = ' '; immain(); wmv(15,0);}gtabstr(i,a,f) int i; char *a; FILE *f;{  int j,c;  j = 0; while(j<i){c = getc(f); if(c==EOF || c == '\r' || c == '\n') break;    if(c=='\t') { if (j%8 != 7) ungetc(c,f); c=' ';}    j++; *a++=c;  } while(j++ <i) *a++ = ' ';  }newgpfield(){  int i,j;  for(i=3;i>0;i--) for(j=0;j<58;j++) outveld[i][j] = outveld[i-1][j];  for(j=0;j<58;j++) outveld[0][j] = ' '; }nextput(c) int c;{  if(c=='\n') {nextput('\\'); nextput('n'); puthp = -1; return;}  if(puthp>57) puthp = -1;     if(puthp < 0) { newgpfield(); puthp = 0;	nextput('>'); nextput(' ');}  if(c<' ') {outveld[0][puthp++] = '^'; c += 64;}  if(c!='\n') outveld[0][puthp++] = c;}getchcmd(){   int i;    if((i= getc(CMD)) !=EOF) {if(i!='\r') return(i); else return(getchcmd());}    if(cmdfl) {fclose(CMD); 	CMD = stdin; cmdfl = 0;  i = getchcmd();}     if(i!='\r') return(i); else return(getchcmd());}getchbp(){   int i;  char *p;  if(inbpl==inbpu) {wmv(11,24);inbpl = inbpu = inbuf;    if(traceflag && !(inpfl)){sprintf(errbuf,"Input expected"); erroutine();	p = inbuf; *p++ = '\n'; *p++ = '\0';	winupdate();wmv(11,24);}    while((i= getc(INP)) !=EOF) { if(i=='\r') continue;	*inbpl++ =i; if(i=='\n') break;}    if(i==EOF) {	if(inpfl>0) {fclose(INP); inpfl = 0; INP=stdin; return(getchbp());}	else if(inpfl) {sprintf(errbuf,"Second time end of input so exit");		erroutine(); exit(0);}	else {fclose(stdin); fopen("/dev/tty","rb"); inpfl--; return(i);}    }  }  return((int)*inbpu++);}meldroutine(){  char *p;   int i,aa;  if(traceflag){   errbuf[11] = ' '; errbuf[12] = ' '; errbuf[13] = ' ';   wmv(10,24); printf("%s",errbuf); system("sleep 1");   wmv(10,78);printf("\n");fprintf(stderr,"\n");   sprintf(window[10]+22,"M %-55.55s",errbuf); winupdate();}  else fprintf(stderr,"%s\n",errbuf);}erroutine(){  char *p;   int i,aa;  if(traceflag){   p = errbuf;aa = 0;for(i=0;i<55;i++) if (*p++ <= '\n'){p--;*p++ = ' ';}   else if(*p ==  '\0' || *p == '\n') aa++;   else if (aa) *p++ = ' ';  *p = '\0';  if (errflag) system("sleep 1");   wmv(10,24);viscursor(); printf("%s",errbuf);inviscur();   wmv(10,78);printf("\n");fprintf(stderr,"");   sprintf(window[10]+22,"E %-55.55s",errbuf); winupdate();errflag = 1;}  else fprintf(stderr,"%s\n",errbuf);}spare(t) word t; { sprintf(errbuf,"8086 undefined instruction %0X",t & 0xff); erroutine();}notim(t) word t; { sprintf(errbuf,"Instruction %0X not implemented",t & 0xff); erroutine();}interrupt(t) int t; { sprintf(errbuf,"Interrupt %0X. Bad division?",t & 0xff); erroutine();}panic(s) char *s; { sprintf(errbuf,"%s",s); erroutine(); system ("sleep 5"); exit(1);}bitmapdump(b,h,buff) int b,h; char *buff;{  if(termbitsize == 2) { if ((bituit=fopen("tERMbITMAP","wb")) == NULL) {	fprintf(stderr,"Kan tERMbITMAP niet openen\n"); exit(1);}  } else { if ((bituit=fopen("tERMbITmAP","wb")) == NULL) {	fprintf(stderr,"Kan tERMbITmAP niet openen\n"); exit(1);}  }  schrijfmap(b,h,termbitsize,buff,bituit);  fclose(bituit);  if(termbitsize == 2) sprintf(bmbuf,".c configure -bitmap @lEEGbITMAP\n");  else sprintf(bmbuf,".c configure -bitmap @lEEGbITmAP\n");  schrijf(); system("sleep 1");  if(termbitsize == 2) sprintf(bmbuf,".c configure -bitmap @tERMbITMAP\n");  else sprintf(bmbuf,".c configure -bitmap @tERMbITmAP\n");  schrijf();  system("sleep 1");} bitmapopen(b,h,s) int b,h,s; {  /*FAKE SYSTEM CALL TO OPEN A BITMAP FOR OPGAVE 1 */  int i;  if(pipe(pfildes)< 0) {fprintf(stderr,"Kan geen pipe creeren\n"); exit(1);}  if((pnr = fork()) < 0) {fprintf(stderr,"Kan niet vorken\n"); exit(1);}  if(pnr == 0){dup2(pfildes[0],0); system("exec /usr/local/bin/wish"); exit(0);}  termbitsize = 1; if(s==2) termbitsize = 2;  if(termbitsize == 2) {    if ((bituit=fopen("lEEGbITMAP","wb")) == NULL) {	fprintf(stderr,"Kan lEEGbITMAP niet openen\n"); exit(1);}  } else {    if ((bituit=fopen("lEEGbITmAP","wb")) == NULL) {	fprintf(stderr,"Kan lEEGbITmAP niet openen\n"); exit(1);}  }  schrijfmap(b,h,termbitsize,bmbuf+800,bituit);  fclose(bituit);  sprintf(bmbuf,"#!/usr/local/bin/wish -f\n. configure -background gray\n");  schrijf();  if (termbitsize == 2) {sprintf(bmbuf,". configure -width 591\n. configure -height 509\n"); schrijf();sprintf(bmbuf,"button .b -text %cexit window %c",'"','"'); schrijf();sprintf(bmbuf,"  -font *-helvetica-bold-r-normal--*-180-* "); schrijf();sprintf(bmbuf," -command %cdestroy .%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .b -x 4 -y 4 -relwidth 0.32 -height 1.1c\n"); schrijf();sprintf(bmbuf,"label .c -bitmap @lEEGbITMAP\nplace .c -x 4 -y 1.4c\n");schrijf();sprintf(bmbuf,"button .d -text %cdisplay new%c ",'"','"'); schrijf();sprintf(bmbuf,"-font *-helvetica-bold-r-normal--*-180-* -command"); schrijf();sprintf(bmbuf," %c.c configure -bitmap @tERMbITMAP%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .d -x 200 -y 4 -relwidth 0.32 -height 1.1c\n"); schrijf();sprintf(bmbuf,"button .e -text %cclear window %c ",'"','"'); schrijf();sprintf(bmbuf,"-font *-helvetica-bold-r-normal--*-180-* -command"); schrijf();sprintf(bmbuf," %c.c configure -bitmap @lEEGbITMAP%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .e -x 396 -y 4 -relwidth 0.32 -height 1.1c\n"); schrijf();  } else {sprintf(bmbuf,". configure -width 302\n. configure -height 266\n"); schrijf();sprintf(bmbuf,"button .b -text %cexit window %c",'"','"'); schrijf();sprintf(bmbuf,"  -font *-helvetica-bold-r-normal--*-120-* "); schrijf();sprintf(bmbuf," -command %cdestroy .%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .b -x 2 -y 3 -relwidth 0.32 -height 0.7c\n"); schrijf();sprintf(bmbuf,"label .c -bitmap @lEEGbITmAP\nplace .c -x 3 -y 0.9c\n");schrijf();sprintf(bmbuf,"button .d -text %cdisplay new%c ",'"','"'); schrijf();sprintf(bmbuf,"-font *-helvetica-bold-r-normal--*-120-* -command"); schrijf();sprintf(bmbuf," %c.c configure -bitmap @tERMbITmAP%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .d -x 101 -y 3 -relwidth 0.32 -height 0.7c\n"); schrijf();sprintf(bmbuf,"button .e -text %cclear window %c ",'"','"'); schrijf();sprintf(bmbuf,"-font *-helvetica-bold-r-normal--*-120-* -command"); schrijf();sprintf(bmbuf," %c.c configure -bitmap @lEEGbITmAP%c\n",'"','"'); schrijf();sprintf(bmbuf,"place .e -x 200 -y 3 -relwidth 0.32 -height 0.7c\n"); schrijf();  }sprintf(bmbuf,".c configure -background black -foreground white\n"); schrijf();sprintf(bmbuf,".b configure -background black -foreground white\n"); schrijf();sprintf(bmbuf,".d configure -background black -foreground white\n"); schrijf();sprintf(bmbuf,".e configure -background black -foreground white\n"); schrijf();  /* system("sleep 1");*/} schrijf(){  int j;  char *p;  p = bmbuf;  j = 0;  while(*p++ > '\0') j++;  write(pfildes[1],bmbuf,j);}  spiegel(m,n) int m,n;{  int i,j,k,l;  if(m == 0) {    i = 1; j = 128; l = 0;    for(k=0;k<8;k++) {if((i&n)>0) l |= j; i <<= 1; j >>= 1;}  } else if (m == 1) {    i = 16; j = 128; l = 0; for(k=0;k<4;k++) {	 if((i&n)>0) l |= j;j >>= 1; if((i&n)>0) l |= j;j >>= 1; i <<= 1;}  } else {    i = 1; j = 128; l = 0; for(k=0;k<4;k++) {	 if((i&n)>0) l |= j;j >>= 1; if((i&n)>0) l |= j;j >>= 1; i <<= 1;}  }  /* if(l>0) fprintf(stderr,"l %x n %x l %d n %d m %d\n",l,n,l,n,m);*/  return(l);} schrijfmap(b,h,s,buf,uitf) int b,h,s; char *buf; FILE *uitf; {  int i,j,k,l,m,c;  char *p,*q;  if(b%8!=0){	fprintf(stderr,"Bitmap breedte hoort een heel aantal bytes te zijn\n");	exit(1);}  fprintf(uitf,"#define noname_width %d\n",b*s);  fprintf(uitf,"#define noname_height %d\n",h*s);  fprintf(uitf,"static char noname_bits[] = {\n ");  p = buf; b >>= 3; k = b*h*s*s-1; m = 1;  for(i=0;i<h;i++) { q = bmbuf; for(j=0;j<b;j++)    if(termbitsize == 2){ c = *p++; *q++ = spiegel(1,c); *q++ = spiegel(2,c);    } else { c = *p++; *q++ = (255 & spiegel(0,c));    }    for(l=0;l<s;l++) {      q = bmbuf; for(j=0;j<b*s;j++) {	fprintf(uitf,"0x%02x",(255 & *q++)); if(k==0) fprintf(uitf,"};\n");	else {putc(',',uitf); if((m % 15) == 0) fprintf(uitf,"\n "); k--; m++;}      }    }  }}extern void prut(u,v) char u,v; {fprintf(stderr,"ah en al  %d %d     %x %x    %o %o\n",	(int)u,(int)v,(int)u,(int)v,(int)u,(int)v);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -