mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Use pointer to memos instead of accessing the array.
Adjust spaces. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23289 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9fa0f79c06
commit
3fa37e94d1
1 changed files with 108 additions and 129 deletions
|
@ -287,7 +287,6 @@ static int is_leap_year(int yr)
|
|||
static int calc_weekday( struct shown *shown )
|
||||
{
|
||||
return ( shown->wday + 36 - shown->mday ) % 7 ;
|
||||
|
||||
}
|
||||
|
||||
static void calendar_init(struct shown *shown)
|
||||
|
@ -299,15 +298,13 @@ static void calendar_init(struct shown *shown)
|
|||
rb->lcd_getstringsize("A", &w, &h);
|
||||
if ( ((w * 14) > LCD_WIDTH) || ((h * 7) > LCD_HEIGHT) )
|
||||
{
|
||||
rb->lcd_setfont(FONT_SYSFIXED);
|
||||
use_system_font = true;
|
||||
}
|
||||
rb->lcd_clear_display();
|
||||
#if CONFIG_RTC
|
||||
tm = rb->get_time();
|
||||
shown->mday = tm->tm_mday;
|
||||
shown->mon = tm->tm_mon + 1;
|
||||
shown->year = 2000+tm->tm_year%100;
|
||||
shown->year = 2000 + (tm->tm_year%100);
|
||||
shown->wday = tm->tm_wday - 1;
|
||||
#endif
|
||||
shown->firstday = calc_weekday(shown);
|
||||
|
@ -318,14 +315,14 @@ static void draw_headers(void)
|
|||
{
|
||||
int i, w, h;
|
||||
int x = X_OFFSET;
|
||||
const char **dayname = (const char**)&dayname_long;
|
||||
const char **dayname = dayname_long;
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
rb->lcd_getstringsize(dayname[i], &w, &h);
|
||||
if (w > CELL_WIDTH)
|
||||
{
|
||||
dayname = (const char**)&dayname_short;
|
||||
dayname = dayname_short;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -345,18 +342,18 @@ static void draw_calendar(struct shown *shown)
|
|||
{
|
||||
int w, h;
|
||||
int x, y, pos, days_per_month, j;
|
||||
char buffer[9];
|
||||
char buffer[12];
|
||||
const char *monthname[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
if(use_system_font)
|
||||
{
|
||||
rb->lcd_setfont(FONT_SYSFIXED);
|
||||
}
|
||||
rb->lcd_getstringsize("A", &w, &h);
|
||||
rb->lcd_clear_display();
|
||||
draw_headers();
|
||||
if (shown->firstday > 6)
|
||||
shown->firstday -= 7;
|
||||
pos = shown->firstday;
|
||||
days_per_month = days_in_month[leap_year][shown->mon];
|
||||
x = X_OFFSET + (pos * CELL_WIDTH);
|
||||
|
@ -388,12 +385,13 @@ static void draw_calendar(struct shown *shown)
|
|||
y += CELL_HEIGHT;
|
||||
}
|
||||
}
|
||||
shown->lastday = pos;
|
||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||
rb->lcd_vline(LCD_WIDTH-w*8-10, LCD_HEIGHT-h-3, LCD_HEIGHT-1);
|
||||
rb->lcd_hline(LCD_WIDTH-w*8-10, LCD_WIDTH-1, LCD_HEIGHT-h-3);
|
||||
rb->snprintf(buffer,9,"%s %04d",monthname[shown->mon-1],shown->year);
|
||||
rb->snprintf(buffer, sizeof(buffer), "%s %04d",
|
||||
monthname[shown->mon-1], shown->year);
|
||||
rb->lcd_putsxy(LCD_WIDTH-w*8-8, LCD_HEIGHT-h-1, buffer);
|
||||
shown->lastday = pos;
|
||||
rb->lcd_update();
|
||||
}
|
||||
|
||||
|
@ -435,54 +433,38 @@ static void load_memo(struct shown *shown)
|
|||
while (!exit)
|
||||
{
|
||||
bool load_to_memory;
|
||||
rb->memset(&memos[memos_in_memory].message, 0, MAX_CHAR_MEMO_LEN);
|
||||
memos[memos_in_memory].file_pointer_start =
|
||||
rb->lseek(fp, 0, SEEK_CUR);
|
||||
struct memo *memo = &memos[memos_in_memory];
|
||||
rb->memset(memo, 0, sizeof(*memo));
|
||||
memo->file_pointer_start = rb->lseek(fp, 0, SEEK_CUR);
|
||||
if (rb->read(fp, temp_memo2, 2) == 2)
|
||||
memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]);
|
||||
else
|
||||
memos[memos_in_memory].day = 0;
|
||||
memo->day = rb->atoi(temp_memo2);
|
||||
if (rb->read(fp, temp_memo2, 2) == 2)
|
||||
memos[memos_in_memory].month = rb->atoi(&temp_memo2[0]);
|
||||
else
|
||||
memos[memos_in_memory].month = 0;
|
||||
memo->month = rb->atoi(temp_memo2);
|
||||
if (rb->read(fp, temp_memo4, 4) == 4)
|
||||
memos[memos_in_memory].year = rb->atoi(&temp_memo4[0]);
|
||||
else
|
||||
memos[memos_in_memory].year = 0;
|
||||
/* as the year returned is sometimes yearmonth, ie if yr should =
|
||||
2003, and month = 06, then it returns 200306 */
|
||||
if (memos[memos_in_memory].year > (shown->year * 10))
|
||||
memos[memos_in_memory].year = (memos[memos_in_memory].year -
|
||||
memos[memos_in_memory].month) /
|
||||
100;
|
||||
memo->year = rb->atoi(temp_memo4);
|
||||
if (rb->read(fp, temp_memo1, 1) == 1)
|
||||
memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]);
|
||||
else
|
||||
memos[memos_in_memory].wday = 0;
|
||||
memo->wday = rb->atoi(temp_memo1);
|
||||
if (rb->read(fp, temp_memo1, 1) == 1)
|
||||
memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]);
|
||||
else
|
||||
memos[memos_in_memory].type = 0;
|
||||
load_to_memory = ((memos[memos_in_memory].type < 2) ||
|
||||
((memos[memos_in_memory].type == 2) &&
|
||||
(memos[memos_in_memory].month == shown->mon)) ||
|
||||
((memos[memos_in_memory].type > 2) &&
|
||||
(memos[memos_in_memory].month == shown->mon) &&
|
||||
(memos[memos_in_memory].year == shown->year)));
|
||||
memo->type = rb->atoi(temp_memo1);
|
||||
load_to_memory = ((memo->type < 2) ||
|
||||
((memo->type == 2) &&
|
||||
(memo->month == shown->mon)) ||
|
||||
((memo->type > 2) &&
|
||||
(memo->month == shown->mon) &&
|
||||
(memo->year == shown->year)));
|
||||
k = 0;
|
||||
while (1)
|
||||
{
|
||||
if (rb->read(fp, temp_memo1, 1) != 1)
|
||||
{
|
||||
memos[memos_in_memory].day = 0;
|
||||
memos[memos_in_memory].month = 0;
|
||||
memos[memos_in_memory].file_pointer_start = 0;
|
||||
memos[memos_in_memory].file_pointer_end = 0;
|
||||
memos[memos_in_memory].year = 0;
|
||||
memos[memos_in_memory].type = 0;
|
||||
memos[memos_in_memory].wday = 0;
|
||||
memos[memos_in_memory].message[0] = 0;
|
||||
memo->day = 0;
|
||||
memo->month = 0;
|
||||
memo->file_pointer_start = 0;
|
||||
memo->file_pointer_end = 0;
|
||||
memo->year = 0;
|
||||
memo->type = 0;
|
||||
memo->wday = 0;
|
||||
memo->message[0] = 0;
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
|
@ -490,19 +472,17 @@ static void load_memo(struct shown *shown)
|
|||
{
|
||||
if (temp_memo1[0] == '\n')
|
||||
{
|
||||
if (memos[memos_in_memory].type > 0)
|
||||
day_has_memo[memos[memos_in_memory].day] =
|
||||
true;
|
||||
if (memo->type > 0)
|
||||
day_has_memo[memo->day] = true;
|
||||
else
|
||||
wday_has_memo[memos[memos_in_memory].wday] =
|
||||
true;
|
||||
memos[memos_in_memory++].file_pointer_end =
|
||||
rb->lseek(fp, 0, SEEK_CUR);
|
||||
wday_has_memo[memo->wday] = true;
|
||||
memo->file_pointer_end = rb->lseek(fp, 0, SEEK_CUR);
|
||||
memos_in_memory++;
|
||||
}
|
||||
else if ( (temp_memo1[0] != '\r') &&
|
||||
(temp_memo1[0] != '\t') &&
|
||||
k < MAX_CHAR_MEMO_LEN-1 )
|
||||
memos[memos_in_memory].message[k++] = temp_memo1[0];
|
||||
memo->message[k++] = temp_memo1[0];
|
||||
}
|
||||
if (temp_memo1[0] == '\n')
|
||||
break;
|
||||
|
@ -522,8 +502,9 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown)
|
|||
{
|
||||
int i;
|
||||
char temp[MAX_CHAR_MEMO_LEN];
|
||||
struct memo *memo = &memos[changed];
|
||||
rb->lseek(fp, 0, SEEK_SET);
|
||||
for (i = 0; i < memos[changed].file_pointer_start; i++)
|
||||
for (i = 0; i < memo->file_pointer_start; i++)
|
||||
{
|
||||
rb->read(fp, temp, 1);
|
||||
rb->write(fq, temp, 1);
|
||||
|
@ -531,14 +512,10 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown)
|
|||
if (new_mod)
|
||||
{
|
||||
rb->fdprintf(fq, "%02d%02d%04d%01d%01d%s\n",
|
||||
memos[changed].day,
|
||||
memos[changed].month,
|
||||
memos[changed].year,
|
||||
memos[changed].wday,
|
||||
memos[changed].type,
|
||||
memos[changed].message);
|
||||
memo->day, memo->month, memo->year, memo->wday,
|
||||
memo->type, memo->message);
|
||||
}
|
||||
rb->lseek(fp, memos[changed].file_pointer_end, SEEK_SET);
|
||||
rb->lseek(fp, memo->file_pointer_end, SEEK_SET);
|
||||
while(rb->read(fp, temp, 1) == 1)
|
||||
{
|
||||
rb->write(fq, temp, 1);
|
||||
|
@ -560,37 +537,35 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown)
|
|||
static void add_memo(struct shown *shown, int type)
|
||||
{
|
||||
bool saved = false;
|
||||
if (rb->kbd_input(memos[memos_in_memory].message,
|
||||
sizeof memos[memos_in_memory].message) == 0)
|
||||
struct memo *memo = &memos[memos_in_memory];
|
||||
if (rb->kbd_input(memo->message, MAX_CHAR_MEMO_LEN) == 0)
|
||||
{
|
||||
if (rb->strlen(memos[memos_in_memory].message))
|
||||
if (memo->message[0])
|
||||
{
|
||||
memos[memos_in_memory].file_pointer_start = 0;
|
||||
memos[memos_in_memory].file_pointer_end = 0;
|
||||
memos[memos_in_memory].day = shown->mday;
|
||||
memos[memos_in_memory].month = shown->mon;
|
||||
memos[memos_in_memory].wday = shown->wday;
|
||||
memos[memos_in_memory].year = shown->year;
|
||||
memos[memos_in_memory].type = type;
|
||||
memo->file_pointer_start = 0;
|
||||
memo->file_pointer_end = 0;
|
||||
memo->day = shown->mday;
|
||||
memo->month = shown->mon;
|
||||
memo->wday = shown->wday;
|
||||
memo->year = shown->year;
|
||||
memo->type = type;
|
||||
if (save_memo(memos_in_memory, true, shown))
|
||||
{
|
||||
saved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
memos[memos_in_memory].file_pointer_start = 0;
|
||||
memos[memos_in_memory].file_pointer_end = 0;
|
||||
memos[memos_in_memory].day = 0;
|
||||
memos[memos_in_memory].month = 0;
|
||||
memos[memos_in_memory].year = 0;
|
||||
memos[memos_in_memory].type = 0;
|
||||
memos[memos_in_memory].wday = 0;
|
||||
memo->file_pointer_start = 0;
|
||||
memo->file_pointer_end = 0;
|
||||
memo->day = 0;
|
||||
memo->month = 0;
|
||||
memo->year = 0;
|
||||
memo->type = 0;
|
||||
memo->wday = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
rb->lcd_clear_display();
|
||||
if(use_system_font)
|
||||
rb->lcd_setfont(FONT_SYSFIXED);
|
||||
if (saved)
|
||||
rb->splash(HZ/2, "Event added");
|
||||
else
|
||||
|
@ -622,13 +597,13 @@ static bool edit_memo(int change, struct shown *shown)
|
|||
switch (rb->do_menu(&edit_menu, &selected, NULL, false))
|
||||
{
|
||||
case 0: /* remove */
|
||||
save_memo(pointer_array[change],false,shown);
|
||||
save_memo(change, false, shown);
|
||||
return false;
|
||||
|
||||
case 1: /* edit */
|
||||
if(rb->kbd_input(memos[pointer_array[change]].message,
|
||||
sizeof memos[pointer_array[change]].message) == 0)
|
||||
save_memo(pointer_array[change],true,shown);
|
||||
if(rb->kbd_input(memos[change].message,
|
||||
MAX_CHAR_MEMO_LEN) == 0)
|
||||
save_memo(change, true, shown);
|
||||
return false;
|
||||
|
||||
case 2: /* weekly */
|
||||
|
@ -666,17 +641,17 @@ static const char* get_event_text(int selected, void *data,
|
|||
char *buffer, size_t buffer_len)
|
||||
{
|
||||
struct shown *shown = (struct shown *) data;
|
||||
struct memo *memo;
|
||||
if (selected < 0 || memos_in_shown_memory <= selected)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (memos[pointer_array[selected]].type == 2)
|
||||
memo = &memos[pointer_array[selected]];
|
||||
if (memo->type == 2)
|
||||
rb->snprintf(buffer, buffer_len, "%s (%d yrs)",
|
||||
memos[pointer_array[selected]].message,
|
||||
shown->year - memos[pointer_array[selected]].year);
|
||||
memo->message, shown->year - memo->year);
|
||||
else
|
||||
rb->snprintf(buffer, buffer_len, "%s",
|
||||
memos[pointer_array[selected]].message);
|
||||
rb->snprintf(buffer, buffer_len, "%s", memo->message);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -701,7 +676,7 @@ static bool view_events(int selected, struct shown *shown)
|
|||
{
|
||||
case ACTION_STD_OK:
|
||||
selected = rb->gui_synclist_get_sel_pos(&gui_memos);
|
||||
return edit_memo(selected, shown);
|
||||
return edit_memo(pointer_array[selected], shown);
|
||||
break;
|
||||
|
||||
case ACTION_STD_CANCEL:
|
||||
|
@ -721,14 +696,16 @@ static bool view_events(int selected, struct shown *shown)
|
|||
static void update_memos_shown(struct shown *shown)
|
||||
{
|
||||
int i;
|
||||
struct memo *memo;
|
||||
memos_in_shown_memory = 0;
|
||||
for (i = 0; i < memos_in_memory; i++)
|
||||
if (((memos[i].type >= 1) &&
|
||||
(memos[i].day == shown->mday)) ||
|
||||
((memos[i].type < 1) &&
|
||||
(memos[i].wday == shown->wday)))
|
||||
{
|
||||
memo = &memos[i];
|
||||
if (((memo->type >= 1) && (memo->day == shown->mday)) ||
|
||||
((memo->type < 1) && (memo->wday == shown->wday)))
|
||||
pointer_array[memos_in_shown_memory++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
static bool any_events(struct shown *shown, bool force)
|
||||
{
|
||||
|
@ -776,6 +753,8 @@ static void prev_month(struct shown *shown, int step)
|
|||
else if (shown->mday > days_in_month[leap_year][shown->mon])
|
||||
shown->mday = days_in_month[leap_year][shown->mon];
|
||||
shown->firstday += 7 - (days_in_month[leap_year][shown->mon] % 7);
|
||||
if (shown->firstday >= 7)
|
||||
shown->firstday -= 7;
|
||||
load_memo(shown);
|
||||
draw_calendar(shown);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue