home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
247.lha
/
pd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-21
|
17KB
|
994 lines
#include "stdio.h"
#include "functions.h"
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/libraries.h"
#include "exec/ports.h"
#include "exec/interrupts.h"
#include "exec/io.h"
#include "exec/memory.h"
#include "exec/types.h"
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "libraries/dos.h"
#include "libraries/dosextens.h"
#include "graphics/GfxBase.h"
long _stack = 8000;
long _priority = 0;
long _BackGroundIO = 0;
char *_procname = "Greetings_from_C&P";
#undef BADDR
#define BADDR(x) ((APTR)((LONG)x << 2))
struct DosList {
BPTR dol_Next; /* bptr to next device list */
LONG dol_Type; /* see DLT below */
struct MsgPort *dol_Task; /* ptr to handler task */
BPTR dol_Lock;
union {
struct {
BSTR *dol_Handler;
LONG dol_StackSize;
LONG dol_Priority;
ULONG dol_Startup;
BPTR dol_SegList;
BPTR dol_GlobVec;
} dol_handler;
struct {
struct DateStamp dol_VolumeDate; /* creation date */
BPTR dol_LockList; /* outstanding locks */
LONG dol_DiskType; /* 'DOS', etc */
} dol_volume;
} dol_misc;
BSTR *dol_Name; /* bptr to bcpl name */
};
struct FileSysStartupMsg {
ULONG fssm_Unit; /* exec unit number for this device */
BSTR fssm_Device; /* null terminated bstring to the device name */
BPTR fssm_Environ; /* ptr to environment table (see above) */
ULONG fssm_Flags; /* flags for OpenDevice() */
};
extern struct Library *DOSBase;
struct FileLock *lock, *Lock(); /* Used for legal check */
FILE *rf, *wf;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Window *Wdw;
short mx,my, endit = 0;
int ret;
char buffer[80], *dr[8];
UBYTE *tit = (UBYTE *)"PD LIST MAKER ©1988 by C&P Software";
SHORT BorderVectors1[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border1 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors1,
NULL
};
struct IntuiText IText1 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget10 = {
NULL,
265,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText1,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors2[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border2 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors2,
NULL
};
struct IntuiText IText2 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget9 = {
&Gadget10,
223,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border2,
NULL,
&IText2,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors3[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border3 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors3,
NULL
};
struct IntuiText IText3 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget8 = {
&Gadget9,
181,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border3,
NULL,
&IText3,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors4[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border4 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors4,
NULL
};
struct IntuiText IText4 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget7 = {
&Gadget8,
139,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border4,
NULL,
&IText4,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors5[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border5 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors5,
NULL
};
struct IntuiText IText5 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget6 = {
&Gadget7,
97,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border5,
NULL,
&IText5,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors6[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border6 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors6,
NULL
};
struct IntuiText IText6 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget5 = {
&Gadget6,
55,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border6,
NULL,
&IText6,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors7[] = {
0,0,
37,0,
37,10,
0,10,
0,0
};
struct Border Border7 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors7,
NULL
};
struct IntuiText IText7 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"SORT",
NULL
};
struct Gadget Gadget4 = {
&Gadget5,
349,14,
36,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border7,
NULL,
&IText7,
NULL,
NULL,
NULL,
NULL
};
SHORT BorderVectors8[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border8 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors8,
NULL
};
struct IntuiText IText8 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget3 = {
&Gadget4,
13,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border8,
NULL,
&IText8,
NULL,
NULL,
NULL,
NULL
};
UBYTE Gadget2SIBuff[100] = "RAM:PD.LIST";
struct StringInfo Gadget2SInfo = {
Gadget2SIBuff,
NULL,
0,
100,
0,
0,0,0,0,0,
0,
0,
NULL
};
SHORT BorderVectors9[] = {
0,0,
371,0,
371,9,
0,9,
0,0
};
struct Border Border9 = {
-1,-1,
3,0,JAM1,
5,
BorderVectors9,
NULL
};
struct IntuiText IText9 = {
1,0,JAM1,
145,1,
NULL,
(UBYTE *)"RAM:PD.LIST",
NULL
};
struct Gadget Gadget2 = {
&Gadget3,
14,38,
370,8,
NULL,
RELVERIFY+STRINGCENTER,
STRGADGET,
(APTR)&Border9,
NULL,
&IText9,
NULL,
(APTR)&Gadget2SInfo,
NULL,
NULL
};
UBYTE Gadget99SIBuff[100] = "RAM:TPD.LIST";
struct StringInfo Gadget99SInfo = {
Gadget99SIBuff,
NULL,
0,
100,
0,
0,0,0,0,0,
0,
0,
NULL
};
SHORT BorderVectors99[] = {
0,0,
371,0,
371,9,
0,9,
0,0
};
struct Border Border99 = {
-1,-1,
3,0,JAM1,
5,
BorderVectors99,
NULL
};
struct IntuiText IText99 = {
1,0,JAM1,
145,1,
NULL,
(UBYTE *)"RAM:TPD.LIST",
NULL
};
struct Gadget Gadget99 = {
&Gadget2,
14,59,
370,8,
NULL,
RELVERIFY+STRINGCENTER,
STRGADGET,
(APTR)&Border99,
NULL,
&IText99,
NULL,
(APTR)&Gadget99SInfo,
NULL,
NULL
};
SHORT BorderVectors10[] = {
0,0,
35,0,
35,10,
0,10,
0,0
};
struct Border Border10 = {
-1,-1,
0,0,JAM2,
5,
BorderVectors10,
NULL
};
struct IntuiText IText10 = {
1,0,JAM2,
2,1,
NULL,
(UBYTE *)"NONE",
NULL
};
struct Gadget Gadget1 = {
&Gadget99,
307,14,
34,9,
NULL,
RELVERIFY,
BOOLGADGET,
(APTR)&Border10,
NULL,
&IText10,
NULL,
NULL,
NULL,
NULL
};
#define GadgetList1 Gadget1
struct NewWindow MyWindow = {
115,68,
396,71,
0,1,
GADGETUP+CLOSEWINDOW,
WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIMPLE_REFRESH,
&Gadget1,
NULL,
(UBYTE *)"PD LIST MAKER ©1988 by C&P Software",
NULL,
NULL,
5,5,
640,200,
WBENCHSCREEN
};
main()
{
int disk_no;
int x, y;
dr[0] = &buffer[0]; dr[1] = &buffer[10];
dr[2] = &buffer[20]; dr[3] = &buffer[30];
dr[4] = &buffer[40]; dr[5] = &buffer[50];
dr[6] = &buffer[60]; dr[7] = &buffer[70];
strcpy(dr[0],"\0"); strcpy(dr[1],"\0");
strcpy(dr[2],"\0"); strcpy(dr[3],"\0");
strcpy(dr[4],"\0"); strcpy(dr[5],"\0");
strcpy(dr[6],"\0"); strcpy(dr[7],"\0");
getdevs();
if(*dr[0])
strcpy(IText8.IText,dr[0]);
if(*dr[1])
strcpy(IText6.IText,dr[1]);
if(*dr[2])
strcpy(IText5.IText,dr[2]);
if(*dr[3])
strcpy(IText4.IText,dr[3]);
if(*dr[4])
strcpy(IText3.IText,dr[0]);
if(*dr[5])
strcpy(IText2.IText,dr[1]);
if(*dr[6])
strcpy(IText1.IText,dr[2]);
if(*dr[7])
strcpy(IText10.IText,dr[3]);
disk_no = setup();
if(!*dr[0])
OffGadget(&Gadget3,Wdw,0L);
if(!*dr[1])
OffGadget(&Gadget5,Wdw,0L);
if(!*dr[2])
OffGadget(&Gadget6,Wdw,0L);
if(!*dr[3])
OffGadget(&Gadget7,Wdw,0L);
if(!*dr[4])
OffGadget(&Gadget8,Wdw,0L);
if(!*dr[5])
OffGadget(&Gadget9,Wdw,0L);
if(!*dr[6])
OffGadget(&Gadget10,Wdw,0L);
if(!*dr[7])
OffGadget(&Gadget1,Wdw,0L);
disk_no = do_list(disk_no);
cleanup(disk_no);
}
setup()
{
int x;
char no[10];
x = 1;
rf = fopen("s:PD.cfg","r");
if(rf){
fgets(&Gadget2SIBuff[0],80,rf);
fgets(&Gadget99SIBuff[0],80,rf);
x = strlen(&Gadget2SIBuff[0]);
Gadget2SIBuff[x-1] = 0;
x = strlen(&Gadget99SIBuff[0]);
Gadget99SIBuff[x-1] = 0;
fgets(&no[0],80,rf);
x = atoi(&no[0]);
fclose(rf);
}
wf = fopen(&Gadget2SIBuff[0],"a");
if(!wf) exit(0);
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",0);
GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library",0);
Wdw = (struct Window *)OpenWindow(&MyWindow);
Move(Wdw->RPort,139,34); Text(Wdw->RPort,"Old PD List File",16);
Move(Wdw->RPort,139,55); Text(Wdw->RPort,"New PD List File",16);
return(x);
}
do_list(no)
int no;
{
char string[2][50];
char *temp = &string[1][0], *temp2 = &string[0][0];
struct Gadget *gotit;
while(!endit){
gotit = (struct Gadget *)0;
switch(ServiceMessages()){
case 1: /* Read Drive 1 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[0],no);
Execute(temp2,0L,0L);
dodir(dr[0],no);
no++;
break;
case 2: /* READ DRIVE 2 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[1],no);
Execute(temp2,0L,0L);
dodir(dr[1],no);
no++;
break;
case 3: /* READ DRIVE 3 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[2],no);
Execute(temp2,0L,0L);
dodir(dr[2],no);
no++;
break;
case 4: /* Read Drive 4 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[3],no);
Execute(temp2,0L,0L);
dodir(dr[3],no);
no++;
break;
case 5: /* Read Drive 5 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[4],no);
Execute(temp2,0L,0L);
dodir(dr[4],no);
no++;
break;
case 6: /* READ DRIVE 6 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[5],no);
Execute(temp2,0L,0L);
dodir(dr[5],no);
no++;
break;
case 7: /* READ DRIVE 7 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[6],no);
Execute(temp2,0L,0L);
dodir(dr[6],no);
no++;
break;
case 8: /* Read Drive 8 */
sprintf(temp2,"Relabel %s \"PDDISK %d\"",dr[7],no);
Execute(temp2,0L,0L);
dodir(dr[7],no);
no++;
break;
case 9: /* Sort/Save List */
SetWindowTitles(Wdw,"Sorting Database...",-1);
fflush(wf);
fclose(wf);
wf = 0;
sort(&Gadget2SIBuff[0],&Gadget99SIBuff[0]);
SetWindowTitles(Wdw,tit,-1);
break;
case 10: /* New File name */
break;
case 11:
break;
default:
;
}
}
return(no);
}
ServiceMessages()
{
struct IntuiMessage *message;
APTR Address;
Wait(1<<Wdw->UserPort->mp_SigBit);
while(message = (struct IntuiMessage *)GetMsg(Wdw -> UserPort)){
if(message->Class == CLOSEWINDOW){
endit = 1; ReplyMsg(message);
return(0);
}
else if(message->Class == GADGETUP){
Address = message->IAddress;
ReplyMsg(message);
if(Address == &Gadget3) return(1); /* DISK0: */
else if(Address == &Gadget5) return(2); /* DISK1: */
else if(Address == &Gadget6) return(3); /* DISK2: */
else if(Address == &Gadget7) return(4); /* DISK3: */
else if(Address == &Gadget8) return(5); /* DISK4: */
else if(Address == &Gadget9) return(6); /* DISK5: */
else if(Address == &Gadget10) return(7);/* DISK6: */
else if(Address == &Gadget1) return(8); /* DISK7: */
else if(Address == &Gadget4) return(9); /* SORT */
else if(Address == &Gadget2) return(10);/* STRING */
else if(Address == &Gadget99) return(11);/* STRING2 */
}
ReplyMsg(message);
}
return(99);
}
dodir(drive,no)
char *drive;
int no;
{
struct FileLock *lock, *Lock();
struct FileInfoBlock *f_info;
if((lock=(struct FileLock *)
AllocMem(sizeof(struct FileLock),MEMF_CHIP|MEMF_CLEAR)) == 0)
return();
if((f_info=(struct FileInfoBlock *)
AllocMem(sizeof(struct FileInfoBlock),MEMF_CHIP|MEMF_CLEAR)) == 0)
return();
if((lock=Lock(drive,ACCESS_READ))==0)
return();
if((Examine(lock,f_info))==0)
return();
while((ExNext(lock,f_info)) != 0)
spill_the_beans(f_info,no);
UnLock(lock);
}
spill_the_beans(info,dno)
struct FileInfoBlock *info;
int dno;
{
char line[80], temp2[25], temp1[15];
protect(&temp1[0],info->fib_Protection);
dates(&temp2[0],&info->fib_Date);
if(info->fib_DirEntryType < 0)
sprintf(&line[0],\
"%-24s %7d %8s %18s PDDISK %d\n",\
info->fib_FileName,info->fib_Size,&temp1[0],&temp2[0],dno);
else
sprintf(&line[0],\
"%-24s %7s %8s %18s PDDISK %d\n",\
info->fib_FileName,"<Dir>",&temp1[0],&temp2[0],dno);
fputs(&line[0],wf);
}
dates(s,dss)
char *s;
struct DateStamp *dss;
{
LONG year,month,day,hours,minutes,secs,tempo;
static char dpm[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
static char *mo[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"
};
year = 1978;
day = dss->ds_Days;
while (day >= 366) {
if ((year-1976) % 4 == 0) {
day -= 366;
year++;
}
else{
if ((year-1976) % 4 != 0 && day >= 365) {
day -= 365;
year++;
}
}
}
if ((year-1976) % 4 == 0) {
day = day % 366;
dpm[2] = 29;
}
else {
day = day % 365;
dpm[2] = 28;
}
for (month = 0; day > dpm[month]; month++)
day -= dpm[month];
minutes = dss->ds_Minute; hours = 0;
while(minutes > 59){
hours++; minutes = minutes - 60L;
}
tempo = dss->ds_Tick; secs = 0;
while(tempo > 49){
secs++; tempo = tempo - 50L;
}
sprintf(s,"%02d-%03s-%02d %02d:%02d:%02d\0",
day,mo[month],year-1900,hours,minutes,secs);
}
protect(s,prot)
char *s;
LONG prot;
{
strcpy(s,"--------");
if(!(prot & 0x00000001))
*(s+7) = 'd';
if(!(prot & 0x00000002))
*(s+6) = 'e';
if(!(prot & 0x00000004))
*(s+5) = 'w';
if(!(prot & 0x00000008))
*(s+4) = 'r';
if(prot & 0x00000010)
*(s+3) = 'a';
if(prot & 0x00000020)
*(s+2) = 'p';
if(prot & 0x00000040)
*(s+1) = 's';
if(prot & 0x00000080)
*s = 'h';
}
getdevs()
{
int x;
char *devicename;
ULONG type;
char buff[80], *name;
char tmp[10];
struct DosList *DevInfo;
struct DosLibrary *dosLibrary;
struct RootNode *RootNode;
struct DosInfo *dosInfo;
struct FileSysStartupMsg *startup;
x = 1;
name = &buff[0];
dosLibrary = (struct DosLibrary *)DOSBase;
RootNode = (struct RootNode *)dosLibrary->dl_Root;
dosInfo = (struct DosInfo *)BADDR(RootNode->rn_Info);
DevInfo = (struct DosList *)BADDR(dosInfo->di_DevInfo);
Forbid();
while(DevInfo != NULL){
if(DevInfo->dol_misc.dol_handler.dol_Startup > 2) {
startup=(struct FileSysStartupMsg *)
BADDR(DevInfo->dol_misc.dol_handler.dol_Startup);
devicename = (char *)BADDR(startup->fssm_Device)+1;
type = DevInfo->dol_Type;
if((type == DLT_DEVICE) && (!strcmp(devicename,"trackdisk.device"))){
name = (char *)BADDR(DevInfo->dol_Name)+1;
strcpy(dr[x-1],name);
strcat(dr[x-1],":");
x = x + 1;
}
}
if(x > 8) break;
DevInfo = (struct DosList *)BADDR(DevInfo->dol_Next);
}
Permit();
strcpy(&tmp[0],dr[0]); strcpy(dr[0],dr[7]); strcpy(dr[7],&tmp[0]);
strcpy(&tmp[0],dr[1]); strcpy(dr[1],dr[6]); strcpy(dr[6],&tmp[0]);
strcpy(&tmp[0],dr[2]); strcpy(dr[2],dr[5]); strcpy(dr[5],&tmp[0]);
strcpy(&tmp[0],dr[3]); strcpy(dr[3],dr[4]); strcpy(dr[4],&tmp[0]);
while(!(*dr[0])){
strcpy(dr[0],dr[1]); strcpy(dr[1],dr[2]); strcpy(dr[2],dr[3]);
strcpy(dr[3],dr[4]); strcpy(dr[4],dr[5]); strcpy(dr[5],dr[6]);
strcpy(dr[6],dr[7]); strcpy(dr[7],"\0");
}
}
errors(er)
char *er;
{
SetWindowTitles(Wdw,er,-1);
Delay(100);
SetWindowTitles(Wdw,tit,-1);
}
cleanup(disk)
int disk;
{
if(wf){
fflush(wf);
fclose(wf);
}
wf = fopen("s:PD.cfg","w");
if(wf){
fprintf(wf,"%s\n%s\n%d\n",&Gadget2SIBuff[0],&Gadget99SIBuff[0],disk);
fclose(wf);
}
CloseWindow(Wdw);
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase);
}
/**************************************************************************
*
* QSORT of the file
*
**************************************************************************/
#define MAXLINES 10000
#define LINESIZE 80
char temp[81], *lines[MAXLINES], *malloc();
int i, numlines;
sort(in,out)
char *in, *out;
{
openfiles(in,out);
tsort();
write();
closefiles();
}
openfiles(i,o)
char *i, *o;
{
rf = fopen(i,"r");
wf = fopen(o,"w");
}
tsort()
{
for(numlines=0;numlines<MAXLINES;numlines++){
if(fgets(&temp[0],80,rf) == NULL) break;
lines[numlines] = (char *)malloc(LINESIZE);
strcpy(lines[numlines],&temp[0]);
}
qs_string(&lines,0,numlines);
for(i=0;i<=numlines;i++){
fputs(lines[i],wf);
free(lines[i]);
}
}
qs_string(item,left,right)
char *item[];
int left,right;
{
register int i, j;
char *x, *y;
i = left; j = right;
x = item[(left+right)/2];
do{
while(strcmp(item[i],x)<0 && i<right) i++;
while(strcmp(item[j],x)>0 && j>left) j--;
if(i<=j){
y = item[i];
item[i] = item[j];
item[j] = y;
i++; j--;
}
}while(i<=j);
if(left<j) qs_string(item,left,j);
if(i<right) qs_string(item,i,right);
}
closefiles()
{
fclose(rf);
fclose(wf);
}