(* JOBS.PAS -- create jobs for cvt2xxx ** Copyright (c) 1996 Jochen Metzinger ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2, or (at your option) ** any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *) UNIT jobs; INTERFACE USES DOS, global, geos, coding, errors, cfg; CONST MAX_JOB_SIZE = 30; (* max. number of entries in .CFG file *) PROCEDURE job_init; (* initialize jobs *) FUNCTION job_first(info: InfoRec; fname: STRING): STRING; (* set up work for this info/fname pair *) FUNCTION job_next(exit_code: INTEGER): STRING; (* get next job after last job return `exit_code' *) IMPLEMENTATION TYPE EntryType = RECORD gtype: INTEGER; class, jobs: STRING; END; (* EntryType *) VAR (* job buffer *) entry: ARRAY [1..MAX_JOB_SIZE] OF EntryType; entry_max: WORD; (* file info *) D: DirStr; N: NameStr; E: ExtStr; this_gtype: INTEGER; this_class: STRING; (* job position *) entry_pos: WORD; the_jobs: STRING; PROCEDURE job_init; VAR i: WORD; BEGIN cfg_open; i := 1; WHILE cfg_line(entry[i].gtype, entry[i].class, entry[i].jobs) DO BEGIN INC(i); IF i > MAX_JOB_SIZE THEN FATAL('entry array overflow'); END; (* while *) entry_max := i; cfg_close; END; (* job_init *) FUNCTION job_first(info: InfoRec; fname: STRING): STRING; BEGIN job_first := ''; FSplit(fname,D,N,E); this_gtype := info.gtyp; this_class := TransStr(TermString(info.class, #0)); entry_pos := 0; the_jobs := ''; job_first := job_next(42); END; (* job_first *) FUNCTION subst(job: STRING): STRING; (* substitute '%' in job *) VAR i: BYTE; out: STRING; BEGIN out := ''; i := 1; WHILE i <= Length(job) DO BEGIN IF job[i] <> '%' THEN out := out + job[i] ELSE BEGIN INC(i); IF i > Length(job) THEN out := out + '%' ELSE CASE UpCase(job[i]) OF '%': out := out + '%'; '.': out := out + ';'; 'B': out := out + N; 'E': out := out + E; 'F': out := out + D + N + E; 'N': out := out + N + E; 'P': out := out + D; ELSE out := out + '%' + job[i]; END; (* case *) END; (* else *) INC(i); END; (* while *) subst := out; END; (* subst *) FUNCTION get_next_job: STRING; (* get next job from `the_jobs' *) VAR pos_semicolon: INTEGER; job: STRING; BEGIN get_next_job := ''; (* get 1st job in jobs *) REPEAT IF the_jobs = '' THEN EXIT; pos_semicolon := Pos(';', the_jobs); IF pos_semicolon < 1 THEN BEGIN job := the_jobs; the_jobs := ''; END ELSE BEGIN job := Copy(the_jobs, 1 ,pos_semicolon-1); Delete(the_jobs, 1, pos_semicolon); END; (* else *) UNTIL job <> ''; (* Delete leading spaces *) WHILE Copy(job, 1, 1) = ' ' DO Delete(job, 1, 1); (* return job *) get_next_job := subst(job); END; (* get_next_job *) FUNCTION job_next(exit_code: INTEGER): STRING; VAR i: INTEGER; BEGIN job_next := ''; (* next job in this entry *) IF exit_code <> 0 THEN BEGIN the_jobs := ''; INC(entry_pos); END ELSE IF the_jobs = '' THEN EXIT (* all done *) ELSE BEGIN job_next := get_next_job; EXIT END; (* if *) (* get next entry *) WHILE entry_pos < entry_max DO WITH entry[entry_pos] DO BEGIN IF (gtype = -1) OR (this_gtype = gtype) THEN IF (class = '') OR (Pos(class, this_class) = 1) THEN BEGIN (* next line found *) the_jobs := jobs; job_next := get_next_job; EXIT END; (* if *) Inc(entry_pos); END; (* whith *) (* no entries found *) END; (* job_next *) END. (* jobs *)