home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / homonlib.zip / BMAKE.BAS next >
BASIC Source File  |  1995-04-13  |  10KB  |  389 lines

  1. '****************************************************************************
  2. '********************               BMAKE                ********************
  3. '********************            Version 1.0             ********************
  4. '********************                by                  ********************
  5. '********************         Raymond W. Marron          ********************
  6. '********************      HOMONCULOUS PROGRAMMING       ********************
  7. '********************             Mesa, AZ               ********************
  8. '****************************************************************************
  9.  
  10. 'Be sure to load the HOMONLIB.QLB upon startup: QB /L HOMONLIB.QLB BMAKE.BAS
  11.  
  12. 'Compile as follows: BC BMAKE /O/S/T  (or from the RUN menu)
  13.  
  14. '*************************** Constants/Includes *****************************
  15.  
  16. DEFINT A-Z
  17.  
  18. ' $DYNAMIC
  19. ' $INCLUDE: 'DIR.INC'
  20. ' $INCLUDE: 'TRUEFALS.INC'
  21.  
  22. '*************************** LIB/QLB Procedures *****************************
  23.  
  24. 'This is a special function to return an errorlevel code to DOS when exiting
  25. 'the program.  DO NOT USE THIS COMMAND IN THE INTERPRETER!
  26. 'Unremark this line and the one in SUB ErrExit ONLY when ready to compile.
  27.  
  28. 'DECLARE SUB EndLevel ALIAS "_exit" (BYVAL Level%)
  29.  
  30. '**************************** Local Procedures ******************************
  31.  
  32. DECLARE SUB ErrExit ()
  33. DECLARE SUB MakeBatch ()
  34. DECLARE SUB ParseCmd ()
  35. DECLARE SUB ReadFile ()
  36. DECLARE SUB Startup ()
  37.  
  38. '************************ Define Global Variables ***************************
  39.  
  40. DIM SHARED DirInfo AS DirType
  41. DIM SHARED report
  42. DIM SHARED batch$
  43. DIM SHARED errfile$
  44. DIM SHARED maxfiles
  45. DIM SHARED maxcmds
  46. DIM SHARED makefile$
  47. DIM SHARED compiler$
  48. DIM SHARED options$
  49. DIM SHARED nf                           'Number of files in .BMK file
  50. DIM SHARED nc                           'Number of commands in .BMK file
  51.  
  52. '******************** Assign Values to Misc Variables ***********************
  53.  
  54. batch$ = "_~BMAKE_.BAT"
  55. errfile$ = "_~BMAKE_.ERR"
  56. compiler$ = "BC"
  57. maxfiles = 100
  58. maxcmds = 10
  59.  
  60. '***************************** Launch Program *******************************
  61.  
  62. ParseCmd                           'Translate the command line to know how
  63.                             'large the arrays need to be dimensioned.
  64. DIM SHARED object$(1 TO maxfiles)
  65. DIM SHARED source$(1 TO maxfiles)
  66. DIM SHARED option$(1 TO maxfiles)
  67. DIM SHARED cmd$(1 TO maxcmds)
  68.  
  69. Startup                            'Find the makefile.
  70. ReadFile                           'Read/parse it's contents.
  71. MakeBatch                          'Transfer the comparisons to a batch file.
  72.  
  73. ERASE object$                      'Free up the memory used by the arrays.
  74. ERASE source$
  75. ERASE option$
  76. ERASE cmd$
  77.  
  78. f$ = Dir$(batch$, DirInfo)         'Run the batch file that contains all of
  79. IF LEN(f$) THEN                    'the commands (if it exists).
  80.     OPEN errfile$ FOR OUTPUT AS #1
  81.     PRINT #1, "You may safely delete this file if found."
  82.     CLOSE #1
  83.     SHELL batch$
  84.     KILL batch$
  85.     f$ = Dir$(errfile$, DirInfo)  'If the errorfile was deleted, it means
  86.     IF LEN(f$) THEN               'the batch file ended in error.
  87.         KILL errfile$
  88.     ELSE
  89.         PRINT
  90.         PRINT "BMAKE execution stopped."
  91.         ErrExit
  92.     END IF
  93. END IF
  94.  
  95. END
  96.  
  97. '************************* Error Handling Routines **************************
  98.  
  99.  
  100. '***************************** Data Statements ******************************
  101.  
  102.  
  103. '****************************************************************************
  104. '********************     End of Module Level Code       ********************
  105. '****************************************************************************
  106.  
  107. SUB ErrExit
  108.     
  109.     PRINT
  110.     BEEP
  111. '     EndLevel (1)       'DON'T RUN THIS LINE IN THE INTERPRETER!!!
  112.     SYSTEM
  113.  
  114. END SUB
  115.  
  116. SUB MakeBatch
  117.  
  118. berr$ = "@if errorlevel 1 goto BErr"
  119.  
  120. OPEN batch$ FOR OUTPUT AS #1
  121.  
  122. IF report THEN
  123.     PRINT #1, "@copy "; batch$; " PRN"
  124. END IF
  125.  
  126. FOR x = 1 TO nf
  127.  
  128.     f$ = Dir$(source$(x), DirInfo)     'Get date/time of source file
  129.     IF f$ = "" THEN
  130.         CLOSE #1
  131.         KILL batch$
  132.         PRINT
  133.         PRINT "ERROR: File not found - " + source$(x)
  134.         ErrExit
  135.     END IF
  136.     sd& = DirInfo.EntryDate
  137.     st = DirInfo.EntryTime
  138.  
  139.     f$ = Dir$(object$(x), DirInfo)     'Get date/time of object file
  140.     IF LEN(f$) = 0 THEN
  141.         od& = 0
  142.         ot = 0
  143.     ELSE
  144.         od& = DirInfo.EntryDate
  145.         ot = DirInfo.EntryTime
  146.     END IF
  147.  
  148.     IF report THEN
  149.         LPRINT
  150.         LPRINT source$(x); TAB(15); sd&; TAB(25); st
  151.         LPRINT object$(x); TAB(15); od&; TAB(25); ot
  152.     END IF
  153.  
  154.     IF od& > sd& THEN GOTO NextFile                   'Compare dates
  155.     IF od& = sd& AND ot > st THEN GOTO NextFile       'Compare times
  156.  
  157.     o$ = options$                                'Global compiler options
  158.     IF LEN(option$(x)) > 0 THEN
  159.         x$ = MID$(option$(x), 2)
  160.         IF LEFT$(option$(x), 1) = "&" THEN      'Additional options? (&)
  161.             o$ = o$ + x$
  162.         ELSE                                    'Replacement options (!)
  163.             o$ = x$
  164.         END IF
  165.     END IF
  166.  
  167.     c$ = " " + source$(x) + " " + o$ + ", " + object$(x) + ";"
  168.  
  169.     PRINT #1, compiler$; c$
  170.     PRINT #1, berr$
  171.  
  172.     IF report THEN
  173.         LPRINT SPACE$(31); "Compiled."
  174.     END IF
  175.  
  176. NextFile:
  177.     
  178. NEXT x
  179.  
  180. IF report THEN
  181.     LPRINT
  182.     LPRINT
  183. END IF
  184.  
  185. FOR x = 1 TO nc                    'Add the COMMANDs to the batch file
  186.     PRINT #1, cmd$(x)
  187.     PRINT #1, berr$
  188. NEXT x
  189.  
  190. PRINT #1, "@goto End"
  191. PRINT #1, ":BErr"
  192. PRINT #1, "@echo off"
  193. PRINT #1, "del "; errfile$
  194. PRINT #1, ":End"
  195.  
  196. CLOSE #1
  197.  
  198. END SUB
  199.  
  200. SUB ParseCmd
  201.  
  202. c$ = COMMAND$
  203.  
  204. x = INSTR(c$, "/")
  205.  
  206. IF x = 0 THEN                           'No other options specified?
  207.     makefile$ = c$
  208.     EXIT SUB
  209. END IF
  210.  
  211. makefile$ = RTRIM$(LEFT$(c$, x - 1))    'Extract makefile name and trim it
  212. c$ = MID$(c$, x)                        'off the rest.
  213.  
  214. DO
  215.  
  216.     SELECT CASE LEFT$(c$, 3)
  217.         CASE "/F:"                    'Specify maxfiles
  218.             GOSUB SplitIt
  219.             IF v > 0 THEN
  220.                 maxfiles = v
  221.             ELSE
  222.                 x$ = "/F:"
  223.                 GOTO BadValue
  224.             END IF
  225.         CASE "/C:"                    'Specify maxcmds
  226.             GOSUB SplitIt
  227.             IF v > 0 THEN
  228.                 maxcmds = v
  229.             ELSE
  230.                 x$ = "/C:"
  231.                 GOTO BadValue
  232.             END IF
  233.         CASE "/PR"                    'Print Report (undocumented)
  234.             c$ = RIGHT$(c$, LEN(c$) - 3)
  235.             report = TRUE
  236.         CASE ELSE                     'What???
  237.             PRINT
  238.             PRINT "ERROR: Unrecognized command line option(s): "; c$
  239.             ErrExit
  240.     END SELECT
  241.  
  242. LOOP UNTIL LEN(c$) = 0
  243.  
  244. EXIT SUB
  245.  
  246.  
  247. SplitIt:
  248.     x = INSTR(2, c$, "/")
  249.     IF x = 0 THEN
  250.         v = VAL(MID$(c$, 4))    'Only want the stuff after the colon.
  251.         c$ = ""
  252.     ELSE
  253.         v = VAL(MID$(RTRIM$(LEFT$(c$, x - 1)), 4))
  254.         c$ = MID$(c$, x)
  255.     END IF
  256.     RETURN
  257.  
  258.  
  259. BadValue:
  260.     PRINT
  261.     PRINT "ERROR: Invalid value for "; x$; ";v"
  262.     ErrExit
  263.  
  264. END SUB
  265.  
  266. SUB ReadFile
  267.  
  268. bas$ = ".BAS"
  269. obj$ = ".OBJ"
  270.  
  271. OPEN makefile$ FOR INPUT AS #1
  272.  
  273. DO WHILE NOT EOF(1)
  274.  
  275.     LINE INPUT #1, l$
  276.     
  277.     l$ = LTRIM$(RTRIM$(l$))                      'Make two copies of the
  278.     o$ = l$                                      'line, one case-sensitive
  279.     l$ = UCASE$(l$)                              'and one that's not.
  280.  
  281.     IF l$ = "" THEN GOTO NextLine                'Skip blank lines
  282.     IF LEFT$(l$, 1) = "'" THEN GOTO NextLine     'Skip commented-out lines
  283.  
  284.     x = INSTR(l$, "'")                           'Remove in-line comments.
  285.     IF x > 0 THEN
  286.         x = x - 1
  287.         l$ = RTRIM$(LEFT$(l$, x))
  288.         o$ = RTRIM$(LEFT$(o$, x))
  289.     END IF
  290.  
  291.     colon = INSTR(l$, ":")                       'Find a colon if any
  292.     pipe = INSTR(l$, "|")                        'Find a pipe if any
  293.  
  294.     IF pipe > 0 THEN                             'Object/Source comparison?
  295.         
  296.         nf = nf + 1                             'Too many?
  297.         IF nf > maxfiles THEN
  298.             PRINT
  299.             PRINT "ERROR: Maximum object-source comparisons exceeded at"; nf
  300.             PRINT "       Increase the /F: command line parameter."
  301.             ErrExit
  302.         END IF
  303.  
  304.         object$(nf) = RTRIM$(LEFT$(l$, pipe - 1))   'Separate object
  305.         source$(nf) = LTRIM$(MID$(l$, pipe + 1))    'from source
  306.         
  307.         work$ = LTRIM$(MID$(o$, pipe + 1))                'Use original
  308.         x = INSTR(work$, "&")                             'string to
  309.         IF x = 0 THEN                                     'separate other
  310.             x = INSTR(work$, "!")                        'options (if any)
  311.         END IF                                            'from source
  312.         IF x > 0 THEN
  313.             option$(nf) = LTRIM$(MID$(work$, x))
  314.             source$(nf) = RTRIM$(LEFT$(source$(nf), x - 1))
  315.         END IF
  316.   
  317.         IF INSTR(object$(nf), ".") = 0 THEN               'Add the
  318.             object$(nf) = object$(nf) + obj$             'proper
  319.         END IF                                            'extensions
  320.         IF INSTR(source$(nf), ".") = 0 THEN               'if needed
  321.             source$(nf) = source$(nf) + bas$
  322.         END IF
  323.         
  324.         GOTO NextLine
  325.  
  326.     ELSEIF colon > 0 THEN                        'BMAKE keyword?
  327.         
  328.         lv$ = LTRIM$(MID$(o$, colon + 1))       'Case-sensitive!
  329.         SELECT CASE LEFT$(l$, 4)
  330.             CASE "COMP"                                  'Alternate
  331.                 compiler$ = UCASE$(lv$)                 'compiler listed
  332.                 GOTO NextLine
  333.             CASE "OPTI"                                  'Compiler options
  334.                 options$ = lv$
  335.                 GOTO NextLine
  336.             CASE "COMM"                                  'Command
  337.                 nc = nc + 1
  338.                 IF nc > maxcmds THEN
  339.                     PRINT
  340.                     PRINT "ERROR: Maximum COMMAND: statements exceeded at"; nc
  341.                     PRINT "       Increase the /C: command line parameter."
  342.                     ErrExit
  343.                 END IF
  344.                 cmd$(nc) = lv$
  345.                 GOTO NextLine
  346.             CASE ELSE                                    '???
  347.                 'See below
  348.         END SELECT
  349.     
  350.     END IF
  351.  
  352.     PRINT
  353.     PRINT "ERROR: Unrecognized syntax in make file:"
  354.     PRINT "       "; o$
  355.     ErrExit
  356.  
  357. NextLine:
  358. LOOP
  359.  
  360. CLOSE #1
  361.  
  362. END SUB
  363.  
  364. SUB Startup
  365.  
  366. q$ = CHR$(34)
  367.  
  368. IF makefile$ = "" THEN
  369.     PRINT
  370.     PRINT "BMAKE 1.0 (c) 1995 Raymond W. Marron - HOMONCULOUS PROGRAMMING"
  371.     PRINT "ERROR: Makefile not specified."
  372.     ErrExit
  373. END IF
  374.  
  375. IF INSTR(makefile$, ".") < 1 THEN       'Add the default extension if not
  376.     makefile$ = makefile$ + ".BMK"     'supplied.
  377. END IF
  378.  
  379. f$ = Dir$(makefile$, DirInfo)
  380.  
  381. IF f$ = "" OR f$ = "***ERROR***" THEN
  382.     PRINT
  383.     PRINT "ERROR: Makefile " + q$ + makefile$ + q$ + " not found."
  384.     ErrExit
  385. END IF
  386.  
  387. END SUB
  388.  
  389.