English Amiga Board Amiga Lore


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

 
 
Thread Tools
Old 17 July 2017, 12:42   #21
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 125
Hi a/b,

Many thanks for yet another extremely helpful and useful post.

Regarding the *ptr=((char)((STRPTR*)clparams[0])[i][0]); line.

I was trying to get the pointer to point *at* the 1st character. I thought if I could I could then run through the string simply incrementing the pointer till I hit a /0. However as you have pointed out I stuffed up badly when I tried to find the length of it using strlen since I'd just got the 1st char and not a pointer to it.

Think I understand what I've just typed...

Thank you for the info regarding casting and the code snippet I've copied it into my library as I'm sure it'll be useful later on.

Luckily I don't have to do any of this as my version of gcc includes a non ANSI strcasecmp (as well as strncasecmp) so thanks for pointing out their existence - my C book makes no mention of them. Could you suggest a good current one?

Oh I'm using messages in the code so the user can localise the template if they wish - messages is defined as -
Code:
static char *messages[]={MSG_READWRITE,MSG_NODISK,MSG_BADDISK,MSG_KICKSTART,MSG_NOT_DOS,MSG_READONLY,MSG_VALIDATING,\
MSG_MOUNTED,MSG_VOL_HEAD,"Unit","DOS","Size","Used","Free","Full","Errors","Status","Name","Amiga Disk","PC Disk",MSG_ERROR_MEM,MSG_BREAK,\
	MSG_ERROR_LIB,TEMPLATE};
TEMPLATE is #defined as I mentioned in the earlier post. I guess I could #define the whole lot, as it looks messy as it is, not sure if there is a recommended way of doing this. Also not sure if I need the static. The pointers get moved to point to localised text in a malloc'ed array if the user has defined them in a preferences file.

Once again massive thanks for all the help.
chocsplease is offline  
AdSense AdSense  
Old 17 July 2017, 19:37   #22
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 2,781
I can't remember ever seeing any localised command line arguments.
idrougge is offline  
Old 18 July 2017, 12:06   #23
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 125
Quote:
Originally Posted by idrougge View Post
I can't remember ever seeing any localised command line arguments.
Oh. I didn't know that! Having never used an Amiga in any language other than English I had assumed that commands etc would be in the native language. When I got a set of blank disks from the folks at Vesalia they were labelled leer (German for empty).

I guess that Commodore must have hard coded everything then? Even after they introduced the localisation system in whatever os version it was.

So much of the old OS info has been replaced by OS 4 specific stuff on the net its very hard to find the info you need.

Anyway my app does offer this and provided it works and I can nail a stupid crash I'm fairly near finishing thanks to all the help I have had from folks on this forum.
chocsplease is offline  
Old 18 July 2017, 13:30   #24
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 2,781
Indeed Workbench uses localised default names for formatted disks.
idrougge is offline  
Old 18 July 2017, 20:31   #25
nogginthenog
Amigan

 
Join Date: Feb 2012
Location: London
Posts: 418
Quote:
Originally Posted by chocsplease View Post
Oh. I didn't know that! Having never used an Amiga in any language other than English I had assumed that commands etc would be in the native language.
Wouldn't make any sense. Scripts etc would have been language dependant!
nogginthenog is online now  
Old Yesterday, 13:44   #26
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 125
Quote:
Originally Posted by nogginthenog View Post
Wouldn't make any sense. Scripts etc would have been language dependant!
Hi,

To be honest I hadn't even thought about scripts! However I've fixed it by simply adding the switch; script. If this is included in the command line then the app uses the the default English arguments no-matter what the user has set the local command line to be.

Obviously if they change the name of the app itself then there is little I can do about it.

Thanks for pointing the possible issue out.
chocsplease is offline  
Old Today, 16:21   #27
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 125
Oh well so much for *that* idea.

Having added SCRIPT/S to my template I am now getting a software failure when the app exits of #80000004. Its not a Guru, but one of the suspend/Reboot type.

The bizarre thing is that all the other switches work fine and the app exits correctly whether you enter anything on the command line or not. It only crashes if you enter SCRIPT.

Here's the template.

#define TEMPLATE "DEVICE/M,HELP/S,WINDOW/S,NOCOLOURS/S,COLOURS/S,LEADINGSPACE/S,TRAILINGSPACE/S,NORMALRAM/S,DECIMALSIZE/S,SCRIPT/S,DUD/S"

I added the DUD switch just in case it was something odd with SCRIPT being the last switch. Adding DUD to the command line also causes the same error!

Here's the code that reads the options. Initially I wasn't doing anything with the switches but then added the if checks with the zz=0; in them in pure desperation.

Code:
/*get args if any from command line*/


			Args=ReadArgs(TEMPLATE,clparams,NULL); /*check first on the default template for script switch*/				

		if (Args)	/*entered something*/
		{
		printf("entered args- clparams[0]=%d \n",clparams[0]);
			if (clparams[0]!= NULL)
			{
			printf("entered device\n");
				i=0;
				while (((STRPTR*)clparams[0])[i]!=NULL)
				{
					printf("%s\n",((STRPTR*)clparams[0])[i]);
					i++;
				}

			}
			
				
		printf("OPTIONS STARTS AS %d\n",options);	
/*			if ((clparams[3]==-1) && (clparams[4]==-1)) DO SOMETHING! <<<<<< cant have colours and no colours speced!*/
		
			if ((clparams[3]==-1) && ((options & NO_COLOURS) ==0)) options=options | NO_COLOURS;	/*if nocolours on cmd line and not in prefs file set*/
			
			if ((clparams[4]==-1) && ((options & NO_COLOURS)> 0)) options=options - NO_COLOURS;		/*if colours on cmd line and nocolours in prefs file reset */

			if ((clparams[5]==-1) && ((options & LEADING_SPACES) == 0)) options=options | LEADING_SPACES;	/*if want leading spaces and not in prefs file set*/
		
			if ((clparams[6]==-1) && ((options & TRAILING_SPACES) == 0)) options=options | TRAILING_SPACES;	/*if want trail scs and not in prefs fileset*/
		
			if ((clparams[7]==-1) && ((options & NORMAL_RAM) == 0)) options=options | NORMAL_RAM; 		/*if want ram disk always 100% and not in prefs set*/
		
			if ((clparams[8]==-1) && ((options & DEC_VALUES) == 0)) options=options | DEC_VALUES;			/*if want fake values for sizes and not in prefs set */
	

			if ((clparams[9]==-1))
			{
				zz=0;
				/*test SCRIPT switch */
			}
			
			if ((clparams[10]==-1))
			{
				zz=0;
			/*test for odd crash */
			}

		
		}
	
	printf("OPTIONS ENDS AS %d\n",options);

The error occurs right at the very end of the main function at the line I have marked <<<<<<<<< :

Code:
				/*clear any stored volist*/
				printf("Clearing vollist_head\n");
				while(vollist_head)
				{
					vollist_temp=vollist_head->next;
   					
   					printf("vollist_temp mem is now %d\n",&vollist_temp);
   					printf("About to freevec vollist_head %d\n",&vollist_head);
   					
   					FreeVec(vollist_head);
   					vollist_head=vollist_temp;
					printf("OK\n");
   				}
		
		
							
				printf("FREE ARGS\n");
				FreeArgs(Args); /* clear mem used for command line*/
				printf("FREE INFODAT\n");
   				FreeVec(infodat);
   				return_code=RETURN_OK;
   			}

			printf("close lib UBase\n");
   			CloseLibrary(UBase);
			printf("close lib DBase\n");

   			CloseLibrary((struct Library *)DBase);
		printf("OK\n");
   		}
   		else
   		{
   			if (DBase)
   			{
   				CloseLibrary((struct Library *) DBase);
   				
   			}
   			Printf("%s\n",(long)messages[22]); 

   		}
   	  	if (PrefsFile) /*if we allocated a prefs file free it*/
	  	{
  			printf("close PREFS file\n");
	  		printf("free prefs =%x\n",PrefsFile);
  			free (PrefsFile);
			printf("OK\n");
  		}
  	}
   	 	
   	
   	printf("END\n");
return return_code;  /*<<<<<<<<<<<<CRASH!<<<<<<<<<<*/
}
I'm baffled. Why would it work with all the other switches?

Why does it work fine with multiple devices specified, no devices specified, all the other switches no other switches etc etc.

It just crashes if I specify SCRIPT or DUD!

Is there a limit to the number of switches you can use?

This is driving me nuts.
chocsplease is offline  
Old Today, 16:49   #28
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 52
How is clparams defined, as [9] or [11]?
This looks like [9] and local (on stack) resulting in stack corruption.
a/b is offline  
Old Today, 19:07   #29
chocsplease
Registered User

 
Join Date: Dec 2016
Location: london
Posts: 125
Quote:
Originally Posted by a/b View Post
How is clparams defined, as [9] or [11]?
This looks like [9] and local (on stack) resulting in stack corruption.
I'll give you three guesses and the first 2 don't count....

It's 9 - why I did't even think of checking this is beyond me

Many thanks for saving my sanity once again a/b. (Wish there was a way of upvoting or something on this forum).
chocsplease is offline  
AdSense AdSense  
 


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 14 21 October 2015 22:10
multiple use of traps Galahad/FLT Coders. General 2 27 November 2014 10:53
Using ReadArgs() from asm oRBIT Coders. General 4 11 May 2010 16:11
multiple HDFs BippyM request.UAE Wishlist 1 24 September 2005 23:12
Multiple Harddrives Unknown_K support.Hardware 3 25 March 2005 12: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 22:52.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.13800 seconds with 13 queries