[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::amiga_v1

Title:AMIGA NOTES
Notice:Join us in the *NEW* conference - HYDRA::AMIGA_V2
Moderator:HYDRA::MOORE
Created:Sat Apr 26 1986
Last Modified:Wed Feb 05 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:5378
Total number of notes:38326

316.0. "Two Programming Questions" by ECADJR::BOSCH () Mon Feb 09 1987 10:48

    I am writing several program for the Amiga, and have several problems.
    1)  I have written a graphic intensive window, gadget program, and
    it runs flawlessly from CLI,  however, when I make an icon for it,
    and try to use it from Workbench, it screws up.  Does anyone know
    what it could be?
    
    2) I am writing a new CLI command to compress disks and files, and
    wanted to know this:
    
    If you type a normal CLI command in the form:
    1> command file-name
    
    How would you in a C-program, find the name of the file specified
    in the command line?  Any help would be welcome.
    
    Derek Bosch
    
T.RTitleUserPersonal
Name
DateLines
316.1Think I remember the detailsSQM::JMSYNGEJames M Synge, VMS Perf AnalMon Feb 09 1987 13:1023
	Sounds like you are unaware of the details of C program startup on
	the Amiga.  My recollection is that your main routine needs the
	following declaration:

	main(argc, argv)
	int argc;	/* Number of arguments. */
	char *argv[];	/* Vector of char * s	*/

	If the program is started from the WorkBench, then argc will be 0,
	and argv will be set to some info about how it was invoked (don't
	remember all the details).

	If the program is started from the CLI, then argc will be set to
	the number of arguments on the command line, including the name
	of the command.  Thus to print the file-name argument in your
	second question, you could do the following:

	printf("file-name: %s\n", argv[1])

	Hope that helps,
		James M Synge,  VMS Performance Analysis, DECnet-VAX

316.2try this way.POMPEO::ZABOTMarco Zabot-Adv.Tech.mgr-Turin ACTMon Feb 09 1987 13:1045
Arguments are passed using argc (count) and argv (values).
Example of usage attached ( from a USENET message ).
Enjoy.
marco


/*
 * Handle commandline
 */
main(argc, argv)
int argc;
char *argv;
{
    int argno;
    int fd, ofd;
    char *s, ofn[STRINGSIZ], ifn[STRINGSIZ];

    /*
     * No instructions:
     * print info about use and
     * exit with bad return code.
     */
    if (argc <= 1)
    {
	s = "-----------------------------------------------------------------\n";
	fprintf(stderr, s);
	fprintf(stderr, "CVT version %s                                      %s\n", version, date);
	fprintf(stderr, "THIS  PROGRAM IS  (C)1985  LANDON M. DYER  AND MAY BE DISTRIBUTED\n");
	fprintf(stderr, "ONLY IF THE FOLLOWING CONDITIONS ARE MET:\n");
	fprintf(stderr, "\t1. YOU DO NOT MAKE A PROFIT ON IT.\n");
	fprintf(stderr, "\t2. IF YOU HAVE THE SOURCE CODE, YOU GIVE THAT AWAY, TOO.\n");
	fprintf(stderr, "\t3. YOU INCLUDE THIS NOTICE IN THE SOURCE AND OBJECT CODE.\n");
	fprintf(stderr, s);
	fprintf(stderr, "Usage:\n");
	fprintf(stderr, "CVT [-d] [-p] inputfile[.LN] [inputfile...]\n");
	fprintf(stderr, "        ==> file.PRG output files.\n");
	exit(1);
    }


   for (argno = 1; argno < argc; ++argno)
        if (*argv[argno] == '-')
	    for (s = &argv[argno][1]; *s; ++s)

............ and so on !!!
316.3ELWOOD::PETERSMon Feb 09 1987 13:5215
    
    	The argc and argv parameters are not specific to the AMIGA.
    They are standard C, therefore are documented in any book about
    C. The information passed then the program is run from an ICON
    is AMIGA specific.
    	As for running a program from an ICON, there are things that
    must be done to allow a program to be started from an ICON. If
    you are using LATTICE C there are 2 different versions of a .obj
    file that are linked into your program. Look at the command line
    you are using to link program. It should be BLINK L???.obj+progrma.obj
    ... the first file is the one that controls if a program can be
    run from an ICON. I'll look up the exact name and post it.
    
    		Steve Peters
    
316.4Q2ECADJR::BOSCHMon Feb 09 1987 14:024
    I am using MANX C, by the way.  Thanks for question 2).  Still need
    help when starting from an ICON though.
    
    Derek