wrong character in the GSM 03.38 table (ç for Ç)
[gammu.git] / helper / message-cmdline.c
blob4860553b730d285669bd7cde85384b88e5bb4d43
1 #define _GNU_SOURCE /* For strcasestr */
2 #include <string.h>
3 #include <stdarg.h>
4 #include <signal.h>
5 #include <stdlib.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #ifdef WIN32
9 # include <io.h>
10 #else
11 # include <unistd.h>
12 #endif
14 #include <gammu.h>
16 #include "locales.h"
18 #include "formats.h"
19 #include "printing.h"
20 #include "string.h"
21 #include "message-cmdline.h"
22 #include "cmdline.h"
24 typedef enum {
25 COMPOSE_ANIMATION = 1,
26 COMPOSE_BOOKMARK,
27 COMPOSE_CALENDAR,
28 COMPOSE_CALLER,
29 COMPOSE_EMS,
30 COMPOSE_MMSINDICATOR,
31 COMPOSE_MMSSETTINGS,
32 COMPOSE_OPERATOR,
33 COMPOSE_PICTURE,
34 COMPOSE_PROFILE,
35 COMPOSE_RINGTONE,
36 COMPOSE_SMSTEMPLATE,
37 COMPOSE_TEXT,
38 COMPOSE_TODO,
39 COMPOSE_VCARD10,
40 COMPOSE_VCARD21,
41 COMPOSE_WAPINDICATOR,
42 COMPOSE_WAPSETTINGS
43 } ComposeType;
45 typedef struct {
46 const char *name;
47 const ComposeType type;
48 } ComposeMapEntry;
50 ComposeMapEntry ComposeMap[] = {
51 {"ANIMATION", COMPOSE_ANIMATION},
52 {"BOOKMARK", COMPOSE_BOOKMARK},
53 {"CALENDAR", COMPOSE_CALENDAR},
54 {"CALLER", COMPOSE_CALLER},
55 {"EMS", COMPOSE_EMS},
56 {"MMSINDICATOR", COMPOSE_MMSINDICATOR},
57 {"MMSSETTINGS", COMPOSE_MMSSETTINGS},
58 {"OPERATOR", COMPOSE_OPERATOR},
59 {"PICTURE", COMPOSE_PICTURE},
60 {"PROFILE", COMPOSE_PROFILE},
61 {"RINGTONE", COMPOSE_RINGTONE},
62 {"SMSTEMPLATE", COMPOSE_SMSTEMPLATE},
63 {"TEXT", COMPOSE_TEXT},
64 {"TODO", COMPOSE_TODO},
65 {"VCARD10", COMPOSE_VCARD10},
66 {"VCARD21", COMPOSE_VCARD21},
67 {"WAPINDICATOR", COMPOSE_WAPINDICATOR},
68 {"WAPSETTINGS", COMPOSE_WAPSETTINGS},
69 {NULL, 0}
73 #define BMP_AUTO_ALLOC(n) \
74 if (bitmap[n] == NULL) { \
75 bitmap[n] = (GSM_MultiBitmap *)malloc(sizeof(GSM_MultiBitmap)); \
76 if (bitmap[n] == NULL) { \
77 error = ERR_MOREMEMORY; \
78 goto end_compose; \
79 } \
80 memset(bitmap[n], 0, sizeof(GSM_MultiBitmap)); \
83 #define RNG_AUTO_ALLOC(n) \
84 if (ringtone[n] == NULL) { \
85 ringtone[n] = (GSM_Ringtone *)malloc(sizeof(GSM_Ringtone)); \
86 if (ringtone[n] == NULL) { \
87 error = ERR_MOREMEMORY; \
88 goto end_compose; \
89 } \
90 memset(ringtone[n], 0, sizeof(GSM_Ringtone)); \
93 #define SEND_SAVE_SMS_BUFFER_SIZE 10000
95 GSM_Error CreateMessage(GSM_Message_Type *type, GSM_MultiSMSMessage *sms, int argc, int typearg, char *argv[], GSM_StateMachine *sm)
97 /**
98 * Whether SMSC is set manually (0) or should be read from phone.
100 int SMSCSet = 1;
101 int startarg;
103 GSM_Error error;
104 #ifdef GSM_ENABLE_BACKUP
105 GSM_Backup Backup;
106 #endif
107 int i,j,z,FramesNum = 0;
108 int Protected = 0;
109 GSM_Ringtone *ringtone[GSM_MAX_MULTI_SMS];
110 GSM_MultiBitmap *bitmap[GSM_MAX_MULTI_SMS];
111 GSM_MultiBitmap bitmap2;
112 GSM_MultiPartSMSInfo SMSInfo;
113 GSM_NetworkInfo NetInfo;
114 GSM_MMSIndicator MMSInfo;
115 FILE *ReplaceFileHadle,*f;
116 unsigned char ReplaceBuffer2 [200],ReplaceBuffer[200];
117 char InputBuffer [SEND_SAVE_SMS_BUFFER_SIZE/2+1];
118 unsigned char Buffer [GSM_MAX_MULTI_SMS][SEND_SAVE_SMS_BUFFER_SIZE];
119 int chars_read = 0;
120 int nextlong = 0;
121 gboolean ReplyViaSameSMSC = FALSE;
122 int MaxSMS = -1;
123 gboolean EMS16Bit = FALSE;
124 int frames_num;
125 int param_value;
127 /* Parameters required only during saving */
128 int Folder = 1; /*Inbox by default */
129 GSM_SMS_State State = SMS_Sent;
131 /* Required only during sending */
132 GSM_SMSValidity Validity;
133 GSM_SMSC PhoneSMSC;
134 gboolean DeliveryReport = FALSE;
135 /* Whether we already got text for TEXT message */
136 gboolean HasText = FALSE;
137 ComposeType compose_type = 0;
139 * Recipient or sender.
141 unsigned char RemoteNumber[(GSM_MAX_NUMBER_LENGTH + 1) * 2];
143 * Name of message.
145 unsigned char Name[(GSM_MAX_SMS_NAME_LENGTH + 1) * 2];
147 * SMSC to use for message.
149 unsigned char SMSC[(GSM_MAX_NUMBER_LENGTH + 1) * 2];
151 /* Some defaults */
152 Name[0] = 0;
153 Name[1] = 0;
155 SMSC[0] = 0;
156 SMSC[1] = 0;
158 ReplaceBuffer[0] = 0;
159 ReplaceBuffer[1] = 0;
161 for (i = 0; i < GSM_MAX_MULTI_SMS; i++) {
162 ringtone[i] = NULL;
163 bitmap[i] = NULL;
166 #ifdef GSM_ENABLE_BACKUP
167 GSM_ClearBackup(&Backup);
168 #endif
170 EncodeUnicode(RemoteNumber, "Gammu", 5);
172 GSM_ClearMultiPartSMSInfo(&SMSInfo);
173 SMSInfo.ReplaceMessage = 0;
174 SMSInfo.EntriesNum = 1;
175 Validity.Format = 0;
176 Validity.Relative = 0;
179 if (*type == SMS_Save) {
180 startarg = typearg + 1;
181 } else {
182 /* When not saving SMS, recipient has to be specified */
183 if (typearg + 1 >= argc) {
184 printf("%s\n", _("Not enough parameters!"));
185 exit(-1);
187 EncodeUnicode(RemoteNumber, argv[typearg + 1], strlen(argv[typearg + 1]));
188 startarg = typearg + 2;
191 if (*type == SMS_SMSD || *type == SMS_Display) {
193 * We don't care about SMSC number here, SMSD handles this
194 * itself and for displaying we don't really need a SMSC
195 * number.
197 SMSCSet = 0;
200 for (i = 0; ComposeMap[i].type != 0; i++) {
201 if (strcasecmp(argv[typearg], ComposeMap[i].name) == 0) {
202 compose_type = ComposeMap[i].type;
203 break;
207 if (compose_type == 0) {
208 printf(_("What format of sms (\"%s\") ?\n"),argv[typearg]);
209 exit(-1);
212 switch (compose_type) {
213 case COMPOSE_TEXT:
214 /* Text is fed to the buffer later! */
215 SMSInfo.Entries[0].Buffer = Buffer[0];
216 SMSInfo.Entries[0].ID = SMS_Text;
217 SMSInfo.UnicodeCoding = FALSE;
218 break;
219 case COMPOSE_SMSTEMPLATE:
220 SMSInfo.UnicodeCoding = FALSE;
221 SMSInfo.EntriesNum = 1;
222 Buffer[0][0] = 0x00;
223 Buffer[0][1] = 0x00;
224 SMSInfo.Entries[0].Buffer = Buffer[0];
225 SMSInfo.Entries[0].ID = SMS_AlcatelSMSTemplateName;
226 break;
227 case COMPOSE_EMS:
228 SMSInfo.UnicodeCoding = FALSE;
229 SMSInfo.EntriesNum = 0;
230 break;
231 case COMPOSE_MMSINDICATOR:
232 if (argc < 3 + startarg) {
233 printf("%s\n", _("Where are parameters?"));
234 exit(-1);
236 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong;
237 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
238 if (*type == SMS_Save) {
239 EncodeUnicode(RemoteNumber,"MMS Info",8);
241 strcpy(MMSInfo.Address, argv[0 + startarg]);
242 strcpy(MMSInfo.Title, argv[1 + startarg]);
243 strcpy(MMSInfo.Sender, argv[2 + startarg]);
244 MMSInfo.Class = GSM_MMS_Auto;
245 MMSInfo.MessageSize = 0;
246 startarg += 3;
247 break;
248 case COMPOSE_WAPINDICATOR:
249 if (argc < 2 + startarg) {
250 printf("%s\n", _("Where are parameters?"));
251 exit(-1);
253 SMSInfo.Entries[0].ID = SMS_WAPIndicatorLong;
254 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
255 if (*type == SMS_Save) {
256 EncodeUnicode(RemoteNumber,"WAP Info",8);
258 strcpy(MMSInfo.Address, argv[0 + startarg]);
259 strcpy(MMSInfo.Title, argv[1 + startarg]);
260 startarg += 2;
261 break;
262 case COMPOSE_RINGTONE:
263 if (argc < 1 + startarg) {
264 printf("%s\n", _("Where is ringtone filename?"));
265 exit(-1);
267 RNG_AUTO_ALLOC(0);
268 ringtone[0]->Format = RING_NOTETONE;
269 error=GSM_ReadRingtoneFile(argv[startarg], ringtone[0]);
270 if (error != ERR_NONE) goto end_compose;
271 SMSInfo.Entries[0].ID = SMS_NokiaRingtone;
272 SMSInfo.Entries[0].Ringtone = ringtone[0];
273 if (*type == SMS_Save) {
274 CopyUnicodeString(RemoteNumber, ringtone[0]->Name);
275 EncodeUnicode(Name,"Ringtone ",9);
276 CopyUnicodeString(Name+9*2, ringtone[0]->Name);
278 startarg += 1;
279 break;
280 case COMPOSE_OPERATOR:
281 if (argc < 1 + startarg) {
282 printf("%s\n", _("Where is logo filename?"));
283 exit(-1);
285 BMP_AUTO_ALLOC(0);
286 bitmap[0]->Bitmap[0].Type = GSM_OperatorLogo;
287 error=GSM_ReadBitmapFile(argv[startarg], bitmap[0]);
288 if (error != ERR_NONE) goto end_compose;
289 strcpy(bitmap[0]->Bitmap[0].NetworkCode,"000 00");
290 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogo;
291 SMSInfo.Entries[0].Bitmap = bitmap[0];
292 if (*type == SMS_Save) {
293 EncodeUnicode(RemoteNumber, "OpLogo",6);
294 EncodeUnicode(Name,"OpLogo ",7);
296 startarg += 1;
297 break;
298 case COMPOSE_CALLER:
299 if (argc < 1 + startarg) {
300 printf("%s\n", _("Where is logo filename?"));
301 exit(-1);
303 BMP_AUTO_ALLOC(0);
304 bitmap[0]->Bitmap[0].Type = GSM_CallerGroupLogo;
305 error=GSM_ReadBitmapFile(argv[startarg], bitmap[0]);
306 if (error != ERR_NONE) goto end_compose;
307 SMSInfo.Entries[0].ID = SMS_NokiaCallerLogo;
308 SMSInfo.Entries[0].Bitmap = bitmap[0];
309 if (*type == SMS_Save) {
310 EncodeUnicode(RemoteNumber, "Caller",6);
312 startarg += 1;
313 break;
314 case COMPOSE_ANIMATION:
315 SMSInfo.UnicodeCoding = FALSE;
316 SMSInfo.EntriesNum = 1;
317 if (argc < 1 + startarg) {
318 printf("%s\n", _("Where is number of frames?"));
319 exit(-1);
321 BMP_AUTO_ALLOC(0);
322 bitmap[0]->Number = 0;
323 i = 1;
324 frames_num = GetInt(argv[startarg]);
325 if (frames_num > GSM_MAX_MULTI_BITMAP) {
326 printf("%s\n", _("Too many animation frames!"));
327 exit(-1);
329 while (1) {
330 bitmap2.Bitmap[0].Type = GSM_StartupLogo;
331 error=GSM_ReadBitmapFile(argv[startarg + i],&bitmap2);
332 if (error != ERR_NONE) goto end_compose;
333 for (j=0;j<bitmap2.Number;j++) {
334 if (bitmap[0]->Number == frames_num)
335 break;
336 memcpy(&bitmap[0]->Bitmap[bitmap[0]->Number],&bitmap2.Bitmap[j],sizeof(GSM_Bitmap));
337 bitmap[0]->Number++;
339 if (bitmap[0]->Number == frames_num)
340 break;
341 i++;
343 SMSInfo.Entries[0].ID = SMS_AlcatelMonoAnimationLong;
344 SMSInfo.Entries[0].Bitmap = bitmap[0];
345 bitmap[0]->Bitmap[0].Text[0] = 0;
346 bitmap[0]->Bitmap[0].Text[1] = 0;
347 startarg += 1 + frames_num;
348 break;
349 case COMPOSE_PICTURE:
350 if (argc < 1 + startarg) {
351 printf("%s\n", _("Where is logo filename?"));
352 exit(-1);
354 BMP_AUTO_ALLOC(0);
355 bitmap[0]->Bitmap[0].Type = GSM_PictureImage;
356 error=GSM_ReadBitmapFile(argv[startarg], bitmap[0]);
357 printf(_("File \"%s\"\n"),argv[startarg]);
358 if (error != ERR_NONE) goto end_compose;
359 SMSInfo.Entries[0].ID = SMS_NokiaPictureImageLong;
360 SMSInfo.Entries[0].Bitmap = bitmap[0];
361 SMSInfo.UnicodeCoding = FALSE;
362 bitmap[0]->Bitmap[0].Text[0] = 0;
363 bitmap[0]->Bitmap[0].Text[1] = 0;
364 if (*type == SMS_Save) {
365 EncodeUnicode(RemoteNumber, "Picture",7);
366 EncodeUnicode(Name,"Picture Image",13);
368 startarg += 1;
369 break;
370 #ifdef GSM_ENABLE_BACKUP
371 case COMPOSE_BOOKMARK:
372 if (argc < 2 + startarg) {
373 printf("%s\n", _("Where is backup filename and location?"));
374 exit(-1);
376 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
377 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
378 i = 0;
379 while (Backup.WAPBookmark[i]!=NULL) {
380 if (i == GetInt(argv[1 + startarg])-1) break;
381 i++;
383 if (i != GetInt(argv[1 + startarg])-1) {
384 printf("%s\n", _("Bookmark not found in file"));
385 exit(-1);
387 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
388 SMSInfo.Entries[0].Bookmark = Backup.WAPBookmark[i];
389 if (*type == SMS_Save) {
390 EncodeUnicode(RemoteNumber, "Bookmark",8);
391 EncodeUnicode(Name,"WAP Bookmark",12);
393 startarg += 2;
394 break;
395 case COMPOSE_WAPSETTINGS:
396 if (argc < 3 + startarg) {
397 printf("%s\n", _("Where is backup filename and location?"));
398 exit(-1);
400 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
401 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
402 i = 0;
403 while (Backup.WAPSettings[i]!=NULL) {
404 if (i == GetInt(argv[1 + startarg])-1) break;
405 i++;
407 if (i != GetInt(argv[1 + startarg])-1 || Backup.WAPSettings[i] == NULL) {
408 printf("%s\n", _("WAP settings not found in file"));
409 exit(-1);
411 SMSInfo.Entries[0].Settings = NULL;
412 for (j=0;j<Backup.WAPSettings[i]->Number;j++) {
413 switch (Backup.WAPSettings[i]->Settings[j].Bearer) {
414 case WAPSETTINGS_BEARER_GPRS:
415 if (strcasecmp(argv[2 + startarg],"GPRS") == 0) {
416 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
417 break;
419 case WAPSETTINGS_BEARER_DATA:
420 if (strcasecmp(argv[2 + startarg],"DATA") == 0) {
421 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
422 break;
424 default:
425 break;
428 if (SMSInfo.Entries[0].Settings == NULL) {
429 printf("%s\n", _("Sorry. For now there is only support for GPRS or DATA bearers end"));
430 exit(-1);
432 SMSInfo.Entries[0].ID = SMS_NokiaWAPSettingsLong;
433 if (*type == SMS_Save) {
434 EncodeUnicode(RemoteNumber, "Settings",8);
435 EncodeUnicode(Name,"WAP Settings",12);
437 startarg += 3;
438 break;
439 case COMPOSE_MMSSETTINGS:
440 if (argc < 2 + startarg) {
441 printf("%s\n", _("Where is backup filename and location?"));
442 exit(-1);
444 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
445 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
446 i = 0;
447 while (Backup.MMSSettings[i]!=NULL) {
448 if (i == GetInt(argv[1 + startarg])-1) break;
449 i++;
451 if (i != GetInt(argv[1 + startarg])-1 || Backup.MMSSettings[i] == NULL) {
452 printf("%s\n", _("MMS settings not found in file"));
453 exit(-1);
455 SMSInfo.Entries[0].Settings = NULL;
456 for (j=0;j<Backup.MMSSettings[i]->Number;j++) {
457 switch (Backup.MMSSettings[i]->Settings[j].Bearer) {
458 case WAPSETTINGS_BEARER_GPRS:
459 SMSInfo.Entries[0].Settings = &Backup.MMSSettings[i]->Settings[j];
460 break;
461 default:
462 break;
465 if (SMSInfo.Entries[0].Settings == NULL) {
466 printf("%s\n", _("Sorry. No GPRS bearer found in MMS settings"));
467 exit(-1);
469 SMSInfo.Entries[0].ID = SMS_NokiaMMSSettingsLong;
470 if (*type == SMS_Save) {
471 EncodeUnicode(RemoteNumber, "Settings",8);
472 EncodeUnicode(Name,"MMS Settings",12);
474 startarg += 2;
475 break;
476 case COMPOSE_CALENDAR:
477 if (argc < 2 + startarg) {
478 printf("%s\n", _("Where is backup filename and location?"));
479 exit(-1);
481 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
482 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
483 i = 0;
484 while (Backup.Calendar[i]!=NULL) {
485 if (i == GetInt(argv[1 + startarg])-1) break;
486 i++;
488 if (i != GetInt(argv[1 + startarg])-1) {
489 printf("%s\n", _("Calendar note not found in file"));
490 exit(-1);
492 SMSInfo.Entries[0].ID = SMS_NokiaVCALENDAR10Long;
493 SMSInfo.Entries[0].Calendar = Backup.Calendar[i];
494 if (*type == SMS_Save) {
495 EncodeUnicode(RemoteNumber, "Calendar",8);
497 startarg += 2;
498 break;
499 case COMPOSE_TODO:
500 if (argc < 2 + startarg) {
501 printf("%s\n", _("Where is backup filename and location?"));
502 exit(-1);
504 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
505 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
506 i = 0;
507 while (Backup.ToDo[i]!=NULL) {
508 if (i == GetInt(argv[1 + startarg])-1) break;
509 i++;
511 if (i != GetInt(argv[1 + startarg])-1) {
512 printf("%s\n", _("ToDo note not found in file"));
513 exit(-1);
515 SMSInfo.Entries[0].ID = SMS_NokiaVTODOLong;
516 SMSInfo.Entries[0].ToDo = Backup.ToDo[i];
517 if (*type == SMS_Save) {
518 EncodeUnicode(RemoteNumber, "ToDo",8);
520 startarg += 2;
521 break;
522 case COMPOSE_VCARD10:
523 case COMPOSE_VCARD21:
524 if (argc < 3 + startarg) {
525 printf("%s\n", _("Where is backup filename and location and memory type?"));
526 exit(-1);
528 error=GSM_ReadBackupFile(argv[startarg],&Backup,GSM_GuessBackupFormat(argv[startarg], FALSE));
529 if (error != ERR_NONE && error != ERR_NOTIMPLEMENTED) goto end_compose;
530 i = 0;
531 if (strcasecmp(argv[1 + startarg],"SM") == 0) {
532 while (Backup.SIMPhonebook[i]!=NULL) {
533 if (i == GetInt(argv[2 + startarg])-1) break;
534 i++;
536 if (i != GetInt(argv[2 + startarg])-1) {
537 printf("%s\n", _("Phonebook entry not found in file"));
538 exit(-1);
540 SMSInfo.Entries[0].Phonebook = Backup.SIMPhonebook[i];
541 } else if (strcasecmp(argv[1 + startarg],"ME") == 0) {
542 while (Backup.PhonePhonebook[i]!=NULL) {
543 if (i == GetInt(argv[2 + startarg])-1) break;
544 i++;
546 if (i != GetInt(argv[2 + startarg])-1) {
547 printf("%s\n", _("Phonebook entry not found in file"));
548 exit(-1);
550 SMSInfo.Entries[0].Phonebook = Backup.PhonePhonebook[i];
551 } else {
552 printf(_("Unknown memory type: \"%s\"\n"),argv[1 + startarg]);
553 exit(-1);
555 if (compose_type == COMPOSE_VCARD10) {
556 SMSInfo.Entries[0].ID = SMS_VCARD10Long;
557 } else {
558 SMSInfo.Entries[0].ID = SMS_VCARD21Long;
560 if (*type == SMS_Save) {
561 EncodeUnicode(RemoteNumber, "VCARD",5);
562 EncodeUnicode(Name, "Phonebook entry",15);
564 startarg += 3;
565 break;
566 #else
567 case COMPOSE_BOOKMARK:
568 case COMPOSE_WAPSETTINGS:
569 case COMPOSE_MMSSETTINGS:
570 case COMPOSE_CALENDAR:
571 case COMPOSE_TODO:
572 case COMPOSE_VCARD10:
573 case COMPOSE_VCARD21:
574 printf("%s\n", _("Backup functionality not compiled in!"));
575 exit(100 + ERR_DISABLED);
576 break;
577 #endif
578 case COMPOSE_PROFILE:
579 SMSInfo.Entries[0].ID = SMS_NokiaProfileLong;
580 if (*type == SMS_Save) {
581 EncodeUnicode(RemoteNumber, "Profile",7);
583 break;
586 for (i = startarg; i < argc; i++) {
587 switch (nextlong) {
588 case 0:
589 if (*type == SMS_Save || *type == SMS_SendSaved) {
590 if (strcasecmp(argv[i],"-folder") == 0) {
591 nextlong=1;
592 continue;
595 if (*type == SMS_Save) {
596 if (strcasecmp(argv[i],"-unread") == 0) {
597 State = SMS_UnRead;
598 continue;
600 if (strcasecmp(argv[i],"-read") == 0) {
601 State = SMS_Read;
602 continue;
604 if (strcasecmp(argv[i],"-unsent") == 0) {
605 State = SMS_UnSent;
606 continue;
608 if (strcasecmp(argv[i],"-sent") == 0) {
609 State = SMS_Sent;
610 continue;
612 if (strcasecmp(argv[i],"-sender") == 0) {
613 nextlong=2;
614 continue;
616 if (strcasecmp(argv[i],"-smsname") == 0) {
617 nextlong=25;
618 continue;
620 } else {
621 if (strcasecmp(argv[i],"-save") == 0) {
622 *type = SMS_SendSaved;
623 continue;
625 if (strcasecmp(argv[i],"-report") == 0) {
626 DeliveryReport=TRUE;
627 continue;
629 if (strcasecmp(argv[i],"-validity") == 0) {
630 nextlong=10;
631 continue;
634 if (strcasecmp(argv[i],"-smscset") == 0) {
635 nextlong=3;
636 continue;
638 if (strcasecmp(argv[i],"-smscnumber") == 0) {
639 nextlong=4;
640 continue;
642 if (strcasecmp(argv[i],"-protected") == 0) {
643 nextlong=19;
644 continue;
646 if (strcasecmp(argv[i],"-reply") == 0) {
647 ReplyViaSameSMSC=TRUE;
648 continue;
650 if (strcasecmp(argv[i],"-maxsms") == 0) {
651 nextlong=21;
652 continue;
654 if (compose_type == COMPOSE_RINGTONE) {
655 if (strcasecmp(argv[i],"-long") == 0) {
656 SMSInfo.Entries[0].ID = SMS_NokiaRingtoneLong;
657 break;
659 if (strcasecmp(argv[i],"-scale") == 0) {
660 RNG_AUTO_ALLOC(0);
661 ringtone[0]->NoteTone.AllNotesScale=TRUE;
662 break;
665 if (compose_type == COMPOSE_TEXT) {
666 if (strcasecmp(argv[i],"-text") == 0) {
667 nextlong = 26;
668 break;
670 if (strcasecmp(argv[i],"-textutf8") == 0) {
671 nextlong = 27;
672 break;
674 if (strcasecmp(argv[i],"-inputunicode") == 0) {
675 ReadUnicodeFile(Buffer[0],InputBuffer);
676 break;
678 if (strcasecmp(argv[i],"-16bit") == 0) {
679 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong16bit;
680 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedAutoTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong16bit;
681 break;
683 if (strcasecmp(argv[i],"-flash") == 0) {
684 SMSInfo.Class = 0;
685 break;
687 if (strcasecmp(argv[i],"-len") == 0) {
688 nextlong = 5;
689 break;
691 /* Backward compatibility with bad docs */
692 if (strcasecmp(argv[i],"-maxlen") == 0) {
693 nextlong = 5;
694 break;
696 if (strcasecmp(argv[i],"-autolen") == 0) {
697 nextlong = 5;
698 break;
700 if (strcasecmp(argv[i],"-unicode") == 0) {
701 SMSInfo.UnicodeCoding = TRUE;
702 break;
704 if (strcasecmp(argv[i],"-enablevoice") == 0) {
705 SMSInfo.Entries[0].ID = SMS_EnableVoice;
706 break;
708 if (strcasecmp(argv[i],"-disablevoice") == 0) {
709 SMSInfo.Entries[0].ID = SMS_DisableVoice;
710 break;
712 if (strcasecmp(argv[i],"-enablefax") == 0) {
713 SMSInfo.Entries[0].ID = SMS_EnableFax;
714 break;
716 if (strcasecmp(argv[i],"-disablefax") == 0) {
717 SMSInfo.Entries[0].ID = SMS_DisableFax;
718 break;
720 if (strcasecmp(argv[i],"-enableemail") == 0) {
721 SMSInfo.Entries[0].ID = SMS_EnableEmail;
722 break;
724 if (strcasecmp(argv[i],"-disableemail") == 0) {
725 SMSInfo.Entries[0].ID = SMS_DisableEmail;
726 break;
728 if (strcasecmp(argv[i],"-voidsms") == 0) {
729 SMSInfo.Entries[0].ID = SMS_VoidSMS;
730 break;
732 if (strcasecmp(argv[i],"-replacemessages") == 0 &&
733 SMSInfo.Entries[0].ID != SMS_ConcatenatedTextLong) {
734 nextlong = 8;
735 break;
737 if (strcasecmp(argv[i],"-replacefile") == 0) {
738 nextlong = 9;
739 continue;
742 if (compose_type == COMPOSE_PICTURE) {
743 if (strcasecmp(argv[i],"-text") == 0) {
744 nextlong = 6;
745 break;
747 if (strcasecmp(argv[i],"-unicode") == 0) {
748 SMSInfo.UnicodeCoding = TRUE;
749 break;
751 if (strcasecmp(argv[i],"-alcatelbmmi") == 0) {
752 BMP_AUTO_ALLOC(0);
753 bitmap[0]->Bitmap[0].Type = GSM_StartupLogo;
754 error = GSM_ReadBitmapFile(argv[startarg-1], bitmap[0]);
755 if (error != ERR_NONE) goto end_compose;
756 SMSInfo.UnicodeCoding = TRUE;
757 SMSInfo.Entries[0].ID = SMS_AlcatelMonoBitmapLong;
758 break;
760 break;
762 if (compose_type == COMPOSE_VCARD10) {
763 if (strcasecmp(argv[i],"-nokia") == 0) {
764 SMSInfo.Entries[0].ID = SMS_NokiaVCARD10Long;
765 break;
767 break;
769 if (compose_type == COMPOSE_VCARD21) {
770 if (strcasecmp(argv[i],"-nokia") == 0) {
771 SMSInfo.Entries[0].ID = SMS_NokiaVCARD21Long;
772 break;
774 break;
776 if (compose_type == COMPOSE_PROFILE) {
777 if (strcasecmp(argv[i],"-name") == 0) {
778 nextlong = 22;
779 break;
781 if (strcasecmp(argv[i],"-ringtone") == 0) {
782 nextlong = 23;
783 break;
785 if (strcasecmp(argv[i],"-bitmap") == 0) {
786 nextlong = 24;
787 break;
790 if (compose_type == COMPOSE_SMSTEMPLATE) {
791 if (strcasecmp(argv[i],"-unicode") == 0) {
792 SMSInfo.UnicodeCoding = TRUE;
793 break;
795 if (strcasecmp(argv[i],"-text") == 0) {
796 nextlong = 11;
797 break;
799 if (strcasecmp(argv[i],"-unicodefiletext") == 0) {
800 nextlong = 18;
801 break;
803 if (strcasecmp(argv[i],"-defsound") == 0) {
804 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedSound;
805 nextlong = 12;
806 break;
808 if (strcasecmp(argv[i],"-defanimation") == 0) {
809 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedAnimation;
810 nextlong = 12;
811 break;
813 if (strcasecmp(argv[i],"-tone10") == 0) {
814 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10;
815 if (Protected != 0) {
816 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
817 Protected --;
819 nextlong = 14;
820 break;
822 if (strcasecmp(argv[i],"-tone10long") == 0) {
823 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10Long;
824 if (Protected != 0) {
825 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
826 Protected --;
828 nextlong = 14;
829 break;
831 if (strcasecmp(argv[i],"-tone12") == 0) {
832 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12;
833 if (Protected != 0) {
834 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
835 Protected --;
837 nextlong = 14;
838 break;
840 if (strcasecmp(argv[i],"-tone12long") == 0) {
841 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12Long;
842 if (Protected != 0) {
843 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
844 Protected --;
846 nextlong = 14;
847 break;
849 if (strcasecmp(argv[i],"-toneSE") == 0) {
850 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSound;
851 if (Protected != 0) {
852 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
853 Protected --;
855 nextlong = 14;
856 break;
858 if (strcasecmp(argv[i],"-toneSElong") == 0) {
859 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSoundLong;
860 if (Protected != 0) {
861 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
862 Protected --;
864 nextlong = 14;
865 break;
867 if (strcasecmp(argv[i],"-variablebitmap") == 0) {
868 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmap;
869 if (Protected != 0) {
870 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
871 Protected --;
873 nextlong = 15;
874 break;
876 if (strcasecmp(argv[i],"-variablebitmaplong") == 0) {
877 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmapLong;
878 if (Protected != 0) {
879 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
880 Protected --;
882 nextlong = 15;
883 break;
885 if (strcasecmp(argv[i],"-animation") == 0) {
886 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSAnimation;
887 if (Protected != 0) {
888 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
889 Protected --;
891 BMP_AUTO_ALLOC(SMSInfo.EntriesNum);
892 bitmap[SMSInfo.EntriesNum]->Number = 0;
893 nextlong = 16;
894 break;
897 if (compose_type == COMPOSE_EMS) {
898 if (strcasecmp(argv[i],"-unicode") == 0) {
899 SMSInfo.UnicodeCoding = TRUE;
900 break;
902 if (strcasecmp(argv[i],"-16bit") == 0) {
903 EMS16Bit = TRUE;
904 break;
906 if (strcasecmp(argv[i],"-format") == 0) {
907 nextlong = 20;
908 break;
910 if (strcasecmp(argv[i],"-text") == 0) {
911 nextlong = 11;
912 break;
914 if (strcasecmp(argv[i],"-unicodefiletext") == 0) {
915 nextlong = 18;
916 break;
918 if (strcasecmp(argv[i],"-defsound") == 0) {
919 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedSound;
920 nextlong = 12;
921 break;
923 if (strcasecmp(argv[i],"-defanimation") == 0) {
924 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedAnimation;
925 nextlong = 12;
926 break;
928 if (strcasecmp(argv[i],"-tone10") == 0) {
929 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10;
930 if (Protected != 0) {
931 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
932 Protected --;
934 nextlong = 14;
935 break;
937 if (strcasecmp(argv[i],"-tone10long") == 0) {
938 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10Long;
939 if (Protected != 0) {
940 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
941 Protected --;
943 nextlong = 14;
944 break;
946 if (strcasecmp(argv[i],"-tone12") == 0) {
947 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12;
948 if (Protected != 0) {
949 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
950 Protected --;
952 nextlong = 14;
953 break;
955 if (strcasecmp(argv[i],"-tone12long") == 0) {
956 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12Long;
957 if (Protected != 0) {
958 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
959 Protected --;
961 nextlong = 14;
962 break;
964 if (strcasecmp(argv[i],"-toneSE") == 0) {
965 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSound;
966 if (Protected != 0) {
967 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
968 Protected --;
970 nextlong = 14;
971 break;
973 if (strcasecmp(argv[i],"-toneSElong") == 0) {
974 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSoundLong;
975 if (Protected != 0) {
976 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
977 Protected --;
979 nextlong = 14;
980 break;
982 if (strcasecmp(argv[i],"-fixedbitmap") == 0) {
983 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSFixedBitmap;
984 if (Protected != 0) {
985 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
986 Protected --;
988 nextlong = 15;
989 break;
991 if (strcasecmp(argv[i],"-variablebitmap") == 0) {
992 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmap;
993 if (Protected != 0) {
994 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
995 Protected --;
997 nextlong = 15;
998 break;
1000 if (strcasecmp(argv[i],"-variablebitmaplong") == 0) {
1001 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmapLong;
1002 if (Protected != 0) {
1003 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
1004 Protected --;
1006 nextlong = 15;
1007 break;
1009 if (strcasecmp(argv[i],"-animation") == 0) {
1010 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSAnimation;
1011 if (Protected != 0) {
1012 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = TRUE;
1013 Protected --;
1015 BMP_AUTO_ALLOC(SMSInfo.EntriesNum);
1016 bitmap[SMSInfo.EntriesNum]->Number = 0;
1017 nextlong = 16;
1018 break;
1021 if (compose_type == COMPOSE_OPERATOR) {
1022 if (strcasecmp(argv[i],"-netcode") == 0) {
1023 nextlong = 7;
1024 break;
1026 if (strcasecmp(argv[i],"-biglogo") == 0) {
1027 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogoLong;
1028 break;
1030 break;
1032 printf(_("Unknown parameter (\"%s\")\n"),argv[i]);
1033 exit(-1);
1034 break;
1035 case 1: /* SMS folder - only during saving SMS */
1036 Folder = GetInt(argv[i]);
1037 nextlong = 0;
1038 break;
1039 case 2: /* Remote number - only during saving SMS */
1040 EncodeUnicode(RemoteNumber,argv[i],strlen(argv[i]));
1041 nextlong = 0;
1042 break;
1043 case 3: /* SMSC set number */
1044 SMSCSet = GetInt(argv[i]);
1045 nextlong = 0;
1046 break;
1047 case 4: /* Number of SMSC */
1048 EncodeUnicode(SMSC,argv[i],strlen(argv[i]));
1049 SMSCSet = 0;
1050 nextlong = 0;
1051 break;
1052 case 5: /* Length of text SMS */
1053 param_value = GetInt(argv[i]);
1054 if (param_value <= 0) {
1055 printf(_("Wrong message length (\"%s\")\n"),argv[i]);
1056 exit(-1);
1058 printf("%d / %d\n", param_value, chars_read);
1059 if (param_value < chars_read) {
1060 Buffer[0][param_value * 2] = 0x00;
1061 Buffer[0][param_value * 2 + 1] = 0x00;
1063 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
1064 if (strcasecmp(argv[i-1],"-autolen") == 0) {
1065 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
1067 nextlong = 0;
1068 break;
1069 case 6: /* Picture Images - text */
1070 BMP_AUTO_ALLOC(0);
1071 EncodeUnicode(bitmap[0]->Bitmap[0].Text,argv[i],strlen(argv[i]));
1072 nextlong = 0;
1073 break;
1074 case 7: /* Operator Logo - network code */
1075 BMP_AUTO_ALLOC(0);
1076 strncpy(bitmap[0]->Bitmap[0].NetworkCode,argv[i],7);
1077 if (!strcmp(DecodeUnicodeConsole(GSM_GetNetworkName(bitmap[0]->Bitmap[0].NetworkCode)),"unknown")) {
1078 printf(_("Unknown GSM network code (\"%s\")\n"),argv[i]);
1079 exit(-1);
1081 if (*type == SMS_Save) {
1082 EncodeUnicode(RemoteNumber, "OpLogo",6);
1083 EncodeUnicode(RemoteNumber+6*2,bitmap[0]->Bitmap[0].NetworkCode,3);
1084 EncodeUnicode(RemoteNumber+6*2+3*2,bitmap[0]->Bitmap[0].NetworkCode+4,2);
1085 if (UnicodeLength(GSM_GetNetworkName(bitmap[0]->Bitmap[0].NetworkCode))<GSM_MAX_SMS_NAME_LENGTH-7) {
1086 EncodeUnicode(Name,"OpLogo ",7);
1087 CopyUnicodeString(Name+7*2,GSM_GetNetworkName(bitmap[0]->Bitmap[0].NetworkCode));
1088 } else {
1089 CopyUnicodeString(Name,RemoteNumber);
1092 nextlong = 0;
1093 break;
1094 case 8:/* Reject duplicates ID */
1095 SMSInfo.ReplaceMessage = GetInt(argv[i]);
1096 if (SMSInfo.ReplaceMessage < 1 || SMSInfo.ReplaceMessage > 7) {
1097 printf(_("You have to give number between 1 and 7 (\"%s\")\n"),argv[i]);
1098 exit(-1);
1100 nextlong = 0;
1101 break;
1102 case 9:/* Replace file for text SMS */
1103 ReplaceFileHadle = fopen(argv[i], "rb");
1104 if (ReplaceFileHadle == NULL) {
1105 error = ERR_CANTOPENFILE;
1106 goto end_compose;
1108 memset(ReplaceBuffer,0,sizeof(ReplaceBuffer));
1109 if (fread(ReplaceBuffer,1,sizeof(ReplaceBuffer),ReplaceFileHadle) != sizeof(ReplaceBuffer)) {
1110 printf_err("%s", _("Error while writing file!\n"));
1112 fclose(ReplaceFileHadle);
1113 ReadUnicodeFile(ReplaceBuffer2,ReplaceBuffer);
1114 for(j=0;j<(int)(UnicodeLength(Buffer[0]));j++) {
1115 for (z=0;z<(int)(UnicodeLength(ReplaceBuffer2)/2);z++) {
1116 if (ReplaceBuffer2[z*4] == Buffer[0][j] &&
1117 ReplaceBuffer2[z*4+1] == Buffer[0][j+1]) {
1118 Buffer[0][j] = ReplaceBuffer2[z*4+2];
1119 Buffer[0][j+1] = ReplaceBuffer2[z*4+3];
1120 break;
1124 nextlong = 0;
1125 break;
1126 case 10:
1127 Validity.Format = SMS_Validity_RelativeFormat;
1128 if (strcasecmp(argv[i],"HOUR") == 0) Validity.Relative = SMS_VALID_1_Hour;
1129 else if (strcasecmp(argv[i],"6HOURS") == 0) Validity.Relative = SMS_VALID_6_Hours;
1130 else if (strcasecmp(argv[i],"DAY") == 0) Validity.Relative = SMS_VALID_1_Day;
1131 else if (strcasecmp(argv[i],"3DAYS") == 0) Validity.Relative = SMS_VALID_3_Days;
1132 else if (strcasecmp(argv[i],"WEEK") == 0) Validity.Relative = SMS_VALID_1_Week;
1133 else if (strcasecmp(argv[i],"MAX") == 0) Validity.Relative = SMS_VALID_Max_Time;
1134 else {
1135 printf(_("Unknown validity string (\"%s\")\n"),argv[i]);
1136 exit(-1);
1138 nextlong = 0;
1139 break;
1140 case 11:/* EMS text from parameter */
1141 EncodeUnicode(Buffer[SMSInfo.EntriesNum],argv[i],strlen(argv[i]));
1142 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_ConcatenatedTextLong;
1143 SMSInfo.Entries[SMSInfo.EntriesNum].Buffer = Buffer[SMSInfo.EntriesNum];
1144 SMSInfo.EntriesNum++;
1145 nextlong = 0;
1146 break;
1147 case 12:/* EMS predefined sound/animation number */
1148 SMSInfo.Entries[SMSInfo.EntriesNum].Number = GetInt(argv[i]);
1149 SMSInfo.EntriesNum++;
1150 nextlong = 0;
1151 break;
1152 case 14: /* EMS ringtone - IMelody */
1153 RNG_AUTO_ALLOC(SMSInfo.EntriesNum);
1154 ringtone[SMSInfo.EntriesNum]->Format = RING_NOTETONE;
1155 error=GSM_ReadRingtoneFile(argv[i], ringtone[SMSInfo.EntriesNum]);
1156 if (error != ERR_NONE) goto end_compose;
1157 SMSInfo.Entries[SMSInfo.EntriesNum].Ringtone = ringtone[SMSInfo.EntriesNum];
1158 SMSInfo.EntriesNum++;
1159 nextlong = 0;
1160 break;
1161 case 15:/* EMS bitmap file */
1162 BMP_AUTO_ALLOC(SMSInfo.EntriesNum);
1163 bitmap[SMSInfo.EntriesNum]->Bitmap[0].Type = GSM_StartupLogo;
1164 error=GSM_ReadBitmapFile(argv[i], bitmap[SMSInfo.EntriesNum]);
1165 if (error != ERR_NONE) goto end_compose;
1166 SMSInfo.Entries[SMSInfo.EntriesNum].Bitmap = bitmap[SMSInfo.EntriesNum];
1167 SMSInfo.EntriesNum++;
1168 nextlong = 0;
1169 break;
1170 case 16:/* Number of frames for EMS animation */
1171 FramesNum = GetInt(argv[i]);
1172 if (FramesNum < 1 || FramesNum > 4) {
1173 printf(_("You have to give number of EMS frames between 1 and 4 (\"%s\")\n"),argv[i]);
1174 exit(-1);
1176 BMP_AUTO_ALLOC(SMSInfo.EntriesNum);
1177 bitmap[SMSInfo.EntriesNum]->Number = 0;
1178 nextlong = 17;
1179 break;
1180 case 17:/*File for EMS animation */
1181 BMP_AUTO_ALLOC(SMSInfo.EntriesNum);
1182 bitmap2.Bitmap[0].Type=GSM_StartupLogo;
1183 error=GSM_ReadBitmapFile(argv[i],&bitmap2);
1184 if (error != ERR_NONE) {
1185 printf(_("Can't open file \"%s\"\n"),argv[i]);
1186 exit(-1);
1188 for (j=0;j<bitmap2.Number;j++) {
1189 if (bitmap[SMSInfo.EntriesNum]->Number == FramesNum) break;
1190 memcpy(&bitmap[SMSInfo.EntriesNum]->Bitmap[bitmap[SMSInfo.EntriesNum]->Number],&bitmap2.Bitmap[j],sizeof(GSM_Bitmap));
1191 bitmap[SMSInfo.EntriesNum]->Number++;
1193 if (bitmap[SMSInfo.EntriesNum]->Number == FramesNum) {
1194 SMSInfo.Entries[SMSInfo.EntriesNum].Bitmap = bitmap[SMSInfo.EntriesNum];
1195 SMSInfo.EntriesNum++;
1196 nextlong = 0;
1198 break;
1199 case 18:/* EMS text from Unicode file */
1200 f = fopen(argv[i],"rb");
1201 if (f == NULL) {
1202 printf(_("Can't open file \"%s\"\n"),argv[i]);
1203 exit(-1);
1205 z=fread(InputBuffer,1,2000,f);
1206 InputBuffer[z] = 0;
1207 InputBuffer[z+1] = 0;
1208 fclose(f);
1209 ReadUnicodeFile(Buffer[SMSInfo.EntriesNum],InputBuffer);
1210 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_ConcatenatedTextLong;
1211 SMSInfo.Entries[SMSInfo.EntriesNum].Buffer = Buffer[SMSInfo.EntriesNum];
1212 SMSInfo.EntriesNum++;
1213 nextlong = 0;
1214 break;
1215 case 19:/* Number of protected items */
1216 Protected = GetInt(argv[i]);
1217 nextlong = 0;
1218 break;
1219 case 20:/* Formatting text for EMS */
1220 if (SMSInfo.Entries[SMSInfo.EntriesNum-1].ID == SMS_ConcatenatedTextLong) {
1221 for(j=0;j<(int)strlen(argv[i]);j++) {
1222 switch(argv[i][j]) {
1223 case 'l': case 'L':
1224 SMSInfo.Entries[SMSInfo.EntriesNum-1].Left = TRUE;
1225 break;
1226 case 'c': case 'C':
1227 SMSInfo.Entries[SMSInfo.EntriesNum-1].Center = TRUE;
1228 break;
1229 case 'r': case 'R':
1230 SMSInfo.Entries[SMSInfo.EntriesNum-1].Right = TRUE;
1231 break;
1232 case 'a': case 'A':
1233 SMSInfo.Entries[SMSInfo.EntriesNum-1].Large = TRUE;
1234 break;
1235 case 's': case 'S':
1236 SMSInfo.Entries[SMSInfo.EntriesNum-1].Small = TRUE;
1237 break;
1238 case 'b': case 'B':
1239 SMSInfo.Entries[SMSInfo.EntriesNum-1].Bold = TRUE;
1240 break;
1241 case 'i': case 'I':
1242 SMSInfo.Entries[SMSInfo.EntriesNum-1].Italic = TRUE;
1243 break;
1244 case 'u': case 'U':
1245 SMSInfo.Entries[SMSInfo.EntriesNum-1].Underlined = TRUE;
1246 break;
1247 case 't': case 'T':
1248 SMSInfo.Entries[SMSInfo.EntriesNum-1].Strikethrough = TRUE;
1249 break;
1250 default:
1251 printf(_("Unknown parameter (\"%c\")\n"),argv[i][j]);
1252 exit(-1);
1255 } else {
1256 printf("%s\n", _("Last parameter wasn't text"));
1257 exit(-1);
1259 nextlong = 0;
1260 break;
1261 case 21:/*MaxSMS*/
1262 MaxSMS = GetInt(argv[i]);
1263 nextlong = 0;
1264 break;
1265 case 22:/* profile name */
1266 EncodeUnicode(Buffer[0],argv[i],strlen(argv[i]));
1267 SMSInfo.Entries[0].Buffer = Buffer[0];
1268 nextlong = 0;
1269 break;
1270 case 23:/* profile ringtone */
1271 RNG_AUTO_ALLOC(0);
1272 ringtone[0]->Format = RING_NOTETONE;
1273 error=GSM_ReadRingtoneFile(argv[i], ringtone[0]);
1274 if (error != ERR_NONE) goto end_compose;
1275 SMSInfo.Entries[0].Ringtone = ringtone[0];
1276 nextlong = 0;
1277 break;
1278 case 24:/* profile bitmap */
1279 BMP_AUTO_ALLOC(0);
1280 bitmap[0]->Bitmap[0].Type = GSM_PictureImage;
1281 error=GSM_ReadBitmapFile(argv[i], bitmap[0]);
1282 if (error != ERR_NONE) goto end_compose;
1283 bitmap[0]->Bitmap[0].Text[0] = 0;
1284 bitmap[0]->Bitmap[0].Text[1] = 0;
1285 SMSInfo.Entries[0].Bitmap = bitmap[0];
1286 nextlong = 0;
1287 break;
1288 case 25:/* sms name */
1289 if (strlen(argv[i])>GSM_MAX_SMS_NAME_LENGTH) {
1290 printf(_("Too long SMS name (\"%s\"), ignored\n"),argv[i]);
1291 } else {
1292 EncodeUnicode(Name, argv[i],strlen(argv[i]));
1294 nextlong = 0;
1295 break;
1296 case 26:/* text from parameter */
1297 chars_read = strlen(argv[i]);
1298 EncodeUnicode(Buffer[0], argv[i], chars_read);
1299 HasText = TRUE;
1300 nextlong = 0;
1301 break;
1302 case 27:/* utf-8 text from parameter */
1303 chars_read = strlen(argv[i]);
1304 DecodeUTF8(Buffer[0], argv[i], chars_read);
1305 HasText = TRUE;
1306 nextlong = 0;
1307 break;
1310 if (nextlong!=0) {
1311 printf_err("%s\n", _("Parameter missing!"));
1312 exit(-1);
1315 if (compose_type == COMPOSE_EMS && EMS16Bit) {
1316 for (i=0;i<SMSInfo.EntriesNum;i++) {
1317 switch (SMSInfo.Entries[i].ID) {
1318 case SMS_ConcatenatedTextLong:
1319 SMSInfo.Entries[i].ID = SMS_ConcatenatedTextLong16bit;
1320 default:
1321 break;
1327 if (compose_type == COMPOSE_TEXT) {
1328 if (! HasText) {
1329 if (isatty(fileno(stdin))) {
1330 printf(_("Enter the message text and press %s:\n"),
1331 #ifdef WIN32
1332 _("Ctrl+Z")
1333 #else
1334 _("Ctrl+D")
1335 #endif
1338 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin);
1339 /* Zero terminate string */
1340 InputBuffer[chars_read] = 0;
1341 /* Trim \n at the end of string */
1342 if (InputBuffer[chars_read - 1] == '\n') {
1343 chars_read--;
1344 InputBuffer[chars_read] = 0;
1346 /* Warn on no input */
1347 if (chars_read == 0) {
1348 printf_warn("%s\n", _("No chars read, assuming it is okay!"));
1351 EncodeUnicode(Buffer[0],InputBuffer,chars_read);
1354 chars_read = UnicodeLength(Buffer[0]);
1356 if (chars_read != 0) {
1357 /* Trim \n at the end of string */
1358 if (Buffer[0][chars_read*2-1] == '\n' && Buffer[0][chars_read*2-2] == 0)
1360 Buffer[0][chars_read*2-1] = 0;
1365 if (*type == SMS_Display || *type == SMS_SMSD) {
1366 if (compose_type == COMPOSE_OPERATOR) {
1367 if (bitmap[0]->Bitmap[0].Type==GSM_OperatorLogo && strcmp(bitmap[0]->Bitmap[0].NetworkCode,"000 00")==0) {
1368 printf("%s\n", _("No network code"));
1369 exit(-1);
1372 } else {
1373 if (sm == NULL) {
1374 printf_err("%s\n", _("You have to set network code!"));
1375 exit(-1);
1377 if (compose_type == COMPOSE_OPERATOR) {
1378 if (bitmap[0]->Bitmap[0].Type == GSM_OperatorLogo &&
1379 strcmp(bitmap[0]->Bitmap[0].NetworkCode,"000 00")==0) {
1380 error = GSM_GetNetworkInfo(sm,&NetInfo);
1381 if (error != ERR_NONE) goto end_compose;
1382 strcpy(bitmap[0]->Bitmap[0].NetworkCode,NetInfo.NetworkCode);
1383 if (*type == SMS_Save) {
1384 EncodeUnicode(RemoteNumber, "OpLogo",6);
1385 EncodeUnicode(RemoteNumber+6*2,bitmap[0]->Bitmap[0].NetworkCode,3);
1386 EncodeUnicode(RemoteNumber+6*2+3*2,bitmap[0]->Bitmap[0].NetworkCode+4,2);
1387 if (UnicodeLength(GSM_GetNetworkName(bitmap[0]->Bitmap[0].NetworkCode))<GSM_MAX_SMS_NAME_LENGTH-7) {
1388 EncodeUnicode(Name,"OpLogo ",7);
1389 CopyUnicodeString(Name+7*2,GSM_GetNetworkName(bitmap[0]->Bitmap[0].NetworkCode));
1390 } else {
1391 CopyUnicodeString(Name,RemoteNumber);
1398 error = GSM_EncodeMultiPartSMS(GSM_GetGlobalDebug(), &SMSInfo, sms);
1399 if (error != ERR_NONE) goto end_compose;
1401 for (i=0;i<SMSInfo.EntriesNum;i++) {
1402 switch (SMSInfo.Entries[i].ID) {
1403 case SMS_NokiaRingtone:
1404 case SMS_NokiaRingtoneLong:
1405 case SMS_NokiaProfileLong:
1406 case SMS_EMSSound10:
1407 case SMS_EMSSound12:
1408 case SMS_EMSSonyEricssonSound:
1409 case SMS_EMSSound10Long:
1410 case SMS_EMSSound12Long:
1411 case SMS_EMSSonyEricssonSoundLong:
1412 if (SMSInfo.Entries[i].RingtoneNotes!=SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands) {
1413 printf_warn(_("Ringtone too long. %i percent part cut\n"),
1414 (SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands-SMSInfo.Entries[i].RingtoneNotes)*100/SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands);
1416 default:
1417 break;
1422 /* Check whether we did not reach user limit of messages */
1423 if (MaxSMS != -1 && sms->Number > MaxSMS) {
1424 printf_err(_("There are %i SMS messages packed and the limit is %i. Exiting\n"),sms->Number,MaxSMS);
1425 error = ERR_MOREMEMORY;
1426 goto end_compose;
1430 * Are we supposed to read SMSC from phone?
1432 if (SMSCSet != 0) {
1433 if (sm == NULL) {
1434 printf_err("%s\n", _("Use -smscnumber option to give SMSC number"));
1435 exit(-1);
1438 PhoneSMSC.Location = SMSCSet;
1439 error = GSM_GetSMSC(sm, &PhoneSMSC);
1440 if (error != ERR_NONE) goto end_compose;
1442 CopyUnicodeString(SMSC, PhoneSMSC.Number);
1443 SMSCSet = 0;
1447 * Fill up all messages with flags.
1449 for (i=0;i<sms->Number;i++) {
1450 CopyUnicodeString(sms->SMS[i].Number, RemoteNumber);
1451 CopyUnicodeString(sms->SMS[i].Name, Name);
1453 sms->SMS[i].Location = 0;
1454 sms->SMS[i].Folder = Folder;
1455 sms->SMS[i].State = State;
1457 sms->SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
1459 sms->SMS[i].SMSC.Location = SMSCSet;
1460 CopyUnicodeString(sms->SMS[i].SMSC.Number, SMSC);
1462 if (DeliveryReport) {
1463 sms->SMS[i].PDU = SMS_Status_Report;
1464 } else {
1465 sms->SMS[i].PDU = SMS_Submit;
1468 if (Validity.Format != 0) {
1469 sms->SMS[i].SMSC.Validity = Validity;
1473 error = ERR_NONE;
1474 end_compose:
1476 for (i = 0; i < GSM_MAX_MULTI_SMS; i++) {
1477 free(ringtone[i]);
1478 free(bitmap[i]);
1481 #ifdef GSM_ENABLE_BACKUP
1482 GSM_FreeBackup(&Backup);
1483 #endif
1484 return error;
1488 /* How should editor hadle tabs in this file? Add editor commands here.
1489 * vim: noexpandtab sw=8 ts=8 sts=8: