home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part01 / selection.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  2.5 KB  |  81 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /*                                    */
  16. /*    The sale of any product based wholely or in part upon the     */
  17. /*    technology provided by tooltool is strictly forbidden without    */
  18. /*    specific, prior written permission from Harris Corporation.    */
  19. /*    Tooltool technology includes, but is not limited to, the source    */
  20. /*    code, executable binary files, specification language, and    */
  21. /*    sample specification files.                    */
  22. /************************************************************************/
  23.  
  24. #include    <stdio.h>
  25. #include    <sys/types.h>
  26. #include    <suntool/selection_svc.h>
  27. #include    <suntool/selection_attributes.h>
  28.  
  29. #include    "tooltool.h"
  30.  
  31. PRIVATE    Seln_result    read_proc();
  32.  
  33. PRIVATE    char    *buf, *pos;
  34.  
  35. EXPORT    char    *tt_get_selection(level)
  36.  
  37. int    level;
  38.  
  39. {    Seln_client    client;
  40.     Seln_holder    holder;
  41.     Seln_rank    rank;
  42.     char        context = 0;
  43.  
  44.     if (level == 1)
  45.        rank = SELN_PRIMARY;
  46.     else if (level == 2)
  47.        rank = SELN_SECONDARY;
  48.     else if (level == 3)
  49.        rank = SELN_SHELF;
  50.     else
  51.        return("");
  52.     holder = seln_inquire(rank);
  53.     if (holder.state == SELN_NONE)
  54.        return("");
  55.     pos = buf = tt_emalloc(65536);
  56.     *buf = '\0';
  57.     seln_query(&holder, read_proc, &context, SELN_REQ_CONTENTS_ASCII, 0, 0);
  58.     return(buf);
  59. }
  60.  
  61. PRIVATE    Seln_result    read_proc(buffer)
  62.  
  63. Seln_request    *buffer;
  64.  
  65. {    char    *reply;
  66.  
  67.     if (buffer) {
  68.        if (*buffer->requester.context == 0) {
  69.           if (*((Seln_attribute *) buffer->data) != SELN_REQ_CONTENTS_ASCII)
  70.              return(SELN_FAILED);
  71.           reply = buffer->data + sizeof(Seln_attribute);
  72.           *buffer->requester.context = 1;
  73.           }
  74.        else
  75.           reply = buffer->data;
  76.        strcpy(pos, reply);
  77.        pos += strlen(reply);
  78.        }
  79.     return(SELN_SUCCESS);
  80. }
  81.