aboutsummaryrefslogtreecommitdiff
path: root/Linux_C_12/cCCallSystem_121.c
blob: a9cb1ea60a1fbe8a2009b771634b0a1516097654 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/********************************************************************************************
    Clean OS Windows library module version 1.2.1.
    This module is part of the Clean Object I/O library, version 1.2.1,
    for the Windows platform.
********************************************************************************************/

/********************************************************************************************
    About this module:
    Routines related to system handling that is not part of standard cross call handling.
********************************************************************************************/
#include "cCCallSystem_121.h"
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

OS WinBeep (OS ios)
{
    rprintf("WinBeep\n");
    gdk_beep();
    return ios;
}

void WinGetBlinkTime(OS ios, int* blinktime, OS *oos)
{
/*	return (int) GetCaretBlinkTime(); */
    rprintf("WinGetBlinkTime -> not implemented\n");
    *oos = ios;
}

void WinGetTickCount (OS ios, int *tickCount, OS *oos)
{
    static struct timeval s;
    static gboolean f = TRUE;
    struct timeval r;
    
    rprintf("WinGetTickCount\n");
    if (f)
    {
        gettimeofday(&s,NULL);
        f = FALSE;
        *oos = ios;
        *tickCount = 0;
        return;
    }    
    
    gettimeofday(&r,NULL);
    *tickCount = (r.tv_sec-s.tv_sec)*1000 + (r.tv_usec-s.tv_usec)/1000;
    *oos = ios;
}

void WinPlaySound (CLEAN_STRING filename, OS ios, Bool *ook, OS *oos)
{
    char sys[64] = "paplay ";

    rprintf("WinPlaySound\n");

    strcat(sys, cstring(filename));

    rprintf("%s - %d\n", sys, system(sys));

    *ook = TRUE;
    *oos = ios;
}

OS WinWait (int delay, OS ios)
{
    rprintf("WinWait: %d\n", delay);
    sleep(delay);
    return ios;
}

void WinGetTime (OS ios, int *hr, int *min, int *second, OS *oos)
{
    struct timeval t;
    struct tm theTime;

    printf("WinGetTime\n");
    
    gettimeofday(&t,NULL);
    localtime_r(&t.tv_sec,&theTime);

    *hr = theTime.tm_hour;
    *min = theTime.tm_min;
    *second = theTime.tm_sec;

    printf("Time: %d:%d:%d\n", *hr, *min, *second);

    *oos = ios;
}

void WinGetDate (OS ios, int *year, int *month, int *day,
                int *weekday, OS *oos)
{
    struct timeval t;
    struct tm theTime;

    printf("WinGetDate\n");
    
    gettimeofday(&t,NULL);
    gmtime_r(&t.tv_sec,&theTime);
    *year = 1900 + theTime.tm_year;
    *month   = 1 + theTime.tm_mon;
    *day     = theTime.tm_mday;
    /* Clean treats 1 == Weekend, 2 == Weekday */
    *weekday = ((theTime.tm_wday == 0) || (theTime.tm_wday == 6)) ? 1 : 2;

    printf("Date: %d-%d-%d\n",*month, *day, *year);
    *oos = ios;
}