home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ST-Computer Leser 1998 October
/
STC_CD_10_1998.iso
/
ONLINE
/
DFUE
/
DOTP118U
/
PLUGIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-26
|
12KB
|
450 lines
#include <stdio.h>
#include <stdlib.h>
#include <standard.h>
#include <string.h>
#include <tos.h>
#include <aes.h>
#include <ext.h>
#include "plugin.h"
#include "plugidef.h"
typedef struct
{
unsigned d_hour: 5;
unsigned d_min: 6;
unsigned d_tsec: 5;
} DT;
typedef struct
{
unsigned d_year: 7;
unsigned d_month: 4;
unsigned d_day: 5;
}DD;
typedef union
{
unsigned int i;
DT dt;
}DTIME;
typedef union
{
unsigned int i;
DD dd;
}DDATE;
char vstr[20]="PlugIn 1.1.8 ╜ PN";
typedef struct{
char length;
char arg[255];
} MYCOMMAND;
long err,size,p;
DTIME zeit;
DDATE dat;
MYCOMMAND cmdline;
int cf,x,y,w,h;
char *buf,*s,*d,*e;
char cmdfile[128],cmd[128],path[128],name[10],logfile[128],tname[10];
char kstr[66],pstr1[66],pstr2[66],estr[40];
int draw_info=0,wait_key=0,on_screen=0,dobreak=1,do_log=0;
char buffer[32*1024L];
long CopyFile(char *p1, char *p2)
BEGIN
int f1,f2;
long anz;
f1=(int)Fopen(p1,0);
IF f1<0 THEN return(f1); END
f2=(int)Fcreate(p2,0);
IF f2<0 THEN
Fclose(f1);
return(f2);
END
REPEAT
anz=Fread(f1,32*1024L,buffer);
Fwrite(f2,anz,buffer);
UNTIL(anz==0);
Fclose(f1); Fclose(f2);
return(0);
END
long AppendFile(char *p1, char *p2)
BEGIN
int f1,f2,exist,i;
long anz;
struct ffblk dta;
char sfile[128],*h;
f2=(int)Fopen(p2,FO_WRITE);
IF f2<0 THEN f2=(int)Fcreate(p2,0); END
IF f2<0 THEN return(f2); END
strcpy(sfile,p1);
IF sfile[1]==':' THEN i=2; ELSE i=0; END
IF (h=strrchr(sfile,'\\'))!=0 THEN ++h; ELSE h=&sfile[i]; END
Fseek(0,f2,2);
exist=findfirst(p1,&dta,0);
WHILE exist==0 DO
*h=0;
strcat(sfile,dta.ff_name);
f1=(int)Fopen(sfile,0);
REPEAT
anz=Fread(f1,32*1024L,buffer);
Fwrite(f2,anz,buffer);
UNTIL(anz==0);
Fclose(f1);
exist=findnext(&dta);
END
Fclose(f2);
return(0);
END
long DelFile(char *p1)
BEGIN
int exist,i;
struct ffblk dta;
char sfile[128],*h;
long err;
strcpy(sfile,p1);
IF sfile[1]==':' THEN i=2; ELSE i=0; END
IF (h=strrchr(sfile,'\\'))!=0 THEN ++h; ELSE h=&sfile[i]; END
exist=findfirst(p1,&dta,0);
WHILE exist==0 DO
*h=0;
strcat(sfile,dta.ff_name);
err=Fdelete(sfile);
IF err!=0 THEN return(err); END
exist=findnext(&dta);
END
return(0);
END
char *strdel(char *s,long p,long n)
BEGIN
long l;
l=strlen(s);
if(p>=l) return(s);
IF (p+n)>=l THEN
s[p]='\0'; return(s);
END
memcpy(s+p,s+p+n,l-p+n);
return(s);
END
char *strins(char *in,char *s,long p)
BEGIN
long lin,ls;
ls=strlen(s);
if(ls==0) return(strcpy(s,in));
if(p>=ls) return(strcat(s,in));
lin=strlen(in);
if(lin==0) return(s);
memcpy(s+p+lin,s+p,ls-p+1);
return(strncpy(s+p,in,lin));
END
void PathDecode(char epath[])
BEGIN
int i;
char *h;
static char p[128];
strcpy(p,epath);
IF p[1]==':' THEN i=2; ELSE i=0; END
IF (h=strrchr(p,'\\'))!=0 THEN ++h; *h=0; ELSE p[i]=0; END
strcpy(path,p);
i=(int)strlen(p);
strcpy(p,epath);
h=strtok(&p[i],".");
name[0]=0;
IF h THEN strcpy(name,h); END
END
void ShowCommand(void)
BEGIN
IF draw_info THEN
strncpy(kstr,cmd,65);
strncpy(pstr1,cmdline.arg,65);
IF cmdline.length>65 THEN
strncpy(pstr2,&cmdline.arg[65],65);
ELSE
pstr2[0]=0;
END
estr[0]=0;
objc_draw(rs_trees[0],0,8,x,y,w,h);
END
IF do_log THEN
Cconws("Kommando: ");
Cconws(cmd); Cconout(' '); Cconws(cmdline.arg);
Cconout(13); Cconout(10);
END
END
long main(int argc, char *argv[])
BEGIN
int get_arg,lf=0,ifcnt=0,ignore=0;
IF argc<2 THEN return(-1); END
appl_init();
_init_rsc();
IF argv[argc-1][strlen(argv[argc-1])-1]=='\\' THEN
get_arg=argc-2; /* ZIP-Aufruf beim Auspacken */
ELSE
get_arg=argc-1; /* alle sonstigen Fälle */
END
PathDecode(argv[get_arg]);
strcpy(cmdfile,path);
strcat(cmdfile,name);
cmdfile[strlen(cmdfile)-4]=0; /* Abschneiden auf IN bzw. OUT */
strcpy(logfile,cmdfile);
strcat(cmdfile,".CMD");
strcat(logfile,"_LOG.TXT");
cf=(int)Fopen(cmdfile,0);
IF cf<0 THEN /* Alternativ COMMAND.IN (OUT) */
strcpy(cmdfile,path);
strcat(cmdfile,"COMMAND.");
strcat(cmdfile,name);
cmdfile[strlen(cmdfile)-4]=0; /* Abschneiden auf IN bzw. OUT */
cf=(int)Fopen(cmdfile,0);
IF cf<0 THEN return(-2); END
END
size=Fseek(0,cf,2);
Fseek(0,cf,0);
buf=Malloc(size+1);
memset(buf,0,size+1);
Fread(cf,size,buf);
Fclose(cf);
s=buf;
form_center(rs_trees[0],&x,&y,&w,&h);
rs_trees[0][0].ob_y -= y-23;
y=23;
REPEAT
s=strchr(s,13);
IF s THEN *s=' '; END;
UNTIL(!s);
s=buf;
WHILE (d=strtok(s,"\n"))!=0 DO
s=0;
strcpy(cmd,d);
e=strchr(cmd,';');
IF e THEN *e=0; END
WHILE *cmd==' ' DO strdel(cmd,0,1); END
e=strchr(cmd,' ');
IF e THEN
*e=0; ++e;
strcpy(cmdline.arg,e);
e=cmdline.arg;
REPEAT
p=strcspn(e,"%");
IF e[p]=='%' THEN
int ind;
strdel(e,p,1);
CASE e[p] OF
WHEN '%' : e+=p+1;
p=0;
break;
WHEN 'n' :
WHEN 'N' : strdel(e,p,1);
strins(name,e,p);
e+=p+strlen(name);
p=0;
break;
WHEN 't' :
WHEN 'T' : strdel(e,p,1);
zeit.i=Tgettime();
dat.i =Tgetdate();
tname[0]=(dat.dd.d_month / 10) + '0';
tname[1]=(dat.dd.d_month % 10) + '0';
tname[2]=(dat.dd.d_day / 10) + '0';
tname[3]=(dat.dd.d_day % 10) + '0';
tname[4]=(zeit.dt.d_hour / 10) + '0';
tname[5]=(zeit.dt.d_hour % 10) + '0';
tname[6]=(zeit.dt.d_min / 10) + '0';
tname[7]=(zeit.dt.d_min % 10) + '0';
tname[8]=0;
strins(tname,e,p);
e+=p+8;
p=0;
break;
WHEN 'p' :
WHEN 'P' : strdel(e,p,1);
strins(path,e,p);
e+=p+strlen(path);
p=0;
break;
WHEN '0' :
WHEN '1' :
WHEN '2' :
WHEN '3' :
WHEN '4' :
WHEN '5' :
WHEN '6' :
WHEN '7' :
WHEN '8' :
WHEN '9' : ind=e[p]-'0';
IF ind<argc THEN
strdel(e,p,1);
strins(argv[ind],e,p);
e+=p+strlen(argv[ind]);
ELSE
e[p]=' ';
e+=p+1;
END
p=0;
break;
END
END
UNTIL(e[p]==0);
cmdline.length=strlen(cmdline.arg);
IF cmdline.length>124 THEN /* GEMDOS-Beschränkung */
cmdline.length=124;
cmdline.arg[124]=0;
END
ELSE
*cmdline.arg=0;
cmdline.length=0;
END
IF *cmd!=0 THEN
IF stricmp("#if",cmd)==0 THEN
ifcnt++;
IF !ignore THEN
ShowCommand();
IF err!=atol(cmdline.arg) THEN ignore=ifcnt; END
END
ELSIF stricmp("#else",cmd)==0 THEN
IF ignore==0 THEN
ShowCommand();
ignore=ifcnt;
ELSIF ignore==ifcnt THEN
ignore=0;
END
ELSIF stricmp("#elsif",cmd)==0 THEN
IF ignore==0 THEN
ignore=ifcnt;
ELSIF ignore==ifcnt THEN
ShowCommand();
IF err==atol(cmdline.arg) THEN ignore=0; END
END
ELSIF stricmp("#endif",cmd)==0 THEN
IF ignore==ifcnt THEN ignore=0; ShowCommand(); END
ifcnt--;
ELSIF !ignore THEN
err=0;
ShowCommand();
IF stricmp("#ren",cmd)==0 THEN
char *p1,*p2;
p1=cmdline.arg;
p2=strchr(cmdline.arg,' ');
*p2=0; p2++;
WHILE *p2==' ' DO strdel(p2,0,1); END
err=Frename(0,p1,p2);
ELSIF stricmp("#del",cmd)==0 THEN
err=DelFile(cmdline.arg);
ELSIF stricmp("#log",cmd)==0 THEN
do_log=(cmdline.arg[0]=='+');
IF lf<=0 THEN
Fdelete(logfile);
lf=(int)Fcreate(logfile,0);
IF lf<0 THEN
do_log=FALSE;
ELSE
Fforce(1,lf);
END
END
IF do_log THEN
Cconws("Kommando: ");
Cconws(cmd); Cconout(' '); Cconws(cmdline.arg);
Cconout(13); Cconout(10);
END
ELSIF stricmp("#info",cmd)==0 THEN
draw_info=(cmdline.arg[0]=='+');
IF draw_info && (!on_screen) THEN
form_dial(FMD_START,x,y,w,h,x,y,w,h);
objc_draw(rs_trees[0],0,8,x,y,w,h);
on_screen=TRUE;
END
ELSIF stricmp("#wait",cmd)==0 THEN
wait_key=(cmdline.arg[0]=='+');
ELSIF stricmp("#exit",cmd)==0 THEN
err=atol(cmdline.arg);
IF draw_info THEN form_dial(FMD_FINISH,x,y,w,h,x,y,w,h); END
IF do_log THEN Fclose(lf); END
appl_exit();
return(err);
ELSIF stricmp("#break",cmd)==0 THEN
dobreak=(cmdline.arg[0]=='+');
ELSIF stricmp("#alert",cmd)==0 THEN
err=form_alert(1,cmdline.arg)-1;
ELSIF (stricmp("#cd",cmd)==0) && (cmdline.length>1) THEN
char *hp;
strupr(cmdline.arg);
IF cmdline.arg[1]==':' THEN
Dsetdrv(cmdline.arg[0]-'A');
END
hp=strchr(cmdline.arg,' ');
IF hp THEN *hp=0; END
err=Dsetpath(cmdline.arg);
IF do_log THEN
char ap[128];
Cconws(" Gesetzt: ");
Cconout(Dgetdrv()+'A'); Cconout(':');
Dgetpath(ap,0);
Cconws(ap);
END
ELSIF stricmp("#copy",cmd)==0 THEN
char *p1,*p2;
p1=cmdline.arg;
p2=strchr(cmdline.arg,' ');
*p2=0; p2++;
WHILE *p2==' ' DO strdel(p2,0,1); END
err=CopyFile(p1,p2);
ELSIF stricmp("#append",cmd)==0 THEN
char *p1,*p2;
p1=cmdline.arg;
p2=strchr(cmdline.arg,' ');
*p2=0; p2++;
WHILE *p2==' ' DO strdel(p2,0,1); END
err=AppendFile(p1,p2);
ELSE
err=Pexec(0,cmd,(COMMAND *)&cmdline,"");
END
ltoa(err,estr,10);
IF draw_info THEN
objc_draw(rs_trees[0],MAERG,1,x,y,w,h);
END
IF do_log THEN
Cconout(13); Cconout(10);
Cconws(" --> "); Cconws(estr);
Cconout(13); Cconout(10);
Cconout(13); Cconout(10);
END
IF wait_key && draw_info THEN
form_alert(1,"[1][PlugIn:|Bitte RETURN drücken.][ Weiter ]");
END
IF err && dobreak THEN
IF draw_info THEN form_dial(FMD_FINISH,x,y,w,h,x,y,w,h); END
IF do_log THEN Fclose(lf); END
appl_exit();
return(err);
END
END
END
END
IF draw_info THEN form_dial(FMD_FINISH,x,y,w,h,x,y,w,h); END
IF do_log THEN Fclose(lf); END
appl_exit();
Mfree(buf);
return(0);
END