home *** CD-ROM | disk | FTP | other *** search
- UNIT startup; {$project vt }
- { Wertet die Programmstartargumente für VideoText aus }
- { ToolTypes: CLI-Parameter: }
- { FILE=<output name> -f=<output name> }
- { FILEMODE=<flag>|<flag>|... }
- { ICONPATH=<pathname> -i=<pathname> }
- { EDITOR=<dos command> -e=<dos command> }
- { CONFIGPATH=<pathname> -c=<pathname> }
- { PALETTE=<rgb>,<rgb>,... -p<rgb>,<rgb>,... }
- { MAXWAIT=<seconds> -w<seconds> }
- { BUSDELAY=<counter> -d<counter> }
- { BURST=<tics> -b<tics> }
- { SHUFFLE=<tics> -s<tics> }
- { FLAGS=<flag>|<flag>|... }
- { <page> <page> ... }
- { <file> <file> ... }
-
- INTERFACE; FROM vt USES jobs;
-
- VAR testing: Boolean;
-
- FUNCTION write_to_icon: Boolean;
- PROCEDURE get_args;
-
- { ---------------------------------------------------------------------- }
-
- IMPLEMENTATION;
-
- {$opt q,s+,i+ } { keine Laufzeitprüfungen außer Stack und Feldindizes }
- {$incl "workbench/startup.h", "icon.lib", "dos.lib" }
- {$incl "exec.lib", "dos/dosextens.h" }
-
- TYPE keyid=(fil,flm,icp,edi,cfp,pal,mxw,bdl,bst,shu,flg,
- asc,vtx,ovw,apd,ics,nic,num,nnm,fif,lif,clk);
- keywords=ARRAY[keyid] OF Str; { s. Inititalisierungsteil }
-
- VAR mypath,homedir: BPTR;
- myname,colors: str80;
- busdelay: Integer;
- hail: p_WBStartup;
- arg: p_WBArg;
- pr: ^Process;
- mycli: ^CommandLineInterface;
- s: ^String[1000];
- keys,ttarry: keywords;
- ttypes: ARRAY[fil..flg] OF str80; STATIC;
-
- PROCEDURE read_from_icon;
- { Startparameter lesen }
- VAR icon: p_DiskObject;
- entry: Str;
- olddir: BPTR;
- ok: Integer;
- key,key2: keyid;
- BEGIN
- IF IconBase=Nil THEN Exit;
- olddir := CurrentDir(mypath);
- icon := GetDiskObject(myname);
- IF icon<>Nil THEN BEGIN
- FOR key := fil TO flg DO BEGIN
- entry := FindToolType(icon^.do_ToolTypes, keys[key]);
- IF Ptr(entry)<>Nil THEN CASE key OF
- fil: outputname := entry;
- flm: FOR key2 := asc TO nnm DO
- IF MatchToolValue(entry,keys[key2]) THEN CASE key2 OF
- asc: asciifile := True;
- vtx: asciifile := False;
- ovw: overwrite := True;
- apd: overwrite := False;
- ics: withicon := True;
- nic: withicon := False;
- num: numbering := True;
- nnm: numbering := False;
- OTHERWISE;
- END;
- icp: iconpath := entry;
- edi: editor := entry;
- cfp: configpath := entry;
- pal: colors := entry;
- mxw: Val(entry,maxwait,ok);
- bdl: Val(entry,busdelay,ok);
- bst: Val(entry,burst,ok);
- shu: Val(entry,shuffle,ok);
- flg: FOR key2 := fif TO clk DO
- IF MatchToolValue(entry,keys[key2]) THEN CASE key2 OF
- fif: fifo := True;
- lif: fifo := False;
- clk: testing := True;
- OTHERWISE;
- END;
- OTHERWISE;
- END;
- END;
- FreeDiskObject(icon);
- END;
- olddir := CurrentDir(olddir);
- END;
-
- FUNCTION write_to_icon{: Boolean};
- { aktuelle Parameter ins Icon zurückschreiben }
- VAR icon: p_DiskObject;
- olddir: BPTR;
- s1: str80;
- j: Integer;
- key: keyid;
- BEGIN
- write_to_icon := False;
- IF IconBase=Nil THEN Exit;
- olddir := CurrentDir(mypath);
- icon := GetDiskObject(myname);
- IF icon<>Nil THEN BEGIN
- FOR key := fil TO clk DO ttarry[key] := Nil;
- icon^.do_ToolTypes := ^ttarry;
- { Informationen auf neuesten Stand bringen: }
- getpalette; colors := ''; FOR j := 0 TO 7 DO
- colors := colors + hexstr(palette[j],3)+',';
- IF I2CBase<>Nil THEN
- busdelay := SetI2CDelay(I2CDELAY_READONLY);
- { Ausgabetexte erzeugen: }
- FOR key := fil TO flg DO BEGIN
- s1 := keys[key]+'=';
- CASE key OF
- fil: s1 := s1 + outputname;
- flm: BEGIN
- IF asciifile THEN s1 := s1 + keys[asc] + '|'
- ELSE s1 := s1 + keys[vtx] + '|';
- IF overwrite THEN s1 := s1 + keys[ovw] + '|'
- ELSE s1 := s1 + keys[apd] + '|';
- IF withicon THEN s1 := s1 + keys[ics] + '|'
- ELSE s1 := s1 + keys[nic] + '|';
- IF numbering THEN s1 := s1 + keys[num]
- ELSE s1 := s1 + keys[nnm];
- END;
- icp: s1 := s1 + iconpath;
- edi: s1 := s1 + editor;
- cfp: s1 := s1 + configpath;
- pal: s1 := s1 + colors;
- mxw: s1 := s1 + IntStr(maxwait);
- bdl: s1 := s1 + IntStr(busdelay);
- bst: s1 := s1 + IntStr(burst);
- shu: s1 := s1 + IntStr(shuffle);
- flg: BEGIN
- IF fifo THEN s1 := s1 + keys[fif]
- ELSE s1 := s1 + keys[lif];
- IF testing THEN s1 := s1 + '|' + keys[clk];
- END;
- OTHERWISE;
- END;
- ttypes[key] := s1;
- ttarry[key] := ttypes[key];
- END;
- write_to_icon := PutDiskObject(myname,icon);
- FreeDiskObject(icon);
- END;
- olddir := CurrentDir(olddir);
- END;
-
- PROCEDURE paraminfo;
- { kurze Info für CLI-Benutzer }
- BEGIN
- WriteLn('legal parameters:');
- WriteLn(myname,' <page> <page> ... <file> <file> ...');
- WriteLn(' -f=<outputfile> -i=<iconpath> -c=<configpath> -e=<editcommand>');
- Write(' -d<delaycount> -w<seconds> -b<frames> -s<frames> -p<rgb>,<rgb>,...');
- { Irgendwer erzeugt mir nach Halt() noch zwei extra LF's ... }
- END;
-
- PROCEDURE get_args;
- { wertet CLI- oder WorkBench-Argumente aus }
- VAR len,i,j,k,ok,gelesen: Integer;
- name: str80;
- is_job: Boolean;
- olddir: BPTR;
- BEGIN
- gelesen := 0;
- busdelay := -1;
- colors := '';
- read_from_icon;
- IF fromWB THEN BEGIN { *** Workbench-Start }
- hail := StartupMessage;
- arg := hail^.sm_ArgList;
- FOR i := 1 to hail^.sm_NumArgs DO BEGIN
- IF i>1 THEN BEGIN { zusätzliche Dateien: enthaltene Seiten einlesen }
- olddir := CurrentDir(arg^.wa_Lock);
- name := arg^.wa_Name;
- IF filetype(name)=1 THEN
- gelesen := gelesen + getpages(name,True);
- END;
- { auf nächsten WBArg-Zeiger zugreifen: }
- arg := Ptr(Long(arg)+SizeOf(WBArg));
- END;
- END ELSE IF ParameterLen>0 THEN BEGIN { *** CLI-Start }
- s := ParameterStr; len := ParameterLen;
- { Parameterzeile in Worte zerlegen, wie der argv[] in C es schon ist :-( }
- i := 1; WHILE i<=len DO BEGIN
- WHILE (s^[i]<=' ') AND (i<=len) DO Inc(i);
- j := i + 1;
- IF s^[i]='"' THEN BEGIN
- Inc(i); WHILE (s^[j]<>'"') AND (j<=len) DO Inc(j);
- END ELSE BEGIN
- WHILE (s^[j]>' ') AND (j<=len) DO Inc(j);
- END;
- { Zeiger i: 1. Zeichen des Wortes, j: 1. Trennzeichen dahinter }
- IF s^[i]='-' THEN BEGIN
- i := i+2;
- CASE s^[i-1] OF
- 'f': BEGIN
- IF s^[i] = '=' THEN Inc(i);
- IF j>i THEN outputname := Copy(s^,i,j-i);
- END;
- 'i': BEGIN
- IF s^[i] = '=' THEN Inc(i);
- IF j>i THEN iconpath := Copy(s^,i,j-i);
- END;
- 'e': BEGIN
- IF s^[i] = '=' THEN Inc(i);
- IF j>i THEN editor := Copy(s^,i,j-i);
- END;
- 'c': BEGIN
- IF s^[i] = '=' THEN Inc(i);
- IF j>i THEN configpath := Copy(s^,i,j-i);
- END;
- 'p': colors := Copy(s^,i,j-i);
- 'd': Val(copy(s^,i,j-i),busdelay,ok);
- 'w': Val(copy(s^,i,j-i),maxwait,ok);
- 'b': Val(copy(s^,i,j-i),burst,ok);
- 's': Val(copy(s^,i,j-i),shuffle,ok);
- '?': BEGIN paraminfo; Halt(5); END;
- OTHERWISE BEGIN
- WriteLn('illegal parameter: ',Copy(s^,i-2,j-i+2));
- END;
- END;
- END ELSE IF i<=len THEN BEGIN
- { Was nur aus '0123456789/*' besteht, ist eine Seitennummer, alles andere eine }
- { Eingabedatei. }
- is_job := True;
- FOR k := i TO j-1 DO
- IF NOT (s^[k] IN ['0'..'9','-','/','*','.','!']) THEN is_job := False;
- name := Copy(s^,i,j-i);
- IF is_job THEN
- add_job(name,True)
- ELSE IF filetype(name)=1 THEN
- gelesen := gelesen + getpages(name,True)
- ELSE
- WriteLn('no VT-pages found in file "',name,'"');
- END;
- i := j + 1;
- END;
- END;
- IF editor<>'' THEN
- IF editor[Length(editor)]<>' ' THEN editor := editor + ' ';
- IF iconpath<>'' THEN
- IF NOT (iconpath[Length(iconpath)] IN [':','/']) THEN
- iconpath := iconpath + '/';
- IF configpath<>'' THEN
- IF NOT (configpath[Length(configpath)] IN [':','/']) THEN
- configpath := configpath + '/';
- IF colors<>'' THEN
- FOR i := 0 TO 7 DO
- palette[i] := hexval(Copy(colors,4*i+1,3));
- IF (I2CBase<>Nil) AND (busdelay>=0) THEN
- IF SetI2CDelay(busdelay)<>busdelay THEN;
- homedir := CurrentDir(mypath); { "cd PROGDIR:" :-) }
- END;
-
- PROCEDURE retreat;
- BEGIN
- IF IconBase<>Nil THEN CloseLibrary(IconBase); IconBase := Nil;
- IF homedir<>0 THEN homedir := CurrentDir(homedir); homedir := 0;
- END;
-
- BEGIN { Initialisierung }
- testing := False;
- { ToolType-Schlüsselwörter über symbolische Konstanten zugänglich machen: }
- keys := keywords('FILE','FILEMODE','ICONPATH','EDITOR','CONFIGPATH',
- 'PALETTE','MAXWAIT','BUSDELAY','BURST','SHUFFLE','FLAGS',
- 'ASCII','VT','OVERWRITE','APPEND','ICONS','NOICONS',
- 'NUMBERS','NONUMBERS','FIFO','LIFO','CLOCK');
- homedir := 0;
- IconBase := OpenLibrary('icon.library',0); AddExitServer(retreat);
- { herausfinden, wie ich an mein Icon komme: }
- IF FromWB THEN BEGIN
- hail := StartupMessage; arg := hail^.sm_ArgList;
- myname := arg^.wa_Name;
- mypath := arg^.wa_Lock;
- END ELSE BEGIN
- pr := Ptr(FindTask(Nil)); mycli := Ptr(4*pr^.pr_CLI);
- s := Ptr(4*mycli^.cli_CommandName);
- myname := Copy(s^,2,Ord(s^[1]));
- mypath := pr^.pr_HomeDir;
- END;
- END.
-
-