home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Mecomp Multimedia 1
/
Mecomp-CD.iso
/
amiga
/
tools
/
cd
/
indexcd
/
bin
/
sources.lha
/
sources
/
E.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-03-06
|
18KB
|
855 lines
/* dcc HD1:IndexCD/Bin/E.c */
char *Titolo = "$VER: E v2.0 (06-03-1997) © by Claudio Buraglio";
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libraries/dosextens.h"
extern struct FileHandle *Open();
// (void) exit(code)
char destdir [80]; // Configuration data
char clha [80];
char ctext [80];
char cpic [80];
char cjpeg [80];
char cmod [80];
char clzx [80];
char cdms [80];
char destdms [80];
char NomeArc [80];
char path[255]; // II parametro della linea di comando
char opath[20];
char cli [255]; // Tutti i file di un'archivio
char exe [255]; // Linea da eseguire
char buff[255]; // Buffer di fgets
char final[255]; // Buffer di fgets
char *ConfigFile = "S:Aminet-Config";
char *Etemp = "T:E.temp";
char *Modtemp = "T:DelMod.temp";
char *LHAtemp = "T:LHA.temp";
char *EXtemp = "T:Delete.temp";
char *ChoiceTemp = "T:Choice.temp";
char *DesTemp = "T:DestDir.temp";
char *run = "Run >NIL: <NIL: ";
char *ptr;
strtoupper(char *p)
{
while (*p != 0)
{
if ((*p > 'a'-1) && (*p < 'z'+1))
*p = (*p & 0xdf);
p++;
}
}
main(int arglen, char **argptr)
{
DeletePreviousFiles();
LoadConfiguration();
strcpy(path, argptr[2]);
int i = 0; // Copia la sola path in opath
while (path[i] != ' ' && path[i] != '/') { opath[i] = path[i]; i++; }
opath[i] = 0;
ptr = strrchr(path, '/');
if (ptr != NULL)
{
ptr++;
strcpy(NomeArc, ptr);
}
strtoupper(path);
strtoupper(opath);
if (strstr(path,":AMINET/") != NULL)
strcpy(cli, path);
else
{
if((strstr(argptr[1],"A") != 0) ||
(strstr(argptr[1],"B") != 0) ||
(strstr(argptr[1],"C") != 0) ||
(strstr(argptr[1],"D") != 0) )
sprintf(cli, "SET%s:Aminet/%s", argptr[1], path);
else
sprintf(cli, "AMINET%s:Aminet/%s", argptr[1], path);
}
exit;
if (arglen < 3 || arglen > 4 )
{
printf("L'uso di E (Execute) e' : %s <disco> <path+file> [C]\n\n",argptr[0]);
printf(" <disco> is the number of Aminet with the file.\n");
printf("<path+file> is the path and the name of the file to match it.\n");
printf(" [C] is an optional switch to force the read of the comment.\n\n");
printf("Example: E 2 UTIL/CAL20.LHA Extract the file from the archive.\n");
printf(" E 2 UTIL/CAL20.LHA C Read the comment file of the archive.\n\n");
goto Esce;
}
if (arglen == 4)
{
if (*argptr[3] == 'C' || *argptr[3] == 'c')
{
ptr = strrchr(cli, '.');
*ptr++= '.';
*ptr++= 'R';
*ptr++= 'E';
*ptr++= 'A';
*ptr = 0x0;
if (access(cli, 0) == 0) { ShowText(); goto Esce;}
*ptr++= 'D';
*ptr++= 'M';
*ptr++= 'E';
*ptr = 0x0;
if (access(cli, 0) == 0) { ShowText(); goto Esce;}
ptr = strrchr(cli, '.');
*ptr++= '.';
*ptr++= 'R';
*ptr++= 'D';
*ptr++= 'M';
*ptr = 0x0;
if (access(cli, 0) == 0) { ShowText(); goto Esce;}
printf("Commento non trovato\n\n");
goto Esce;
}
else
{
printf("ERRORE! Il terzo argomento dev'essere lo switch C oppure c.\n\n");
goto Esce;
}
}
if (strstr(cli,".TXT") ||
strstr(cli,".DOC") ||
strstr(cli,".C" ) != NULL)
{
ShowText();
goto Esce;
}
if (strstr(opath,"MODS") ||
strstr(cli,".MOD") ||
strstr(cli,".MED") ||
strstr(cli,".S3M") != NULL)
{
PlayMods();
goto Esce;
}
if(strstr(opath,"PIX") ||
strstr(cli, ".JPEG") ||
strstr(cli, ".JPG") ||
strstr(cli, ".GIF") ||
strstr(cli, ".IFF") ||
strstr(cli, ".MPG") != NULL)
{
switch(RequesterPic())
{
case 1: // Visualizza i disegni
ShowPic();
goto Esce;
break;
case 2: // scompatta l'archivio in destdir
if(strstr(cli,".LHA") || strstr(cli,".LZH") != NULL)
{
sprintf(exe, "%s -x -m x %s %s",clha, cli, destdir);
system(exe);
goto Esce;
break;
}
else
{
sprintf(exe, "c:Copy %s %s", cli, destdir);
system(exe);
goto Esce;
break;
}
default: // Cancella
goto Esce;
break;
}
}
else
{
if(strstr(path,".LHA") ||
strstr(path,".LZH") ||
strstr(path,".LZX") != NULL)
{
switch(RequesterLHA())
{
case 2: // Change desstdir
sprintf(exe, "c:RequestFile >%s TITLE \"New Destination Dir...\" DRAWER %s", DesTemp, destdir);
system(exe);
FILE *fpr;
if (fpr = fopen(DesTemp, "r"))
{
fgets(buff, sizeof(buff)-1, fpr);
if ( strrchr(buff, '"') != NULL)
{
if((ptr = strrchr(buff, '/')) != 0) { *++ptr = 0; }
else { ptr = strrchr(buff, ':'); *++ptr = 0; }
ptr = buff; *ptr++;
strcpy(destdir, ptr);
fclose(fpr);
if (strstr(path,".LZX") == NULL)
sprintf(exe, "%s >NIL: -x -m x %s %s", clha, cli, destdir);
else
sprintf(exe, "%s >NIL: -a x %s %s", clzx, cli, destdir);
system(exe);
goto Esce;
break;
}
else
{
fclose(fpr);
remove(DesTemp);
goto Esce;
break;
}
remove(DesTemp);
}
case 1: // Scompatta Archivio in destdir
struct FileHandle *dos_fh; // Apre la window
dos_fh = Open("CON:100/100/440/74/IndexCD", MODE_NEWFILE);
sprintf(final, "\n\tDearchive: %s\n"
"\n\tto: %s", NomeArc, destdir);
Write(dos_fh, final, strlen(final));
if (strstr(path,".LZX") == NULL)
sprintf(exe, "%s >NIL: -x -m x %s %s", clha, cli, destdir);
else
sprintf(exe, "%s >NIL: -a x %s %s", clzx, cli, destdir);
system(exe);
sleep(1);
Close(dos_fh); // Chiude la window
goto Esce;
break;
default: // Cancella
goto Esce;
break;
}
}
if (strstr(path,".DMS") != NULL)
{
if (RequesterDMS() == 1)
{
sprintf(exe, "%s WRITE %s TO %s",cdms, cli, destdms);
system(exe);
}
}
}
Esce:
return(0);
}
RequesterPic()
{
int r = 1;
/*
sprintf(exe, "c:RequestChoice >%s IndexCD \"Dearchive ''%s'' to ''%s'' ?\" Show Dearchive Abort",ChoiceTemp, NomeArc, destdir);
system(exe);
FILE *fpr;
if (fpr = fopen("T:Choice.temp", "r"))
{
fgets(buff, sizeof(buff)-1, fpr);
if ( strchr(buff, '1') != NULL)
{
r = 1;
}
if ( strchr(buff, '2') != NULL)
{
r = 2;
}
fclose(fpr);
}
remove("T:Choice.temp");
*/
return(r);
}
RequesterLHA()
{
int r = 0;
sprintf(exe, "c:RequestChoice >%s IndexCD \"Dearchive ''%s'' to ''%s'' ?\" Dearchive NewDestination Abort", ChoiceTemp, NomeArc, destdir);
system(exe);
FILE *fpr;
if (fpr = fopen("T:Choice.temp", "r"))
{
fgets(buff, sizeof(buff)-1, fpr);
if ( strchr(buff, '1') != NULL)
{
r = 1;
}
if ( strchr(buff, '2') != NULL)
{
r = 2;
}
fclose(fpr);
}
remove("T:Choice.temp");
return(r);
}
RequesterDMS()
{
int r = 0;
sprintf(exe,"c:RequestChoice >%s IndexCD \"Write the archive ''%s'' to ''%s'' ?\" Yes No", ChoiceTemp, NomeArc, destdms);
system(exe); // Visualizza requester
FILE *fpr;
if (fpr = fopen("T:Choice.temp", "r"))
{
fgets(buff, sizeof(buff)-1, fpr);
if ( strchr(buff, '1') != NULL)
{
r = 1;
}
fclose(fpr);
}
remove("T:Choice.temp");
return(r);
}
ShowPic()
{
struct FileHandle *dos_fh; // Apre la window
dos_fh = Open("CON:100/100/440/174/IndexCD", MODE_NEWFILE);
sprintf(final, "\n Showing...\n\n ");
Write(dos_fh, final, strlen(final));
FILE *fpr;
if(strstr(path,".LHA") || strstr(path,".LZH") != NULL)
{
sprintf(exe, "%s >%s vq %s", clha, LHAtemp, cli);
system(exe);
LHAtempToDeleteList();
sprintf(exe,"%s >NIL: -x -m x %s %s",clha, cli, destdir);
system(exe);
}
else
{
sprintf(final, "%s\n ", cli);
Write(dos_fh, final, strlen(final));
sprintf(exe, "%s \"%s\"",cpic, cli);
system(exe);
goto Esce;
}
if (fpr = fopen(LHAtemp, "r"))
{
while (fgets(buff, sizeof(buff)-1, fpr))
{
int poin;
int i = 0;
do
{
poin = toupper(buff[i]);
buff[i] = poin;
i++;
}
while (buff[i] != 0);
i = 0;
while(buff[i++] != 0)
{
if (buff[i] == 0x0a)
{
buff[i] = '"';
}
}
if (
((ptr = strstr(buff, "LHA EVALUATION ")) == NULL) &&
((ptr = strstr(buff, "ALL RIGHTS ")) == NULL) &&
((ptr = strstr(buff, "UNABLE TO OPEN ARCHIVE")) == NULL) &&
((ptr = strstr(buff, "OPERATION FAILED")) == NULL) &&
((ptr = strstr(buff, "README")) == NULL) &&
((ptr = strstr(buff, ".REA")) == NULL) &&
((ptr = strstr(buff, ".INFO")) == NULL) &&
((ptr = strstr(buff, ".DIZ")) == NULL) &&
((ptr = strstr(buff, ".TXT")) == NULL) &&
((ptr = strstr(buff, ".TEXT")) == NULL) &&
((ptr = strstr(buff, ".GUIDE")) == NULL) &&
(buff[0] != 0x0A) )
{
sprintf(final, "\"%s\n ", buff);
Write(dos_fh, final, strlen(final));
sprintf(exe, "%s \"%s%s", cpic, destdir, buff);
system(exe);
}
}
/*
FILE *fpw;
if (fpw = fopen(EXtemp, "a"))
{
if ( (strlen(cpic)+4) <= (strlen(cli)) )
fputs(cli, fpw);
fclose(fpw);
}
*/
fclose(fpr);
}
sprintf(exe, "Execute >NIL: %s", EXtemp);
system(exe);
DeletePreviousFiles();
Esce:
sprintf(final, "\n Done.", cli);
Write(dos_fh, final, strlen(final));
// sleep(2);
Close(dos_fh); // Chiude la window
}
PlayMods()
{
int NrMods = 0;
FILE *fp;
unsigned char *add[255];
DeletePreviousMods();
if ((strstr(cmod, "HIP")) != NULL)
{
int r = system("sys:Rexxc/RX >NIL: ICD:ARexx/HiP_stop.rexx");
if (r > 9) { system(cmod); }
system("sys:Rexxc/RX ICD:ARexx/HiP_clear.rexx");
strcpy(add, "sys:Rexxc/RX ICD:ARexx/HiP_add1.rexx ");
goto OK1;
}
if ((strstr(cmod, "SOUNDSTUDIO")) != NULL)
{
int r = system("sys:Rexxc/RX >NIL: ICD:ARexx/SS_Clear.rexx");
if (r > 9) { system(cmod); }
strcpy(add, "sys:Rexxc/RX ICD:ARexx/SS_Load.rexx ");
goto OK1;
}
if ((strstr(cmod, "DELITRACKER")) != NULL)
{
int r = system("sys:Rexxc/RX >NIL: ICD:ARexx/dt_clearlist2.rexx");
if (r > 9)
{
unsigned char *com[255]; // Directory of the command in the string 'com'
strcpy(com, cmod);
char *ptr = strrchr(com, '/');
*ptr++; *ptr=0;
chdir(com);
sprintf(exe, "c:RUN >NIL <NIL: %s", cmod,);
system(exe);
sleep(4);
system("sys:Rexxc/RX ICD:ARexx/dt_appendon.rexx");
}
strcpy(add, "sys:Rexxc/RX ICD:ARexx/dt_makelist.rexx ");
system(exe);
goto OK1;
}
if ((strstr(cmod, "PLAYER")) != NULL)
{
system("sys:Rexxc/RX >NIL: ICD:ARexx/MultiPlay_Quit.rexx");
sprintf(add, "%s DIR=%s PLAY", cmod, destdir);
}
OK1:
if(strstr(cli, ".MOD") != NULL)
{
// Copia il .mod in T:
char *ptr = strrchr(cli, '/');
ptr++;
sprintf(exe, "c:copy \"%s\" T:",cli);
strcat(exe, ptr);
system(exe);
// Suona il modulo dalla dir T:
if ((strstr(cmod, "HIP")) != NULL)
{
sprintf(exe,"%s T:%s", add, ptr);
system(exe);
system("sys:Rexxc/RX ICD:ARexx/HiP_play2.rexx");
goto OK2;
}
if ((strstr(cmod, "SOUNDSTUDIO")) != NULL)
{
// sprintf(exe,"%s T:%s", add, ptr);
// system(exe);
// system("sys:Rexxc/RX ICD:ARexx/HiP_play2.rexx");
// goto OK2;
}
if ((strstr(cmod, "DELITRACKER")) != NULL)
{
sprintf(exe,"%s T:%s", add, ptr);
system(exe);
system("sys:Rexxc/RX ICD:ARexx/dt_playlist.rexx 1");
goto OK2;
}
if ((strstr(cmod, "PLAYER")) != NULL)
{
sprintf(exe,"%s PLAY \"T:%s\"", cmod, ptr);
system(exe);
}
OK2:
// Cancella il modulo dalla dir T:
sleep(1);
sprintf(exe,"T:%s", ptr);
remove(exe);
goto Esce;
}
sprintf(exe, "%s >%s vq %s",clha, LHAtemp, cli);
system(exe);
LHAtempToDeleteList();
sprintf(exe, "%s >NIL: -x -m x %s %s",clha, cli, destdir);
system(exe);
if (fp = fopen(LHAtemp, "r"))
{
while (fgets(buff, sizeof(buff)-1, fp))
{
int poin;
int i = 0;
do
{
poin = toupper(buff[i]);
buff[i] = poin;
i++;
}
while (buff[i] != 0);
i = 0;
while(buff[i++] != 0)
{
if (buff[i] == 0x0a)
{
buff[i] = 0;
}
}
if (
((ptr = strstr(buff, "LHA EVALUATION ")) == NULL) &&
((ptr = strstr(buff, "UNABLE TO OPEN ARCHIVE")) == NULL) &&
((ptr = strstr(buff, "OPERATION FAILED")) == NULL) &&
((ptr = strstr(buff, "SA7ISFAC7ION")) == NULL) &&
((ptr = strstr(buff, "ALL RIGHTS ")) == NULL) &&
((ptr = strstr(buff, "DISPLAYME")) == NULL) &&
((ptr = strstr(buff, "README")) == NULL) &&
((ptr = strstr(buff, ".GUIDE")) == NULL) &&
((ptr = strstr(buff, ".INSTR")) == NULL) &&
((ptr = strstr(buff, ".REA")) == NULL) &&
((ptr = strstr(buff, ".INFO")) == NULL) &&
((ptr = strstr(buff, ".ASCII")) == NULL) &&
((ptr = strstr(buff, ".DIZ")) == NULL) &&
((ptr = strstr(buff, ".TXT")) == NULL) &&
((ptr = strstr(buff, ".TEXT")) == NULL) &&
((ptr = strstr(buff, ".JPG")) == NULL) &&
((ptr = strstr(buff, ".NFO")) == NULL) &&
((ptr = strstr(buff, ".DOC")) == NULL) &&
((ptr = strstr(buff, ".EXE")) == NULL) &&
((ptr = strstr(buff, ".REL")) == NULL) &&
((ptr = strstr(buff, ".SS")) == NULL) &&
((ptr = strstr(buff, ".PP")) == NULL) &&
(buff[0] != 0x0A) )
{
if ((strstr(cmod, "HIP")) != NULL)
{
sprintf(exe,"%s%s%s", add, destdir, buff);
system(exe);
goto OK3;
}
if ((strstr(cmod, "SOUNDSTUDIO")) != NULL)
{
if (NrMods == 0)
{
sprintf(exe,"%s\"%s%s\"", add, destdir, buff);
system(exe);
}
else
{
sprintf(exe,"sys:Rexxc/RX ICD:ARexx/SS_Append.rexx \"%s%s\"", destdir, buff);
system(exe);
}
sprintf(exe,"c:delete \"%s%s\"", destdir, buff);
system(exe);
NrMods++;
goto OK3;
}
if ((strstr(cmod, "DELITRACKER")) != NULL)
{
sprintf(exe,"%s%s%s", add, destdir, buff);
system(exe);
goto OK3;
}
if ((strstr(cmod, "PLAYER")) != NULL)
{
strcat(add, " \"");
strcat(add, destdir);
strcat(add, buff);
strcat(add, "\"");
}
OK3:
}
}
fclose(fp);
}
if ((ptr = strstr(cmod, "HIP")) != NULL)
{ system("sys:Rexxc/RX ICD:ARexx/HiP_play2.rexx");
goto Esce;
}
if ((ptr = strstr(cmod, "SOUNDSTUDIO")) != NULL)
{ system("sys:Rexxc/RX ICD:ARexx/SS_Play.rexx");
DeletePreviousFiles();
goto Esce;
}
if ((ptr = strstr(cmod, "DELITRACKER")) != NULL)
{ system("sys:Rexxc/RX ICD:ARexx/dt_playlist.rexx 1");
goto Esce;
}
if ((ptr = strstr(cmod, "PLAYER")) != NULL)
{ system(add);}
Esce:
sprintf(exe,"c:Rename >NIL: %s %s", Etemp, Modtemp);
system(exe);
}
ShowText()
{
sprintf(exe, "%s %s",ctext, cli);
system(exe);
}
DeletePreviousFiles()
{
if (access(Etemp,0) == NULL)
{
sprintf(exe, "Execute %s", Etemp);
system(exe);
sprintf(exe, "Delete >NIL: %s", Etemp);
system(exe);
}
remove(EXtemp);
remove(LHAtemp);
}
DeletePreviousMods()
{
if (access(Modtemp,0) == NULL)
{
sprintf(exe, "Execute %s", Modtemp);
system(exe);
sprintf(exe, "Delete >NIL: %s", Modtemp);
system(exe);
}
remove(EXtemp);
remove(LHAtemp);
}
LoadConfiguration()
{
FILE *fp;
char *coda;
strcpy(destdir, "RAM:");
strcpy( clha, "CD0:Tools/LHA");
strcpy( ctext, "CD0:Tools/Guide");
strcpy( cjpeg, "CD0:Tools/FJPEG_ECS");
strcpy( cpic, "CD0:Tools/VT");
strcpy( cmod, "CD0:Tools/DeliTracker2");
strcpy( clzx, "C:LZX");
strcpy( cdms, "CD0:Tools/DMS");
strcpy(destdms, "DF0:");
if (fp = fopen(ConfigFile, "r"))
{
while (fgets(buff, sizeof(buff)-1, fp))
{
if ((ptr = strstr(buff, "destdir=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(destdir, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "lha=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(clha, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "lzx=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(clzx, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "text=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(ctext, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "jpeg=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(cjpeg, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "pic=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(cpic, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "mod=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(cmod, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, " dms=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(cdms, ptr);
*--coda = 0;
}
if ((ptr = strstr(buff, "destdms=")) != NULL)
{
ptr = strchr(buff, '=');
ptr++;
coda = stpcpy(destdms, ptr);
*--coda = 0;
}
}
fclose(fp);
}
strtoupper(cmod); // cmod in Uppercase
}
LHAtempToDeleteList()
{
char line[255];
char oldline[255];
FILE *fpr;
FILE *fpw;
char *ptr;
if (fpr = fopen(LHAtemp, "r"))
{
if (fpw = fopen(Etemp, "w"))
{
fgets(buff, sizeof(buff)-1, fpr);
fgets(buff, sizeof(buff)-1, fpr);
fgets(buff, sizeof(buff)-1, fpr);
while (fgets(buff, sizeof(buff)-1, fpr))
{
char *ptr = strchr(buff, '\n');
if (*ptr == '\n')
*ptr = 0;
sprintf(line, "Delete >NIL: \"%s%s\"\n", destdir, buff);
fputs(line, fpw);
}
}
fclose(fpr);
// Lista di delete per tutte le directory create dall'archivio
if (fpr = fopen(LHAtemp, "r"))
{
fgets(buff, sizeof(buff)-1, fpr);
fgets(buff, sizeof(buff)-1, fpr);
fgets(buff, sizeof(buff)-1, fpr);
while (fgets(buff, sizeof(buff), fpr))
{
ptr = strrchr(buff, '/');
if (ptr != 0)
{
*ptr = 0;
if (stricmp(oldline, buff) != 0)
{
strcpy(oldline, buff);
sprintf(line, "Delete >NIL: \"%s%s\" ALL\n", destdir, buff);
fputs(line, fpw);
}
}
}
}
fclose(fpr);
fclose(fpw);
}
return(0);
}