'===========================================================================
' Subject: CHANGING DIRECTORY UTILITY         Date: 02-02-00 (10:56)       
'  Author: Hermann Seegert                    Code: PB                     
'  Origin: Hermann.Seegert@t-online.de      Packet: PB.ABC
'===========================================================================
 '
 '                      What is this about? It's a:
 '      "Directory changing program with user defined shortcuts!"
 '                          or, a little shorter:
 '              "Path changing done by (your own!) shortcuts"
 '                          or, even shorter:
 '                    "Path changing done by shortcuts"
 '                              **********
 '                              * Enjoy! *
 '                              **********
 ' Programed  by: Hermann Seegert, email: hermann.seegert@t-online.de
 '                 Programed with: PowerBASIC, Version 3.2
 '
 $lib all off
 $compile exe "we.exe"
 $string 8
 $if 0
   Look close to my comments in this listing. Perhaps not  everything
   is  mentioned  in the  help, which you get with WE /h or WE /H  in
   the compiled EXE- File!!

              ************* January 2000 !  *************

   I know, this program isn't  a  realy new idea, but I have got  the
   impression, the idea is new under DOS. Even if not: Have fun  with
   it, if you are a programming beginner, may be, you can learn some-
   thing from this program.
                     You can send me an email to:
                     hermann.seegert@t-online.de
   and  send  me  your critisism and all you want to say about WE.EXE
   (or any other stuff).

   What's this program  REALY about? It's a little directory changing
   program for DOS. The special  point  of this tool is, that you can
   define  a  shortcut  for  the  directory  you want to change with.
   Shortcuts  and paths are saved in a temporary file, which name de-
   pends  on how you name  the  EXE- File. If you call it X.EXE, then
   the temporary file is  called X.TMP. A second  TMP- file  will  be
   created, if you use the delete- function- in case of deleting  the
   directory  and  the  shortcut  would  be wrong then- and is called
   X.TM2 (if X.EXE!). All temporary files are saved in the directory,
   where you save the EXE- file.

   WE.BAS was programed with PowerBASIC, version 3.2. If you like the
   idea  and you don't have PowerBASIC and  you want to have the EXE-
   file; email  me, I'll  send you the  EXE- file (if there are thou-
   sands of people, who want to have this program, I can't do it; but
   this is a realy dream, I assume).

   I've named this program WE.EXE, because  I'm  german and these are
   the  first  two  letters  for  the  german word "Wechsel", english
   "change".  Also  it can be typed in rather easily. It doesn't make
   sense to rename WE.EXE in a name with e.g. 8 letters! I think, you
   understand, why!

                         Structure of WE.TMP:
                         --------------------
   S    P      (S=shortcut, P=Path)  /= the delimiter
   a/=c:\dos

   You can  use  any sign you want for a shortcut except of spaces on
   the left or right side of the shortcut (but allowed e.g. is: a d).
   TAB-  signs also are allowed. The longest "shortcut" is  9  signs,
     because longer shortcuts are no longer shortcuts, aren't they?

     Not allowed signs and sign- combinations for a shortcut are:
              /= , /+ , /l , /L, /h, /H und ~DEFAULT~
   It's  allowed to manipulate WE.TMP in an ASCII- editor. The editor
   must  be able to save  the changed  file as ASCII-  file! You  can
   write in comments  and  remarks, you only have to take care of the
   /= - sign- combination. Please note, that  there is a delete func-
   tion. This function  I think is very comfortable, but 'only' works
   with a TMP- file, which isn't  longer  than  2000  lines. So don't
               write in a whole book into that file, ok?

   If  you are german speaking, you can email me for a german version
                 of WE.EXE. There is no disadvantage!

   Now  a  word  for  all german speaking people, who can't speak en-
   glish. I tell them, that they can get a german version of WE.BAS.
    Ŀ
    Also: Wer deutsch lieber hat, besser kann oder mit meiner Mut-
    tersprache  sympathisiert  (was  gibt's noch fr Grnde?), der
    kann  die deutsche Version von WE.EXE bei mir anfordern unter:
                     hermann.seegert@t-online.de                  
    Wenn  nicht  Millionen  auf  die Idea kommen, bin ich da nicht
    kleinlich und schicke es via Email zu, aber das ist sicher nur
                            ein Traum!                            
    
 $endif
 defint a-z                                  'why more?
 %false=0                                    'boolean...
 %true=not %false                            'boolean...
 shared tmpfile$,prg_pure$                   'temporary path and PURE name
                                             'of program
 shared tmpfile2$                            'BAK- filename before executing
                                             'automatic deleting function
 shared desktop$()                           'screensaving variable
 dos$=command$
 '------------------- TEST INPUTS in the IDE of PB ------------------
 'dos$="/=c:\dos/+da"                        'TEST in IDE
 'dos$="/+d a/=c:\dos"                       'TEST in IDE
 'dos$="d"                                   'Test in IDE
 'dos$="/l=c:\dos"                           'Test in IDE
 'dos$="/l+d                                 'Test in IDE
 'dos$="/H"                                  'Test in IDE big help
 'dos$="/h"                                  'Test in IDE small help
 '-------------------------------------------------------------------
 u_dos$=ucase$(dos$)                         'important for delete- function
                                             'and the help...
 call temppath_and_progname                  'Programname and TMP- filenames
                                             '(WE.TMP and WE.TM2)
 if instr(u_dos$,"/H") then                  'help
   call shorthelp : end
 end if
 '------------------ check out the commandline ----------------------
 '
 'I know, there are parsers to check out such things like commandline
 'inputs  very  clearly,  but  often  these parsers are very big. Why
 'using  such  big  moduls, if some small lines do the same? Here the
 'commandline  isn't that big. In the whole there are only a very few
 'possibilities of input:
 '
 '/+(shortcut)         : setting actual path with your given shortcut
 '/+(shortcut)/=(path) : setting path together with a shortcut
 '/l=(path)            : deleting by giving a path
 '/l+(shortcut)        : deleting by giving a shortcut
 '
 'Ok,  there  is  one function, which is called: Make a new TMP- file
 'from the existing TM2- file, and this is:
 '/l=/
 'Probably  it  seems  to  be a complicated way of input, but keep in
 'mind,  that  it's  better  to use this then creating a new command.
 'This couldn't be used as a shortcut then.
 '
 'Some  words  for installation WE.EXE- after having compiled in with
 'PBC.EXE  or  in  the IDE of PB (probably it can be compiled with PB
 'Version  3.1  and PB version 3.5 too). Put it into a path, which is
 'declared in your autoexec.bat. All other installations have no sen-
 'se for this tool.
 '
 'Note:  In my opinion INSTR is a rather powerful way, to make a good
 'and also powerful IF- THEN structure in a program. In my commandli-
 'ne  there are three possibilities of input: /l , /= or /+ (well, we
 'can  neglect  the /h). First of all I will have a look, which input
 'is  real.  Then I go and ask again, if 'ispaththere' is there. BUT:
 'All that is only possible, because I can ask: IF where_x>2 THEN !
 '
 'One last  thing  I have to mention before going on with the code: I
 'haven't  translated ALL variables into those, which are more sense-
 'ful  for an  english speaking person. Anyway, I  think, if you  are
 'interested in my little program, you will find through, wan't  you?
 '
 dell=instr(u_dos$,"/L")                   'Deleting function of
                                           'paths or / and shorcuts
 where_x=instr(dos$,"/+")+2                'first /+ from the left(SHORTCUT)
 ispaththere=instr(dos$,"/=")+2            'first /= from the left (PATH)
 '--------------------- checking out wrong inputs -------------------
 if dell and where_x>2 then                'this would be add and delete!
   ? tab(5) "This is not possible: Either you add or" _
            " you delete or you change!"; : end
 elseif ispaththere>2 and where_x=2 then   'Path without shortcut
   path$=mid$(u_dos$,dell+3)               'let's see, how clever
                                           'the user was!
   ? tab(5) "For setting  a path you have forgotten the shortcut."
   if path$="" then
     ? tab(10) "You have forgotten to set a path!!!"
   end if
   ? tab(5) "You get help with >"+prg_pure$+" /H< on DOS- Prompt.";
   end
 end if
 '---- now we've checked the wrong inputs and we can get paths and
 '     strings ....
 if dell then                              'delete item ....
   'COMMAND  /l or /L FOR DELETING A PATH OUT OF WE.TMP (because of
   'a shortcut (/l+) OR  because of a PATH PFADES (/l=))..
   testsign$=mid$(dos$,dell+2,1)           'only + or = allowed!
   if testsign$="+" then                   'Deleting because of
                                           'shortcut.....
     shortcut$=mid$(dos$,dell+3)
     if shortcut$="~DEFAULT~" then
       ? tab(5) "You like to type very much, don't you? "_
                "It would be enough to"
       ? tab(5) "type >"+prg_pure$+"/+< to delete the default path.";
       end
     end if
     if shortcut$="" then shortcut$="~DEFAULT~" 'deleting default path
   elseif testsign$="=" then               'deleting because of given path
     path$=mid$(u_dos$,dell+3)
     if path$="/" then                     'TM2- file instead of TMP- file
       call takebackupfile : end
     end if
   else                                    'wrong input......
     ? tab(5) "The sign behind '/l' or '/L' must be "_
              "'+' or '='. For help"
     ? tab(5) "type in >"+prg_pure$+" /h< "+string$(30,46); : end
   end if
   testsign$=""                            'get out of memory.....
   call shortcutcheck(shortcut$,dell)      'check, if shortcut has
                                           'invalid signs.....
   path$=remove$(path$,any chr$(0,9,32,255)) 'Waste get out of path
   call delete_item(shortcut$,_            'the shortcut
                    path$)                 'the path
   end
 elseif where_x>2 then                     'WITHOUT where_x here the pro-
                                           'gram ends or you want to
                                           'change on a path (look down)
   'put in a path into the file................
   if ispaththere>2 then                   'Path- input on DOS- prompt..
     if where_x<ispaththere then           'first /+(shortcut), then /=(Path)
       shortcut$=mid$(dos$,where_x,ispaththere-where_x-2)
       path$=mid$(u_dos$,ispaththere)
     elseif ispaththere<where_x then       'Path- input on DOS- prompt....
                                           'first /=(Path), then /+(shortcut)
       shortcut$=mid$(dos$,where_x)
       path$=mid$(u_dos$,ispaththere,where_x-ispaththere-2)
     end if
     path$=remove$(path$,any chr$(0,9,32,255)) 'otherwise it will not work..
   elseif ispaththereabe<=2 then           'only /+
     shortcut$=mid$(dos$,where_x)
     path$=curdir$                         'PATH, if NO given Path on
                                           'Prompt: the actual path!
   end if
   call shortcutcheck(shortcut$,dell)      'check, if shortcut has invalid
   if shortcut$<>"" and path$<>"" then     'signs ONLY then input is valid
     call put_item_in_tmp(shortcut$,_      'the shortcut
                          path$)           'the path
   else
     ? tab(5) "There was occuring a mistake in your input. Type in"
     ? tab(5) ">"+prg_pure$+" /h< please.........................."; : end
   end if
 else                                      'neither /= , /+ , /l nor /L ...
                                           'and also no help (look above)
                                           'Then it's clear, that you want to
                                           'change on a directory with your
                                           'shortcut- input
   shortcut$=dos$
   if shortcut$="" then
     shortcut$="~DEFAULT~"                 'DEFAULT- shortcut for changing
                                           'on a path WITHOUT a shortcut!
   elseif shortcut$<>"" then
     call shortcutcheck(shortcut$,dell)    'check, if shortcut has invalid
                                           'signs.....
   end if
   call changing_path_part_one(shortcut$)  'change, "part 1"...
 end if
 end                                       'this is the END of the main
                                           'program.........
 '
 '********************* functions and procedures ********************
 '
 '----------------- add a path with a shortcut ----------------------
 '
sub put_item_in_tmp(shortcut$,_            'the shortcut
                    path$)                 'the path
  'next  finds  out,  if  there is still existing a shortcut for this
  'path or if the shortcut is still connected with a path...
  if dir$(tmpfile$,39)<>"" then            'it's a must before the
                                           'first item is set......
    open tmpfile$ for input as #1
      while not eof(1)
        line input #1,tmp$
        if instr(tmp$,"/=")=0 then iterate 'comments and empty lines
        'next question: Shortcut and path are already used together...
        if left$(tmp$,instr(tmp$,"/=")-1)=shortcut$ and _
          ucase$(mid$(tmp$,instr(tmp$,"/=")+2))=ucase$(path$) then
          ? tab(5) "The path"
          color 0,7 : locate ,5 : ? path$; : color 7,0
          ? tab(5) "has already the shortcut "; : color 0,7
          ? chr$(175)+shortcut$+chr$(174);
          color 7,0 : ? ". Please take an other one."; : end
        end if
        'shortcut is already taken for an other path............
        if left$(tmp$,instr(tmp$,"/=")-1)=shortcut$ then
          'next question is easy, but wrong!
          'if left$(tmp$,len(shortcut$))=shortcut$ then
          ? tab(5) "The shortcut you want to use is already used by path:"
          color 0,7 : locate,5 : ? mid$(tmp$,instr(tmp$,"/=")+2);
          color 7,0 : end
        end if
      wend
    close #1
  end if
  call put_in_tmp_file(shortcut$,path$)
end sub
 '
 '---------------------- delete an item -----------------------------
 '
sub delete_item(shortcut$,_                'the shortcut
                path$)                     'the path
  ' The  not  very  probable case must be catched: The case, that the
  ' file  tmpfile$ doesn't exist. If this file exists, then it's ne-
  ' cessary to check out, if it's not a file with 0 byte!
  local shortc_there,path_there,zeile,remarking,y&
  remarking=%false                         'for the case, that everything
                                           'is fine
  if dir$(tmpfile$,39)<>"" then            'file exists? Then check, if it's
    open tmpfile$ for input as #1          'a file with perhaps 0 bytes!
      y&=lof(1)
      if y&=0 then                         'file is there, but it's a file
        attrib tmpfile$,32                 'with 0 bytes: It can be deleted
        kill tmpfile$                      'and be used for our needs later.
        remarking=%true                    '(it's like a not existing file)
      end if
    close #1
  elseif dir$(tmpfile$,39)="" then         'file isn't there definitely?
    remarking=%true                        'then print a message!
  end if
  '--- Attention: All in all tmpfile$ can be 79 signs long! Therefore:
  '--- No margins!
  if remarking then                        'file NOT there....
    ? "File"
    color 0,7 : ? tmpfile$; : color 7,0 : print
    ? "isn't there! Type in >"+prg_pure$+" /h<.";
    end
  end if
  dim text(2000) as string                 'creating an array....
  zeile=0
  open tmpfile$ for input as #1
    while not eof(1)
      incr zeile
      if zeile>2000 then                   'not more than 2000 lines ...
        ? "Maximum number of lines in file"
        color 0,7 : ? tmpfile$; : color 7,0 : print
        ? "is 2000. If file has more lines, the "_
          "delete function can't work properly."
        ? "Type in >"+prg_pure$+" /h< .";
        end
      end if
      line input #1, text(zeile)
      if instr(text(zeile),"/=")=0 then iterate  'for comments!
      ' Check,  if  path or shortcut are in tmpfile$ or if the input
      ' of the user was bad.
      if shortcut$<>"" then                'deleting because of a given
                                           'shortcut...
        if left$(text(zeile),instr(text(zeile),"/=")-1)=shortcut$ then
          shortc_there=%true               'ah, shortcut there, fine
        end if
      elseif path$<>"" then                'deleting because of a given
                                           'path......
        if mid$(ucase$(text(zeile)),instr(text(zeile),"/=")+2)=path$ then
          path_there=%true                 'ah, path there, fine....
        end if
      end if
      '
    wend
  close #1
  '
  if path_there or shortc_there then       'path or shortcut for deleting
                                           'are existing in TMP- file!
    call make_copy_of_tmpdatei             'make a copy before deleting
                                           'tmpfile$ (security!).....
    'File  tmpfile$  is  not  allowed  to be deleted, because I will
    'overwrite it with OUTPUT...
    open tmpfile$ for output as #2         'open the same file again...
      for a=1 to zeile                     'zeile = max. length of text
        if instr(text(a),"/=")=0 then      'comments are not interesting
          ? #2,text(a)                     'for us....
          iterate for
        end if
        if shortcut$<>"" then              'deleting because of a given
                                           'shortcut...
          if left$(text(a),instr(text(a),"/=")-1)=shortcut$ then
            iterate for
          else
            ? #2,text(a)
          end if
        elseif path$<>"" then              'deleting because of a given
                                           'path...
          if mid$(ucase$(text(a)),instr(text(a),"/=")+2)=path$ then
            iterate for
          else
            ? #2,text(a)
          end if
        end if
      next
    close #2
  else                                     'no shortcut, no path or:
                                           'no path, no shortcut...
    if shortcut$="~DEFAULT~" then          'it was an empty input
      schreib$="there is no default directory at the "+_
               "moment. Type >"+prg_pure$+"/h < !"
    else
      if shortcut$<>"" then
        schreib$="there's no path for this shortcut!"
      elseif path$<>"" then
        schreib$="for this path there is no shortcut!"
      elseif path$="" then
        schreib$="you have to type in a path!"
      end if
    end if
    ? tab(5) "Joker, "+schreib$; : end
  end if
end sub
 '
 '----- copy the TMP- file to TM2 before using delete function ------
 '
sub make_copy_of_tmpdatei
  if dir$(tmpfile2$,39)<>"" then
    attrib tmpfile2$,32
    kill tmpfile2$                         'for new files it's better
                                           'this way!
  end if
  open "B",#1,tmpfile$                     'WE.TMP
  open "B",#2,tmpfile2$                    'WE.TM2
    while not eof(1)
      get$ #1,2048,txt$                    'reading WE.TMP
      put$ #2,txt$                         'write into WE.TM2
    wend
  reset
  attrib tmpfile2$,1                       'write protection ON
end sub
 '
 '--------------- the TM2- file is taken for TMP- file --------------
 '
sub takebackupfile
  local txt$,tmp&,tm2&
  'next line: bytes are only in an existing file :)
  tmp&=0 : tm2&=0                          'do it like in Turbo Pascal...
  if dir$(tmpfile$,39)<>"" then
    open tmpfile$ for input as #1
      tmp&=lof(1)
    close #1
  end if
  if dir$(tmpfile2$,39)<>"" then
    open tmpfile2$ for input as #2
      tm2&=lof(2)
    close #2
  end if
  '
  if tmp&>0 and tm2&>0 then                'here we have possibly a usable
                                           'result.....
    if tm2&<=tmp& then                     'less bytes in WE.TM2 than in
                                           'WE.TMP or the same number of
                                           'bytes ?!?
      call errormessages("1")              'this cannot be!
    end if
    'Now let's go.............
    attrib tmpfile$,32                     'sure is sure.........
    attrib tmpfile2$,32                    'sure is sure.........
    kill tmpfile$                          'has to go....
    name tmpfile2$ as tmpfile$             'rename it....
    '--- Message a-f-t-e-r deleting (ok, I mean renaming)........
    ? tab(5) "Your file "; : color 0,7 : ? prg_pure$+".TMP"; : color 7,0
    ? " was overwritten now by file "; : color 0,7 : ? prg_pure$+".TM2";
    color 7,0 : ? " and" : locate,5 : color 0,7 : ? prg_pure$+".TM2";
    color 7,0 : ? " was deleted! Take care if use the "_
    "delete function!"; : end
  else                                     'one file or both have no bytes!
    'First there  is  the possibility, that there  is  nothing in the
    'two files (neither in WE.TMP, nor in WE.TM2); if these files are
    '0- files, this doesn't matter anyhow ....
    if tmp&=0 and tm2&=0 then
      call errormessages("2")
    end if
    if tmp&=0 then                         'without TMP- file nothing goes..
      call errormessages("3")
    elseif tm2&=0 then                     'without TM2- file?
                                           'Nothing at all!
      call errormessages("4")
    end if
  end if
end sub
 '
 '----------------- errormessages for 'takebackupfile' ------------
 '
sub errormessages(welchemeldung$)
  select case welchemeldung$
    case "1"                               '-- In TM2 less than in TMP ???
      ? tab(5) "It  looks, as if there are only the same bytes or even less"
      ? tab(5) "bytes in file "; : color 0,7 : ? prg_pure$+".TM2";
      color 7,0 : ? " compared with file "; : color 0,7
      ? prg_pure$+".TMP"; : color 7,0 : ? "."
      ? tab(5) "But this isn't realy possible, except, you have changed the"
      ? tab(5) "file in an editor, and so I'm asking, why you've  done  so?"
      ? tab(5) "Well, it's sure, that file "; : color 0,7
      ? prg_pure$+".TM2"; : color 7,0 : ? " isn't the one, which"
      ? tab(5) "was saved on disk by "+prg_pure$+" before using "_
               " the delete func-"
      ? tab(5) "tion. There is no doubt about, you have to reconstruct the"
      ? tab(5) "file "; : color 0,7 : ? prg_pure$+".TMP"; : color 7,0
      ? " out of  your mind and have to pay more at-"
      ? tab(5) "tention in  future. Read my help by typing in ";
      color 15 : ? prg_pure$+" /h<"; : color 7
      ? " ."; : end
    case "2"                               '-- No TM* - files!
      ? tab(5) "The files "; : color 0,7 : ? prg_pure$+".TMP";
      color 7,0 : ? " and "; : color 0,7 : ? prg_pure$+".TM2";
      color 7,0 : ? " aren't there right now!"
      ? tab(5) "It seems to be, that  your have  installed "_
               prg_pure$+".EXE some"
      ? tab(5) "seconds ago, haven't you? And haven't you read"_
               " the help just"
      ? tab(5) "now  too? So  do it again! Type in >"+prg_pure$+" /h< on"_
               " DOS- prompt"
      ? tab(5) "and read the lines with more attention!"; : end
      end
    case "3"                               '-- No TMP- file....
      ? tab(5) "Without file "; : color 0,7 : ? prg_pure$+".TMP";
      color 7,0 : ? " it seems to be sure, that you don't know the"
      ? tab(5) "program until now. Read the helping "_
               "lines by typing >"+prg_pure$+" /H< !"; : end
    case "4"                               '-- no TM2- file....
      ? tab (5) "You never have deleted, otherwise there "_
                "would be a file "; : color 0,7 : ? prg_pure$+".TM2";
      color 7,0
      ? tab(5) "on  your PC. Or did you  type in just for fun ";
      color 0,7 : ? prg_pure$+" /l=/"; : color 7,0 : ? " ? Or did"
      ? tab(5) "you delete the  TM2- file  on  DOS-  prompt "_
               "seconds ago ? This"
      ? tab(10) "could have been a mistake! So type in  >"+prg_pure$+_
                " /h< again!"; : end
  end select
end sub
 '
 '--------------------- To change on a path -------------------------
 '
sub changing_path_part_one(shortcut$)
  ' Here  is  set the default- path if doesn't exist, the file tmpfi-
  ' le$ doesn't exist until now in this program....
  if dir$(tmpfile$,39)="" then
    dosline=csrlin                         'where is the cursor now?
    screenreadwrite "R",1                  'save the screen first...
    cls
    ? tab(9) "The file with the items doesn't exist by  now! You  can  set"
    ? tab(9) "the  actual path now as default- path by pressing ";
    color 0,7 : ? "ENTER"; : color 7,0 : ? ", you"
    ? tab(9) "may also leave now  by  pressing "; : color 0,7 : ? "ESC";
    color 7,0 : ? ". You get a little help,"
    ? tab(9) "if you type in >"+prg_pure$+" /h< on the DOS- prompt." : print
    do
      t$=inkey$
      if t$=chr$(13) then
        call defaultabfrage("~DEFAULT~",_  'Shortcut = Default
                            "",_           'Path is empty of course
                            %false,_       'Var.: wohinaufdemschirm
                            %false,_       'Var.: sichern
                            dosline)       'Cursor is in that line
        exit loop
      elseif t$=chr$(27) then
        ? tab(9) "Program ends, go on with ANY KEY........";
        call ending(dosline)               'End in this procedure
      end if
    loop
    end
  end if
  '
  open tmpfile$ for input as #2
    while not eof(2)
      line input #2,textt$
      if instr(textt$,"/=")=0 then iterate
      if shortcut$=left$(textt$,instr(textt$,"/=")-1) then
        on_this_path$=ltrim$(rtrim$(mid$(textt$,instr(textt$,"/=")+2),_
                      any chr$(0,9,32,255)),any chr$(0,9,32,255))
        exit loop
      end if
    wend
  close #2
  ' Special  case:  DEFAULT-  path  is not set, but here tmpfile$ is
  ' existing, but user was calling the program without a shortcut.
  call defaultabfrage(shortcut$,_          'the shortcut
                      on_this_path$,_      'path out of tmpfile$
                      %true,_              'place of the message
                      %true,_              'Scrennsaving? Here: yes
                      0)                   'Var. dosline=0, saving in
                                           'procedure 'defaultabfrage'
  call change_path(on_this_path$,shortcut$)
end sub
 '
 '------------------- path can be changed now -----------------------
 '
 ' So until now you know, that  you  can create  paths with shortcuts
 ' and  put  them  together into  a file, ok? If you call the program
 ' with a shortcut, combined with  a  path, you will change  on  that
 ' path,  BUT: You can arrange it, that  you  can  change  to several
 ' paths with  only  ONE shortcut. Assume, you have two partitions or
 ' harddisks or whatever in  this way. On the one drive there is e.g.
 ' a path named:
 '                      C:\TEST\WHERE\THERE\IS\NOTHING\TO\TEST
 ' On drive D you have a path named:
 '      D:\WHEN\IS\IT\TRUE\TEST\WHERE\THERE\IS\NOTHING\TO\TEST
 ' You now can set a shortcut- let's say 'x'- with the following path
 ' into TMP- file by typing:
 '                  WE /+x/=where\there\is\nothing\to\test
 ' Now  you can change to that ...TEST- directory on drive C by chan-
 ' ging first on C:\TEST and then typing in WE x , and on Drive D you
 ' have  to change an path d:\when\is\it\true\test and then typing WE
 ' x. Well, may be, my example isn't good, but I sometimes use WE.EXE
 ' in this way. Then there is the possiblity to type e.g.:
 '                  WE /+x/=\windows\command
 ' Assume, you have two drives with Win 9x, then you only have to set
 ' ONE  shortcut,  because  if  typing the path in this way, there it
 ' doesn't  matter, on which drive this path- over the ROOT- directo-
 ' ry!- is.
 ' I know, normally this has to be in the helplines, but I'm tired of
 ' writing  them..... sorry. I'm sure, I've forgotten something else,
 ' but if you want to know something: email me or study the code.
 '
sub change_path(on_this_path$,shortcut$)
  on local error resume next               'important!
  if on_this_path$="" then                 'NO valid shortcut!
    ? tab(5) "Sorry, but for the shortcut"
    color 0,7 : locate, 5 : ? chr$(175)+shortcut$+chr$(174); : color 7,0
    ? tab(5) "there is no path..........."; : end
  end if
  aktp$=curdir$                            'saving the act. directory;
                                           'very important, otherwise it
                                           'wouldn't work
  '---------------------- special Questions -------------------------
  if on_this_path$="\" then       '*** no mistake possible here :)...
    chdir "\" : end
  elseif left$(on_this_path$,1)="\" then   'path over ROOT;
                                           'the same drive...
    chdir on_this_path$
    if err<>0 then
      on_this_path$=left$(aktp$,2)+on_this_path$ 'complete Output
                                                 'for message
      call error_messages(on_this_path$,"Pfad ungltig; ")
    end if
    end
  end if
  '---------------------------- The rest ----------------------------
  if mid$(on_this_path$,2,1)=":" then      'changing drive is planed
    chdrive left$(on_this_path$,1)         'changing drive
    chdir on_this_path$                    'changing path
    if err<>0 then
      if err=71 then
        message$="Laufwerk ungltig; "
        chdrive mid$(aktp$,1,1)          'back to where you come from (drive)
        chdir mid$(aktp$,3)              'back to where you come from (path)
      else
        message$="Path invalid; "
      end if
      call error_messages(on_this_path$,message$)
      end
    end if
  else                                     'going f-r-o-m a path...
    on_this_path$=rtrim$(aktp$,"\")+"\"+_  'valid for ROOT a-n-d sub-
                     on_this_path$         'directories .....
    chdir mid$(on_this_path$,3)
    if err<>0 then
      call error_messages(on_this_path$,"Path invalid; ")
    end if
  end if
end sub
 '
 '------------------------ errormessage -----------------------------
 '
sub error_messages(on_this_path$,message$)
  ' Helping procedure for the Sub change_path; checking out, if the who-
  ' le path is to long.....
  local joke
  ? tab(5) message$+"the path"
  if len(on_this_path$)>66 then            'longer path impossible
    if len(on_this_path$)>74 then          'must be formatted, if 74!
      on_this_path$=left$(on_this_path$,3)+"..."+_
                       right$(on_this_path$,68)
    end if
    joke=%true                             'for a 'joke message'!
  end if
  color 0,7 : locate,5
  ? ucase$(on_this_path$); : color 7,0     'uni- like because of UCASE$
  if not joke then
    ? tab(5) "isn't still actual now "+string$(34,46); : end
  elseif joke then
    ? tab(5) "can't be created, you joker, because the  path is to long.";
    end
  end if
end sub
 '
 '-------------- request for setting the default path ---------------
 '
sub defaultabfrage(shortcut$,_             'the shortcut
                   on_this_path$,_         'the path (from tmpfile$)
                   wohinaufdemschirm,_     'place on the screen....
                   sichern,_               'Screensaving now? Then %true
                   dosline)                'Where is the cursor?
  '
  ' If  program  is called by it's name, then automatically ~DEFAULT~
  ' will be set from the program as the actual shortcut. The  path of
  ' course is empty  then. Therefore program is coming up to the next
  ' 'topic'....
  ' But  there  is  still an other case for the question, and that's,
  ' when  the  program  was installed just now. Then there also is NO
  ' default- path. Have a look in procedure:
  '            sub changing_path_part_one(shortcut$)
  '           Also in this case this procedure is called!
  '
  local abbruch
  if sichern then
    dosline=csrlin
    screenreadwrite "R",1
  end if
  if shortcut$="~DEFAULT~" and on_this_path$="" then
    if wohinaufdemschirm then cls : locate 5 'place the message...
    ? tab(9) "What's  that! There is no default- path by now, on which you"
    ? tab(9) "could  change  by typing in the name of this program! If you"
    ? tab(9) "would  like  to  have  the actual path as the default- path,"
    ? tab(9) "then simply press "; : color 0,7 : ? "ENTER"; : color 7,0
    ? ". If you want to select an other path"
    ? tab(9) "for the default- path, then  press "; : color 0,7
    ? "SPACE"; : color 7,0 : ? ". You want  to  exit"
    ? tab(9) "program? Then press "; : color 0,7 : ? "ESC";
    color 7,0 : ? ". Help you get with >"+prg_pure$+" /h<."
    do
      t$=inkey$
      if t$=chr$(13) then                  'Defaultpath = actual directory
        print : path$=curdir$
        exit loop
      elseif t$=chr$(32) then              'Defaultpfad = any other directoy
        print : cursorzeile=csrlin
        do
          locate cursorzeile
          ? tab(9) "Type in your wished default- "_
                   "path. Exit with ,"
          line input "        ";path$
          path$=remove$(ucase$(path$),any chr$(0,9,32,255))
          if path$="," then abbruch=%true  'ending then...
        loop until path$<>""
        exit loop
      elseif t$=chr$(27) then              'the end....
        abbruch=%true
        exit loop
      end if
    loop
    if abbruch then                        'Ending twice possible.....
      print
      ? tab(9) "Of  course  you  can  write down your default- path and each"
      ? tab(9) "other  path  with  an ASCII- editor. Noone is forced to make"
      ? tab(9) "his life easier! For help type in >"+prg_pure$+" /h<."
      ? tab(9) "...... It's going on by pressing ANY KEY ......"
      call ending(dosline)
    end if
    '--- Now program is writing path and shortcut in the TMP- file...
    call put_in_tmp_file(shortcut$,path$)  'put them in there!!
    ? tab(9) "Default- path now is:"
    color 0,7 : locate,9 : ? path$; : color 7,0
    ? tab(9) "You are changing on this directory "_
             "by typing "+prg_pure$
    ? tab(9) "............ PRESS ANY KEY ............"
    call ending(dosline)
  end if
end sub
  '
  '------------- put into the tmpfile$: shortcut$ + path$ -----------
  '
sub put_in_tmp_file(shortcut$,path$)
  local remarking,y&                       'Var: 'remarking': if it's first
  remarking=%false                         'time default for this variable
  if dir$(tmpfile$,39)<>"" then
    attrib tmpfile$,32                     'because nobody knows, how
                                           'file is attributed
    open tmpfile$ for input as #1
      y&=lof(1)                            'how many bytes?
      if y&=0 then remarking=%true         'then a little text must be
                                           'written into the new file...
    close #1
  elseif dir$(tmpfile$,39)="" then
    remarking=%true
  end if
  ' The  only combination of signs, which is not allowed for comments
  ' in tmpfile$  is /= , because for this  combination the program is
  ' looking for, if searching for valid path and shortcut....
  open tmpfile$ for append as #2
    if remarking then
      ? #2, "This  file belongs to program "+prg_pure$+".EXE. Before"
      ? #2, "you change this file or even delete, please read the help-"
      ? #2, "lines ! Type  in >"+prg_pure$+" /H< for  further  help."
      ? #2, "----------------------------------------------------------"
    end if
    ? #2,shortcut$+"/="+path$ 'And now it's all in the file.....
  close #2
end sub
 '
 '--------------- ending after request for default- path ------------
 '
sub ending(dosline)
  while not instat : wend
    x$=inkey$
    screenreadwrite "W",1
    locate dosline-1
    end
end sub
 '
 '----------- check, if invalid signs are in the shortcut -----------
 '
sub shortcutcheck(shortcut$,dell)
  shortcut$=ltrim$(rtrim$(shortcut$,any chr$(0,32,255)),_
           any chr$(0,32,255))             'better, because TAB is allowed
  if instr(shortcut$,"/+") or instr(shortcut$,"/=") or _
    instr(shortcut$,"/l") or instr(shortcut$,"/L") or _
    instr(shortcut$,"/h") or instr(shortcut$,"/H") or _
    instr(shortcut$,"~DEFAULT~") then
    if dell and instr(shortcut$,"~DEFAULT~") then exit if 'delete- function,
                                                         'so go out of here!
    ? tab(5) "There  are  signs  in your sign combination you were typing"
    ? tab(5) "in,  which are not allowed for a shortcut. Please not, that"
    ? tab(5) "the  following  sign  combinations  are  not  allowed for a"
    ? tab(5) "shortcut  and are not allowed IN a shortcut: /+ , /= , /l ,"
    ? tab(5) "/L , /h , /H and ~DEFAULT~. Type >"+prg_pure$+" /h<.";
    end
  end if
  ' if you don't like, you can  drop the  following IF-  request; but
  ' anyway: I  think  this  would lead you up to the point, where you
  ' can ask: What's the sense of  that (damned)  program?! A shortcut
  ' doesn't make much sense, if it's 20 Bytes long, doesn't it?
  if len(shortcut$)>9 then
    ? tab(5) "That's your shortcut?!? There are max. 9 signs possible for"
    ? tab(5) "a shortcut. Otherwise  you  could  type  the  path  itself,"
    ? tab(5) "couldn't you?"; : end
  end if
end sub
 '
 '-------------------- a short help for WE.EXE ----------------------
 '
sub shorthelp
  cr$="Hermann Seegert"
  call checksum(cr$,1464,"H",1,"S",9,"m",4,"g",12) 'for: Hermann Seegert
  play "l24mbcdecp16cdec"                  'you don't like? Drop it!
page1:
  cls : locate 1
  '***** LINE 1                            'I mark each line for a better
  locate ,12 : color 0,7                   'overview
  ? "  ***** Short help for WE.EXE ,"_
    " version 1.0, Freeware ***** "; : color 7,0 : print
  '***** LINE 2
  ? tab(5) "Please install WE.EXE in  a path, which is "_
           "in your AUTOEXEC.BAT! Note: You"
  '***** LINE 3
  ? tab(5) "can rename WE.EXE; the TMP- file then "_
           "is named e.g. X.TMP, if program name"
  '***** LINE 4
  ? tab(5) "is e.g. X.EXE. "; : color 15 : ? "WE /h (and /H)"; : color 7,0
  ? " : This  little  help. If you call WE.EXE the"
  '***** LINE 5
  ? tab(5) "first time, you are asked for  a default "_
           "path  input, a path, on which you"
  '***** LINE 6
  ? tab(5) "can change without any shortcut, the "_
           "most simple way of changing  a  path!"
  '***** LINE 7
  color 15 : locate ,5 : ? "WE /+(shortcut)"; : color 7
  ? " : Shortcut for the actual path is set. Example: You are on"
  '***** LINE 8
  ? tab(5) "path C:\TEST\TEST2 and type in: WE /+t . "_
           "Then you can change on this  path"
  '***** LINE 9
  ? tab(5) "in future by simply typing WE t . "; : color 15
  ? "WE /+(shortcut)/=(path)"; : color 7,0 : ? ": Path and short-"
  '***** LINE 10
  ? tab(5) "cut are set  in independence on the path you are (Note: ";
  color 15 : ? "/=.../+..."; : color 7 : ? " is also"
  '***** LINE 11
  ? tab(5) "possible, grin). You can arrange it, that you "_
           "can change to  several paths"
  '***** LINE 12
  ? tab(5) "with only  ONE shortcut. Assume, you  have "_
           "two  partitions or harddisks or"
  '***** LINE 13
  ? tab(5) "whatever  in  this  way. On  the  one drive "_
           "C there  is  e.g. a path named"
  '***** LINE 14
  ? tab(5) "C:\TEST\WHERE\THERE\IS\NOTHING\TO\TEST . "_
           "On drive D you have a path named:"
  '***** LINE 15
  ? tab(5) "D:\WHEN\IS\IT\TRUE\TEST\WHERE\THERE\IS\NOTHING\TO\TEST . You "_
           "now can set a"
  '***** LINE 16
  ? tab(5) "shortcut- let's say 'x'- with the "_
           "following path into TMP- file by typing:"
  '***** LINE 17
  ? tab(5) "WE /+x/=where\there\is\nothing\to\test . Now "_
           "you can change to  that TEST-"
  '***** LINE 18
  ? tab(5) "directory on drive C by changing first on "_
           "C:\TEST and then typing in WE x,"
  '***** LINE 19
  ? tab(5) "and on Drive D you have to change "_
           "an path D:\WHEN\IS\IT\TRUE\TEST and then"
  '***** LINE 20
  ? tab(5) "typing  WE x . Well, may  be, my  "_
           "example isn't good, but I sometimes  use"
  '***** LINE 21
  ? tab(5) "WE.EXE in this way. Then there "_
           "is the possiblity  to type e.g.:"
  '***** LINE 22
  ? tab(5) "WE /+x/=\windows\command. Assume, you  have  "_
           "two  drives with Win 9x, then"
  '***** LINE 23
  ? tab(5) "you only have to set ONE shortcut, "_
           "because if typing the path in this way,"
  '***** LINE 24
  ? tab(5) "there it doesn't matter, on which drive "_
           "this path- over the ROOT- directo-"
  '***** LINE 25
  call keypressed(dosline,"SECOND")   'go to page 2 or exit with ESC...
  cls
  '***** LINE 1
  locate ,5 : color 0,7 : ? "PAGE 2"; : color 7,0 : print
  '***** LINE 2
  ? tab(5) "ry!- is. "; : color 15 : ? "WE /l+(shortcut)"; : color 7,0
  ? " : Path, which is  set  to  this shortcut will be"
  '***** LINE 3
  ? tab(5) "deleted from TMP- file. "; : color 15 : ? "WE /l=(path)";
  color 7 : ? " : This  path and  all  shortcuts  for"
  '***** LINE 4
  ? tab(5) "this path will be deleted from TMP- file. "; : color 15
  ? "WE /+"; : color 7 : ? " : deleting  default  entry"
  '***** LINE 5
  ? tab(5) "out of TMP- file. "; : color 15 : ? "WE /l=/"; : color 7
  ? " : Make a new TMP- file  from  TM2- file, if  you"
  '***** LINE 6
  ? tab(5) "have used the delete function by "_
           "mistake!  TM2- file will ONLY be  created"
  '***** LINE 7
  ? tab(5) "after having used  the delete function. Instead  "_
           "of  small letters you can"
  '***** LINE 8
  ? tab(5) "type with capital  letters. Only  for  shortcuts "_
           "there  is a difference in"
  '***** LINE 9
  ? tab(5) "spelling. The TAB- signs are allowed; SPACES "_
           "and ASCII 0  and  255  cannot"
  '***** LINE 10
  ? tab(5) "be  used on the margins of a shortcut, only "_
           "between  two allowed signs. If"
  '***** LINE 11
  ? tab(5) "you want to set paths and  shortcuts  in TMP- file "_
           "with an editor, you can"
  '***** LINE 12
  ? tab(5) "do so, but pay attention for  correct writing! "_
           "If you set  comments, don't"
  '***** LINE 13
  ? tab(5) "use /= !! If TMP-file is getting  larger then  "_
           "2000 lines, delete function"
  '***** LINE 14
  ? tab(5) "will not work! For your shortcuts please "_
           "DON'T use the following signs:"
  '***** LINE 15
  locate ,5 : color 15 : ? "/= /+ /l /L /h /H and ~DEFAULT~"; : color 7
  ? ". If you are  changing WE, you are allowed,"
  '***** LINE 16
  ? tab(5) "of course. But then it would be nice from "_
           "you, if you'ld send  me an email"
  '***** LINE 17
  ? tab(5) "and tell me  about  your work! Of  course "_
           "all criticism, wishes or remarks"
  '***** LINE 18
  ? tab(5) "about WE are welcome, but I have to say, that  "_
           "I'm not responsible for any"
  '***** LINE 19
  ? tab(5) "soft- or hardware- damage (directly or indirectly) because "_
           "of this softwa-"
  '***** LINE 20
  ? tab(5) "re! Last note about hard- and software: Minimum for  "_
           "this program is a 386"
  '***** LINE 21
  ? tab(5) "CPU on an IBM PC with a DOS 3.3. 550 KB "_
           "conventional RAM  are recommanded."
  '***** LINE 22
  print
  '***** LINE 23
  ? tab(5) "COPYRIGHT(c) WE.EXE "+cr$+", Leopoldstr. 36,  32756 "_
           "Detmold,  Ger-"
  '***** LINE 24
  ? tab(5) "many,  Telefon: 05231 / 37964, email  "_
           "address: hermann.seegert@t-online.de"
  '***** LINE 24
  call keypressed(dosline," FIRST") 'go back to page 1 or exit with ESC...
  goto page1
end sub
 '
 '------- to change from one page to the other and ending help ------
 '
sub keypressed(dosline,page$)
  color 0,7 : locate ,8
  ? " *********** PRESS SPACE FOR "+page$+" PAGE OR ESC FOR "_
    "EXIT *********** ";
  color 7,0
  do
    t$=inkey$
    if t$=chr$(32) then
      exit loop
    elseif t$=chr$(27) then
      end
    end if
  loop
end sub
 '
 '---------- procedure checks out checksum of a string and ----------
 '         the correct place of some letters in this string
 '
 '  call checksum(cr$,1464,"H",1,"S",9,"m",4,"g",12) 'for: Hermann Seegert
sub checksum(cr$,checknumber,b1$,gr1,b2$,gr2,b3$,gr3,b4$,gr4) local
  for a=1 to len(cr$)
    cc$=mid$(cr$,a,1)
    check_sum=check_sum+asc(cc$)
  next
  'print check_sum : end
  'next is checking the sum and the place of 4 letters
  if check_sum<>checknumber or _
    instr(cr$,b1$)<>gr1 or _  '*** check the correct place of 1. letter
    instr(cr$,b2$)<>gr2 or _  '*** check the correct place of 2. letter
    instr(cr$,b3$)<>gr3 or _  '*** check the correct place of 3. letter
    instr(cr$,b4$)<>gr4 then  '*** check the correct place of 4. letter
    screen 0                  '*** a must, if grafik
    cls : color 0,7 : locate,5
    ? "THE PROGRAM is ILLEGAL and was PATCHED, "_
      "signed by the correct author!"; : end
  end if
end sub
 '
 '---------- screen saving and screen writing procedure -------------
 '
sub screenreadwrite (modus$,Seite)         'SAVE-SCREEN as STRING$
  'li=  number of lines
  'desktop$() is forced to be a shared- variable...
  if (pbvScrnCard and 1)=0 then
    def seg=&HB800                         'color
  else
    def seg=&HB000                         'black/white
  end if
  if li=25 then n=4 else n=8         'page 1 and 2 allowed, otherwise
  if modus$="R" then                 'increase DIM S$
    for i=1 to n                     'screenpage at 25 / 28 - 50
      desktop$(seite*i)=peek$((i-1)*1000,1000) 'lines splitted on 4/8
    next                                       'strings, therefore $STRING
  else  'jetzt auf "W"                         'could be on 1 !
    for i=1 to n
      poke$ (i-1)*1000,desktop$(seite*i)
    next
  end if
end sub
 '
 '-------- program name and path for TMP- file and TM2- file --------
 '
sub temppath_and_progname
  local tmp$,p_name$,where_bs,praefix$
  ! mov ax,&h6200
  ! int &h21
  ! mov es,bx
  ! mov ax, word ptr es:[&h2c]
  ! mov pbvDefSeg, ax
  for i=0 to 1024
    if peek$(i,4)=chr$(0,0,1,0) then exit for
  next
  while peek(i+4)<>0
    Tmp$=Tmp$+chr$(peek(i+4))              'everything is in there!
    incr i
  wend
  def seg
  'next  for-next- loop is an instr- function from right side in it's
  'most simple way. But for our needs it's well and quick enough too!
  for where_bs=len(tmp$) to 1 step -1
    if mid$(tmp$,where_bs,1)="\" then exit for  'first \ from right...
  next where_bs
  ' The variables prg_pure$  and  tmpfile$ and tmpfile2$ are set SHA-
  ' RED in the  header  of  the  listing. The  variable 'where_bs' is
  ' good for all, which is important to know.
  p_name$=mid$(tmp$,where_bs+1)            'Name of program (with .EXE)
  prg_pure$=left$(p_name$,instr(p_name$,".")-1) ' PURE name
  praefix$=left$(tmp$,len(tmp$)-4)
  tmpfile$=praefix$+".TMP"                 'creating TMP- file...
  tmpfile2$=praefix$+".TM2"                'TM2- file for backup
                                           'TMP- file before using
                                           'delete- function!
end sub
 '
 '*************************** EOF ***********************************
