home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
back2roots/padua
/
padua.7z
/
padua
/
arc
/
freeze233.lha
/
amiga.c
next >
Wrap
C/C++ Source or Header
|
1992-05-07
|
4KB
|
182 lines
#include <libraries/dosextens.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ios1.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
int foreground(void) {
struct Process *pr = (struct Process *)FindTask(NULL);
struct CommandLineInterface *cli;
struct UFB *ufb;
BPTR afh;
if (pr->pr_Task.tc_Node.ln_Type == NT_PROCESS) {
if (cli = (struct CommandLineInterface *)BADDR(pr->pr_CLI)) {
if (cli->cli_Background == DOSFALSE) {
ufb = (struct UFB *) chkufb(fileno(stderr));
afh = (BPTR) (ufb->ufbfh);
return IsInteractive(afh);
}
}
}
return FALSE;
}
/*
* Function - SendPacket written by Phil Lindsay, Carolyn Scheppner, and Andy
* Finkel. This function will send a packet of the given type to the Message
* Port supplied.
*/
static long SendPacket(pid, action, args, nargs)
struct MsgPort *pid; /* process indentifier ...
* (handlers message port ) */
long action, /* packet type ...
* (what you want handler to do ) */
args[], /* a pointer to a argument list */
nargs; /* number of arguments in list */
{
struct MsgPort *replyport;
struct StandardPacket *packet;
long count, *pargs, res1 = 0;
replyport = CreatePort(NULL, 0);
if (replyport != NULL) {
/* Allocate space for a packet, make it public and clear it */
packet = (struct StandardPacket *)
AllocMem(sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
if (packet != NULL) {
packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
packet->sp_Pkt.dp_Port = replyport;
packet->sp_Pkt.dp_Type = action;
/* copy the args into the packet */
pargs = &(packet->sp_Pkt.dp_Arg1); /* address of first argument */
for (count = 0; count < nargs; count++)
pargs[count] = args[count];
PutMsg(pid, (struct Message *)packet); /* send packet */
WaitPort(replyport);
GetMsg(replyport);
res1 = packet->sp_Pkt.dp_Res1;
FreeMem(packet, (long) sizeof(struct StandardPacket));
}
DeletePort(replyport);
}
return (res1);
}
#define SECONDS_PER_DAY (60*60*24)
#define FIRST_JAN_1978 2922
char *_TZ = "GMT000";
void setfiledate(char *name, time_t t) {
struct DateStamp ds;
struct FileLock *fl;
BPTR lock, parent;
char bstr[32], *ptr;
int i;
long Arg[4];
if (lock = Lock(name, SHARED_LOCK)) {
parent = ParentDir(lock);
for (ptr = name; *ptr; ptr++) {
if (*ptr == '/' || *ptr == ':') {
name = ptr+1;
}
}
for (i = 0; i < 31; i++) {
if (*name) {
bstr[i+1] = *name++;
} else {
break;
}
}
*bstr = i;
ds.ds_Days = t / SECONDS_PER_DAY - FIRST_JAN_1978;
ds.ds_Minute = t % SECONDS_PER_DAY / 60;
ds.ds_Tick = t % 60 * TICKS_PER_SECOND;
Arg[0] = 0;
Arg[1] = parent;
Arg[2] = (long)bstr >> 2;
Arg[3] = (long)&ds;
fl = (struct FileLock *)BADDR(lock);
SendPacket(fl->fl_Task, ACTION_SET_DATE, Arg, 4);
UnLock(parent);
UnLock(lock);
}
}
char *getfilenote(char *name) {
static struct FileInfoBlock __aligned fib;
BPTR lock;
char *fn = NULL;
if (lock = Lock(name, SHARED_LOCK)) {
if (Examine(lock, &fib)) {
fn = fib.fib_Comment;
}
UnLock(lock);
}
return fn;
}
void setfilenote(char *name, char *comment) {
if (comment) SetComment(name, comment);
}
#ifdef TEST
main(int argc, char **argv) {
char fname[256], *filenote;
int arg;
struct stat st;
FILE *fp;
for (arg = 1; arg < argc; arg++) {
puts(argv[arg]);
if (stat(argv[arg], &st) == 0) {
if (filenote = getfilenote(argv[arg])) {
sprintf(fname, "%s.F", argv[arg]);
if (fp = fopen(fname, "w")) {
fclose(fp);
setfilenote(fname, filenote);
setfiledate(fname, st.st_mtime);
chmod(fname, st.st_mode & 07777);
} else {
perror("fopen");
}
}
} else {
perror("stat");
}
}
if (!foreground()) {
fputs("running in background!\n", stderr);
}
return 0;
}
#endif