home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / pwrmake / pwrmake.prg < prev   
Encoding:
Text File  |  1992-07-14  |  15.2 KB  |  425 lines

  1. /*
  2.  * File......: PWRMAKE.PRG
  3.  * Author....: Clifford Wiebe [CIS ID: 73670,1377]
  4.  * Date......: 16 Jan 1992 12:00:00
  5.  * Revision..: Revision: 1.3
  6.  *
  7.  * This is an original work by Clifford Wiebe and is placed in the
  8.  * public domain.
  9.  *
  10.  * Note: Auxiliary files CHECKVOL.EXE, PKZIP.EXE, PKUNZIP.EXE are referenced
  11.  *         in the backup and restore batch files.
  12.  *
  13.  *
  14. */
  15.  
  16.  
  17. #include "fileio.ch"
  18. #include "directry.ch"
  19. #include "inkey.ch"
  20.  
  21. #define COMPILER_NAME                'CLIPPER'
  22. #define OBJ_ENVIRONMENT             '.;C:\CLIPPER5\OBJ'
  23. #define CH_ENVIRONMENT                'C:\CLIPPER5\INCLUDE'
  24. #define LIB_ENVIRONMENT             'C:\CLLIPPER5\LIB'
  25. #define CMD_ENVIRONMENT             '/v /w /m'
  26. #define LINKER_NAME                 'BLINKER'
  27. #define PLL_ENVIRONMENT             'C:\CLIPPER5\PLL'
  28. #define BACKUP_DIRECTORY            'C:\ZIP'
  29. #define DATA_DIRECTORY                '.\'
  30.  
  31. // define support pseudo-functions
  32. #command DEFAULT <p> TO <val> [,<pn> TO <valn>] ;
  33.          => ;
  34.          <p> = iif(<p> = NIL, <val>, <p>) ;
  35.          [;<pn> = iif(<pn> = NIL, <valn>, <pn>)]
  36.  
  37. #xtranslate StripPath( <c> )  =>       ;
  38.    if('\' $ <c>,substr(<c>,rat('\',<c>)+1),<c>)
  39.  
  40. function main(cOpt1, cOpt2, cOpt3, cOpt4, cOpt5, cOpt6, cOpt7, cOpt8, cOpt9)
  41.     Local x, n, n2, c, aOptions := {}, aProg := {}, aClip := {}
  42.     local lOverwrite := .f., cAuthor := 'Your Name Here', lHelp := .f.
  43.     local cProject := '', nHandle, cBackup, cCompiler
  44.     local cEnvCmd, cEnvCh, cEnvLib, cEnvObj, cEnvPll, cData, cMainPrg
  45.  
  46.     Local nClip, nPrg, nLink, cOut, nOut, cDataZip
  47.  
  48.     ? "Power Make v1.4 for Clipper 5.01"
  49.     ? "Copyright 1992 (C) Clifford Wiebe 1992. Public Domain Version"
  50.     ?
  51.  
  52.     // Parse the command line options
  53.     aOptions := {cOpt1,cOpt2,cOpt3,cOpt4,cOpt5,cOpt6,cOpt7,cOpt8,cOpt9}
  54.  
  55.     // Setup defaults before the command line override
  56.     cCompiler    := COMPILER_NAME
  57.     cEnvObj     := OBJ_ENVIRONMENT
  58.     cEnvCh        := CH_ENVIRONMENT
  59.     cEnvLib     := LIB_ENVIRONMENT
  60.     cEnvPll     := PLL_ENVIRONMENT
  61.     cEnvCmd     := CMD_ENVIRONMENT
  62.     cBackup     := BACKUP_DIRECTORY
  63.     cData        := DATA_DIRECTORY
  64.  
  65.     for n := 1 to len(aOptions)
  66.         aOptions[n] := iif(aOptions[n] == nil,'',aOptions[n] )
  67.     next
  68.     for n := 1 to len(aOptions)
  69.         do case
  70.             case '/o' $ lower(aOptions[n])
  71.                 lOverwrite := .t.
  72.             case '/a' $ lower(aOptions[n])
  73.                 cAuthor := substr(aOptions[n],3)
  74.                 // Author is special command line option, it
  75.                 // can contain spaces. Check for it.
  76.                 n2 := n
  77.                 while n2 < len(aOptions) .and. !('/' $ aOptions[n2+1] )
  78.                     n2++
  79.                     cAuthor += ' ' + aOptions[n2]
  80.                 enddo
  81.             case '/?' $ aOptions[n]
  82.                 lHelp := .t.
  83.             case '/n' $ lower(aOptions[n])
  84.                 cProject := upper(substr(aOptions[n],3))
  85.             case '/b' $ lower(aOptions[n])
  86.                 cBackup := substr(aOptions[n],3)
  87.                 // strip any trailing backslash
  88.                 if right(cBackup,1) != '\'
  89.                     cBackup += '\'
  90.                 endif
  91.             case '/d' $ lower(aOptions[n])
  92.                 cData := substr(aOptions[n],3)
  93.                 // strip any trailing backslash
  94.                 if right(cData,'\') != '\'
  95.                     cData += '\'
  96.                 endif
  97.             case '/c' $ lower(aOptions[n])
  98.                 cCompiler := upper(substr(aOptions[n],3))
  99.             case '/m' $ lower(aOptions[n])
  100.                 cMainPrg := upper(substr(aOptions[n],3))
  101.         endcase
  102.     next
  103.  
  104.     if lHelp
  105.         HelpScreen()
  106.         quit
  107.     endif
  108.     // If the main (.prg) is not specified, default to the project
  109.     // name for the main module. This module is only one that is
  110.     // not overlayed in the link file. It also will be the of the
  111.     // executable.
  112.     if !(file("*.prg"))
  113.         ? "No PRG files found...exiting"+chr(7)
  114.         quit
  115.     endif
  116.  
  117.     if empty(cProject)
  118.         ? 'Project name not found, enter PWRMAKE /? for help'
  119.         quit
  120.     elseif len(cProject) > 8
  121.         ? 'Project name greater than 8 characters'
  122.         quit
  123.     endif
  124.  
  125.  
  126.     ? 'Creating Project files for '+ cProject
  127.  
  128.     * declare and load the array
  129.     ****************************
  130.     aProg  := Directory("*.prg")
  131.     aClip := Directory("*.clp")
  132.  
  133.     if len(aProg) == 0
  134.         ? 'no .PRG files found'
  135.         quit
  136.     endif
  137.  
  138.     asort(aProg,,,{|x,y| x[1] < y[1]})
  139.  
  140.     ? 'creating ' + cProject + '.RMK'
  141.     if file(cProject + '.rmk') .and. !lOverwrite
  142.         if !YesNo(cProject+'.rmk project found, Ok to Overwrite? ')
  143.             quit
  144.         endif
  145.     endif
  146.     if (nHandle := fcreate(cProject+'.RMK',FC_NORMAL)) == -1
  147.         ? 'make file cannot be created, exiting'
  148.         quit
  149.     endif
  150.  
  151.     // Write the header file information
  152.     fwriteline(nHandle,"// Make File....: "+cProject)
  153.     fwriteline(nHandle,"// Date Created.: "+dtoc(date()))
  154.     fwriteline(nHandle,"// Author.......: "+cAuthor)
  155.     fwriteline(nHandle,"// Comments.....: Created by Pwrmake")
  156.     fwriteline(nHandle,"//                                  ")
  157.     fwriteline(nHandle,"")
  158.     fwriteline(nHandle,"// Make File macros")
  159.     fwriteline(nHandle,padr("COMPILER        = " + cCompiler,40) + '// Compiler Name')
  160.     fwriteline(nHandle,padr("CLIPPERCMD      = " + cEnvCmd,40) + "// Default Compiler Directives")
  161.     fwriteline(nHandle,padr("LINKERNAME      = "+LINKER_NAME,40)+"// Linker name")
  162.     fwriteline(nHandle,padr("CLIPDEBUG       = " + cEnvCmd + " /b ",40) + "// Debug Compiler Directives")
  163.     fwriteline(nHandle,"")
  164.     fwriteline(nHandle,"// makepath macros")
  165.     fwriteline(nHandle,"makepath[.obj] = " + cEnvObj)
  166.     fwriteline(nHandle,"makepath[.ch]  = " + cEnvCh)
  167.     fwriteline(nHandle,"makepath[.lib] = " + cEnvLib)
  168.     fwriteline(nHandle,"makepath[.pll] = " + cEnvPll)
  169.     fwriteline(nHandle,"")
  170.     fwriteline(nHandle,"// Inference rules ")
  171.     fwriteline(nHandle,".PRG.OBJ:")
  172.     fwriteline(nHandle,"    $(COMPILER) $* (CLIPPERCMD)")
  173.     fwriteline(nHandle,"")
  174.  
  175.     // Process the .PRG files
  176.     nPrg  := len(aProg)
  177.     for n := 1 to nPrg
  178.         c := padr(StripExt(aProg[n,F_NAME])+".OBJ",15)
  179.         fwriteline(nHandle,c + ":"+space(6)+StripExt(aProg[n,F_NAME])+".PRG")
  180.     next
  181.     fwriteline(nHandle,"")
  182.  
  183.     fwriteline(nHandle,padr(cMainPrg+".EXE",15)+":")
  184.     fwriteline(nHandle,space(3)+"$(LINKERNAME) @"+StripExt(cProject)+".LNK")
  185.     fclose(nHandle)
  186.  
  187.     //*******************************************************************
  188.  
  189.     ? 'creating '+cProject+'.LNK'
  190.     nLink := fcreate(cProject+'.LNK',FC_NORMAL)
  191.     fwriteline(nHandle,"#  Link File....: "+cProject)
  192.     fwriteline(nHandle,"#  Date Created.: "+dtoc(date()))
  193.     fwriteline(nHandle,"#  Author.......: "+cAuthor)
  194.     fwriteline(nHandle,"")
  195.     fwriteline(nHandle,"BLINKER OVERLAY FIXED")
  196.     fwriteline(nHandle,"BLINKER OVERLAY UMB ON")
  197.     fwriteline(nHandle,"BLINKER OVERLAY PAGEFRAME ON")
  198.     fwriteline(nHandle,"BLINKER ENVIRONMENT NAME "+upper(cProject))
  199.     fwriteline(nHandle,"BLINKER INCREMENTAL ON")
  200.     fwriteline(nHandle,"OUTPUT "+cMainPrg+'.EXE')
  201.     fwriteline(nHandle,"FILE   "+cMainPrg)
  202.     fwriteline(nHandle,"#Force commonly used routines resident")
  203.     fwriteline(nHandle,"#module -*-*-* place common routine here")
  204.     fwriteline(nHandle,"BEGINAREA   ")
  205.     for n := 1 to nPrg
  206.         if !(upper(cProject)+'.PRG' == aProg[n,F_NAME])
  207.             fwriteline(nHandle,CHR(9)+"FILE "+StripExt(aProg[n,F_NAME]))
  208.         endif
  209.     next
  210.     fwriteline(nHandle,"ENDAREA")
  211.     fwriteline(nHandle,"# Overlayed Library files, could be replaced with")
  212.     fwriteline(nHandle,"# one of various (.std) files available")
  213.     fwriteline(nHandle,"BEGINAREA   ")
  214.     fwriteline(nHandle,CHR(9)+"ALLOCATE NANFOR")
  215.     fwriteline(nHandle,CHR(9)+"ALLOCATE EXTEND")
  216.     fwriteline(nHandle,"ENDAREA")
  217.     fwriteline(nHandle,"SEARCH CLIPPER")
  218.     fwriteline(nHandle,"SEARCH DBFNTX")
  219.     fwriteline(nHandle,"SEARCH TERMINAL")
  220.     fclose(nHandle)
  221.  
  222.     ? 'creating COMPILE.BAT'
  223.     nHandle := fcreate("COMPILE.BAT",FC_NORMAL)
  224.     fwriteLine(nHandle,"@Echo Off")
  225.     fwriteline(nHandle,"Echo Making Project "+cProject)
  226.     fwriteline(nHandle,"")
  227.     fwriteline(nHandle,"rmake /w "+cProject)
  228.     fwriteline(nHandle,"")
  229.  
  230.     ? 'creating BACKUP.BAT'
  231.     nHandle := fcreate('Backup.Bat',FC_NORMAL)
  232.     fwriteline(nHandle,"@Echo Off")
  233.     fwriteline(nHandle,"REM Backup Batch File created by PwrMake on "+dtoc(date()))
  234.     fwriteline(nHandle,"if (%1)==() goto nodrive")
  235.     fwriteline(nHandle,"")
  236.     fwriteline(nHandle,"REM    Next section uses CheckVol to verify the disk is correct")
  237.     fwriteline(nHandle,"REM    You can use the DOS Label or Nortons VL command to put")
  238.     fwriteline(nHandle,"REM    a volume label on a disk")
  239.     fwriteline(nHandle,"REM    Checkvol is a utility written in C")
  240.     fwriteline(nHandle,":checkdisk")
  241.     fwriteline(nHandle,"checkvol %1"+upper(cProject))
  242.     fwriteline(nHandle,"if errorlevel 1 goto wrong")
  243.     fwriteline(nHandle,"goto continue")
  244.     fwriteline(nHandle,":wrong")
  245.     fwriteline(nHandle,"Echo "+upper(cProject)+" disk not found in Drive %1")
  246.     fwriteline(nHandle,"pause")
  247.     fwriteline(nHandle,"goto checkdisk")
  248.     fwriteline(nHandle,"")
  249.     fwriteline(nHandle,":continue")
  250.     fwriteline(nHandle,"Echo Backing up "+upper(cProject)+" system to Drive %1 using "+upper(cProject)+".LST")
  251.     fwriteline(nHandle,"if not exist "+cBackup+"NUL echo Creating "+cBackup+" directory")
  252.     fwriteline(nHandle,"if not exist " + cBackup + "*.* if not exist " + cBackup + "NUL md "+  substr(cBackup,1,len(cBackup)-1))
  253.     fwriteline(nHandle,"pkzip -u " + cBackup + cProject +" @"+cProject+".lst")
  254.     fwriteline(nHandle,"echo Copying ZipFile to Diskette in Drive %1")
  255.     fwriteline(nHandle,"copy "+cBackup+cProject+".zip %1 > NUL")
  256.     fwriteline(nHandle,"")
  257.     fwriteline(nHandle,"REM Check if data should be backed up")
  258.     fwriteline(nHandle,"if (%2)==() goto end")
  259.     fwriteline(nHandle,"if (%2)==(/DATA) goto data")
  260.     fwriteline(nHandle,"if (%2)==(/data) goto data")
  261.     fwriteline(nHandle,"goto end")
  262.     fwriteline(nHandle,"")
  263.     fwriteline(nHandle,":DATA")
  264.     fwriteline(nHandle,"Echo Backing up DBF/NTX files")
  265.     // Create the name for the data zipfile
  266.     cDataZip := rtrim(left(cProject,7)) + "D"
  267.     fwriteline(nHandle,"pkzip -u "+cBackup+cDataZip+" "+cData+"*.dbf "+cData+"*.ntx ")
  268.     fwriteline(nHandle,"Echo Ready to move "+cDataZip+".zip to Drive %1, any key")
  269.    fwriteline(nHandle,"pause > nul")
  270.    fwriteline(nHandle,"copy "+cBackup+cDataZip+".zip %1 > NUL")
  271.    fwriteline(nHandle,"goto end")
  272.    fwriteline(nHandle,"")
  273.    fwriteline(nHandle,":noDrive")
  274.    fwriteline(nHandle,"echo Drive not specified")
  275.    fwriteline(nHandle,"echo Backup [a:/b:] [/DATA]")
  276.    fwriteline(nHandle,":end")
  277.    fclose(nHandle)
  278.  
  279.    ? 'creating RESTORE.BAT'
  280.    nHandle := fcreate('Restore.bat',FC_NORMAL)
  281.    fwriteline(nHandle,"@Echo Off")
  282.    fwriteline(nHandle,"REM Restore Batch File created by PwrMake on "+dtoc(date()))
  283.    fwriteline(nHandle,"if (%1)==() goto nodrive")
  284.    fwriteline(nHandle,"")
  285.    fwriteline(nHandle,"REM    Next section uses CheckVol to verify the disk is correct")
  286.    fwriteline(nHandle,"REM    You can use the DOS Label or Nortons VL command to put")
  287.    fwriteline(nHandle,"REM    a volume label on a disk")
  288.    fwriteline(nHandle,":checkdisk")
  289.    fwriteline(nHandle,"checkvol %1"+upper(cProject))
  290.    fwriteline(nHandle,"if errorlevel 1 goto wrong")
  291.    fwriteline(nHandle,"goto continue")
  292.    fwriteline(nHandle,":wrong")
  293.    fwriteline(nHandle,"Echo "+upper(cProject)+" disk not found in Drive %1")
  294.    fwriteline(nHandle,"pause")
  295.    fwriteline(nHandle,"goto checkdisk")
  296.    fwriteline(nHandle,"")
  297.    fwriteline(nHandle,":continue")
  298.  
  299.     fwriteline(nHandle,"if not exist "+cBackup+"NUL echo Creating "+cBackup+" directory")
  300.     fwriteline(nHandle,"if not exist " + cBackup + "*.* if not exist " + cBackup + "NUL md "+  substr(cBackup,1,len(cBackup)-1))
  301.    fwriteline(nHandle,"if not exist %1"+cProject+".zip goto nofile")
  302.    fwriteline(nHandle,"Echo Restoring "+upper(cProject)+" system from Drive %1")
  303.    fwriteline(nHandle,"copy %1" + cProject + ".zip "+cBackup+cProject)
  304.    fwriteline(nHandle,"Echo Only files newer than existing files will be restored")
  305.    fwriteline(nHandle,"pkunzip -n "+cBackup+cProject)
  306.    fwriteline(nHandle,"")
  307.    fwriteline(nHandle,"REM Check if data should be backed up")
  308.    fwriteline(nHandle,"if (%2)==() goto end")
  309.    fwriteline(nHandle,"if (%2)==(/DATA) goto data")
  310.    fwriteline(nHandle,"if (%2)==(/data) goto data")
  311.    fwriteline(nHandle,"goto end")
  312.    fwriteline(nHandle,"")
  313.    fwriteline(nHandle,":DATA")
  314.    fwriteline(nHandle,"Echo Restoring DBF/NTX files")
  315.    // Create the name for the data zipfile
  316.    cDataZip := rtrim(left(cProject,7)) + "D"
  317.    fwriteline(nHandle,":CheckData")
  318.    fwriteline(nHandle,"if not exist %1"+cDataZip+".zip goto NoData")
  319.    fwriteline(nHandle,"copy %1"+cDataZip+".zip "+cBackup+cDataZip+".zip > nul")
  320.    fwriteline(nHandle,"pkunzip -n "+cBackup+cDataZip +" "+cData+"*.dbf "+cData+"*.ntx")
  321.    fwriteline(nHandle,"goto end")
  322.    fwriteline(nHandle,"")
  323.    fwriteline(nHandle,":NoData")
  324.    fwriteline(nHandle,"echo Data File %1"+cDataZip+".zip not found")
  325.    fwriteline(nHandle,"echo Insert Data Disk and press a key")
  326.    fwriteline(nHandle,"pause > nul")
  327.    fwriteline(nHandle,"goto CheckData")
  328.    fwriteline(nHandle,"")
  329.  
  330.    fwriteline(nHandle,":nofile")
  331.    fwriteline(nHandle,"echo "+cProject+".zip not found on Drive %1")
  332.    fwriteline(nHandle,"goto end")
  333.    fwriteline(nHandle,"")
  334.    fwriteline(nHandle,":noDrive")
  335.    fwriteline(nHandle,"echo Drive not specified")
  336.    fwriteline(nHandle,":end")
  337.    fclose(nHandle)
  338.  
  339.    ? 'creating '+cProject+'.LST'
  340.    nHandle := fcreate(cProject+'.lst')
  341.    fwriteline(nHandle,"*.BAT")
  342.    fwriteline(nHandle,"*.FRM")
  343.    fwriteline(nHandle,"*.LBL")
  344.    fwriteline(nHandle,"*.DOC")
  345.    fwriteline(nHandle,"*.CNF")
  346.    fwriteline(nHandle,"*.TXT")
  347.    fwriteline(nHandle,"*.DOC")
  348.    fwriteline(nHandle,"*.CH")
  349.    fwriteline(nHandle,cProject+".lnk")
  350.    fwriteline(nHandle,cProject+".rmk")
  351.    fwriteline(nHandle,cProject+".lst")
  352.    fwriteline(nHandle,cProject+".prg")
  353.  
  354.  
  355.    ? 'done'
  356.    ?
  357.    ? 'To use the Backup/Restore Batch Files, you must have'
  358.    ? 'a single diskette with a volume label of '+upper(cProject)
  359. return ( NIL )
  360. *----------------------------------------------------------------------------*
  361. function HelpScreen()
  362.  
  363.     ? "Syntax:  PwrMake /nproject [switches] "
  364.     ?
  365.     ? "where:   /n<project> = project name"
  366.     ? "         /n<MainPrg> = main non-overlayed program for project"
  367.     ? "                       defaults to <project>"
  368.     ? "         /a<name>    = author's name"
  369.     ? "         /b<dir>     = backup directory, defaults to c:\zip"
  370.     ? "         /c<compiler>= compiler name, defaults to CLIPPER.EXE"
  371.     ? "         /o          = overwrite existing files without prompting"
  372.     ? "         /d<dir>     = dbf file directory, defaults to current directory"
  373.     ? "         /?          = displays this help screen"
  374.     ?
  375.     ? "Files Created:"
  376.     ? "         compile.bat    runs RMAKE with <project>.rmk"
  377.     ? "         backup.bat     Backs up complete system to zipfile and floppy"
  378.     ? "                        /DATA will backup dbf files"
  379.     ? "         restore.bat    Restores system saved with Backup.bat"
  380.     ? "         <project>.RMK  Make file"
  381.     ? "         <project>.LNK  Link file"
  382.     ? "         <project>.LST  File list for pkzip"
  383.     ?
  384.     ? "Environment variables will be used for paths"
  385. return ( nil )
  386.  
  387. function YesNo ( cText )
  388.     //
  389.     //    returns .T. if Y or y is pressed
  390.     //
  391.     local n := 0, c := ''
  392.  
  393.     ? cText
  394.     while .t.
  395.         n := inkey(0)
  396.         c := chr(n)
  397.         if c $ 'YyNn'
  398.             exit
  399.         endif
  400.     enddo
  401.     ?
  402. return ( c $ 'Yy' )
  403.  
  404. function fwriteline(fileHandle,cString)
  405.     local nStringLen
  406.  
  407.     cString += chr(13) + chr(10)
  408.     nStringLen := len(cString)
  409.  
  410. return( nStringLen == fwrite(fileHandle,cString,nStringLen) )
  411.  
  412. function StripExt( cFile )
  413.     // returns a path/filename without an extension
  414.    local cPath := '', c, nPos
  415.  
  416.    if (nPos := rat('\', cFile)) > 0
  417.       cPath := substr(cFile,1,nPos)
  418.       cFile := StripPath(cFile)
  419.    endif
  420.    if (nPos := rat('.',cFile)) > 0
  421.       cFile := substr(cFile,1,nPos-1)
  422.    endif
  423. return (  cPath + cFile )
  424.  
  425.