home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 376_01 / os2tool.000 / DIRS.C < prev    next >
C/C++ Source or Header  |  1992-08-23  |  2KB  |  91 lines

  1. /*
  2. * DIRS.C - Print the directory stack from dirserver.
  3. *
  4. *
  5. * PROGRAMMER:        Martti Ylikoski
  6. * CREATED:        29.3.1991
  7. */
  8. static char *VERSION = "Version  1.0" ;
  9. /*
  10. */
  11.  
  12. static char *progname ;
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #define INCL_KBD
  18. #define INCL_DOS
  19. #include <os2.h>
  20. #include "queue.h"
  21.  
  22. typedef struct kbdpacket
  23. {
  24.    unsigned monflags ;
  25.    KBDKEYINFO kbdkeyinfo ;
  26.    unsigned ddflags ;
  27. } KBDBUF ;
  28.  
  29. KBDBUF kbdbuf ;
  30. //int send_queue(char *queue_name, char *message, USHORT cbElement, USHORT usRequest) ;
  31.  
  32. int main(int argc, char *argv[])
  33. {
  34. HQUEUE hdirsresp ; /* queuehandle */
  35. USHORT ret ;
  36. int i ;
  37. QUEUERESULT qres ;
  38. PVOID pmesg ;
  39. USHORT cbElement ;
  40. BYTE bElemprty ;
  41. char *ptmp ;
  42. SEL ginfo, linfo ;
  43. LINFOSEG FAR *plis ;
  44. char sga[4], queue_name[80] ;
  45.  
  46.    progname = argv[0] ;
  47.  
  48.    if (argc == 2 && (strcmpi(argv[1], "-q") == 0
  49.        || strcmpi(argv[1], "/q") == 0))
  50.    {
  51.       QueSend("\\queues\\popreq", "  ", 3, 1,"START /C dirserv.exe",progname) ; /* send EXIT command */
  52.       printf("Directory stack server removed. \n") ;
  53.       return( 0 ) ;
  54.    }
  55.  
  56.    if (( ret = DosGetInfoSeg(&ginfo, &linfo)) != 0)
  57.    {
  58.       printf("%s: error in DosGetInfoSeg", progname) ;
  59.       return(1) ;
  60.    }
  61.  
  62.    plis = MAKEPLINFOSEG(linfo) ;
  63.    itoa(plis->sgCurrent, sga, 10) ;
  64.    strcpy(queue_name, "\\queues\\sg") ; /* sg prefix - somebody might use PIDs
  65.                         as a name base. We want to minimize
  66.                         risk for a name clash */
  67.    strcat(queue_name, sga) ;
  68.  
  69.    if (( ret = DosCreateQueue(&hdirsresp, QUE_FIFO, queue_name)) != 0)
  70.    {
  71.       fprintf(stderr, "%s: error creating queues...\Exiting...\n", progname ) ;
  72.       return( 1 ) ;
  73.    }
  74.  
  75.     QueSend("\\queues\\popreq", sga, strlen(sga)+1, 2, "START /C dirserv.exe",progname ) ; /* send DIRS-command */
  76.  
  77.      while (( ret = DosReadQueue(hdirsresp, &qres, &cbElement, &pmesg, 0, DCWW_WAIT,
  78.          &bElemprty, NULL)) == 0 && qres.usEventCode != 3)
  79.       {
  80.       ptmp = (char *) pmesg ;
  81.       printf("%s\n", ptmp) ;
  82.       DosFreeSeg(SELECTOROF(pmesg)) ;
  83.       }
  84.       ptmp = (char *) pmesg ;
  85.       printf("%s\n", ptmp) ;
  86.  
  87.    DosCloseQueue(hdirsresp) ;
  88.    return( 0 ) ;
  89. }
  90.  
  91.