home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 03 / dolib.bas < prev    next >
BASIC Source File  |  1991-04-16  |  6KB  |  119 lines

  1. '***********************************************************************
  2. '                              DOLIB.BAS                               *
  3. '    DOLIB is a program to update the private libraries used with      *
  4. ' Microsoft BASIC compiler (BC) version 7.  It adds (or replaces)      *
  5. ' named modules to the private searchable libraries, PB.LIB and        *
  6. ' PBF.LIB, by constructing and then running a batch file.  The batch   *
  7. ' file also runs the compiled BASIC program PBBI.EXE to update the     *
  8. ' declaration header file, PB.BI.                                      *
  9. '    The command-line call is "DOLIB [<path>]<modname>"                *
  10. '           where <modname> is the name of the module to be added.     *
  11. '                 <path> is required if the source-code file for       *
  12. '                        <modname> is not in a directory in the PATH   *
  13. '                        environment string.                           *
  14. '    If the source file for <modname> is <modname>.ASM, DOLIB will be  *
  15. ' assembled before adding it to both libraries.  If the source file is *
  16. ' <modname>.BAS, the file will be compiled twice: in default mode for  *
  17. ' PB.LIB, and for "far strings" for PBF.LIB.  If the BASIC source file *
  18. ' contains local error trapping, the compilation will be made with the *
  19. ' "/E" switch.                                                         *
  20. '    DOLIB updates copies of the libraries and header file in the      *
  21. ' default directory.  If any of these files is not in the default      *
  22. ' directory, DOLIB will copy it from the directory named in the LIB or *
  23. ' INCLUDE environment string.  If <modname> already exists in either   *
  24. ' library copy, it will be replaced by the new version.  An existing   *
  25. ' SUB or FUNCTION declaration statement in the PB.BI file for the same *
  26. ' procedure name will be replaced.                                     *
  27. '----------------------------------------------------------------------*
  28. '               Written by M. L. Lesser, April 14, 1990                *
  29. '                 Compiled with BC v. 7.1, switch "/O"                 *
  30. '        Linked to COMMAND, FINDFILE, NOCOM, NOLPT, and NOFLTIN        *
  31. '                        with switches "/E/NOE"                        *
  32. '***********************************************************************
  33.  
  34.     DEFINT I
  35.     DEFSTR E,F,M,P,T
  36.     DECLARE FUNCTION FINDFILE$ (A$)
  37.     DECLARE FUNCTION MAKNAME$ (A$)
  38.     DECLARE SUB COMMAND (A$)
  39.  
  40. '  Local subroutine to write $$$.BAT command that copies file from
  41. '    directory designated in Environment string to default directory:
  42. SUB WRITIT(ENVIRONMENT, FILENAME)
  43.     LET PATH = ENVIRON$(UCASE$(ENVIRONMENT))
  44.     IF RIGHT$(PATH,1) <> "\" THEN LET PATH = PATH + "\"
  45.     PRINT #1, "COPY " PATH FILENAME
  46. END SUB 
  47.  
  48.     COLOR 2,0                           'Dealer's choice
  49.     CLS
  50.     PRINT TAB(20) "Private Library Update Program for BC 7"
  51.     PRINT STRING$(80,"-")
  52.     LET TEXT = COMMAND$                 'Get <modname> from command line
  53. ' Make sure there is a <modname> to add:
  54.     WHILE LEN(TEXT) = 0
  55.         LINE INPUT "Enter [<path>]<modname> for update:  "; TEXT
  56.     WEND
  57.     LET I = INSTR(TEXT,".")             'Remove any extension
  58.     IF I <> 0 THEN LET TEXT = LEFT$(TEXT,I-1)
  59.     LET MODNAME = LCASE$(MAKNAME(TEXT))
  60.     PRINT "Adding Module " CHR$(34) MODNAME CHR$(34);
  61.     PRINT " to private libraries PB.LIB and PBF.LIB."
  62.     PRINT
  63.     OPEN "$$$.BAT" FOR OUTPUT AS #1
  64.     PRINT #1, "@ECHO OFF"               '"@" requires DOS 3.3 (or later)
  65. ' Check for private libraries and header file in default directory:
  66.     IF LEN(DIR$("PB.LIB")) = 0 THEN CALL WRITIT("LIB","PB.LIB")
  67.     IF LEN(DIR$("PBF.LIB")) = 0 THEN CALL WRITIT("LIB","PBF.LIB")
  68.     IF LEN(DIR$("PB.BI")) = 0 THEN CALL WRITIT("INCLUDE","PB.BI")
  69. ' Try assembled module first:
  70.     LET FILE = FINDFILE(UCASE$(TEXT) + ".ASM")
  71.     IF LEN(FILE) <> 0 THEN              'Assemble it
  72.         PRINT #1, "MASM " FILE ";"
  73.     ELSE
  74.         LET FILE = FINDFILE(UCASE$(TEXT) + ".BAS")
  75.         IF LEN(FILE) <> 0 THEN
  76.             OPEN FILE FOR INPUT AS #2      'Read first, to check for
  77.             WHILE NOT EOF(2)               ' local error trapping
  78.                 LINE INPUT #2, TEXT        'Variable name is reused
  79.                 IF INSTR(UCASE$(TEXT),"LOCAL ERROR GOTO") THEN
  80.                     LET FILE = FILE + "/E"
  81.                     GOTO DONE
  82.                 END IF
  83.             WEND
  84. DONE:       CLOSE #2
  85.             PRINT #1, "BC " FILE ";"
  86.         ELSE                            'Abnormal end if not source file
  87.             PRINT TAB(5) "Source code for " CHR$(34) MODNAME CHR$(34);
  88.             PRINT " module not found.  Terminating program."
  89.             CLOSE #1
  90.             KILL "$$$.BAT"
  91.             END
  92.         END IF
  93.     END IF
  94.     PRINT #1, "IF ERRORLEVEL 1 GOTO END"        'Assemble/compile error
  95. ' Replace/Add module in PB.LIB (near strings):
  96.     PRINT #1, "LIB PB-+" MODNAME ",PB.IDX;"
  97.     PRINT #1, "IF ERRORLEVEL 1 GOTO END"
  98. ' If module was compiled, recompile for far strings for PBF.LIB
  99.     IF MID$(FILE,INSTR(FILE,"."),4) = ".BAS" THEN
  100.         PRINT #1, "BC " FILE "/Fs;"
  101.         PRINT #1, "IF ERRORLEVEL 1 GOTO END
  102.     END IF    
  103. ' Replace/Add module in PBF.LIB (far strings):
  104.     PRINT #1, "LIB PBF-+" MODNAME ",PBF.IDX;" 
  105.     PRINT #1, "IF ERRORLEVEL 1 GOTO END
  106. ' Clean up default directory by removing object file:
  107.     PRINT #1, "DEL " MODNAME ".OBJ"
  108. ' Update PB.BI header file after deleting "/E" switch from file:
  109.     LET I = INSTR(FILE,"/")
  110.     IF I THEN LET FILE = LEFT$(FILE,I-1)
  111.     PRINT #1, "PBBI " FILE
  112. ' Closeout
  113.     PRINT #1, ":END"
  114.     PRINT #1, "DEL $$$.BAT";
  115.     CLOSE #1
  116.     LET FILE = ENVIRON$("COMSPEC")      'Use COMMAND.COM
  117.     CALL COMMAND("/C $$$")              '  to run $$$.BAT
  118.     RUN FILE
  119.