P-CAD Printed Circuit Board design environment. Project file template
#
# Project.prj
#
# Template for projectfile
#
# Version: 0.07
# Date   : 25 augustus 1994
#

#
# Keyword       attribute1  attribute2  attribute3  Remark
# ------------------------------------------------------------
# Schema        pro1.sch        [<LA3|SA3|LA4|SA4>]     ; *
# Attribute     pro1.atr                                ; 1x max
# Crossref      pro1.fil                                ; *
# Print         pro1.pcb                                ; 1x max
# Route         pro1.ctl                                ; 1x max
# Submit        pro1.ctl                                ; 1x max
# Erc           pro1.cfg                                ; 1x max
# Drc           pro1.cfg        [.rul        [.ign]]    ; 1x max
# Plot                                              ; Reserved
#

Schema          PROJECT.sch     .A.                 # Schema
Attribute       c:\pcad\bat\form.atr                # Attr. recognized by Form
Crossref        PROJECT.fli                         # Keep as first crossref
Crossref        c:\pcad\prt\rlib.fil                # Keep as second crossref
Crossref        c:\pcad\prt\gllib.fil               # Keep as third crossref


#
# Printed circuit boards:
#
# Print c:\pcad\prt\1layer.pcb    # single layer board, no boardlayout
# Print c:\pcad\prt\2layer.pcb    # double layer board, no boardlayout
# Print c:\pcad\prt\ruleuro.pcb   # RULBUS euro card, boardlayout & CN1 (PIN50)
# Print c:\pcad\prt\ruleuroa.pcb  # RULBUS euro card, boardlayout & CN1 (PIN50A)
#
#
# Pcad crossreference files:
#
# Crossref c:\pcad\prt\amd.fil
# Crossref c:\pcad\prt\cmos.fil
# Crossref c:\pcad\prt\discrete.fil
# Crossref c:\pcad\prt\dsparts.fil
# Crossref c:\pcad\prt\ecl.fil
# Crossref c:\pcad\prt\elco.fil
# Crossref c:\pcad\prt\electro.fil
# Crossref c:\pcad\prt\intel.fil
# Crossref c:\pcad\prt\linear.fil
# Crossref c:\pcad\prt\memory.fil
# Crossref c:\pcad\prt\motorola.fil
# Crossref c:\pcad\prt\national.fil
# Crossref c:\pcad\prt\rlib.fil
# Crossref c:\pcad\prt\ttl.fil
# Crossref c:\pcad\prt\zilog.fil
#

#
# End of file
#


Batch file to drive Korn-Shell script
@echo off
Rem
Rem Pack.bat [ project.prj ...]
Rem

sh c:/pcad/bat/pack.ksh %1 %2 %3 %4 %5 %6 %7 %8 %9
if not errorlevel 1 c:\pcad\bat\mdbatch.bat

Rem
Rem End of file
Rem


Korn-Shell script to do the complete pack process
#
# Pack.ksh
#
# Pack schematic file(s) and print as specified in
#   project file into a project.pkg file, ready to place with pcplace.
#
# Version : 0.08
# Date    : 25 oct 1994
#


function usage
{
   print -r - "Create PCB database"
   print -r - "Usage: pack [<project.prj> ...]"
   exit 2
}


function header                                 # Write header lines of batchfile
{
   typeset -H  hme=$HOME  dir=$(pwd)

   print -r - "@echo off"                         >$bat # Be silent
   print -r - "Rem MDBATCH.BAT produced by $prg" >>$bat
   print -r - "Rem User: $LOGNAME"               >>$bat
   print -r - "Rem Home: $hme"                   >>$bat
   print -r - "Rem Dir.: $dir"                   >>$bat
   print -r - "Rem Date: $(date '+%d/%m/%y %T')" >>$bat
}


function trailer                                        # Write trailing lines of batchfile
{
   print -r - "goto ok"                >>$bat           # Skip error handling
   print -r - ":quit"                  >>$bat           # Label quit
   print -r - "echo Batch interrupted" >>$bat
   print -r - "echo Check PACK.LOG"    >>$bat
   print -r - ":ok"                    >>$bat           # Label ok

   print -r - "if exist $bcf del $bcf" >>$bat           # Remove batch controlfile
   print -r - "if exist $tmp del $tmp" >>$bat           # Remove temporary .fil file
}


#
# Collect info from project file
#

function collect  # ( prj )                             # Collect project info
{
   typeset prj=$1                                       # Project name

   atrfil=$(awk '$1 == "Attribute" {print $2}' $prj)    # Get Attribute file
   pcbfil=$(awk '$1 == "Print"     {print $2}' $prj)    # Get PCB file
   schlst=$(awk '$1 == "Schema"    {print $2}' $prj)    # Build list of schema's
   reflst=$(awk '$1 == "Crossref"  {print $2}' $prj)    # Build list of schema's

   return 0                                             # Return ok
}


#
# Create linked netlist .XNL
#

function nodes  # ( prj )                               # Make .NLT file for schematic
{                                                       # Local variables
   typeset fn                                           #   Loop filename
   typeset prj=$1                                       #   Project filename

   print -r - "Echo Project   '"$prj"'"         >>$bat  # Keep user informed

   schcnt=0                                             # Reset schemacount

   for fn in $schlst                                    # Loop through .sch files
   do
      if [ -f $fn ]                                     # Does file exist?
      then
         typeset nlt=${fn%.*}.NLT                       # Schema netlist
         let     lab=lab+1  schcnt=schcnt+1             # Increment label/schema count

         print -r - "$tst $fn -nt $nlt"         >>$bat  # Schema newer than netlist?
         print -r - "if errorlevel 1 goto L$lab">>$bat  # No : skip
         print -r - "Echo  Nodes    '"$fn"'"    >>$bat  #      keep user informed
         print -r - "pcnodes $fn >>$log"        >>$bat  # Yes: extract netlist
         print -r - "if errorlevel 1 goto quit" >>$bat  #      quit batch on error
         print -r - ":L$lab"                    >>$bat
      else
         print    - "\n$prg: cannot find '"$fn"'.\c"    # No : issue warning
         return 1                                       #      return error
      fi
   done
   return 0                                             # return ok
}


function link  # ( prj )                                # Link netlists
{                                                       # Local variables
   typeset fn                                           #   loop filename
   typeset nlt                                          #   schema netlist
   typeset prj=$1                                       #   project file
   typeset xnl=${prj%.*}.XNL                            #   pclink cross ref. output
 
   if [ schcnt -eq 1 ]                                  # Only one schema?
   then
      let  lab=lab+1                                    # New label
      nlt=${schlst%.*}.NLT                              # Schema name

      print -r - "$tst $nlt -nt $xnl"          >>$bat   # New netlist?
      print -r - "if errorlevel 1 goto L$lab"  >>$bat   # No: skip
      print -r - "Echo  Create   '"$xnl"'"     >>$bat   # Keep user informed
      print -r - "Copy $nlt $xnl >>$log"       >>$bat   # Yes: copy .nlt to .xnl
      print -r - ":L$lab"                      >>$bat   # Link end label

      return 0                                          # Return ok
   else                                                 # More than one schema
      typeset -i lnk                                    # Label for linking
      typeset    cmd

      let  lnk=lab+1  lab=lab+2                         # New label, link label

      cmd="NAME $xnl\nLINK "                            # Create batch control file
      for fn in $schlst                                 # and test for file timerelation
      do
         nlt=${fn%.*}.NLT                               # Netlist filename
         cmd="$cmd $nlt +"                              # Command for pclink
         print -r - "$tst $xnl -nt $nlt"         >>$bat # .xnl newer than .nlt?
         print -r - "if errorlevel 1 goto L$lnk" >>$bat # No : link
      done
      print    - "$cmd"                       >$bcf     # Create batch controlfile
      print -r - "goto L$lab"                >>$bat     # No linking necessary

      print -r - ":L$lnk"                    >>$bat     # Label for linking
      print -r - "Echo  Link     '"$xnl"'"   >>$bat     # Keep user informed
      print -r - "pclink $bcf >>$log"        >>$bat     # Link netlists
      print -r - "if errorlevel 1 goto quit" >>$bat     # Quit batch on error
      print -r - ":L$lab"                    >>$bat     # Link end label

      return 0                                          # return ok
   fi
}


#
# Extract .FIL file
#

function extract_fil  # ( prj, fli )                    # Extract from a single .fil file
{                                                       # Local variables
   typeset prj=$1                                       #   project file
   typeset fli=$2                                       #   .fil input file
   typeset nam=$(basename $fli)                         #   .fil input basename
   typeset xnl=${prj%.*}.XNL                            #   input crossref. file
   typeset fil=${prj%.*}.FIL                            #   output .fil file

   if [ -f $fli ]                                       # Does .fil file exist?
   then
      print -r - "Echo  Extract  '"$nam"'"      >>$bat  # Yes: keep user informed
      print -r - "pcpack $xnl -f $fli -e $tmp   >>$log" \
                                                >>$bat
      print -r - "if errorlevel 1 goto quit"    >>$bat  # Quit batch on error
      print -r - "type $tmp  >>$fil"            >>$bat  # Append extracted crossref
      return 0                                          # Return ok
   else
      print    - "\n$prg: cannot find '"$fli"'.\c"      # No : issue warning
      return 1                                          # return error
   fi
}


function extract  # ( prj )                             # Make .fil file
{                                                       # Local variables
   typeset fn                                           #   loop filename
   typeset prj=$1                                       #   project file
   typeset fil=${1%.*}.FIL                              #   output .fil file
   typeset fli sts=0                                    #   loop name, list, status

   typeset -i xtr                                       # Label for start extract
   let        xtr=lab+1  lab=lab+2                      # New labels

   for fn in $prj $reflst                               # Check project/xref files
   do
      print -r - "$tst $fil -nt $fn"           >>$bat   # New netlist?
      print -r - "if errorlevel 1 goto L$xtr"  >>$bat   # Yes: extract
   done
   print -r - "goto L$lab"                   >>$bat     # No : skip extraction

   print -r - ":L$xtr"                       >>$bat     # Extract start label
   print -r - "Echo  Create   '"$fil"'"      >>$bat     # Keep user informed
                                                        # Header for $fil file
   print -r - "sed -e s,\$prg,$prg," \
                  "-e s,\$fil,$fil," \
                  "-e s,\$tim,\"$(date '+%d/%m/%y %T')\"," \
                  "$dat >$fil"               >>$bat     # Edit pack.dat

   for fli in $reflst                                   # Process all .fil files
   do
      extract_fil $prj $fli || sts=1                    # Extract a single .fil file
   done

   print -r - ":L$lab"                       >>$bat     # Extract end label

   return sts                                           # Return status
}


#
#  Annotate schematics
#

function annotate  # ( prj )                            # Annotate schematic file
{                                                       # Local variables
   typeset fn                                           #   loop filename
   typeset prj=$1                                       #   project file
   typeset cmd=${prj%.*}.CMD                            #   pccaps command file

   typeset -i ann                                       # Label for annotation
   let  ann=lab+1  lab=lab+2                            # Set label values
 
   for fn in $schlst                                    # Loop through .sch files
   do
      print -r - "$tst $fn -nt $cmd"         >>$bat     # .sch newer than .cmd?
      print -r - "if errorlevel 1 goto L$ann">>$bat     # No: annotate
   done
   print -r - "goto L$lab"                   >>$bat     # Skip

   print -r - ":L$ann"                       >>$bat     # Start annotation
   print -r - "if not exist $cmd goto quit"  >>$bat     # Commandfile exists?
   print -r - "type $qui >>$cmd"             >>$bat     # Append 'sys quit' to $cmd file
   print -r - "$cap @$cmd"                   >>$bat     # Annotate schematics
   print -r - "if errorlevel 1  goto quit"   >>$bat     # Quit batch on error
   print -r - ":L$lab"                       >>$bat     # Annotate end label

   return 0                                             # Return ok
}


#
# Pack into .PKG file
#

function packprj  # ( prj, opt )                        # Make package file
{                                                       # Local variables
   typeset fn                                           #   loop filename
   typeset prj=$1                                       #   project file
   typeset opt=$2                                       #   pcpack options
   typeset cmd=${prj%.*}.CMD                            #   pccaps command file
   typeset fil=${prj%.*}.FIL                            #   output .fil file
   typeset xnl=${prj%.*}.XNL                            #   input crossref. file
   typeset pkg=${prj%.*}.PKG                            #   input crossref. file

   typeset atr pcb

   typeset -i pck                                       # Pack label
   let  pck=lab+1  lab=lab+2                            # New label

   if [ "X$atrfil" != "X" ]                             # Build attribute option
   then
      atr="@$atrfil "
   fi

   if [ "X$pcbfil" != "X" ]                             # Build pcb option
   then
      pcb="-i $pcbfil "
   fi

   for fn in $fil $xnl                                  # Must pack?
   do
      print -r - "$tst $pkg -nt $fn"            >>$bat  # Newer file?
      print -r - "if errorlevel 1 goto L$pck"   >>$bat  # Yes: pack
   done
   print -r - "goto L$lab"                      >>$bat  # No packaging necessary

   print -r - ":L$pck"                          >>$bat  # Label for packaging
   print -r - "Echo  Pack     '"$pkg"'"         >>$bat  # Keep user informed
   print -r - "pcpack $xnl $fil $opt $pcb $atr  >>$log" \
                                                >>$bat  # @attrib
   print -r - "if errorlevel 1 goto quit"       >>$bat  # Quit batch on error
   print -r - ":L$lab"                          >>$bat  # Pack end label

   return 0                                             # Return ok
}


function pack1  # ( prj )                               # Pack pass 1
{                                                       # Create backannotation commandfile
   typeset sts=0

   packprj $1 "-c"  ||  sts=1                              # Create command file

   return sts                                           # Return status
}


function pack2  # ( prj )                               # Pack pass 2
{                                                       # Create .pkg/.pnl files
   typeset sts=0

   packprj $1 "-bn"  ||  sts=1                             # Pack

   return sts                                           # Return status
}


#
# Pack specified project
#

function pack  # ( prj )                                # Pack project
{
   typeset sts=0                                        # Return status
   typeset prj=$1                                       # Project name

   if [ -f $prj ]                                       # Does project file exist?
   then                                                 # Yes: create packaged file
      collect  $prj  &&                                 #      collect info from project
      nodes    $prj  &&                                 #      extract netlists
      link     $prj  &&                                 #      link netlists
      extract  $prj  &&                                 #      extract .fil file
      pack1    $prj  &&                                 #      pack pass 1
      annotate $prj  &&                                 #      annotate schematic(s)
      nodes    $prj  &&                                 #      extract updated netlist
      link     $prj  &&                                 #      link updated netlists
      pack2    $prj  ||  sts=1                          #      pack pass 2 for savety
   else                                                 # No : issue warning
      print    - "\n$prg: cannot find project file '"$prj"'.\c"
      return 2
   fi

   return sts
}


#
# Main line: pack project(s)
#

prg="PACK.KSH"                                          # Shell script name
log="PACK.LOG"

cap='call c:\pcad\bat\pccaps.bat'                       # Pccaps program
dat='c:\pcad\bat\pack.dat'                              # Info for .fil file
bcf='c:\pcad\bat\pack.bcf'                              # Batch controlfile (pclink)
tmp='c:\pcad\bat\pack.tmp'                              # Temporary file
qui='c:\pcad\bat\sysquit.dat'                           # Sys-quit command for .cmd
bat="c:/pcad/bat/MDBATCH.BAT"                           # Batchfile to create

typeset mv=c:/mks/bin/mv                                # MKS mv
typeset rm=c:/mks/bin/rm                                # MKS rm

typeset -H tst="c:/mks/bin/test.exe"                    # MKS Test program

typeset -i lab=0                                        # Label counter
typeset -i schcnt=0                                     # Schema file counter
typeset schlst reflst atrfil pcbfil                     # List of schema/ref/atr/pcb files

typeset sts=0                                           # Exit status (ok)

trap "$rm -f $bcf $tmp $bat; exit 2" INT                # Action on ^C

if [ $# -eq 0 ]                                         # Any arguments given?
then
   usage                                                # No : show usage
else                                                    # Yes: process given arguments
   arg=$1

   while true                                           # Loop while options present
   do
      if [ $# -eq 0 ]                                   # Any arguments left?
      then
         usage                                          # No : show usage
      fi

      case $arg in
         -*)  print -r - "Unknown option '"$arg"'."     # -?: invalid option
              usage ;;
         *)   break ;;                                  # ? : no more options
      esac

      arg=${arg#-?}                                     # Compute next arg
      case $arg in
         "") shift; arg=$1 ;;                           # Next argument
         *)  arg=-$arg ;;                               # Next option within argument
      esac

   done

   >$log                                                # Create empty .LOG file
   >$bat                                                # Create empty .BAT file

   print - "$prg: creating batchfile...\c"              # Inform user

   header                                               # Write header lines to batchfile

   for fn in $@                                         # Loop through given filenames
   do
      pack $fn  ||  sts=1                               # Pack project
   done

   trailer                                              # Write trailer lines to batchfile
   print -                                              # Newline

fi

exit sts                                                # Exit status


#
# End of file
#