/*************************************************************** Copy a modified "compressed view file" back to the original file. To use this macro, do the following: Load a file, run CompressedView, then select "Edit This File" . Change the compressed view file as needed, but do not split any lines, do not mess with the first line, and do not mess with the line numbers. Now, when you are finished changing the compressed view file, run this macro. Assuming you didn't do anything wrong, and this macro works, the compressed view file lines are copied back into the file from whence they came. Mar 7, 2005 SEM: Support multiple files Feb 16, 1999 Sjoerd W. Rienstra Bug! If a line in the "compressed file" is made empty (after the 999:) the lFind fails. Aug 17, 1998 SEM: Original version Algorithm: save stuff get the name if find the first line number repeat mark the line, move to scratch buffer go to original file go to remembered line number replace the line with the new one go back to the compressed view until not find the next line number endif restore stuff File: D:\this is a test 78 occurrences found 7: 2unk junk junk junk 8: 3unk junk junk junk 9: 4unk junk This is a test to see if we junk junk ***************************************************************/ string file_tag[] = "File: " string line_no_tag[] = ":" string occurr_tag[] = " occurrences found on " proc main() string fn[_MAXPATH_], s[40], line_st[30] integer orig_buf, cv_buf, line, orig_buf_pos_saved, count, p count = 0 PushPosition() PushBlock() UnMarkBlock() // get the name of the original file BegFile() loop orig_buf_pos_saved = FALSE if GetText(1, Length(file_tag)) <> file_tag Warn("File: tag not found") goto finished endif fn = Trim(GetText(length(file_tag) + 1, 255)) p = Pos(occurr_tag, fn) if p == 0 Warn("occurrences tag not found") goto finished endif fn = DelStr(fn, p, sizeof(fn)) while isDigit(fn[Length(fn)]) fn = DelStr(fn, Length(fn), 1) endwhile fn = Trim(fn) // v2.5 thru at least 2.9x put a chr(0) at the end of the // filename - get rid of it if fn[Length(fn)] == Chr(0) fn = DelStr(fn, Length(fn), 1) endif // and make sure that file is still loaded cv_buf = GotoBufferId(GetBufferId(fn)) if cv_buf == 0 Warn("Original file not loaded: ", fn) goto finished endif orig_buf = GetBufferId() // save the position in the original file PushPosition() orig_buf_pos_saved = TRUE GotoBufferId(cv_buf) loop if not Down() goto finished endif // Get the line number - account for empty text s = GetText(1, sizeof(s)) if s[1:Length(file_tag)] == file_tag break endif p = Pos(line_no_tag, s) // ":" if p == 0 Warn("Line number tag not found at line ", CurrLine()) goto finished endif line_st = Trim(s[1:p - 1]) if not isDigit(line_st) Warn("Line number not found at line ", CurrLine()) goto finished endif line = Val(line_st) if line == 0 Warn("Line number is not valid at line ", CurrLine()) goto finished endif GotoColumn(p + 2) // mark the text, and replace the corresponding line // in the original file MarkToEOL will fail if there // is no text to mark, so unmark the block first so // we can check for no block marked later UnMarkBlock() MarkToEOL() GotoBufferId(orig_buf) GotoLine(line) if CurrLine() <> line Warn("Replacement line ", line, " is not in the original file") goto finished endif BegLine() KillToEol() // only copy if there is a block, thus handling empty // replacements if isBlockMarked() CopyBlock() endif count = count + 1 GotoBufferId(cv_buf) endloop if orig_buf_pos_saved GotoBufferId(orig_buf) PopPosition() GotoBufferId(cv_buf) endif endloop finished: if orig_buf_pos_saved GotoBufferId(orig_buf) PopPosition() GotoBufferId(cv_buf) endif PopPosition() PopBlock() if count Message(count, " line(s) replaced") endif end