English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 04 July 2017, 12:47   #1
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Help please strugglng to get multiple options out of ReadArgs

Hi,

Can someone explain how I get the values out from a multiple value in a ReadArgs template?

say I have this

Code:
args=ReadArgs("DIR/M,HELP/S,WINDOW/S",params,NULL);
The only info I can find on reading multiple argument, like the DIR above is here - http://wiki.amigaos.net/wiki/Basic_I...d_Line_Parsing

And it is for OS4 (as a lot of info is now). The www.pjhutchison.org/tutorial/amiga_c.html (which is a great resource) only has an example for single arguments. The wiki states -

Quote:
/M - Multiple This means the option will take any number of arguments, returning them as an array of pointers. Any arguments not considered to be part of another option will be added to this option. Only one /M should appear in a template. Example: for a template "Dir/M,All/S" the command line "foo bar all qwe" will set the boolean "all", and return an array consisting of "foo", "bar" and "qwe". The entry in the array will be a pointer to an array of string pointers, the last of which will be NULL.
And I am sorry to say that the last line has me confused. I get that params[0] will be a pointer to an array of char arrays. But have no idea how to reference those char arrays.

Can someone post or point me at a code segment to read a multiple argument from ReadArgs?

While I'm about it can I use ReadArgs to see if an app has been started from the shell or Workbench? My app can run without any arguments as these act as filters reducing the output.

Thanks in advance.
chocsplease is offline  
Old 04 July 2017, 14:04   #2
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,679
Are you sure you need the /M option?
idrougge is offline  
Old 04 July 2017, 14:13   #3
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Thanks for the reply..

Quote:
Originally Posted by idrougge View Post
Are you sure you need the /M option?
Erm yes, otherwise I would not have asked
chocsplease is offline  
Old 04 July 2017, 15:04   #4
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,201
params[0][0]
,
params[0][1]
etc. will be the arguments, terminated by a NULL. If you use the
main(int nargs, char** pargs)
prototype, then if nargs is 0, you have been started from Workbench.
Leffmann is offline  
Old 04 July 2017, 15:18   #5
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
Part of my ancient code for argument parsing, asm but should be clear enough (hopefully..):
Code:
	move.l	#ArgTemplate,d1
	move.l	#ArgArray,d2
	moveq	#0,d3
	jsr	_LVOReadArgs(a6)	; dos
...

	lea	ArgArray,a4
	move.l	(a4)+,d0
	beq.b	Printed
	move.l	d0,a4
PrintFiles
	move.l	(a4)+,d0
	beq.b	Printed
	lea	FormatArgs,a0
	move.l	d0,(a0)
	move.l	#StringNL,d1
	move.l	a0,d2
	jsr	_LVOVPrintf(a6)		; dos
	bra.b	PrintFiles
Printed


; defaults:
First		DC.L	500

ArgTemplate	DC.B	"FILES/M,F=FIRST/N,S=SECOND/S",0
ArgArray	DC.L	0,First,0

FormatArgs	DC.L	0,0
StringNL		DC.B	"%s",10,0
a/b is offline  
Old 04 July 2017, 15:46   #6
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
OK, managed to dig out c code as well. Don't guarantee it works, it's just some test stuff (I could only find number/string/bool parameters in my 'serious' code).

Code:
STRPTR 	template = "FILES/M";
struct RDArgs*	p_args;
STRPTR		str_args[2];

memset(str_args,0,sizeof(str_args));
p_args = ReadArgs(template,(LONG*) str_args,NULL); // check result
STRPTR* p_file = (STRPTR*) p_args[0];
while(*p_file) {
	Printf("%s\n",*p_file);
	++p_file;
	}
a/b is offline  
Old 06 July 2017, 14:15   #7
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Many thanks for all your replies

Quote:
Originally Posted by Leffmann View Post
params[0][0]
,
params[0][1]
etc. will be the arguments, terminated by a NULL. If you use the
main(int nargs, char** pargs)
prototype, then if nargs is 0, you have been started from Workbench.
I have, I think, tried this - here is my code:

Code:
     
/*for readArgs*/

    struct RDArgs *Args;
    long clparams[8]={0};     
     char out[100];

/*get args if any from command line*/

        Args= ReadArgs(messages[23],clparams, NULL);
        
        if (Args)    /*entered something*/
        {
            if ((STRPTR)clparams[0][0]!= NULL)  /*<<<*/
            {
                i=0;
                while ((STRPTR)clparams[0][i]!=NULL) /*<<<*/
                {    
                    sprintf(out," DEVICES %d\n", (STRPTR)clparams[0][i]); /*<<<*/
                    PutStr(out);
                    i++;
                }
            }
        
/*            if (clparams[3] && clparams[4]) DO SOMETHING! cant have colours and no colours speced!*/
Unfortunately I'm getting an error on each of the lines I have marked with <<< that states 'subscripted value is neither array nor pointer'

I don't really understand this error, but suspect its due to the way I have defined clparams as a single dimension long.

Quote:
Originally Posted by a/b View Post
OK, managed to dig out c code as well. Don't guarantee it works, it's just some test stuff (I could only find number/string/bool parameters in my 'serious' code).

Code:
STRPTR     template = "FILES/M";
struct RDArgs*    p_args;
STRPTR        str_args[2];

memset(str_args,0,sizeof(str_args));
p_args = ReadArgs(template,(LONG*) str_args,NULL); // check result
STRPTR* p_file = (STRPTR*) p_args[0];
while(*p_file) {
    Printf("%s\n",*p_file);
    ++p_file;
    }
Thanks for the code example, I wish I was a better programmer as there is a lot I just can't figure out.

I get the definition of the template and p_args but not str_args.
I think that you clear str_args to 0 with the memset and then get the shell args.

Its from here on I'm lost.

What is p_file? is it being defined by the line - STRPTR* p_file = (STRPTR*) p_args[0]; ? Or is it defined elsewhere? I thought you had to define everything before code(?).

The while I assume runs until whatever p_file is pointing at is Null? But how does the increment work? Doesn't that just add 1 to the address the p_file is pointing at?

Sorry I am very confused..
chocsplease is offline  
Old 06 July 2017, 15:07   #8
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
p_args is an array of pointers, you take the first one (=> p_file).
That first pointer points to another array of (string) pointers, one for each argument you have supplied on command line.
So now you have p_file pointing to the first string pointer, if you dereference p_file with *p_file you get the actual string pointer. When you increase p_file you move on to the next string pointer, and you repeat that until p_file points to a null pointer indicating no more strings.

Using Leffmann's explanation, this is the condensed version of what I just typed:
for (int i = 0; *(p_args[0][i]) != NULL; ++i) {
Printf("%s\n",*(p_args[0][i])); }

EDIT: When you increment a pointer it's incremented not by 1 (byte) but for the size of the object it points to. So in this case it's 4 (bytes) since it points to a 32-bit pointer. String pointer is incremented by 1 since it points to a character (string = array of characters).

Last edited by a/b; 06 July 2017 at 15:16.
a/b is offline  
Old 06 July 2017, 18:00   #9
ross
Sum, ergo Cogito

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 1,366
Quote:
Originally Posted by a/b View Post
Part of my ancient code for argument parsing, asm but should be clear enough (hopefully..):
Hi a/b, I need something similar but parsing the same args also from Icon Tool Types array.

Is there something already written? (in asm..)

I can write myself but i'm lazy (and this stuff is boring)

ross
ross is offline  
Old 06 July 2017, 18:17   #10
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Huge thanks again

Quote:
Originally Posted by a/b View Post
p_args is an array of pointers, you take the first one (=> p_file).
That first pointer points to another array of (string) pointers, one for each argument you have supplied on command line.
So now you have p_file pointing to the first string pointer, if you dereference p_file with *p_file you get the actual string pointer. When you increase p_file you move on to the next string pointer, and you repeat that until p_file points to a null pointer indicating no more strings.

Using Leffmann's explanation, this is the condensed version of what I just typed:
for (int i = 0; *(p_args[0][i]) != NULL; ++i) {
Printf("%s\n",*(p_args[0][i])); }

EDIT: When you increment a pointer it's incremented not by 1 (byte) but for the size of the object it points to. So in this case it's 4 (bytes) since it points to a 32-bit pointer. String pointer is incremented by 1 since it points to a character (string = array of characters).
Sadly I am still getting that error when I compile - my code

Code:
struct RDArgs* Args;
    long clparams[8]={0};   
    STRPTR str_args[8];  
     char out[100];

Args= ReadArgs("DIR/M,HELP/S,WINDOW/S",clparams, NULL);
        
           
            i=0;
            while (*(Args[0][i]!=NULL))
            {    
                printf("DEVICES %s\n",*(Args[0][i]));
        
                i++;
            }
Do I need to use str_args as in your code? The while I have put together does not reference it and I'm sure (or maybe not) that its the same as the for loop you kindly posted.

The error occurs every time I reference Args (which I am using in place of your p_args) I'm using gcc does that have anything to do with it?
chocsplease is offline  
Old 06 July 2017, 21:05   #11
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 42
Posts: 3,085
Perhaps it's because ReadArgs() returns a structure: http://amigadev.elowar.com/read/ADCD.../node01A1.html

Or perhaps I'm missing something
Thorham is offline  
Old 06 July 2017, 21:18   #12
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
Try this:
Code:
#include <stdio.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <proto/dos.h>

int main()
{
struct RDArgs* Args;
LONG           clparams[3] = { 0, 0, 0 };
int            i = 0;

Args = ReadArgs("DIR/M,HELP/S,WINDOW/S",clparams,NULL);
if (Args == NULL)
	return -1;

if (clparams[0] != 0)
	while (((STRPTR*)clparams[0])[i] != 0)
		printf("DIR: %s\n",((STRPTR*)clparams[0])[i++]);

if (clparams[1] != 0)
	printf("HELP enabled\n");

if (clparams[2] != 0)
	printf("WINDOW enabled\n");

FreeArgs(Args);

return 0;
}

Last edited by a/b; 06 July 2017 at 21:58. Reason: printf() is hard
a/b is offline  
Old 06 July 2017, 21:42   #13
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
Quote:
Originally Posted by ross View Post
Hi a/b, I need something similar but parsing the same args also from Icon Tool Types array.

Is there something already written? (in asm..)

I can write myself but i'm lazy (and this stuff is boring)

ross
Yeah, this is part of my ancient (don't ask why or how, it works for me ) digiclock code. I can't post the entire source code because it's using round corners and I don't have a few billion spacebucks to spare.

a5 = (small) data segment
You'll have to open relevant libs, etc... Hopefully nothing important is missing.

Code:
GetToolTypes
	move.l	(Message-Data,a5),d0   ; from _LVOGetMsg() if WB, 0 if CLI
	beq.b	.FromCLI
	move.l	d0,a2
	move.l	(sm_ArgList,a2),a2
	move.l	(wa_Lock,a2),d1
	move.l	(DOSLib-Data,a5),a6
	jsr	(_LVOCurrentDir,a6)
.FromCLI
	move.l	d0,d4

	move.l	(IconLib-Data,a5),a6
	move.l	(NotifyName-Data,a5),a0  <= PROGRAM NAME (with accompanying .info)
	jsr	(_LVOGetDiskObject,a6)
	tst.l	d0
	beq.b	.NoInfo
	move.l	d0,a2

	lea	(Args-Data,a5),a3
	lea	(ArgOffsets-Data,a5),a4
	move.l	(DOSLib-Data,a5),d7
	moveq	#NUMNUMBERARGS-1,d3
	subq.l	#4,a7
	move.l	a7,d2
.HandleNumbers	move.l	(do_ToolTypes,a2),a0
	move.w	(a4)+,d0
	lea	(a5,d0.w),a1
	jsr	(_LVOFindToolType,a6)
	move.l	d0,d1
	beq.b	.NextNumber
	exg	d7,a6
	jsr	(_LVOStrToLong,a6)
	exg	d7,a6
	tst.l	d0
	ble.b	.NextNumber
	move.l	(a7),(a3)
.NextNumber	addq.l	#4,a3
	dbf	d3,.HandleNumbers
	addq.l	#4,a7

	moveq	#NUMSWITCHARGS-1,d3
.HandleSwitches	move.l	(do_ToolTypes,a2),a0
	move.w	(a4)+,d0
	lea	(a5,d0.w),a1
	jsr	(_LVOFindToolType,a6)
	tst.l	d0
	sne	(a3)+
	dbf	d3,.HandleSwitches

	move.l	a2,a0
	jsr	(_LVOFreeDiskObject,a6)

.NoInfo	move.l	d4,d1
	beq.b	.Quit
	move.l	(DOSLib-Data,a5),a6
	jsr	(_LVOCurrentDir,a6)
.Quit	rts

...
Data

ArgTT
.Left	DC.B	"LEFT",0
.Top	DC.B	"TOP",0
.Date	DC.B	"DATE",0
.Autofront	DC.B	"AUTOFRONT",0
.BattClock	DC.B	"BATTCLOCK",0
.TimeColor	DC.B	"TIMECOLOR",0
.DateColor	DC.B	"DATECOLOR",0
.TimeBack	DC.B	"TIMEBACKGROUND",0
.DateBack	DC.B	"DATEBACKGROUND",0
.Priority	DC.B	"CX_PRIORITY",0

ArgOffsets
.Numbers	DC.W	ArgTT\.Left-Data
	DC.W	ArgTT\.Top-Data
	DC.W	ArgTT\.TimeColor-Data
	DC.W	ArgTT\.DateColor-Data
	DC.W	ArgTT\.TimeBack-Data
	DC.W	ArgTT\.DateBack-Data
	DC.W	ArgTT\.Autofront-Data
	DC.W	ArgTT\.BattClock-Data
	DC.W	ArgTT\.Priority-Data
.NumbersEnd
.Switches	DC.W	ArgTT\.Date-Data
.SwitchesEnd

	ALIGN	0,4
Args
ArgsNumbers
Left	DC.L	640-WinWidth
Top	DC.L	16
TimeColor	DC.L	1
DateColor	DC.L	1
TimeBack	DC.L	4
DateBack	DC.L	0
Autofront	DC.L	30
BattClock	DC.L	30
Priority	DC.L	0
ArgsNumbersEnd
ArgsSwitches
Date	DC.B	0
ArgsSwitchesEnd

NUMNUMBERARGS		EQU	(ArgOffsets\.NumbersEnd-ArgOffsets\.Numbers)/2
NUMSWITCHARGS		EQU	(ArgOffsets\.SwitchesEnd-ArgOffsets\.Switches)/2
NUMARGS		EQU	NUMNUMBERARGS+NUMSWITCHARGS
a/b is offline  
Old 06 July 2017, 22:05   #14
ross
Sum, ergo Cogito

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 1,366
Quote:
Originally Posted by a/b View Post
Yeah, this is part of my ancient --cut---
I'll take a look and probably steal the code

Thanks!
ross
ross is offline  
Old 09 July 2017, 13:46   #15
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Many thanks again for the replies.

Quote:
Originally Posted by a/b View Post
Try this:
Code:
#include <stdio.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <proto/dos.h>

int main()
{
struct RDArgs* Args;
LONG           clparams[3] = { 0, 0, 0 };
int            i = 0;

Args = ReadArgs("DIR/M,HELP/S,WINDOW/S",clparams,NULL);
if (Args == NULL)
    return -1;

if (clparams[0] != 0)
    while (((STRPTR*)clparams[0])[i] != 0)
        printf("DIR: %s\n",((STRPTR*)clparams[0])[i++]);

if (clparams[1] != 0)
    printf("HELP enabled\n");

if (clparams[2] != 0)
    printf("WINDOW enabled\n");

FreeArgs(Args);

return 0;
}
A/B this is perfect! I would never have guessed that you had to cast only part of the array - ((STRPTR*)clparams[0])[i] !

Thank you!

Sadly I am now stuck trying to dig the device name out of DosList.

I can do it like this -

Code:
struct list_keeper 
{
    struct list_keeper *next;
    struct DosList dlist;
    struct InfoData infodat;
    struct drive_information drive_info;
};
.
.
.
in main()

struct list_keeper *dostemp;
struct DosList *llist;
char *ptr;   
char devname[ENVMAX];
.
.
while (llist = NextDosEntry(llist,LDF_DEVICES|LDF_READ))
.
.
dostemp = AllocVec(sizeof(struct list_keeper), MEMF_CLEAR|MEMF_ANY))
.
.
memcpy((char *)&dostemp->dlist, (char *)llist, sizeof(struct DosList));
.
.
ptr =(char *)BADDR(dostemp->dlist.dol_Name);
memcpy(devname, &ptr[1], (long)ptr[0]);
devname[ptr[0]]=NULL;
But this needs me to allocate memory in order to grab the device.

Is there any way of doing this without allocating the memory?

DosList is listed here in the autodocs - http://amigadev.elowar.com/read/ADCD.../node05D9.html

and here's the code to save folk hunting for it as it's a bit buried.

Code:
/* combined structure for devices, assigned directories, volumes */

struct DosList {
    BPTR        dol_Next;     /* bptr to next device on list */
    LONG        dol_Type;     /* see DLT below */
    struct MsgPort     *dol_Task;     /* ptr to handler task */
    BPTR        dol_Lock;
    union {
    struct {
    BSTR    dol_Handler;    /* file name to load if seglist is null */
    LONG    dol_StackSize;    /* stacksize to use when starting process */
    LONG    dol_Priority;    /* task priority when starting process */
    ULONG    dol_Startup;    /* startup msg: FileSysStartupMsg for disks */
    BPTR    dol_SegList;    /* already loaded code for new task */
    BPTR    dol_GlobVec;    /* BCPL global vector to use when starting
                 * a process. -1 indicates a C/Assembler
                 * program. */
    } dol_handler;

    struct {
    struct DateStamp    dol_VolumeDate;     /* creation date */
    BPTR            dol_LockList;     /* outstanding locks */
    LONG            dol_DiskType;     /* 'DOS', etc */
    } dol_volume;

    struct {
    UBYTE    *dol_AssignName;     /* name for non-or-late-binding assign */
    struct AssignList *dol_List; /* for multi-directory assigns (regular) */
    } dol_assign;

    } dol_misc;

    BSTR        dol_Name;     /* bptr to bcpl name */
    };
I hope someone can help, and as always many thanks in advance.
chocsplease is offline  
Old 09 July 2017, 18:34   #16
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 456
http://eab.abime.net/showpost.php?p=...6&postcount=16

last sentence.
alkis is offline  
Old 16 July 2017, 15:03   #17
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Thanks, I'd forgotten about that thread entirely. I just wish programming on the Amiga was a bit easier!

For example I am now getting a recoverable alert - 0100 000F if I enter args but not if I don't. It appears to be around the area where I start cleaning up (closing libs etc) but this is exactly the same code for both cases.

At present I have not idea why entering args is causing problems when I start closing my libs. It is not when I freeArgs, which was the first place I checked.

Any suggestions appreciated.
chocsplease is offline  
Old 16 July 2017, 15:36   #18
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 456
Showing the source code might get you a faster response.
alkis is offline  
Old 16 July 2017, 17:33   #19
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 168
Quote:
Originally Posted by alkis View Post
Showing the source code might get you a faster response.
Sorry I was trying to nail the line that was causing the problem.

I've now found them and its almost certainly because I still can't get my head around multiple arguments and am somehow overwriting a chunk of memory I should be leaving alone.

The code in question is below
Code:
Args= ReadArgs(messages[23],clparams, NULL);
        
        if (Args)    /*entered something*/
        {
        printf("entered args\n");
            if (clparams[0]!= NULL)
            {
            printf("entered device\n");
                i=0;
                while (((STRPTR*)clparams[0])[i]!=NULL)
                {
                    *ptr=((char)((STRPTR*)clparams[0])[i][0]); /*<<<<<*/
                    printf("LEN PTR==%ld\n",strlen(ptr));    
                    /*for(ii=0;ii<strlen(((STRPTR*)clparams[0])[i],i++);*/
                    
                    printf("DEVICES %s\n", ((STRPTR*)clparams[0])[i]);
                    printf("1st char= %c\n",((char)((STRPTR*)clparams[0])[i][0])); /*<<<<<<*/
                    
                    i++;
                }
            }            
        printf("OPTIONS STARTS AS %d\n",options);    
/*            if (clparams[3] && clparams[4]) DO SOMETHING! <<<<<< cant have colours and no colours speced!*/
        
            if ((clparams[3]) && ((options & NO_COLOURS) ==0)) options=options | NO_COLOURS;    /*if nocolours on cmd line and not in prefs file set*/
            
            if ((clparams[4]) && ((options & NO_COLOURS)> 0)) options=options - NO_COLOURS;        /*if colours on cmd line and nocolours in prefs file reset */

            if ((clparams[5]) && ((options & LEADING_SPACES) == 0)) options=options | LEADING_SPACES;    /*if want leading spaces and not in prefs file set*/
        
            if ((clparams[6]) && ((options & TRAILING_SPACES) == 0)) options=options | TRAILING_SPACES;    /*if want trail scs and not in prefs fileset*/
        
            if ((clparams[7]) && ((options & NORMAL_RAM) == 0)) options=options | NORMAL_RAM;         /*if want ram disk always 100% and not in prefs set*/
        
            if ((clparams[8]) && ((options & DEC_VALUES) == 0)) options=options | DEC_VALUES;            /*if want fake values for sizes and not in prefs set */
    
        
        }
My command line template (messages[23]) is
Code:
 DEVICE/M,HELP/S,WINDOW/S,NOCOLOURS/S,COLOURS/S,LEADINGSPACE/S,TRAILINGSPACE/S,NORMALAM/S,DECIMALSIZE/S
And the problem lines have been marked with <<<<

I suspect they are just garbage due to my lack of understanding.

What I am trying to do is get a pointer to point to the 1st character in the 1st argument of the multiple section so that I can then run through the string making everything upper case. The system returns devices in upper case so I need the cases to match.

If I comment out those two lines then I don't get the recoverable alert.
chocsplease is offline  
Old 16 July 2017, 21:16   #20
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 77
Code:
  *ptr=((char)((STRPTR*)clparams[0])[i][0]); /*<<<<<*/
  printf("LEN PTR==%ld\n",strlen(ptr));    
...
  printf("1st char= %c\n",((char)((STRPTR*)clparams[0])[i][0])); /*<<<<<<*/
That's not how you copy a string. First line only copies the first character and then you call strlen with a bogus string. And not knowing how ptr is declared, it maybe even causes a NULL/invalid pointer exception.
If you have a problem understanding what is going on, casting something to a different type is generally a bad idea. It will let you force something to a completely wrong type and then bad things happen. Instead, use an intermediate variable of the corrent type. If the compiler complains, think it over and try again. Something like...
Code:
  STRPTR p_tmp = ((STRPTR*)clparams[0])[i];  // or: char* p_tmp = ...
  strcpy(some_buffer,p_tmp);
  char first_char = *p_tmp;
  char first_char = p_tmp[0];
  char first_char = *(((STRPTR*)clparams[0])[i]);

  printf("LEN PTR==%ld\n",strlen(p_tmp));    
  printf("1st char= %c\n",*p_tmp);
  printf("1st char= %c\n",first_char);
  printf("1st char= %c\n",*(((STRPTR*)clparams[0])[i]));
The reason STRPTR* is needed is because clparams is declared as array of LONGs (as required by ReadArgs), and being polymorphic, it actually contains a STRPTR* and not a LONG in the case of /M.
That's also why you should compare clparams[X] with 0, and not NULL. Technically both are 0, but not of the same type (one is integer, the other is a pointer). Point being, c lets you get away with that but e.g. in c++ with stronger types and/or stricter compiler options you would get a warning/error. And when you don't have a complete control over pointer arithmetics and cast juggling, it spells trouble.

There are non-case sensitive string compare functions. stricmp or strcasecmp or probably something else, depends on platform/os/...

Also, don't do "messages[23]". Define constants or enums so you don't have to search through your code when you change them, something like:
Code:
#define MY_STR_ARGTEMPLATE 23
typedef enum { MY_STR_FIRST = 0, MY_STR_SECOND, .. MY_STR_ARGTEMPLATE, ... } MyStringsEnum;
a/b is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
ReadArgs implementation for kickstart 1.3 jotd Coders. Asm / Hardware 15 13 November 2017 07:09
multiple use of traps Galahad/FLT Coders. General 2 27 November 2014 11:53
Using ReadArgs() from asm oRBIT Coders. General 4 11 May 2010 17:11
multiple HDFs BippyM request.UAE Wishlist 1 25 September 2005 00:12
Multiple Harddrives Unknown_K support.Hardware 3 25 March 2005 13:28

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 20:38.


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