Example #1
0
int main( int argc, char *argv[] ) {

    short i, n[10];
    Digit r;
    DigitList x;

    srand( (unsigned int) getpid() );

    list_New( &x );

    /* Zero the frequency array */
    for( i=0; i<10; i++ )
        n[i] = 0;

    /* Insert digits, counting frequency as we go */
    for( i=0; i<1000; i++ ) {
        r = RandomNumberInRange( 0, 9 );
        n[r]++;
        list_Add( &x, r );
    }

    /* Display frequencies */
    for( i=0; i<10; i++ )
        printf( "%d: %d\n", i, n[i] );

#if kDEBUG
    /* Display raw data if we are debugging */
    for( i=1; i<=list_Size( x ); i++ )
        printf( "%u ", list_Nth( x, i ) );
    printf( "\n" );
#endif

    /* Zero the frequency array */
    for( i=0; i<10; i++ )
        n[i] = 0;

    /* Recompute the frequencies by traversing the list */
    for( i=1; i<=list_Size( x ); i++ )
        n[ list_Nth( x, i ) ]++;

    /* Display frequencies again */
    for( i=0; i<10; i++ )
        printf( "%d: %d\n", i, n[i] );

    printf( "\n" );
    list_Dispose( &x );

    return( 0 );
}
Example #2
0
void control_Report(Control_Event *event)
{
    struct list *keyList = event->eventKeys;
    Control_Keys *key = NULL;
    int x = 1;
    int y = 0;

    printf("Report %s\n", event->name);
    printf("Num key combinations %d, Activated %d (Control structure paused %d)\n", list_Size(event->eventKeys), control_KeyCheck(event->eventKeys, C_BUTTON_NORMAL), controlData.paused);

    while(keyList != NULL)
    {
        key = keyList->data;

        printf("[%d] numKeys %d, eventType %d, pollType %d, useStates %d:\n", x, key->numKeys, key->eventType, key->pollType, key->useKeystates);
        for(y = 0; y < key->numKeys; y++)
        {
            printf("\t%d\n", key->keys[y]);
        }

        x++;

        keyList = keyList->next;
    }

    printf("\n");

    return;
}
Example #3
0
void control_AddKeyList(Control_Event *event, unsigned int pollType, int eventType, struct list *keyList)
{
    int *key = NULL;
    int *keyValue = NULL;
    int numKey = list_Size(keyList);
    Control_Keys *cKeys = NULL;

    int x = 0;

    cKeys = control_CreateKeys(numKey, pollType, eventType);

    while(keyList != NULL)
    {
        keyValue = keyList->data;
        cKeys->keys[x] = *keyValue;

        x++;
        keyList = keyList->next;
    }

    switch (pollType)
    {
        case C_KEYBOARD:
        case C_JOYSTICK:
        case C_MOUSE:
        list_Push(&event->eventKeys, cKeys, numKey);
        break;

        default:
        file_Log(ker_Log(), 1, "Error: key not added to list, undefined poll type %d.\n", pollType);
        break;
    }

    return;
}
Example #4
0
/*
    Function: control_Save

    Description -
    Saves the keys of a control to a file.

    2 arguments:
    Control_Event *c - The control to be saved.
    FILE *save - The FILE location to save it at.
*/
void control_Save(Control_Event *c, FILE *save)
{
    int totalControls = list_Size(c->eventKeys);

    Control_Keys *keys = NULL;
    struct list *controlList = NULL;

    char controlName[255];

    int x = 0;

    strncpy(controlName, c->name, 254);

    string_ReplaceChar(controlName, ' ', '%');

    /*First save the name and total controls held*/
    file_Log(save, 0, "%d %s\n%d\n",
    strlen(controlName),
    controlName,
    totalControls
    );

    /*Then save each control event*/
    controlList = c->eventKeys;

    while(controlList != NULL)
    {
        keys = controlList->data;

        /*Save the description of the key/s*/
        file_Log(save, 0, "%d %d %d\n",
        keys->numKeys,
        keys->eventType,
        keys->pollType
        );

        /*Save the key values*/
        for(x = 0; x < keys->numKeys; x++)
        {
            file_Log(save, 0, "%d ", keys->keys[x]);
        }

        if(keys->numKeys > 0)
            file_Log(save, 0, "\n");

        controlList = controlList->next;
    }

    return;
}