meUndoNode * meUndoCreateNode(size_t size) { meUndoNode *nn ; if((nn = meMalloc(size)) != NULL) { nn->type = 0 ; nn->next = frameCur->bufferCur->undoHead ; frameCur->bufferCur->undoHead = nn ; nn->udata.dotp = frameCur->windowCur->dotLineNo ; nn->doto = frameCur->windowCur->dotOffset ; nn->str[0] = '\0' ; if(frameCur->bufferCur->undoContFlag == undoContFlag) nn->type |= meUNDO_CONTINUE ; else frameCur->bufferCur->undoContFlag = undoContFlag ; } else { /* ditch all undos to get more memory back and make ME more stable */ meUndoRemove(frameCur->bufferCur) ; meModeClear(frameCur->bufferCur->mode,MDUNDO) ; } return nn ; }
/* meFrameInitWindow * * Creates the initial window for a frame, would be part of * meFrameInit except the order of events at startup make this * impossible (no buffer) */ int meFrameInitWindow(meFrame *frame, meBuffer *buffer) { meWindow *wp; meLine *lp, *off; if(((wp = meMalloc(sizeof(meWindow))) == NULL) || ((lp = meLineMalloc(frame->widthMax,0)) == NULL) || ((off= meLineMalloc(frame->widthMax,0)) == NULL)) return false ; frame->bufferCur = buffer ; /* Make this current */ frame->windowList = wp ; frame->windowCur = wp ; frame->windowCount = 1 ; memset(wp,0,sizeof(meWindow)) ; /* Window # columns & rows */ wp->width = frame->width; wp->depth = frame->depth; wp->modeLine = lp ; off->next = NULL ; wp->dotCharOffset= off ; wp->buffer = buffer ; wp->dotLine = buffer->baseLine ; wp->updateFlags = WFMODE|WFRESIZE|WFSBAR; #if MEOPT_EXTENDED wp->id = ++nextWindowId ; #endif /* Flag buffer as displayed. */ buffer->windowCount++ ; meWindowFixTextSize(wp) ; meVideoAttach(&(frame->video), wp) ; return true ; }
/* * rnodeNew * Allocate and initialise a new node */ static meRegNode * rnodeNew (meUByte *name) { meRegNode *np; /* Pointer to the node */ int len; /* Length of the string */ /* Get the length of the node name */ len = meStrlen(name) ; /* Allocate space for the node and copy in the node name */ if ((np = (meRegNode *) meMalloc(sizeof(meRegNode) + len)) == NULL) return NULL; memset(np, 0, sizeof(meRegNode)); meStrcpy(np->name,name) ; return (np); }
meInt * meUndoAddLineSort(meInt lineCount) { meUndoNode *nn ; meInt *lineSort ; if(meModeTest(frameCur->bufferCur->mode,MDUNDO) && ((nn = meUndoCreateNode(sizeof(meUndoNode))) != NULL) && ((lineSort = meMalloc((lineCount + 1) * sizeof(meInt))) != NULL)) { nn->type |= meUNDO_SPECIAL|meUNDO_LINE_SORT ; nn->count = lineCount ; nn->udata.lineSort = lineSort ; *lineSort++ = frameCur->windowCur->dotLineNo ; return lineSort ; } return NULL ; }
/* * meFrameEnlargeVideo * Enlarge the video frames attached to the virtual video structures. * Usually follows an enlargement of the screen. */ int meFrameEnlargeVideo(meFrame *frame, int rows) { meVideo *vvptr; /* Pointer to the video blocks */ meVideoLine *vs; /* Video store line */ for (vvptr = &frame->video; vvptr != NULL; vvptr = vvptr->next) { /* Try and allocate new video frame */ if ((vs = (meVideoLine *) meMalloc (rows * sizeof (meVideoLine))) == NULL) return (false); /* Allocation successful. Reset the contents to zero and swap for the existing one */ memset (vs, 0, rows * sizeof (meVideoLine)); /* Reset to zero */ meFree (vvptr->lineArray); /* Dispose of old one */ vvptr->lineArray = vs; /* Swap in new one */ } return (true); }
static meMacro * createMacro(meUByte *name) { meUByte buff[meBUF_SIZE_MAX] ; register meMacro *mac ; register meLine *hlp ; register int idx ; /* If the macro name has not been give then try and get one */ if((name == NULL) && (meGetString((meUByte *)"Macro name",MLCOMMAND|MLEXECNOUSER, 0, buff, meBUF_SIZE_MAX) > 0) && (buff[0] != '\0')) name = buff ; if((name == NULL) || ((hlp = meLineMalloc(0,0)) == NULL)) return NULL ; /* if it already exists */ if((idx = decode_fncname(name,1)) >= 0) { /* if function return error, else clear the buffer */ if(idx < CK_MAX) { mlwrite(MWABORT|MWPAUSE,(meUByte *)"Error! can't re-define a base function") ; meFree(hlp) ; return NULL ; } mac = getMacro(idx) ; if(!(mac->hlp->flag & meMACRO_EXEC)) { #if MEOPT_EXTENDED if(mac->hlp->flag & meMACRO_FILE) { if(meNullFree(mac->fname)) mac->fname = NULL ; } #endif meLineLoopFree(mac->hlp,1) ; } } else { meCommand **cmd ; if((cmdTableSize & 0x1f) == 0) { /* run out of room in the command table, malloc more */ meCommand **nt ; if((nt = (meCommand **) meMalloc((cmdTableSize+0x20)*sizeof(meCommand *))) == NULL) return NULL ; memcpy(nt,cmdTable,cmdTableSize*sizeof(meCommand *)) ; if(cmdTable != __cmdTable) free(cmdTable) ; cmdTable = nt ; } if(((mac = (meMacro *) meMalloc(sizeof(meMacro))) == NULL) || ((mac->name = meStrdup(name)) == NULL)) { meFree(hlp) ; return NULL ; } mac->id = cmdTableSize ; #if MEOPT_EXTENDED mac->varList.head = NULL ; mac->varList.count = 0 ; mac->fname = NULL ; mac->callback = -1 ; #endif cmdTable[cmdTableSize++] = (meCommand *) mac ; /* insert macro into the alphabetic list */ cmd = &(cmdHead) ; while((*cmd != NULL) && (meStrcmp((*cmd)->name,name) < 0)) cmd = &((*cmd)->anext) ; mac->anext = *cmd ; *cmd = (meCommand *) mac ; #if MEOPT_CMDHASH /* insert macro into the hash table */ { meUInt key ; mac->hnext = NULL ; key = cmdHashFunc(name) ; cmd = &(cmdHash[key]) ; while(*cmd != NULL) cmd = &((*cmd)->hnext) ; *cmd = (meCommand *) mac ; } #endif } mac->hlp = hlp ; hlp->next = hlp ; hlp->prev = hlp ; return mac ; }
int meUndo(int f, int n) { if(n < -1) { #ifndef NDEBUG if(n == -4) { meUndoNode *nn ; FILE *undoFp=NULL ; if(undoFp == NULL) undoFp = fopen("undo.log","w+") ; fprintf(undoFp,"[Undo stack for %s]\n",frameCur->bufferCur->name) ; nn=frameCur->bufferCur->undoHead ; while(nn != NULL) { if(meUndoIsLineSort(nn)) { fprintf(undoFp,"Undo 0x%02x %p %ld %ld:",nn->type,nn->next, nn->udata.lineSort[0],nn->count) ; for(n=0 ; n<nn->count ; n++) fprintf(undoFp," %ld",nn->udata.lineSort[n+1]) ; fprintf(undoFp,"\n") ; } #if MEOPT_NARROW else if(meUndoIsNarrow(nn)) { meUndoNarrow *nun = (meUndoNarrow *) nn ; fprintf(undoFp,"Undo 0x%02x %p Nrrw %x %ld %ld %d [%s]\n",nun->type,nun->next, nun->name,nun->count,nun->udata.dotp,nun->markupCmd,nun->str) ; } #endif else { fprintf(undoFp,"Undo 0x%02x %p %ld (%ld,%d) [%s]\n",nn->type,nn->next,nn->count, nn->udata.dotp,nn->doto,nn->str) ; if(meUndoIsReplace(nn)) { for(n=0 ; n<nn->doto ; n++) fprintf(undoFp,"(%d,%d) ",nn->udata.pos[n][0],nn->udata.pos[n][1]) ; fprintf(undoFp,"\n") ; } } nn = nn->next ; } fprintf(undoFp,"---------------\n") ; fflush(undoFp) ; } else #endif undoContFlag++ ; } else if(!meModeTest(frameCur->bufferCur->mode,MDUNDO)) return ctrlg(meFALSE,1) ; else if(n < 0) meUndoRemove(frameCur->bufferCur) ; else { static meUndoNode *cun ; static meInt ccount ; static meUShort cdoto ; if((lastflag != meCFUNDO) && ((cun = frameCur->bufferCur->undoHead) != NULL)) { cdoto = cun->doto ; ccount = cun->count ; } for(;;) { meInt count, cont ; if((cun == NULL) || ((n <= 0) && !meModeTest(frameCur->bufferCur->mode,MDEDIT))) break ; if(bufferSetEdit() <= 0) /* Check we can change the buffer */ return meABORT ; cont=0 ; if(cun->type & meUNDO_SPECIAL) { if(meUndoIsSetEdit(cun)) { if(!(cun->type & meUNDO_UNSET_EDIT)) { autowriteremove(frameCur->bufferCur) ; meModeClear(frameCur->bufferCur->mode,MDEDIT) ; frameAddModeToWindows(WFMODE) ; /* update ALL mode lines */ } } else if(meUndoIsLineSort(cun)) { meLine *ln, *eln, **list ; meInt *lineSort, *undoInfo, dddd ; lineSort = cun->udata.lineSort ; windowGotoLine(meTRUE,(*lineSort++) + 1) ; if((list = meMalloc(cun->count * sizeof(meLine *))) == NULL) return meABORT ; undoInfo = meUndoAddLineSort(cun->count) ; eln = frameCur->windowCur->dotLine ; ln = meLineGetPrev(eln) ; for(count=0 ; count<cun->count ; eln=meLineGetNext(eln),count++) { list[*lineSort++] = eln ; eln->prev = (meLine *) count ; } for(count=0 ; count<cun->count ; ln=meLineGetNext(ln),count++) { if(undoInfo != NULL) { dddd = (meInt) list[count]->prev ; *undoInfo++ = dddd ; } ln->next = list[count] ; list[count]->prev = ln ; } ln->next = eln ; eln->prev = ln ; frameCur->windowCur->dotLine = list[0] ; meFree(list) ; } #if MEOPT_NARROW else if(meUndoIsNarrow(cun)) { meUndoNarrow *nun = (meUndoNarrow *) cun ; meInt name ; name = nun->name ; windowGotoLine(meTRUE,nun->udata.dotp+1) ; if(nun->type & meUNDO_NARROW_ADD) { meNarrow *nrrw ; nrrw = frameCur->bufferCur->narrow ; while(nrrw->name != name) nrrw = nrrw->next ; frameCur->bufferCur->dotLine = frameCur->windowCur->dotLine ; frameCur->bufferCur->dotLineNo = frameCur->windowCur->dotLineNo ; frameCur->bufferCur->dotOffset = 0 ; meBufferRemoveNarrow(frameCur->bufferCur,nrrw, (nun->markupCmd > 0) ? nun->str:NULL,1) ; } else { meLine *slp ; slp = frameCur->windowCur->dotLine ; windowGotoLine(meTRUE,ccount+1) ; meBufferCreateNarrow(frameCur->bufferCur,slp,frameCur->windowCur->dotLine, nun->udata.dotp,ccount,name,nun->scheme, (nun->markupFlag) ? nun->str:NULL,nun->markupCmd,1) ; } } #endif if(cun->type & meUNDO_CONTINUE) cont=1 ; goto meUndoNext ; } if(cun->type & meUNDO_REPLACE) { windowGotoLine(meTRUE,cun->udata.pos[cdoto-1][0]+1) ; count = cun->udata.pos[cdoto-1][1] ; if(count < 0) { cont = 1 ; count = -1 - count ; } frameCur->windowCur->dotOffset = (meUShort) count ; } else { if(cun->type & meUNDO_CONTINUE) cont = 1 ; windowGotoLine(meTRUE,cun->udata.dotp+1) ; frameCur->windowCur->dotOffset = cdoto ; } if(cun->type & meUNDO_SINGLE) { ccount-- ; count = 1 ; } else count = ccount ; if(cun->type & meUNDO_INSERT) { meWindowBackwardChar(frameCur->windowCur,count) ; if((count == 1)) meUndoAddDelChar() ; else meUndoAddDelChars(count) ; mldelete(count,NULL) ; } if(cun->type & meUNDO_DELETE) { /* When dealing with long lines this loop becomes infinitly * long because of the number of times that the line is * re-allocated - pre-allocate the line length first. In order * to reduce the processing overhead then we find the longest * strings and then add them back in in one go, this ensures * that we only ever re-allocate the line once. * Jon - 99/12/12. */ meUByte *ss, cc ; ss = cun->str ; /* Deal with a single character undo */ if(cun->type & meUNDO_SINGLE) { ss += ccount ; if((cc = *ss++) == meCHAR_NL) lineInsertNewline(meBUFINSFLAG_UNDOCALL); else if (cc != '\0') lineInsertChar(1, cc); meUndoAddInsChar() ; } else { /* Deal with a multiple character undo. */ count = bufferInsertText(ss,meBUFINSFLAG_UNDOCALL) ; if(count > 0) meUndoAddInsChars(count) ; } } if((cun->type & meUNDO_SINGLE) && (ccount > 0)) { if(cun->type & meUNDO_FORWARD) cdoto++ ; else if(cun->type & meUNDO_INSERT) cdoto-- ; } else if(cun->type & meUNDO_REPLACE) { cdoto-- ; if(!cdoto) goto meUndoNext ; } else { meUndoNext: if((cun = cun->next) != NULL) { cdoto = cun->doto ; ccount = cun->count ; } } if(!cont && (--n == 0)) break ; } thisflag = meCFUNDO ; } return meTRUE ; }
void meSetupPathsAndUser(char *progname) { meUByte *ss, buff[meBUF_SIZE_MAX] ; int ii, ll, gotUserPath ; curdir = gwd(0) ; if(curdir == NULL) /* not yet initialised so mlwrite will exit */ mlwrite(MWCURSOR|MWABORT|MWWAIT,(meUByte *)"Failed to get cwd\n") ; /* setup the $progname make it an absolute path. */ if(executableLookup(progname,evalResult)) meProgName = meStrdup(evalResult) ; else { #ifdef _ME_FREE_ALL_MEMORY /* stops problems on exit */ meProgName = meStrdup(progname) ; #else meProgName = (meUByte *)progname ; #endif } #if MEOPT_BINFS /* Initialise the built-in file system. Note for speed we only check the * header. Scope the "exepath" locally so it is discarded once the * pathname is passed to the mount and we exit the braces. */ bfsdev = bfs_mount (meProgName, BFS_CHECK_HEAD); #endif if(meUserName == NULL) { if(((ss = meGetenv ("MENAME")) == NULL) || (ss[0] == '\0')) ss = "user" ; meUserName = meStrdup(ss) ; } /* get the users home directory, user path and search path */ if(((ss = meGetenv("HOME")) == NULL) || (ss[0] == '\0')) ss = "c:/" ; fileNameSetHome(ss) ; if(((ss = meGetenv ("MEUSERPATH")) != NULL) && (ss[0] != '\0')) meUserPath = meStrdup(ss) ; if(((ss = meGetenv("MEPATH")) != NULL) && (ss[0] != '\0')) { /* explicit path set by the user, don't need to look at anything else */ searchPath = meStrdup(ss) ; /* we just need to add the $user-path to the front */ if(meUserPath != NULL) { /* check that the user path is first in the search path, if not add it */ ll = meStrlen(meUserPath) ; if(meStrncmp(searchPath,meUserPath,ll) || ((searchPath[ll] != '\0') && (searchPath[ll] != mePATH_CHAR))) { /* meMalloc will exit if it fails as ME has not finished initialising */ ss = meMalloc(ll + meStrlen(searchPath) + 2) ; meStrcpy(ss,meUserPath) ; ss[ll] = mePATH_CHAR ; meStrcpy(ss+ll+1,searchPath) ; meFree(searchPath) ; searchPath = ss ; } } } else { /* construct the search-path */ /* put the $user-path first */ if((gotUserPath = (meUserPath != NULL))) meStrcpy(evalResult,meUserPath) ; else evalResult[0] = '\0' ; ll = meStrlen(evalResult) ; /* look for the ~/jasspa directory */ if(homedir != NULL) { meStrcpy(buff,homedir) ; meStrcat(buff,"jasspa") ; if(((ll = mePathAddSearchPath(ll,evalResult,buff,&gotUserPath)) > 0) && !gotUserPath) /* as this is the user's area, use this directory unless we find * a .../<$user-name>/ directory */ gotUserPath = -1 ; } /* Get the system path of the installed macros. Use $MEINSTPATH as the * MicroEmacs standard macros */ if(((ss = meGetenv ("MEINSTALLPATH")) != NULL) && (ss[0] != '\0')) { meStrcpy(buff,ss) ; ll = mePathAddSearchPath(ll,evalResult,buff,&gotUserPath) ; } /* also check for directories in the same location as the binary */ if((meProgName != NULL) && ((ss=meStrrchr(meProgName,DIR_CHAR)) != NULL)) { ii = (((size_t) ss) - ((size_t) meProgName)) ; meStrncpy(buff,meProgName,ii) ; buff[ii] = '\0' ; ll = mePathAddSearchPath(ll,evalResult,buff,&gotUserPath) ; } if(!gotUserPath && (homedir != NULL)) { /* We have not found a user path so set ~/ as the user-path * as this is the best place for macros to write to etc. */ meStrcpy(buff,homedir) ; if(ll) { ii = meStrlen(buff) ; buff[ii++] = mePATH_CHAR ; meStrcpy(buff+ii,evalResult) ; } searchPath = meStrdup(buff) ; } else if(ll > 0) searchPath = meStrdup(evalResult) ; } if(searchPath != NULL) { fileNameConvertDirChar(searchPath) ; if(meUserPath == NULL) { /* no user path yet, take the first path from the search-path, this * should be a sensible directory to use */ if((ss = meStrchr(searchPath,mePATH_CHAR)) != NULL) *ss = '\0' ; meUserPath = meStrdup(searchPath) ; if(ss != NULL) *ss = mePATH_CHAR ; } } if(meUserPath != NULL) { fileNameConvertDirChar(meUserPath) ; ll = meStrlen(meUserPath) ; if(meUserPath[ll-1] != DIR_CHAR) { meUserPath = meRealloc(meUserPath,ll+2) ; meUserPath[ll++] = DIR_CHAR ; meUserPath[ll] = '\0' ; } } }
int meFrameChangeWidth(meFrame *frame, int ww) { /* ensure the value is in range */ if(ww < 8) ww = 8 ; else if(ww > 400) ww = 400 ; /* Already this size ?? Nothing to do */ if(frame->width == ww) return true; meFrameLoopBegin() ; /* only process frames which use the same screen window */ meFrameLoopContinue(loopFrame->mainId != frame->mainId) ; /* Only process if the window size is different from the current * window size. If we got here that is true, */ if(ww > loopFrame->widthMax) { /* Must extend the length of loopFrame->mlLine, loopFrame->mlLineStore, and all window * mode lines */ meWindow *wp ; /* Temporary window pointer */ meFrameLine *flp; /* Frame line pointer */ meFrameLine fl; /* Temporary frame line */ int ii, jj; /* Local loop counters */ meLine *ml ; meUByte *mls ; if(((ml = meLineMalloc(ww,0)) == NULL) || ((mls = meMalloc(ww+1)) == NULL)) return false ; /* Fix up the frame store by growing the lines. Do a safe * grow where by we can recover if a malloc fails. */ for (flp = loopFrame->store, ii = 0; ii < loopFrame->depthMax; ii++, flp++) { if ((fl.scheme = meMalloc(ww*(sizeof(meUByte)+sizeof(meStyle)))) == NULL) return false ; fl.text = (meUByte *) (fl.scheme+ww) ; /* Data structures allocated. Copy accross the new screen * information and pad endings with valid data. Strictly we * do not need to do this for all platforms, however if it * is safer if we make sure the data is valid. Resize is an * infrequent operation and time is not critical here */ memcpy(fl.text, flp->text, sizeof(meUByte) * loopFrame->widthMax); memcpy(fl.scheme, flp->scheme, sizeof(meScheme) * loopFrame->widthMax); jj = ww ; while(--jj >= loopFrame->widthMax) { fl.text[jj] = ' ' ; fl.scheme[jj] = globScheme ; } /* Free off old data and copy in new */ meFree (flp->scheme); flp->text = fl.text; flp->scheme = fl.scheme; } /* Fix up the window structures */ memcpy(ml,loopFrame->mlLine,meLINE_SIZE+loopFrame->mlLine->length) ; if(loopFrame->mlStatus & MLSTATUS_KEEP) { meStrcpy(mls,loopFrame->mlLine->text); loopFrame->mlColumnStore = loopFrame->mlColumn ; loopFrame->mlStatus = (loopFrame->mlStatus & ~MLSTATUS_KEEP) | MLSTATUS_RESTORE ; } else if(loopFrame->mlStatus & MLSTATUS_RESTORE) meStrcpy(mls,loopFrame->mlLineStore) ; free(loopFrame->mlLine) ; free(loopFrame->mlLineStore) ; loopFrame->video.lineArray[loopFrame->depth].line = (loopFrame->mlLine = ml) ; loopFrame->mlLineStore = mls ; wp = loopFrame->windowList ; while(wp != NULL) { if((ml = meLineMalloc(ww,0)) == NULL) return false ; memcpy(ml,wp->modeLine,meLINE_SIZE+wp->modeLine->length) ; free(wp->modeLine) ; wp->modeLine = ml ; wp = wp->next ; } loopFrame->widthMax = ww ; } loopFrame->width = ww ; /* Fix up the windows */ #if MEOPT_FRAME { meFrame *fc=frameCur ; frameCur = loopFrame ; meFrameResizeWindows(frameCur,meFRAMERESIZEWIN_WIDTH); frameCur = fc ; } #else meFrameResizeWindows(frameCur,meFRAMERESIZEWIN_WIDTH); #endif meFrameLoopEnd() ; return true ; }
/* initialize a frame, mallocing required video and framestore space. * * The frame depthMax and widthMax must be set */ meFrame * meFrameInit(meFrame *sibling) { meFrame *frame ; meFrameLine *flp; /* Frame store line pointer */ int ii, jj ; /* Local loop counters */ /* add 2 to hilBlockS to allow for a double trunc-scheme change */ if((frame = meMalloc(sizeof(meFrame))) == NULL) return NULL ; memset(frame,0,sizeof(meFrame)) ; #if MEOPT_FRAME if(sibling != NULL) { frame->mainId = sibling->mainId ; frame->width = sibling->width ; frame->depth = sibling->depth ; frame->widthMax = sibling->widthMax ; frame->depthMax = sibling->depthMax ; } else #else meAssert(sibling == NULL) ; #endif { frame->mainId = 0 ; #if MEOPT_FRAME { meFrame *ff = frameList ; while(ff != NULL) { if(ff->mainId == frame->mainId) { if(frame->mainId == 255) { free(frame) ; return NULL ; } frame->mainId++ ; ff = frameList ; } ff = ff->next ; } } #endif frame->width = TTwidthDefault ; frame->depth = TTdepthDefault-1 ; frame->widthMax = TTwidthDefault ; frame->depthMax = TTdepthDefault ; } if(meFrameTermInit(frame,sibling) <= 0) return NULL ; if(((frame->video.lineArray = meMalloc(frame->depthMax * sizeof(meVideoLine))) == NULL) || ((frame->mlLine = meLineMalloc(frame->widthMax,0)) == NULL) || ((frame->mlLineStore = meMalloc(frame->widthMax+1)) == NULL)) return NULL ; /* Initialise the virtual video structure. */ memset(frame->video.lineArray,0,frame->depthMax*sizeof(meVideoLine)) ; frame->video.lineArray[frame->depth].flag = VFMESSL ; frame->video.lineArray[frame->depth].line = frame->mlLine ; /* Reset the video list block */ frame->video.next = NULL; /* No next block */ frame->video.window = NULL; /* No windows attached */ memset(frame->mlLine->text,'\0',frame->widthMax) ; frame->mlLineStore[0] = '\0'; #if MEOPT_EXTENDED frame->id = ++nextFrameId ; #endif /* Frame Store storage * The frame store hold's 'n' lines of video information. * The frame->store is an array of points to meFrameLine structures * which hold the physical line contents. * * Allocate lines in the frame store to hold the video information. */ if((frame->store = meMalloc(sizeof(meFrameLine) * frame->depthMax)) == NULL) return NULL ; for (flp = frame->store, ii = 0; ii < frame->depthMax; ii++, flp++) { if ((flp->scheme = meMalloc(frame->widthMax*(sizeof(meUByte)+sizeof(meStyle)))) == NULL) return NULL ; flp->text = (meUByte *) (flp->scheme+frame->widthMax) ; /* Fill with data */ jj = frame->widthMax ; while(--jj >= 0) { flp->text[jj] = ' ' ; flp->scheme[jj] = meSCHEME_NDEFAULT ; } } return frame ; }
int meFrameChangeDepth(meFrame *frame, int dd) { /* ensure the value is in range */ if(dd < 4) dd = 4 ; else if(dd > 400) dd = 400 ; /* Already this size ?? Nothing to do */ if((frame->depth+1) == dd) return true; meFrameLoopBegin() ; /* only process frames which use the same screen window */ meFrameLoopContinue(loopFrame->mainId != frame->mainId) ; /* Only process if the window size is different from the current * window size. If we got here that is true. * Go and get some more screen space */ if (dd > loopFrame->depthMax) { meFrameLine *flp; /* Temporary frame line */ int ii, jj; /* Local loop counter */ if (meFrameEnlargeVideo(loopFrame,dd) == false) return false ; /* Grow the Frame store depthwise do this safely so that * we do not cause a crash at the video end. * * Grow the frame store first. Reallocate and then * copy across the old information. */ if ((flp = (meFrameLine *) meMalloc (sizeof (meFrameLine) * dd)) == NULL) return false ; memcpy (flp, loopFrame->store, sizeof (meFrameLine) * loopFrame->depthMax); meFree (loopFrame->store); /* Free off old store */ loopFrame->store = flp; /* Re-assign */ /* Allocate a new set of lines for the remainder of the space */ for (flp += loopFrame->depthMax, ii = loopFrame->depthMax; ii < dd; ii++, flp++) { if ((flp->scheme = meMalloc(loopFrame->widthMax*(sizeof(meUByte)+sizeof(meScheme)))) == NULL) return false ; flp->text = (meUByte *) (flp->scheme+loopFrame->widthMax) ; /* Initialise the data to something valid */ jj = loopFrame->widthMax ; while(--jj >= 0) { flp->text[jj] = ' ' ; flp->scheme[jj] = globScheme ; } } loopFrame->depthMax = dd ; } /* Fix up the message line by binding to the new video frame */ loopFrame->video.lineArray[loopFrame->depth].flag = 0 ; /* Decouple the old one */ loopFrame->video.lineArray[loopFrame->depth].line = NULL ; loopFrame->video.lineArray[dd-1].flag = VFMESSL; /* Bind in new message line */ loopFrame->video.lineArray[dd-1].line = loopFrame->mlLine ; loopFrame->video.lineArray[dd-1].endp = loopFrame->width; loopFrame->depth = dd-1 ; /* Set up global number of rows */ #if MEOPT_OSD if (loopFrame->menuDepth > 0) loopFrame->video.lineArray[0].line = loopFrame->menuLine; #endif /* Fix up the windows */ #if MEOPT_FRAME { meFrame *fc=frameCur ; frameCur = loopFrame ; meFrameResizeWindows(frameCur,meFRAMERESIZEWIN_DEPTH); frameCur = fc ; } #else meFrameResizeWindows(frameCur,meFRAMERESIZEWIN_DEPTH); #endif meFrameLoopEnd() ; return true ; }