Code Center
Code Center is a resource that provides programming solutions for common tasks
(subroutines) involved with writing Vedit Plus macros. The hope is to evolve
the fastest, shortest, "best", debugged, and most "elegant" way to do the particular
task.
Eventually, this will serve to prevent "re-inventing the wheel" for each macro project.
The solutions should also help novice macro programmers speed up the learning curve.
Best way to use this page is to use your browser File - Save As function and then load
the page into Vedit to copy the code you want.
Users of versions previous to 5.2x, click here
Register Usage
Register ranges included both text and numeric registers
Input Registers : 10 - 19
Output Registers : 20 - 29
Working Registers : 30 - 49
Main Temp. Buffer : 33
Secondary Temp Buffer : 34
// search for a blank line in a file
// search for optional whitespace characters at start of line followed by the end of line
// characters (decimal ascii values of 10 and / or 13 depending on file type)
search("|<|[|W]|L",noerr)
// get the height and width of a .jpg file
// works with garden variety standard or progressive jpegs
// might not work with exotic subtypes
// #20 = the height in pixels
// #21 = the width in pixels
goto_pos(163)
#20=cur_char*256 // multiple the height high byte by 256
goto_pos(164)
#20=#20+cur_char // add the low byte
goto_pos(165)
#21=cur_char*256 // multiple the width high byte by 256
goto_pos(166)
#21=#21+cur_char // add the low byte
// get the height and width of a .gif file
// works with gif87a and gif89a
// has not been tested with animated gifs
// #20 = the height in pixels
// #21 = the width in pixels
goto_pos(7)
#21=cur_char*256 // multiple the width high byte by 256
goto_pos(6)
#21=#21+cur_char // add the low byte
goto_pos(9)
#20=cur_char*256 // multiple the height high byte by 256
goto_pos(8)
#20=#20+cur_char // add the low byte
// get the height and width of a .jpg, or .gif file
// combines the two above subroutines into one.
// #20 = the height in pixels
// #21 = the width in pixels
reg_set(10,file_ext)
if(reg_compare(10,".jpg")==0) {
goto_pos(163)
#20=cur_char*256 // multiple the height high byte by 256
goto_pos(164)
#20=#20+cur_char // add the low byte
goto_pos(165)
#21=cur_char*256 // multiple the width high byte by 256
goto_pos(166)
#21=#21+cur_char // add the low byte
}
if(reg_compare(10,".gif")==0) {
goto_pos(7)
#21=cur_char*256 // multiple the width high byte by 256
goto_pos(6)
#21=#21+cur_char // add the low byte
goto_pos(9)
#20=cur_char*256 // multiple the height high byte by 256
goto_pos(8)
#20=#20+cur_char // add the low byte
}
// template for a macro that needs to process multiple files in a directory
// and optionally it's subdirectories
// supports wildcards - assumes all files unless otherwise specified
// text register 10 holds the directory path - ie c:\letters
// text register 11 holds the filespec - ie *.doc
// numeric register #10 holds the "included subdirectories ?" flag : 0=no 1=yes
// text register 20 holds current directory path ie c:\letters
// text register 21 holds current filename ie moremoney.doc
// text register 22 holds the whole path and filename of current file ie c:\letters\moremoney.doc
// numeric register #30 holds starting buffer #
// numeric register #31 holds buffer # of temp buffer for dir listing
// initialize registers
#30=buf_num // save current buffer #
#31=buf_free // find a free buffer to hold dir listing
#10=0 // set include subdirectories flag to no
// get user input
get_input(10,"Enter Directory Path = ",nocr+statline) // get directory path
get_input(11,"Enter FileSpec = ",nocr+statline) // get filespec
if(reg_size(11)==0) {reg_set(11,"*.*")} // if no filespec, assume *.*
#10=get_num("Include Subdirectories ? 0=no 1=yes : ") // ask about subdirectories
// get directory listing
buf_switch(#31) // switch to temp buffer
buf_empty(ok) // empty it
file_save_as("c:\dirlist.tmp",nomsg+ok) // give it a filename to enable auto-buffering
reg_set(30,@10) // set t-reg 30 to directory path
reg_set(30,"\",append) // add a \
reg_set(30,@11,append) // add the filespec in t-reg 11
if(#10==1) {reg_set(30," -s",append)} // add the -s if subdirectory flag is set
out_ins() // re-direct output to temp buffer
directory(@30,suppress+count,1) // dump dir, one column, no subdir or hidden names
out_ins(clear) // turn off output re-direct
begin_of_file() // goto start of buffer
repeat(all) { // repeat loop 1
// get directory path
search("Directory ",advance+noerr) // search for word Directory
if(return_value==0) {break} // didn't find it, exit repeat loop 1
block_begin(cur_pos) // set block begin to current position
block_end(eol_pos) // set block end to end of line postion
reg_copy_block(20,block_begin,block_end) // shove directory path into t-reg 20
repeat(all) { // repeat loop 2
// get a filename
goto_line(cur_line+1) // goto start of next line
match("|F") // match letter or digit
if(return_value<>0) { // if no filename on current line, do
break // exit repeat loop 2
} // end of if
block_begin(cur_pos) // set block begin to current position
block_end(eol_pos) // set block end to end-of-line postion
reg_copy_block(21,block_begin,block_end) // shove filename into t-reg 21
reg_set(22,@20) // set t-reg 22 to current dir path
reg_set(22,"\",append) // add a \
reg_set(22,@21,append) // add current filename
buf_switch(#30) // switch back to original buffer
//--------------------------------------------------------------------------
// start of user's code to process filename in t-reg 22
// do not alter text or numeric registers in the range of 10 to 39
// demo code - delete before writing your code
reg_ins(22)
ins_newline(1)
update()
sleep(20)
// end of demo code
// end of user's code
//--------------------------------------------------------------------------
buf_switch(#31) // switch back to temp buffer
} // end of repeat loop 2
} // end of repeat loop 1
// macro shutdown
buf_switch(#31) // switch to temp buffer
buf_quit(ok) // kill it
buf_switch(#30) // goto original buffer
file_delete("c:\dirlist.tmp",ok+noerr) // delete temp file
block_begin(clear) // clear any stray block markers
update() // update screen - end of macro
Return to Table of Contents