@setdos /x0 @echo off %+ setlocal %+ unalias * :: :: 4TAG v2.0c 24/Oct/95 :: :: Tagline manager by Wade Bowmer, FidoNet 3:712/505.17 :: :: Based on an idea and 4TAG.BTM from Douglas King, FidoNet 1:163/543.1 :: which was originally posted in the International 4DOS echo. :: :: Coding notes: :: 1. I have used %+ and %= instead of the normal characters :: so I don't have to figure them out and reset them. :: 2. I have structured the code like any other structured programming :: language. This means use of IFF..ENDIFF rather than IF in a lot :: of cases. It also means that there are very few lines beyond 70 :: characters. The ones that are are usually alias definitions. :: 3. Note the UNALIAS * at the start; this solves one fundamental :: problem that all 4DOS application batch files face: local name :: spaces. It also improves speed. The small number I have defined :: are to make the language's control structures slightly easier :: to read. (Yes, I know, the first two make command groups unavailable. :: This is okay; I don't use them in this file.) :: alias if( `iff %& then` alias ) endiff alias done enddo :: 4DOS version checking. 4TAG requires 4DOS 5.5 or 4OS/2 2.5 if( %_4VER lt 5.5 .or. %_DOS == OS2 .and. %_4VER lt 2.5 echo 4TAG requires 4OS/2 2.5 or 4DOS 5.5 or above. echo You are using version 4%_DOS %_4VER quit ) :: Help screen check. if %# == 0 goto :helpscreen :: SETDOS settings. Hmmm. Douglas went to a lot of trouble to find and :: record everything, but after thinking about it, I don't really see :: the point - or the need! I mean, how many people normally run with :: something other than SETDOS /X0 ? I will just set it as I like. setdos /X0 :: Housekeeping. set MENUCLR=bri cya on cya set MENUITEM=bri whi on cya set MENUKEY=blu on cya :: Setup the routines. gosub :setup_routines cls whi on bla %+ message Loading 4TAG... if "%TAGFILES" == "" set TAGFILES=%@path[%DFLT4TAG]*.tag if( "%@path[%TAGFILES]" == "" .and. not exist %TAGFILES if( "%DFLT4TAG" == "" set TAGFILES=%@path[%0]%%@filename[%TAGFILES] else set TAGFILES=%@path[%0]%%@filename[%DFLT4TAG] ) ) :: Command line. set OPT=%1 do while "%@instr[0,1,%OPT]" == "/" set AOPT=%@word[":",0,%OPT] if "%AOPT" == "/LIMIT" set LIMIT=%@word[":",1,%OPT] echo Invalid Option "%AOPT" shift %+ set OPT=%1 :: Clever use of SHIFT, eh? done unset /q OPT AOPT set MESGFILE=%1 if( "%MESGFILE" == "" echo Message file parameter is missing. pause %+ quit ) if( not exist %MESGFILE echo The message file %MESGFILE does not exist. pause %+ quit ) :: Check to see if we need to call the editor. :editmesg if( "%2" ne "" message Calling your message editor... set STAMP=%@filedate[%MESGFILE],%@filetime[%MESGFILE] set > 4tag.set %+ alias > 4tag.als endlocal %2& %1 setlocal unalias * %+ alias /r 4tag.als %+ set /r 4tag.set del /q 4tag.als 4tag.set if "%STAMP" eq "%@filedate[%MESGFILE],%@filetime[%MESGFILE]" quit ) :: This alias allows for some cleanup to occur. alias quit goto :quit :: This bit rewrites the to/from rubbish in your reply message to :: something a little more interesting. Of course, it relies on your :: message beginning with :: something I've gotta figure out yet :-) :quoteheader rem quit :taglines drawtitle :: Find existing taglines. :: This copies the message file to a temporary copy, and finds the false tear :: line in the original file. message Opening %@upper[%MESGFILE] ... %+ color gre on bla set COPY=%@unique[%@path[%MESGFILE]] %+ copy /q %MESGFILE %COPY set Z=%@filesize[%MESGFILE,b] %+ set X=%@if[%Z lt 500,0,%@eval[%Z - 500]] set Q=%@fileopen[%MESGFILE,read] %+ set HERE=%@fileseek[%Q,%X,0] set Z=%@eval[%Z\100+1] unset /q TEARAT TAGCNT WRITEAT setdos /X-4568 set LIN=%@fileread[%Q] do while "%LIN" ne "**EOF**" scrput %@dec[%_ROWS] 76 gre on bla %@eval[%HERE\%Z]%% if( "%@instr[0,4,%LIN]" == "--- " set TEARAT=%HERE leave ) if "%TAGCNT" ne "" set TAGCNT=%@inc[%TAGCNT] if( "%@instr[0,11,%LIN]" == "___ 4TAG v2" set R=%@fileopen[%COPY,append] set X=%@fileseek[%R,%HERE,0] set X=%@filewrite[%R,___ 4TAG v2.0c 24/Oct/95] set X=%@fileclose[%R] set TAGCNT=0 ) set HERE=%@fileseek[%Q,0,1] set LIN=%@fileread[%Q] done screen %@dec[%_ROWS] 75 100%% setdos /X0 if "%TAGCNT" == "" set TAGCNT=0 if "%TEARAT" == "" set TEARAT=%@fileseek[%Q,0,1] set WRITEAT=%TEARAT set X=%@fileclose[%Q] unset X Z :: show the number of taglines in the message message The message has %TAGCNT tagline(s). if "%LIMIT" ne "" .and. %TAGCNT ge %LIMIT quit if( "%DFLT4TAG" == "" message Select your tagfile. gosub :choosefile else set TAGFILE=%DFLT4TAG ) :: main menu :tagmenu drawtitle %+ message The message has %TAGCNT tagline(s). setdos /X-4 unset /q _K menu 1 36 9 75 menuitem 0 Add a Tagline menuitem 0 Change Tagfile menuitem 7 Change Tagfile, then add a tagline menuitem 11 Add from a different Tagfile menuitem 18 Pick a tagline at random menuitem 8 Enter a new tagline menuitem 1 Exit 4TAG scrput %@eval[%_ROWS-5] 1 whi on blu Current Tagfile: scrput %@eval[%_ROWS-5] 18 bri whi on blu %@instr[0,40,%@descript[%TAGFILE]] :getkey setdos /X0 getitem if "%CMD" == "@28" set CMD=A markitem 1 38 36 if "%CMD" == "X" .or. "%CMD" == "" quit if( "%CMD" == "C" message Select your tagfile. gosub :choosefile ) if( "%CMD" == "T" message Select your tagfile. The message has %TAGCNT taglines. gosub :choosefile message Pick a tagline. The message has %TAGCNT taglines. gosub :choosetags setdos /x-4568 if "%TAGLINE" ne "" gosub :addtags setdos /x0 ) if( "%CMD" == "D" set OLDTAGFILE=%TAGFILE message Select your tagfile. The message has %TAGCNT taglines. gosub :choosefile message Pick a tagline. The message has %TAGCNT taglines. gosub :choosetags setdos /x-4568 if "%TAGLINE" ne "" gosub :addtags setdos /x0 set TAGFILE=%OLDTAGFILE %+ unset OLDTAGFILE ) if( "%CMD" == "A" .or. "%CMD" == "@28" message Pick a tagline. The message has %TAGCNT tagline(s). gosub :choosetags setdos /x-4568 if "%TAGLINE" ne "" gosub :addtags setdos /x0 ) if( "%CMD" == "R" do until "%CMD" == "N" message Picking a line from the current tagfile ... set X=%@random[0,%@lines[%TAGFILE]] setdos /x-4568 set TAGLINE=%@line[%TAGFILE,%X] scrput 17 1 bri whi on blu %TAGLINE setdos /x0 message The message has %TAGCNT tagline(s). menu 10 1 14 24 menuitem 0 Yes, put this one in menuitem 0 No, forget the idea menuitem 0 Pick another one getitem %+ drawtitle if( "%CMD" == "Y" message Adding tagline ... gosub :addtags %+ leave ) done goto :tagmenu ) if( "%CMD" == "N" gosub :addtagline goto :tagmenu ) goto :tagmenu :: Add a *new* tagline. :addtagline scrput 14 1 whi on blu Enter your new tagline! (Limit of 75 characters.) scrput 17 0 bri whi on blu ... color bri whi on blu %+ screen 17 4 input /L75 %%TAGLINE drawbox 17 0 17 79 0 blu on blu fill blu setdos /x-4568 scrput 17 0 bri whi on blu ... %TAGLINE setdos /x0 menu 8 1 12 27 menuitem 0 Yes, add it and use it menuitem 0 Add it without using it menuitem 0 No, forget the idea getitem %+ markitem 8 3 22 %+ rem drawtitle if( "%CMD" != "N" message Adding tagline to tagline file ... gosub :tag2file if "%CMD" == "Y" gosub :addtags ) return :: Choose a tagline. :choosetags setdos /x0 if( %@filesize[%TAGFILE] == 0 message Tagline file is empty. Press any key. beep %+ inkey /p /x %%X return ) setdos /x-4568 set X=%@eval[%@int[%@eval[(%_ROWS-1)/10]]*10+2] set TAGLINE=%@select[%TAGFILE,2,2,%X,77,Choosing from %@descript[%TAGFILE]] setdos /x0 return :: Open the files. :addtags setdos /X0 set Q=%@fileopen[%COPY,append] set X=%@fileseek[%Q,%WRITEAT,0] :: Add the new tagline setdos /x-4568 if %TAGCNT == 0 set X=%@filewrite[%Q,___ 4TAG v2.0c 24/Oct/95] set X=%@filewrite[%Q,... %TAGLINE] setdos /x0 set WRITEAT=%@fileseek[%Q,0,1] :: Close the file! set X=%@fileclose[%Q] set TAGCNT=%@inc[%TAGCNT] return :: This bit lets you choose from a number of files. :choosefile setdos /X0 set X=%@unique[%@path[%MESGFILE]] %+ set Z=%@unique[%@path[%MESGFILE]] dir %TAGFILES /b /[s0,63k] >%Z if( %@filesize[%Z] == 0 message No tagfiles. pause del /q %X %Z %+ unset /q X Z return ) for %a in (@%Z) echo>>%X %@format[12,%a] %@descript[%a] set Q=%TAGFILE set TAGFILE=%@select[%X,5,3,20,77,Select a tagline file] if( "%TAGFILE" == "" set TAGFILE=%Q else set TAGFILE=%@path[%TAGFILES]%@trim[%@instr[0,13,%TAGFILE]] ) del /q %X %Z %+ unset /q Q X Z return :: Add TAGLINE to a tagfile. :tag2file set R=%@fileopen[%TAGFILE,append] setdos /x-4568 set X=%@filewrite[%R,%TAGLINE] setdos /x0 set X=%@fileclose[%R] return :: General routines. :: These are accessed by aliases which set parameters to PASS and then :: gosub the relevant routine. :setup_routines alias drawtitle=gosub :draw_title alias message `set PASS=%& %+ gosub :message` alias menu `set _R=%1 %+ drawbox %_R %2 %3 %4 2 %MENUCLR fill %@word[-0,%MENUCLR] shadow %+ unset /q _K %+ set _C=%@eval[%2+2]` alias menuitem `set _R=%@inc[%_R] %+ scrput %_R %_C %MENUITEM %2& %+ scrput %_R %@eval[%_C+%1] %MENUKEY %@instr[%1,1,%2&] %+ set _K=%_K%%@instr[%1,1,%2&]` alias getitem `gosub :getitem` alias markitem `set _R=%@eval[%1+%@index[%_K,%CMD]+1] %+ scrput %_R %2 bri whi on red %@readscr[%_R,%2,%3] %+ unset /q _R` return :draw_title cls whi on blu drawbox 1 2 3 27 1 bri gre on gre fill gre shadow scrput 2 4 bri whi on gre 4TAG scrput 2 9 bri gre on gre v2.0c 24/Oct/95 return :message drawbox %@dec[%_ROWS] 0 %@dec[%_ROWS] 79 0 bla on bla scrput %@dec[%_ROWS] 0 gre on bla %PASS unset PASS %+ return :getitem set _K=%@upper[%_K] do until %@index[%_K,%CMD] ge 0 unset /q CMD %+ inkey /x /p %%CMD set CMD=%@upper[%CMD] done return :: Quit code :quit unalias quit :: If there were taglines, then copy the tear and origin lines. :: If it was copied... if( "%COPY" ne "" :: .and. "%TAGCNT" ne "" message Closing %@upper[%MESGFILE] ... set Q=%@fileopen[%COPY,append] set X=%@fileseek[%Q,%WRITEAT,0] set R=%@fileopen[%MESGFILE,read] set X=%@fileseek[%R,%TEARAT,0] setdos /X-4568 set LIN=%@fileread[%R] do while "%LIN" ne "**EOF**" set X=%@filewrite[%Q,%LIN] set LIN=%@fileread[%R] done setdos /X0 set X=%@fileclose[%Q] set X=%@fileclose[%R] copy /q %COPY %MESGFILE del /q %COPY %+ unset COPY ) cls %+ quit :: Code jumps here when it has no choice but to abort. :abort unalias quit echo 4TAG v2 must abort! > con quit :: This is the help screen. :helpscreen text 4TAG v2.0c 24/Oct/95 Tagline manager by Wade Bowmer, 3:712/505.17 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Usage 4TAG [options] messagefile [editor [parameters]] This will allow you to add taglines to the specified message file. If you specify your editor, it will run your editor first. The name of the messagefile will be placed after any parameters supplied. If you exit the editor without saving the messagefile, 4TAG will automatically exit. Options: /LIMIT:x will cause 4TAG to automatically exit if the message already has x or more taglines. Taglines are, by default, *.tag. To change this, define TAGLINES to be the file mask. Use DFLT4TAG to point to the default tagfile. If you specify a directory, all tagline files will be sought there instead of in the current directory. Acknowledgements to Douglas King, 1:163/543.1, for the original 4TAG. endtext quit