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

📄 test.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
   INTERNAL_CHAR *t = buf+start ;
   if (type == COLORIZE_ASM) {
    sr = ASM_keywordList ;
    size = sizeof(ASM_keywordList)/sizeof(KEYLIST) ;
    preproc = '%' ;
   }
   while (t->ch && xchars > 0) {
      while (t->ch && t->color == commentColor && xchars >0)
        t++, xchars-- ;
      if (xchars > 0 &&  (t == buf || !keysym(t[-1].ch) && (keysym(t->ch) || t->ch == preproc))) {
        int len ;
        KEYLIST *p = matchkeyword(sr,size,preproc,t,&len,type == COLORIZE_ASM) ;
        if (p) {
            Colorize(buf,t-buf,len,*p->color,FALSE) ;
            t += len ;
            xchars -= len ;
        } else
            t++,xchars-- ;
      } else
        t++,xchars-- ;
	}

	for (i=0; i < chars; i++)
      if (buf[start+i].color != commentColor)
         if (isdigit(buf[start+i].ch)) {
            if (!backalpha(buf,start+i-1)) {
               int j = i ;
               char c = buf[start+i++].ch ;
               if (type == COLORIZE_C) {
                    if (isdigit(buf[start+i].ch) || (hexflg |= (buf[start+i].ch == 'x' && c == '0'))) {
                      i++ ;
                      while (isdigit(buf[start+i].ch) || hexflg && isxdigit(buf[start+i].ch)) 
                         i++ ;
                    }
               } else {
                  while (isxdigit(buf[start+i].ch))
                    i++ ;
                  if (buf[start+i].ch != 'H' && buf[start+i].ch != 'h') {
                    i = j ;
                    while (isdigit(buf[start+i].ch))
                        i++ ;
                  } else
                    i++ ;
               }    
               hexflg = FALSE ;
               Colorize(buf,start+j,i-j,numberColor,FALSE) ;
               i-- ;
            }
         } else
            if ((buf[start+i].ch == '"' || buf[start+i].ch == '\'') &&
                  (buf[start+i-1].ch != '\\' ||buf[start+i-2].ch == '\\')) {
               int ch = buf[start+i].ch ;
               int j = i++ ;
               while (buf[start+i].ch && (buf[start+i].ch != ch && buf[start+i].ch != '\n' || buf[start+i-1].ch =='\\' && buf[start+i-2].ch != '\\' )&& i < chars)
                  i++ ;
               Colorize(buf,start+j+1,i-j-1,stringColor,FALSE) ;
            }
            
				
}
/**********************************************************************
 * FormatBuffer colorizes comments over a range of text, 
 * then calls SearchKeywords to colorize keywords
 **********************************************************************/
static void FormatBuffer(INTERNAL_CHAR *buf, int start, int end, int type)
{
    if (type == COLORIZE_C) {
      INTERNAL_CHAR *t=buf+start ;
      int type ;
      INTERNAL_CHAR *t1 ;
      t1 = strpstr(t,"//",end - (t- buf)) ;
      while (t1) {
         t = strpstr(t1,"\n",-1) ;
         if (!t) {
            t = t1 + strplen(t1) ;
         }
         Colorize(buf,t1-buf,t-t1+1,commentColor,TRUE) ;
         t1 = strpstr(t,"//",end - (t- buf)) ;
      }
      t = buf + start ;
      while (TRUE) {
         t1 = strpstr(t,"/*",end - (t- buf)) ;
         if (t1) {
            t = strpstr(t1+2,"*/",-1) ;
            if (!t)
               t = t1 + strplen(t1) ;
            else {
               t += 2 ;
            }
            Colorize(buf,t1-buf,t - t1,commentColor, TRUE) ;
         } else
            break ;
      }
    } else if (type == COLORIZE_ASM) {
      INTERNAL_CHAR *t=buf+start ;
      int type ;
      INTERNAL_CHAR *t1 ;
      t1 = strpstr(t,";",end - (t- buf)) ;
      while (t1) {
         t = strpstr(t1,"\n",-1) ;
         if (!t) {
            t = t1 + strplen(t1) ;
         }
         Colorize(buf,t1-buf,t-t1+1,commentColor,TRUE) ;
         t1 = strpstr(t,";",end - (t- buf)) ;
      }
    }
    SearchKeywords(buf,end-start,start,type) ;
}
static void FormatBufferFromScratch(INTERNAL_CHAR *buf, int start, int end, int type)
{
   int xend, xstart ;
      xend = end ;
      if (start < 0)
         start = 0 ;
      xstart = start ;
      while (xstart && (buf[xstart-1].ch != '\n' || buf[xstart-1].color == commentColor))
			xstart -- ;
#ifdef OLD_EDIT_FORMAT
      while (buf[xend].ch && buf[xend].ch != '\r')
#else
      while (buf[xend].ch && (buf[xend].ch != '\n' || buf[xend].color == commentColor))
#endif
			xend++ ;

      Colorize(buf,xstart,xend-xstart,textColor,FALSE) ;
      FormatBuffer(buf,xstart,xend,type) ;
}
/**********************************************************************
 * FormatLine is an optimized colorizer that just colorizes the current
 * line
 **********************************************************************/

static void FormatLine(HWND hwnd, INTERNAL_CHAR *buf, int type)
{
      int start, end;
		SendMessage(hwnd, EM_GETSEL, (WPARAM) &start,(LPARAM) &end) ;
      FormatBufferFromScratch(buf,start,start,type) ;

}
/**********************************************************************
 * GetWordFromPos is a utility to find out what the word under the
 * cursor is, and various information about it
 **********************************************************************/
int GetWordFromPos(HWND hwnd, char *outputbuf, int charpos, int *linenum, int *startoffs, int *endoffs)
{
   int linepos ;
   int linecharpos ;
   int linecharindex ;
   char buf[1000] ;   
   charinfo charrange ;
   if (charpos == -1) {
      SendMessage(hwnd,EM_EXGETSEL,(WPARAM) 0, (LPARAM) &charrange) ;
      charpos = charrange.min ;
   }
   linepos = SendMessage(hwnd,EM_EXLINEFROMCHAR,0,(LPARAM)charpos) ;
   linecharindex = SendMessage(hwnd, EM_LINEINDEX,linepos,0) ;
   linecharpos = charpos - linecharindex;
   *(short *)buf = 1000 ;
   SendMessage(hwnd,EM_GETLINE,linepos,(LPARAM)buf) ;
   outputbuf[0] = 0 ;
   while (linecharpos && (buf[linecharpos] == ' ' || buf[linecharpos] == '\n' || buf[linecharpos] == '\t' || buf[linecharpos] == 0)) 
      linecharpos-- ;
   {
      char *start = buf + linecharpos, *end = start ;
      if (start > buf) {
         start -- ;

         if (start == buf) {
            if (!keysym(*start))
               start++ ;
         } else while (start > buf) {
            if (!keysym(*start)) {
               start++ ;
               break ;
            }
            start--;
         }
         if (!keysym(*start))
            start++ ;
      }
      while (*end && keysym(*end))
         end++ ;
      *end = 0 ;
      if (start > end)
         start = end ;
      if (linenum)
         *linenum = linepos ;
      if (startoffs)
         *startoffs = start - buf + linecharindex ;
      if (endoffs)
         *endoffs = end - buf + linecharindex ;
      strcpy(outputbuf,start) ;
      return TRUE ;
   }
   return FALSE ;
}
/**********************************************************************
 * DoHelp handles the F1 key functionality - it gets the word under the
 * cursor then tries a lookup from the favorite help engine.  Again this
 * is kind of linked to the rest of CCIDE
 **********************************************************************/

static void DoHelp(HWND edwin)
{
   char buf[256] ;   
   if (!GetWordFromPos(edwin,buf,-1,0,0,0)) 
      return ;
   else
      ShowHelp(buf) ;
}
/**********************************************************************
 * RunToolTip starts the tooltip running when the cursor moves
 **********************************************************************/
static void RunToolTip(EDITDATA *p, HWND edwin,int x, int y)
{
   static int semaphore ;
   static POINT oldpt ;
   int charpos ;
   int linepos ;
   int left, right ;
   int start, end ;
   TOOLINFO t ;
   POINT pt,lpt,rpt ;

   pt.x = x ;
   pt.y = y ;

   if (pt.x == oldpt.x && pt.y == oldpt.y)
      return ;
   if (semaphore)
      return ;
   semaphore = TRUE ;

   oldpt = pt ;

   if (p->ttup) {
      SendMessage(p->tooltip,TTM_ACTIVATE,FALSE,0) ;
      p->ttup = FALSE ;
   }
   if (uState == notDebugging || uState == Running) {
      semaphore = FALSE ;
      return ;
   }
#ifdef XXXXX
   if (p->ttrect.left <= x && p->ttrect.right > x && p->ttrect.top <= y &&
         p->ttrect.bottom > y) {
      semaphore = FALSE ;
      return ;
   }
#endif
   charpos = SendMessage(edwin,EM_CHARFROMPOS,0,(LPARAM)&pt) ;
   if (GetWordFromPos(edwin,p->ttident,charpos,&linepos,&start,&end)) {
      p->ttup = TRUE ;
      p->ttlineno = linepos + 1 ;
      memset(&t,0,sizeof(t)) ;
      t.cbSize = sizeof(TOOLINFO) ;
      t.hwnd = edwin ;
	  t.uFlags = 0 ;
      t.uId = 10000 ;
	  t.rect.left = x - 8 ;
     t.rect.right = x + 8 ;
	  t.rect.top = y ;
	  t.rect.bottom = y+ p->txtFontHeight ;
     SendMessage(p->tooltip,TTM_NEWTOOLRECT,0,(LPARAM)&t) ;
     SendMessage(p->tooltip,TTM_ACTIVATE,TRUE,0) ;
   }
   semaphore = FALSE ;
}
/**********************************************************************
 * relays a mouse event to the tooltip
 **********************************************************************/
void RelayToolTipEvent(EDITDATA *p, HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	MSG msg ;
	memset(&msg,0,sizeof(msg)) ;
	msg.hwnd = hwnd ;
	msg.message = iMessage ;
	msg.wParam = wParam ;
	msg.lParam = lParam ;
//   GetCursorPos(&msg.pt) ;
	SendMessage(p->tooltip,TTM_RELAYEVENT,0,(LPARAM)&msg) ;
}

/**********************************************************************
 * getundo creates an UNDO structure based on the user's last operation
 **********************************************************************/
UNDO *getundo(EDITDATA *p, int type)
{
   int x  ;
   UNDO *u ;
   if (p->undoing)
      return 0 ;
   if (type != UNDO_DELETESELECTION && type != UNDO_INSERTSELECTION && type != UNDO_CASECHANGE && type != UNDO_INSERTINDENT && type != UNDO_DELETEINDENT && p->undohead != p->undotail) {
      x = p->undohead-1 ;
      if (x < 0) x+= UNDO_MAX ;
      if (p->undolist[x].type == type)
         if (type != UNDO_BACKSPACE) {
            if (p->selstartcharpos == p->undolist[x].postselstart)
               return &p->undolist[x] ;
         } else {
            if (p->selstartcharpos+1 == p->undolist[x].postselstart)
               return &p->undolist[x] ;
         }
   }
   u = &p->undolist[p->undohead] ;
   if (++p->undohead >= UNDO_MAX)
      p->undohead = 0 ;
   if (p->undohead == p->undotail)
      if (++p->undotail >= UNDO_MAX)
         p ->undotail = 0 ;
   u->len = 0 ;
   u->preselstart = p->selstartcharpos ;
   u->preselend = p->selendcharpos ;
   u->modified = p->modified ;
   p->modified = TRUE ;
   u->type = type ;
   return u ;
}
/**********************************************************************
 * undo_deletesel gets the undo structure for a CUT operation
 **********************************************************************/
UNDO *undo_deletesel(EDITDATA *p)
{
   UNDO *u ;
   int start,end ;
   int i = 0 ;
   if (p->selstartcharpos == p->selendcharpos)
      return 0 ;
   u = getundo(p,UNDO_DELETESELECTION) ;

   if (!u)
      return u ;
   if (p->selstartcharpos < p->selendcharpos) {
      start = p->selstartcharpos ;
      end = p->selendcharpos ;
   } else {
      start = p->selendcharpos ;
      end = p->selstartcharpos ;
   }
   if (end - start > u->max) {
      char *temp = realloc(u->data,end-start) ;
      if (!temp)
         return 0 ;
      u->data = temp ;
      u->max = end - start ;
   }
   u->len = end - start ;
   while (start < end) {
      u->data[i++] = p->text[start++].ch ;
   }
   return u ;
}    
UNDO *undo_casechange(EDITDATA *p)
{
   UNDO *x = undo_deletesel(p) ;
   x->type = UNDO_CASECHANGE ;
   return x ;
}
/**********************************************************************
 * undo_insertsel gets the undo structure for an operation which pasts
 **********************************************************************/
UNDO *undo_insertsel(EDITDATA *p, char *s)
{
   UNDO *u = getundo(p,UNDO_INSERTSELECTION) ;
   if (!u)
      return u ;
   u->len = strlen(s) ;
   return u ;  
}
/**********************************************************************
 * undo_deletechar gets the undo structure for a character deletion
 **********************************************************************/
UNDO *undo_deletechar(EDITDATA *p, int ch, int type)
{
   UNDO *u = getundo(p,type) ;
   if (!u)
      return u ;
   if (u->max <= u->len) {
      char *temp = realloc(u->data,u->max + 64) ;
      if (!temp)
         return 0 ;
      u->data = temp ;
      u->max += 64 ;
   }
   memmove(u->data+1,u->data,u->len++) ;
   u->data[0] = ch ;
   u->postselstart = p->selstartcharpos ;
   u->postselend = p->selendcharpos ;
   return u ;  
}
/**********************************************************************
 * undo_deletechar gets the undo structure for typing over a character
 **********************************************************************/
UNDO *undo_modifychar(EDITDATA *p)

⌨️ 快捷键说明

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