ResourcePack.st
changeset 6992 498b1d7e697e
parent 6919 61df9e689fca
child 7387 d741fec3516b
equal deleted inserted replaced
6991:8271065cb89a 6992:498b1d7e697e
  1384 
  1384 
  1385     |lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler
  1385     |lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler
  1386      printError fileName pushedSkipValues|
  1386      printError fileName pushedSkipValues|
  1387 
  1387 
  1388     fileName := (inStream isFileStream
  1388     fileName := (inStream isFileStream
  1389 		    ifTrue:[inStream pathName asFilename baseName]
  1389                     ifTrue:[inStream pathName asFilename baseName]
  1390 		    ifFalse:['---']).
  1390                     ifFalse:['---']).
  1391 
  1391 
  1392     printError := [:message |
  1392     printError := [:message |
  1393 		    'ResourcePack [warning]: ' errorPrint.
  1393                     'ResourcePack [warning]: ' errorPrint.
  1394 		    message errorPrint.
  1394                     message errorPrint.
  1395 		    ' in file:' errorPrint.
  1395                     ' in file:' errorPrint.
  1396 		    fileName errorPrint.
  1396                     fileName errorPrint.
  1397 		    ' line: ' errorPrint.
  1397                     ' line: ' errorPrint.
  1398 		    lineNumber errorPrintCR
  1398                     lineNumber errorPrintCR
  1399 		  ].
  1399                   ].
  1400 
  1400 
  1401     printError := [:message | ].
  1401     printError := [:message | ].
  1402 
  1402 
  1403     encoding := nil.
  1403     encoding := nil.
  1404 
  1404 
  1407     skipping := false.
  1407     skipping := false.
  1408     lineNumber := 0.
  1408     lineNumber := 0.
  1409     pushedSkipValues := OrderedCollection new.
  1409     pushedSkipValues := OrderedCollection new.
  1410 
  1410 
  1411     errorHandler := [:ex |
  1411     errorHandler := [:ex |
  1412 			|con|
  1412                         |con|
  1413 
  1413 
  1414 			Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR".
  1414                         Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR".
  1415 			Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR".
  1415                         Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR".
  1416 			con := ex suspendedContext.
  1416                         con := ex suspendedContext.
  1417 			Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR".
  1417                         Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR".
  1418 			con := con sender.
  1418                         con := con sender.
  1419 			Transcript showCR:('ResourcePack [info]:   : ' , con fullPrintString) "errorPrintCR".
  1419                         Transcript showCR:('ResourcePack [info]:   : ' , con fullPrintString) "errorPrintCR".
  1420 			con := con sender.
  1420                         20 timesRepeat:[
  1421 			Transcript showCR:('ResourcePack [info]:   : ' , con fullPrintString) "errorPrintCR".
  1421                             con notNil ifTrue:[
  1422 			value := nil.
  1422                                 con := con sender.
  1423 			ok := false.
  1423                                 Transcript showCR:('ResourcePack [info]:   : ' , con fullPrintString) "errorPrintCR".
  1424 		    ].
  1424                             ].
       
  1425                         ].    
       
  1426                         value := nil.
       
  1427                         ok := false.
       
  1428                     ].
  1425 
  1429 
  1426     [inStream atEnd] whileFalse:[
  1430     [inStream atEnd] whileFalse:[
  1427 	lineString := inStream nextLine. lineNumber := lineNumber + 1.
  1431         lineString := inStream nextLine. lineNumber := lineNumber + 1.
  1428 	[lineString notNil and:[lineString endsWith:$\]] whileTrue:[
  1432         [lineString notNil and:[lineString endsWith:$\]] whileTrue:[
  1429 	    lineString := lineString copyButLast:1.
  1433             lineString := lineString copyButLast:1.
  1430 	    l := inStream nextLine. lineNumber := lineNumber + 1.
  1434             l := inStream nextLine. lineNumber := lineNumber + 1.
  1431 	    l notNil ifTrue:[
  1435             l notNil ifTrue:[
  1432 		lineString := lineString , l.
  1436                 lineString := lineString , l.
  1433 	    ].
  1437             ].
  1434 	].
  1438         ].
  1435 
  1439 
  1436 	(lineString size > 0) ifTrue:[
  1440         (lineString size > 0) ifTrue:[
  1437 	    first := lineString at:1.
  1441             first := lineString at:1.
  1438 	    "/
  1442             "/
  1439 	    "/ for your convenience: treat both ';' AND '"/' as comment-line
  1443             "/ for your convenience: treat both ';' AND '"/' as comment-line
  1440 	    "/
  1444             "/
  1441 	    ((first == $;) or:[lineString startsWith:'"/']) ifFalse:[
  1445             ((first == $;) or:[lineString startsWith:'"/']) ifFalse:[
  1442 		((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[
  1446                 ((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[
  1443 		    "/ a directive
  1447                     "/ a directive
  1444 		    lineString := (lineString copyFrom:2) withoutSpaces.
  1448                     lineString := (lineString copyFrom:2) withoutSpaces.
  1445 
  1449 
  1446 		    (lineString startsWith:'if') ifTrue:[
  1450                     (lineString startsWith:'if') ifTrue:[
  1447 			pushedSkipValues add:skipping.
  1451                         pushedSkipValues add:skipping.
  1448 			skipping ifFalse:[
  1452                         skipping ifFalse:[
  1449 			    rest := lineString copyFrom:3.
  1453                             rest := lineString copyFrom:3.
  1450 			    Error, UserInformation
  1454                             Error, UserInformation
  1451 				handle:errorHandler
  1455                                 handle:errorHandler
  1452 				do:[
  1456                                 do:[
  1453 				    value := Compiler evaluate:rest compile:false.
  1457                                     value := Compiler evaluate:rest compile:false.
  1454 				].
  1458                                 ].
  1455 			    (value == #Error) ifTrue:[
  1459                             (value == #Error) ifTrue:[
  1456 				printError value:('error in resource:' , lineString).
  1460                                 printError value:('error in resource:' , lineString).
  1457 			    ].
  1461                             ].
  1458 			    (value == false) ifTrue:[
  1462                             (value == false) ifTrue:[
  1459 				skipping := true
  1463                                 skipping := true
  1460 			    ]
  1464                             ]
  1461 			].
  1465                         ].
  1462 			ifLevel := ifLevel + 1
  1466                         ifLevel := ifLevel + 1
  1463 		    ] ifFalse:[
  1467                     ] ifFalse:[
  1464 			(lineString startsWith:'endif') ifTrue:[
  1468                         (lineString startsWith:'endif') ifTrue:[
  1465 			    ifLevel == 0 ifTrue:[
  1469                             ifLevel == 0 ifTrue:[
  1466 				printError value:('if/endif nesting error').
  1470                                 printError value:('if/endif nesting error').
  1467 			    ] ifFalse:[
  1471                             ] ifFalse:[
  1468 				ifLevel := ifLevel - 1.
  1472                                 ifLevel := ifLevel - 1.
  1469 				skipping := pushedSkipValues removeLast.
  1473                                 skipping := pushedSkipValues removeLast.
  1470 			    ]
  1474                             ]
  1471 			] ifFalse:[
  1475                         ] ifFalse:[
  1472 			    (lineString startsWith:'else') ifTrue:[
  1476                             (lineString startsWith:'else') ifTrue:[
  1473 				(pushedSkipValues includes:true) ifFalse:[
  1477                                 (pushedSkipValues includes:true) ifFalse:[
  1474 				    skipping := skipping not
  1478                                     skipping := skipping not
  1475 				]
  1479                                 ]
  1476 			    ] ifFalse:[
  1480                             ] ifFalse:[
  1477 				skipping ifFalse:[
  1481                                 skipping ifFalse:[
  1478 				    (lineString startsWith:'superpack') ifTrue:[
  1482                                     (lineString startsWith:'superpack') ifTrue:[
  1479 					rest := lineString copyFrom:('superpack' size + 1).
  1483                                         rest := lineString copyFrom:('superpack' size + 1).
  1480 					value := Compiler evaluate:rest compile:false.
  1484                                         value := Compiler evaluate:rest compile:false.
  1481 					(value isKindOf:ResourcePack) ifTrue:[
  1485                                         (value isKindOf:ResourcePack) ifTrue:[
  1482 					    superPack := value
  1486                                             superPack := value
  1483 					]
  1487                                         ]
  1484 				    ] ifFalse:[
  1488                                     ] ifFalse:[
  1485 					(lineString startsWith:'include') ifTrue:[
  1489                                         (lineString startsWith:'include') ifTrue:[
  1486 					    (lineString startsWith:'includeResourcesFor') ifTrue:[
  1490                                             (lineString startsWith:'includeResourcesFor') ifTrue:[
  1487 						"/ include those resources ...
  1491                                                 "/ include those resources ...
  1488 						rest := lineString copyFrom:('includeResourcesFor' size + 1).
  1492                                                 rest := lineString copyFrom:('includeResourcesFor' size + 1).
  1489 						value := Compiler evaluate:rest compile:false.
  1493                                                 value := Compiler evaluate:rest compile:false.
  1490 						value isBehavior ifTrue:[
  1494                                                 value isBehavior ifTrue:[
  1491 						    pack := self class for:value.
  1495                                                     pack := self class for:value.
  1492 						    pack notNil ifTrue:[
  1496                                                     pack notNil ifTrue:[
  1493 							self addAll:pack.
  1497                                                         self addAll:pack.
  1494 						    ]
  1498                                                     ]
  1495 						]
  1499                                                 ]
  1496 					    ] ifFalse:[
  1500                                             ] ifFalse:[
  1497 						rest := lineString copyFrom:('include' size + 1).
  1501                                                 rest := lineString copyFrom:('include' size + 1).
  1498 						value := Compiler evaluate:rest compile:false.
  1502                                                 value := Compiler evaluate:rest compile:false.
  1499 						value isString ifFalse:[
  1503                                                 value isString ifFalse:[
  1500 						    printError value:('bad include filename: ' , value printString, ' "',lineString,'"').
  1504                                                     printError value:('bad include filename: ' , value printString, ' "',lineString,'"').
  1501 						] ifTrue:[
  1505                                                 ] ifTrue:[
  1502 						    self readFromFile:value directory:dirName
  1506                                                     self readFromFile:value directory:dirName
  1503 						]
  1507                                                 ]
  1504 					    ]
  1508                                             ]
  1505 					] ifFalse:[
  1509                                         ] ifFalse:[
  1506 					    (lineString startsWith:'encoding') ifTrue:[
  1510                                             (lineString startsWith:'encoding') ifTrue:[
  1507 "/decoder notNil ifTrue:[self halt:'oops - encoding change in file'].
  1511 "/decoder notNil ifTrue:[self halt:'oops - encoding change in file'].
  1508 						encoding := self class extractEncodingFromLine:lineString.
  1512                                                 encoding := self class extractEncodingFromLine:lineString.
  1509 						decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
  1513                                                 decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
  1510 					    ]
  1514                                             ]
  1511 					]
  1515                                         ]
  1512 				    ]
  1516                                     ]
  1513 				]
  1517                                 ]
  1514 			    ]
  1518                             ]
  1515 			]
  1519                         ]
  1516 		    ].
  1520                     ].
  1517 		] ifFalse:[
  1521                 ] ifFalse:[
  1518 		    skipping ifFalse:[
  1522                     skipping ifFalse:[
  1519 			Error, UserInformation
  1523                         Error, UserInformation
  1520 			    handle:errorHandler
  1524                             handle:errorHandler
  1521 			    do:[
  1525                             do:[
  1522 				(lineString at:1) == $!! ifTrue:[
  1526                                 (lineString at:1) == $!! ifTrue:[
  1523 				    "/ evaluate the rest
  1527                                     "/ evaluate the rest
  1524 				    Compiler evaluate:(lineString copyFrom:2)
  1528                                     Compiler evaluate:(lineString copyFrom:2)
  1525 						      receiver:self
  1529                                                       receiver:self
  1526 						      notifying:nil
  1530                                                       notifying:nil
  1527 						      compile:false.
  1531                                                       compile:false.
  1528 				] ifFalse:[
  1532                                 ] ifFalse:[
  1529 				    "/ process as resource
  1533                                     "/ process as resource
  1530 				    self
  1534                                     self
  1531 					processLine:lineString
  1535                                         processLine:lineString
  1532 					encoding:decoder
  1536                                         encoding:decoder
  1533 					file:(inStream isFileStream
  1537                                         file:(inStream isFileStream
  1534 						ifTrue:[inStream pathName]
  1538                                                 ifTrue:[inStream pathName]
  1535 						ifFalse:['---'])
  1539                                                 ifFalse:['---'])
  1536 					printErrorWith:printError
  1540                                         printErrorWith:printError
  1537 				]]
  1541                                 ]]
  1538 		    ]
  1542                     ]
  1539 		]
  1543                 ]
  1540 	    ]
  1544             ]
  1541 	]
  1545         ]
  1542     ].
  1546     ].
  1543     ^ ok
  1547     ^ ok
  1544 
  1548 
  1545     "Modified: / 31-08-1995 / 02:33:45 / claus"
  1549     "Modified: / 31-08-1995 / 02:33:45 / claus"
  1546     "Modified: / 18-09-2006 / 20:35:37 / cg"
  1550     "Modified: / 18-09-2006 / 20:35:37 / cg"