Some unifications in the "SEE ALSO" section.
[cake.git] / workbench / c / SetClock.c
blob078536387ff548a453611eef52d865a14477e8a3
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: SetClock - set/save the date from/to the BBU clock.
6 Lang: English
7 */
9 /*************************************************************************
11 NAME
12 SetClock
14 FORMAT
15 SetClock {LOAD|SAVE|RESET}
17 SYNOPSIS
18 LOAD/S,SAVE/S,RESET/S
20 LOCATION
21 Sys:c
23 FUNCTION
24 SetClock can be used to:
25 o Load the time from the battery backed-up clock,
26 o Save the time to the battery backed-up clock,
27 o Reset the battery backed up clock.
29 EXAMPLE
31 SetClock LOAD
33 will set the system time from the battery backed-up clock.
34 In most systems this will be done automatically during
35 system startup.
37 SetClock SAVE
39 will set the time of the battery backed-up clock from the
40 current system clock time.
42 SetClock RESET
44 will reset the battery backed-up to a value of the
45 1st January 1978 00:00:00. This is mostly used if the
46 battery backed-up clock has an error and will not
47 respond to normal load and save commands.
49 SEE ALSO
50 Date, Sys:Prefs/Time
52 *************************************************************************/
54 #include <exec/types.h>
55 #include <dos/dosextens.h>
56 #include <dos/rdargs.h>
57 #include <devices/timer.h>
58 #include <utility/tagitem.h>
60 #include <proto/exec.h>
61 #include <proto/dos.h>
62 #include <proto/battclock.h>
63 #include <proto/timer.h>
65 const char version[] = "$VER: SetClock 41.1 (21.2.1997)";
66 const char exthelp[] =
67 "SetClock : Set or save the date from/to the battery backed-up clock\n"
68 "\tLOAD Load the time from the battery-backed-up clock\n"
69 "\tSAVE Save the time to the battery-backed-up clock\n"
70 "\tRESET Reset the battery-backed-up clock\n";
72 #define ARG_TEMPLATE "LOAD/S,SAVE/S,RESET/S"
73 #define ARG_LOAD 0
74 #define ARG_SAVE 1
75 #define ARG_RESET 2
76 #define TOTAL_ARGS 3
78 int main(int argc, char **av)
80 IPTR args[TOTAL_ARGS] = { 0, 0, 0 };
81 struct RDArgs *rda, *rd;
82 APTR BattClockBase = NULL;
83 struct Device *TimerBase = NULL;
84 ULONG time, error = 0;
85 struct timerequest *tr;
86 struct MsgPort *mp;
87 struct timeval t;
89 rda = AllocDosObject(DOS_RDARGS, NULL);
90 if(rda != NULL)
92 rda->RDA_ExtHelp = (STRPTR)exthelp;
93 rd = ReadArgs(ARG_TEMPLATE, args, rda);
95 if(rd)
97 BattClockBase = OpenResource("battclock.resource");
98 if(BattClockBase)
100 if((mp = CreateMsgPort()))
102 if((tr = (struct timerequest *)
103 CreateIORequest(mp, sizeof(struct timerequest))))
105 if(OpenDevice("timer.device", UNIT_VBLANK,
106 (struct IORequest *)tr, 0) == 0)
108 TimerBase = tr->tr_node.io_Device;
110 if(args[0])
112 /* Loading */
113 time = ReadBattClock();
115 /* Set timer.device clock */
116 tr->tr_node.io_Command = TR_SETSYSTIME;
117 tr->tr_time.tv_secs = time;
118 tr->tr_time.tv_micro = 0;
119 tr->tr_node.io_Flags = IOF_QUICK;
120 DoIO((struct IORequest *)tr);
121 if(tr->tr_node.io_Error != 0)
123 FPuts(Output(), "Error: Could not set system time!\n");
126 else if(args[1])
128 /* Saving */
129 GetSysTime(&t);
130 WriteBattClock(t.tv_secs);
132 else if(args[2])
134 /* Resetting */
135 ResetBattClock();
137 else
138 error = ERROR_REQUIRED_ARG_MISSING;
140 } /* OpenDevice() */
141 else
142 error = ERROR_INVALID_RESIDENT_LIBRARY;
144 DeleteIORequest((struct IORequest *)tr);
146 } /* CreateIORequest() */
147 else
148 error = ERROR_NO_FREE_STORE;
150 DeleteMsgPort(mp);
151 } /* CreateMsgPort() */
153 else
154 error = ERROR_NO_FREE_STORE;
156 } /* OpenResource() */
157 FreeArgs(rd);
159 } /* ReadArgs() */
160 else
161 error = IoErr();
163 FreeDosObject(DOS_RDARGS, rda);
164 } /* AllocDosObject() */
165 else
166 error = IoErr();
168 if(error != 0)
170 PrintFault(error, "SetClock");
171 return RETURN_FAIL;
173 SetIoErr(0);
174 return 0;