summaryrefslogtreecommitdiffabout
path: root/gammu/emb
authorzautrix <zautrix>2004-09-12 13:11:10 (UTC)
committer zautrix <zautrix>2004-09-12 13:11:10 (UTC)
commitb2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26 (patch) (unidiff)
treea25dbba0cac09b7a7892405b11eb08c7d02e6b6b /gammu/emb
parent3c954091cb8d90c185403c68a8bbbb2a961f67fe (diff)
downloadkdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.zip
kdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.tar.gz
kdepimpi-b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26.tar.bz2
many phonesync fixes
Diffstat (limited to 'gammu/emb') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmcal.c2
-rw-r--r--gammu/emb/gammu/gammu.c41
2 files changed, 35 insertions, 8 deletions
diff --git a/gammu/emb/common/service/gsmcal.c b/gammu/emb/common/service/gsmcal.c
index 598292c..ddf9790 100644
--- a/gammu/emb/common/service/gsmcal.c
+++ b/gammu/emb/common/service/gsmcal.c
@@ -1,337 +1,337 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2 2
3#include <string.h> 3#include <string.h>
4 4
5#include "gsmcal.h" 5#include "gsmcal.h"
6#include "gsmmisc.h" 6#include "gsmmisc.h"
7#include "../misc/coding/coding.h" 7#include "../misc/coding/coding.h"
8 8
9bool IsCalendarNoteFromThePast(GSM_CalendarEntry *note) 9bool IsCalendarNoteFromThePast(GSM_CalendarEntry *note)
10{ 10{
11 bool Past = true; 11 bool Past = true;
12 int i; 12 int i;
13 GSM_DateTimeDT; 13 GSM_DateTimeDT;
14 14
15 GSM_GetCurrentDateTime (&DT); 15 GSM_GetCurrentDateTime (&DT);
16 for (i = 0; i < note->EntriesNum; i++) { 16 for (i = 0; i < note->EntriesNum; i++) {
17 switch (note->Entries[i].EntryType) { 17 switch (note->Entries[i].EntryType) {
18 case CAL_RECURRANCE: 18 case CAL_RECURRANCE:
19 Past = false; 19 Past = false;
20 break; 20 break;
21 case CAL_START_DATETIME : 21 case CAL_START_DATETIME :
22 if (note->Entries[i].Date.Year > DT.Year) Past = false; 22 if (note->Entries[i].Date.Year > DT.Year) Past = false;
23 if (note->Entries[i].Date.Year == DT.Year && 23 if (note->Entries[i].Date.Year == DT.Year &&
24 note->Entries[i].Date.Month > DT.Month) Past = false; 24 note->Entries[i].Date.Month > DT.Month) Past = false;
25 if (note->Entries[i].Date.Year == DT.Year && 25 if (note->Entries[i].Date.Year == DT.Year &&
26 note->Entries[i].Date.Month == DT.Month && 26 note->Entries[i].Date.Month == DT.Month &&
27 note->Entries[i].Date.Day > DT.Day) Past = false; 27 note->Entries[i].Date.Day > DT.Day) Past = false;
28 break; 28 break;
29 default: 29 default:
30 break; 30 break;
31 } 31 }
32 if (!Past) break; 32 if (!Past) break;
33 } 33 }
34 switch (note->Type) { 34 switch (note->Type) {
35 case GSM_CAL_BIRTHDAY: 35 case GSM_CAL_BIRTHDAY:
36 Past = false; 36 Past = false;
37 break; 37 break;
38 default: 38 default:
39 break; 39 break;
40 } 40 }
41 return Past; 41 return Past;
42} 42}
43 43
44void GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *Recurrance, int *EndTime, int *Location) 44void GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *Recurrance, int *EndTime, int *Location)
45{ 45{
46 int i; 46 int i;
47 47
48 *Text = -1; 48 *Text = -1;
49 *Time = -1; 49 *Time = -1;
50 *Alarm = -1; 50 *Alarm = -1;
51 *Phone = -1; 51 *Phone = -1;
52 *Recurrance= -1; 52 *Recurrance= -1;
53 *EndTime= -1; 53 *EndTime= -1;
54 *Location= -1; 54 *Location= -1;
55 for (i = 0; i < entry->EntriesNum; i++) { 55 for (i = 0; i < entry->EntriesNum; i++) {
56 switch (entry->Entries[i].EntryType) { 56 switch (entry->Entries[i].EntryType) {
57 case CAL_START_DATETIME : 57 case CAL_START_DATETIME :
58 if (*Time == -1) *Time = i; 58 if (*Time == -1) *Time = i;
59 break; 59 break;
60 case CAL_END_DATETIME : 60 case CAL_END_DATETIME :
61 if (*EndTime == -1) *EndTime = i; 61 if (*EndTime == -1) *EndTime = i;
62 break; 62 break;
63 case CAL_ALARM_DATETIME : 63 case CAL_ALARM_DATETIME :
64 case CAL_SILENT_ALARM_DATETIME: 64 case CAL_SILENT_ALARM_DATETIME:
65 if (*Alarm == -1) *Alarm = i; 65 if (*Alarm == -1) *Alarm = i;
66 break; 66 break;
67 case CAL_RECURRANCE: 67 case CAL_RECURRANCE:
68 if (*Recurrance == -1) *Recurrance = i; 68 if (*Recurrance == -1) *Recurrance = i;
69 break; 69 break;
70 case CAL_TEXT: 70 case CAL_TEXT:
71 if (*Text == -1) *Text = i; 71 if (*Text == -1) *Text = i;
72 break; 72 break;
73 case CAL_PHONE: 73 case CAL_PHONE:
74 if (*Phone == -1) *Phone = i; 74 if (*Phone == -1) *Phone = i;
75 break; 75 break;
76 case CAL_LOCATION: 76 case CAL_LOCATION:
77 if (*Location == -1) *Location = i; 77 if (*Location == -1) *Location = i;
78 break; 78 break;
79 default: 79 default:
80 break; 80 break;
81 } 81 }
82 } 82 }
83} 83}
84 84
85GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note, bool header, GSM_VCalendarVersion Version) 85GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note, bool header, GSM_VCalendarVersion Version)
86{ 86{
87 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location; 87 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location;
88 char buffer[2000]; 88 char buffer[2000];
89 89
90 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location); 90 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location);
91 91
92 if (header) { 92 if (header) {
93 *Length+=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10); 93 *Length+=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10);
94 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10); 94 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10);
95 } 95 }
96 *Length+=sprintf(Buffer+(*Length), "BEGIN:VEVENT%c%c",13,10); 96 *Length+=sprintf(Buffer+(*Length), "BEGIN:VEVENT%c%c",13,10);
97 97
98 if (Version == Nokia_VCalendar) { 98 if (Version == Nokia_VCalendar) {
99 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:"); 99 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:");
100 switch (note->Type) { 100 switch (note->Type) {
101 case GSM_CAL_REMINDER: 101 case GSM_CAL_REMINDER:
102 *Length+=sprintf(Buffer+(*Length), "Reminder%c%c",13,10); 102 *Length+=sprintf(Buffer+(*Length), "Reminder%c%c",13,10);
103 break; 103 break;
104 case GSM_CAL_MEMO: 104 case GSM_CAL_MEMO:
105 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10); 105 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10);
106 break; 106 break;
107 case GSM_CAL_CALL: 107 case GSM_CAL_CALL:
108 *Length+=sprintf(Buffer+(*Length), "Phone Call%c%c",13,10); 108 *Length+=sprintf(Buffer+(*Length), "Phone Call%c%c",13,10);
109 break; 109 break;
110 case GSM_CAL_BIRTHDAY: 110 case GSM_CAL_BIRTHDAY:
111 *Length+=sprintf(Buffer+(*Length), "Special Occasion%c%c",13,10); 111 *Length+=sprintf(Buffer+(*Length), "Special Occasion%c%c",13,10);
112 break; 112 break;
113 case GSM_CAL_MEETING: 113 case GSM_CAL_MEETING:
114 default: 114 default:
115 *Length+=sprintf(Buffer+(*Length), "MeetingDEF%c%c",13,10); 115 *Length+=sprintf(Buffer+(*Length), "MeetingDEF%c%c",13,10);
116 break; 116 break;
117 } 117 }
118 if (note->Type == GSM_CAL_CALL) { 118 if (note->Type == GSM_CAL_CALL) {
119 buffer[0] = 0; 119 buffer[0] = 0;
120 buffer[1] = 0; 120 buffer[1] = 0;
121 if (Phone != -1) CopyUnicodeString(buffer,note->Entries[Phone].Text); 121 if (Phone != -1) CopyUnicodeString(buffer,note->Entries[Phone].Text);
122 if (Text != -1) { 122 if (Text != -1) {
123 if (Phone != -1) EncodeUnicode(buffer+UnicodeLength(buffer)*2," ",1); 123 if (Phone != -1) EncodeUnicode(buffer+UnicodeLength(buffer)*2," ",1);
124 CopyUnicodeString(buffer+UnicodeLength(buffer)*2,note->Entries[Text].Text); 124 CopyUnicodeString(buffer+UnicodeLength(buffer)*2,note->Entries[Text].Text);
125 } 125 }
126 SaveVCALText(Buffer, Length, buffer, "SUMMARY"); 126 SaveVCALText(Buffer, Length, buffer, "SUMMARY");
127 } else { 127 } else {
128 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); 128 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY");
129 } 129 }
130 if (note->Type == GSM_CAL_MEETING && Location != -1) { 130 if (note->Type == GSM_CAL_MEETING && Location != -1) {
131 SaveVCALText(Buffer, Length, note->Entries[Location].Text, "LOCATION"); 131 SaveVCALText(Buffer, Length, note->Entries[Location].Text, "LOCATION");
132 } 132 }
133 133
134 if (Time == -1) return ERR_UNKNOWN; 134 if (Time == -1) return ERR_UNKNOWN;
135 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART"); 135 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART");
136 136
137 if (EndTime != -1) { 137 if (EndTime != -1) {
138 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DTEND"); 138 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DTEND");
139 } 139 }
140 140
141 if (Alarm != -1) { 141 if (Alarm != -1) {
142 if (note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) { 142 if (note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) {
143 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM"); 143 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM");
144 } else { 144 } else {
145 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "AALARM"); 145 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM");
146 } 146 }
147 } 147 }
148 148
149 /* Birthday is known to be recurranced */ 149 /* Birthday is known to be recurranced */
150 if (Recurrance != -1 && note->Type != GSM_CAL_BIRTHDAY) { 150 if (Recurrance != -1 && note->Type != GSM_CAL_BIRTHDAY) {
151 switch(note->Entries[Recurrance].Number/24) { 151 switch(note->Entries[Recurrance].Number/24) {
152 case 1 : *Length+=sprintf(Buffer+(*Length), "RRULE:D1 #0%c%c",13,10); break; 152 case 1 : *Length+=sprintf(Buffer+(*Length), "RRULE:D1 #0%c%c",13,10); break;
153 case 7 : *Length+=sprintf(Buffer+(*Length), "RRULE:W1 #0%c%c",13,10); break; 153 case 7 : *Length+=sprintf(Buffer+(*Length), "RRULE:W1 #0%c%c",13,10); break;
154 case 14 : *Length+=sprintf(Buffer+(*Length), "RRULE:W2 #0%c%c",13,10); break; 154 case 14 : *Length+=sprintf(Buffer+(*Length), "RRULE:W2 #0%c%c",13,10); break;
155 case 365 : *Length+=sprintf(Buffer+(*Length), "RRULE:YD1 #0%c%c",13,10); break; 155 case 365 : *Length+=sprintf(Buffer+(*Length), "RRULE:YD1 #0%c%c",13,10); break;
156 } 156 }
157 } 157 }
158 } else if (Version == Siemens_VCalendar) { 158 } else if (Version == Siemens_VCalendar) {
159 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:"); 159 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:");
160 switch (note->Type) { 160 switch (note->Type) {
161 case GSM_CAL_MEETING: 161 case GSM_CAL_MEETING:
162 *Length+=sprintf(Buffer+(*Length), "Meeting%c%c",13,10); 162 *Length+=sprintf(Buffer+(*Length), "Meeting%c%c",13,10);
163 break; 163 break;
164 case GSM_CAL_CALL: 164 case GSM_CAL_CALL:
165 *Length+=sprintf(Buffer+(*Length), "Phone Call%c%c",13,10); 165 *Length+=sprintf(Buffer+(*Length), "Phone Call%c%c",13,10);
166 break; 166 break;
167 case GSM_CAL_BIRTHDAY: 167 case GSM_CAL_BIRTHDAY:
168 *Length+=sprintf(Buffer+(*Length), "Anniversary%c%c",13,10); 168 *Length+=sprintf(Buffer+(*Length), "Anniversary%c%c",13,10);
169 break; 169 break;
170 case GSM_CAL_MEMO: 170 case GSM_CAL_MEMO:
171 default: 171 default:
172 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10); 172 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10);
173 break; 173 break;
174 } 174 }
175 175
176 if (Time == -1) return ERR_UNKNOWN; 176 if (Time == -1) return ERR_UNKNOWN;
177 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART"); 177 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART");
178 178
179 if (Alarm != -1) { 179 if (Alarm != -1) {
180 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM"); 180 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM");
181 } 181 }
182 182
183 if (Recurrance != -1) { 183 if (Recurrance != -1) {
184 switch(note->Entries[Recurrance].Number/24) { 184 switch(note->Entries[Recurrance].Number/24) {
185 case 1 : *Length+=sprintf(Buffer+(*Length), "RRULE:D1%c%c",13,10);break; 185 case 1 : *Length+=sprintf(Buffer+(*Length), "RRULE:D1%c%c",13,10);break;
186 case 7 : *Length+=sprintf(Buffer+(*Length), "RRULE:D7%c%c",13,10);break; 186 case 7 : *Length+=sprintf(Buffer+(*Length), "RRULE:D7%c%c",13,10);break;
187 case 30 : *Length+=sprintf(Buffer+(*Length), "RRULE:MD1%c%c",13,10);break; 187 case 30 : *Length+=sprintf(Buffer+(*Length), "RRULE:MD1%c%c",13,10);break;
188 case 365 : *Length+=sprintf(Buffer+(*Length), "RRULE:YD1%c%c",13,10);break; 188 case 365 : *Length+=sprintf(Buffer+(*Length), "RRULE:YD1%c%c",13,10);break;
189 } 189 }
190 } 190 }
191 191
192 if (note->Type == GSM_CAL_CALL) { 192 if (note->Type == GSM_CAL_CALL) {
193 buffer[0] = 0; 193 buffer[0] = 0;
194 buffer[1] = 0; 194 buffer[1] = 0;
195 if (Phone != -1) CopyUnicodeString(buffer,note->Entries[Phone].Text); 195 if (Phone != -1) CopyUnicodeString(buffer,note->Entries[Phone].Text);
196 if (Text != -1) { 196 if (Text != -1) {
197 if (Phone != -1) EncodeUnicode(buffer+UnicodeLength(buffer)*2," ",1); 197 if (Phone != -1) EncodeUnicode(buffer+UnicodeLength(buffer)*2," ",1);
198 CopyUnicodeString(buffer+UnicodeLength(buffer)*2,note->Entries[Text].Text); 198 CopyUnicodeString(buffer+UnicodeLength(buffer)*2,note->Entries[Text].Text);
199 } 199 }
200 SaveVCALText(Buffer, Length, buffer, "DESCRIPTION"); 200 SaveVCALText(Buffer, Length, buffer, "DESCRIPTION");
201 } else { 201 } else {
202 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "DESCRIPTION"); 202 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "DESCRIPTION");
203 } 203 }
204 } else if (Version == SonyEricsson_VCalendar) { 204 } else if (Version == SonyEricsson_VCalendar) {
205 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:"); 205 *Length+=sprintf(Buffer+(*Length), "CATEGORIES:");
206 switch (note->Type) { 206 switch (note->Type) {
207 case GSM_CAL_MEETING: 207 case GSM_CAL_MEETING:
208 *Length+=sprintf(Buffer+(*Length), "Meeting%c%c",13,10); 208 *Length+=sprintf(Buffer+(*Length), "Meeting%c%c",13,10);
209 break; 209 break;
210 case GSM_CAL_REMINDER: 210 case GSM_CAL_REMINDER:
211 *Length+=sprintf(Buffer+(*Length), "Date%c%c",13,10); 211 *Length+=sprintf(Buffer+(*Length), "Date%c%c",13,10);
212 break; 212 break;
213 case GSM_CAL_TRAVEL: 213 case GSM_CAL_TRAVEL:
214 *Length+=sprintf(Buffer+(*Length), "Travel%c%c",13,10); 214 *Length+=sprintf(Buffer+(*Length), "Travel%c%c",13,10);
215 break; 215 break;
216 case GSM_CAL_VACATION: 216 case GSM_CAL_VACATION:
217 *Length+=sprintf(Buffer+(*Length), "Vacation%c%c",13,10); 217 *Length+=sprintf(Buffer+(*Length), "Vacation%c%c",13,10);
218 break; 218 break;
219 case GSM_CAL_BIRTHDAY: 219 case GSM_CAL_BIRTHDAY:
220 *Length+=sprintf(Buffer+(*Length), "Anninversary%c%c",13,10); 220 *Length+=sprintf(Buffer+(*Length), "Anninversary%c%c",13,10);
221 break; 221 break;
222 case GSM_CAL_MEMO: 222 case GSM_CAL_MEMO:
223 default: 223 default:
224 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10); 224 *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10);
225 break; 225 break;
226 } 226 }
227 227
228 if (Time == -1) return ERR_UNKNOWN; 228 if (Time == -1) return ERR_UNKNOWN;
229 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART"); 229 SaveVCALDateTime(Buffer, Length, &note->Entries[Time].Date, "DTSTART");
230 230
231 if (EndTime != -1) { 231 if (EndTime != -1) {
232 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DTEND"); 232 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DTEND");
233 } 233 }
234 234
235 if (Alarm != -1) { 235 if (Alarm != -1) {
236 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "AALARM"); 236 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "AALARM");
237 } 237 }
238 238
239 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); 239 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY");
240 240
241 if (Location != -1) { 241 if (Location != -1) {
242 SaveVCALText(Buffer, Length, note->Entries[Location].Text, "LOCATION"); 242 SaveVCALText(Buffer, Length, note->Entries[Location].Text, "LOCATION");
243 } 243 }
244 } 244 }
245 245
246 *Length+=sprintf(Buffer+(*Length), "X-PILOTID:%d%c%c",note->Location,13,10); 246 *Length+=sprintf(Buffer+(*Length), "X-PILOTID:%d%c%c",note->Location,13,10);
247 *Length+=sprintf(Buffer+(*Length), "END:VEVENT%c%c",13,10); 247 *Length+=sprintf(Buffer+(*Length), "END:VEVENT%c%c",13,10);
248 if (header) *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10); 248 if (header) *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10);
249 249
250 return ERR_NONE; 250 return ERR_NONE;
251} 251}
252 252
253void GSM_ToDoFindDefaultTextTimeAlarmCompleted(GSM_ToDoEntry *entry, int *Text, int *Alarm, int *Completed, int *EndTime, int *Phone) 253void GSM_ToDoFindDefaultTextTimeAlarmCompleted(GSM_ToDoEntry *entry, int *Text, int *Alarm, int *Completed, int *EndTime, int *Phone)
254{ 254{
255 int i; 255 int i;
256 256
257 *Text = -1; 257 *Text = -1;
258 *EndTime= -1; 258 *EndTime= -1;
259 *Alarm = -1; 259 *Alarm = -1;
260 *Completed= -1; 260 *Completed= -1;
261 *Phone = -1; 261 *Phone = -1;
262 for (i = 0; i < entry->EntriesNum; i++) { 262 for (i = 0; i < entry->EntriesNum; i++) {
263 switch (entry->Entries[i].EntryType) { 263 switch (entry->Entries[i].EntryType) {
264 case TODO_END_DATETIME : 264 case TODO_END_DATETIME :
265 if (*EndTime == -1) *EndTime = i; 265 if (*EndTime == -1) *EndTime = i;
266 break; 266 break;
267 case TODO_ALARM_DATETIME : 267 case TODO_ALARM_DATETIME :
268 case TODO_SILENT_ALARM_DATETIME: 268 case TODO_SILENT_ALARM_DATETIME:
269 if (*Alarm == -1) *Alarm = i; 269 if (*Alarm == -1) *Alarm = i;
270 break; 270 break;
271 case TODO_TEXT: 271 case TODO_TEXT:
272 if (*Text == -1) *Text = i; 272 if (*Text == -1) *Text = i;
273 break; 273 break;
274 case TODO_COMPLETED: 274 case TODO_COMPLETED:
275 if (*Completed == -1) *Completed = i; 275 if (*Completed == -1) *Completed = i;
276 break; 276 break;
277 case TODO_PHONE: 277 case TODO_PHONE:
278 if (*Phone == -1) *Phone = i; 278 if (*Phone == -1) *Phone = i;
279 break; 279 break;
280 default: 280 default:
281 break; 281 break;
282 } 282 }
283 } 283 }
284} 284}
285 285
286GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool header, GSM_VToDoVersion Version) 286GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool header, GSM_VToDoVersion Version)
287{ 287{
288 int Text, Alarm, Completed, EndTime, Phone; 288 int Text, Alarm, Completed, EndTime, Phone;
289 289
290 GSM_ToDoFindDefaultTextTimeAlarmCompleted(note, &Text, &Alarm, &Completed, &EndTime, &Phone); 290 GSM_ToDoFindDefaultTextTimeAlarmCompleted(note, &Text, &Alarm, &Completed, &EndTime, &Phone);
291 291
292 if (header) { 292 if (header) {
293 *Length+=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10); 293 *Length+=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10);
294 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10); 294 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10);
295 } 295 }
296 296
297 *Length+=sprintf(Buffer+(*Length), "BEGIN:VTODO%c%c",13,10); 297 *Length+=sprintf(Buffer+(*Length), "BEGIN:VTODO%c%c",13,10);
298 298
299 if (Version == Nokia_VToDo) { 299 if (Version == Nokia_VToDo) {
300 if (Text == -1) return ERR_UNKNOWN; 300 if (Text == -1) return ERR_UNKNOWN;
301 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); 301 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY");
302 302
303 if (Completed == -1) { 303 if (Completed == -1) {
304 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10); 304 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10);
305 } else { 305 } else {
306 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10); 306 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10);
307 } 307 }
308 308
309 switch (note->Priority) { 309 switch (note->Priority) {
310 case GSM_Priority_Low: *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break; 310 case GSM_Priority_Low: *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break;
311 case GSM_Priority_Medium: *Length+=sprintf(Buffer+(*Length), "PRIORITY:3%c%c",13,10); break; 311 case GSM_Priority_Medium: *Length+=sprintf(Buffer+(*Length), "PRIORITY:3%c%c",13,10); break;
312 case GSM_Priority_High: *Length+=sprintf(Buffer+(*Length), "PRIORITY:1%c%c",13,10); break; 312 case GSM_Priority_High: *Length+=sprintf(Buffer+(*Length), "PRIORITY:1%c%c",13,10); break;
313 } 313 }
314 314
315 if (EndTime != -1) { 315 if (EndTime != -1) {
316 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DUE"); 316 SaveVCALDateTime(Buffer, Length, &note->Entries[EndTime].Date, "DUE");
317 } 317 }
318 318
319 if (Alarm != -1) { 319 if (Alarm != -1) {
320 if (note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) { 320 if (note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) {
321 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM"); 321 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "DALARM");
322 } else { 322 } else {
323 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "AALARM"); 323 SaveVCALDateTime(Buffer, Length, &note->Entries[Alarm].Date, "AALARM");
324 } 324 }
325 } 325 }
326 } else if (Version == SonyEricsson_VToDo) { 326 } else if (Version == SonyEricsson_VToDo) {
327 if (Text == -1) return ERR_UNKNOWN; 327 if (Text == -1) return ERR_UNKNOWN;
328 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); 328 SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY");
329 329
330 if (Completed == -1) { 330 if (Completed == -1) {
331 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10); 331 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10);
332 } else { 332 } else {
333 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10); 333 *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10);
334 } 334 }
335 335
336 switch (note->Priority) { 336 switch (note->Priority) {
337 case GSM_Priority_Low: *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break; 337 case GSM_Priority_Low: *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break;
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 5163d81..a3b93a8 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -8052,350 +8052,377 @@ static void HelpGeneral(void)
8052 i++; 8052 i++;
8053 } 8053 }
8054 printf("\n"); 8054 printf("\n");
8055} 8055}
8056 8056
8057static void HelpSplit(int cols, int len, unsigned char *buff) 8057static void HelpSplit(int cols, int len, unsigned char *buff)
8058{ 8058{
8059 int l, len2, pos, split; 8059 int l, len2, pos, split;
8060 bool in_opt,first=true; 8060 bool in_opt,first=true;
8061 char *remain, spaces[50], buffer[500]; 8061 char *remain, spaces[50], buffer[500];
8062 8062
8063 if (cols == 0) { 8063 if (cols == 0) {
8064 printf(" %s\n", buff); 8064 printf(" %s\n", buff);
8065 } else { 8065 } else {
8066 printf(" "); 8066 printf(" ");
8067 spaces[0] = 0; 8067 spaces[0] = 0;
8068 len2 = strlen(buff); 8068 len2 = strlen(buff);
8069 if (len + len2 < cols) { 8069 if (len + len2 < cols) {
8070 printf("%s\n", buff); 8070 printf("%s\n", buff);
8071 } else { 8071 } else {
8072 for(l = 0; l < len; l++) strcat(spaces, " "); 8072 for(l = 0; l < len; l++) strcat(spaces, " ");
8073 8073
8074 remain = buff; 8074 remain = buff;
8075 8075
8076 while (strlen(remain) > 0) { 8076 while (strlen(remain) > 0) {
8077 split= 0; 8077 split= 0;
8078 pos= 0; 8078 pos= 0;
8079 in_opt= false; 8079 in_opt= false;
8080 if (!first) printf(spaces); 8080 if (!first) printf(spaces);
8081 while (pos < cols - len && remain[pos] != 0) { 8081 while (pos < cols - len && remain[pos] != 0) {
8082 if (in_opt && remain[pos] == ']') { 8082 if (in_opt && remain[pos] == ']') {
8083 in_opt = false; 8083 in_opt = false;
8084 split = pos; 8084 split = pos;
8085 } else if (remain[pos] == '[') { 8085 } else if (remain[pos] == '[') {
8086 in_opt = true; 8086 in_opt = true;
8087 } else if (!in_opt && remain[pos] == ' ') { 8087 } else if (!in_opt && remain[pos] == ' ') {
8088 split = pos - 1; 8088 split = pos - 1;
8089 } 8089 }
8090 pos++; 8090 pos++;
8091 } 8091 }
8092 /* Can not be split */ 8092 /* Can not be split */
8093 if (split == 0) { 8093 if (split == 0) {
8094 printf("%s\n", remain); 8094 printf("%s\n", remain);
8095 remain += strlen(remain); 8095 remain += strlen(remain);
8096 } else { 8096 } else {
8097 first = false; 8097 first = false;
8098 split++; 8098 split++;
8099 strncpy(buffer, remain, split); 8099 strncpy(buffer, remain, split);
8100 buffer[split] = 0; 8100 buffer[split] = 0;
8101 printf("%s\n", buffer); 8101 printf("%s\n", buffer);
8102 remain += split; 8102 remain += split;
8103 if (remain[0] == ' ') remain++; 8103 if (remain[0] == ' ') remain++;
8104 } 8104 }
8105 } 8105 }
8106 } 8106 }
8107 } 8107 }
8108} 8108}
8109 8109
8110static void Help(int argc, char *argv[]) 8110static void Help(int argc, char *argv[])
8111{ 8111{
8112 int i = 0, j = 0, k, cols; 8112 int i = 0, j = 0, k, cols;
8113 bool disp; 8113 bool disp;
8114#ifdef TIOCGWINSZ 8114#ifdef TIOCGWINSZ
8115 struct winsize w; 8115 struct winsize w;
8116#endif 8116#endif
8117#if defined(WIN32) || defined(DJGPP) 8117#if defined(WIN32) || defined(DJGPP)
8118#else 8118#else
8119 char *columns; 8119 char *columns;
8120#endif 8120#endif
8121 8121
8122 /* Just --help */ 8122 /* Just --help */
8123 if (argc == 2) { 8123 if (argc == 2) {
8124 HelpGeneral(); 8124 HelpGeneral();
8125 return; 8125 return;
8126 } 8126 }
8127 8127
8128 if (!strcmp(argv[2],"all")) { 8128 if (!strcmp(argv[2],"all")) {
8129 HelpHeader(); 8129 HelpHeader();
8130 } else { 8130 } else {
8131 while (HelpDescriptions[i].category != 0) { 8131 while (HelpDescriptions[i].category != 0) {
8132 if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; 8132 if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break;
8133 i++; 8133 i++;
8134 } 8134 }
8135 if (HelpDescriptions[i].category == 0) { 8135 if (HelpDescriptions[i].category == 0) {
8136 HelpGeneral(); 8136 HelpGeneral();
8137 printmsg("Unknown help topic specified!\n"); 8137 printmsg("Unknown help topic specified!\n");
8138 return; 8138 return;
8139 } 8139 }
8140 HelpHeader(); 8140 HelpHeader();
8141 printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); 8141 printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description);
8142 } 8142 }
8143 8143
8144#if defined(WIN32) || defined(DJGPP) 8144#if defined(WIN32) || defined(DJGPP)
8145 cols = 80; 8145 cols = 80;
8146#else 8146#else
8147 cols = 0; 8147 cols = 0;
8148 /* If stdout is a tty, we will wrap to columns it has */ 8148 /* If stdout is a tty, we will wrap to columns it has */
8149 if (isatty(1)) { 8149 if (isatty(1)) {
8150#ifdef TIOCGWINSZ 8150#ifdef TIOCGWINSZ
8151 if (ioctl(2, TIOCGWINSZ, &w) == 0) { 8151 if (ioctl(2, TIOCGWINSZ, &w) == 0) {
8152 if (w.ws_col > 0) cols = w.ws_col; 8152 if (w.ws_col > 0) cols = w.ws_col;
8153 } 8153 }
8154#endif 8154#endif
8155 if (cols == 0) { 8155 if (cols == 0) {
8156 columns = getenv("COLUMNS"); 8156 columns = getenv("COLUMNS");
8157 if (columns != NULL) { 8157 if (columns != NULL) {
8158 cols = atoi(columns); 8158 cols = atoi(columns);
8159 if (cols <= 0) cols = 0; 8159 if (cols <= 0) cols = 0;
8160 } 8160 }
8161 } 8161 }
8162 8162
8163 if (cols == 0) { 8163 if (cols == 0) {
8164 /* Fallback */ 8164 /* Fallback */
8165 cols = 80; 8165 cols = 80;
8166 } 8166 }
8167 } 8167 }
8168#endif 8168#endif
8169 8169
8170 while (Parameters[j].Function != NULL) { 8170 while (Parameters[j].Function != NULL) {
8171 k = 0; 8171 k = 0;
8172 disp = false; 8172 disp = false;
8173 if (!strcmp(argv[2],"all")) { 8173 if (!strcmp(argv[2],"all")) {
8174 if (j==0) disp = true; 8174 if (j==0) disp = true;
8175 if (j!=0) { 8175 if (j!=0) {
8176 if (strcmp(Parameters[j].help,Parameters[j-1].help)) { 8176 if (strcmp(Parameters[j].help,Parameters[j-1].help)) {
8177 disp = true; 8177 disp = true;
8178 } else { 8178 } else {
8179 if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { 8179 if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) {
8180 disp = true; 8180 disp = true;
8181 } 8181 }
8182 } 8182 }
8183 } 8183 }
8184 } else { 8184 } else {
8185 while (Parameters[j].help_cat[k] != 0) { 8185 while (Parameters[j].help_cat[k] != 0) {
8186 if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { 8186 if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) {
8187 disp = true; 8187 disp = true;
8188 break; 8188 break;
8189 } 8189 }
8190 k++; 8190 k++;
8191 } 8191 }
8192 } 8192 }
8193 if (disp) { 8193 if (disp) {
8194 printf("%s", Parameters[j].parameter); 8194 printf("%s", Parameters[j].parameter);
8195 if (Parameters[j].help[0] == 0) { 8195 if (Parameters[j].help[0] == 0) {
8196 printf("\n"); 8196 printf("\n");
8197 } else { 8197 } else {
8198 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); 8198 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help);
8199 } 8199 }
8200 } 8200 }
8201 j++; 8201 j++;
8202 } 8202 }
8203} 8203}
8204#if 0 8204#if 0
8205#endif // 0 8205#endif // 0
8206int main(int argc, char *argv[]) 8206int main(int argc, char *argv[])
8207{ 8207{
8208 8208
8209 //fprintf(stderr,"HIIIIIIIIIIIII \n"); 8209 //fprintf(stderr,"HIIIIIIIIIIIII \n");
8210 //#if 0 8210 //#if 0
8211 static int z ,start,i; 8211 static int z ,start,i;
8212 static intonly_config ; 8212 static intonly_config ;
8213#if !defined(WIN32) && defined(LOCALE_PATH) 8213#if !defined(WIN32) && defined(LOCALE_PATH)
8214 static char*locale, locale_file[201]; 8214 static char*locale, locale_file[201];
8215#endif 8215#endif
8216 static char*cp; 8216 static char*cp;
8217 static boolcount_failed; 8217 static boolcount_failed;
8218 z = 0; 8218 z = 0;
8219 start=0;only_config = -1;count_failed = false; 8219 start=0;only_config = -1;count_failed = false;
8220 s.opened = false; 8220 s.opened = false;
8221 s.msg = NULL; 8221 s.msg = NULL;
8222 s.ConfigNum = 0; 8222 s.ConfigNum = 0;
8223 8223
8224 setlocale(LC_ALL, ""); 8224 setlocale(LC_ALL, "");
8225#ifdef DEBUG 8225#ifdef DEBUG
8226 di.dl = DL_TEXTALL; 8226 di.dl = DL_TEXTALL;
8227 di.df = stdout; 8227 di.df = stdout;
8228#endif 8228#endif
8229 //#if 0 8229 //#if 0
8230 /* Any parameters? */ 8230 /* Any parameters? */
8231 if (argc == 1) { 8231 if (argc == 1) {
8232 HelpGeneral(); 8232 HelpGeneral();
8233 printmsg("Too few parameters!\n"); 8233 printmsg("Too few parameters!\n");
8234 exit(1); 8234 exit(1);
8235 } 8235 }
8236 8236
8237 /* Help? */ 8237 /* Help? */
8238 if (strncmp(argv[1 + start], "--help", 6) == 0) { 8238 if (strncmp(argv[1 + start], "--help", 6) == 0) {
8239 Help(argc - start, argv + start); 8239 Help(argc - start, argv + start);
8240 exit(1); 8240 exit(1);
8241 } 8241 }
8242 8242
8243 /* Is first parameter numeric? If so treat it as config that should be loaded. */ 8243 /* Is first parameter numeric? If so treat it as config that should be loaded. */
8244 if (isdigit(argv[1][0])) { 8244 //if (isdigit(argv[1][0])) {
8245 only_config = atoi(argv[1]); 8245 //only_config = atoi(argv[1]);
8246 if (only_config >= 0) start++; else only_config = -1; 8246 //if (only_config >= 0) start++; else only_config = -1;
8247 } 8247 //}
8248 8248 only_config = 0;;
8249#if 0
8249 GSM_ReadConfig(NULL, &s.Config[0], 0); 8250 GSM_ReadConfig(NULL, &s.Config[0], 0);
8250 s.ConfigNum = 1; 8251 s.ConfigNum = 1;
8251 GSM_Config *con = &s.Config[0]; 8252 GSM_Config *con = &s.Config[0];
8252 8253
8253 char* tempC; 8254 char* tempC;
8254 tempC = argv[argc-1]+2; 8255 tempC = argv[argc-1]+2;
8255 if ( *tempC != 0 ) { 8256 if ( *tempC != 0 ) {
8256 fprintf(stderr,"Using model %s \n",tempC); 8257 fprintf(stderr,"Using model %s \n",tempC);
8257 strcpy(con->Model,tempC ); 8258 strcpy(con->Model,tempC );
8258 } 8259 }
8259 tempC = argv[argc-2]+2; 8260 tempC = argv[argc-2]+2;
8260 if ( *tempC != 0 ) { 8261 if ( *tempC != 0 ) {
8261 fprintf(stderr,"Using device %s \n",tempC); 8262 fprintf(stderr,"Using device %s \n",tempC);
8262 con->Device = strdup(tempC); 8263 con->Device = strdup(tempC);
8263 con->DefaultDevice = false; 8264 con->DefaultDevice = false;
8264 } 8265 }
8265 tempC = argv[argc-3]+2; 8266 tempC = argv[argc-3]+2;
8266 if ( *tempC != 0 ) { 8267 if ( *tempC != 0 ) {
8267 fprintf(stderr,"Using connection %s \n",tempC); 8268 fprintf(stderr,"Using connection %s \n",tempC);
8268 con->Connection = strdup(tempC); 8269 con->Connection = strdup(tempC);
8269 con->DefaultConnection = false; 8270 con->DefaultConnection = false;
8270 } 8271 }
8271 argc = argc-3; 8272 argc = argc-3;
8272#if 0 8273 //#if 0
8273 if ( ! mConnection.isEmpty() ) { 8274 if ( ! mConnection.isEmpty() ) {
8274 cfg->Connection = strdup(mConnection.latin1()); 8275 cfg->Connection = strdup(mConnection.latin1());
8275 cfg->DefaultConnection = false; 8276 cfg->DefaultConnection = false;
8276 qDebug("Connection set %s ", cfg->Connection ); 8277 qDebug("Connection set %s ", cfg->Connection );
8277 8278
8278 } 8279 }
8279 if ( ! mDevice.isEmpty() ) { 8280 if ( ! mDevice.isEmpty() ) {
8280 cfg->Device = strdup(mDevice.latin1()); 8281 cfg->Device = strdup(mDevice.latin1());
8281 cfg->DefaultDevice = false; 8282 cfg->DefaultDevice = false;
8282 qDebug("Device set %s ", cfg->Device); 8283 qDebug("Device set %s ", cfg->Device);
8283 8284
8284 } 8285 }
8285 if ( ! mModel.isEmpty() ) { 8286 if ( ! mModel.isEmpty() ) {
8286 strcpy(cfg->Model,mModel.latin1() ); 8287 strcpy(cfg->Model,mModel.latin1() );
8287 cfg->DefaultModel = false; 8288 cfg->DefaultModel = false;
8288 qDebug("Model set %s ",cfg->Model ); 8289 qDebug("Model set %s ",cfg->Model );
8289 } 8290 }
8290 8291
8291#endif 8292#endif
8292 8293
8293#if 0 8294
8294 cfg=GSM_FindGammuRC(); 8295 cfg=GSM_FindGammuRC();
8295 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 8296 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
8296 if (cfg!=NULL) { 8297 if (cfg!=NULL) {
8297 cp = INI_GetValue(cfg, "gammu", "gammucoding", false); 8298 cp = INI_GetValue(cfg, "gammu", "gammucoding", false);
8298 if (cp) di.coding = cp; 8299 if (cp) di.coding = cp;
8299 8300
8300 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); 8301 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false);
8301 if (s.Config[i].Localize) { 8302 if (s.Config[i].Localize) {
8302 s.msg=INI_ReadFile(s.Config[i].Localize, true); 8303 s.msg=INI_ReadFile(s.Config[i].Localize, true);
8303 } else { 8304 } else {
8304#if !defined(WIN32) && defined(LOCALE_PATH) 8305#if !defined(WIN32) && defined(LOCALE_PATH)
8305 locale = setlocale(LC_MESSAGES, NULL); 8306 locale = setlocale(LC_MESSAGES, NULL);
8306 if (locale != NULL) { 8307 if (locale != NULL) {
8307 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 8308 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
8308 LOCALE_PATH, 8309 LOCALE_PATH,
8309 tolower(locale[0]), 8310 tolower(locale[0]),
8310 tolower(locale[1])); 8311 tolower(locale[1]));
8311 s.msg = INI_ReadFile(locale_file, true); 8312 s.msg = INI_ReadFile(locale_file, true);
8312 } 8313 }
8313#endif 8314#endif
8314 } 8315 }
8315 } 8316 }
8316 8317
8317 /* Wanted user specific configuration? */ 8318 /* Wanted user specific configuration? */
8319
8318 if (only_config != -1) { 8320 if (only_config != -1) {
8319 /* Here we get only in first for loop */ 8321 /* Here we get only in first for loop */
8320 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; 8322 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break;
8321 } else { 8323 } else {
8322 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 8324 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
8323 } 8325 }
8324 s.ConfigNum++; 8326 s.ConfigNum++;
8325 8327
8326 /* We want to use only one file descriptor for global and state machine debug output */ 8328 /* We want to use only one file descriptor for global and state machine debug output */
8327 s.Config[i].UseGlobalDebugFile = true; 8329 s.Config[i].UseGlobalDebugFile = true;
8328 8330
8329 /* It makes no sense to open several debug logs... */ 8331 /* It makes no sense to open several debug logs... */
8330 if (i != 0) { 8332 if (i != 0) {
8331 strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); 8333 strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel);
8332 free(s.Config[i].DebugFile); 8334 free(s.Config[i].DebugFile);
8333 s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); 8335 s.Config[i].DebugFile = strdup(s.Config[0].DebugFile);
8334 } else { 8336 } else {
8335 /* Just for first config */ 8337 /* Just for first config */
8336 /* When user gave debug level on command line */ 8338 /* When user gave debug level on command line */
8337 if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { 8339 if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) {
8338 /* Debug level from command line will be used with phone too */ 8340 /* Debug level from command line will be used with phone too */
8339 strcpy(s.Config[i].DebugLevel,argv[1 + start]); 8341 strcpy(s.Config[i].DebugLevel,argv[1 + start]);
8340 start++; 8342 start++;
8341 } else { 8343 } else {
8342 /* Try to set debug level from config file */ 8344 /* Try to set debug level from config file */
8343 GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); 8345 GSM_SetDebugLevel(s.Config[i].DebugLevel, &di);
8344 } 8346 }
8345 /* If user gave debug file in gammurc, we will use it */ 8347 /* If user gave debug file in gammurc, we will use it */
8346 error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); 8348 error=GSM_SetDebugFile(s.Config[i].DebugFile, &di);
8347 Print_Error(error); 8349 Print_Error(error);
8348 } 8350 }
8349 8351
8350 /* We wanted to read just user specified configuration. */ 8352 /* We wanted to read just user specified configuration. */
8351 if (only_config != -1) {break;} 8353 if (only_config != -1) {break;}
8352 } 8354 }
8355#if 0
8356 GSM_Config *con = &s.Config[0];
8357
8358 char* tempC;
8359 tempC = argv[argc-1]+2;
8360 if ( *tempC != 0 ) {
8361 fprintf(stderr,"Using model %s \n",tempC);
8362 strcpy(con->Model,tempC );
8363 }
8364 tempC = argv[argc-2]+2;
8365 if ( *tempC != 0 ) {
8366 fprintf(stderr,"Using device %s \n",tempC);
8367 con->Device = strdup(tempC);
8368 con->DefaultDevice = false;
8369 }
8370 tempC = argv[argc-3]+2;
8371 if ( *tempC != 0 ) {
8372 fprintf(stderr,"Using connection %s \n",tempC);
8373 con->Connection = strdup(tempC);
8374 con->DefaultConnection = false;
8375 }
8353#endif 8376#endif
8377 argc = argc-3;
8378
8379
8354 /* Do we have enough parameters? */ 8380 /* Do we have enough parameters? */
8355 if (argc == 1 + start) { 8381 if (argc == 1 + start) {
8356 HelpGeneral(); 8382 HelpGeneral();
8357 printmsg("Too few parameters!\n"); 8383 printmsg("Too few parameters!\n");
8358 exit(-2); 8384 exit(-2);
8359 } 8385 }
8360 8386
8361 /* Check used version vs. compiled */ 8387 /* Check used version vs. compiled */
8362 if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { 8388 if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) {
8363 printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", 8389 printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n",
8364 GetGammuVersion(),VERSION); 8390 GetGammuVersion(),VERSION);
8365 exit(-1); 8391 exit(-1);
8366 } 8392 }
8367 8393
8368 /* Check parameters */ 8394 /* Check parameters */
8369 while (Parameters[z].Function != NULL) { 8395 while (Parameters[z].Function != NULL) {
8370 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { 8396 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) {
8371 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { 8397 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) {
8398 fprintf(stderr,"Executing \n");
8372 Parameters[z].Function(argc - start, argv + start); 8399 Parameters[z].Function(argc - start, argv + start);
8373 break; 8400 break;
8374 } else { 8401 } else {
8375 count_failed = true; 8402 count_failed = true;
8376 } 8403 }
8377 } 8404 }
8378 z++; 8405 z++;
8379 } 8406 }
8380 8407
8381 /* Tell user when we did nothing */ 8408 /* Tell user when we did nothing */
8382 if (Parameters[z].Function == NULL) { 8409 if (Parameters[z].Function == NULL) {
8383 HelpGeneral(); 8410 HelpGeneral();
8384 if (count_failed) { 8411 if (count_failed) {
8385 printmsg("Bad parameter count!\n"); 8412 printmsg("Bad parameter count!\n");
8386 } else { 8413 } else {
8387 printmsg("Bad option!\n"); 8414 printmsg("Bad option!\n");
8388 } 8415 }
8389 } 8416 }
8390 8417
8391 /* Close debug output if opened */ 8418 /* Close debug output if opened */
8392 if (di.df!=stdout) fclose(di.df); 8419 if (di.df!=stdout) fclose(di.df);
8393 //#endif // 0 8420 //#endif // 0
8394 fprintf(stderr,"kammu: Success. End. \n"); 8421 fprintf(stderr,"kammu: Success. End. \n");
8395 exit(0); 8422 exit(0);
8396} 8423}
8397 8424
8398/* How should editor hadle tabs in this file? Add editor commands here. 8425/* How should editor hadle tabs in this file? Add editor commands here.
8399 * vim: noexpandtab sw=8 ts=8 sts=8: 8426 * vim: noexpandtab sw=8 ts=8 sts=8:
8400 */ 8427 */
8401 8428