@@ -318,6 +318,7 @@ mt_wind_get (short WindowHandle, short What,
318318 aes_intout [AES_INTOUTMAX ];
319319 long aes_addrin [AES_ADDRINMAX ],
320320 aes_addrout [AES_ADDROUTMAX ];
321+ short namebuf [64 ];
321322 AESPB aes_params ;
322323
323324 aes_params .control = & aes_control [0 ]; /* AES Control Array */
@@ -337,11 +338,16 @@ mt_wind_get (short WindowHandle, short What,
337338 case WF_DCOLOR :
338339 case WF_COLOR :
339340 aes_intin [2 ] = * W1 ;
341+ /* older versions of XaAES expect the element in intout[1] */
342+ aes_intout [1 ] = * W1 ;
343+ /* AES 4.1/N.AES do not return the 3d flags */
344+ aes_intout [4 ] = 0x0f0f ;
340345 * (ptr ++ ) = 3 ; /* aes_control[1] */
341346 break ;
342347 case WF_INFO :
343348 case WF_NAME :
344- aes_intin_ptr (2 , short * ) = W1 ;
349+ aes_intin_ptr (2 , short * ) = namebuf ;
350+ namebuf [0 ] = -1 ;
345351 * (ptr ++ ) = 4 ; /* aes_control[1] */
346352 break ;
347353 default :
@@ -355,12 +361,82 @@ mt_wind_get (short WindowHandle, short What,
355361 /* ol: this line is required for WF_FIRSTXYWH and WF_NEXTXYWH because
356362 lot of programmers doesn't verify the return value and espect W or H
357363 will be 0 it's not true for NAES */
364+ aes_intout [0 ] = 0 ;
365+ aes_intout [1 ] = aes_intout [2 ] = -1 ;
358366 aes_intout [3 ] = aes_intout [4 ] = 0 ;
359367
360368 AES_TRAP (aes_params );
361369
362370 if (What == WF_INFO || What == WF_NAME ) {
363- /* special case where W1 shall not be overwritten */
371+ /*
372+ * we want to behave like documented above (copying the string to
373+ * where the first parameter points to), however things are a bit
374+ * more complicated:
375+ * - XaAES will already do that, if nintin is 4
376+ * - N.AES will do that regardless of nintin
377+ * - MagiC does not return the string, but instead its address in intout[1/2]
378+ * There are applications that expect MagiC's behaviour,
379+ * so we must handle all cases.
380+ */
381+ char * name ;
382+ char * dst ;
383+
384+ name = aes_intout_ptr (1 , char * );
385+ if (name != (char * )-1 )
386+ {
387+ /* name was returned as address (MagiC) */
388+ if (W2 != NULL && W2 == (W1 + 1 ))
389+ {
390+ /* application passed two pointers, to get the address as hi/lo */
391+ * W1 = aes_intout [1 ];
392+ * W2 = aes_intout [2 ];
393+ } else
394+ {
395+ /* application passed only one pointer */
396+ if (name == 0 )
397+ {
398+ dst = (char * )W1 ;
399+ if (dst != NULL )
400+ {
401+ if (name == NULL )
402+ {
403+ * dst = '\0' ;
404+ } else
405+ {
406+ while ((* dst ++ = * name ++ ) != '\0' )
407+ ;
408+ }
409+ }
410+ }
411+ }
412+ } else if (namebuf [0 ] != -1 )
413+ {
414+ /* name was written to buffer */
415+ if (W2 != NULL && W2 == (W1 + 1 ))
416+ {
417+ /* application passed two pointers, to get the address */
418+ /* no way to support this, since we only have the string */
419+ * W1 = 0 ;
420+ * W2 = 0 ;
421+ aes_intout [0 ] = 0 ;
422+ } else
423+ {
424+ /* application passed only one pointer */
425+ name = (char * )namebuf ;
426+ dst = (char * )W1 ;
427+ if (dst != NULL )
428+ {
429+ while ((* dst ++ = * name ++ ) != '\0' )
430+ ;
431+ }
432+ }
433+ } else
434+ {
435+ /*
436+ * nothing was returned?
437+ * hopefully return code will indicate error
438+ */
439+ }
364440 } else {
365441#if CHECK_NULLPTR
366442 if (W1 ) * W1 = aes_intout [1 ];
0 commit comments