void HandleSlaveInput(int msqid)
{
     pthread_t* hAPI;
     char outputTextBuffer[256] = {0};
     textmsg msg;

     memset(msg.mtext, 0, 200);


     while(true) {
          printf("Please enter Message\n");

          fgets(outputTextBuffer, 255, stdin);

          if (!strcmp(outputTextBuffer, "q\n")) {
               goto OutLoop;
          } else {
               SetTextMsg(&msg, TYPE_MSG, WINDOW_OUTPUT, outputTextBuffer, PROP_CLEAR | PROP_TOP);

               if (SendMessage(msqid, &msg)) {
                    break;
               }
          }

          memset(outputTextBuffer, 0, strlen(outputTextBuffer));
     }

OutLoop:

     return;
}
Exemplo n.º 2
0
/* ------- Window processing module for EDITBOX class ------ */
int EditorProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
    switch (msg)    {
		case KEYBOARD:
            if (KeyboardMsg(wnd, p1, p2))
                return TRUE;
            break;
		case SETTEXT:
			return SetTextMsg(wnd, (char *) p1);
        default:
            break;
    }
    return BaseWndProc(EDITOR, wnd, msg, p1, p2);
}
void HandleMasterInput(pthread_t hOutput, int msqid)
{

     pthread_t* hAPI;
     int counter = 0;
     char d = 0;
     char inputTextBuffer[256] = {0};
     char outputTextBuffer[256] = {0};
     textmsg msg;

     memset(msg.mtext, 0, 200);


     while(true) {
          strcpy(inputTextBuffer, "Please enter Message\n");
          SetTextMsg(&msg, TYPE_MSG, WINDOW_INPUT, inputTextBuffer, PROP_TOP|PROP_CLEAR);

          if (SendMessage(msqid, &msg)) {
               break;
          }

          // get input using curses
          while((d = getch()) != '\n') {
               if (d == 'q' && !counter) {
                    // 3rd parameter is unnecessary
                    SetTextMsg(&msg, TYPE_QUIT, (windowtype)0, (char*)&"", NULL);

                    if (SendMessage(msqid, &msg)) {
                         pthread_kill(hOutput, SIGINT);
                    }

                    goto OutLoop;

               } else if (d == 'Q') {
                    if (strlen(outputTextBuffer) == 0) {
                         continue;
                    }

                    SetTextMsg(&msg, TYPE_MSG, WINDOW_INPUT, (char*)&"", PROP_DEL);

                    if (SendMessage(msqid, &msg)) {
                         break;
                    }

                    outputTextBuffer[--counter] = '\0';


               } else {
                    memset(inputTextBuffer, 0, strlen(inputTextBuffer));
                    inputTextBuffer[0] = d;
                    outputTextBuffer[counter] = d;

                    if (counter) {
                         SetTextMsg(&msg, TYPE_MSG, WINDOW_INPUT, inputTextBuffer, 0);
                    } else {
                         SetTextMsg(&msg, TYPE_MSG, WINDOW_INPUT, inputTextBuffer, PROP_BOTTOM);
                    }

                    if (SendMessage(msqid, &msg)) {
                         break;
                    }

                    counter++;

               }
          }

          SetTextMsg(&msg, TYPE_MSG, WINDOW_OUTPUT, outputTextBuffer, PROP_CLEAR | PROP_TOP);

          if (SendMessage(msqid, &msg)) {
               break;
          }

          memset(outputTextBuffer, 0, strlen(outputTextBuffer));
          counter = 0;
     }

OutLoop:

     return;
}
Exemplo n.º 4
0
/* ------- Window processing module for EDITBOX class ------ */
int EditBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
    int rtn;
    switch (msg)    {
        case CREATE_WINDOW:
            return CreateWindowMsg(wnd);
        case ADDTEXT:
            return AddTextMsg(wnd, p1, p2);
        case SETTEXT:
            return SetTextMsg(wnd, p1);
        case CLEARTEXT:
			return ClearTextMsg(wnd);
        case GETTEXT:
            return GetTextMsg(wnd, p1, p2);
        case SETTEXTLENGTH:
            return SetTextLengthMsg(wnd, (unsigned) p1);
        case KEYBOARD_CURSOR:
            KeyboardCursorMsg(wnd, p1, p2);
			return TRUE;
        case SETFOCUS:
			if (!(int)p1)
				SendMessage(NULL, HIDE_CURSOR, 0, 0);
        case PAINT:
        case MOVE:
            rtn = BaseWndProc(EDITBOX, wnd, msg, p1, p2);
            SendMessage(wnd,KEYBOARD_CURSOR,WndCol,wnd->WndRow);
            return rtn;
        case SIZE:
            return SizeMsg(wnd, p1, p2);
        case SCROLL:
            return ScrollMsg(wnd, p1);
        case HORIZSCROLL:
            return HorizScrollMsg(wnd, p1);
        case SCROLLPAGE:
            return ScrollPageMsg(wnd, p1);
        case HORIZPAGE:
            return HorizPageMsg(wnd, p1);
        case LEFT_BUTTON:
            if (LeftButtonMsg(wnd, p1, p2))
                return TRUE;
            break;
        case MOUSE_MOVED:
            if (MouseMovedMsg(wnd, p1, p2))
                return TRUE;
            break;
        case BUTTON_RELEASED:
            if (ButtonReleasedMsg(wnd))
                return TRUE;
            break;
        case KEYBOARD:
            if (KeyboardMsg(wnd, p1, p2))
                return TRUE;
            break;
        case SHIFT_CHANGED:
            ShiftChangedMsg(wnd, p1);
            break;
        case COMMAND:
            if (CommandMsg(wnd, p1))
                return TRUE;
            break;
        case CLOSE_WINDOW:
            return CloseWindowMsg(wnd, p1, p2);
        default:
            break;
    }
    return BaseWndProc(EDITBOX, wnd, msg, p1, p2);
}