/* msg.c (emx+gcc) */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INCL_DOSMISC
#include <os2.h>

int main (int argc, char *argv[])
{
  ULONG rc, len;
  char text[512];
  unsigned char buf[512];
  int i, j;
  USHORT count, codepage;
  ULONG lang;

  rc = DosGetMessage (argv, 1, text, sizeof (text), 1, "msgtest.msg", &len);
  if (rc != 0)
    {
      fprintf (stderr, "DosGetMessage failed, rc=%lu\n", rc);
      return 1;
    }
  if (len >= sizeof (text))
    --len;
  text[len] = 0;
  puts (text);
#if 0                           /* does not work */
  rc = DosQueryMessageCP (buf, sizeof (buf), "msgtest.msg", &len);
  if (rc != 0)
    {
      fprintf (stderr, "DosQueryMessageCP failed, rc=%lu\n", rc);
      return 1;
    }
  i = 0;
  while (i < len)
    {
      count = *(USHORT *)&buf[i]; i += sizeof (USHORT);
      printf ("Code pages:");
      for (j = 0; j < count; ++j)
        {
          codepage = *(USHORT *)&buf[i]; i += sizeof (USHORT);
          printf (" %d", codepage);
        }
      lang = *(ULONG *)&buf[i]; i += sizeof (ULONG);
      printf (" language=%lu\n", lang);
    }
#endif
  return 0;
}
