From: s37732v@snakemail.hut.fi (Markus Juhani Aalto)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Sigh.. OKAY.  ReadArgs() is buggy?
Date: 19 Dec 92 09:06:43 GMT
Organization: Helsinki University of Technology, Finland
Distribution: inet
NNTP-Posting-Host: lk-hp-16.hut.fi
In-reply-to: shulick@navajo.ucs.indiana.edu's message of Sat, 19 Dec 1992 06:21:45 GMT

In article <BzHto9.9pG@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu (Sam Hulick) writes:

   (*&%(*@&(*&%!!  I've about had it with this fucking routine!  (If only I
   had the money to buy a book...)

   #define TEMPLATE "Files/M/A,I=Ignore/S,L=Learn/S,V=Verbose/S,Action=ToDo/K"

   ...
   ...

   LONG arr[5];
   struct RDArgs *rd;

Did you initialize arr array to zeros. Like this arr[0]=0; arr[1]=0; etc..

       rd = ReadArgs(TEMPLATE, arr, NULL);  /* Let's assume success */

   Ok, let's say the command line was:  "program blech.pic"
   For some WEIRD reason, arr[1] == -1, arr[2] == 0 (this is ok), and
   arr[3] == 32791839!!  What the HELL?  I checked someone else's source
   code, and indeed, if it's -1, the switch (/S) was picked, and if not, 0.
   What the hell is a 32791839 doing in arr[3]?  Arr[3] corresponds to
   "V=Verbose/S".  Well, there's not much I can say about this.  I have no
   idea what would cause this.  Again, please follow-up here, do NOT e-mail
   me.  Thanks.

       // Amiga 3000   ___ \ Sam Hulick: shulick@indiana.edu (NeXTmail OK!)

You've been torturing :^) yourself too long with this problem. Here is a
working code from my ScreenSelect. Well, just a part anyway.

#define TEMPLATE        "CX_POPKEY/K,CX_PRIORITY/N/K,QUICKKEYS/K,\
SCREENKEY/K,CX_POPUP/S,ALLSCREENS/S,SMARTPOINTER/S,AUTOACTIVATE/S"

#define CXPOPKEY            0
#define CXPRI               1
#define CXQUICKKEYS         2
#define CXSCREENKEY         3
#define CXPOPUP             4
#define CXALLSCREENS        5
#define CXSMARTPOINTER      6
#define CXAUTOACTIVATION    7
#define ARG_COUNT           8


struct RDArgs *my_rda;
LONG *Array;

Array = (LONG *)AllocMem(sizeof(LONG)*ARG_COUNT,MEMF_ANY|MEMF_CLEAR);
if( Array ) {
    my_rda = (struct RDArgs *)AllocDosObject(DOS_RDARGS,NULL);
    if(my_rda) {
        my_rda->RDA_Source.CS_Buffer = GetArgStr();
        my_rda->RDA_Source.CS_Length = strlen( GetArgStr() );
        my_rda->RDA_Source.CS_CurChr = 0;

        if( ReadArgs(TEMPLATE,Array,my_rda) ) {
            if(Array[CXPOPUP] != 0) {
                dtb->cx_popup = TRUE;
            }

            if(Array[CXPOPKEY] != 0) {
                dtb->cx_hotkey = (UBYTE *)AllocMem(1+
                        strlen((UBYTE *)Array[CXPOPKEY]),MEMF_ANY);
                if(dtb->cx_hotkey == NULL) {
                    FreeArgs(my_rda);
                    FreeDosObject(DOS_RDARGS,(VOID *)my_rda);
                    FreeMem((void *)Array,sizeof(LONG)*ARG_COUNT);
                    return(FALSE);
                }

                strcpy(dtb->cx_hotkey,(UBYTE *)Array[CXPOPKEY]);
                dtb->cx_hotkeyreserved = TRUE;
            }

            if(Array[CXSCREENKEY] != 0) {
                dtb->pubscreen_hotkey = (UBYTE *)AllocMem(1+
                        strlen((UBYTE *)Array[CXSCREENKEY]),MEMF_ANY);
                if(dtb->pubscreen_hotkey == NULL) {
                    FreeArgs(my_rda);
                    FreeDosObject(DOS_RDARGS,(VOID *)my_rda);
                    FreeMem((void *)Array,sizeof(LONG)*ARG_COUNT);
                    return(FALSE);
                }

                strcpy(dtb->pubscreen_hotkey,(UBYTE *)Array[CXSCREENKEY]);
                dtb->pubscreenkey_reserved = TRUE;
            }


            if(Array[CXPRI] != 0) {
                dtb->cx_pri = (BYTE)(*(LONG *)Array[CXPRI]);
            }

            if(Array[CXALLSCREENS] != 0 ) {
                dtb->cx_AllScreens = TRUE;
            }

            if(Array[CXSMARTPOINTER] != 0) {
                dtb->cx_SmartPointer = TRUE;
            }

            if(Array[CXAUTOACTIVATION] != 0) {
                dtb->cx_AutoActivation = TRUE;
            }

            if(Array[CXQUICKKEYS] != 0 ) {
                if( !ParseQuickKeys(dtb,(UBYTE *)Array[CXQUICKKEYS]) ) {
                    FreeArgs(my_rda);
                    FreeDosObject(DOS_RDARGS,(VOID *)my_rda);
                    FreeMem((void *)Array,sizeof(LONG)*ARG_COUNT);
                    return(FALSE);
                }
            }

            FreeArgs(my_rda);
        }
        else PrintFault( IoErr(), "Args");

        FreeDosObject(DOS_RDARGS,(VOID *)my_rda);
    }
    FreeMem((void *)Array,sizeof(LONG)*ARG_COUNT);
}

------------------------------------------------------

Hope this helps!
--


**************************************************************************
*         Markus Aalto              | Helsinki University of Technology  *
*                                   |                                    *
*  EMail: s37732v@vipunen.hut.fi    | Faculty of Electric Engineering    *
*  Fax:   358-0-8746991 (Sometimes) |                                    *
*                                   | Undergraduate in Computer Science  *
**************************************************************************