home *** CD-ROM | disk | FTP | other *** search
/ Global Amiga Experience / globalamigaexperience.iso / graphic / cad / board_design / proboard_demo / rexx / bomtopl.rexx next >
Encoding:
OS/2 REXX Batch file  |  1995-07-10  |  6.8 KB  |  238 lines

  1. /* Read Pro-Net BOM file and create Pro-Board Part List                */
  2. /* This is a simple program.  It does not maintain a library of parts.
  3.    You may optionally abort if a Part List already exists.
  4.    It also does a very simple sort of the Device Labels.               */
  5.  
  6. /* $VER: BOMtoPL V1.0 by Jeff Lindstrom ©1992  EP Systems              */
  7.  
  8. /* Add the Support Library if not already in the system                */
  9. IF ~SHOW('L', 'rexxsupport.library') THEN
  10.   CALL ADDLIB('rexxsupport.library',0,-30)
  11.  
  12. ADDRESS COMMAND
  13.  
  14. /* ASCII New Line character */
  15. NL = '0A'x
  16.  
  17. BOMdir = "" /* Set BOM directory for use */
  18. IF ARG(1, 'Exists') THEN BOMdir = ARG(1)
  19.                     ELSE IF EXISTS(PNPOST) THEN BOMdir = "PNPOST/"
  20.   
  21. IF BOMdir = "" THEN
  22. DO
  23.   DS = 0  /* BOOLEAN Directory Specification flag  */
  24.   /* Use current directory to list BOM files */
  25.   'LIST >T:BOMFILES #?.BOM NOHEAD QUICK'
  26. END
  27. ELSE /* BOM directory specified.  Check format & verify that it exists */
  28. DO
  29.   DS = 1  /* BOOLEAN Directory Specification flag  */
  30.   /* If no directory or sub-directory marker (':' or '/') is present,
  31.      add a directory marker to end of text.
  32.      If the Post Processing directory PNPOST is a sub-directory of the
  33.      current directory, it will have automatically been entered as the 
  34.      working directory with the sub-directory marker '/' added, if no
  35.      directory was specified on the command line.                      */
  36.   IF (0 = VERIFY(BOMdir, ':/', M)) THEN BOMdir = BOMdir || ':'
  37.   LastChar = (SUBSTR(BOMdir, LENGTH(BOMdir), 1))
  38.   
  39.   /* If the last character is not ':' or '/', add '/' (the ':' would
  40.      already be in the body of the text because of the 3rd line up). */
  41.   IF ((INDEX(':/', LastChar)) = 0) THEN BOMdir = BOMdir || '/'
  42.   IF ~EXISTS(BOMdir) THEN
  43.   DO
  44.     SAY "Directory path doesn't exist."
  45.     EXIT
  46.   END
  47.   
  48.   /* By default, use the PNPOST sub-directory of the specified directory
  49.      if it exists (this is Pro-Net's default action, anyway).     */
  50.   IF EXISTS(BOMdir'PNPOST') THEN BOMdir = BOMdir || 'PNPOST/'
  51.   
  52.   'LIST >T:BOMFILES 'BOMdir'#?.BOM NOHEAD QUICK'
  53. END
  54.  
  55. PARSE VALUE STATEF('T:BOMFILES') WITH Type Size Other
  56. IF Size = 0 THEN
  57. DO
  58.   SAY NL "No .BOM files in this directory." NL
  59.   EXIT
  60. END
  61.  
  62. 'SORT T:BOMFILES T:BOMFILES'
  63. IF DS THEN SAY NL"Bills of Materials in" BOMdir
  64.       ELSE SAY NL"Bills of Materials"
  65. 'TYPE T:BOMFILES'
  66. 'DELETE >NIL: T:BOMFILES'
  67. OPTIONS PROMPT NL "Enter the Bill Of Materials (no suffix): "
  68. PULL BOM
  69.  
  70. IF BOM = "" THEN
  71. DO
  72.   SAY NL "No BOM file specified." NL
  73.   EXIT
  74. END
  75.  
  76. Check = 1
  77. IF DS THEN
  78.  DO
  79.   IF EXISTS(BOMdir || BOM".BOM") THEN Check = 0
  80.  END
  81. ELSE
  82.   IF EXISTS(BOM".BOM") THEN Check = 0
  83.  
  84. IF Check THEN
  85. DO
  86.   SAY "Bill of Materials" BOM".BOM does not exist.  Check the list."
  87.   EXIT
  88. END
  89.  
  90. /* Check if Part List already exists */
  91. Check = 0
  92. IF DS THEN
  93.  DO
  94.   IF EXISTS(BOMdir || BOM'.PAT') THEN Check = 1
  95.  END
  96. ELSE IF EXISTS(BOM'.PAT') THEN Check = 1
  97.  
  98. IF Check THEN
  99. DO
  100.   SAY NL "A Part List named" BOM".PAT already exists."
  101.   SAY " The information in this file will not be used."
  102.   OPTIONS PROMPT NL "Do you wish to continue? (Y/N)=> "
  103.   PULL Choice
  104.   IF (SUBSTR(Choice, 1, 1) ~= 'Y') THEN EXIT
  105.   SAY NL "Say bye-bye to the old Part List." NL
  106. END
  107.  
  108. IF DS THEN CALL OPEN('BOMlist', BOMdir || BOM'.BOM', 'r')
  109.       ELSE CALL OPEN('BOMlist', BOM'.BOM', 'r')
  110.  
  111. /* Open temporary Part List (no header information) */
  112. CALL OPEN('PATlist', 'T:PARTS', 'w')
  113.  
  114. /* Throw away first 8 lines from the Bill of Materials */
  115. DO 9
  116.   BOMline = READLN('BOMlist')
  117. END
  118.  
  119. /* Read lines from BOM & prompt for Device Type */
  120. DO UNTIL LENGTH(BOMline) = 0
  121.  
  122.   /* Device Names can have included spaces, so do not use PARSE */
  123.   Device = STRIP(SUBSTR(BOMline, 1, 15))
  124.   
  125.   /* Adjust BOMline to eliminate Device Name from text string   */
  126.   BOMline = SUBSTR(BOMline, 16)
  127.   PARSE VALUE BOMline WITH Quantity Labels
  128.   
  129.   /* Labels can continue on next line, so put all Labels in one string */
  130.   /* The last Label is denoted by a semi-colon                         */
  131.   DO WHILE (0 = INDEX(Labels, ";"))
  132.     BOMline = READLN('BOMlist')
  133.     Labels = Labels || BOMline
  134.   END
  135.   
  136.   /* Get rid of all spaces in Labels string and the ";" at end of string */
  137.   Labels = COMPRESS(STRIP(Labels,, ";"))
  138.   
  139.   /* Get Device type */
  140.   OPTIONS PROMPT NL "Is the" Device" a <D>IP, <S>IP, <T>wo-Pin, or <L>ib? "
  141.   PULL description
  142.   Type = SUBSTR(description, 1, 1)
  143.   DO WHILE (INDEX("DSTLE", Type) = 0)
  144.     SAY "Try again: Is the" Device" a <D>IP, <S>IP, <T>wo-Pin, or <L>ib?"
  145.     OPTIONS PROMPT "(<E>scape) => "
  146.     PULL description
  147.     Type = SUBSTR(description, 1, 1)
  148.     IF Type = 'E' THEN EXIT
  149.   END
  150.   
  151.   SELECT
  152.     WHEN Type = 'D' THEN
  153.      DO
  154.       OPTIONS PROMPT " How many pins does this DIP have? "
  155.       PULL Number
  156.       DO FOREVER
  157.         IF (Number//2 = 0) THEN LEAVE /* Modulo 2 check for evenness */
  158.         SAY NL "Come on! DIPs don't have an odd number of Pins."
  159.         PULL Number
  160.       END
  161.       OPTIONS PROMPT " What is the separation between rows of Pins? "
  162.       PULL Separation
  163.       /* I was going to automatically convert mils to inches,   */
  164.       /* but that would make it difficult for Metric unit users */
  165.       /* To use, eliminate the comments around the next line.   */
  166.       /* IF Number > 2 THEN Number = Number/1000                */
  167.       
  168.       /* Write the data */
  169.       LabelInfo = '/' || Type || '/' || Number || '/' || Separation || ';'
  170.       CALL WriteLine()
  171.      END
  172.     
  173.     WHEN Type = 'S' THEN
  174.      DO
  175.       OPTIONS PROMPT " How many pins does this SIP have? "
  176.       PULL Number
  177.       
  178.       LabelInfo = '/' || Type || '/' || Number || ';'
  179.       CALL WriteLine()
  180.      END
  181.     
  182.     WHEN Type = 'T' THEN
  183.      DO
  184.       OPTIONS PROMPT " What is the pin separation? "
  185.       PULL Separation
  186.       
  187.       LabelInfo = '/' || Type || '/' || Separation || ';'
  188.       CALL WriteLine()
  189.      END
  190.     
  191.     WHEN Type = 'L' THEN
  192.      DO
  193.       OPTIONS PROMPT " Which Library Part do you want to use here? "
  194.       PARSE PULL Library   /* Don't convert to upper case */
  195.       
  196.       LabelInfo = '/' || Type || '/' || Library || ';'
  197.       CALL WriteLine()
  198.      END
  199.   END
  200.   
  201.   /* Get next line of data for the next loop */
  202.   BOMline = READLN('BOMlist')
  203.  
  204. END
  205.  
  206. CALL CLOSE('PATlist')
  207. CALL CLOSE('BOMlist')
  208. CALL OPEN('HText', 'T:HEADER', 'w')
  209. CALL WRITELN('HText', "")
  210. CALL WRITELN('HText', "Part List :")
  211. CALL WRITELN('HText', "")
  212. CALL CLOSE('HText')
  213.  
  214. 'SORT T:PARTS T:PARTS'
  215.  
  216. IF DS THEN 'JOIN T:HEADER T:PARTS AS 'BOMdir || BOM'.PAT'
  217.       ELSE 'JOIN T:HEADER T:PARTS AS 'BOM'.PAT'
  218.  
  219. 'DELETE >NIL: T:PARTS'
  220. 'DELETE >NIL: T:HEADER'
  221.  
  222. SAY NL "  New Part List written." NL
  223. EXIT
  224.  
  225. /* Extract individual Device Labels from the string Labels */
  226. /* and write each line of data to the Part List file.      */
  227.  
  228. WriteLine:
  229.  
  230. Labels = STRIP(Labels,, NL)
  231. PARSE VAR Labels Label','Labels
  232.  
  233. DO UNTIL (LENGTH(Label) = 0)
  234.   CALL WRITELN('PATlist', Label || LabelInfo)
  235.   PARSE VAR Labels Label','Labels
  236. END
  237.  
  238. RETURN