home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5230 < prev    next >
Encoding:
Text File  |  1992-07-25  |  8.7 KB  |  288 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!math.fu-berlin.de!fub!heinz!federico
  3. From: federico@heinz.in-berlin.de (Federico Heinz)
  4. Subject: Structured output to from the WS to an App --- does it work outside a wrap?
  5. Message-ID: <1992Jul25.004708.29582@heinz.in-berlin.de>
  6. Sender: federico@heinz.in-berlin.de
  7. Organization: Federico Heinz Consulting
  8. Date: Sat, 25 Jul 1992 00:47:08 GMT
  9. Lines: 277
  10.  
  11. This one's for DPS Client Libary hackers:
  12.  
  13. I'm trying to asynchronously get results back from the WS using the  
  14. printobject operator. To do so, I arrange my data in an array on the top of  
  15. the stack and invoke, say '0 printobject'. Unfortunately, the Client Library  
  16. seems to think it has monopolic access to printobject, and raises the error  
  17. dps_err_resultTagCheck. No problem, says me, since there's still arg1 and  
  18. arg2 there, which are supposed to contain a pointer to the rejected binary  
  19. object sequence and its length, respectively, so all I have to do is call my  
  20. code from within the error handler, ignore the error-that-is-not, and I'm  
  21. set.
  22.  
  23. Even more unfortunately, the binary object sequence arrives at the error  
  24. handler in a rather crippled form. It seems the Client Library wipes away  
  25. everything but the top-level object from the sequence. I'm enclosing a very  
  26. short program that sends its standard input to the WS.  If you compile and  
  27. invoke it to send the (enclosed) file test.ps, it should print the ASCII  
  28. representation of an array of two strings, followed by the binary object  
  29. sequence representation of the same array (in hex). The result, however, is  
  30. disappointing:
  31.  
  32. federico@louis 41> BinObjTest < test.ps
  33. ====
  34. WS says:
  35. [(hi there) (how's business)]
  36. ====
  37. ====
  38. WS complains:
  39. Got 50-byte binary object sequence:
  40. 80 01 00 32 09 00 00 02 
  41. 00 00 00 08 00 00 00 00 
  42. 00 00 00 00 00 00 00 00 
  43. 00 00 00 00 00 00 00 00 
  44. 00 00 00 00 00 00 00 00 
  45. 00 00 00 00 00 00 00 00 
  46. 00 00 
  47. ====
  48.  
  49. The binary sequence is wrong. Its length is OK (4 bytes header, 8 bytes root  
  50. object, 2*8 bytes for the string objects + 22 chars for the strings = 50  
  51. bytes), but the contents are correct only up to byte #12. I would have  
  52. expected the following:
  53.  
  54. 80 01 00 32 09 00 00 02 
  55. 00 00 00 08 05 00 00 08 
  56. 00 00 00 18 05 00 00 0e 
  57. 00 00 00 20 68 69 20 74 
  58. 68 65 72 65 68 6f 77 27
  59. 73 20 62 75 73 69 6e 65
  60. 73 73
  61.  
  62. What happened to the rest of my data? Is there no way to send structured data  
  63. to the app besides through the use of wraps? Please take into account that I  
  64. can't use wraps to get this data, because it is produced asynchronously.
  65.  
  66. Wondering again
  67.  
  68.     Federico
  69.  
  70.  
  71. ----- Here it comes ----
  72. #! /bin/sh
  73. # This is a shell archive, meaning:
  74. # 1. Remove everything above the #! /bin/sh line.
  75. # 2. Save the resulting text in a file.
  76. # 3. Execute the file with /bin/sh (not csh) to create the files:
  77. #       BinObjTest
  78. # This archive created: Sat Jul 25 02:44:45 1992
  79. export PATH; PATH=/bin:$PATH
  80. if test ! -d 'BinObjTest'
  81. then
  82.         mkdir 'BinObjTest'
  83. fi
  84. cd 'BinObjTest'
  85. if test -f 'test.ps'
  86. then
  87.         echo shar: will not over-write existing file "'test.ps'"
  88. else
  89. cat << \SHAR_EOF > 'test.ps'
  90. %!
  91.  
  92. % Put two strings in an array
  93. (hi there) (how's business) 2 array astore
  94.  
  95. % Now the array is at the top of the stack. Show it, so we can be sure
  96. pstack flush
  97.  
  98. % Now send the array as a binary object sequence to the app
  99. 15 printobject flush
  100. SHAR_EOF
  101. fi # end of overwriting check
  102. if test -f 'Makefile'
  103. then
  104.         echo shar: will not over-write existing file "'Makefile'"
  105. else
  106. cat << \SHAR_EOF > 'Makefile'
  107. CFLAGS        = -O -g -Wall
  108.  
  109. DESTDIR           = .
  110.  
  111. HDRS          = 
  112.  
  113. LIBS          = -lNeXT_s
  114.  
  115. LINKER            = cc
  116.  
  117. OBJS      = BinObjTest.o 
  118.  
  119. SRCS          = BinObjTest.c
  120.  
  121. all:            BinObjTest
  122.  
  123. BinObjTest:             $(OBJS)
  124.                                 $(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o  
  125. BinObjTest
  126.  
  127. clean:;                 rm *.o 
  128.  
  129. BinObjTest.o:           BinObjTest.c
  130.  
  131. SHAR_EOF
  132. fi # end of overwriting check
  133. if test -f 'BinObjTest.c'
  134. then
  135.         echo shar: will not over-write existing file "'BinObjTest.c'"
  136. else
  137. cat << \SHAR_EOF > 'BinObjTest.c'
  138. #import <sys/types.h>
  139. #import <sys/stat.h>
  140. #import <dpsclient/dpsclient.h>
  141. #import <libc.h>
  142. #import <mach.h>
  143. #import <mach_error.h>
  144. #import <objc/error.h>
  145. #import <cthreads.h>
  146. #import <stdio.h>
  147.  
  148.  
  149. DPSContext context;
  150.  
  151.  
  152. /*
  153.   Write text from the WS to stdout
  154. */
  155.  
  156. static mutex_t libc_mutex;              /* just so we won't bother the C  
  157. library */
  158.  
  159. static void textCallBack(DPSContext pctx, char *text,
  160.                                                           unsigned long  
  161. length)
  162. {
  163.         mutex_lock(libc_mutex);
  164.         fprintf(stderr, "====\nWS says:\n");
  165.         write(fileno(stderr), text, length);
  166.         write(fileno(stderr), "====\n", 5L);
  167.         mutex_unlock(libc_mutex);
  168. }
  169.  
  170.  
  171. static void errorCallBack(DPSContext ctxt,
  172.                                                   DPSErrorCode errorCode,
  173.                                                   long unsigned int arg1, 
  174.                                                   long unsigned int arg2)
  175. {
  176.         int i;
  177.         unsigned char *p;
  178.  
  179.         mutex_lock(libc_mutex);
  180.         fprintf(stderr, "====\nWS complains:\n");
  181.         switch (errorCode)
  182.         {
  183.           case dps_err_ps:
  184.                 fprintf(stderr, "PostScript error in file to print:\n");
  185.                 DPSPrintError(stderr, (DPSBinObjSeq)(arg1));;
  186.                 break;
  187.           case dps_err_nameTooLong:
  188.                 fprintf(stderr, "Name too long: %s.\n", (char *)arg1);
  189.                 break;
  190.           case dps_err_resultTagCheck:
  191.                 fprintf(stderr, "Got %d-byte binary object sequence:",
  192.                                 (int)arg2);
  193.                 for (i = 0, p = (unsigned char *)arg1;
  194.                          i < (int)arg2;
  195.                          i++, p++)
  196.                 {
  197.                         if (i % 8 == 0)
  198.                                 putc('\n', stderr);
  199.                         fprintf(stderr, "%0.2x ", *p);
  200.                 }
  201.                 putc('\n', stderr);
  202.                 break;
  203.           case dps_err_resultTypeCheck:
  204.                 fprintf(stderr, "Wrong type of result.\n");
  205.                 break;
  206.           case dps_err_invalidContext:
  207.                 fprintf(stderr, "Context doesn't exist any longer.\n");
  208.                 break;
  209.           case dps_err_select:
  210.           case dps_err_read:
  211.           case dps_err_write:
  212.                 fprintf(stderr, "Communications error: %d.\n", arg1);
  213.                 break;
  214.           case dps_err_connectionClosed:
  215.                 fprintf(stderr, "Lost connection to window server.\n");
  216.                 break;
  217.           case dps_err_invalidFD:
  218.                 fprintf(stderr, "Invalid file descriptor: %d.\n", arg1);
  219.                 break;
  220.           case dps_err_invalidTE:
  221.                 fprintf(stderr, "Invalid timed entry: %d.\n", arg1);
  222.                 break;
  223.           case dps_err_invalidPort:
  224.                 fprintf(stderr, "Invalid mach port: %d.\n", arg1);
  225.                 break;
  226.           case dps_err_outOfMemory:
  227.                 fprintf(stderr, "Out of memory.\n");
  228.                 break;
  229.           case dps_err_cantConnect:
  230.                 fprintf(stderr, "Cannot connect to window server.\n");
  231.                 break;
  232.           default:
  233.                 fprintf(stderr, "Unknown DPS error.\n");
  234.         }
  235.         write(fileno(stderr), "====\n", 5L);
  236.         exit(4);
  237.         mutex_unlock(libc_mutex);
  238. }
  239.  
  240.  
  241. void main(int argc, char *argv[])
  242. {
  243.         kern_return_t retc;
  244.         struct stat statbuf;
  245.         char *memfile = NULL;
  246.  
  247.         NX_DURING
  248.         {
  249.                 context = DPSCreateContext((void *)NULL, (void *)NULL,
  250.                                                                    textCallBa 
  251. ck, DPSDefaultErrorProc);
  252.         } NX_HANDLER
  253.         {
  254.                 if (NXLocalHandler.code != dps_err_cantConnect)
  255.                         NX_RERAISE();
  256.                 else
  257.                 {
  258.                         fprintf(stderr, "Could not connect to DPS, host  
  259. %s.\n",
  260.                                         (char *)NXLocalHandler.data2);
  261.                         exit(1);
  262.                 }
  263.         } NX_ENDHANDLER;
  264.         DPSSetErrorProc(context, errorCallBack);
  265.         DPSSetTextProc(context, textCallBack);
  266.         libc_mutex = mutex_alloc();
  267.         DPSSetContext(context);
  268.         if (   (fstat(fileno(stdin), &statbuf) == 0)
  269.                 && (statbuf.st_size != 0)
  270.                 && ((retc = map_fd(fileno(stdin), (vm_offset_t)0,
  271.                                                    &(vm_offset_t)memfile,  
  272. TRUE,
  273.                                                    (vm_size_t)statbuf.st_size 
  274. ) == KERN_SUCCESS)))
  275.                 DPSWriteData(context, memfile, statbuf.st_size);
  276.         DPSFlushContext(context);
  277.         DPSWaitContext(context);
  278.         exit(0);
  279. }
  280. SHAR_EOF
  281. fi # end of overwriting check
  282. cd ..
  283. #       End of shell archive
  284. exit 0
  285.  
  286.  
  287.  
  288.