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

📄 edit.c

📁 MMURTL(tm) Computer Operating System Ver x0.8, source code.
💻 C
📖 第 1 页 / 共 3 页
字号:
	}
	if ((pEdit->oBufInsert < iMk) || (pEdit->oBufInsert > iBd)) {
	  	for (i=0; i <= pEdit->oBufLast; i++)
    		pBuffWork[i] = pBuff[i];
	    if (pEdit->oBufInsert < iMk) {
    	  for (i=0; i<=iBd-iMk; i++)                /* Move mk/bd */
        	 pBuff[pEdit->oBufInsert+i] = pBuffWork[iMk+i];
      	  for (i=0; i<=iMk - pEdit->oBufInsert - 1; i++) /* Shift overwritten ahead */
       	 	pBuff[pEdit->oBufInsert+iBd-iMk+1+i] =
        	pBuffWork[pEdit->oBufInsert+i];
    	}
    	if (pEdit->oBufInsert > iBd) {
      		for (i=0; pEdit->oBufInsert - iBd - 1; i++)
      	  		pBuff[iMk+i] = pBuffWork[iBd+1+i];
     	 	pEdit->oBufInsert = pEdit->oBufInsert - iBd + iMk - 1;
     	 	for (i=0; i <=iBd-iMk; i++)
     	   		pBuff[pEdit->oBufInsert+i] = pBuffWork[iMk+i];
    	}
    	iBd = pEdit->oBufInsert + iBd - iMk;
    	iMk = pEdit->oBufInsert;
    	if (pEdit->oBufBound > pEdit->oBufMark) {
      		pEdit->oBufBound = iBd;
      		pEdit->oBufMark = iMk;
    	}
    	else {
      		pEdit->oBufMark = iBd;
     	 	pEdit->oBufBound = iMk;
    	}
	}
}
 else Beep();
}


void CopyIt (void)
{
unsigned long  i, iMk, iBd;
char *pBuff, *pBuffWork;

	pBuff = pEdit->pBuf;
	pBuffWork = pEdit->pBufWork;

if (pEdit->oBufMark < EMPTY) {
	fModified = 1;

  if (pEdit->oBufMark <= pEdit->oBufBound) {
    iMk = pEdit->oBufMark;
    iBd = pEdit->oBufBound;
  } else {
    iBd = pEdit->oBufMark;
    iMk = pEdit->oBufBound;
  }
  if (pEdit->oBufLast+iBd-iMk+1 < pEdit->iBufMax) {
	CopyData(pBuff, pBuffWork, pEdit->oBufLast+1);
	CopyData(&pBuffWork[iMk], &pBuff[pEdit->oBufInsert], iBd-iMk+1);
    if (pEdit->oBufLast >= pEdit->oBufInsert)
    	CopyData(&pBuffWork[pEdit->oBufInsert],
                &pBuff[pEdit->oBufInsert+iBd-iMk+1],
                pEdit->oBufLast - pEdit->oBufInsert+1);
    iBd = pEdit->oBufInsert + iBd - iMk;
    iMk = pEdit->oBufInsert;
    pEdit->oBufInsert = pEdit->oBufInsert + iBd - iMk + 1;
    pEdit->oBufLast = pEdit->oBufLast + iBd - iMk + 1;
    if (pEdit->oBufBound > pEdit->oBufMark) {
      pEdit->oBufBound = iBd;
      pEdit->oBufMark = iMk;
    }
    else {
      pEdit->oBufMark = iBd;
      pEdit->oBufBound = iMk;
    }
  }
}
else Beep();
}


void normAttr (void)
{
unsigned long  i;

  for (i = pEdit->iRowMin; i <= pEdit->iRowMax; i++)
     PutVidAttrs (pEdit->iColMin, i, pEdit->sLine, pEdit->iAttrNorm);
}


void nullMarkBound (void)
{
  pEdit->oBufMark = EMPTY;
  pEdit->oBufBound = EMPTY;
  normAttr ();
}



void deleteData (void)
{
unsigned long  i, iMk, iBd;
char  fProb;
char *pBuff, *pBuffWork;

  pBuff = pEdit->pBuf;
  pBuffWork = pEdit->pBufWork;

if (pEdit->oBufMark < EMPTY) {
  fModified = 1;
  if (pEdit->oBufMark <= pEdit->oBufBound)  {
    iMk = pEdit->oBufMark;
    iBd = pEdit->oBufBound;
  } else {
    iBd = pEdit->oBufMark;
    iMk = pEdit->oBufBound;
  }
  if ((pEdit->oBufLine0 >= iMk) && (pEdit->oBufLine0 <= iBd))
     fProb = TRUE;
  else fProb = FALSE;
  CopyData(&pBuff[iBd+1], &pBuff[iMk], pEdit->oBufLast-iBd);
  pEdit->oBufLast = pEdit->oBufLast - iBd + iMk - 1;
  if (pEdit->oBufInsert > iBd)
  	  pEdit->oBufInsert = pEdit->oBufInsert - iBd + iMk;
  else if ((pEdit->oBufInsert > iMk) && (pEdit->oBufInsert <= iBd))
      pEdit->oBufInsert = iMk;
  if (pEdit->oBufInsert > pEdit->oBufLast)
     pEdit->oBufInsert = pEdit->oBufLast;
  if (fProb)  {
    i = findPrevLine (pEdit->oBufInsert);
    pEdit->oBufLine0 = i;
  }
  nullMarkBound ();
}
}


void findCursor (void)
{
	/* locates cursor based on oBufInsert
	   - might be off screen - if it is, this
       will adjust screen */

unsigned long  i, j;

  i = pEdit->iRowMin;
  while ((i <= pEdit->iRowMax) && (pEdit->oBufInsert >= pEdit->Line[i]))
       i++;
  pEdit->iLine = i - 1;
  if (pEdit->iLine < pEdit->iRowMin)
     pEdit->iLine = pEdit->iRowMin;

  j = pEdit->iLine;
  if ((pEdit->Line[j+1] < EMPTY) &&
      (pEdit->oBufInsert >= pEdit->Line[j+1]))
     	pEdit->iLine = pEdit->iLine + 1;
  j = pEdit->iLine;
  pEdit->iCol = pEdit->oBufInsert - pEdit->Line[j] + pEdit->iColMin;
  if (pEdit->iLine > pEdit->iRowMax + 1)
     pEdit->iLine = pEdit->iRowMax;
}


void coordCursor_oBuf (void)
{
unsigned long  oBuf, i;
/*
   This readjusts iCol & iLine to get them back in sync with
   oBufInsert if oBufInsert is on screen.  If oBufInsert is
   not onscreen, this makes it so it is!
*/

  i = pEdit->iRowMax+1;
  if ((pEdit->oBufInsert >= pEdit->oBufLine0) &&
      (pEdit->oBufInsert < pEdit->Line[i]))  {

    /* if bogus line, guarantee end of good */

	i = pEdit->iLine;
    if (pEdit->Line[i] == EMPTY)
       pEdit->iCol = pEdit->iColMax;

     /* if bogus line, find last good line */

    while ((pEdit->Line[i] == EMPTY) &&
           (i > pEdit->iRowMin)) {
        pEdit->iLine--;
		i = pEdit->iLine;
	}

	i = pEdit->iLine;
    pEdit->oBufInsert =
    	pEdit->Line[i] + pEdit->iCol - pEdit->iColMin;
    if (pEdit->oBufInsert > pEdit->oBufLast)
       pEdit->oBufInsert = pEdit->oBufLast;
    oBuf = pEdit->Line[i+1];
    if (pEdit->oBufInsert > oBuf)
       pEdit->oBufInsert = oBuf;   /* get to potential insert - is, if
                                      	   prev char <> CR, is not if prev = CR */
    if (pEdit->oBufInsert == oBuf)            /* if at EOL */
       if (pEdit->pBuf[oBuf-1] == 0x0A)
         pEdit->oBufInsert--;
    pEdit->iCol = pEdit->oBufInsert + pEdit->iColMin -
    			  pEdit->Line[i];
  }
}


/*  Adjusts oBufLine0 to make sure that oBufInsert is on the screen.
    This also sets all of the Line array values (Line[n]) */


void makeOnScreen (void)
{
unsigned long  i, j, k;

  /* If oBufInsert is not on screen (above current display)
     then find the previous line beginning and make that
     the new first line 1 until it is!
  */

  while (pEdit->oBufInsert < pEdit->oBufLine0)
  	pEdit->oBufLine0 = findPrevLine (pEdit->oBufLine0);

  /* Set Line[iRowMin] to match oBufLine0 */

  k = pEdit->iRowMin;
  pEdit->Line[k] = pEdit->oBufLine0;

  /* Set all subsequent Line[s] by calling findEol for each. */

  for (i = k; i <= pEdit->iRowMax; i++) {
    if (pEdit->Line[i] < EMPTY) {
      j = findEol (pEdit->Line[i]);
      if (j < pEdit->oBufLast)       /* j = offset of last char of line */
        pEdit->Line[i+1] = j + 1;
      else
      	for (j=i+1; j<NLINESMAX; j++)
          		pEdit->Line[j] = EMPTY;
  	}
  }

	/* If the InsertPoint (your cursor position) is past
	the last line then do this junk to fix it */

  j = pEdit->iRowMin;
  k = pEdit->iRowMax;
  while (pEdit->oBufInsert >= pEdit->Line[k+1]) {
    for (i=j; i<=k; i++)
      pEdit->Line[i] = pEdit->Line[i+1];
    pEdit->oBufLine0 = pEdit->Line[j];

    i = findEol (pEdit->Line[k]);		  /* EOL of iRowMax */
    if (i < pEdit->oBufLast)              /* i = offset of last char of line */
    	pEdit->Line[k+1] = i + 1;
    else pEdit->Line[k+1] = EMPTY;
  }
}


void showScreen (char *pFiller)
{
unsigned long i, iLn, cb, oBuf;
char *pBuff;

	pBuff = pEdit->pBuf;

	makeOnScreen ();    /* oBufInsert on screen - Line correct */

	for (iLn = pEdit->iRowMin; iLn <= pEdit->iRowMax; iLn++) {

		/* i = offset in buf of last char on line */
		/* cb = nchars in line */

		cb = 0;
		oBuf = pEdit->Line[iLn];
		if (oBuf < EMPTY) {
			if (pEdit->Line[iLn+1] < EMPTY)
				i = pEdit->Line[iLn+1] - 1;
			else
	    	  	i = pEdit->oBufLast;
		    cb = i - oBuf + 1;      	/* Make size, not offset */


		    if ((!pEdit->fVisible) &&
		    	(pBuff[i] == 0x0A) &&
		    	(cb))
		    	   	cb--;
		}

		if ((cb) && (oBuf < EMPTY))
		  	PutVidChars (pEdit->iColMin, iLn, pBuff+oBuf, cb,
					  pEdit->iAttrNorm);

		if (cb < pEdit->sLine)
		  	PutVidChars (pEdit->iColMin+cb, iLn, pFiller, pEdit->sLine-cb,
		  			  pEdit->iAttrNorm);

		doMark (iLn);
	}
}


void clearbuf (void)
{
unsigned long i;
char *pBuff;

	pBuff = pEdit->pBuf;
	FillData(filler, 80, 0x20);
	for (i=0; i<NLINESMAX; i++)
       pEdit->Line[i] = EMPTY;
	i = pEdit->iRowMin;
	pEdit->Line[i] = 0;

    pEdit->iCol = pEdit->iColMin;
    pEdit->iLine = pEdit->iRowMin;
  	pEdit->bSpace = 0x20;
  	pEdit->fVisible = FALSE;
	fModified = 0;
	fOvertype = FALSE;
	pEdit->oBufLast	 = 0;
    pEdit->oBufInsert = 0;
    pEdit->oBufLine0 = 0;
	pBuff[pEdit->oBufLast] = 0x0F;		/* the SUN */
	nullMarkBound();
	normAttr ();
}



void EditSFA (char *pbExitRet)
{
unsigned long  cRows, i, j, k, key;
char  fSpecInsert;     /* TRUE = insert no matter what fOvertype is */
char  fScreen;   	   /* TRUE = display entire screen */
char  fDone;
unsigned char b, b1;
char *pBuff, *pBuffWork;

  pBuff = pEdit->pBuf;
  pBuffWork = pEdit->pBufWork;

  cRows = pEdit->iRowMax - pEdit->iRowMin + 1;  /* cRows not used yet */

  FillData(filler, 80, 0x20);
  for (i=0; i<NLINESMAX; i++)
       pEdit->Line[i] = EMPTY;
  i = pEdit->iRowMin;
  pEdit->Line[i] = 0;

  if (pEdit->fVisible)  {
    pEdit->bSpace = 0x07;
    for (i=0; i <=pEdit->oBufLast; i++)
      if (pBuff[i] == 0x20)
         pBuff[i] = pEdit->bSpace;
  } else
  	pEdit->bSpace = 0x20;

  fModified = 0;
  fOvertype = FALSE;    /* Set Overtype OFF */
  fDone = FALSE;
  normAttr ();
  fScreen = TRUE;
  pBuff[pEdit->oBufLast] = 0x0F;		/* the SUN */

  while (!fDone)    {
    if (fScreen)  {
      showScreen (filler);    /* we know oBufInsert on screen */
      findCursor ();
      fScreen = FALSE;
    }
    SetXY (pEdit->iCol, pEdit->iLine);
	FillData(aStat, 80, 0x20);
	sprintf(aStat,"C: %02d  L: %05d  nChars: %05d",
			pEdit->iCol, pEdit->iLine, pEdit->oBufLast);
	if (cbFilename)
		CopyData(Filename, &aStat[40], cbFilename);
	if (fOvertype)
		CopyData("OVR", &aStat[77], 3);
	else
		CopyData("INS", &aStat[77], 3);
    PutVidChars (0,0, aStat, 80, STATVID);

    fSpecInsert = FALSE;  /* True if char should be inserted even if fOver */
    ReadKbd (&key, 1);	  /* Wait for char */
    b = key & 0xff;

	if (key & 0x3000) {		/* ALT key is down */

		switch (b) {

      		case 0x42:		/* ALT-B -- Beginning of Text */
      		case 0x62:		/* ALT-b  */
                   pEdit->oBufLine0 = 0;
                   pEdit->oBufInsert = 0;
                   pEdit->iCol = pEdit->iColMin;
                   pEdit->iLine = pEdit->iRowMin;
                   fScreen = TRUE;
				 break;

      		case 0x43:		/* ALT-C -- CloseFile */
      		case 0x63:		/* ALT-c  */
				if (fh) {
					if (pEdit->fVisible) {    /* fix visible characters */
					     for (i=0; i <=pEdit->iBufMax; i++)
					         if (pBuff[i] == 0x07)
					         	  pBuff[i] = 0x20;
                        pEdit->fVisible = FALSE;
					}
					if (fModified) {
						erc = CheckErc(6, SetFileLFA(fh, 0));
						if (!erc)
							erc = CheckErc(5, SetFileSize(fh,
										pEdit->oBufLast));
						if (!erc)
							erc = CheckErc(3, WriteBytes (fh, pBuf1,
										   pEdit->oBufLast, &i));
						fModified = 0;
					}
					CloseFile(fh);
				    PutVidChars (40, 24, "DONE...   ", 10, STATVID);
					Sleep(100);
				    PutVidChars (40, 24, "          ", 10, STATVID);
					fh = 0;

⌨️ 快捷键说明

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