示例#1
0
void main()
{
        double x, y;
        int counter = 0;
        char s[2] = {' ', '\0'};
        /*        clrscr(); */
        VioScrollDn(0,0,-1,-1,-1,(PBYTE)&s,0);
        VioSetCurPos(0,0,0);
        
        puts("PRIME NUMBER GENERATOR v1.3");
        puts("(C) 1996 by Jawed Karim <*****@*****.**> and Paul Damer");
        puts("--------------------------------------------------------------");
        puts("");
        printf("START: ");
        scanf("%lf", &x);

        if ( (x < 0) || ( floor(x) != x ) )
        {
                puts("ERROR: enter positive integers only.");
                exit(1);
        }
        
        if (x < 2)
                printf("2\n3\n"); /* the loop leaves these numbers out.. */
        
        if (x == 2)
                printf("3\n");
        
        while (1)
        {
                x++;                
        
                y = floor ( sqrt ( x ) );

        lbl: ;

                if ( ( (x/y)-(floor (x/y)) ) != 0 )
                {
                        y--;                
                        
                        if ( y<2 )
                        {        
                                if (counter == 24)
                                {
                                        VioSetCurPos(0,0,0);
                                        counter = 0;
                                }

                                printf("%.0lf\n", x);
                                counter++;
                        }
                        
                        else
                                goto lbl;
                }
        }
}
示例#2
0
/*--------------------------------------------------------------------------*
 *  setcursorpos                                                            *
 *                                                                          *
 *--------------------------------------------------------------------------*/
void setcursorpos(int row, int col)
{
   int rc;

   if (rc = VioSetCurPos(row, col, (HVIO)0))
     printf("Failed setting cursor position. rc = %d", rc);
}
示例#3
0
文件: aaos2.c 项目: JohnChu/Snoopy
void breakfunc(int signo) {
  BYTE bCell[2];
  
  bCell[0] = 0x20;
  bCell[1] = ( WM_BLACK << 4 ) + WM_PALEGRAY;
  
  VioScrollDn(TOP_ROW,LEFT_COL,0xFFFF,0xFFFF,0xFFFF,bCell,(HVIO) 0);
  VioSetMode(&oldMode, (HVIO) 0);
  VioSetCurPos(0, 0, (HVIO)0);
  VioSetCurType(&oldCurInfo, (HVIO)0);

  switch(signo) {
  case SIGINT:
    fprintf(stderr, "Interrupt (Ctrl-C)\n"); break;
  case SIGQUIT:
    fprintf(stderr, "Quit\n"); break;
  case SIGILL:
    fprintf(stderr, "Illegal instruction\n"); break;
  case SIGFPE:
    fprintf(stderr, "Floating point\n"); break;
  case SIGKILL:
    fprintf(stderr, "Kill process\n"); break;
  case SIGBUS:
    fprintf(stderr, "Bus error\n"); break;
  case SIGSEGV:
    fprintf(stderr, "Segmentation fault\n"); break;
  case SIGTERM:
    fprintf(stderr, "Termination, process killed\n"); break;
  case SIGBREAK:
    fprintf(stderr, "Break (Ctrl-Break)\n"); break;
  }
  exit(99);
}
示例#4
0
void Vid_Erase(int fcolor, int bcolor)
{
BYTE Attr[2];
   Attr[1]=MKATRB(bcolor,fcolor);
   Attr[0]=0x20;
   VioScrollUp(0,0,0xFFFF,0xFFFF,0xFFFF,(PBYTE)Attr,hvio);
   VioSetCurPos(0,0,hvio);
}
示例#5
0
int main(void)
{
    APIRET16 apiret;
    char *str1 = "First string";
    char *str2 = "Second string";

    printf(__FILE__ " main function invoked\n");
    printf("Test VIO functions\n");
    DosSleep(2000);

    /* move the cursor around some */
    apiret = VioSetCurPos(0, 0, 0);
    DosSleep(1000);
    apiret = VioSetCurPos(1, 0, 0);
    DosSleep(1000);
    apiret = VioSetCurPos(2, 0, 0);
    DosSleep(1000);
    apiret = VioSetCurPos(3, 0, 0);
    DosSleep(1000);
    apiret = VioSetCurPos(4, 0, 0);
    DosSleep(1000);
    apiret = VioSetCurPos(5, 0, 0);
    DosSleep(1000);

    /* write some strings */
    VioWrtTTY(str1, strlen(str1), 0);
    DosSleep(2000);
    apiret = VioSetCurPos(6, 0, 0);
    VioWrtTTY(str2, strlen(str2), 0);
    DosSleep(2000);

    return 0;
}
示例#6
0
VOID ClearScreen(THREAD *pstThd)
  {
  VIOCELL Cell;
  VIOPS *pVio = &pstThd->stVio;
  BYTE byBackground;
  BYTE byForeground;


  byBackground = ClrTable[pVio->wBackground].PSClr;
  byForeground = ClrTable[pVio->wForeground].PSClr;


  /*
  ** Set foreground and background colors in ANSI, so that the
  ** VioWrtTTY function will pick up the correct colors.
  */
  chAnsi[ANSI_FORE] = QueryAnsiClr(byForeground);
  chAnsi[ANSI_BACK] = QueryAnsiClr(byBackground);
  VioSetAnsi (ANSI_ON,pVio->hpsVio);
  VioWrtTTY( (PCH)chAnsi,sizeof(chAnsi),pVio->hpsVio);
  if (!pstThd->stCfg.bEnableAnsi)
    VioSetAnsi (ANSI_OFF,pVio->hpsVio);

  /*
  ** Set Presentation Space to a known state - full of spaces.
  */
  Cell.vc      = ' ';
  Cell.ExtAttr = Cell.Spare = 0;
  Cell.Attr    =  (byBackground << 4) | byForeground;
  VioWrtNCell((PBYTE)&Cell,pVio->usPsWidth * pVio->usPsDepth,0,0,pVio->hpsVio);
  VioSetOrg(0,0,pVio->hpsVio);
  VioSetCurPos(0,0,pVio->hpsVio);

  /*
  ** Zero the scroll bars.
  */
  WinSendMsg(WinWindowFromID(pstThd->hwndFrame,FID_VERTSCROLL),
             SBM_SETPOS,
             MPFROMSHORT(0),
             MPFROMSHORT(0));

  WinSendMsg(WinWindowFromID(pstThd->hwndFrame,FID_HORZSCROLL),
             SBM_SETPOS,
             MPFROMSHORT(0),
             MPFROMSHORT(0));

  WinSendMsg(WinWindowFromID(pstThd->hwndFrame,FID_VERTSCROLL),
              SBM_SETTHUMBSIZE,
              MPFROM2SHORT(pVio->usWndWidth,pVio->usPsWidth),
              (MPARAM)NULL);

  WinSendMsg(WinWindowFromID(pstThd->hwndFrame,FID_HORZSCROLL),
              SBM_SETTHUMBSIZE,
              MPFROM2SHORT(pVio->usWndDepth,pVio->usPsDepth),
              (MPARAM)NULL);

  }
示例#7
0
/* --------------------------------------------------------------------------
 Clear the screen.
- Parameters -------------------------------------------------------------
 ULONG attribute : foreground/background colors attribute.
- Return value -----------------------------------------------------------
 BOOL : TRUE/FALSE (success/error).
-------------------------------------------------------------------------- */
BOOL screenClear(ULONG attribute) {
   CHAR buf[4];
   buf[0] = ' ';
   buf[1] = attribute;
   if (VioScrollUp(0, 0, 0xffff, 0xffff, 0xffff, buf, 0))
      return FALSE;
   VioSetCurPos(0, 0, 0);
   return TRUE;
}
示例#8
0
/* --------------------------------------------------------------------------
 Display a menu of choices, returning the ordinal (0 based) of the selected
 choice.
- Parameters -------------------------------------------------------------
 INT iRow      : line position (0 = top of screen, -1 = current position).
 PSZ pszPrompt : prompt message.
 PSZ choices   : array of choice characters (max 5 characters).
 PMENUFN pfunc : optional callback function used when the menu has a
                 'retry' item. When pfunc() returns FALSE the loop is
                 terminated.
 PVOID pparm   : optional pfunc() parameters.
- Return value -----------------------------------------------------------
 ULONG : number of the selected choice.
- Note: ------------------------------------------------------------------
 If pszPrompt is NULL the area where the prompt message is printed is
 cleared and no other action is performed.
-------------------------------------------------------------------------- */
ULONG showMenu(PSZ pszPrompt, PSZ choices) {
   CHAR achscr[1760];
   CHAR achmenu[1760];
   CHAR buf[4];
   ULONG key;
   USHORT row, col, irow, cb;
   PSZ pChoice, pLine, pEnd;

   buf[0] = ' ';
   buf[1] = VIOB_GRAY | VIOF_DARKBLUE;
   DosBeep(220, 50);
   DosBeep(440, 50);
   DosBeep(880, 50);
   cb = sizeof(achscr);
   VioReadCellStr(achscr, &cb, 7, 0, 0);
   VioScrollUp(7, 0, 17, 80, 11, buf, 0);
   sprintf(achmenu, pszPrompt,
           choices[0], choices[1], choices[2], choices[3], choices[4]);
   VioGetCurPos(&row, &col, 0);
   for (pLine = pEnd = achmenu, irow = 8; pEnd; ++irow)
   {
      if (NULL != (pEnd = strchr(pLine, '\r')))
      {
         *pEnd = '\0';
         if (*++pEnd == '\n') ++pEnd;
      }
      // skip empty lines
      if (*pLine)
         VioWrtCharStrAtt(pLine, strlen(pLine), irow, 0, buf + 1, 0);
      pLine = pEnd;
   }
   VioSetCurPos(irow, 0, 0);
//   VioWrtCharStrAtt(pszPrompt, strlen(pszPrompt), 8, 0, buf + 1, 0);
   for (;;)
   {
      key = kbdKeyChar(kbdKey()) & ~0x20;
      if (NULL != (pChoice = strchr(choices, (INT)key)))
         break;
      DosBeep(440, 100);
   }
   VioWrtCellStr(achscr, cb, 7, 0, 0);
   VioSetCurPos(row, col, 0);
   return (ULONG)(pChoice - choices);
}
示例#9
0
void PDC_gotoyx(int row, int col)
{
    PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));

#ifdef EMXVIDEO
    v_gotoxy(col, row);
#else
    VioSetCurPos(row, col, 0);
#endif
}
示例#10
0
int MLE_edit(PMLE pmle)
{
int K_TYPE;
int K_CODE;
int rc,i;
USHORT x,y;
   if (mAcurs !=&Ins[pmle->ins])
      {
      mAcurs =&Ins[pmle->ins];
      VioSetCurType(&Ins[pmle->ins],hvio);
      }


   rc=1;
   while (rc)
      {
      x=pmle->cursor % pmle->width;         // положение курсора
      y=pmle->cursor / pmle->width;         // в окне
      VioSetCurPos(pmle->luy+y,pmle->lux+x,hvio);

      Kbd_Wait();
      K_TYPE = Kbd_GetType();
      K_CODE = Kbd_GetCode();

      if (K_TYPE==KBD_ASCII)
         {
         if (EDO_allow((EDO *)pmle,K_CODE)!=FLG_YES && EDO_deny((EDO *)pmle,K_CODE)==FLG_YES)
            {
            DosBeep(500,50);
            continue;
            }
         else
            {
            K_CODE=EDO_filtr((EDO *)pmle,K_CODE);
            if (!K_CODE)
               {
               DosBeep(500,50);
               continue;
               }
            rc=MLE_edit_ascii(K_CODE,pmle);
            }
         }
      else
         if (K_CODE !=ESC)
            rc=MLE_edit_control(K_CODE,pmle);
         else
            rc=0;

      if (rc == 1)
         MLE_reload(pmle);
      else if (rc==-1)
         DosBeep(400,50);
      }
   return K_CODE;
}
示例#11
0
static void hb_gt_os2_SetCursorPosition( int iRow, int iCol )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_os2_SetCursorPosition(%d, %d)", iRow, iCol ) );

   if( s_iCurRow != iRow || s_iCurCol != iCol )
   {
      VioSetCurPos( ( USHORT ) iRow, ( USHORT ) iCol, 0 );
      s_iCurRow = iRow;
      s_iCurCol = iCol;
   }
}
示例#12
0
void vm_gotoxy(char x, char y)
{
    if (_osmode == DOS_MODE)
    {
        vi_init();
        v_gotoxy((int)(x - 1), (int)(y - 1));
    }
    else
    {
        VioSetCurPos((USHORT) (y - 1), (USHORT) (x - 1), 0);
    }
}
示例#13
0
文件: aaos2.c 项目: JohnChu/Snoopy
static void os2vio_uninit(aa_context * c)
{
  BYTE bCell[2];
  
  bCell[0] = 0x20;
  bCell[1] = ( WM_BLACK << 4 ) + WM_PALEGRAY;
  
  VioScrollDn(TOP_ROW,LEFT_COL,0xFFFF,0xFFFF,0xFFFF,bCell,(HVIO) 0);
  VioSetMode(&oldMode, (HVIO) 0);
  VioSetCurPos(0, 0, (HVIO)0);
  VioSetCurType(&oldCurInfo, (HVIO)0);
}
示例#14
0
/* --------------------------------------------------------------------------
 Print an error message to the standard error output and to the log file.
- Parameters -------------------------------------------------------------
 PSZ pszMsg  : message to be printed.
 ULONG cbMsg : length of the message.
- Return value -----------------------------------------------------------
 VOID
-------------------------------------------------------------------------- */
VOID printError(PSZ pszMsg, ULONG cbMsg) {

   if (!(g.mode & FSJQUIET))
   {
      if (g.mode & FSJ_RUNNING) VioSetCurPos(20, 0, 0);
      DosPutMessage((HFILE)2, cbMsg, pszMsg);
   }
   if (FMO_ERROR != g.hfLog)
   {
      pszMsg[cbMsg++] = '\r', pszMsg[cbMsg++] = '\n';
      DosPutMessage(g.hfLog, cbMsg, pszMsg);
   }
}
示例#15
0
void UIAPI uioncursor( void )
/****************************/
{
    CHAR                CharCellPair[2];
    VIOCURSORINFO       vioCursor;


    VioGetCurType( &vioCursor, 0 );
    if( UIData->cursor_type == C_INSERT ) {
        vioCursor.yStart = vioCursor.cEnd / 2;
    } else {
        vioCursor.yStart = (vioCursor.cEnd * 7) / 8;
    }
    vioCursor.cx = 1;
    vioCursor.attr = 1;

    VioSetCurType(&vioCursor, 0);


    /* set cursor position */

    VioSetCurPos( UIData->cursor_row, UIData->cursor_col, 0);

    if( UIData->cursor_attr != -2 ) {
    /* get current character and attribute */

        VioGetCurPos( &r, &c, 0 );
        length = sizeof(CharCellPair);
        VioReadCellStr(&CharCellPair[0],
                       &length,
                       UIData->cursor_row,
                       UIData->cursor_col,
                       0);

        /* write out the character and the new attribute */
        CharCellPair[1] = UIData->cursor_attr;
        VioWrtNCell((PBYTE)&CharCellPair[0],
                    24,
                    UIData->cursor_row,
                    UIData->cursor_col,
                    0);

    }
    UIData->cursor_on = true;
}
示例#16
0
int tty_setsize (struct winsize *ws)
{
  USHORT cx, cy;
  VIOMODEINFO vi;
  vi.cb = sizeof (vi);
  VioGetMode(&vi, 0);

  VioGetCurPos (&cx, &cy, 0);

  vi.col = ws->ws_col;
  vi.row = ws->ws_row;
  vi.cb = sizeof (vi.cb) + sizeof (vi.fbType) + sizeof (vi.color) +
          sizeof (vi.col) + sizeof (vi.row);
  VioSetMode (&vi, 0);

  VioSetCurPos (cx, cy, 0);
  return 0;
}
示例#17
0
static void 
vio_CM (int row, int col)
{
  USHORT o_row, o_col;

  c_row = row;
  c_col = col;

  /*
   * Don't move the cursor if it's already in the right place.  We
   * want to avoid any weird flickering that might result if moving 
   * the cursor resets its blink timer.
   */
  VioGetCurPos (&o_row, &o_col, 0);
  if (o_row != c_row || o_col != c_col)
    {
      VioSetCurPos (c_row, c_col, 0);
    }
}
示例#18
0
/* --------------------------------------------------------------------------
 Print a text message on the screen and on standard output.
- Parameters -------------------------------------------------------------
 LONG irow : row position of the message. If this is < 0 the cursor
              position is not changed.
 PSZ pszMsg : text message with formatting tags.
 ...        : variable number of parameters.
- Return value -----------------------------------------------------------
 VOID
-------------------------------------------------------------------------- */
VOID printMsg(ULONG irow, PSZ pszMsg, ...) {
   CHAR buf[CBMSG_BUF];
   ULONG cb;
   va_list ap;

   va_start(ap, pszMsg);
   cb = vsprintf(buf, pszMsg, ap);
   va_end(ap);
   cb +=sprintf(buf + cb, "\r\n");
   if (!(g.mode & FSJQUIET))
   {
      if (irow > 0)
      {
         VioScrollUp(irow, 0, irow + 5, 80, 6, " \x00", 0);
         VioSetCurPos(irow, 0, 0);
      }
      DosPutMessage((HFILE)1, cb, buf);
   }
   if (g.hfLog) DosPutMessage(g.hfLog, cb, buf);
}
示例#19
0
VOID SetScreenColors(THREAD *pstThd)
  {
  VIOCELL Cell;
  VIOPS *pVio = &pstThd->stVio;
  WORD wRow;
  WORD wColumn;
  BYTE byBackground;
  BYTE byForeground;


  byBackground = ClrTable[pVio->wBackground].PSClr;
  byForeground = ClrTable[pVio->wForeground].PSClr;

  Cell.ExtAttr = Cell.Spare = 0;
  Cell.Attr    =  (byBackground << 4) | byForeground;

  DosEnterCritSec();
  VioGetCurPos(&wRow,&wColumn,pVio->hpsVio);
  VioWrtNAttr((PBYTE)&Cell.Attr,pVio->usPsWidth * pVio->usPsDepth,0,0,pVio->hpsVio);
  VioSetCurPos(wRow,wColumn,pVio->hpsVio);
  DosExitCritSec();
  }
示例#20
0
文件: cls.c 项目: ErisBlastar/osfree
int main(int argc,char *argv[])
{
  BYTE bCell[2];                       /* Char/Attribute array       */

 if ((argc>1)&&((argv[1][0]==PARAM_CHAR1) || (argv[1][0]==PARAM_CHAR2)))
 {
  if ((argv[1][1]=='?')&& (argv[1][2]=='\0'))
  {
    cmd_ShowSystemMessage(cmd_MSG_CLS_HELP,0L);
    return NO_ERROR;
  } else
  {
    cmd_ShowSystemMessage(MSG_BAD_SYNTAX,0L);
    return 1;
  };
 };
  bCell[0] = 0x20;                     /* Space Character            */
  bCell[1] = 0x07;                     /* Default Attrib             */
  VioScrollDn( 0, 0, (USHORT)0xFFFF, (USHORT)0XFFFF,
                     (USHORT)0xFFFF, bCell, (HVIO) 0);/* CLS         */
  VioSetCurPos(0, 0, (HVIO) 0);        /*                Pos cursor  */

  return NO_ERROR;
};
示例#21
0
void vm_gotoxy(char x, char y)
{
    VioSetCurPos((USHORT) (y - 1), (USHORT) (x - 1), 0);
}
示例#22
0
int ConSetCursorPos(int X, int Y) {
  VioSetCurPos((USHORT)Y, (USHORT)X, 0);
  return 0;
}
示例#23
0
文件: wrap.c 项目: ErisBlastar/osfree
USHORT __pascal VIOSETCURPOS(const USHORT Row, const USHORT Column, const HVIO Handle)
{
  return VioSetCurPos(Row, Column, Handle);
}
uint  ExcepDialogFunction( DIALOGSHELL *shell, DIALOGCHOICE *ptr,
                           EVENT *nEvent, void *ParamBlock )
{
  uint   fldcol;
  uchar  *pExcepMap;                    /* Pointer to exception map.         */
  int    SelectIndex;                   /* Index into exception map array.   */

  SelectIndex = shell->CurrentField + ptr->SkipRows - 1;
  pExcepMap = LocalExcepMap + SelectIndex;
  for( ;; )
  {
    switch( nEvent->Value )
    {
      case INIT_DIALOG:
      {
        /*********************************************************************/
        /* This message is sent before displaying elements in display area.  */
        /* It is to initialise the locals in the dialog function.            */
        /*  - Make a copy of the global exception map.                       */
        /*  - Set the field cursor and variables to the first field.         */
        /*  - Set the length of the field highlite bar in normal and hilite  */
        /*    arrays (used in the call to putrc).                            */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        memcpy( LocalExcepMap, ExceptionMap, MAXEXCEPTIONS );
        fldcol = shell->col + 2;
        VioSetCurPos( (short)(shell->row + shell->SkipLines +
                       shell->CurrentField - 1), (short)fldcol, 0 );
        fld = ExpField;

        hilite[1] = normal[1] = (UCHAR)VATTLENGTH - 4;
        return( 0 );
      }

      case ENTER:
      {
        /*********************************************************************/
        /* This message is sent if the user clicks on the ENTER button or    */
        /* presses the ENTER key.                                            */
        /*  - Copy the local excetion map to the global exception map.       */
        /*  - Return non zero value to denote the end of dialog processing.  */
        /*********************************************************************/
        ptr->SkipRows = 0;
        memcpy( ExceptionMap, LocalExcepMap, MAXEXCEPTIONS );
        return( ENTER );
      }

      case F1:
      {
        uchar  *HelpMsg;

        HelpMsg = GetHelpMsg( HELP_DLG_EXCEPTIONS, NULL,0 );
        CuaShowHelpBox( HelpMsg );
        return( 0 );
      }

      case ESC:
      case F10:
      {
        /*********************************************************************/
        /* This message is sent if the user clicks on the CANCEL button or   */
        /* presses the ESC/F10 keys.                                         */
        /*  - Return non zero value to denote the end of dialog processing.  */
        /*********************************************************************/
        ptr->SkipRows = 0;
        return( nEvent->Value );
      }

      case MOUSEPICK:
      {
        /*********************************************************************/
        /* This message is sent if the clicks in the dialog display area.    */
        /*  - Determine on which field the user clicked.                     */
        /*  - Set the cursor on that field.                                  */
        /*  - If the field turns out to be notify field,                     */
        /*     - Set the event value as SPACEBAR (simulate) and stay in the  */
        /*       outer for loop to process SPACEBAR.                         */
        /*    Else                                                           */
        /*     - Return zero to denote continue dialog processing.           */
        /*********************************************************************/
        if( ((uint)nEvent->Col >= (shell->col + 2 + VATTLENGTH)) &&
            ((uint)nEvent->Col < (shell->col+ 2 + VATTLENGTH + NOTIFYMSGWIDTH)))
        {
           fldcol = shell->col+ 2 + VATTLENGTH;
           fld = NotifyField;
        }
        else
        {
           fldcol = shell->col+2;
           fld = ExpField;
        }

        VioSetCurPos( (short)(shell->row + shell->SkipLines +
                       shell->CurrentField - 1), (short)fldcol, 0 );

        if( fld == NotifyField )
        {
          nEvent->Value = SPACEBAR;
          continue;
        }

        return( 0 );
      }

      case key_R:
      case key_r:
      {
        /*********************************************************************/
        /* This message is sent if the user clicks in the RESET button or    */
        /* presses 'R' / 'r' keys.                                           */
        /*  - Reset the current exception notification to default.           */
        /*  - Display the new notification value in the field.               */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        *pExcepMap = DefExcepMap[ SelectIndex ];
        putrc( shell->row + shell->SkipLines + shell->CurrentField - 1,
               shell->col + 2 + VATTLENGTH, ExcepSel[*pExcepMap] );
        return( 0 );
      }

      case key_D:
      case key_d:
      {
        /*********************************************************************/
        /* This message is sent if the user clicks in the DEFAULT button or  */
        /* presses 'D' / 'd' keys.                                           */
        /*  - Copy the default exception map to the local exception map.     */
        /*  - Redisplay the display area of the dialog.                      */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        memcpy( LocalExcepMap, DefExcepMap, MAXEXCEPTIONS );
        DisplayExcepChoice( shell, ptr );
        return( 0 );
      }

      case key_S:
      case key_s:
      {
        /*********************************************************************/
        /* This message is sent if the user clicks on the SAVE button or     */
        /* presses the 'S' / 's' keys.                                       */
        /*  - Find the fully qualified file name for the .pro                */
        /*  - Call function to save the exceptions.                          */
        /*  - If not successfull in saving exceptions, display the error box */
        /*    with appropriate error message.                                */
        /*  - If successfull display a timmed message and copy the local     */
        /*    exception map to the default exception map.                    */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        uchar  StatusMsg[100];
        uchar  fn[MAXFNAMELEN];
        int    rc;

        findpro( "SD386.PRO", fn, MAXFNAMELEN );
        rc = SaveExceptions( fn );
        if( rc )
        {
          if( rc == FILENOTFOUND )
            sprintf( StatusMsg, "Unable to find \"SD386.PRO\" in DPATH" );
          else
            sprintf( StatusMsg, "Unable to save to profile \"%s\"", fn );
        }
        else
        {
          sprintf( StatusMsg, "Saving Exceptions to profile \"%s\"", fn );
          memcpy( ExceptionMap, LocalExcepMap, MAXEXCEPTIONS );
        }
        SayMsgBox2( StatusMsg, 1200UL );
        VioSetCurType( &NormalCursor, 0 );
        return( 0 );
      }

      case RIGHT:
      case TAB:
      {
        /*********************************************************************/
        /* This message is sent if the user presses TAB or right arrow  key.*/
        /*  - Depending on the current field determine to which field we have*/
        /*    to move to the right or loop around.                           */
        /*  - Set the field variables.                                       */
        /*  - Set the cursor position.                                       */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        switch( fld )
        {
          case ExpField:
          {
            fldcol = shell->col + 2 + VATTLENGTH;
            fld    = NotifyField;
            break;
          }

          case NotifyField:
          {
            fldcol = shell->col + 2;
            fld    = ExpField;
            break;
          }
        }
        VioSetCurPos( (short)(shell->row + shell->SkipLines +
                       shell->CurrentField - 1), (short)fldcol, 0 );
        return( 0 );
      }

      case LEFT:
      case S_TAB:
      {
        /*********************************************************************/
        /* This message is sent if the user presses SHIFT TAB or left arrow  */
        /*  key.                                                            */
        /*  - Depending on the current field determine to which field we have*/
        /*    to move to the left or loop around.                            */
        /*  - Set the field variables.                                       */
        /*  - Set the cursor position.                                       */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        switch( fld )
        {
          case ExpField:
          {
            fldcol = shell->col + 2 + VATTLENGTH;
            fld    = NotifyField;
            break;
          }

          case NotifyField:
          {
            fldcol = shell->col + 2;
            fld    = ExpField;
            break;
          }
        }
        VioSetCurPos( (short)(shell->row + shell->SkipLines +
                       shell->CurrentField - 1), (short)fldcol, 0 );
        return( 0 );
      }

      case SPACEBAR:
      {
        /*********************************************************************/
        /* This message is sent if the user presses the SPACEBAR.            */
        /*  - Toggle the notification value of the current field.            */
        /*  - Display the new notification value in the field.               */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        pExcepMap = LocalExcepMap + SelectIndex;
        *pExcepMap = (uchar)(*pExcepMap + 1);
        if( *pExcepMap > 1 )
          *pExcepMap  = 0;

        ClearField[1] = NOTIFICATION;
        putrc( shell->row + shell->SkipLines + shell->CurrentField - 1,
               shell->col + 2 + VATTLENGTH, ClearField );
        putrc( shell->row + shell->SkipLines + shell->CurrentField - 1,
               shell->col + 2 + VATTLENGTH, ExcepSel[*pExcepMap] );
        return( 0 );
      }

      case UP:
      case DOWN:
      case SCROLLUP:
      case SCROLLDOWN:
      case SCROLLBAR:
      {
        /*********************************************************************/
        /* These messages are sent if the user presses up  or down  arrow  */
        /* keys or the user clicks on the  or  in the scrollbar.           */
        /*  - Set the field variables.                                       */
        /*  - Set the cursor position.                                       */
        /*  - Return zero to denote continue dialog processing.              */
        /*********************************************************************/
        switch( fld )
        {
          case ExpField:
          {
            fldcol = shell->col + 2;
            break;
          }

          case NotifyField:
          {
            fldcol = shell->col + 2 + VATTLENGTH;
            break;
          }
        }

        VioSetCurPos( (short)(shell->row + shell->SkipLines +
                       shell->CurrentField - 1), (short)fldcol, 0 );
        return( 0 );
      }

      default:
        /*********************************************************************/
        /* Any other message.                                                */
        /* - Return zero to denote continue dialog processing.               */
        /*********************************************************************/
        return( 0 );
    }
  }
}
示例#25
0
文件: aaos2.c 项目: JohnChu/Snoopy
static void os2vio_gotoxy(aa_context * c, int x, int y)
{
  VioSetCurPos(y, x, (HVIO)0);
}
uint GetString( uint FieldRow, uint FieldCol, uint length, uint displen,
                uint *cursor, uchar *pInbuf, uint InFlags, POPUPSHELL *pShell)
{
  /***************************************************************************/
  /* Diagram to explain local variables.                                     */
  /*                                                                         */
  /*  0  ...     10        ...                   40       ...          200   */
  /*                                                                         */
  /*             +-------------------------------+                           */
  /*  +----------|                               |---------------------+     */
  /*  |          |  Portion of the string shown  |                     |     */
  /*  |          |  in the screen.               |                     |     */
  /*  +----------|                               |---------------------+     */
  /*             +-------------------------------+                           */
  /*             |<---- Display Length --------->|                           */
  /*                                                                         */
  /*  |<------------ length (length of the entire buffer) ------------>|     */
  /*                                                                         */
  /*   In the above example:                                                 */
  /*                                                                         */
  /*   length            ===>  200                                           */
  /*   DisplayLength     ===>  30                                            */
  /*   DisplayOffset     ===>  10                                            */
  /*                                                                         */
  /***************************************************************************/
  uint        key;
  int         n, i;
  ushort      rc;
  int         voff;
  uint        IsInsertMode = 0, scratch, BufLen;
  uint        DisplayOffset;
  uint        CursorRow, CursorCol;
  int         FirstKeyEntry = TRUE;                                     /*910*/
  uint        flags = InFlags;                                          /*910*/
  int         state = MOU_STATE_UP; /* assume this! */                  /*910*/
  int         NextState = 0;                                            /*910*/
  BUTTON     *pButtonDown = NULL;                                       /*910*/

  /***************************************************************************/
  /*                                                                         */
  /* flags  - Flags which indicate type of the field.                        */
  /*          (AUTOEXIT / HEXONLY / BINONLY)                                 */
  /***************************************************************************/
  if(pShell)
   flags = pShell->Flags;                                               /*910*/

  /***************************************************************************/
  /* - Set keyboard flush buffer flag to indiacte not to flush the keyboard  */
  /*   buffer while we are in getstring.                                     */
  /* - Initialise the local variables.                                       */
  /***************************************************************************/
  SetFlushBufferFlag( NOFLUSHNOW );                                     /*820*/
  FieldDisplayLength = displen;
  DisplayOffset = 0;
  CursorRow = FieldRow;

  CursorCol = ( *cursor > displen ) ? FieldCol : FieldCol + *cursor;

#ifdef MSH
  if(iview) {
    CursorRow+=RowStart;
    FieldRow+=RowStart;
    CursorCol+=ColStart;
    FieldCol+=ColStart;
  }
#endif

  /***************************************************************************/
  /* Allocate memory for the local buffer.                                   */
  /***************************************************************************/
  Buffer = (uchar *)Talloc( (length+1) * sizeof( uchar ) );
  memset( Buffer, '\0', length+1 );
  if(!iview) {
  /***************************************************************************/
  /* Adjust display length if the length specified by the caller goes out of */
  /* the screen.                                                             */
  /***************************************************************************/
  if( FieldCol + FieldDisplayLength > VideoCols )
    FieldDisplayLength = VideoCols - FieldCol;

  /***************************************************************************/
  /* Check to see if the field would over lap some other window, if so adjust*/
  /* the display length accordingly.                                         */
  /***************************************************************************/
  if( FieldDisplayLength + FieldCol > BoundPtr[FieldRow] )
    FieldDisplayLength = BoundPtr[FieldRow] - FieldCol;
  }
  else
  {
#ifdef MSH
      if( FieldDisplayLength + FieldCol - ColStart> VideoWidth )
        FieldDisplayLength = VideoWidth - FieldCol + ColStart;
#endif

  }/* End if*/
  /***************************************************************************/
  /* RightScrollOffset is the amount of scrolling to be done when the user   */
  /* goes out of the display length. It is 2/3 rds of the display length.    */
  /***************************************************************************/
  RightScrollOffset  = (FieldDisplayLength * 2)/3;
  LeftScrollOffset   = FieldDisplayLength - RightScrollOffset;

  FieldBase = (uchar *)Sel2Flat( HiFlat(VideoPtr) ) +
              ( voff = 2*(FieldRow*VideoCols + FieldCol) );
  FieldType = flags;

  /***************************************************************************/
  /* Depending on the type of the string copy the initial string to the local*/
  /* buffer. Display the string.                                             */
  /***************************************************************************/
  if( (FieldType & HEXONLY) || (FieldType & BINONLY) )
  {
    for( i = 0; i < length; i++ )
      Buffer[i] = FieldBase[i*2];
  }
  else
    strcpy( Buffer, pInbuf );

  DisplayField( DisplayOffset );
  VioShowBuf( (ushort)voff,(ushort) (2*FieldDisplayLength), 0 );

  VioSetCurType( &NormalCursor, 0 );

  for(;;)
  {
    VioSetCurPos( (ushort)CursorRow, (ushort)CursorCol, 0 );

    Event = GetEvent( SEM_INDEFINITE_WAIT );

    switch( Event->Type )
    {
      case TYPE_MOUSE_EVENT:                                            /*910*/
      {                                                                 /*910*/
       /******************************************************************910*/
       /* Test for mouse event between the string brackets.               910*/
       /******************************************************************910*/
       if( ( Event->Row == (ushort)FieldRow ) &&                        /*910*/
           ( Event->Col >= (ushort)FieldCol ) &&                        /*910*/
           ( Event->Col <= ((ushort)FieldCol+(ushort)FieldDisplayLength-1))
         )                                                              /*910*/
       {                                                                /*910*/
        /*****************************************************************910*/
        /* - If it's a button down event then set the cursor at the       910*/
        /*   end of the string or on the character that was clicked on.   910*/
        /*****************************************************************910*/
        if( Event->Value == EVENT_BUTTON_1_DOWN)                        /*910*/
        {                                                               /*910*/
          BufLen = strlen( Buffer );                                    /*910*/
          if( (DisplayOffset + (Event->Col - FieldCol)) > BufLen )      /*910*/
          {                                                             /*910*/
            keybeep();                                                  /*910*/
            CursorCol = FieldCol + (BufLen - DisplayOffset);            /*910*/
          }                                                             /*910*/
          else                                                          /*910*/
            CursorCol = (uint)Event->Col;                               /*910*/
        }                                                               /*910*/
        /*****************************************************************910*/
        /* - Ignore events between the brackets that are not button       910*/
        /*   down events.                                                 910*/
        /* - Any mouse event between []s turns off the erasure of a       910*/
        /*   cursor sensitive prompt.                                     910*/
        /*****************************************************************910*/
        FieldType &= ~CLEAR1ST;                                         /*910*/
        continue;                                                       /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       /**********************************************************************/
       /* - handle strings that are not in the context of a popup.           */
       /**********************************************************************/
       if(pShell == NULL )                                              /*910*/
       {                                                                /*910*/
        NextState = GetMouseState( Event );                             /*910*/
        if( (state == MOU_STATE_UP) &&                                  /*910*/
            (NextState == MOU_STATE_DOWN)                               /*910*/
          )                                                             /*910*/
        {                                                               /*910*/
         key = LEFTMOUSECLICK;                                          /*910*/
         break;                                                         /*910*/
        }                                                               /*910*/
                                                                        /*910*/
        state = NextState;                                              /*910*/
        continue;                                                       /*910*/
       }                                                                /*910*/
       /******************************************************************910*/
       /* - Now, handle mouse events outside the []s within the context   910*/
       /*   of a popup.                                                   910*/
       /*                                                                 910*/
       /* - Button events are valid on the release event.                 910*/
       /*                                                                 910*/
       /* - Transitions from up to down "outside" the <>s and []s         910*/
       /*   are returned to the caller as a LEFTMOUSECLICK.               910*/
       /*                                                                 910*/
       /*  ------------------------                                       910*/
       /* |                        |                                      910*/
       /* |                       -----------                             910*/
       /* |         <------------|           |<----------------           910*/
       /* |        |              -----------                  |          910*/
       /* |      ----                                        ----         910*/
       /* |     |    |---                                ---|    |---     910*/
       /* |     | UP |   | BU,BUM                BD,BDM |   | DN |   |    910*/
       /* |     |    |<--                                -->|    |<--     910*/
       /* |      ----                                        ----         910*/
       /* |        |                                           |          910*/
       /* |        |                                           |          910*/
       /* |        |              -----------                  |          910*/
       /* |         ------------>|           |---------------->           910*/
       /* |                       -----------                             910*/
       /* |                               |                               910*/
       /* |                               |                               910*/
       /* | BU  - Button up event.        |                               910*/
       /* | BUM - Button up move event.    -(1) If BD or BDM event        910*/
       /* | BD  - Button down event.            occurs in a button(<>s),  910*/
       /* | BDM - Button down move event.       then set pButtonDown      910*/
       /* |                                     to point to the BUTTON    910*/
       /* |                                     structure. This is        910*/
       /* |                                     effectively a "pending"   910*/
       /*  ----(1) If BU or BUM event           button event. If the      910*/
       /*          && if the event occurs       up event occurs within    910*/
       /*          in the same button as        the same <>s, then we've  910*/
       /*          a "pending" button           got ourselves a valid     910*/
       /*          then we have a button        button event.             910*/
       /*          event.                                                 910*/
       /*                                   (2) If BD or BDM do not       910*/
       /*                                       occur within a button,    910*/
       /*                                       then set pButtonDown=NULL 910*/
       /*                                       and go back to the        910*/
       /*                                       caller with a             910*/
       /*                                       LEFTMOUSECLICK.           910*/
       /*                                                                 910*/
       /******************************************************************910*/
       NextState = GetMouseState( Event );                              /*910*/
       if( (state == MOU_STATE_DOWN) &&                                 /*910*/
           (NextState == MOU_STATE_UP) &&                               /*910*/
           (pButtonDown != NULL) &&                                     /*910*/
           (pButtonDown == GetButtonPtr(pShell,Event))                  /*910*/
         )                                                              /*910*/
       {                                                                /*910*/
        key = pButtonDown->Key;                                         /*910*/
        break;                                                          /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       if( (state == MOU_STATE_UP) &&                                   /*910*/
           (NextState == MOU_STATE_DOWN)                                /*910*/
         )                                                              /*910*/
       {                                                                /*910*/
        pButtonDown = GetButtonPtr( pShell,Event);                      /*910*/
        if( pButtonDown == NULL )                                       /*910*/
        {                                                               /*910*/
         key = LEFTMOUSECLICK;                                          /*910*/
         break;                                                         /*910*/
        }                                                               /*910*/
       }                                                                /*910*/
                                                                        /*910*/
       state = NextState;                                               /*910*/
       continue;                                                        /*910*/
      }

      case TYPE_KBD_EVENT:
      {
        key = Event->Value;
        break;
      }
    }

    if( (FieldType & CLEAR1ST) && (FirstKeyEntry == TRUE) )             /*910*/
     FirstKeyEntry = FALSE;                                             /*910*/

    switch( key )
    {
      case F1:
      case ESC:
      case ENTER:
      case UP:
      case DOWN:
      case A_ENTER:
      case MOUSECLICK:
      /***********************************************************************/
      /* - these keys are specific to the watchpoint dialog.              910*/
      /***********************************************************************/
      case TYNEXT:                      /* watchpoint type button.        910*/
      case SPNEXT:                      /* watchpoint scope button.       910*/
      case SZNEXT:                      /* watchpoint size button.        910*/
      case STNEXT:                      /* watchpoint status button.      910*/
      {
        /*********************************************************************/
        /* All the above keys cannot be proccessed by getstring, so return   */
        /* the key to the caller.                                            */
        /*********************************************************************/
        rc = RCBREAK;
        break;
      }

      case C_HOME:
      {
        /*********************************************************************/
        /* Control-Home takes you to the start of the string.                */
        /*********************************************************************/
        DisplayOffset = 0;
        CursorCol = FieldCol;
        rc = RCREDRAW;
        break;
      }

      case C_END:
      {
        /*********************************************************************/
        /* Control-End takes you to the end of the string (to the last char  */
        /* the user has types in).                                           */
        /*********************************************************************/
        BufLen = strlen( Buffer );
        if( BufLen > FieldDisplayLength )
        {
          DisplayOffset = BufLen - FieldDisplayLength;
          CursorCol = FieldCol + FieldDisplayLength - 1;
        }
        else
        {
          DisplayOffset = 0;
          CursorCol = FieldCol + BufLen;
        }
        rc = RCREDRAW;
        break;
      }

      case TAB:
      case S_TAB:
      {
        /*********************************************************************/
        /* If the user has keyed in a tab  and the field type is AUTOEXIT,   */
        /* return to the caller.                                             */
        /*********************************************************************/
        if( FieldType & AUTOEXIT )
          rc = RCBREAK;
        else
        {
          keybeep();
          rc = 0;
        }
        break;
      }

      case LEFT:
      {
        /*********************************************************************/
        /* The user has pressed the left arrow key.                          */
        /*  - If the cursor is not in the starting column move the cursor    */
        /*    one column to the left.                                        */
        /*********************************************************************/
        if( CursorCol > FieldCol )
        {
          CursorCol--;
          rc = 0;
        }
        else
        {
          /*******************************************************************/
          /* If the cursor is in the starting column, a non zero value in the*/
          /* display offset would indicate we have some characters to the    */
          /* left to be displayed (see diagram above). If you have enough    */
          /* characters to scroll to LeftScrollOffset amount, do so. If not  */
          /* scroll to the start of the string.                              */
          /*******************************************************************/
          if( DisplayOffset )
          {
            if( (int)(DisplayOffset - LeftScrollOffset) >= 0 )
            {
              DisplayOffset -= LeftScrollOffset;
              CursorCol += (LeftScrollOffset - 1);
            }
            else
            {
              CursorCol += DisplayOffset;
              DisplayOffset = 0;
            }
            rc = RCREDRAW;
          }
          else
          {
            if( FieldType & AUTOEXIT )
              rc = RCBREAK;
            else
            {
               keybeep();
               rc = 0;
            }
          }
        }
        break;
      }

      case RIGHT:
      {
        /*********************************************************************/
        /* The user has pressed the right arrow key.                         */
        /*  - If the cursor is not in the ending column of display and not   */
        /*    end of the string, move the cursor one column to the right.    */
        /*********************************************************************/
        BufLen = strlen( Buffer );
        if( CursorCol < ( FieldCol + FieldDisplayLength - 1 ) )
        {
          if( (DisplayOffset + (CursorCol - FieldCol)) < BufLen )
          {
            CursorCol++;
            rc = 0;
          }
          else
          {
            keybeep();
            rc = 0;
          }
        }
        else
        {
          /*******************************************************************/
          /* If the cursor is at the ending column of display, check to see  */
          /* if we are within the buffer length. If we have enough space to  */
          /* scroll by RightScrollOffset amount do so, if not scroll till the*/
          /* end of the string.                                              */
          /*******************************************************************/
          if( DisplayOffset + FieldDisplayLength < BufLen )
          {
            DisplayOffset += (FieldDisplayLength - RightScrollOffset);
            if( (DisplayOffset + (CursorCol - FieldCol)) > BufLen )
              CursorCol = FieldCol + (BufLen - DisplayOffset);
            else
              CursorCol = FieldCol + RightScrollOffset;
            rc = RCREDRAW;
          }
          else
          {
            /*****************************************************************/
            /* If we reached the ending column and the end of the buffer, if */
            /* the field type is AUTOEXIT return to the caller.              */
            /*****************************************************************/
            if( FieldType & AUTOEXIT )
              rc = RCBREAK;
            else
            {
              keybeep();
              rc = 0;
            }
          }
        }
        break;
      }

      case HOME:
      {
        /*********************************************************************/
        /* Home takes to the starting column of the string.                  */
        /*********************************************************************/
        CursorCol = FieldCol;
        break;
      }

      case END:
      {
        /*********************************************************************/
        /* End takes you to the ending column of the string. If the string   */
        /* is not long enough till the ending column of the display, End     */
        /* takes you to the end of the string.                               */
        /*********************************************************************/
        CursorCol = FieldCol + FieldDisplayLength - 1;
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        BufLen = strlen( Buffer );
        if( scratch > BufLen )
          CursorCol = FieldCol + (BufLen - DisplayOffset);
        break;
      }

      case INS:
      {
        /*********************************************************************/
        /* Insert key is pressed. This toggles the InsertMode flag. If the   */
        /* current length of the string is less than the buffer length,      */
        /* InsertMode could be allowed. Set the cusror type accordingly.     */
        /*********************************************************************/
        if( IsInsertMode )
        {
          IsInsertMode = 0;
          VioSetCurType( &NormalCursor, 0 );
        }
        else
        {
          if( length != strlen( Buffer ) )
          {
            IsInsertMode = 1 - IsInsertMode;
            IsInsertMode ? VioSetCurType( &InsertCursor, 0 ) :
                           VioSetCurType( &NormalCursor, 0 );
          }
          else                           /* Display proper error message...   */
            keybeep();
        }
        break;
      }

      case DEL:
      {
        /*********************************************************************/
        /* Delete the current character. The rest of the string is shifted   */
        /* left.                                                             */
        /*********************************************************************/
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        ( scratch < strlen( Buffer ) ) ? ShiftLeft( scratch ) :
                                       keybeep();
        rc = RCREDRAW;
        break;
      }

      case BACKSPACE:
      {
        /*********************************************************************/
        /* The previous character to the cursor is deleted. By default the   */
        /* string is shifted left by one character. But if the cursor is on  */
        /* the starting column then the string is shifted by LeftScrollOffset*/
        /* amount.                                                           */
        /*********************************************************************/
        scratch = DisplayOffset + (CursorCol - FieldCol);
        if( scratch )
        {
          ShiftLeft( scratch - 1 );
          CursorCol--;
          if( CursorCol < FieldCol )
          {
            if( (int)(DisplayOffset - LeftScrollOffset) >= 0 )
            {
              DisplayOffset -= LeftScrollOffset;
              CursorCol += LeftScrollOffset;
            }
            else
            {
              CursorCol += (DisplayOffset + 1);
              DisplayOffset = 0;
            }
          }
        }
        else
          keybeep();
        rc = RCREDRAW;
        break;
      }

      default:
      {
        /*********************************************************************/
        /* Any other character key is pressed. Verify the validity of the    */
        /* character depending on the type of the string (HEX/BIN).          */
        /*********************************************************************/
        key &= 0xFF;
        if( key != 0x15 )
        if( (key < 0x20) || (key > 0x7E) )
        {
          rc = RCBREAK;
          break;
        }

        if( FieldType & HEXONLY )
        {
          if( (key < '0') || (key > '9') )
          {
            key &= 0xDF;
            if( (key < 'A') || (key > 'F') )
            {
              keybeep();
              rc = 0;
              break;
            }
          }
        }

        if( FieldType & BINONLY )
        {
          if( (key != '0') && (key != '1') )
          {
            keybeep();
            rc = 0;
            break;
          }
        }


        if( FieldType & CLEAR1ST )                                      /*910*/
        {                                                               /*910*/
         memset(Buffer,'\0',strlen(Buffer) );                           /*910*/
         *cursor = 0;                                                   /*910*/
         CursorCol = (*cursor > displen)?FieldCol : FieldCol + *cursor; /*910*/
        }                                                               /*910*/

        /*********************************************************************/
        /* Scratch gives you the exact number of characters so far typed in  */
        /* by the user. Accept the last character only if scratch is less    */
        /* than the total length of the string.                              */
        /*********************************************************************/
        scratch = DisplayOffset + ( CursorCol - FieldCol );
        if( scratch < length )
        {
          if( IsInsertMode )
          {
            if( (strlen( Buffer ) + 1) > length )
            {
              keybeep();
              rc = 0;
              break;      /* reject */
            }
            else
               ShiftRight( scratch );
          }

          Buffer[scratch] = ( uchar )key;

          /*******************************************************************/
          /* Adjust the cursor position accordingly so that it stays ahead   */
          /* of the last character.                                          */
          /*******************************************************************/
          if( CursorCol >= (FieldCol + FieldDisplayLength) )
          {
            DisplayOffset += (FieldDisplayLength - RightScrollOffset - 1);
            CursorCol = FieldCol + RightScrollOffset + 2;
          }
          else
            CursorCol++;

          /*******************************************************************/
          /* It the type of the field is AUTOEXIT return to the caller once  */
          /* the buffer is full.                                             */
          /*******************************************************************/
          BufLen = strlen( Buffer );
          if( (BufLen == length) &&
              (FieldType & AUTOEXIT) &&
              ((CursorCol - FieldCol) == FieldDisplayLength) )
            rc = RCREDRAW + RCBREAK + RCDATAXT;
          else
            rc = RCREDRAW;
          break;
        }
        else
        {
          keybeep();
          rc = 0;
          break;
        }
      }
    }

    /*************************************************************************/
    /* - Turn off the clear field flag after any event.                      */
    /*************************************************************************/
    FieldType &= ~CLEAR1ST;                                             /*910*/

   if( rc & RCREDRAW )
   {
     DisplayField( DisplayOffset );
     VioShowBuf( (ushort)voff, (ushort)( 2 * FieldDisplayLength ), 0 );
   }
   if( rc & RCBREAK )
     break;
  }                                     /* end of for loop to handle keystrks*/
    VioSetCurType( &HiddenCursor, 0 );

    /*************************************************************************/
    /* - Copy the local buffer to the caller supplied buffer.                */
    /* - Free the local buffer.                                              */
    /* - Reset the keyboard buffer flush flag.                               */
    /*************************************************************************/
    for( n = 0; n < strlen( Buffer ); n++ )
        *pInbuf++ = Buffer[n];

    *pInbuf = 0;
    *cursor = CursorCol;
    Tfree( Buffer );
    ResetFlushBufferFlag();                                             /*820*/
    return( (rc & RCDATAXT) ? DATAKEY : key );
}
int EditAttributes (FILES *f) {

  char  *buf;
  USHORT len = (vio.col * 7) * 2,curpos = 0;
  char   nattr = (1 << 4) | (7 | 8);
  char   sattr = 8;
  int    ret = 0,x,key;
  BOOL   okay = TRUE;
  char   attrs[5] = "----";

  if(!f)
    return -1;
  buf = malloc(len);
  if(!buf)
    return -1;

  ThreadMsg(" ");

  VioReadCellStr(buf,&len,(vio.row / 2) - 1,0,0);

  VioWrtCharStrAtt("ÚÄ Attributes: Ä¿",17,(vio.row / 2) - 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Readonly: [ ] ³",17,vio.row / 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Hidden:   [ ] ³",17,(vio.row / 2) + 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ System:   [ ] ³",17,(vio.row / 2) + 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Archived: [ ] ³",17,(vio.row / 2) + 3,
                   34,&nattr,0);
  VioWrtCharStrAtt("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ",17,(vio.row / 2) + 4,
                   34,&nattr,0);
  VioWrtNAttr(&sattr,1,vio.row / 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 1,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 3,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 4,51,0);
  VioWrtNAttr(&sattr,16,(vio.row / 2) + 5,36,0);
  if(f->attrFile & FILE_READONLY)
    attrs[0] = 'x';
  if(f->attrFile & FILE_HIDDEN)
    attrs[1] = 'x';
  if(f->attrFile & FILE_SYSTEM)
    attrs[2] = 'x';
  if(f->attrFile & FILE_ARCHIVED)
    attrs[3] = 'x';
  for(x = 0;x < 4;x++)
    VioWrtCharStr(attrs + x,1,x + (vio.row / 2),47,0);
  VioSetCurPos(curpos + (vio.row / 2),47,0);
  ShowCursor(FALSE);
  while(okay) {
    VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
    VioSetCurPos(curpos + (vio.row / 2),47,0);
    key = get_ch(-1);
    switch(key) {
      case 256:
        break;

      case 45 | 256:
      case 61 | 256:
      case '\x1b':  /* abort */
        okay = FALSE;
        ret = -1;
        break;

      case '\r':      /* process */
        okay = FALSE;
        {
          FILESTATUS3 fs3;

          if(!DosQueryPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3))) {
            fs3.attrFile &= (~FILE_DIRECTORY);
            if(attrs[0] == 'x')
              fs3.attrFile |= FILE_READONLY;
            else
              fs3.attrFile &= (~FILE_READONLY);
            if(attrs[1] == 'x')
              fs3.attrFile |= FILE_HIDDEN;
            else
              fs3.attrFile &= (~FILE_HIDDEN);
            if(attrs[2] == 'x')
              fs3.attrFile |= FILE_SYSTEM;
            else
              fs3.attrFile &= (~FILE_SYSTEM);
            if(attrs[3] == 'x')
              fs3.attrFile |= FILE_ARCHIVED;
            else
              fs3.attrFile &= (~FILE_ARCHIVED);
            if(DosSetPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3),
                              DSPI_WRTTHRU))
              DosBeep(50,100);
            else
              ret = 1;
          }
          else
            DosBeep(50,100);
        }
        break;

      case 72 | 256:  /* up */
        curpos--;
        if(curpos > 3)
          curpos = 3;
        break;

      case 'x':
      case 'X':
      case '+':
        attrs[curpos] = 'x';
        break;

      case '-':
        attrs[curpos] = '-';
        break;

      case ' ':       /* toggle */
        attrs[curpos] = (attrs[curpos] == 'x') ? '-' : 'x';
        VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
        /* intentional fallthru */
      case 80 | 256:  /* down */
        curpos++;
        if(curpos > 3)
          curpos = 0;
        break;
    }
  }

  ShowCursor(TRUE);
  VioWrtCellStr(buf,len,(vio.row / 2) - 1,0,0);
  free(buf);
  SetupConsole();
  ThreadMsg(NULL);
  return ret;
}
int EnterLine (char *buf,ULONG len,USHORT y,char *filename,
               char **choices,int numc,int start) {

  ULONG         pos = 0,c,nm,numchars = 0,tpos,wl;
  APIRET        rc;
  int           key,attr = ((7 << 4) << 8) | ' ',ret = 0;
  BOOL          okay = TRUE,insert = TRUE,lasttab = FALSE;
  char         *sav,*k = NULL,*p;
  static char   keybuf[1026];
  USHORT        t;
  FILEFINDBUF3  fb3;
  HDIR          hdir = HDIR_CREATE;

  wl = 0;

  sav = malloc(vio.col * 2);
  if(!sav) {
    DosBeep(50,100);
    *buf = 0;
    return -1;
  }

  ThreadMsg(" ");

  t = vio.col * 2;
  VioReadCellStr(sav,&t,y,0,0);
  VioWrtNCell((char *)&attr,vio.col,y,0,0);
  ShowCursor(FALSE);
  VioSetCurPos(y,0,0);

  for(c = 0;c < len - 1;c++) {          /* find end of default string */
    if(!buf[c])
      break;
  }
  pos = c;
  for(;c < len - 1;c++)                 /* space-pad remainder of buf */
    buf[c] = ' ';

  while(okay) {
    /* assure buffer is null terminated (cluck, cluck) */
    buf[len - 1] = 0;

    /* assure pos hasn't gone past our limit */
    if(pos > len - 1)
      pos = len - 1;

    /* set left side of entry field */
    if(pos < wl)
      wl = pos;
    if(pos >= wl + vio.col)
      wl = (pos - vio.col) + 1;

    /* set cursor position */
    VioSetCurPos(y,pos - wl,0);

    /* display buf */
    tpos = min(vio.col,len - wl); /* max length of displayable text */
    VioWrtCharStr(buf + wl,tpos,y,0,0); /* show text */
    if(tpos < vio.col)                  /* space-pad? */
      VioWrtNChar(" ",vio.col - tpos,y,tpos,0);

    if(k && *k)   /* "macros" waiting to be entered? */
      key = *k++; /* yep, skip keyboard input */
    else {        /* nope, go to the keyboard */
      k = NULL;   /* clear macro pointer */
      key = get_ch(-1);
    }

    switch(key) {
      case 256:       /* shiftstate changed -- ignore */
        break;

      case '\r':      /* accept input */
        okay = FALSE;
        break;

      case 45 | 256:
      case 61 | 256:
      case '\x1b':    /* Escape -- exit editor */
        memset(buf,' ',len - 1);
        buf[len - 1] = 0;
        okay = FALSE;
        ret = -1;
        break;

      case '\b':
        if(pos) {
          pos--;
          memmove(buf + pos,buf + (pos + 1),len - (pos + 1));
          buf[len - 2] = ' ';
        }
        lasttab = FALSE;
        break;

      case 25:          /* ctrl+y -- clear input */
        VioWrtNCell((char *)&attr,vio.col,y,0,0);
        memset(buf,' ',len - 1);
        buf[len - 1] = 0;
        wl = pos = 0;
        lasttab = FALSE;
        break;

      case 59 | 256:    /* F1 -- insert directory */
        k = directory;
        lasttab = FALSE;
        break;

      case 60 | 256:    /* F2 -- insert filename */
        if(filename)
          k = filename;
        lasttab = FALSE;
        break;

      case 62 | 256:    /* F4 -- insert target */
        k = target;
        lasttab = FALSE;
        break;

      case 15:          /* shift+tab */
        if(hdir != (HDIR)HDIR_CREATE) {
          DosFindClose(hdir);
          hdir = HDIR_CREATE;
          lasttab = FALSE;
        }
        /* intentional fallthru */
      case 9:           /* tab -- auto-complete */
        if(!pos || pos >= len - 1)
          break;
        if(lasttab && numchars) {
          lasttab = FALSE;
          for(tpos = 0;tpos < numchars;tpos++)
            keybuf[tpos] = '\b';
          keybuf[tpos++] = '\01';
          keybuf[tpos] = 0;
          numchars = 0;
          k = keybuf;
          break;
        }
        else {
          if(hdir != (HDIR)HDIR_CREATE)
            DosFindClose(hdir);
          hdir = HDIR_CREATE;
        }
        /* intentional fallthru */
      case 1:           /* cheat! */
        k = NULL;
        if(!pos || pos >= len - 1)
          break;
        tpos = pos - 1;
        while(tpos && buf[tpos] != ' ')
          tpos--;
        if(buf[tpos] == ' ')
          tpos++;
        strcpy(keybuf,buf + tpos);
        tpos = 0;
        while(keybuf[tpos] && keybuf[tpos] != ' ')
          tpos++;
        keybuf[tpos] = 0;
        lstrip(rstrip(keybuf));
        if(*keybuf) {
          strcat(keybuf,"*");
          nm = 1;
          if(hdir == (HDIR)HDIR_CREATE)
            rc = DosFindFirst(keybuf,
                              &hdir,
                              FILE_NORMAL    | FILE_HIDDEN   | FILE_SYSTEM |
                              FILE_DIRECTORY | FILE_ARCHIVED | FILE_READONLY,
                              &fb3,
                              sizeof(fb3),
                              &nm,
                              FIL_STANDARD);
          else
            rc = DosFindNext(hdir,&fb3,sizeof(fb3),&nm);
          if(!rc) {
            while((fb3.attrFile & FILE_DIRECTORY) &&
                  (*fb3.achName == '.' && (!fb3.achName[1] ||
                                           (fb3.achName[1] == '.' &&
                                            !fb3.achName[2])))) {
              nm = 1;
              if(DosFindNext(hdir,&fb3,sizeof(fb3),&nm)) {
                DosFindClose(hdir);
                hdir = HDIR_CREATE;
                *fb3.achName = 0;
                break;
              }
            }
            if(*fb3.achName) {
              keybuf[strlen(keybuf) - 1] = 0;
              p = strchr(keybuf,'\\');
              if(p)
                p++;
              else
                p = keybuf;
              tpos = 0;
              while(*p && fb3.achName[tpos] &&
                    toupper(*p) == toupper(fb3.achName[tpos])) {
                p++;
                tpos++;
              }
              if(fb3.achName[tpos]) {
                strcpy(keybuf,fb3.achName + tpos);
                numchars = strlen(keybuf);
                lasttab = TRUE;
                k = keybuf;
              }
              else if(hdir != (HDIR)HDIR_CREATE) {
                DosFindClose(hdir);
                hdir = HDIR_CREATE;
              }
            }
          }
          else if(hdir != (HDIR)HDIR_CREATE) {
            DosBeep(50,50);
            DosFindClose(hdir);
            hdir = HDIR_CREATE;
          }
        }
        break;

      case 83 | 256:    /* delete */
        memmove(buf + pos,buf + (pos + 1),len - (pos + 1));
        buf[len - 2] = ' ';
        lasttab = FALSE;
        break;

      case 82 | 256:    /* insert */
        insert = (insert) ? FALSE : TRUE;
        break;

      case 71 | 256:    /* home */
        wl = pos = 0;
        lasttab = FALSE;
        break;

      case 79 | 256:    /* end */
        pos = len - 2;
        while(pos && buf[pos] == ' ')
          pos--;
        if(pos && buf[pos] != ' ')
          pos++;
        lasttab = FALSE;
        break;

      case 75 | 256:    /* left */
        if(pos)
          pos--;
        lasttab = FALSE;
        break;

      case 77 | 256:    /* right */
        if(pos < len - 1)
          pos++;
        lasttab = FALSE;
        break;

      case 72 | 256:    /* up */
        lasttab = FALSE;
        if(choices) {
          if(choices[start]) {
            VioWrtNCell((char *)&attr,vio.col,y,0,0);
            memset(buf,' ',len - 1);
            buf[len - 1] = 0;
            wl = pos = 0;
            k = choices[start];
            start++;
            while(start < numc && !choices[start])
              start++;
            if(start > (numc - 1))
              start = 0;
            if(!choices[start]) {
              while(start < numc && !choices[start])
                start++;
            }
            if(start > (numc - 1))
              start = 0;
          }
        }
        break;

      case 80 | 256:    /* down */
        lasttab = FALSE;
        if(choices) {
          if(choices[start]) {
            VioWrtNCell((char *)&attr,vio.col,y,0,0);
            memset(buf,' ',len - 1);
            buf[len - 1] = 0;
            wl = pos = 0;
            k = choices[start];
            start--;
            while(start >= 0 && !choices[start])
              start--;
            if(start < 0)
              start = numc - 1;
            if(!choices[start]) {
              while(start >= 0 && !choices[start])
                start--;
            }
            if(start < 0)
              start = numc - 1;
          }
        }
        break;

      case 115 | 256:   /* ctrl+left */
        while(pos && buf[pos] == ' ')
          pos--;
        while(pos && buf[pos] != ' ')
          pos--;
        lasttab = FALSE;
        break;

      case 116 | 256:   /* ctrl + right */
        while(pos < len - 1 && buf[pos] == ' ')
          pos++;
        while(pos < len - 1 && buf[pos] != ' ')
          pos++;
        lasttab = FALSE;
        break;

      default:
        if(pos < len - 1 && !(key & 256) && !iscntrl(key)) {
          if(insert) {
            if(pos < len - 2) {
              memmove(buf + (pos + 1),buf + pos,len - (pos + 2));
              buf[len - 2] = ' ';
            }
            buf[pos] = (char)key;
          }
          else
            buf[pos] = (char)key;
          pos++;
        }
        else if(pos >= len - 1)
          DosBeep(250,25);
        break;
    }
  }

  if(hdir != (HDIR)HDIR_CREATE)
    DosFindClose(hdir);

  ShowCursor(TRUE);
  VioWrtCellStr(sav,vio.col * 2,y,0,0);
  free(sav);
  SetupConsole();

  ThreadMsg(NULL);

  buf[len - 1] = 0;
  lstrip(rstrip(buf));
  return (ret) ? ret : strlen(buf);
}
示例#29
0
void move_cursor (int row, int col)
{
    grab_video ();
    VioSetCurPos (row, col, hvps);
    release_video ();
}
int SimpleInput (char *title,char *text,ULONG beep,ULONG dur,ULONG wait,
                 int *responses) {

  char  *buf;
  int    xlen,key = 0,x;
  USHORT len = (vio.col * 7) * 2,start,mlen,cell;
  char   sattr = 8;
  BOOL   okay = TRUE;

  if(!title)
    title = "";
  if(!text)
    return key;
  xlen = min(max(strlen(title),strlen(text)),vio.col - 6);
  mlen = xlen + 6;
  start = (vio.col - xlen) / 2;

  buf = malloc(len);
  if(buf) {
    /* save screen under */
    VioReadCellStr(buf,&len,(vio.row / 2) - 2,0,0);
    /* draw borders */
    /* first, bright white left and top */
    cell = ((((7 | 8) << 4) | 7) << 8) | ' ';
    VioWrtNCell((char *)&cell,mlen,(vio.row / 2) - 2,start,0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) - 1,start,0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2),start,0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 1,start,0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 2,start,0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 3,start,0);
    /* now dark grey right and bottom */
    cell = (((8 << 4) | 7) << 8) | ' ';
    VioWrtNCell((char *)&cell,1,(vio.row / 2) - 1,start + (mlen - 1),0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2),start + (mlen - 1),0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 1,start + (mlen - 1),0);
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 2,start + (mlen - 1),0);
    VioWrtNCell((char *)&cell,mlen - 1,(vio.row / 2) + 3,start + 1,0);
    /* fill title area with light grey foreground, red background */
    cell = (((7 << 4) | 4) << 8) | ' ';
    VioWrtNCell((char *)&cell,mlen - 2,(vio.row / 2) - 1,start + 1,0);
    /* fill text area with light grey foreground, black background */
    cell = (((7 << 4) | 0) << 8) | ' ';
    VioWrtNCell((char *)&cell,mlen - 4,(vio.row / 2) + 1,start + 2,0);
    /* make interior border -- first white on light grey */
    cell = (((7 << 4) | (7 | 8)) << 8) | 'Ú';
    VioWrtNCell((char *)&cell,1,(vio.row / 2),start + 1,0);
    cell = (((7 << 4) | (7 | 8)) << 8) | '¿';
    VioWrtNCell((char *)&cell,1,(vio.row / 2),start + (mlen - 2),0);
    cell = (((7 << 4) | (7 | 8)) << 8) | 'Ä';
    VioWrtNCell((char *)&cell,mlen - 4,(vio.row / 2),start + 2,0);
    cell = (((7 << 4) | (7 | 8)) << 8) | '³';
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 1,start + 1,0);
    cell = (((7 << 4) | (7 | 8)) << 8) | 'À';
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 2,start + 1,0);
    /* now dark grey on light grey */
    cell = (((7 << 4) | 8) << 8) | 'Ä';
    VioWrtNCell((char *)&cell,mlen - 4,(vio.row / 2) + 2,start + 2,0);
    cell = (((7 << 4) | 8) << 8) | 'Ù';
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 2,start + (mlen - 2),0);
    cell = (((7 << 4) | 8) << 8) | '³';
    VioWrtNCell((char *)&cell,1,(vio.row / 2) + 1,start + (mlen - 2),0);

    /* insert title */
    VioWrtCharStr(title,
                  min(xlen,strlen(title)),
                  (vio.row / 2) - 1,
                  (start + (mlen / 2)) - (min(xlen,strlen(title)) / 2),
                  0);
    /* insert text */
    VioWrtCharStr(text,
                  min(xlen,strlen(text)),
                  (vio.row / 2) + 1,
                  (start + (mlen / 2)) - (min(xlen,strlen(text)) / 2),
                  0);
    /* draw shadow */
    VioWrtNAttr(&sattr,1,(vio.row / 2) - 1,start + mlen,0);
    VioWrtNAttr(&sattr,1,(vio.row / 2),start + mlen,0);
    VioWrtNAttr(&sattr,1,(vio.row / 2) + 1,start + mlen,0);
    VioWrtNAttr(&sattr,1,(vio.row / 2) + 2,start + mlen,0);
    VioWrtNAttr(&sattr,1,(vio.row / 2) + 3,start + mlen,0);
    VioWrtNAttr(&sattr,mlen,(vio.row / 2) + 4,start + 1,0);
    VioSetCurPos((vio.row / 2) + 1,start + (mlen - 3),0);
    if(responses)
      ShowCursor(FALSE);
    if(beep)
      DosBeep(beep,dur);
    if(!responses)
      DosSleep(wait);
    else {
      KbdFlushBuffer(0);
      while(okay) {
        key = get_ch(-1);
        if(!*responses)
          break;
        for(x = 0;responses[x];x++) {
          if(key == responses[x]) {
            okay = FALSE;
            break;
          }
        }
      }
    }
    ShowCursor(TRUE);
    VioWrtCellStr(buf,len,(vio.row / 2) - 2,0,0);
    free(buf);
    KbdFlushBuffer(0);
    ThreadMsg(NULL);
  }
  return key;
}