Beispiel #1
0
/* At last: THE FUNCTION */
int ScrEnter(char *Prompt_Text, int Prompt_Attr, int Row, int Column,
              int Box_Attr, char *Text, char *Default_Text, int *Text_Length,
              int Text_Attr, int *Exit_Keys)
{
  int
    ch,                                  /* character just input            */
    Pos,                                 /* position in Text                */
    Index,                               /* index for shuffling elements    */
    Buffer_Size,                         /* size of the screen saving buffer*/
    Prompt_Length = strlen(Prompt_Text), /* length of the prompt            */
    Text_Start = Column+Prompt_Length+1, /* column text input starts at     */
    Text_Max = *Text_Length,             /* local variable for Text_Length  */
    Cur_Row, Cur_Col,                    /* old cursor coordinates          */
    Tmp = (Text_Max<0) ? 0 : 1,         /* for people who just want a key  */
    No_Prompt = Text_Max == 0;           /* for people who just want a box  */
  char
    *Save_Buffer;                        /* area for storing the space used */
  enum Ins_Mode
    Mode = Insert;                       /* what mode the user is in        */

  if (!Tmp) Text_Max = 0;
  if (!Text_Max) Text_Start -= 1;

  /* Store the current cursor position */
  ScrGetCursorPos (&Cur_Row, &Cur_Col);

  if (Box_Attr == NO_BOX) {
    /* Only save area used by prompt and text */
    Buffer_Size = Prompt_Length+Text_Max+2;
    Buffer_Size *= 2;
    Save_Buffer = (char *) malloc (Buffer_Size*sizeof(char));
    ScrRead (Row, Column, Prompt_Length+Text_Max+2, 1, Save_Buffer);
  }
  else {
    /* save whole area */
    Buffer_Size = (Prompt_Length+Text_Max+4) * 3;
    Buffer_Size *= 2;
    Save_Buffer = (char *) malloc (Buffer_Size*sizeof(char));
    ScrRead (Row-1, Column-1, Prompt_Length+Text_Max+4, 3, Save_Buffer);
    /* Draw the box if requested */
    ScrBox (Row-1, Column-1, Row+1, Column + Prompt_Length + Text_Max +
           1 - 2*No_Prompt + Tmp, Box_Attr);
  }

  /* Put the prompt where it belongs */
  ScrPrint (Row, Column, Prompt_Length, Prompt_Attr, Prompt_Text);

  /* Put up the default text */
  if (Text_Max) {
    ScrClear (Row, Text_Start - 1, Text_Max + Tmp + 1, 1, Text_Attr);
    ScrPrintText (Row, Text_Start, Text_Max, Default_Text);
  }

  /* Put the cursor at the end of the default text */
  Pos = strlen (Default_Text);
  if (Pos > Text_Max)
    Pos = Text_Max;
  ScrSetCursorPos(Row, Text_Start+Pos);

  if (!No_Prompt) {
  /* Initialize the array to 0's */
  for (Pos = 0; Pos <= Text_Max; Text[Pos++] = '\000');
  Pos = -1;

  /* Do the actual input of the string */
//  if (Mode == Replace)
//    ScrSetCursorSize (1,8);
//  else
//    ScrSetCursorSize (7,8);
//
// ScrSetCursorSize() is no longer supported in portscr, but it may be added
//   again before too long.

  do {
    ch = ScrKey();
    if (Pos == -1) {
      Pos = 0;
    }
    switch (ch) {
      case K_RETURN: case K_UP: case K_DOWN:
        /* Ignore these keys */
        break;
      case K_LEFT:
        if (Pos > 0)
          Pos--;
        break;
      case K_RIGHT:
        if (Pos < strlen(Text))
          Pos++;
        break;
      case K_CRIGHT:
        while ((!isspace(Text[Pos])) && (Pos < strlen(Text)))
          Pos++;
        while ((isspace(Text[Pos])) && (Pos < strlen(Text)))
          Pos++;
        break;
      case K_CLEFT:
        if (Pos > 0)
          Pos--;
        while ((isspace(Text[Pos])) && (Pos > 0))
          Pos--;
        while ((!isspace(Text[Pos])) && (Pos > 0))
          Pos--;
        if (Pos > 0)
          Pos++;
        break;
      case K_HOME:
        Pos = 0;
        break;
      case K_END:
        Pos = strlen(Text);
        break;
      case K_INS:
        if (Mode == Insert) {
          Mode = Replace;
          // ScrSetCursorSize (1,8);
        }
        else {
          Mode = Insert;
          // ScrSetCursorSize (7,8);
        }
        break;
      case K_BACKSPACE:
        if (Pos == 0)
          break;
        Pos--;
      case K_DEL:
        for (Index = Pos; Index < Text_Max; Text[Index++] = Text[Index+1]);
        Text[Text_Max] = '\000';
        break;
      default:
        if ((!isprint(ch)) || (In (ch,Exit_Keys)))
          break;
        if (Mode == Insert) {
          if (strlen(Text) == Text_Max)
            break;
          for (Index = Text_Max-1; Index > Pos; Index--)
            Text[Index] = Text[Index-1];
        }
        if (Pos < Text_Max)
          Text[Pos++] = ch;
        break;
    }

    /* Clear entry area, show current text, and put the cursor at its end */
    ScrClear (Row, Text_Start-1, Text_Max + Tmp + 1, 1, Text_Attr);
    ScrPrintText (Row, Text_Start, strlen(Text), Text);
    ScrSetCursorPos(Row, Text_Start+Pos);
  } while ((ch != K_RETURN) && (!In (ch, Exit_Keys)));


  /* Put back onto the screen what was there before */
  if (Box_Attr == NO_BOX)
    ScrWrite (Row, Column, Prompt_Length+Text_Max+2, 1, Save_Buffer);
  else
    ScrWrite (Row-1, Column-1, Prompt_Length+Text_Max+4, 3, Save_Buffer);

  free (Save_Buffer);

  /* Clean up the string by truncating trailing spaces */
  if (Tmp) while (Text[--Text_Max] == ' ')
    Text[Text_Max] = '\000';
  if (strlen(Text) == 0)
    strcpy (Text, Default_Text);
  *Text_Length = strlen(Text);

  }

  /* Restore the original cursor position */
  ScrSetCursorPos (Cur_Row, Cur_Col);
//  ScrSetCursorSize (7,8);
  return ch;
}
Beispiel #2
0
/*
**  void main(int argc, CHAR * argv[])
*/
void main(int argc, CHAR * argv[])
{
    unsigned   us;
    CHAR *     pch;
    int        cch;
    int        i;
#ifdef OS2SU
    KBDKEYINFO  kb;
#endif /* OS2SU */


    vcolorCurFore = colorWhite;
    vcolorCurBack = colorBlue;
    vcolorScrFore = colorWhite;
    vcolorScrBack = colorBlue;
    vcolorEditFore = colorRed;
    vcolorEditBack = colorWhite;
    vcolorListboxFore = colorWhite;
    vcolorListboxBack = colorBlue;
    vcolorLbMoreFore = colorRed;
    vcolorLbMoreBack = colorWhite;
    vcolorErrorFore = colorWhite;
    vcolorErrorBack = colorRed;

      /* parse command line args */
    for (i = 1; i < argc; i++)
        {
        if (argv[i][0] == '/' || argv[i][0] == '-')
            {
            switch (argv[i][1])
                {
            default:
            case '?':
                Usage();
                break;

            case 'c':
            case 'C':
                fMonoDisplay = TRUE;
                break;
                }
            }
        }

    if (!fMonoDisplay && !FDetectAndSetMonoDisplay())
        {
        /* detection not sure if color or mono -- set to mono by routine
        ** we could ask the user here and reset to color, or just run
        */
        }

    for (us = 0; (rgchSourcePath[us] = *(_pgmptr + us)) != '\0'; us++)
        ;

    if (rgchSourcePath[1] != ':' || rgchSourcePath[2] != '\\')
        {
        _getcwd(rgchSourcePath, PATHMAX - 1);
        if (rgchSourcePath[strlen(rgchSourcePath) - 1] != '\\')
            strcat(rgchSourcePath, "\\");
        }
    else
        {
        pch = strrchr(rgchSourcePath, '\\');
        *(pch + 1) = '\0';     /* strip off SETUP.EXE */
        _strupr(rgchSourcePath);
        }

      /*  Replace INT24 disk-error handler.  Restore with CloseDisks at
      **    termination of program via ExitPgm().
      */
    OpenDisks();

    QueryDisks(&vdskFloppy, &vdskHard, FALSE);

      /* steal CTRL+C interrupt */
    signal(SIGINT, SIG_IGN);

    ScrClear();

      /* switch to source directory to read INF file */
    cch = strlen(rgchSourcePath);
    if (cch > 3)     /* remove trailing backslash except for root case */
        rgchSourcePath[cch - 1] = '\0';
#ifdef OS2SU
    DosSelectDisk(*rgchSourcePath - 'A' + 1);
#else  /* !OS2SU */
    _dos_setdrive(*rgchSourcePath - 'A' + 1, &us);
#endif /* !OS2SU */
    _chdir(rgchSourcePath + 2);
    rgchSourcePath[cch - 1] = '\\';

      /* read SETUP.INF */
    if (!FOpenInfo(SetupInf, CLIST, CMACRO, CMENU, CSCREEN))
        FatalError(smInfOpenErr, 8);
    GetInfo();
    CloseInfo();

    Install();

      /* switch to destination directory to exit */
    cch = strlen(rgchDestPath);
    if (cch > 3)     /* remove trailing backslash except for root case */
        rgchDestPath[cch - 1] = '\0';
#ifdef OS2SU
    DosSelectDisk(*rgchDestPath - 'A' + 1);
    KbdCharIn(&kb, IO_WAIT, 0);           /* ensure current message gets read */
#else  /* !OS2SU */
    _dos_setdrive(*rgchDestPath - 'A' + 1, &us);
#endif /* !OS2SU */
    _chdir(rgchDestPath + 2);

    ExitPgm();
} /* main */