/* $VER: PasFont2TDS 1.2 (9.9.97) © Copyright 1997 by hartmut Goebel ** ** Convert the PasTex pk-font-tree (as on Meeting-Pearls-IV) to TDS ** ** Usage: FontDir/A : base dir for fonts (e.g. TEX:Fonts) ** TargetDir : target base dir for fonts (e.g. share/tex/fonts) ** (defaults to FontDir) ** Copy/S : Do not move/rename the files but copy them ** LogFile/K : logfile (default: no logfile) ** Test/S : do not actually move/rename/copy ** MapFile/K : name of the mapfile to be read ** default: special.map_2.5b ** in addition 'special.map.local' will be read ** CheckMapFileOnly/S: read and check mapfiles, then finish ** ** Configuration: check the config-part below for correct dos commands; ** cmd_move will be used only then renaming across devices, ** since C:Rename does not handle this case ** ** Tips: ** 1) When using PasFonts2TDS for converting data _on_ a CD-ROM using ** CD-Write, it's recommended NOT to use the COPY option: this ** will copy the font files onto your hard-disk since the ** CD-Write file-system can't know the copy source is on this ** CD, too. Unfortunately BabelCDWrieFS 1.2 does not support ** links. ** If you want to copy your font file onto your hard-disk, it's ** perfectly fine to use the COPY option. ** ** 2) You may speed up things a lot by increasing the devices ** buffer size (C:AddBuffers). A test-run took about ** on my A4000/40 with A2091 (oh, well ...), even with laaarge ** buffers. ** ** Todo: - convert the tfm tree, too ** */ /*-- start of config-part --*/ DOS.CMD_COPY = "copy"; DOS.CMD_MOVE = "mv"; /* across devices */ /* if not available: set to "" (empty string) */ /*-- end of config-part --*/ options results call addlib('rexxdossupport.library', 0, -30, 1) call addlib('rexxsupport.library', 0, -30, 1) ProgramName = "PasFont2TDS" ArgsTemplate = "FontsDir/A,TargetDir=Target,Test/S,Copy/S,LogFile/K," ||, "MapFile/K,CheckMapFileOnly/S" parse arg arguments Args.Mapfile = "special.map_2.5b" if strip(arguments) = '?' then do call writech(STDOUT, ArgsTemplate': ') arguments = readln(STDIN) end; else nop if ~ ReadArgs(arguments,ArgsTemplate, args.) then do say Fault(RC,ProgramName) exit 10 end; else nop drop arguments if symbol('ARGS.LOGFILE') = 'VAR' then do if ~ open(LOG_FILE, args.logfile, 'w') then do say "Can't open logfile" args.logfile exit 20; end; drop args.logfile /* avoid errors */ end; else LOG_FILE = ''; if args.CheckMapfileOnly then do call time('r'); call ReadSupplierFile(args.mapfile); t = time('e'); say 'read' Supplier.E.0 + Supplier.P.0 'entries' if exists('special.map.local') then do call ReadSupplierFile('special.map.local') say 'read' Supplier.E.0 + Supplier.P.0 'entries (in total)' end; say 'elapsed time:' t % 60':'t // 60 exit 0; end; else call ReadSupplierFile(args.mapfile); if exists('special.map.local') then call ReadSupplierFile('special.map.local') if symbol('ARGS.TARGETDIR') ~= 'VAR' then args.targetdir = args.fontsdir; sourcedir = CheckExists(args.fontsdir); targetdir = CheckExists(args.targetdir); drop args.fontsdir args.targetdir DOS.SameDevice = CheckSameDevice(sourcedir,targetdir); return_value = 0; call time('r'); /* convert pk */ say "converting pk dir ..." sd = Addpart(sourcedir, 'pk'); td = Addpart(targetdir, 'pk'); if ~ Exists(sd) then do call ERR_LOG "No directory" sd "-- pk fonts are not converted" return_value = 5; end; else do mode_list = showdir(sd, 'DIR') do i = 1 to words(mode_list) call Convert_PK_DPIs(AddPart(sd, word(mode_list, i)), AddPArt(td, word(mode_list, i))); end call DeleteEmptyDirs(sd) end; /*--- todo ----- problem: tfm dir may or may not be pre-structured /* convert tfm */ say "converting tfm dir ..." sd = Addpart(sourcedir, 'tfm'); td = Addpart(targetdir, 'tfm'); if ~ Exists(sd) then do call ERR_LOG "No directory" sd "-- tfm files are not converted" return_value = 5; end; else do call Convert_TFM_DIRS(sd, td); list = showdir(sd, 'DIR') do i = 1 to words(list) call Convert_TFM_DIRS(AddPart(sd, td); end call DeleteEmptyDirs(sd) end; ---*/ t = time('e'); call ERR_LOG('elapsed time:' t % 60':'t // 60) exit return_value; /*--------------*/ /* todo Concert_TFM_Dirs: PROCEDURE expose DOS. Supplier. Args. Log_File sourcedir = arg(1); targetdir = arg(2); list = showdir(sd), 'DIR') do i = 1 to words(list) call Convert_TFM_DIRS(AddPart(sd, td); end return '' */ Convert_PK_DPIs: PROCEDURE expose DOS. Supplier. Args. Log_File sourcedir = arg(1); targetdir = arg(2); dir_list = showdir(sourcedir, 'DIR') do i = 1 to words(dir_list) call Convert_PK_Fonts(sourcedir, targetdir, word(dir_list, i)); end return ''; Convert_PK_Fonts: PROCEDURE expose DOS. Supplier. Args. Log_File sourcedir = arg(1); targetdir = arg(2); dpi = arg(3); dpidir = addpart(sourcedir, dpi); say dpidir file_list = SHOWDIR(dpidir, 'FILE'); do i = 1 to words(file_list) file = word(file_list, i); parse var file base '.' dummy 'pk' if dummy ~= dpi then do call ERR_LOG (dummy dpi) call ERR_LOG ("error: file" file 'seams to be in wrong dir' Addpart(sourcedir, dpi)) /*exit 10*/ end; supplier = FindSupplier(base); if supplier = 'unknow' then call ERR_LOG ('Supplier is unknow for font' base) else do targetfile = AddMultiPart(targetdir, supplier, 'dpi'dpi, base'.pk') call MoveFile(addpart(dpidir, file), targetfile) end end return ''; /*--------------*/ ERR_LOG: expose LOG_FILE say arg(1); call LOG(arg(1)); return; LOG: PROCEDURE expose LOG_FILE if LOG_FILE ~= "" then do call WriteLn(LOG_FILE, arg(1)); end return '' MoveFile: PROCEDURE expose Args. DOS. LOG_FILE fromfile = arg(1); tofile = arg(2); todir = PathPart(tofile); call LOG('moving' fromfile '-->' tofile); if ~ args.test then do if ~ exists(todir) then mkdir(todir) /* recursively make target dir */ if Args.Copy then do address command DOS.CMD_COPY fromfile tofile end; else if DOS.SameDevice then do call Rename(fromfile, tofile); end; else if DOS.CMD_MOVE ~= "" then do address command DOS.CMD_MOVE fromfile tofile end; else do address command DOS.CMD_COPY fromfile tofile call Delete(fromfile); end; end return '' AddMultiPart: PROCEDURE name=arg(1) do i=2 to arg() name=addpart(name,arg(i)); end; return name CheckSameDevice: PROCEDURE parse value AbsolutePath(arg(1)) with a ':' . parse value AbsolutePath(arg(2)) with b ':' . return a = b CheckExists: PROCEDURE name = AbsolutePath(arg(1)); IF RC ~= 0 then do say "can't find/lock directory" arg(1) exit 10 end; return name DeleteEmptyDirs: PROCEDURE expose Args. dir = arg(1); list = showdir(dir, 'DIR') do i = 1 to words(list) call DeleteEmptyDirs(word(list, i)) end if showdir(dir, 'ALL') = "" then do if ~ Args.test then do call LOG('deleting' dir); call Delete(dir); end; end; return '' /*--------------*/ FindSupplier: PROCEDURE expose Supplier. RESULT fontname = arg(1); RESULT = ''; do i = 1 for Supplier.E.0 if fontname = supplier.E.i.prefix then do RESULT = supplier.E.i.prefix; return supplier.E.i.dir end; end; do i = 1 for Supplier.P.0 if abbrev(fontname, supplier.P.i.prefix) then do RESULT = supplier.P.i.prefix; return supplier.P.i.dir end; end; return 'unknow'; ReadSupplierFile: PROCEDURE expose Supplier. Args. LOG_FILE IF ~ open(SUP_FILE, arg(1), 'R') then do say "Can't open supplier mapfile" arg(1); exit 10 end; say "reading supplier mapfile" arg(1) "..." if symbol('Supplier.E.0') ~= 'VAR' then do /* first mapfile */ Supplier.E.0 = 0; Supplier.P.0 = 0; end; do while ~eof(SUP_FILE) line = strip(readln(SUP_FILE)); select when line = "" then; iterate when left(line, 1) = "@" then; do if left(line, 2) = "@c" then /* comment */ iterate /* comment */ else do parse var line cmd . say "unknown command in supplier mapfile" arg(1)':' cmd exit 20 end; end otherwise /* supplier entry */ parse var line prefix type name . call AddSupplierEntry(prefix, strip(type)'/'strip(name)) end; end call close(SUP_FILE); return '' AddSupplierEntry: PROCEDURE expose Supplier. Args. LOG_FILE prefix_name = arg(1); if FindSupplier(prefix_name) ~= 'unknow' then do call ERR_LOG("ambiguos prefix" prefix_name "(already matched by" RESULT")") return '' end; type = 'P'; if datatype(right(prefix_name, 1), "NUM") then type = 'E'; i = Supplier.type.0+1 Supplier.type.i.prefix = prefix_name; Supplier.type.i.dir = arg(2); Supplier.type.0 = i; return '';