;; | ---------------------------------------------------------------------------- ;; | MI_AddLine2File ;; | ---------------------------------------------------------------------------- ;; | Function : Adds a line of text to an ASCII file at a position immediately ;; | after or before a specified text matching line ;; | Argument : 'fn' - ASCII file name ;; | 'Where' - Can be "Before" or "After" - position of line entry ;; | 'Mode' - Mode of search, can be "Partial" or "Exact" ;; | 'SrchStr' - String to search for ;; | 'ReplStr' - String to replace with ;; | Returns : The filename 'fn' is replaced with the updated string values. ;; | Updated : August 20, 2002 ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | ---------------------------------------------------------------------------- (defun MI_AddLine2File ( fn Where Mode SrchStr ReplStr / Lst Lst1 Found Str diff ) (setq Lst (TX_File2Lst fn) Lst1 '() ) (if Lst (progn (setq Lst1 '()) (foreach Str Lst (setq Found nil) (cond ((= Mode "Exact") (if (= Str SrchStr) (setq Found T) ) ) ((= Mode "Partial") (if (wcmatch Str (strcat "*" SrchStr "*")) (setq Found T) ) ) ) (if Found (progn (cond ((= Where "Before") (setq Lst1 (cons ReplStr Lst1) Lst1 (cons Str Lst1) ) ) ((= Where "After") (setq Lst1 (cons Str Lst1) Lst1 (cons ReplStr Lst1) ) ) ) ) (setq Lst1 (cons Str Lst1)) ) ) (setq Lst1 (reverse Lst1) diff (- (length Lst1) (length Lst)) ) (if (> diff 0) (progn (TX_Lst2File fn Lst1 "w") (princ (strcat "\n" (itoa diff) " new lines were added to the file " fn)) ) (princ (strcat "\nNo new lines were added to the file " fn)) ) )) Lst1 )