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

📄 basic4.c

📁 用C语言写的YABasic解释器
💻 C
📖 第 1 页 / 共 2 页
字号:
       rect.x = client.x;
       rect.y = client.y;
       rect.width = client.width;
       rect.height = client.height;
       SysSetFontLib(SYSFONT_GBK16);
       hListBox = GuiListCreateEx((UInt8*)Null,0,&rect,0,ofListNoStorage,FileCount+1,1,10);
       if (hListBox==(UInt8*)Null) return;
       colinfo.width = rect.width;
       colinfo.format = ListDataFormat_Text;
       GuiListAddCol(hListBox, &colinfo);
       GuiGroupInsert((MView *)hListBox, (MGroup *)hBasicWnd);
       if (*pBasicFileName!=0)
               CurLine = BasicQuickFind(pBasicFileName);
       else if (CurLine==0||CurLine==FileCount) CurLine = 0;
       GuiListSetCurrentLine(hListBox,CurLine);
}

FAR void BasicFileFind()
{
       char *ptemp;
       int i;
       Boolean done;
       StructFileFind  bffblk;
       char  *temp_file;
       
       temp_file = GetAllocBuf();
       Strcpy(temp_file,pBasicFileName);
       Memset(pInBuf,0,BUFFERPROGRAM); 	
       i = 0;
       ptemp = pInBuf;
       done = FileFindFirst(&bffblk,_Far("*.bsc"));
       FileCount = -1;
       while (done)
       {
     	      Memset(pBasicFileName,0,20);
     	      Strncpy(pBasicFileName,bffblk.szFileName,Strlen(bffblk.szFileName)-4);
     	      Strncpy(ptemp+i,pBasicFileName,10);
              i += 10;
              FileCount++;
              done = FileFindNext(&bffblk);
       }
       BasicFileSort(0,FileCount);
       Strcpy(pBasicFileName,temp_file);       
}

FAR void CreateBasicFileSaveWindow(char flag)
{
	UInt16 edit_style;
	UInt8  style_win, *hEditWnd1, *hBmp;
	char *title_buf, *line_buf;
	MRect client,rect;
	MEditParam pEditParam;
	MEvent pEvent;
	
	title_buf = GetAllocBuf();
	line_buf = GetAllocBuf();
			
	rect.x = 0;
	rect.y = 0;
	rect.width = LcdGetWidth();
	if (!flag)
	     rect.height = LcdGetHeight() - 16;
	else
	     rect.height = LcdGetHeight();
        style_win = wsBoundType0 | wsTitleArea | wsHelp;
        hBasicWnd = GuiWindowCreate((UInt8 *)Null, 0, &rect, style_win, _Far("Basic编程"), IDH_BASIC_01, 0);
        GuiWindowGetClientArea(hBasicWnd, &client);
        rect.x = client.x + 32;
#ifdef	__IQ688__
        rect.y = client.y + 32;
#else
        rect.y = client.y + 16;
#endif        
        rect.width = client.width - 32;
        rect.height = 16;
        edit_style = EDS_ENABLE|EDS_VISIBLE;
        pEditParam.dwHandle = NullID;
	pEditParam.dwCaption = NullID;
        pEditParam.wAllowChar = EDITALLOW_ALL;
        pEditParam.wFirstChar = EDITALLOW_ASCII;
        SysSetFontLib(SYSFONT_GBK12);
        if (Lastcurrent_mode == EDITMODE)
        {
        	pEvent.type = evCommand;
	        pEvent.x = cmSetCursorLast;
	        MsgPost(&pEvent);
        }
        else 
                *pOutBuf = 0;        
        hMainEdit = GuiEditCreate((UInt8*)Null,0,&rect,edit_style,pOutBuf,(UInt16)9,0,0,&pEditParam);                
        rect.x = client.x;
#ifdef __IQ688__
        rect.y = client.y + 16;
#else
        rect.y = client.y;
#endif   
        rect.width = client.width;
        Strcpy(title_buf,"请输入文件名:");
        hEditWnd1 = GuiEditCreate((UInt8*)Null,0,&rect,edit_style,title_buf,(UInt16)15,0,0,&pEditParam);
        
        rect.x = client.x + 32;
#ifdef __IQ688__
        rect.y = client.y + 48;
#else
        rect.y = client.y + 32;
#endif
        rect.width = 70;		
	rect.height = 1;
	hBmp = GuiLabelCreate((UInt8*)Null, 768, &rect, ofIconStyle|ofResource, IDB_AP_UNDERLIN);	
	GuiGroupInsert((MView *)hBmp, (MGroup *)hBasicWnd);
        GuiGroupInsert((MView *)hMainEdit, (MGroup *)hBasicWnd);
        GuiGroupInsert((MView *)hEditWnd1,(MGroup *)hBasicWnd);
        GuiSetState(hMainEdit, sfFocused);
        GuiSoftKBSetCurrent(IMEnglish,False);
}

void Freedstack(Data_List *d)
{
	Data_List *t,*q;
	while (d!=(Data_List*)Null) {
        	t = d; 
        	q = t;
        	while (t->next!=(Data_List*)Null) {
        		q = t;
        		t = t->next;
        	}
        	if (t!=q) q->next = (Data_List*)Null;
        	else  d = (Data_List*)Null;
        	if (t->data!=(char*)Null)
        	          MemFree(t->data);
        	MemFree((Int8 *)t);
        }	 
}

void Freeostack(Op_List *o)
{
	Op_List *t1,*q1;
        while (o->cod!=0) {
        	t1 = o; 
        	q1 = t1;
        	while (t1->next!=(Op_List*)Null) {
        		q1 = t1;
        		t1 = t1->next;
        	}
        	if (t1!=q1) { 
        		q1->next = (Op_List*)Null; 
        		MemFree((Int8*)t1); 
        	}
        	else  
        	        o->cod = 0;        	                        
        }
        MemFree((Int8*)o);        		
}

FAR void FreeOpMem()
{         
         Do_List *dltemp, *fdltemp;                  
         
         while (dl!=(Do_List *)Null) {
         	dltemp = dl;
         	fdltemp = dl;
         	while (dltemp->next!=(Do_List*)Null) {
         		fdltemp = dltemp;
         		dltemp = dltemp->next;
         	}
         	if (fdltemp!=dltemp) 
         	        fdltemp->next = (Do_List*)Null;
         	else 
         	        dl = (Do_List*)Null;
         	Freedstack(dltemp->fd); 
         	Freeostack(dltemp->od);
         	MemFree((Int8*)dltemp);                  	
         }         
}

int BasicFastSort(int i, int j)
{	
	char *key, *ptemp;
	int ii,jj;
	ii = i;
	jj = j;
	ptemp = pInBuf;
	key = TmpOut;
	Strncpy(key,ptemp+(UInt16)(ii*10),10);	
	while (ii<jj) {		
		while (ii<jj&&Stricmp(ptemp+(UInt16)(jj*10),key)>0) 
		       jj--;
		if (ii<jj) 
		       Strncpy(ptemp+(UInt16)(ii*10),ptemp+(UInt16)(jj*10),10);		
		while (ii<jj&&Stricmp(ptemp+(UInt16)(ii*10),key)<0) 
		       ii++;
		if (ii<jj) 
		       Strncpy(ptemp+(UInt16)(jj*10),ptemp+(UInt16)(ii*10),10);
	}
	Strncpy(ptemp+(UInt16)(ii*10),key,10);		
	return ii;	
}

FAR void BasicFileSort(int f, int l)
{
	 int m;
	 if (f<l) {
	 	m = BasicFastSort(f,l);
	 	BasicFileSort(f,m-1);
	 	BasicFileSort(m+1,l);
	 }
}

FAR void exec_eof(char *v, char *result)
{
      fsnode *q; 
      int i;
      UInt32 len;
      char tend;
      UInt32 curPos;
      
      i = atoi(v+1);      
      q = fl;
      while (q) {
	    if (q->filenum==i) break;
	    else q = q->next;
      }
      *result++ = BOOL_TYPE;
      curPos = FileTell(q->handle);      
      len = FileRead(q->handle,_Far(&tend),1);
      if (len==0) *result++ = '1';
      else {
      	        *result++ = '0';
                FileSeek(q->handle,curPos,FILESEEK_BEGIN);         
      }
      *result = 0;
}

FAR UInt8 IsInteger(char *value_ptr)
{
	char *dot_pos, *dot_tmp;
	
	if (*value_ptr==INTEGER_TYPE) 
	{
		if (atoi(value_ptr + 1)==0) Strcpy(value_ptr + 1,"0");
		return 1;
	}
	if (*value_ptr==REAL_TYPE)
	{
		if ((dot_pos = Strchr(value_ptr,'.'))==(char*)Null) {
			if (atoi(value_ptr + 1)==0) Strcpy(value_ptr + 1,"0");
			return 1;
		}
		else
		{
			dot_tmp = value_ptr + Strlen(value_ptr) - 1;
			while (*dot_tmp=='0') dot_tmp--;
			if (*dot_tmp=='.') {
				*dot_tmp = 0;
				if (*(dot_tmp-1)=='0'&&*(dot_tmp-2)=='-') {
					*(dot_tmp-2)= '0'; 
					*(dot_tmp-1)= 0;
			        }
				return 1;
			}
			else 
				*(dot_tmp+1) = 0;							
		}
	}
	return 0;
}




FAR void exec_right()
{
       char *value, *llen, *p, *temp, *exp_buf;
       int stop, j;
       
       llen = GetAllocBuf();     
       value = GetAllocBuf();
       prog++;
       get_exp(value);       
       if (*value!=STRING_TYPE) serror(19);          /***Right语句出现语法错误***/
       if (*prog==',')
               prog++;
       else
               serror(19);       
       p = prog;
       while (*p!=')'&&*p!=0x0d&&!Strchr(":,;#",*p)) p++;
       if (*p!=')') serror(19);
       exp_buf = GetAllocBuf();
       *p = 0;
       Strcpy(exp_buf,prog);
       *p = ')';
       p = prog;
       prog = exp_buf;       
       get_exp(llen);
       prog = p + Strlen(exp_buf) + 1;        
       if (Strchr(llen,'-')||!IsInteger(llen)) serror(19);        
       p = value + 1; 
       stop = atoi(llen+1);
       j = 0;
       while (*p!=0)
       {
       	      if ((UInt8)*p>=0x80) p += 2;
       	      else p += 1;
       	      j++;
       }
       stop = j - stop;
       if (stop<=0) 
       {
       	     Strcpy(token,value+1);
       	     return;
       }
       p = value + 1;
       j = 0;
       while (j < stop)
       { 
       	      if ((UInt8)*p>=0x80) p += 2;
       	      else p += 1;
       	      j++;       	     
       }
       Strcpy(token,p)       
}

FAR void exec_left()
{
       char *value, *llen, *p, *temp, *exp_buf;
       int stop, j;
       
       llen = GetAllocBuf();
       value = GetAllocBuf();
       prog++;
       get_exp(value);
       if (*value!=STRING_TYPE) serror(20);   /***Left语句出现语法错误***/
       while (*prog==0x20&&*prog==0x09) prog++;
       if (*prog==',')
              prog++;
       else 
              serror(20); 
       p = prog;
       while (*p!=')'&&*p!=0x0d&&!Strchr(":,;#",*p)) p++;
       if (*p!=')') serror(20);
       exp_buf = GetAllocBuf();
       *p = 0;
       Strcpy(exp_buf, prog);
       *p = ')';
       p = prog;
       prog = exp_buf;
       get_exp(llen);
       prog = p + Strlen(exp_buf) + 1;       
       if (Strchr(llen,'-')||!IsInteger(llen)) serror(20);        
       stop = atoi(llen+1);
       j = 0;
       p = value+1;
       *token = 0; 
       temp = token;
       while ( j++ < stop && *p != 0 ) 
       {
       	     *temp++ = *p++;
       	     if ((UInt8)*(p-1) >= 0x80) *temp++ = *p++;
       }
       *temp = 0;
}



/*
FAR void exec_rset()
{
     char *flag, *var, *value, *s1, *s2;
     bitnode *p;
     int i,j;
     get_token(0); 
     flag=get_token_last();
     if (flag!=(char*)Null&&*flag!='$') serror(0);
     if (flag!=(char*)Null) *flag='\0';
     if ((var=(char *)MemAlloc(strlen(token)+1))==(char*)Null) serror(14);
     if ((value=(char *)malloc())==(char*)Null) serror(14);
     strcpy(var,token); *(var+strlen(var))='\0';
     get_token(0);
     if (*token!='=') serror(2);
     get_exp(value);
     if (*value!=STRING_TYPE) serror(0);
     realloc(value,34);
     if (strlen(value+1)<32) {
	  i=strlen(value+1);
	  s2=value+32; s1=value+i;
	  for (j=i; j; j--)
	      *s2--=*s1--;
	  while (s2!=value) *s2--=' ';
     }
     *(value+33)='\0';
     p=search_vartree(var);
     if (p==NULL) doingassign(var,value);
     else {
	 if (*p->value_addr!=STRING_TYPE) serror(0);
	 free(p->value_addr); p->value_addr=value;
	 free(var);
     }
}
FAR void exec_lset()
{
     char *flag, *var, *value, *s1, *s2;
     bitnode *p;
     int i,j;
     get_token(0); 
     flag = get_token_last();
     if (flag!=NULL&&*flag!='$') serror(0);
     if (flag!=NULL) *flag='\0';
     if ((var=(char *)malloc(strlen(token)+1))==NULL) serror(14);
     if ((value=(char *)malloc(VALUE_SIZE))==NULL) serror(14);
     strcpy(var,token); *(var+strlen(var))='\0';
     get_token(0);
     if (*token!='=') serror(2);
     get_exp(value);
     if (*value!=STRING_TYPE) serror(0);
     realloc(value,34);
     if (strlen(value+1)<32) {
	s1=value+strlen(value);
	s2=value+33;
	while (s1!=s2) *s1++=' ';
     }
     *(value+33)='\0';
     p=search_vartree(var);
     if (p==NULL) doingassign(var,value);
     else {
	 if (*p->value_addr!=STRING_TYPE) serror(0);
	 free(p->value_addr); p->value_addr=value;
	 free(var);
     }
}*/

⌨️ 快捷键说明

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