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

📄 x_wrdwindow.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 4 页
字号:
    nparam=0;    params[0]=DEFAULT;    prstbl=csitable;    break;  case CASE_SCR_STATE:    prstbl=scrtable;    mbcs=0;    break;  case CASE_MBCS:    hankaku=0;    prstbl=mbcstable;    mbcs=MBCS;    break;  case CASE_SCS_STATE:    if(mbcs)      prstbl=smbcstable;    else      prstbl=scstable;    break;  case CASE_GSETS:    mywin.curattr=(mbcs)?(mywin.curattr|CATTR_16FONT):      (mywin.curattr&~(CATTR_16FONT));    if(!mbcs){      hankaku=(c=='I')?1:0;    }    prstbl=groundtable;    break;  case CASE_DEC_STATE:    prstbl =dectable;    break;  case CASE_SS2:  case CASE_SS3:    /*These are ignored because this will not accept SS2 SS3 charset*/  case CASE_GROUND_STATE:    prstbl=groundtable;    break;  case CASE_CR:    mywin.curcol=0;    prstbl=groundtable;    break;  case CASE_IND:  case CASE_VMOT:    mywin.curline++;    mywin.curcol=0;    prstbl=groundtable;    break;  case CASE_CUP:    mywin.curline=(params[0]<1)?0:params[0]-1;    if(nparam>=1)      mywin.curcol=(params[1]<1)?0:params[1]-1;    else      mywin.curcol=0;    prstbl=groundtable;    break;  case CASE_PRINT:    if(mywin.curcol==COLS){      mywin.curcol++;      return 1;    }    if(mywin.curattr&CATTR_16FONT){      if(!(mywin.curattr&CATTR_LPART)&&(mywin.curcol==COLS-1)){	mywin.curcol+=2;	return 1;      }      mywin.curattr^=CATTR_LPART;    }    else      mywin.curattr&=~CATTR_LPART;    DelChar(mywin.curline,mywin.curcol);    if(hankaku==1)      c|=0x80;    mywin.scrnbuf[mywin.curline][mywin.curcol].attr=mywin.curattr;    mywin.scrnbuf[mywin.curline][mywin.curcol].c=c;      mywin.curcol++;    break;  case CASE_CUU:    mywin.curline-=((params[0]<1)?1:params[0]);    prstbl=groundtable;    break;  case CASE_CUD:    mywin.curline+=((params[0]<1)?1:params[0]);    prstbl=groundtable;    break;  case CASE_CUF:    mywin.curcol+=((params[0]<1)?1:params[0]);    prstbl=groundtable;    break;  case CASE_CUB:    mywin.curcol-=((params[0]<1)?1:params[0]);    prstbl=groundtable;    break;  case CASE_ED:    switch(params[0]){    case DEFAULT:    case 1:      {	int j;	if(mywin.scrnbuf[mywin.curline]!=NULL)	  ClearLeft();	for(j=0;j<mywin.curline;j++)	  ClearLine(j);	      }      break;    case 0:      {	int j;	if(mywin.scrnbuf[mywin.curline]!=NULL){	  ClearRight();	}	for(j=mywin.curline;j<LINES;j++)	  ClearLine(j);	      }      break;    case 2:      {	int j;	for(j=0;j<LINES;j++){	  free(mywin.scrnbuf[j]);	  mywin.scrnbuf[j]=NULL;	}	mywin.curline=0;	mywin.curcol=0;	break;      }    }    RedrawInject(0,0,SIZEX,SIZEY,False);    prstbl=groundtable;    break;  case CASE_DECSC:    savcol=mywin.curcol;    savline=mywin.curline;    savattr=mywin.curattr;    prstbl=groundtable;  case CASE_DECRC:    mywin.curcol=savcol;    mywin.curline=savline;    mywin.curattr=savattr;    prstbl=groundtable;    break;  case CASE_SGR:    {      int i;      for(i=0;i<nparam+1;i++)	switch(params[i]){	default:	  mywin.curattr&=~(CATTR_COLORED|CATTR_BGCOLORED|CATTR_TXTCOL_MASK);	  break;	case 16:	case 17:	case 18:	case 19:	case 20:	case 21:	case 22:	case 23:	  /* Remap 16-23 into 30-37 */	  params[i] = wrd_color_remap[params[i] - 16] + 30;	  /*FALLTHROUGH*/	case 30:	case 31:	case 32:	case 33:	case 34:	case 35:	case 36:	case 37:	  mywin.curattr&=~CATTR_TXTCOL_MASK;	  mywin.curattr|=(params[i]-30)<<CATTR_TXTCOL_MASK_SHIFT;	  mywin.curattr|=CATTR_COLORED;	  break;	case 40:	case 41:	case 42:	case 43:	case 44:	case 45:	case 46:	case 47:	  mywin.curattr&=~CATTR_TXTCOL_MASK;	  mywin.curattr&=~CATTR_COLORED;	  mywin.curattr|=(params[i]-40)<<CATTR_TXTCOL_MASK_SHIFT;	  mywin.curattr|=CATTR_BGCOLORED;	  break;	}    }    prstbl=groundtable;    break;  case CASE_EL:    switch(params[0]){    case DEFAULT:    case 0:      ClearRight();      break;    case 1:      ClearLeft();      break;    case 2:      ClearLine(mywin.curline);      break;    }    prstbl=groundtable;    break;  case CASE_NEL:    mywin.curline++;    mywin.curcol=0;    mywin.curline=(mywin.curline<LINES)?mywin.curline:LINES;    break;/*Graphic Commands*/  case CASE_MY_GRAPHIC_CMD:    GrphCMD(params,nparam);    prstbl=groundtable;    break;/*Unimpremented Command*/  case CASE_ICH:  case CASE_IL:  case CASE_DL:  case CASE_DCH:  case CASE_DECID:  case CASE_DECKPAM:  case CASE_DECKPNM:  case CASE_HP_BUGGY_LL:  case CASE_HTS:  case CASE_RI:  case CASE_DA1:  case CASE_CPR:  case CASE_DECSET:  case CASE_RST:  case CASE_DECSTBM:  case CASE_DECREQTPARM:  case CASE_OSC:  case CASE_RIS:  case CASE_HP_MEM_LOCK:  case CASE_HP_MEM_UNLOCK:  case CASE_LS2:  case CASE_LS3:  case CASE_LS3R:  case CASE_LS2R:  case CASE_LS1R:    ctl->cmsg(CMSG_INFO,VERB_VERBOSE,"NOT IMPREMENTED:%d\n",prstbl[c]);    prstbl=groundtable;    break;  case CASE_BELL:  case CASE_IGNORE:  default:    break;  }  return 0;}void AddLine(const unsigned char *str,int len){  Linbuf *ptr;  int i,j;  /*Initialize Redraw rectangle Manager*/  RedrawInject(-1,-1,-1,-1,False);    /*Allocate LineBuffer*/  if(len==0)    len=strlen(str);  for(i=0;i<len;i++){    if(mywin.scrnbuf[mywin.curline]==NULL){      ptr=(Linbuf *)calloc(COLS,sizeof(Linbuf)+1);      if(ptr==NULL)	exit(-1);      else	mywin.scrnbuf[mywin.curline]=ptr;    }    /*     * Proc Each Charactor     * If >0 Returned unput current value     */    if(Parse(str[i])!=0){      i--;    }    /*Wrapping Proc*/    while(mywin.curcol>=COLS+1){      mywin.curcol-=COLS;      mywin.curline++;    }    while(mywin.curcol<0){      mywin.curcol+=COLS;      mywin.curline--;    }    /*Scroll Proc*/    mywin.curline=(mywin.curline<0)?0:mywin.curline;    while(mywin.curline>=LINES){      mywin.curline--;      free(mywin.scrnbuf[0]);      mywin.scrnbuf[0]=NULL;      for(j=1;j<LINES;j++){	mywin.scrnbuf[j-1]=mywin.scrnbuf[j];      }      mywin.scrnbuf[LINES-1]=NULL;      RedrawInject(0,0,SIZEX,SIZEY,False);    }  }  RedrawInject(0,0,0,0,True);}void WinFlush(void){  if(mywin.redrawflag)    XFlush(mywin.d);}/* *This Function Dumps Charactor Screen buffer status *Purely Debugging Purpose this code should be desabled  *if you need not. */#ifdef SCREENDEBUGDebugDump(void){  FILE *f;  int i,j;  f=fopen("screen","w+");  for(i=0;i<LINES;i++){    fprintf(f,"LINE %d \n",i);    for(j=0;j<COLS;j++){      if(mywin.scrnbuf[i]!=NULL){	Linbuf *a=&mywin.scrnbuf[i][j];	fprintf(f,"{%x %c}",a->attr,a->c);      }    }   fprintf(f,"\n");  }  fclose(f);}#endifvoid WinEvent(void){  XEvent e;  int rdx1, rdy1, rdx2, rdy2;   rdx1 = rdy1 = rdx2 = rdy2 = -1;  XSync(mywin.d, False);  while(QLength(mywin.d)>0){    XNextEvent(mywin.d,&e);    switch(e.type){    case ButtonPress:      Redraw(0,0,SIZEX,SIZEY);      rdx1=0;      rdy1=0;      rdx2=SIZEX;      rdy2=SIZEY;      if(e.xbutton.button==3){#ifdef SCREENDEBUG	DebugDump();#endif      }    }  }    if(rdx1 != -1){    Redraw(rdx1, rdy1, rdx2 - rdx1, rdy2 - rdy1);    XFlush(mywin.d);  }}void EndWin(void){  if(mywin.d!=NULL)  {    if(truecolor && shm_screen)      free_image_pixmap(shm_screen);    XCloseDisplay(mywin.d);    free(image_buffer);  }  mywin.d=NULL;}  int OpenWRDWindow(char *opt){    if(InitWin(opt) == -1)    {	ctl->cmsg(CMSG_ERROR, VERB_NORMAL,		  "WRD: Can't open WRD window becase of error");	return -1;    }    XMapWindow(mywin.d, mywin.w);    XSync(mywin.d, False);    return 0;}void CloseWRDWindow(void){    if(mywin.d != NULL)    {	XUnmapWindow(mywin.d, mywin.w);	XSync(mywin.d, False);    }}static void free_image_pixmap(ImagePixmap *ip){    XFreePixmap(mywin.d, ip->pm);#if XSHM_SUPPORT    if(ip->shminfo.shmid != -1)    {	/* To destroy a shard memory XImage, you should call XShmDetach()	 * first.	 */	XShmDetach(mywin.d, &ip->shminfo);	/* Unmap shared memory segment */	shmdt(ip->shminfo.shmaddr);	/* Remove a shared memory ID from the system */	shmctl(ip->shminfo.shmid, IPC_RMID, NULL);    }#endif /* XSHM_SUPPORT */    if(ip->im != NULL)      XDestroyImage(ip->im);    free(ip);}#if XSHM_SUPPORTstatic int shm_error;static int my_err_handler(Display* dpy, XErrorEvent* e){    shm_error = e->error_code;    ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,	      "Warning: X WRD Warning: Can't create SHM Pixmap. error-code=%d",	      shm_error);    return shm_error;}static ImagePixmap *create_shm_image_pixmap(int width, int height){    XErrorHandler origh;    ImagePixmap *ip;    int shm_depth;    shm_depth = theDepth;    ip = (ImagePixmap *)safe_malloc(sizeof(ImagePixmap));    shm_error = 0;    origh = XSetErrorHandler(my_err_handler);    /* There is no need to initialize XShmSegmentInfo structure     * before the call to XShmCreateImage.     */    ip->im = XShmCreateImage(mywin.d, theVisual, theDepth,			     ZPixmap, NULL,			     &ip->shminfo, width, height);    if(ip->im == NULL)    {	if(shm_error == 0)	    shm_error = -1;	goto done;    }    /* allocate n-depth Z image data structure */    ip->im->data = (char *)safe_malloc(ip->im->bytes_per_line *				       ip->im->height);    /* The next step is to create the shared memory segment.     * The return value of shmat() should be stored both     * the XImage structure and the shminfo structure.     */    ip->shminfo.shmid = shmget(IPC_PRIVATE,			       ip->im->bytes_per_line * ip->im->height,			       IPC_CREAT | 0777);    if(ip->shminfo.shmid == -1)    {	ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		  "X Sherry Warning: Can't create SHM Pixmap.\n"		  "shmget: %s", strerror(errno));	XDestroyImage(ip->im);	ip->im = NULL;	shm_error = -1;	goto done;    }    ip->shminfo.shmaddr = ip->im->data =	(char *)shmat(ip->shminfo.shmid, NULL, 0);    if(ip->shminfo.shmaddr == (void *)-1)    {	ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		  "X Sherry Warning: Can't create SHM Pixmap.\n"		  "shmget: %s", strerror(errno));	shmctl(ip->shminfo.shmid, IPC_RMID, NULL);	XDestroyImage(ip->im);	ip->im = NULL;	shm_error = -1;	goto done;    }    /* If readOnly is True, XShmGetImage calls will fail. */    ip->shminfo.readOnly = False;    /* Tell the server to attach to your shared memory segment. */    if(XShmAttach(mywin.d, &ip->shminfo) == 0)    {	if(shm_error == 0)	{	    ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		      "X Sherry Warning: Can't create SHM Pixmap.\n"		      "Can't attach to the shared memory segment.");	    shm_error = -1;	}	shmdt(ip->shminfo.shmaddr);	shmctl(ip->shminfo.shmid, IPC_RMID, NULL);	XDestroyImage(ip->im);	ip->im = NULL;	goto done;    }    XSync(mywin.d, False);		/* Wait until ready. */    ip->pm = XShmCreatePixmap(mywin.d, mywin.w, ip->im->data,			      &ip->shminfo, width, height, shm_depth);    if(ip->pm == None)    {	if(shm_error == 0)	{	    ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,		      "X Sherry Warning: Can't create SHM Pixmap.\n"		      "XShmCreatePixmap() is failed");	    shm_error = -1;	}	shmdt(ip->shminfo.shmaddr);	shmctl(ip->shminfo.shmid, IPC_RMID, NULL);	XDestroyImage(ip->im);	ip->im = NULL;	goto done;    }  done:    XSetErrorHandler(origh);    if(ip->im == NULL)    {	free(ip);	return NULL;    }    return ip;}#endif

⌨️ 快捷键说明

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