#include <string.h>
#include <ctype.h>
#include <descrip.h>
#include <jpidef.h>
#include <brkdef.h>

long sys$brkthruw();
long lib$getjpi();

void uppcascvt(const char *s1,const char *s2)
{
   register char *ss1,*ss2;
   ss1 = s1;
   ss2 = s2;
   while(*ss2) {
      *ss1 = toupper(*ss2); 
      ss1++; ss2++;
   }
   *ss1 = *ss2;
   return;
}

void prncvt(const char *s1,const char *s2)
{
   register char *ss1,*ss2;
   ss1 = s1;
   ss2 = s2;
   while(*ss2) {
      if (isgraph(*ss2)||(*ss2==' ')) {
         *ss1 = *ss2; 
      } else {
         *ss1 = '.';
      }
      ss1++; ss2++;
   }
   *ss1 = *ss2;
   return;
}

main(int argc,char *argv[])
{
   long code = JPI$_USERNAME;
   long stat;
   short iosb[4];
   char un[13],self[13];
   char msg[80];
   $DESCRIPTOR(undsc,un);
   $DESCRIPTOR(selfdsc,self);
   $DESCRIPTOR(msgdsc,msg);
   if (argc>2) {
      uppcascvt(un,argv[1]);
      undsc.dsc$w_length = strlen(un);
      stat = lib$getjpi(&code,0,0,0,&selfdsc,0);
      self[12] = '\0';
      sprintf(msg,"%s: ",self);
#ifndef _ONLY_USERS_WITH_PRIVS_
      prncvt(&msg[14],argv[2]);
#else
      strcpy(&msg[14],argv[2]);
#endif
      msgdsc.dsc$w_length = strlen(msg);
      stat = sys$brkthruw(0,&msgdsc,&undsc,BRK$C_USERNAME,iosb,0,BRK$M_CLUSTER,
                          BRK$C_USER1,0,0,0);
   } else {
      printf("username or message not specified\n");
   }
}
