Esempio n. 1
0
/* Returns the lock of a name (Allocated with AllocVec()) */
STRPTR NameOfLock( BPTR lock )
{
	STRPTR n;
	BOOL again;
	ULONG bufSize = 127;
	if( !lock ) return NULL;

	do
	{
		again = FALSE;
		if((n = (STRPTR)AllocVec(bufSize, 0x10000 )))
		{
			if( NameFromLock( lock, n, bufSize-1 ) == DOSFALSE )
			{
				if( IoErr() == ERROR_LINE_TOO_LONG )
				{
					bufSize += 127;
					again = TRUE;
				}
				FreeVec(n);
				n = NULL;
			}
		}
	}	while(again);

	return n;
}
Esempio n. 2
0
/* Wanderer doesnt free this mem at the moment but should 
   incase it is every closed */
static STRPTR ExpandEnvName(STRPTR env_path)
{
    BOOL     ok = FALSE;
    char     tmp_envbuff[1024];
    STRPTR   fullpath = NULL;
    BPTR     env_lock = (BPTR) NULL;

    env_lock = Lock("ENV:", SHARED_LOCK);
    if (env_lock)
    {
        if (NameFromLock(env_lock, tmp_envbuff, 256)) ok = TRUE;
        UnLock(env_lock);
    }
    
    if (ok)
    {
        if ((fullpath = AllocVec(strlen(tmp_envbuff) + strlen(env_path) + 1 + 1 - 4, MEMF_CLEAR | MEMF_PUBLIC)) != NULL)
        {
            strcpy(fullpath, tmp_envbuff);
            AddPart(fullpath, env_path + 4, 1019);
            return fullpath;
        }     
    }

    //We couldnt expand it so just use as is ..
    return env_path;
}
Esempio n. 3
0
INLINE STRPTR Executable(struct Task *task)
{
	STRPTR ename = NULL;
	GLOBAL struct DosLibrary * DOSBase;
	
//	ENTER();
	DBG_ASSERT(G->mTask == FindTask(NULL));
	DBG_ASSERT(IsTaskRunning(task)==TRUE);
	
	if((ename = Malloc(1025)))
	{
		struct Process * pr = ((struct Process *)task);
		STRPTR tn = GetTaskName(task, NULL);
		
		if(task->tc_Node.ln_Type != NT_TASK && pr->pr_HomeDir)
		{
			NameFromLock( pr->pr_HomeDir, ename, 1024);
		}
		
		if(tn != NULL)
		{
			AddPart( ename, FilePart(tn), 1024);
			Free(tn);
		}
	}
	
//	DBG_STRING(ename);
	
//	RETURN(ename);
	return(ename);
}
Esempio n. 4
0
static const char *fullprogpath(void)
{
	static char path[MAXPATHLEN*2];
	static char prog[MAXPATHLEN];

	BPTR dir;

	extern BOOL from_WB;	/* in main.c */

	// If the program name contains ':' or '/' it's not in the user's path
	// and probably set by using Py_SetProgramName. In that case, just
	// use this. If it exists!
	strcpy(path,Py_GetProgramName());
	if(strchr(path,':') || strchr(path,'/'))
	{
		if(!isxfile(path))
		{
			// Error; the specified file does not exist or is no exe
			path[0]='\0';
		}
		return path;
	}

	// Construct the full path of our executable program.
	if(from_WB)
	{
		/* We're launced from WB, GetProgramName() won't work */
		/* Use WB's argv[0] as the executable path */
		int argc;
		char **argv;
		Py_GetArgcArgv(&argc, &argv);
		if(argc>0)
			strcpy(path,argv[0]);
		else
			strcpy(path,"!error!");
	}
	else
	{
		/* Launced from CLI, use GetProgramName */

		/* However, first check if the specified name exists */
		if(!isxfile(path))
		{
			path[0]='\0';
			return path;
		}

		path[0]=0;
		if(dir=GetProgramDir())
		{
			(void)NameFromLock(dir,path,MAXPATHLEN);
			if(!GetProgramName(prog,MAXPATHLEN))	// this is a dos.library function!
				strcpy(prog,"!error!");
			if(!AddPart(path,prog,MAXPATHLEN*2))
				strcpy(path,"!error!");
		}
	}
	return path;
}
Esempio n. 5
0
/*
=================
Sys_SetBinaryPath
=================
*/
void Sys_SetBinaryPath(const char *path)
{
#if defined(__AROS__) || defined(__MORPHOS__)
	NameFromLock(GetProgramDir(), binaryPath, sizeof(binaryPath));
#else
	Q_strncpyz(binaryPath, path, sizeof(binaryPath));
#endif
}
Esempio n. 6
0
File: cpp2.c Progetto: WangHoi/slc
//
//  amp July 9, 1997
//
//  Use the OS Luke...
//
//  We do the sneaky version and let the OS do all
//  the hard work so we don't have to mess around
//  a lot ;)
//
ReturnCode MultiAssignLoad( struct Global *global, char *incptr, char *filename, char *tmpname )

{ /* MultiAssignLoad */

    struct MsgPort  *FSTask;
    struct DevProc  *DevProc = NULL;
    LONG            RtnCode = FPP_NO_INCLUDE;

    FSTask = GetFileSysTask();

    do
        {
        //
        //  This should not bring up a requester.
        //  check to see if cpp does in fact tweek
        //  the process WindowPtr.
        //
        DevProc = GetDeviceProc( incptr, DevProc );

        if( DevProc )
            {
            SetFileSysTask( DevProc->dvp_Port );

            //
            //  Normally we would pass the lock and filename
            //  to the Load() routine, which would CD to the
            //  directory and Open(filename), but in order to
            //  satisfy the exisiting openfile() function, we
            //  bite the bullet and build the complete pathspec
            //  rather than add the standard Load() routine.
            //
            if( NameFromLock( DevProc->dvp_Lock, tmpname, NWORK ) )
                {
                AddPart( tmpname, filename, NWORK );

                RtnCode = openfile( global, tmpname );

                if( ! RtnCode )
                    break;
                }
            }

        } while ( RtnCode &&
            DevProc &&
            (DevProc->dvp_Flags & DVPF_ASSIGN) &&
            IoErr() == ERROR_OBJECT_NOT_FOUND); /* repeat if multi-assign */

    SetFileSysTask( FSTask );

    if( DevProc )
        FreeDeviceProc( DevProc );

    return RtnCode;

} /* MultiAssignLoad */
Esempio n. 7
0
static EIF_POINTER simulated_getcwd(char *buffer, size_t maximum_length) {
     EIF_POINTER result = NULL;
     BPTR lock = Lock("", ACCESS_READ);
     if (lock != NULL) {
       if (NameFromLock(lock, buffer, maximum_length) != DOSFALSE) {
         result = (EIF_POINTER) buffer;
       }
       UnLock(lock);
     }
     return result;
   }
Esempio n. 8
0
void ReadAll(BPTR lock)
{
  struct FileInfoBlock * FIB = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR);
  BOOL success;
  int count = 1;

  success = Examine(lock, FIB);
  if (FIB->fib_DirEntryType < 0)
    success = FALSE;
  if (success)
    success = ExNext(lock, FIB);
  while (success)
  {
    printf("%s",FIB->fib_FileName);
    if (FIB->fib_DirEntryType > 0)
    {
      printf(" (Dir)\n");
      count++;
      if (count > 1)
      {
        char * name = AllocVec(1024,0);
        BPTR tmplock;
        NameFromLock(lock,name,1024);
        AddPart(name,FIB->fib_FileName,1024);
        printf("Entering %s\n",name);
        tmplock = Lock(name , ACCESS_READ);
        ReadAll(tmplock);
        NameFromLock(lock,name,1024);
        printf("Returning to %s\n",name);
        UnLock(tmplock);
        FreeVec(name);
      }
    }
    else
    {
      printf("\n");
    }
    success = ExNext(lock,FIB);
  }
  FreeVec(FIB);
}
Esempio n. 9
0
/*
=================
Sys_SetBinaryPath
=================
*/
void Sys_SetBinaryPath(const char *path)
{
#ifdef __AROS__
	if (!strcmp(path, "."))
	{
		NameFromLock(GetProgramDir(), binaryPath, sizeof(binaryPath));
	}
	else
#endif
	{
		Q_strncpyz(binaryPath, path, sizeof(binaryPath));
	}
}
Esempio n. 10
0
STRPTR AllocateNameFromLock(BPTR lock)
{
    ULONG  length = 512;
    STRPTR buffer = NULL;
    BOOL   done   = FALSE;
    
    while (!done)
    {
        if (buffer != NULL) FreeVec(buffer);
        
        buffer = AllocVec(length, MEMF_ANY);
        if (buffer != NULL)
        {
            if (NameFromLock(lock, buffer, length))
            {
                done = TRUE;
                break;
            }
            else
            {
                if (IoErr() == ERROR_LINE_TOO_LONG)
                {
                    length += 512;
                    continue;
                }
                else
                {
                    break;
                }                
            }
        }
        else
        {
            SetIoErr(ERROR_NO_FREE_STORE);
            break;
        }
    }
    
    if (done)
    {
        return buffer;
    }
    else
    {
        if (buffer != NULL) FreeVec(buffer);
        return NULL;
    }
}
Esempio n. 11
0
void Q_getwd (char *out, size_t size, qboolean trailing_dirsep)
{
#if 0
	qerr_strlcpy(__thisfunc__, __LINE__, out, "PROGDIR:", size);
#else
	size_t sz;
	if (NameFromLock(((struct Process *) FindTask(NULL))->pr_CurrentDir, (STRPTR) out, size) == 0)
		COM_Error ("Couldn't determine current directory");
	if (!trailing_dirsep)
		return;
	sz = strlen(out);
	if (!sz || out[sz - 1] == ':' || out[sz - 1] == '/')
		return;
	qerr_strlcat(__thisfunc__, __LINE__, out, "/", size);
#endif
}
Esempio n. 12
0
const char *archdep_boot_path(void)
{
    if (boot_path == NULL) {
        char cwd[1024];
        BPTR lock;

        lock = GetProgramDir();
        if (NameFromLock(lock, cwd, 1024)) {
            if (cwd[strlen(cwd) - 1] != ':') {
                strcat(cwd, "/");
            }
            boot_path = lib_stralloc(cwd);
        }
    }

    return boot_path;
}
Esempio n. 13
0
/* return malloc'd version of full pathname of orig_name */
int archdep_expand_path(char **return_path, const char *orig_name)
{
    BPTR lock;

    lock = Lock(orig_name, ACCESS_READ);
    if (lock) {
        char name[1024];
        LONG rc;

        rc = NameFromLock(lock, name, 1024);
        UnLock(lock);
        if (rc) {
            *return_path = lib_stralloc(name);
            return 0;
        }
    }
    *return_path = lib_stralloc(orig_name);
    return 0;
}
Esempio n. 14
0
HOOKPROTONH(AppMessageCode, VOID, Object* htmlview, struct MUIP_AppMessage *args)
{
    if(args->appmsg->am_NumArgs)
    {
      char dir[256+8];

      #if defined(__MORPHOS__)
      stccpy(dir, "file://", sizeof(dir));
      #else
      strlcpy(dir, "file://", sizeof(dir));
      #endif

        if(NameFromLock(args->appmsg->am_ArgList[0].wa_Lock, dir+7, 256))
        {
            AddPart(dir+7, args->appmsg->am_ArgList[0].wa_Name, 256);
            DoMethod(htmlview, MUIM_HTMLview_GotoURL, (ULONG)dir, NULL);
        }
    }
}
Esempio n. 15
0
/*
=================
Sys_SetBinaryPath
=================
*/
void Sys_SetBinaryPath(const char *path)
{
#ifdef __AROS__
	if (!strcmp(path, "."))
	{
		BPTR lock = Lock("PROGDIR:", ACCESS_READ);

		if (lock)
		{
			NameFromLock(lock, binaryPath, sizeof(binaryPath));
			UnLock(lock);
		}
	}
	else
#endif
	{
		Q_strncpyz(binaryPath, path, sizeof(binaryPath));
	}
}
Esempio n. 16
0
char *
canonicalize_file_name (const char *path)
{
  char *ret;
  BPTR lck;

  if (path[0] == '/' && path[1] == '/' && path[2] == ':')
    return xstrdup (path);

  ret = xmalloc (2048);
  lck = Lock ((const unsigned char *) path, SHARED_LOCK);

  if (!lck || !NameFromLock (lck, (unsigned char *) ret, 2040))
    {
      free (ret);
      ret = xstrdup (path);
    }
  if (lck)
    UnLock (lck);

  return ret;
}
Esempio n. 17
0
int __stat_from_path(const char *path, struct stat *sb)
{
    int                  len;
    char                 *mypath;
    int                  cwdsize = FILENAME_MAX;
    char                 *cwd = NULL;
    char                 *abspath = NULL;
    char                 *filepart = NULL;
    char                 *split;
    struct FileInfoBlock *fib = NULL;
    BPTR                 lock = BNULL;
    BPTR                 cwdlock;
    int                  fallback_to_defaults = 0;
    BOOL                 loop;
    int                  res = -1;

    /* copy path and strip trailing slash */
    len = strlen(path);
    if (!(mypath = AllocVec(len + 1, MEMF_ANY)))
    {
        errno = ENOMEM;
        goto out;
    }
    strcpy(mypath, path);
    if (len && mypath[len-1] == '/')
        mypath[len-1] = '\0';

    /* do we have an absolute path */
    if (!strchr(mypath, ':'))
    {
        /* no, then create one */
        cwdlock = CurrentDir(BNULL);
        CurrentDir(cwdlock);
        do
        {
            if (!(cwd = AllocVec(cwdsize, MEMF_ANY)))
            {
                errno = ENOMEM;
                goto out;
            }

            if (NameFromLock(cwdlock, cwd, cwdsize))
                break;
            else if (IoErr() != ERROR_LINE_TOO_LONG)
            {
                errno = __stdc_ioerr2errno(IoErr());
                goto out;
            }

            FreeVec(cwd);
            cwdsize *= 2;
        }
        while (TRUE);

        /* get memory for current dir + '/' + input path + zero byte */
        len = strlen(cwd) + 1 + len + 1;
        abspath = AllocVec(len, MEMF_ANY);
        if (!abspath)
        {
            errno = ENOMEM;
            goto out;
        }

        strcpy(abspath, cwd);
        AddPart(abspath, mypath, len);
        FreeVec(mypath);
    }
    else
        abspath = mypath;

    /* split into path part and file part */
    split = FilePart(abspath);
    filepart = AllocVec(strlen(split) + 1, MEMF_ANY);
    if (!filepart)
    {
        errno = ENOMEM;
        goto out;
    }
    strcpy(filepart, split);
    *split = '\0';

    if (   !(fib = AllocDosObject(DOS_FIB, NULL))
        || !(lock = Lock(abspath, SHARED_LOCK)))
    {
        errno = __stdc_ioerr2errno(IoErr());
        goto out;
    }

    /* examine parent directory of object to stat */
    if (!Examine(lock, fib))
    {
        if (IoErr() == ERROR_NOT_IMPLEMENTED ||
            IoErr() == ERROR_ACTION_NOT_KNOWN)
            fallback_to_defaults = 1;
        else
        {
            errno = __stdc_ioerr2errno(IoErr());
            goto out;
        }
    }

    if (*filepart == '\0' || fallback_to_defaults)
        __fill_statbuffer(sb, abspath, fib, fallback_to_defaults, lock);
    else
        /* examine entries of parent directory until we find the object to stat */
        do
        {
            loop = ExNext(lock, fib);

            if (loop)
            {
                if (stricmp(fib->fib_FileName, filepart) == 0)
                {
                    __fill_statbuffer(sb, abspath, fib, 0, lock);
                    res = 0;
                    break;
                }

                continue;
            }

            if (IoErr() != ERROR_NO_MORE_ENTRIES)
                errno = __stdc_ioerr2errno(IoErr());
            else
                /* nothing found to stat */
                errno = ENOENT;
        }
        while (loop);

out:
    if (lock)
        UnLock(lock);

    FreeVec(cwd);

    /* if we had absolute path as input, mypath is free'd here */
    FreeVec(abspath);

    FreeVec(filepart);

    if (fib)
        FreeDosObject(DOS_FIB, fib);

    return res;
}
Esempio n. 18
0
int __stat(BPTR lock, struct stat *sb, BOOL filehandle)
{
    struct FileInfoBlock *fib;
    UBYTE *buffer;
    int buffersize = 256;
    int fallback_to_defaults = 0;
    BOOL Examined;

    fib = AllocDosObject(DOS_FIB, NULL);

    if (!fib)
    {
        errno = __stdc_ioerr2errno(IoErr());

        return -1;
    }

    Examined = filehandle
             ? ExamineFH(lock, fib)
             : Examine(lock, fib);
    if (!Examined)
    {
	if(IoErr() == ERROR_NOT_IMPLEMENTED ||
	   IoErr() == ERROR_ACTION_NOT_KNOWN)
	{
	    fallback_to_defaults = 1;
	}
	else
	{
            errno = __stdc_ioerr2errno(IoErr());
            FreeDosObject(DOS_FIB, fib);
            return -1;
	}
    }

    /* Get the full path of the stated filesystem object and use it to
       compute hash value */
    do
    {
        BOOL GotName;

        if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
        {
            errno = ENOMEM;
            FreeDosObject(DOS_FIB, fib);
            return -1;
        }

        GotName = filehandle
                ? NameFromFH(lock, buffer, buffersize)
                : NameFromLock(lock, buffer, buffersize);
        if(GotName)
            break;
        else if(   IoErr() == ERROR_OBJECT_IN_USE
                || IoErr() == ERROR_NOT_IMPLEMENTED
                || IoErr() == ERROR_ACTION_NOT_KNOWN
                || (IoErr() == ERROR_OBJECT_NOT_FOUND && fib->fib_EntryType == ST_PIPEFILE))
        {
            /* We can't retrieve name because lock is an exclusive lock
               or Examine is not implemented in this handler
               or the lock refers to an XPIPE: file having always empty name */
            buffer[0] = '\0';
            break;
        }
        else if(IoErr() != ERROR_LINE_TOO_LONG)
        {
            errno = __stdc_ioerr2errno(IoErr());
            FreeDosObject(DOS_FIB, fib);
            FreeVec(buffer);
            return -1;
        }
        FreeVec(buffer);
        buffersize *= 2;
    }
    while(TRUE);

    // We need a FileLock. Otherwise a call of Info() within __fill_statbuffer() will crash
    // FIXME: how can we get a lock on an exclusive file?
    if (filehandle)
    {
        BPTR filelock = DupLockFromFH(lock);
        __fill_statbuffer(sb, (char*) buffer, fib, fallback_to_defaults, filelock);
        UnLock(filelock);
    }
    else
    {
        __fill_statbuffer(sb, (char*) buffer, fib, fallback_to_defaults, lock);
    }

    FreeVec(buffer);
    FreeDosObject(DOS_FIB, fib);

    return 0;
}
Esempio n. 19
0
char *getcwd(char *b, int size)
{
  struct Process *p = (struct Process*)FindTask(NULL);
  NameFromLock(p->pr_CurrentDir, b, size);
  return b;
}
Esempio n. 20
0
__asm ULONG ObjStringDispatcher(a0 struct IClass *cl, a2 Object *o, a1 Msg msg)
{
    TagItem    *ti;
    struct ObjStringData *idata = INST_DATA(cl, o);

    putreg(REG_A6, (long)cl->cl_UserData);
    geta4();

    switch (msg->MethodID) {
    case OM_NEW: {
        Object *obj = (Object*)DoSuperMethodA(cl, o, msg);
        if (obj) {
            idata = INST_DATA(cl, obj);
            if (ti = FindTagItem(SWA_ObjString_StrAttr, ((opSet *)msg)->ops_AttrList))
                idata->StrAttr = ti->ti_Data;
            SetAttrs(obj, MUIA_Draggable,          TRUE,
                     MUIA_CycleChain,         1,
                     MUIA_String_AdvanceOnCR, TRUE, TAG_DONE);
        }
        return (ULONG)obj;
    }

    case OM_GET: {
        if (((struct opGet *)msg)->opg_AttrID == SWA_ObjString_NumVal) {
            ULONG *Store = ((struct opGet *)msg)->opg_Storage;

            if (Store) *Store = SWGetUL(o, MUIA_String_Integer);

            return 1;
        }

        break;
    }

    case OM_SET:
    case OM_UPDATE: {
        ULONG rc;

        if (ti=FindTagItem(MUIA_String_Contents,((opSet *)msg)->ops_AttrList)) {
            rc = DoSuperMethodA(cl, o, msg);
            set(o, SWA_ObjString_NumVal, SWGetUL(o, MUIA_String_Integer));
            return rc;
        }


        if (ti=FindTagItem(SWA_ObjString_NumVal,((opSet *)msg)->ops_AttrList)) {
            if (idata->LastVal == ti->ti_Data) {
                ti->ti_Tag = TAG_IGNORE;
                rc = DoSuperMethodA(cl, o, msg);
                ti->ti_Tag = SWA_ObjString_NumVal;
                return rc;
            }

            SetSuperAttrs(cl, o,
                          MUIA_NoNotify,       TRUE,
                          MUIA_String_Integer, idata->LastVal = ti->ti_Data,
                          TAG_DONE);
        }
    }

    break;

    case MUIM_DragQuery: {
        Object *drag_o = ((struct MUIP_DragQuery *)msg)->obj;
        if (drag_o == o)                        return MUIV_DragQuery_Refuse;
        if (OCLASS(drag_o) == OCLASS(o)) {
            UBYTE *s1, *s2;
            get(drag_o, MUIA_String_Accept, &s1);
            get(o,      MUIA_String_Accept, &s2);
            if (!s1 && !s2) return MUIV_DragQuery_Accept;
            if (!s1 || !s2) return MUIV_DragQuery_Refuse;
            return (ULONG)(!strcmp(s1, s2) ? MUIV_DragQuery_Accept
                           : MUIV_DragQuery_Refuse);
        }

        if (OCLASS(drag_o) == SWObjListClass()) SWDB_RET(MUIV_DragQuery_Accept);

        if (!idata->StrAttr)                    return MUIV_DragQuery_Refuse;

        if (!(drag_o = (Object *)DoMethod(drag_o, SWM_Root_GetDragObj)))
            return MUIV_DragQuery_Refuse;

        return (ULONG)(get(drag_o, idata->StrAttr, NULL)
                       ? MUIV_DragQuery_Accept : MUIV_DragQuery_Refuse);
    }

    case MUIM_DragDrop: {
        Object *drag_o = ((struct MUIP_DragQuery *)msg)->obj;
        if (OCLASS(drag_o) == OCLASS(o)) {
            set(o, MUIA_String_Contents, SWGetUL(drag_o, MUIA_String_Contents));
            set(o, SWA_ObjString_NumVal, SWGetUL(o,      MUIA_String_Integer));
            return 0;
        }

        // -- if objlist, append its primary attribute -----------------------

        if (OCLASS(drag_o) == SWObjListClass()) {
            UBYTE *c, *val;
            get(o, MUIA_String_Contents, &c);

            val = (UBYTE *)DoMethod((Object *)muiUserData(drag_o),
                                    SWM_E_Listmgr_StrCopy, c);

            if (val && c) {
                set(o,  MUIA_String_Contents, val);
                FreeVec(val);
                return 0;
            }
        }

        if (!(drag_o = (Object *)DoMethod(drag_o, SWM_Root_GetDragObj)))
            return MUIV_DragQuery_Refuse;

        set(o, MUIA_String_Contents, SWGetStr(drag_o, idata->StrAttr));
        return 0;
    }

    case SWM_ObjString_AppMsg: {
        UBYTE FSpec[FMSIZE];
        struct AppMessage *AMsg = ((struct SWP_AppMsg *)msg)->AMsg;

        if (AMsg->am_NumArgs > 0) {
            NameFromLock(AMsg->am_ArgList[0].wa_Lock, FSpec, FMSIZE);
            AddPart(FSpec, AMsg->am_ArgList[0].wa_Name, FMSIZE);
            set(o, MUIA_String_Contents, FSpec);
        }
        return 0;
    }

    }

    return DoSuperMethodA(cl, o, msg);
}
Esempio n. 21
0
int LIBFUNC L_Module_Entry(
	REG(a0, char *argstring),
	REG(a1, struct Screen *screen),
	REG(a2, IPCData *ipc),
	REG(a3, IPCData *main_ipc),
	REG(d0, ULONG mod_id),
	REG(d1, EXT_FUNC(func_callback)))
{
	DOpusCallbackInfo info, *infoptr = &info;
	char filename[300];
	FuncArgs *args;

	// Get callbacks
    info.dc_Count=DOPUS_HOOK_COUNT;
    info.dc_RexxCommand=0;
    info.dc_FileRequest=0;
    info.dc_GetThemes=0;
    info.dc_UnlockSource=0;
    IPC_Command(main_ipc,HOOKCMD_GET_CALLBACKS,0,&info,0,REPLY_NO_PORT);

	// Must be able to send rexx commands and show file requester
	if (!info.dc_RexxCommand || !info.dc_FileRequest) return 0;

	// See if filename is supplied
	filename[0]=0;
	if ((args=ParseArgs(func_templates[mod_id],argstring)) && args->FA_Arguments[0])
	{
		strcpy(filename,(char *)args->FA_Arguments[0]);
		if (!strchr(filename,'/') && !strchr(filename,':'))
		{
			lsprintf(filename,"D5THEMES:%s",(IPTR)args->FA_Arguments[0]);
		}	
		if (mod_id!=CONVERTTHEME && (strlen(filename)<7 || stricmp(filename+strlen(filename)-6,".theme")!=0))
			strcat(filename,".theme");
	}

	// No filename?
	if (!*filename && (mod_id==LOADTHEME || mod_id==CONVERTTHEME))
	{
		FunctionEntry *entry;

		// Get first entries
		if ((entry=(FunctionEntry *)func_callback(EXTCMD_GET_ENTRY,IPCDATA(ipc),0)))
		{
			struct endentry_packet packet;

			// Build filename
			func_callback(EXTCMD_GET_SOURCE,IPCDATA(ipc),filename);
			AddPart(filename,entry->name,256);

			// Fill out packet to end entry
			packet.entry=entry;
			packet.deselect=1;
			func_callback(EXTCMD_END_ENTRY,IPCDATA(ipc),&packet);
		}
	}

	// Unlock source lister
	if (info.dc_UnlockSource)
		DC_CALL1(infoptr, dc_UnlockSource, DC_REGA0, IPCDATA(ipc));
		//DC_UnlockSource(infoptr, IPCDATA(ipc));
		//info.dc_UnlockSource(IPCDATA(ipc));
	
	// Save theme?
	if (mod_id==SAVETHEME || mod_id==BUILDTHEME)
	{
		char buf[256];

		// Get themes path
		if (info.dc_GetThemes)
			DC_CALL1(infoptr, dc_GetThemes, DC_REGA0, buf);
			//DC_GetThemes(infoptr,buf);
			//info.dc_GetThemes(buf);
		else
			strcpy(buf,"D5THEMES:");

		// Get filename
		if (filename[0] ||
			DC_CALL6(infoptr, dc_FileRequest,
				DC_REGA0, (struct Window *)screen,
				DC_REGA1, GetString(locale,(mod_id==SAVETHEME)?MSG_SAVE_THEME_MSG:MSG_BUILD_THEME_MSG),
				DC_REGA2, buf,
				DC_REGA3, filename,
				DC_REGD0, (1<<30)|(1<<31)|FRF_DOSAVEMODE,
				DC_REGD1, 0))
			//DC_FileRequest(infoptr,
			//info.dc_FileRequest(
			/*	(struct Window *)screen,
				GetString(locale,(mod_id==SAVETHEME)?MSG_SAVE_THEME_MSG:MSG_BUILD_THEME_MSG),
				buf,
				filename,
				(1<<30)|(1<<31)|FRF_DOSAVEMODE,0))*/
		{
			long res;
			char *ptr;

			// Check .theme suffix
			if (strlen(filename)<7 || stricmp(filename+strlen(filename)-6,".theme")!=0)
				strcat(filename,".theme");

			// Remove spaces
			for (ptr=FilePart(filename);*ptr;ptr++)
				if (*ptr==' ') *ptr='_';

			// Save theme
			if ((res=save_theme(screen,&info,filename,(mod_id==BUILDTHEME)?TRUE:FALSE)))
			{
				// Build error
				lsprintf(filename,GetString(locale,MSG_SAVE_ERROR),res);

				// Show error
				AsyncRequestTags(
					ipc,
					REQTYPE_SIMPLE,
					0,
					0,
					0,
					AR_Screen,(IPTR)screen,
					AR_Message,(IPTR)filename,
					AR_Button,(IPTR)GetString(locale,MSG_OK),
					TAG_END);
			}
		}
	}

	// Load theme
	else
	if (mod_id==LOADTHEME)
	{
		ULONG apply_flags=0;

		// Flags supplied?
		if (args)
		{
			short num;
			for (num=0;num<4;num++)
			{
				if (args->FA_Arguments[num+1])
					apply_flags|=1<<num;
			}
		}

		// No name supplied?
		if (!filename[0])
		{
			BPTR lock;
			Att_List *list;
			Att_Node *node;
			char *apply_switches[5];
			char temp[20];
			char path[256];
			long err;

			// Get old apply flags
			if (!apply_flags && (GetVar("dopus/taf",temp,16,GVF_GLOBAL_ONLY))>0)
				apply_flags=atoi(temp);

			// Initial theme path
			strcpy(path,"D5THEMES:");
			if ((lock=Lock(path,ACCESS_READ)))
			{
				NameFromLock(lock,path,256);
				UnLock(lock);
			}
			
			// Get list of themes
			while ((list=theme_build_list(path)))
			{
				// Switches for what to apply
				apply_switches[0]=GetString(locale,MSG_THEME_APPLY_PALETTE);
				apply_switches[1]=GetString(locale,MSG_THEME_APPLY_FONTS);
				apply_switches[2]=GetString(locale,MSG_THEME_APPLY_PICTURES);
				apply_switches[3]=GetString(locale,MSG_THEME_APPLY_SOUNDS);
				apply_switches[4]=0;

				// Show selection list
				strcpy(filename,path);
				if ((err=SelectionList(
							list,
							0,
							screen,
							GetString(locale,MSG_LOAD_THEME_MSG),
							-1,
							SLF_DIR_FIELD|SLF_USE_INITIAL|SLF_SWITCHES|SLF_RETURN_PATH,
							filename,
							GetString(locale,MSG_OK),
							GetString(locale,MSG_CANCEL),
							apply_switches,
							&apply_flags))>-1)
				{
					// Name selected?
					if ((node=Att_FindNode(list,err)))
					{
						char *ptr;
						for (ptr=node->node.ln_Name;*ptr;ptr++)
							if (*ptr==' ') *ptr='_';
						lsprintf(filename,"D5THEMES:%s.theme",(IPTR)node->node.ln_Name);
					}
					else
						filename[0]=0;

					// Save apply flags
					lsprintf(temp,"%ld",apply_flags);
					SetEnv("dopus/taf",temp,TRUE);
				}
				else
				if (err!=-1 && filename[0]!=0 && filename[strlen(filename)-1]=='/') filename[0]=0;

				// Free list
				Att_RemList(list,0);

				// Break out?
				if (err!=-1) break;

				// Empty path returns to default
				if (!filename[0])
				{
					// Get themes path
					if (info.dc_GetThemes)
						DC_CALL1(infoptr, dc_GetThemes,	DC_REGA0, filename);
						//DC_GetThemes(infoptr,filename);
						//info.dc_GetThemes(filename);
					else 
						strcpy(filename,"DOpus5:Themes/");
					
				}

				// Re-open with new path
				strcpy(path,filename);

				// Assign D5THEMES to the new directory
				if ((lock=Lock(filename,ACCESS_READ)) &&
					!(AssignLock("D5THEMES",lock)))
					UnLock(lock);
			}
		}

		// File to load?
		if (filename[0])
		{
			short num;
			char apply[20],*ptr,command[400],port[40];

			// Build apply flags
			for (num=0,ptr=apply;num<APPLY_LAST;num++)
			{
				if (apply_flags&(1<<num))
					*(ptr++)=apply_lookup[num];
			}
			*ptr=0;

			// Get ARexx port name
			DC_CALL1(infoptr, dc_GetPort, DC_REGA0, port);
			//DC_GetPort(infoptr,port);
			//info.dc_GetPort(port);

			// Build ARexx command to send to DOpus
			lsprintf(command,"%s %s %s",(IPTR)filename,(IPTR)port,(IPTR)apply);
			DC_CALL4(infoptr, dc_SendCommand,
				DC_REGA0, 0,
				DC_REGA1, command,
				DC_REGA2, 0,
				DC_REGD0, COMMANDF_RUN_SCRIPT);
			//DC_SendCommand(infoptr,0,command,0,COMMANDF_RUN_SCRIPT);
			//info.dc_SendCommand(0,command,0,COMMANDF_RUN_SCRIPT);
		}
	}

	// Convert theme
	else
	if (mod_id==CONVERTTHEME)
	{
		// Get filename
		if (filename[0] ||
			DC_CALL6(infoptr, dc_FileRequest,
				DC_REGA0, (struct Window *)screen,
				DC_REGA1, GetString(locale,MSG_CONVERT_THEME_MSG),
				DC_REGA2, 0,
				DC_REGA3, filename,
				DC_REGD0, (1<<30)|(1<<31)|(1<<29)|FRF_DOPATTERNS,
				DC_REGD1, "#?.theme"))
			//DC_FileRequest(infoptr,
			//info.dc_FileRequest(
				/*(struct Window *)screen,
				GetString(locale,MSG_CONVERT_THEME_MSG),
				0,
				filename,
				(1<<30)|(1<<31)|(1<<29)|FRF_DOPATTERNS,
				"#?.theme"))*/
		{
			char dest[256],buf[256],*ptr;

			dest[0]=0;
			if ((args=ParseArgs(func_templates[mod_id],argstring)) && args->FA_Arguments[1])
			{
				strcpy(dest,(char *)args->FA_Arguments[1]);
				if (!strchr(dest,'/') && !strchr(dest,':'))
				{	
					lsprintf(dest,"D5THEMES:%s",(IPTR)args->FA_Arguments[0]);
				}	
			}

			// Ask for path?
			if (!dest[0])
			{
				// Get themes path
				if (info.dc_GetThemes)
					DC_CALL1(infoptr, dc_GetThemes,	DC_REGA0, buf);
					//DC_GetThemes(infoptr,buf);
					//info.dc_GetThemes(buf);
				else
					strcpy(buf,"D5THEMES:");
			}	

			// Get save filename
			if (dest[0] ||
				DC_CALL6(infoptr, dc_FileRequest,
					DC_REGA0, (struct Window *)screen,
					DC_REGA1, GetString(locale,MSG_SAVE_THEME_MSG),
					DC_REGA2, buf,
					DC_REGA3, dest,
					DC_REGD0, (1<<30)|(1<<31)|FRF_DOSAVEMODE,
					DC_REGD1, 0))
				//(DC_FileRequest(infoptr,
				//(info.dc_FileRequest(
				/*	(struct Window *)screen,
					GetString(locale,MSG_SAVE_THEME_MSG),
					buf,
					dest,
					(1<<30)|(1<<31)|FRF_DOSAVEMODE,0)))*/
			{
				short res;

				// Check .theme suffix
				if (strlen(dest)<7 || stricmp(dest+strlen(dest)-6,".theme")!=0)
					strcat(dest,".theme");

				// Remove spaces
				for (ptr=FilePart(dest);*ptr;ptr++)
					if (*ptr==' ') *ptr='_';

				// Convert the file
				if ((res=convert_theme(&info,filename,dest)))
				{
					// Build error
					lsprintf(filename,GetString(locale,MSG_SAVE_ERROR),res);

					// Show error
					AsyncRequestTags(
						ipc,
						REQTYPE_SIMPLE,
						0,
						0,
						0,
						AR_Screen,(IPTR)screen,
						AR_Message,(IPTR)filename,
						AR_Button,(IPTR)GetString(locale,MSG_OK),
						TAG_END);
				}
			}
		}
	}

	DisposeArgs(args);
	return 1;
}
Esempio n. 22
0
/*************
 * DESCRIPTION:   Saves a image. Invokes the different handlers.
 * INPUT:         handler     handler name
 *                param       parameter to pass to saver
 * OUTPUT:        error code
 *************/
int IMAGE::Save(RSICONTEXT *rc, char *handler, void *param)
{
	char buf[256];
	char error[256];
	PICTURE image;
#ifdef __AMIGA__
	BPTR lock;
	char buf1[32];
	int i;
#endif

	rc->SetImageError(NULL);

	image.name = name;
	image.colormap = colormap;
	image.width = width;
	image.height = height;
	image.caller = NULL;
	image.param = param;
	image.malloc = malloc;
	image.Progress = NULL;

#ifndef __AMIGA__
	if (keyWritePicture)
	{
		strcpy(buf, WorkingDirectory);
		AddPart(buf, "modules", 256);
		AddPart(buf, "picture", 256);
		AddPart(buf, handler, 256);
		strcat(buf, ".dll");

		if (!keyWritePicture(buf, &image, error))
		{
			rc->SetImageError(error);
			return ERR_PICHANDLER;
		}
	}
	return ERR_NONE;
#else
	if(KeyfileBase)
	{
		// get directory RayStorm was started from and
		// search file from there
		// get a lock to the program directory
		lock = GetProgramDir();
		if(!NameFromLock(lock, buf, 256))
			return ERR_PICHANDLER;
		AddPart(buf, "modules/picture", 256);

		// we need lower case names because library names are case sensitve
		i=0;
		strcpy(buf1, handler);
		while(buf1[i])
		{
			if((buf1[i] >= 'A') && (buf1[i] <= 'Z'))
				buf1[i] += 'a'-'A';
			i++;
		}
		AddPart(buf, buf1, 256);
#ifdef __PPC__
		strcat(buf, "ppc");
#endif

		if(!keyWritePicture(buf, &image, error))
		{
			rc->SetImageError(error);
			return ERR_PICHANDLER;
		}
	}

	return ERR_NONE;
#endif // !__AMIGA__
}
Esempio n. 23
0
// Change entry's path
void config_paths_change(config_path_data *data)
{
	char *str;
	BPTR lock;
	char path[256];
	position_rec *pos;
	Att_Node *node;
	struct List *search;

	// No path selected?
	if (!data->path_sel) return;

	// Get path string
	str=(char *)GetGadgetValue(data->objlist,GAD_PATHFORMAT_PATH);

	// Invalid?
	if (!str || !*str)
	{
		// Remove this path
		config_paths_remove(data,TRUE);
		return;
	}

	// Try to lock
	if ((lock=Lock(str,ACCESS_READ)))
	{
		// Get full pathname
		NameFromLock(lock,path,256);
		UnLock(lock);
	}

	// Otherwise, use entered path
	else strcpy(path,str);

	// Fix path with trailing /
	AddPart(path,"",256);

	// See if path is already in edit list
	if ((node=(Att_Node *)FindNameI((struct List *)data->path_list,path)))
	{
		// Not the currently selected node?
		if (node!=data->path_sel)
		{
			// Error
			DisplayBeep(data->window->WScreen);
			ActivateStrGad(GADGET(GetObject(data->objlist,GAD_PATHFORMAT_PATH)),data->window);
			return;
		}
	}

	// Is path already in snapshot list?
	search=data->paths;
	while ((pos=(position_rec *)FindNameI(search,path)))
	{
		// Position entry?
		if (pos->node.ln_Type==PTYPE_POSITION) break;
		search=(struct List *)pos;
	}

	// Found it?
	if (pos)
	{
		// Different entry?
		if (pos!=(position_rec *)data->path_sel->data)
		{
			// Remove current entry from list
			Remove((struct Node *)data->path_sel->data);

			// Free current data
			FreeMemH((void *)data->path_sel->data);
			data->path_sel->data=(ULONG)pos;
		}

		// If path exists, clear "new" flag
		if (lock) pos->flags&=~POSITIONF_NEW;
	}

	// It is now
	else pos=(position_rec *)data->path_sel->data;

	// Set its user flag
	pos->flags|=POSITIONF_USER;

	// Store new name
	strcpy(pos->name,path);

	// Remove list from gadget
	SetGadgetChoices(data->objlist,GAD_PATHFORMAT_PATHS,(APTR)~0);

	// Remove existing node and add new one
	Att_RemNode(data->path_sel);

	// Add to list
	data->path_sel=Att_NewNode(data->path_list,pos->node.ln_Name,(ULONG)pos,ADDNODE_SORT);

	// Attach list to gadget
	SetGadgetChoices(data->objlist,GAD_PATHFORMAT_PATHS,data->path_list);

	// Select the new node
	config_paths_select(data,data->path_sel,TRUE);
}
Esempio n. 24
0
int LIBFUNC L_Module_Entry(
	REG(a0, struct List *files),
	REG(a1, struct Screen *screen),
	REG(a2, IPCData *ipc),
	REG(a3, IPCData *main_ipc),
	REG(d0, ULONG mod_id),
	REG(d1, ULONG mod_data))
{
	config_path_data *data;
	short success=1;

	// Allocate data
	if (!(data=AllocVec(sizeof(config_path_data),MEMF_CLEAR)) ||
		!(data->path_list=Att_NewList(0)))
	{
		FreeVec(data);
		return 0;
	}

	// Store data pointers
	data->paths=files;
	data->ipc=ipc;
	data->main_ipc=main_ipc;
	data->memory=(APTR)mod_id;
	data->def_format=(ListFormat *)mod_data;

	// AppPort
	data->appport=CreateMsgPort();

	// Open commodities library
	/*data->cxbase=OpenLibrary("commodities.library",0);
	#ifdef __amigaos4__
	ICommodities=(struct CommoditiesIFace *)GetInterface(data->cxbase,"main",1,NULL); 
	#endif	*/
	
	// Build path list
	config_paths_build_list(data);

	// Open window
	if (!(config_paths_open(data,screen)))
		return 0;

	// Event loop
	FOREVER
	{
		IPCMessage *imsg;
		struct IntuiMessage *msg;
		int quit_flag=0;

		// IPC messages?
		while ((imsg=(IPCMessage *)GetMsg(ipc->command_port)))
		{
			// Quit?
			if (imsg->command==IPC_QUIT)
			{
				quit_flag=1;
				success=0;
			}

			// Hide?
			else if (imsg->command==IPC_HIDE)
			{
				RemoveAppWindow(data->appwindow);
				data->appwindow=0;
				CloseConfigWindow(data->window);	
				data->window=0;
			}

			// Show?
			else if (imsg->command==IPC_SHOW)
			{
				if (!(config_paths_open(data,imsg->data)))
				{
					quit_flag=1;
					success=0;
				}
			}

			// Activate
			else if (imsg->command==IPC_ACTIVATE)
			{
				if (data->window)
				{
					WindowToFront(data->window);
					ActivateWindow(data->window);
				}
			}

			// Reply
			IPC_Reply(imsg);
		}

		// Any messages to the window?
		if (data->window)
		{
			while ((msg=GetWindowMsg(data->window->UserPort)))
			{
				struct IntuiMessage msg_copy;
				UWORD gadgetid;

				// Copy message and reply
				msg_copy=*msg;
				ReplyWindowMsg(msg);

				// Look at message
				switch (msg_copy.Class)
				{
					// Close window
					case IDCMP_CLOSEWINDOW:
						quit_flag=1;
						success=0;
						break;


					// Gadget
					case IDCMP_GADGETUP:
					case IDCMP_GADGETDOWN:

						// Get GadgetID
						gadgetid=((struct Gadget *)msg_copy.IAddress)->GadgetID;

						// Look at gadget
						switch (gadgetid)
						{
							// Cancel
							case GAD_PATHFORMAT_CANCEL:
								success=0;

							// Use
							case GAD_PATHFORMAT_SAVE:
								quit_flag=1;
								break;


							// Add an entry
							case GAD_PATHFORMAT_ADD:
								config_paths_add(data,TRUE);
								break;


							// Change path name
							case GAD_PATHFORMAT_PATH:
								config_paths_change(data);
								break;


							// Select an entry
							case GAD_PATHFORMAT_PATHS:
								{
									Att_Node *node;

									// Find selected entry
									node=Att_FindNode(data->path_list,msg_copy.Code);

									// Double-click?
									if (DoubleClick(data->seconds,data->micros,msg_copy.Seconds,msg_copy.Micros) &&
										node==data->path_sel)
									{
										// Edit it	
										config_paths_edit(data);
										break;
									}

									// Store double-click time
									data->seconds=msg_copy.Seconds;
									data->micros=msg_copy.Micros;

									// Not already selected?
									if (node!=data->path_sel)
									{
										// Select it
										config_paths_select(data,node,FALSE);
									}
								}
								break;


							// Key
							case GAD_PATHFORMAT_KEY:
								config_paths_get_key(data);
								break;


							// Open new lister
							case GAD_PATHFORMAT_NEW_LISTER:

								// Valid selection?
								if (data->path_sel)
								{
									position_rec *pos=(position_rec *)data->path_sel->data;

									// Open new lister?
									if (msg_copy.Code)
									{
										// Set flag
										pos->flags|=POSITIONF_OPEN_NEW;
	
										// Clear type flags
										pos->flags&=~(POSITIONF_ICON|POSITIONF_ICON_ACTION);

										// Icon action?
										if (msg_copy.Code==MODE_ACTION)
											pos->flags|=POSITIONF_ICON|POSITIONF_ICON_ACTION;

										// Icon?
										else
										if (msg_copy.Code==MODE_ICON)
											pos->flags|=POSITIONF_ICON;
									}

									// No lister
									else pos->flags&=~POSITIONF_OPEN_NEW;
								}
								break;


							// Remove
							case GAD_PATHFORMAT_REMOVE:
								config_paths_remove(data,TRUE);
								break;


							// Edit
							case GAD_PATHFORMAT_EDIT:
								config_paths_edit(data);
								break;
						}
						break;


					// Key press
					case IDCMP_RAWKEY:

						// Help?
						if (msg_copy.Code==0x5f &&
							!(msg_copy.Qualifier&VALID_QUALIFIERS))
						{
							// Valid main IPC?
							if (main_ipc)
							{
								// Set busy pointer
								SetWindowBusy(data->window);

								// Send help request
								IPC_Command(main_ipc,IPC_HELP,(1<<31),"Paths",0,(struct MsgPort *)-1);

								// Clear busy pointer
								ClearWindowBusy(data->window);
							}
						}
						break;
				}

				// Check quit flag
				if (quit_flag) break;
			}
		}

		// Check quit flag
		if (quit_flag) break;

		// App messages?
		if (data->appport)
		{
			struct AppMessage *msg;

			// Get messages
			while ((msg=(struct AppMessage *)GetMsg(data->appport)))
			{
				// Get first argument
				if (msg->am_NumArgs>0)
				{
					// Is it a directory?
					if (!msg->am_ArgList[0].wa_Name || !*msg->am_ArgList[0].wa_Name)
					{
						char buf[256];

						// Expand path name	
						if (NameFromLock(msg->am_ArgList[0].wa_Lock,buf,256))
						{
							Att_Node *node;

							// Fix trailing /
							AddPart(buf,"",256);

							// Check it's not already in the list
							if (!(node=(Att_Node *)FindNameI((struct List *)data->path_list,buf)))
							{
								// Add a new entry
								config_paths_add(data,FALSE);

								// Copy path to path field
								SetGadgetValue(data->objlist,GAD_PATHFORMAT_PATH,(ULONG)buf);

								// Accept the new path
								config_paths_change(data);
							}

							// It is, select this entry
							else config_paths_select(data,node,FALSE);
						}
					}
				}

				// Reply message
				ReplyMsg((struct Message *)msg);
			}
		}

		// Wait for input
		Wait(
			((data->window)?(1<<data->window->UserPort->mp_SigBit):0)|
			((data->appport)?(1<<data->appport->mp_SigBit):0)|
			1<<ipc->command_port->mp_SigBit);
	}

	// Free stuff
	config_paths_cleanup(data);
	return success;
}
Esempio n. 25
0
// Display a buffer in a lister
// Called from LISTER PROCESS
void lister_show_buffer(Lister *lister,DirBuffer *buffer,int show,BOOL active)
{
	// Different to current buffer?
	if (lister->cur_buffer!=buffer)
	{
		// End a direct edit
		lister_end_edit(lister,0);

		// Clear lock pointer in current buffer
		buffer_clear_lock(lister->cur_buffer,0);

		// Free icons
		backdrop_free_list(lister->backdrop_info);

		// Store new buffer pointer
		lister->cur_buffer=buffer;
		buffer->buf_CurrentLister=lister;

		// Remove buffer and add to head of list
		Remove(&buffer->node);
		AddHead(&GUI->buffer_list.list,&buffer->node);

		// See if buffer needs to be resorted
		lister_resort(lister,0);

		// Clear save status flag
		lister->flags&=~LISTERF_SAVE_STATUS;

		// Does new buffer have a custom handler?
		if (lister->cur_buffer->buf_CustomHandler[0] && active)
		{
			// Send active message
			buffer_active(lister->cur_buffer,0);
		}

		// Add to history list
		lister_add_history(lister);
	}

	// Initialise path field
	if (show && lister_valid_window(lister))
	{
		// Is volume present?
		if (!lister->cur_buffer->buf_CustomHandler[0] &&
			VolumePresent(buffer))
		{
			BPTR lock;
			struct FileInfoBlock __aligned fib;

			// Lock path
			if (lock=Lock(buffer->buf_Path,ACCESS_READ))
			{
				// Store full path
				NameFromLock(lock,buffer->buf_ExpandedPath,512);
				AddPart(buffer->buf_ExpandedPath,"",512);

				// Examine object
				Examine(lock,&fib);
				UnLock(lock);

				// Save object name
				if (fib.fib_FileName[0])
					strcpy(buffer->buf_ObjectName,fib.fib_FileName);
				else
				{
					if (buffer->flags&DWF_ROOT)
					{
						char *ptr;

						stccpy(buffer->buf_ObjectName,buffer->buf_ExpandedPath,GUI->def_filename_length-1);
						if (ptr=strchr(buffer->buf_ObjectName,':')) *ptr=0;
					}
					else stccpy(buffer->buf_ObjectName,FilePart(buffer->buf_ExpandedPath),GUI->def_filename_length-1);
				}
			}

			// Failed to lock
			else strcpy(buffer->buf_ExpandedPath,buffer->buf_Path);

			// Update disk name and size
			lister_update_name(lister);
		}

		// No, refresh disk name from buffer
		else lister_show_name(lister);

		// Not showing icons?
		if (!(lister->flags&LISTERF_VIEW_ICONS) || lister->flags&LISTERF_ICON_ACTION)
		{
			// Update path field
			lister_update_pathfield(lister);

			// Refresh window
			lister_refresh_display(lister,REFRESHF_SLIDERS|REFRESHF_STATUS|REFRESHF_CLEAR_ICONS);

			// Show selection information
			select_show_info(lister,1);
		}
	}
}
Esempio n. 26
0
void FiletypeEditor(void)
{
	filetype_ed_data *data=0;
	IPCData *ipc;
	short success=0,pending_quit=0;
	BOOL change_flag=0;

	// Do startup
	if (!(ipc=Local_IPC_ProcStartup((ULONG *)&data, (APTR)&_filetypeed_init)))
		return;

	// Create App stuff
	if ((data->app_port=CreateMsgPort()))
	{
		data->app_window=AddAppWindowA(0,0,data->window,data->app_port,0);
	}

	// Get icon image
	if (data->type->icon_path)
	{
#ifdef USE_DRAWICONSTATE
		{
			char *path_copy;
			data->icon_image=NULL;
			if ((path_copy=AllocMemH(0,strlen(data->type->icon_path)+1)))
			{
				// icon_path is guaranteed to have a .info at the end
				stccpy(path_copy,data->type->icon_path,strlen(data->type->icon_path)-4);
				data->icon_image=GetCachedDiskObject(path_copy,0);
				FreeMemH(path_copy);
			}
		}
#else
		data->icon_image=OpenImage(data->type->icon_path,0);
#endif
		// Show icon image
		filetypeed_show_icon(data);
	}

	// Launch class editor immediately?
	if (data->edit_flag) filetypeed_edit_definition(data);

	// Message loop
	FOREVER
	{
		IPCMessage *msg;
		struct IntuiMessage *imsg;
		short break_flag=0;

		// Check drag
		if (config_drag_check(&data->drag))
		{
			// End drag
			filetypeed_end_drag(data,0);
		}

		// Task message?
		while ((msg=(IPCMessage *)GetMsg(ipc->command_port)))
		{
			switch (msg->command)
			{
				// Close message?
				case IPC_QUIT:
					if (!pending_quit)
					{
						success=msg->flags;
						break_flag=1;
					}
					break;


				// Activate
				case IPC_ACTIVATE:
					if (data->window)
					{
						WindowToFront(data->window);
						ActivateWindow(data->window);
					}
					break;


				// Editor saying goodbye
				case IPC_GOODBYE:
					{
						ULONG which;

						// What's just gone?
						which=IPC_GetGoodbye(msg);

						// Class editor?
						if (which==(ULONG)-1) data->class_editor=0;

						// Icon menu editor?
						else
						if (which>15)
						{
							Att_Node *node;

							// Go through icon list
							for (node=(Att_Node *)data->icon_list->list.lh_Head;
								node->node.ln_Succ;
								node=(Att_Node *)node->node.ln_Succ)
							{
								// Match function
								if (((func_node *)node->data)->func==(Cfg_Function *)which)
								{
									// Clear editor pointer
									((func_node *)node->data)->editor=0;

									// Check for invalid function
									if (filetypeed_check_iconmenu(data,node,FALSE))
										change_flag=1;
									break;
								}
							}
						}

						// Normal filetype editor
						else data->editor[which]=0;
					}
					break;


				// Editor returning a function
				case FUNCTIONEDIT_RETURN:
					{
						short ret;

						if ((ret=filetypeed_receive_edit(
							data,
							(FunctionReturn *)msg->data)))
						{
							change_flag=1;
							filetypeed_update_actions(data);
							if (ret==2) filetypeed_update_iconmenu(data);
						}
					}
					break;


				// Class editor returning
				case CLASSEDIT_RETURN:
					filetypeed_receive_class(data,(Cfg_Filetype *)msg->data);
					change_flag=1;
					break;


				// Get a copy of a button
				case BUTTONEDIT_CLIP_BUTTON:

					// Handle this button
					if (filetypeed_get_button(data,(Cfg_Button *)msg->data,(Point *)msg->data_free))
						change_flag=1;
					break;
			}

			// Reply the message
			IPC_Reply(msg);
		}

		// Intuimessage
		if (data->window)
		{
			while ((imsg=GetWindowMsg(data->window->UserPort)))
			{
				struct IntuiMessage msg_copy;
				struct Gadget *gadget;
				struct TagItem *tags;

				// Copy message
				msg_copy=*imsg;

				// Don't reply to IDCMPUPDATE messages just yet
				if (imsg->Class!=IDCMP_IDCMPUPDATE)
				{
					ReplyWindowMsg(imsg);
					imsg=0;
				}

				// Get gadget and tag pointers
				gadget=(struct Gadget *)msg_copy.IAddress;
				tags=(struct TagItem *)gadget;

				// Look at message
				switch (msg_copy.Class)
				{
					// Close window
					case IDCMP_CLOSEWINDOW:
						if (!pending_quit) break_flag=1;
						break;


					// Gadget
					case IDCMP_GADGETUP:
						switch (gadget->GadgetID)
						{
							// Use
							case GAD_FILETYPEED_USE:
								success=1;

							// Cancel
							case GAD_FILETYPEED_CANCEL:
								if (!pending_quit) break_flag=1;
								break;


							// Select a function
							case GAD_FILETYPEED_ACTION_LIST:
								{
									Att_Node *node;

									// Get selected node
									if (!(node=Att_FindNode(data->action_list,msg_copy.Code)))
										break;

									// Enable edit action button
									DisableObject(data->objlist,GAD_FILETYPES_EDIT_ACTION,FALSE);

									// Double-click?
									if (!(DoubleClick(data->last_sec,data->last_mic,msg_copy.Seconds,msg_copy.Micros)) ||
										node!=data->last_sel)
									{
										data->last_sec=msg_copy.Seconds;
										data->last_mic=msg_copy.Micros;
										data->last_sel=node;
										data->last_icon=0;
										break;
									}
								}

								// Fall through

							case GAD_FILETYPES_EDIT_ACTION:

								// No current selection?
								if (!data->last_sel) break;

								// Is editor already up for this action?	
								if (data->editor[data->last_sel->data])
									IPC_Command(data->editor[data->last_sel->data],IPC_ACTIVATE,0,0,0,0);

								// Need to launch editor
								else filetypeed_edit_action(data,data->last_sel->data,data->last_sel->node.ln_Name);
								break;


							// Delete action
							case GAD_FILETYPES_DEL_ACTION:

								// No current selection?
								if (!data->last_sel) break;

								// Is editor up for this action?	
								if (data->editor[data->last_sel->data])
									IPC_Command(data->editor[data->last_sel->data],IPC_QUIT,0,0,0,0);

								// Delete it
								if (filetypeed_del_action(data,data->last_sel->data))
									change_flag=1;
								break;


							// Edit filetype definition
							case GAD_FILETYPEED_EDIT_CLASS:

								// Is class editor already up for this action?	
								if (data->class_editor)
									IPC_Command(data->class_editor,IPC_ACTIVATE,0,0,0,0);

								// Need to launch editor
								else filetypeed_edit_definition(data);
								break;


							// Select icon
							case GAD_FILETYPEED_SELECT_ICON:
								if (filetypeed_pick_icon(data))
									change_flag=1;
								break;


							// Add to icon menu
							case GAD_FILETYPES_ADD_ICON_MENU:
								filetypeed_add_iconmenu(data);
								break;


							// Select an icon menu
							case GAD_FILETYPES_ICON_MENU:
								{
									Att_Node *last=data->last_icon;

									// Handle selection
									if (!(filetypeed_sel_icon(data,msg_copy.Code))) break;

									// Double-click?
									if (data->last_icon!=last ||
										!(DoubleClick(
											data->last_sec,
											data->last_mic,
											msg_copy.Seconds,
											msg_copy.Micros)))
									{
										data->last_sec=msg_copy.Seconds;
										data->last_mic=msg_copy.Micros;
										data->last_sel=0;
										break;
									}
								}

								// Fall through

							case GAD_FILETYPES_EDIT_ICON_MENU:

								// No current selection?
								if (!data->last_icon) break;

								// Edit it
								filetypeed_edit_iconmenu(data,data->last_icon);
								break;


							// Delete from icon menu
							case GAD_FILETYPES_DEL_ICON_MENU:

								// No current selection?
								if (!data->last_icon) break;

								// Delete function
								if (filetypeed_check_iconmenu(data,data->last_icon,TRUE))
									change_flag=1;
								break;
						}
						break;


					// BOOPSI message
					case IDCMP_IDCMPUPDATE:
						{
							short item;

							// Icon list?
							if (GetTagData(GA_ID,0,tags)!=GAD_FILETYPES_ICON_MENU) break;

							// Get item
							if ((item=GetTagData(DLV_DragNotify,-1,tags))!=-1)
							{
								// Handle selection
								filetypeed_sel_icon(data,item);

								// Start the drag
								config_drag_start(&data->drag,data->icon_list,item,tags,TRUE);
							}
						}
						break;


					// Ticks
					case IDCMP_INTUITICKS:
						++data->drag.tick_count;
						break;


					// Mouse move
					case IDCMP_MOUSEMOVE:

						// Handle drag move
						config_drag_move(&data->drag);
						break;


					// Mouse buttons
					case IDCMP_MOUSEBUTTONS:

						// Valid drag info?
						if (data->drag.drag)
						{
							short ok=-1;

							// Dropped ok?
							if (msg_copy.Code==SELECTUP)
							{
								// Remember last position
								data->drag.drag_x=data->window->WScreen->MouseX;
								data->drag.drag_y=data->window->WScreen->MouseY;
								ok=1;
							}

							// Aborted
							else
							if (msg_copy.Code==MENUDOWN) ok=0;

							// End drag?
							if (ok!=-1 && filetypeed_end_drag(data,ok)) change_flag=1;
						}
						break;


					// Key press
					case IDCMP_RAWKEY:

						// Help?
						if (msg_copy.Code==0x5f &&
							!(msg_copy.Qualifier&VALID_QUALIFIERS))
						{
							// Set busy pointer
							SetWindowBusy(data->window);

							// Send help command
							IPC_Command(data->func_startup.main_owner,IPC_HELP,(1<<31),"File Type Editor",0,REPLY_NO_PORT);

							// Clear busy pointer
							ClearWindowBusy(data->window);
						}
						break;
				}

				// Reply to outstanding messages
				if (imsg) ReplyWindowMsg(imsg);
			}

			// Check break flag
			if (break_flag || pending_quit)
			{
				// See if all the editors are gone
				if (IsListEmpty(&data->proc_list.list))
					break;

				// Send quit?
				if (break_flag)
				{
					IPC_ListQuit(&data->proc_list,0,success,FALSE);
					SetWindowBusy(data->window);
				}
				pending_quit=1;
			}
		}

		// AppMessage
		if (data->app_window)
		{
			struct AppMessage *msg;

			while ((msg=(struct AppMessage *)GetMsg(data->app_port)))
			{
				// Got an argument?
				if (msg->am_NumArgs>0)
				{
					char name[256];
					short len;
					APTR image;

					// Get full name
					NameFromLock(msg->am_ArgList[0].wa_Lock,name,256);
					if (msg->am_ArgList[0].wa_Name &&
						*msg->am_ArgList[0].wa_Name)
						AddPart(name,msg->am_ArgList[0].wa_Name,256);

					// Add .info
					if ((len=strlen(name))<6 ||
						stricmp(name+len-5,".info")!=0) strcat(name,".info");

					// Try to get image
#ifdef USE_DRAWICONSTATE
					{
						char *path_copy;
						image=NULL;
						if ((path_copy=AllocMemH(0,strlen(name)+1)))
						{
							// icon_path is guaranteed to have a .info at the end
							stccpy(path_copy,name,strlen(name)-4);
							image=GetCachedDiskObject(path_copy,0);
							FreeMemH(path_copy);
						}
					}
#else
					image=OpenImage(name,0);
#endif

					if (image)
					{
						// Store path
						FreeMemH(data->type->icon_path);
						if ((data->type->icon_path=AllocMemH(0,strlen(name)+1)))
							strcpy(data->type->icon_path,name);

						// Free existing image
#ifdef USE_DRAWICONSTATE
						FreeCachedDiskObject(data->icon_image);
#else
						CloseImage(data->icon_image);
#endif
						data->icon_image=image;

						// Show new image
						filetypeed_show_icon(data);
						change_flag=1;
					}
				}

				// Reply message
				ReplyMsg((struct Message *)msg);
			}
		}

		Wait(1<<ipc->command_port->mp_SigBit|
			1<<data->drag.timer->port->mp_SigBit|
			((data->window)?(1<<data->window->UserPort->mp_SigBit):0)|
			((data->app_window)?(1<<data->app_port->mp_SigBit):0));
	}

	// End any drag in progress
	filetypeed_end_drag(data,0);

	// Need to send button back?
	if (success==1 && change_flag)
	{
		if (IPC_Command(
			data->owner_ipc,
			FILETYPEEDIT_RETURN,
			(ULONG)data->type,
			data->node,
			0,
			REPLY_NO_PORT))
		{
			data->node=0;
		}
	}

	// Free edit filetype
	FreeFiletype(data->type);

	// Remove AppWindow
	RemoveAppWindow(data->app_window);

	// Close window
	CloseConfigWindow(data->window);

	// Close app port
	if (data->app_port)
	{
		struct Message *msg;
		while ((msg=GetMsg(data->app_port)))
			ReplyMsg(msg);
		DeleteMsgPort(data->app_port);
	}

	// Say goodbye
	IPC_Goodbye(ipc,data->owner_ipc,(success==-1)?0:(ULONG)data->node);

	// Free icon image
#ifdef USE_DRAWICONSTATE
	FreeCachedDiskObject(data->icon_image);
#else
	CloseImage(data->icon_image);
#endif

	// Close timer
	FreeTimer(data->drag.timer);

	// Free data
	IPC_Free(ipc);
	Att_RemList(data->action_list,0);
	Att_RemList(data->icon_list,REMLIST_FREEDATA);
	FreeVec(data);
}
Esempio n. 27
0
//***********************************************************************
//* Procedure: full_path
//* Synopsis:  path = full_path(name)
//* Purpose:   Constructs a fully expanded filename
//*            Note, we can not assume that the file exists, so it will
//*            not be possible to actually lock it.  We can assume that
//*            the directory it is part of does exist.  Note that it can
//*            return NULL if there is no memory available.
//***********************************************************************
char *full_path(char *name)
{
   BPTR lock;
   __aligned struct FileInfoBlock fib;
   char *tail, *p;
   int pos;

   //
   // Step 1 - split out any directory information from the actual name
   //
   p = strrchr(name, '/');
   if (p == NULL) p = strrchr(name, ':');
   if (p != NULL)
   {
      //
      // There was some directory information involved
      //
      char c;
      tail = strdup(p+1);
      c = p[1];
      p[1] = 0;
      lock = Lock(name, SHARED_LOCK);
      p[1] = c;
   }
   else
   {
      //
      // No directory information involved, just the name relative to the
      // current directory
      //
      lock = Lock("", SHARED_LOCK);
      tail = strdup(name);
   }

   //
   // Step 2 - we have the lock on the directory and the tail part of the name
   // We want to construct a fully qualified path for the directory.
   // If for some reason the lock on the directory returned 0, we want to just
   // return the name they gave us to begin with.
   //
   if (lock == 0)
   {
      free(tail);
      return(strdup(name));
   }

   //
   // Step 3 - Fully qualify the directory portion into the buffer
   //
   if (DOSBase->dl_lib.lib_Version >= 36)
   {
      if (!NameFromLock(lock, buf, MAX_FILENAME))
      {
         //
         // Either the name is too long or there was something else wrong with
         // the file name, just return what they gave us as a start
         //
         UnLock(lock);
         free(tail);
         return(strdup(name));
      }
      UnLock(lock);
      pos = 0;
   }
   else
   {
      // Running under 1.3, we have to do this the old fashion way

      //
      // Just so we don't have to do any inserts/extra copies, we will work
      // from the end of the buffer and insert as we go
      //
      pos = MAX_FILENAME-1;  // Leave room for a '/' on the end sometimes
      buf[--pos] = 0;
      while(lock != 0)
      {
         BPTR parent;
         int len;

         //
         // Examine the lock to get the name for it
         //
         Examine(lock, &fib);

         //
         // Find the parent of this directory
         //
         parent = ParentDir(lock);
         UnLock(lock);
         lock = parent;

         len = strlen(fib.fib_FileName);
         pos -= 1;

         if (len > pos)
         {
            //
            // oops, not enough room, just return the name they gave us
            //
            UnLock(lock);
            free(tail);
            return(strdup(name));
         }
         buf[pos] = lock ? ':' : '/';
         pos -= len;
         memcpy(buf+pos, fib.fib_FileName, len);
      }
   }

   //
   // We have the path part in the buffer and the name part in the tail
   // All that is left is to concatenate them together correctly
   //
   {
      int len;

      //
      // Successful, the buf holds the path for the directory.  We will need
      // to add a / to the end if it doesn't end in a colon
      //
      len = strlen(buf+pos);
      if ((buf[pos+len-1] != ':') && (buf[pos+len-1] != '/'))
      {
         buf[pos+len++] = '/';
         buf[pos+len] = 0;
      }
      name = malloc(len+strlen(tail)+1);
      if (name != NULL)
      {
         strcpy(name, buf+pos);
         strcpy(name+len, tail);
      }
   }
   return(name);
}