English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 11 April 2010, 07:25   #1
zoneuser
 
Posts: n/a
Expanding command line wildcards and Icon Drag and Drop

Wildcard Expansion:
How do you handle command line wildcards such as #? when writing a command line tool in C. I want my tool to take action on all files passed by the command line; ie: tool.exe #?

Icon Drag and Drop
How do I write code to handle files dragged onto my tool's icon. For example, when I drag a file(s) from workbench onto my tools icon I want to know how to get the dragged icon's filename(s).

I'm using SAS/C.

Any help/code examples would be appreciated.
 
Old 11 April 2010, 10:29   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,024
Quote:
How do you handle command line wildcards such as #? when writing a command line tool in C.
See ParsePattern/NoCase and MatchPattern/NoCase in dos.library. In 1.3 and below you can use arp.library for that.

Quote:
How do I write code to handle files dragged onto my tool's icon.
See AddAppIcon/AddAppWindow/AddAppMenu in workbench.library. In 1.3 and below there is no way to do this.


Come back when you've read the autodocs and still are suck.
thomas is offline  
Old 13 April 2010, 09:05   #3
zoneuser
 
Posts: n/a
I've got the argument handling finished. Now I'm trying to do some directory recursion using exnext.

I can't seem to get it right. Does anyone have some sample code for traversing directory trees recursively?
 
Old 13 April 2010, 10:47   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,024
Code:
#include <proto/dos.h>

char indent[] = "                                                                                ";


BOOL read_dir (ULONG level,char *path,BOOL recursive)

{
BOOL success = FALSE;
BPTR lock;
struct FileInfoBlock *fib;
BPTR oldcd;

if (fib = AllocDosObject (DOS_FIB,TAG_END))
	{
	if (lock = Lock (path,SHARED_LOCK))
		{
		if (Examine (lock,fib))	
			{
			success = TRUE;

			if (fib->fib_DirEntryType > 0)
				{
				if (level == 0)
					Printf ("Contents of directory %s\n",fib->fib_FileName);

				oldcd = CurrentDir (lock);
				while (ExNext (lock,fib))
					{
					if (fib->fib_DirEntryType > 0)
						{
						Printf ("%s   (Dir) %s\n",&indent[80-2*level],fib->fib_FileName);
						if (recursive)
							read_dir (level+1,fib->fib_FileName,recursive);
						}
					else
						Printf ("%s%8lu %s\n",&indent[80-2*level],fib->fib_Size,fib->fib_FileName);
					}
				CurrentDir (oldcd);
				}
			else
				Printf ("%s%8lu %s\n",&indent[80-2*level],fib->fib_Size,fib->fib_FileName);
			}

		UnLock (lock);
		}
	FreeDosObject (DOS_FIB,fib);
	}

return (success);
}



int main (void)

{
struct RDArgs *rdargs;
struct {
	char *path;
	long all;
	} args = {"",0};
int rc;

rdargs = ReadArgs ("PATH,ALL/S",(LONG *)&args,NULL);
if (!rdargs)
	{
	PrintFault (IoErr(),"error in arguments");
	return (RETURN_ERROR);
	}

rc = RETURN_FAIL;

if (read_dir (0,args.path,args.all))
	rc = RETURN_OK;

FreeArgs (rdargs);

return (rc);
}
thomas is offline  
Old 13 April 2010, 15:17   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,024
By the way, as you were asking about wildcards before, you probably want to combine directory reading with wildcard resolution. For this the examine/exnext approach with manual recursion is not the best idea. You'd better use MatchFirst/MatchNext/MatchEnd. This works similar to the List shell command.

Here is an example. It's basically the example from the OS 4.0 SDK, adjusted for OS 3.x:

Code:
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/dostags.h>
#include <dos/dosasl.h>


int main (void)

{
struct RDArgs *rdargs;
struct {
	char *path;
	long all;
	} args = {"",0};
struct AnchorPath *ap;
LONG error;
LONG level,i;

rdargs = ReadArgs ("PATH,ALL/S",(LONG *)&args,NULL);
if (!rdargs)
	{
	PrintFault (IoErr(),NULL);
	return (RETURN_FAIL);
	}

if (ap = AllocVec (sizeof(struct AnchorPath) + 1024,MEMF_CLEAR))
	{
	ap->ap_BreakBits = SIGBREAKF_CTRL_C;
	ap->ap_Strlen = 1024;
	}

level = 0;

error = MatchFirst (args.path,ap);
if (error == 0 && ap->ap_Info.fib_DirEntryType >= 0)
	ap->ap_Flags |= APF_DODIR;

while (error == 0)
	{
	if (ap->ap_Flags & APF_DIDDIR)
		{
		/* Leaving a directory entered below (APF_DODIR) */
		level--;
		ap->ap_Flags &= ~APF_DIDDIR;
		}
	else
		{
		/* Soft linked objects are returned by the scanner
		   but they need special treatment; we are merely
		   ignoring them here in order to keep this
		   example simple */
		if (ap->ap_Info.fib_DirEntryType != ST_SOFTLINK)
			{
			/* Provide for some indentation */
			for (i = 0 ; i < level ; i++)
				Printf (" ",0);

			Printf ("%s%s\n",ap->ap_Buf,
				(ap->ap_Info.fib_DirEntryType < 0) ? "" : " (Dir)");

			/* If this is a directory, enter it */
			if (ap->ap_Info.fib_DirEntryType >= 0 && args.all)
				{
				ap->ap_Flags |= APF_DODIR;
				level++;
				}
			}
		}

	error = MatchNext (ap);
	}

MatchEnd (ap);

FreeVec (ap);

FreeArgs (rdargs);

return (RETURN_OK);
}
thomas is offline  
Old 13 April 2010, 19:35   #6
zoneuser
 
Posts: n/a
Thank you so much!

Do you know of any good websites with examples for Amiga coding?
 
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adf Drag and Drop and association problem? kern support.WinUAE 5 17 September 2012 17:37
Drag and drop opening of adf files? zardoz support.OtherUAE 3 08 May 2012 23:19
Problems on an A3000 (Drag-and-Drop & palettes broken) BuddhaPhi project.ClassicWB 1 01 March 2012 00:46
Drag and Drop HDF mounting? killergorilla request.UAE Wishlist 5 02 July 2008 12:12
Odd request - ADFs drag and drop BippyM request.UAE Wishlist 9 23 April 2006 00:36

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:42.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08202 seconds with 13 queries