int insMacro(int f, int n) { meWindow *wp ; register meLine *lp, *slp ; meMacro *mac ; meUByte buf[meBUF_SIZE_MAX] ; meInt nol, lineNo, len ; int ii ; meStrcpy(buf,"define-macro ") ; if((mac=userGetMacro(buf+13, meBUF_SIZE_MAX-13)) == NULL) return false ; if((ii=bufferSetEdit()) <= 0) /* Check we can change the buffer */ return ii ; frameCur->windowCur->dotOffset = 0 ; slp = frameCur->windowCur->dotLine ; lineNo = frameCur->windowCur->dotLineNo ; nol = addLine(slp,buf) ; len = meStrlen(buf) + 9 ; lp = meLineGetNext(mac->hlp); /* First line. */ while (lp != mac->hlp) { nol += addLine(slp,lp->text) ; len += meLineGetLength(lp) + 1 ; lp = meLineGetNext(lp); } nol += addLine(slp,(meUByte *)"!emacro") ; frameCur->bufferCur->lineCount += nol ; meFrameLoopBegin() ; for (wp=loopFrame->windowList; wp!=NULL; wp=wp->next) { if (wp->buffer == frameCur->bufferCur) { if(wp->dotLineNo >= lineNo) wp->dotLineNo += nol ; if(wp->markLineNo >= lineNo) wp->markLineNo += nol ; wp->updateFlags |= WFMAIN|WFMOVEL ; } } meFrameLoopEnd() ; #if MEOPT_UNDO meUndoAddInsChars(len) ; #endif return true ; }
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 ; }
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 ; }
/* * regSave * Save the registry back to file */ int regSave(meRegNode *rnp, meUByte *fname, int mode) { meRegNode *rr ; meInt ss=meTRUE, level=0, lineCount, charCount ; meUInt flags ; if(mode & meREGMODE_FROOT) { /* Find the filename */ if ((fname == NULL) || (fname[0] == '\0')) { fname = NULL; if(rnp->mode & meREGMODE_FROOT) fname = rnp->value; /* Use the default file name */ if(fname == NULL) return mlwrite(MWABORT|MWPAUSE,(meUByte *)"Registry: No file name specified on save"); } flags = meRWFLAG_WRITE ; if(mode & meREGMODE_BACKUP) flags |= meRWFLAG_BACKUP ; if(mode & meREGMODE_CRYPT) { meUByte s1[meBUF_SIZE_MAX], *s2 ; int len ; meCrypt(NULL,0); meStrcpy(s1,getFileBaseName(fname)) ; len = meStrlen(s1) + 1 ; meCrypt(s1,len) ; if((s2=meUserName) == NULL) s2 = (meUByte *) "" ; meStrcpy(s1+len,s2) ; meCrypt(s1,len+meStrlen(s1+len)+1) ; flags |= meRWFLAG_CRYPT ; } /* Open the file */ if(ffWriteFileOpen(fname,flags,NULL) <= 0) return meABORT ; /* Add a recognition string to the header */ if(!(mode & meREGMODE_CRYPT)) ss = ffWriteFileWrite(12,(meUByte *) ";-!- erf -!-",1) ; } else { mode &= ~meREGMODE_CRYPT ; lineCount = 0 ; charCount = 0 ; } /* Recurse the children of the node and write to file */ rr = rnp->child ; while((ss > 0) && (rr != NULL)) { meUByte buff[4096] ; int len ; /* Print the node */ if((len = level) != 0) memset(buff,' ',len) ; buff[len++] = '"' ; len = expandexp(-1,rr->name,4096-11,len,buff,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO|meEXPAND_PRINTABLE) ; buff[len++] = '"' ; if (rr->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)) { buff[len++] = ' ' ; buff[len++] = '0' + (rr->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)) ; } if (rr->value != NULL) { buff[len++] = ' ' ; buff[len++] = '=' ; buff[len++] = ' ' ; buff[len++] = '"' ; len = expandexp(-1,rr->value,4096-4,len,buff,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO|meEXPAND_PRINTABLE) ; buff[len++] = '"' ; } /* write open '{' if it has children */ if (rr->child != NULL) { buff[len++] = ' ' ; buff[len++] = '{' ; } if((mode & meREGMODE_FROOT) == 0) { buff[len] = '\0' ; if((ss = addLine(frameCur->windowCur->dotLine,buff)) <= 0) break ; lineCount += ss ; charCount += len + 1 ; } else if((ss = ffWriteFileWrite(len,buff,1)) <= 0) break ; /* Descend child */ if (rr->child != NULL) { rr = rr->child; level++; continue; } /* Ascend the tree */ for (;;) { /* Move to sibling */ if (rr->next != NULL) { rr = rr->next; break; } if (rr->parent != NULL) { if (--level < 0) { rr = NULL; break; } rr = rr->parent; /* as we are assending the tree, at least the first 'level' * number of chars in buffer must be ' 's so just splat in the '}' */ len = level ; buff[len++] = '}' ; if((mode & meREGMODE_FROOT) == 0) { buff[len] = '\0' ; if((ss = addLine(frameCur->windowCur->dotLine,buff)) <= 0) break ; lineCount += ss ; charCount += len + 1 ; } else if((ss = ffWriteFileWrite(len,buff,1)) <= 0) break ; } } } if(mode & meREGMODE_FROOT) { if(ffWriteFileClose(fname,meRWFLAG_WRITE,NULL) <= 0) return meABORT ; rnp->mode &= ~meREGMODE_CHANGE; } else { meWindow *wp ; level = frameCur->windowCur->dotLineNo ; frameCur->bufferCur->lineCount += lineCount ; meFrameLoopBegin() ; for(wp=loopFrame->windowList; wp!=NULL; wp=wp->next) { if (wp->buffer == frameCur->bufferCur) { if(wp->dotLineNo >= level) wp->dotLineNo += lineCount ; if(wp->markLineNo >= level) wp->markLineNo += lineCount ; wp->updateFlags |= WFMAIN|WFMOVEL ; } } meFrameLoopEnd() ; frameCur->windowCur->dotOffset = 0 ; #if MEOPT_UNDO meUndoAddInsChars(charCount) ; #endif if(ss <= 0) return mlwrite(MWABORT|MWPAUSE,(meUByte *)"[Failed to write registry %s]",fname) ; } return meTRUE ; }