7 #include "../helper/locales.h"
12 #include "../helper/formats.h"
13 #include "../helper/memory-display.h"
14 #include "../helper/printing.h"
15 #include "../helper/string.h"
16 #include "../helper/cmdline.h"
18 void GetAllMemory(int argc UNUSED
, char *argv
[])
21 GSM_MemoryType MemoryType
;
23 signal(SIGINT
, interrupt
);
24 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
26 MemoryType
= GSM_StringToMemoryType(argv
[2]);
28 if (MemoryType
== 0) {
29 printf_err(_("Unknown memory type (\"%s\")\n"),argv
[2]);
35 #ifdef GSM_ENABLE_BACKUP
36 error
= ReadPhonebook(NULL
, MemoryType
, NULL
, 0, PrintMemoryEntryLocation
, FALSE
);
42 if (ringtones_info
.Ringtone
) {
43 free(ringtones_info
.Ringtone
);
49 void GetMemory(int argc
, char *argv
[])
51 int j
, start
, stop
, emptynum
= 0, fillednum
= 0;
52 GSM_MemoryEntry entry
;
53 gboolean empty
= TRUE
;
57 entry
.MemoryType
= GSM_StringToMemoryType(argv
[2]);
59 if (entry
.MemoryType
==0) {
60 printf_err(_("Unknown memory type (\"%s\")\n"),argv
[2]);
64 GetStartStop(&start
, &stop
, 3, argc
, argv
);
66 if (argc
> 5 && strcmp(argv
[5],"")) {
67 if (strcasecmp(argv
[5],"-nonempty") == 0) {
70 printf_err(_("Unknown parameter (\"%s\")\n"),argv
[5]);
77 if (strcmp(GSM_GetModelInfo(gsm
)->model
, "3310") == 0) {
78 error
= GSM_GetFirmware(gsm
, NULL
, NULL
, &version
);
79 if (error
== ERR_NONE
&& version
<= 4.06) {
80 printf_warn("%s\n", _("You will have null names in entries. Upgrade firmware in phone to higher than 4.06"));
83 if (strcmp(GSM_GetModelInfo(gsm
)->model
, "3210") == 0) {
84 error
= GSM_GetFirmware(gsm
, NULL
, NULL
, &version
);
85 if (error
== ERR_NONE
&& version
<= 6.00) {
86 printf_warn("%s\n", _("You will have null names in entries. Upgrade firmware in phone to higher than 6.00"));
90 for (j
=start
;j
<=stop
;j
++) {
91 if (empty
) printf(_("Memory %s, Location %i\n"),argv
[2],j
);
95 error
=GSM_GetMemory(gsm
, &entry
);
96 if (error
!= ERR_EMPTY
) {
97 if (ringtones_info
.Ringtone
) free(ringtones_info
.Ringtone
);
101 if (error
== ERR_EMPTY
) {
104 printf("%s\n", _("Entry is empty"));
109 if (!empty
) printf(_("Memory %s, Location %i\n"),argv
[2],j
);
110 error
= PrintMemoryEntry(&entry
, gsm
);
111 GSM_FreeMemoryEntry(&entry
);
116 printf(_("%i entries empty, %i entries filled\n"),emptynum
,fillednum
);
118 if (ringtones_info
.Ringtone
) free(ringtones_info
.Ringtone
);
123 void DeleteMemory(int argc
, char *argv
[])
126 GSM_MemoryEntry entry
;
129 entry
.MemoryType
= GSM_StringToMemoryType(argv
[2]);
131 if (entry
.MemoryType
==0) {
132 printf_err(_("Unknown memory type (\"%s\")\n"),argv
[2]);
136 GetStartStop(&start
, &stop
, 3, argc
, argv
);
140 for (j
=start
;j
<=stop
;j
++) {
141 printf(LISTFORMAT
"%i\n", _("Location"), j
);
145 error
= GSM_DeleteMemory(gsm
, &entry
);
147 if (error
!= ERR_EMPTY
) Print_Error(error
);
149 if (error
== ERR_EMPTY
) {
150 printf("%s\n", _("Entry was empty"));
152 printf("%s\n", _("Entry was deleted"));
160 void DeleteAllMemory(int argc
, char *argv
[])
162 GSM_MemoryType MemoryType
;
165 MemoryType
= GSM_StringToMemoryType(argv
[2]);
167 if (MemoryType
== 0) {
168 printf_err(_("Unknown memory type (\"%s\")\n"),argv
[2]);
174 error
= GSM_DeleteAllMemory(gsm
, MemoryType
);
176 if (error
!= ERR_NONE
) Print_Error(error
);
182 * Searches if memory entry contains given text.
184 * It prints it in match.
186 void SearchOneEntry(GSM_MemoryEntry
*Entry
, const unsigned char *Text
)
191 for (i
=0;i
<Entry
->EntriesNum
;i
++) {
192 switch (Entry
->Entries
[i
].EntryType
) {
193 case PBK_Number_General
:
194 case PBK_Number_Mobile
:
195 case PBK_Number_Fax
:
196 case PBK_Number_Pager
:
197 case PBK_Number_Other
:
198 case PBK_Number_Messaging
:
199 case PBK_Number_Video
:
201 case PBK_Text_Postal
:
202 case PBK_Text_Email
:
203 case PBK_Text_Email2
:
212 case PBK_Text_LastName
:
213 case PBK_Text_FirstName
:
214 case PBK_Text_SecondName
:
215 case PBK_Text_FormalName
:
216 case PBK_Text_NamePrefix
:
217 case PBK_Text_NameSuffix
:
218 case PBK_Text_NickName
:
219 case PBK_Text_Company
:
220 case PBK_Text_JobTitle
:
221 case PBK_Text_StreetAddress
:
223 case PBK_Text_State
:
225 case PBK_Text_Country
:
226 case PBK_Text_Custom1
:
227 case PBK_Text_Custom2
:
228 case PBK_Text_Custom3
:
229 case PBK_Text_Custom4
:
230 case PBK_Text_UserID
:
231 case PBK_Text_PictureName
:
232 case PBK_PushToTalkID
:
233 if (mywstrstr(Entry
->Entries
[i
].Text
, Text
) != NULL
) {
234 fprintf(stderr
,"\n");
235 printf(_("Memory %s, Location %i\n"),GSM_MemoryTypeToString(Entry
->MemoryType
),Entry
->Location
);
236 error
= PrintMemoryEntry(Entry
, gsm
);
241 case PBK_Caller_Group
:
248 case PBK_LastModified
:
259 * Reads all entries from one memory and searches them for some text.
261 * All matched entries are printed.
263 void SearchOneMemory(GSM_MemoryType MemoryType
, const char *Title
, const unsigned char *Text
)
265 GSM_MemoryEntry Entry
;
266 GSM_MemoryStatus Status
;
270 Status
.MemoryType
= MemoryType
;
271 Entry
.MemoryType
= MemoryType
;
274 if (GSM_GetMemoryStatus(gsm
, &Status
) == ERR_NONE
) {
275 fprintf(stderr
,"%c%s: %i%%", 13, Title
, (i
+1)*100/(Status
.MemoryUsed
+1));
276 error
= GSM_GetNextMemory(gsm
, &Entry
, TRUE
);
277 if (error
!= ERR_NOTSUPPORTED
&& error
!= ERR_NOTIMPLEMENTED
) {
278 while (i
< Status
.MemoryUsed
) {
279 if (error
== ERR_EMPTY
) break;
281 SearchOneEntry(&Entry
, Text
);
282 GSM_FreeMemoryEntry(&Entry
);
283 if (gshutdown
) return;
285 fprintf(stderr
,"\r%s: %i%%", Title
, (i
+1)*100/(Status
.MemoryUsed
+1));
286 error
= GSM_GetNextMemory(gsm
, &Entry
, FALSE
);
289 while (i
< Status
.MemoryUsed
) {
291 error
= GSM_GetMemory(gsm
, &Entry
);
292 if (error
!= ERR_EMPTY
) {
295 SearchOneEntry(&Entry
, Text
);
296 GSM_FreeMemoryEntry(&Entry
);
298 fprintf(stderr
,"%c%s: %i%%", 13, Title
, (i
+1)*100/(Status
.MemoryUsed
+1));
302 fprintf(stderr
,"\n");
306 void SearchMemory(int argc UNUSED
, char *argv
[])
308 unsigned char Text
[(GSM_PHONEBOOK_TEXT_LENGTH
+1)*2];
311 signal(SIGINT
, interrupt
);
312 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
314 Length
= strlen(argv
[2]);
315 if (Length
> GSM_PHONEBOOK_TEXT_LENGTH
) {
316 printf(_("Search text too long, truncating to %d chars!\n"), GSM_PHONEBOOK_TEXT_LENGTH
);
317 Length
= GSM_PHONEBOOK_TEXT_LENGTH
;
319 EncodeUnicode(Text
, argv
[2], Length
);
323 if (!gshutdown
) SearchOneMemory(MEM_ME
, "Phone phonebook", Text
);
324 if (!gshutdown
) SearchOneMemory(MEM_SM
, "SIM phonebook", Text
);
325 if (!gshutdown
) SearchOneMemory(MEM_ON
, "Own numbers", Text
);
326 if (!gshutdown
) SearchOneMemory(MEM_DC
, "Dialled numbers", Text
);
327 if (!gshutdown
) SearchOneMemory(MEM_RC
, "Received numbers", Text
);
328 if (!gshutdown
) SearchOneMemory(MEM_MC
, "Missed numbers", Text
);
329 if (!gshutdown
) SearchOneMemory(MEM_FD
, "Fix dialling", Text
);
330 if (!gshutdown
) SearchOneMemory(MEM_VM
, "Voice mailbox", Text
);
331 if (!gshutdown
) SearchOneMemory(MEM_SL
, "Sent SMS log", Text
);
336 void ListMemoryCategoryEntries(int Category
)
338 GSM_MemoryEntry Entry
;
339 gboolean start
= TRUE
;
343 /* Category can be only for ME stored entries */
344 Entry
.MemoryType
= MEM_ME
;
347 error
= GSM_GetNextMemory(gsm
, &Entry
, start
);
348 if (error
== ERR_EMPTY
) break;
350 for (j
=0;j
<Entry
.EntriesNum
;j
++) {
351 if (Entry
.Entries
[j
].EntryType
== PBK_Category
&& Entry
.Entries
[j
].Number
== Category
) {
352 printf(_("Memory %s, Location %i\n"),GSM_MemoryTypeToString(Entry
.MemoryType
),Entry
.Location
);
353 error
= PrintMemoryEntry(&Entry
, gsm
);
357 GSM_FreeMemoryEntry(&Entry
);
362 void ListMemoryCategory(int argc UNUSED
, char *argv
[])
364 GSM_Category Category
;
365 GSM_CategoryStatus Status
;
369 unsigned char Text
[(GSM_MAX_CATEGORY_NAME_LENGTH
+1)*2];
371 gboolean Number
= TRUE
;;
375 signal(SIGINT
, interrupt
);
376 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
378 Length
= strlen(argv
[2]);
379 for (j
= 0; j
< Length
; j
++) {
380 if (!isdigit((int)argv
[2][j
])) {
389 ListMemoryCategoryEntries(j
);
392 if (Length
> GSM_MAX_CATEGORY_NAME_LENGTH
) {
393 printf(_("Search text too long, truncating to %d chars!\n"), GSM_MAX_CATEGORY_NAME_LENGTH
);
394 Length
= GSM_MAX_CATEGORY_NAME_LENGTH
;
396 EncodeUnicode(Text
, argv
[2], Length
);
398 Category
.Type
= Category_Phonebook
;
399 Status
.Type
= Category_Phonebook
;
401 if (GSM_GetCategoryStatus(gsm
, &Status
) == ERR_NONE
) {
402 for (count
=0,j
=1;count
<Status
.Used
;j
++) {
404 error
=GSM_GetCategory(gsm
, &Category
);
406 if (error
!= ERR_EMPTY
) {
408 if (mywstrstr(Category
.Name
, Text
) != NULL
) {
409 ListMemoryCategoryEntries(j
);
418 /* How should editor hadle tabs in this file? Add editor commands here.
419 * vim: noexpandtab sw=8 ts=8 sts=8: