コード例 #1
0
ファイル: zmwin.c プロジェクト: mingpen/OpenNT
/*  KeyManager - intercept keystrokes and hand them to the active window
 *
 *  We use the top of winList as the current input focus.  All input is handed
 *  to the window procedure EXCEPT for the tab key.  The tab key is responsible
 *  for placing the top window on the bottom of the stack to cycle through the
 *  set of windows.
 *
 */
VOID PASCAL INTERNAL KeyManager (VOID)
{
    LONG    now;
#if defined (HEAPCRAP)
    INT     fHeapChk;
#endif

    /*  do script first in case in contains a password command
     */
    if ( pInitScript )
        DoScript ( hCommand, pInitScript, 0 );

    if (fMailAllowed) {
        GetAliases ( fNotifyTools & F_LOADALIAS );
        fNotifyTools &= ~(FLAG)F_LOADALIAS;
        NotifyTools ( );
        }
    if ( fComposeOnBoot )
        ( *( winList->wndProc ) ) ( winList, KEY, 0 );

    SendMessage ( hCommand, DISPPROMPT, TRUE );

    while ( ( winList != NULL ) && ( !fQuit ) ) {
        time ( &now );
	CheckTimeDisplay ( now );

        if ( pInitHdrCmd ) {
            DoHeaders ( hCommand, pInitHdrCmd, TRUE );
            SendMessage ( hCommand, DISPPROMPT, 0 );
            ZMfree ( pInitHdrCmd );
            pInitHdrCmd = NULL;
        }

        /*  if system has not received a char for 10 sec then checkmail
         */
        if (fMailAllowed)
            CheckMail ( now );

        /*  time out password after (default) 6 hours in case user has
         *  left WZMAIL running and gone home
         */
        if ( now > lTmPassword + lPasswordAge )
            ResetPassword ( );

        if ( now > lTmConnect + cSecConnect )
            ZMDisconnect ( );

        /*  On multitasking systems, it is rude to go into polling loops.
         *
         *  For OS/2, we have a separate thread dedicated to reading from the
         *  console.  We clear a semaphore to let him read and then wait on
         *  a response semaphore with the specified timeout.  This avoids
         *  polling.
         *
         *  For real mode DOS, we presume that INT 16 (poll) will cause an
         *  explicit yield to other runnable threads.
         */
        if (kbwait (60 * 1000)) {

            fMailUnSeen = FALSE;

            do {
                (*winList->wndProc) ( winList, KEY, ReadKey() );

            } while (!fQuit && kbwait (10000));
        }

#if defined (HEAPCRAP)
        if ( ( fHeapChk = heapchk ( ) ) != HEAPOK ) {
            fprintf ( stderr, "%s\n",
                ( fHeapChk == HEAPBADBEGIN ? "Can't find heap" :
                    "Damaged heap" ) );
            assert ( fHeapChk == HEAPOK );
            }
#endif

    }
    return;
}
コード例 #2
0
ファイル: libecoteste.c プロジェクト: drbeco/libeco
int main(int argc, char *argv[])
{

    int a, i, novo=0;
    char c;
    int amax, amin;
    double x2;

    int last=0;
    char str[TAM];
    clock_t clock1, clock2, diffclock;

    if(argc==2)
        if(!strcmp(argv[1],"-n"))
            novo=1;

    printf("\nlibecoteste version v0.1.090902.000301\n\n");

    if(!novo)
    {
        printf("Teste getch()\n");
        c=getch();
        printf("Char: %c ASCII: %d\n", c, c);
        printf("Teste ok\n\n");

        printf("Teste kbhit()\n");
        clock1 = clock() / CLOCKS_PER_SEC;
        clock2 = clock1;
        diffclock = clock2 - clock1;
        printf("Tecle algo no tempo de: ");
        while(diffclock<10)
        {
            if((a=kbhit())) /* kbbuff() deprecated */
                break;
            clock2 = clock() / CLOCKS_PER_SEC;
            diffclock = clock2 - clock1;
            if(diffclock>last)
            {
                printf("%lus ", 10-diffclock);
                last++;
            }
            fflush(stdout);
        }
        if(a)
            printf("\nTecla disponivel no buffer\n");
        else
            printf("\nTecla nao pressionada\n");
        printf("Teste ok\n\n");

        printf("Teste min(3,2)\n");
        printf("%d\n", min(3,2));
        printf("Teste min(-3,-2)\n");
        printf("%d\n", min(-3,-2));
        printf("Teste ok\n\n");


        printf("Teste kbwait(1000)\n");
        //sleep(1);
        printf("Tecle algo 10s\n");
        a=kbwait(1000);
        if(a)
            printf("Tecla disponivel no buffer\n");
        else
            printf("Tecla nao pressionada\n");
        printf("Teste ok\n\n");

        printf("Teste getfrom(\"0a\")\n");
        c=getfrom("0a");
        if(c!='a' && c!='0')
            printf("\nTeste FALHOU!\n\n");
        else
            printf("Teste ok\n\n");



        printf("Teste rand_minmax(0,10) em 10000 iteracoes\n");
        amax = -1;
        amin = 11;
        for(i=0; i<10000; i++)
        {
            a=rand_minmax(0, 10);

            if(a>amax)
                amax=a;
            if(a<amin)
                amin=a;
        }
        printf("max=%d, min=%d\n", amax, amin);
        if(amax<10 && amin>=0)
            printf("\nTeste ok\n\n");
        else
            printf("\nTeste FALHOU!\n\n");


        printf("Teste x2=mudaintervalo(0.0, 50.0, 0.0, 100.0, 25.0)\n");
        x2=mudaintervalo(0.0, 50.0, 0.0, 100.0, 25.0);
        printf("x2: %f\n", x2);
        if(x2!=50.0)
            printf("\nTeste FALHOU!\n\n");
        printf("Teste x2=mudaintervalo(0.0, 100.0, 0.0, 0.4, 50.0)\n");
        x2=mudaintervalo(0.0, 100.0, 0.0, 0.4, 50.0);
        printf("x2: %f\n", x2);
        printf("\nTeste ok\n\n");


        printf("Teste de limites dos tipos\n");
        printf("--------------------------\n");
        printf("unsigned %lu bits %lu bytes\n", sizeof(unsigned)*CHAR_BIT,(sizeof(unsigned)*CHAR_BIT)/8);
        printf("max unsigned %u, min unsigned %u\n\n", UINT_MAX, 0);

        printf("int %lu bits %lu bytes\n", sizeof(int) * CHAR_BIT, (sizeof(int) * CHAR_BIT)/8);
        printf("max int %d, min int %d\n\n", INT_MAX, INT_MIN);

        printf("long int %lu bits %lu bytes\n", sizeof(long) * CHAR_BIT, (sizeof(long) * CHAR_BIT)/8);
        printf("max %ld, min %ld\n\n", (long)LONG_MAX, (long)LONG_MIN);

        printf("long long int %lu bits %lu bytes\n\n", sizeof(long long) * CHAR_BIT, (sizeof(long long) * CHAR_BIT)/8);
    //    printf("max %d, min %d\n\n", LLONG_MAX, LLONG_MIN);

        printf("float %lu bits %lu bytes\n", sizeof(float) * CHAR_BIT, (sizeof(float) * CHAR_BIT)/8);
        printf("max, min float +-%f\n", (double)FLT_MAX);
        printf("max float 10^%f-1 is valid\n", (double)FLT_MAX_10_EXP);
        printf("min float 10^%f-1 is valid\n\n", (double)FLT_MIN_10_EXP);

        printf("double %lu bits %lu bytes\n", sizeof(double) * CHAR_BIT, (sizeof(double) * CHAR_BIT)/8);
        printf("max, min double +-%f\n", (double)DBL_MAX);
        printf("max double 10^%f-1 is valid\n", (double)DBL_MAX_10_EXP);
        printf("min double 10^%f-1 is valid\n\n", (double)DBL_MIN_10_EXP);
        //FLT_MAX_EXP
        //FLT_RADIX^FLT_MAX_EXP-1 is valid
        //DBL_MAX_EXP
        printf("FLT_ROUNDS: %d\n", FLT_ROUNDS);
        printf("--------------------------\n");

        printf("%f+%f=%f\n", 83484516925440.000000, 1.1, 83484516925440.000000+1.1);
        x2=5000000000000.0;
        x2+=1.1;
        printf("x:%.15f\n", x2);

        printf("%f+%f=%f\n", 340282346638528859811704183484516925440.0, 1.1, (double)((double)340282346638528859811704183484516925440.0+(double)1.1));


        printf("\nchar getfrom(\"01923456789.-\\n\");");
        printf("Press ENTER to end, or fill %d chars.\n", TAM-1);
        i=0;
        str[0]=str[TAM-1]='\0';
        while(1)
        {
            a=getfrom("01923456789.-\n");
            if(a>=32&&a<=127)
            {
                str[i]=a;
                str[i+1]='\0';
                printf("%c", a);
                if(i==TAM-2)
                    break;
                i++;
            }
            else if(a=='\n')
                break;
        }
        printf("\ns='%s'\nlength: %lu\n", str, strlen(str));
        printf("sizeof(s): %lu\n", sizeof(str));
        printf("s[%d]:'%d'\n", TAM-1, str[TAM-1]);
        printf("s[%d]:'%d'\n", TAM-2, str[TAM-2]);
        printf("s[%d]:'%d'\n", TAM-3, str[TAM-3]);
        printf("\nTeste ok\n\n");

    }

    printf("Teste chkpipe()\n");
    printf("Teste nao implementado\n\n");



    // printf("Teste ok\n\n");
    printf("Fim dos testes\n");
    printf("Nota: para compilar use: gcc libecoteste.c -o libecoteste\n\n");
}