home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18316 < prev    next >
Encoding:
Text File  |  1993-01-07  |  3.8 KB  |  130 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!sdd.hp.com!ux1.cso.uiuc.edu!usenet.ucs.indiana.edu!navajo!shulick
  2. From: shulick@navajo.ucs.indiana.edu (Sam Hulick)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Please help with stupid memory leak
  5. Message-ID: <C0ICKI.H57@usenet.ucs.indiana.edu>
  6. Date: 7 Jan 93 23:43:26 GMT
  7. Sender: news@usenet.ucs.indiana.edu (USENET News System)
  8. Reply-To: shulick@navajo.ucs.indiana.edu
  9. Organization: Vallen Software
  10. Lines: 116
  11. Originator: shulick@navajo
  12. Nntp-Posting-Host: navajo.ucs.indiana.edu
  13.  
  14.  
  15. I can't figure this one out.  It seems to not free either 56 bytes or
  16. 296.  Anyway, the usage is:  req <title> <text> <choice1> [choice]...
  17. Some examples:
  18.   req Problem "There's a bug in here." "Kill it" "Hang it" Cancel
  19.  
  20. Well, it doesn't free up memory, but I can't figure out WHAT.. any help
  21. would be appreciated.
  22.  
  23. /* req.c - Use system requests in scripts */
  24. /* This is free.  Copy it, sell it, eat it, reprogram it, eat it.  No one
  25.    gives a crap. :)
  26. Notice, you can customize what sort of output you want.  If you want, you can
  27. convert the values into something else and pass them to exit(), or you can
  28. just print them out (as I have here).  See doc for more info on usage. */
  29. /* BTW - it's messy, but it works.  Reprogram if you want. */
  30.  
  31. #include <stdio.h>
  32. #include <intuition/intuition.h>
  33. #include <dos/rdargs.h>
  34. #include <exec/alerts.h>
  35.  
  36. #include <clib/dos_protos.h>
  37. #include <clib/exec_protos.h>
  38.  
  39. /* All we need is one.. */
  40. struct EasyStruct ereq = {
  41.    sizeof(struct EasyStruct), 0,  /* unimportant stuff */
  42.    NULL,  /* Title of requester */
  43.    NULL,  /* Text */
  44.    NULL   /* Choices */
  45. };  /* of course, these will be filled in later, by the user */
  46.  
  47. struct Library *IntuitionBase=NULL;
  48. LONG arr[4];
  49. char workstr2[BUFSIZ], sigh[BUFSIZ];
  50. struct RDArgs *rd=NULL;
  51.  
  52. void bye();
  53.  
  54. void main(int ac, char **av)
  55. {
  56.    int x, len;
  57.    char workstr[BUFSIZ];
  58.  
  59.    memset(arr, '\0', sizeof(arr));
  60.    /* Oh, ReadArgs() is so nice.. :) */
  61.    if (!(rd = ReadArgs("Title/A,Text/A,Choice1/A,Choices/F", arr, NULL)))
  62.    {
  63.       fprintf(stderr, "required argument missing\n");
  64.       bye();
  65.    }
  66.  
  67.    if (!(IntuitionBase = OpenLibrary("intuition.library", 37)))
  68.    {
  69.       fprintf(stderr, "Can't open intuition.library V37\n");
  70.       bye();
  71.    }
  72.  
  73.    if (!(ereq.es_Title = (UBYTE *)malloc(strlen((char *)arr[0])+1)))
  74.    {
  75.       Alert(AT_Recovery | AG_NoMemory);
  76.       exit(0);
  77.    }
  78.    ereq.es_Title = (UBYTE *)arr[0];
  79.    strcpy(workstr, arr[3]); /* Because we can't do arr[3][x] */
  80.    len = strlen(workstr);
  81.    for (x = 0; x < len; ++ x)
  82.    {
  83.       if (workstr[x] == ' ')
  84.          workstr[x] = '|';
  85.    }
  86.    strcpy(workstr2, arr[1]);
  87.    len = strlen(workstr2);
  88.    for (x = 0; x < len; ++ x)
  89.    {
  90.       if (workstr2[x] == '\\')
  91.          workstr[x] = '\n';
  92.    }
  93.    if (!(ereq.es_TextFormat = (UBYTE *)malloc(strlen((char *)workstr2)+1)))
  94.    {
  95.       Alert(AT_Recovery | AG_NoMemory);
  96.       exit(0);
  97.    }
  98.    ereq.es_TextFormat = (UBYTE *)workstr2;
  99.    /* sprintf()'ing into 'sigh' is easier than malloc()'ing GadgetFormat */
  100.    /*  :)  */
  101.    if (workstr[0])
  102.       sprintf(sigh, "%s\|%s", (char *)arr[2], workstr);
  103.    else
  104.       strcpy(sigh, (char *)arr[2]);
  105.    if (!(ereq.es_GadgetFormat = (UBYTE *)malloc(strlen((char *)sigh)+1)))
  106.    {
  107.       Alert(AT_Recovery | AG_NoMemory);
  108.       exit(0);
  109.    }
  110.    ereq.es_GadgetFormat = (UBYTE *)sigh;
  111.    printf("%d\n", EasyRequest(NULL, &ereq, NULL));
  112.  
  113.    bye();
  114. }
  115.  
  116. void bye()
  117. {
  118.    free(ereq.es_TextFormat);
  119.    free(ereq.es_GadgetFormat);
  120.    free(ereq.es_Title);
  121.    if (IntuitionBase)
  122.       CloseLibrary(IntuitionBase);
  123.    exit(0);
  124. }
  125. -- 
  126.     // Amiga 3000   ___ \ Sam Hulick: shulick@indiana.edu (NeXTmail OK!)
  127.    // 68030 25 MHz /__/\ \ My opinions wear combat boots.  Or whatever.
  128. \\// OS 2.04       \__\/ / "Walk!  Not bloody likely.  I am going in a
  129.  \/                     / taxi."  --George Bernard Shaw
  130.