Changeset 2851
- Timestamp:
- Dec 28, 2017, 12:55:15 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/netlabs/bin/colors.erx ¶
r2783 r2851 119 119 GlobalVars = GlobalVars 'PalTitlePrefix ObjectIdPrefix' 120 120 GlobalVars = GlobalVars 'PalIndexList ColorList' 121 GlobalVars = GlobalVars 'WorkDir TmpDir DllName' 121 GlobalVars = GlobalVars 'WorkDir TmpDir DllName NepmdIni rc' 122 /* rc was made global to allow functions return other values */ 122 123 /* -------------------------------------------- */ 123 124 … … 140 141 DestDllDir = UserDir'\dll' 141 142 TmpDir = UserDir'\tmp' /* Better use a unique name in %TMP%? */ 142 143 NepmdIni = VALUE( 'NEPMD_USERDIR',, env)'\bin\NEPMD.INI' /* Full filename of NEPMD.INI */ 143 144 144 145 DO 1 … … 614 615 /* section in StdCfg or Remove it already before call to this func from */ 615 616 /* AddCfg array */ 616 617 617 SaveAddCfg: PROCEDURE EXPOSE (GlobalVars) 618 618 … … 623 623 /* Write new color cfg to TmpFile */ 624 624 DO 1 625 IF STREAM( TmpFile, 'C', 'QUERY EXIST') <> ''THEN625 IF FileExist( TmpFile) THEN 626 626 rcx = FileDelete( TmpFile) 627 627 next = STREAM( TmpFile, 'C', 'OPEN WRITE') … … 660 660 END 661 661 next = STREAM( TmpFile, 'C', 'CLOSE') 662 IF STREAM( TmpFile, 'C', 'QUERY EXIST') = ''THEN662 IF \FileExist( TmpFile) THEN 663 663 DO 664 664 rc = ERROR.WRITE_FAULT … … 1333 1333 1334 1334 /* ----------------------------------------------------------------------- */ 1335 FileExist: PROCEDURE 1335 FindTool: PROCEDURE EXPOSE (GlobalVars) 1336 Exe = '' 1337 Parameters = '' 1338 WorkingDir = '' 1339 DefaultCmd = '' 1340 ValidKeywords = 'Exe Parameters WorkingDir DefaultCmd' 1341 1342 FoundExe = '' 1343 fWpsEntry = 0 1344 do once = 1 to 1 1345 Tool = Lower( ARG(1)) 1346 /* Allow for a space- or a semicolon-separated keyword list. */ 1347 /* Keywords are case-sensitive (camel-case). */ 1348 Keywords = STRIP( TRANSLATE( ARG(2), ' ', ';')) 1349 /* Check keywords */ 1350 UnknownKeywords = '' 1351 DO w = 1 TO WORDS( Keywords) 1352 next = WORD( Keywords, w) 1353 IF WORDPOS( next, ValidKeywords) = 0 THEN 1354 UnknownKeywords = strip( UnknownKeywords next) 1355 END 1356 IF UnknownKeywords <> '' THEN 1357 DO 1358 ErrorMessage = 'FindTool: Unknown keyword(s) "'UnknownKeywords'" specified.' 1359 rc = ERROR.INVALID_PARAMETER 1360 RETURN '' 1361 END 1362 1363 /* Check if key \ToolBaseName is defined */ 1364 /* This key can be used as a reference to another exe */ 1365 KeyPath = '\NEPMD\User\Tools\'Tool'\ToolBaseName' 1366 CfgToolBaseName = Lower( SysIni( NepmdIni, 'RegKeys', KeyPath)) 1367 /* If not, take Tool instead */ 1368 IF CfgToolBaseName <> '' THEN 1369 ToolBaseName = CfgToolBaseName 1370 ELSE 1371 ToolBaseName = Tool 1372 1373 /* Strip extension */ 1374 p2 = LASTPOS( '.exe', ToolBaseName) 1375 IF p2 > 1 THEN 1376 ToolBaseName = SUBSTR( ToolBaseName, 1, p2 - 1) 1377 1378 /* Refer to defined config key */ 1379 IF WORDPOS( ToolBaseName,'md5sum md5suml md5') THEN 1380 ToolBaseName = 'md5' 1381 1382 /* Read entries from ini */ 1383 KeyPath = '\NEPMD\User\Tools\'ToolBaseName 1384 Exe = SysIni( NepmdIni, 'RegKeys', KeyPath'\Exe') 1385 Parameters = SysIni( NepmdIni, 'RegKeys', Keypath'\Parameters') 1386 WorkingDir = SysIni( NepmdIni, 'RegKeys', KeyPath'\WorkingDir') 1387 DefaultCmd = SysIni( NepmdIni, 'RegKeys', KeyPath'\DefaultCmd') 1388 1389 /* Allow for specifying env vars in value */ 1390 Exe = ResolveEnvVars( Exe) 1391 WorkingDir = ResolveEnvVars( WorkingDir) 1392 1393 /* Use fallback value if config key isn't defined */ 1394 IF Exe = '' THEN 1395 Exe = ToolBaseName'.exe' 1396 1397 /* Handle WPS and fully qualified filenames */ 1398 IF TRANSLATE( Exe) = 'WPS' THEN 1399 DO 1400 fWpsEntry = 1 1401 leave 1402 END 1403 IF POS( ':\', Exe) | LEFT( Exe, 2) = '\\' THEN 1404 DO 1405 IF FileExist( Exe) THEN 1406 DO 1407 FoundExe = Exe 1408 LEAVE 1409 END 1410 END 1411 1412 ToolList = Exe 1413 PathEnvVarList = 'PATH EPMTOOLSPATH' 1414 FoundExe = '' 1415 DO w = 1 TO WORDS( PathEnvVarList) 1416 CurPath = WORD( PathEnvVarList, w) 1417 Rest = ToolList 1418 DO FOREVER 1419 IF Rest = '' THEN 1420 LEAVE 1421 PARSE VALUE Rest WITH FSpec';'Rest 1422 FoundExe = SysSearchPath( CurPath, FSpec) 1423 IF FoundExe <> '' THEN 1424 LEAVE 1425 END 1426 IF FoundExe <> '' THEN 1427 LEAVE 1428 END 1429 1430 END 1431 1432 IF fWpsEntry THEN 1433 SELECT 1434 WHEN Tool = 'mail' THEN 1435 DO 1436 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultMailExe') 1437 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultMailExe') 1438 Parameters = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultMailParameters') 1439 WorkingDir = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultMailWorkingDir') 1440 END 1441 WHEN Tool = 'news' THEN 1442 DO 1443 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultNewsExe') 1444 Parameters = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultNewsParameters') 1445 WorkingDir = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultNewsWorkingDir') 1446 END 1447 WHEN Tool = 'ftp' THEN 1448 DO 1449 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultFTPExe') 1450 Parameters = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultFTPParameters') 1451 WorkingDir = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultFTPWorkingDir') 1452 END 1453 WHEN Tool = 'irc' THEN 1454 DO 1455 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultIRCExe') 1456 Parameters = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultIRCParameters') 1457 WorkingDir = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultIRCWorkingDir') 1458 END 1459 END 1460 IF Tool = 'browser' | Exe = '' THEN 1461 DO 1462 Exe = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultBrowserExe') 1463 Parameters = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultParameters') 1464 WorkingDir = SysIni( 'USER', 'WPURLDEFAULTSETTINGS', 'DefaultWorkingDir') 1465 END 1466 FoundExe = Exe 1467 endif 1468 1469 RetString = '' 1470 IF Keywords = '' THEN 1471 RetString = FoundExe 1472 ELSE 1473 DO k = 1 to WORDS( Keywords) 1474 Keyword = WORD( Keywords, k) 1475 Val = '' 1476 SELECT 1477 WHEN Keyword = 'Exe' THEN 1478 Val = FoundExe 1479 WHEN Keyword = 'Parameters' THEN 1480 Val = Parameters 1481 WHEN Keyword = 'WorkingDir' THEN 1482 Val = WorkingDir 1483 WHEN Keyword = 'DefaultCmd' THEN 1484 Val = DefaultCmd 1485 END 1486 RetString = RetString''Keyword'='Val';' 1487 END 1488 RETURN RetString 1489 1490 /* ----------------------------------------------------------------------- */ 1491 /* Resolves environment variables in a string. Keeps %...% string if env */ 1492 /* var isn't set. Additionally ?: is replaced with the boot drive. Returns */ 1493 /* converted string. */ 1494 /* To convert also '=', the proc parse_filename( filename) should be used. */ 1495 /* It calls this proc as well. */ 1496 ResolveEnvVars: PROCEDURE EXPOSE (GlobalVars) 1497 Spec = ARG(1) 1498 1499 startp = 1 1500 DO FOREVER 1501 p1 = POS( '%', Spec, startp) 1502 IF p1 = 0 THEN 1503 LEAVE 1504 startp = p1 + 1 1505 p2 = POS( '%', Spec, startp) 1506 IF p2 = 0 THEN 1507 LEAVE 1508 LeftPart = SUBSTR( Spec, 1, p1 - 1) 1509 EnvVarName = SUBSTR( Spec, p1 + 1, p2 - p1 - 1) 1510 RightPart = SUBSTR( Spec, p2 + 1) 1511 EnvVarValue = Get_Env( EnvVarName) 1512 /* Handle unset vars: keep %... or %...% string */ 1513 IF EnvVarValue = '' THEN 1514 ITERATE 1515 /* Value exists, replace %...% string and move startp */ 1516 startp = LENGTH( LeftPart) + LENGTH( EnvVarValue) + 1 1517 Spec = LeftPart''EnvVarValue''RightPart 1518 END 1519 1520 /* Replace ?: with bootdrive */ 1521 DO WHILE POS( '?:', Spec) > 0 1522 PARSE VALUE Spec WITH LeftPart'?:'RightPart 1523 BootDrive = GetBootDrive() 1524 Spec = LeftPart''BootDrive''RightPart 1525 END 1526 1527 RETURN Spec 1528 1529 /* ----------------------------------------------------------------------- */ 1530 LOWER: PROCEDURE EXPOSE (GlobalVars) 1531 1532 Lower = 'abcdefghijklmnopqrstuvwxyz' 1533 Upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1534 1535 PARSE ARG String 1536 RETURN( TRANSLATE( String, Lower, Upper)) 1537 1538 /* ----------------------------------------------------------------------- */ 1539 FileExist: PROCEDURE EXPOSE (GlobalVars) 1336 1540 PARSE ARG Filename 1337 1541 IF FileName = '' THEN
Note:
See TracChangeset
for help on using the changeset viewer.