"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "prefs.c" between
jpilot-1.8.2.tar.gz and jpilot-2_0_1.tar.gz

About: J-Pilot is a desktop organizer application for Palm Pilot (PalmOS) devices. Ported to GTK3.

prefs.c  (jpilot-1.8.2):prefs.c  (jpilot-2_0_1)
skipping to change at line 23 skipping to change at line 23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/ ******************************************************************************/
/********************************* Includes ***********************************/ /********************************* Includes ***********************************/
#include "config.h" #include "config.h"
#include "utils.h"
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
# include <langinfo.h> # include <langinfo.h>
#endif #endif
#include "i18n.h" #include "i18n.h"
skipping to change at line 52 skipping to change at line 53
#define NUM_TIMES_NO_AMPM 6 #define NUM_TIMES_NO_AMPM 6
#define NUM_RATES 11 #define NUM_RATES 11
#define NUM_PAPER_SIZES 2 #define NUM_PAPER_SIZES 2
/******************************* Global vars **********************************/ /******************************* Global vars **********************************/
static int t_fmt_ampm = TRUE; static int t_fmt_ampm = TRUE;
/* These are the default settings */ /* These are the default settings */
/* name, usertype, filetype, ivalue, char *svalue, svalue_size; */ /* name, usertype, filetype, ivalue, char *svalue, svalue_size; */
static prefType glob_prefs[NUM_PREFS] = { static prefType glob_prefs[NUM_PREFS] = {
{"jpilotrc", CHARTYPE, CHARTYPE, 0, NULL, 0}, {"jpilotcss", CHARTYPE, CHARTYPE, 0, "jpilotcss.default", 16},
{"time", CHARTYPE, INTTYPE, 0, NULL, 0}, {"time", CHARTYPE, INTTYPE, 0, NULL, 0},
{"sdate", CHARTYPE, INTTYPE, 0, NULL, 0}, {"sdate", CHARTYPE, INTTYPE, 0, NULL, 0},
{"ldate", CHARTYPE, INTTYPE, 0, NULL, 0}, {"ldate", CHARTYPE, INTTYPE, 0, NULL, 0},
{"xxx_internal1_xxx", CHARTYPE, INTTYPE, 0, NULL, 0}, {"xxx_internal1_xxx", CHARTYPE, INTTYPE, 0, NULL, 0},
{"show_deleted", INTTYPE, INTTYPE, 0, NULL, 0}, {"show_deleted", INTTYPE, INTTYPE, 0, NULL, 0},
{"show_modified", INTTYPE, INTTYPE, 0, NULL, 0}, {"show_modified", INTTYPE, INTTYPE, 0, NULL, 0},
{"todo_hide_completed", INTTYPE, INTTYPE, 0, NULL, 0}, {"todo_hide_completed", INTTYPE, INTTYPE, 0, NULL, 0},
{"datebook_highlight_days", INTTYPE, INTTYPE, 1, NULL, 0}, {"datebook_highlight_days", INTTYPE, INTTYPE, 1, NULL, 0},
{"port", CHARTYPE, CHARTYPE, 0, NULL, 0}, {"port", CHARTYPE, CHARTYPE, 0, NULL, 0},
{"rate", CHARTYPE, INTTYPE, 8, NULL, 0}, {"rate", CHARTYPE, INTTYPE, 8, NULL, 0},
skipping to change at line 155 skipping to change at line 156
{"todo_sort_order", INTTYPE, INTTYPE, 0, NULL, 0}, {"todo_sort_order", INTTYPE, INTTYPE, 0, NULL, 0},
{"addr_sort_order", INTTYPE, INTTYPE, 0, NULL, 0}, {"addr_sort_order", INTTYPE, INTTYPE, 0, NULL, 0},
{"addr_name_col_sz", INTTYPE, INTTYPE, 140, NULL, 0}, {"addr_name_col_sz", INTTYPE, INTTYPE, 140, NULL, 0},
{"todo_note_pane", INTTYPE, INTTYPE, 200, NULL, 0}, {"todo_note_pane", INTTYPE, INTTYPE, 200, NULL, 0},
{"expense_sort_column", INTTYPE, INTTYPE, 0, NULL, 0}, {"expense_sort_column", INTTYPE, INTTYPE, 0, NULL, 0},
{"expense_sort_order", INTTYPE, INTTYPE, 0, NULL, 0}, {"expense_sort_order", INTTYPE, INTTYPE, 0, NULL, 0},
{"keyr_export_filename", CHARTYPE, CHARTYPE, 0, NULL, 0}, {"keyr_export_filename", CHARTYPE, CHARTYPE, 0, NULL, 0},
{"external_editor", CHARTYPE, CHARTYPE, 0, NULL, 0}, {"external_editor", CHARTYPE, CHARTYPE, 0, NULL, 0},
}; };
struct name_list { char *get_new_css_name(char *field2);
char *name;
struct name_list *next;
};
static struct name_list *dir_list=NULL; gboolean using_old_rc_name_in_pref_file(const char *field1);
/****************************** Main Code *************************************/ /****************************** Main Code *************************************/
void pref_init(void) void pref_init(void)
{ {
int i; int i;
/* Determine whether locale supports am/pm time formats */ /* Determine whether locale supports am/pm time formats */
# ifdef HAVE_LANGINFO_H # ifdef HAVE_LANGINFO_H
t_fmt_ampm = strcmp(nl_langinfo(T_FMT_AMPM), ""); t_fmt_ampm = strcmp(nl_langinfo(T_FMT_AMPM), "");
# endif # endif
for (i=0; i<NUM_PREFS; i++) { for (i=0; i<NUM_PREFS; i++) {
switch (i) { switch (i) {
case PREF_PORT: case PREF_PORT:
glob_prefs[i].svalue=strdup("usb:"); glob_prefs[i].svalue=strdup("usb:");
glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1; glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1;
break; break;
case PREF_RCFILE: case PREF_RCFILE:
glob_prefs[i].svalue=strdup(EPN"rc.default"); glob_prefs[i].svalue=strdup(EPN"css.default");
glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1; glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1;
break; break;
case PREF_PRINT_COMMAND: case PREF_PRINT_COMMAND:
glob_prefs[i].svalue=strdup("lpr -h"); glob_prefs[i].svalue=strdup("lpr -h");
glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1; glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1;
break; break;
case PREF_ALARM_COMMAND: case PREF_ALARM_COMMAND:
glob_prefs[i].svalue=strdup("echo %t %d"); glob_prefs[i].svalue=strdup("echo %t %d");
glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1; glob_prefs[i].svalue_size=strlen(glob_prefs[i].svalue)+1;
break; break;
skipping to change at line 323 skipping to change at line 321
next_list=temp_list->next; next_list=temp_list->next;
if (temp_list->name) { if (temp_list->name) {
free(temp_list->name); free(temp_list->name);
} }
free(temp_list); free(temp_list);
} }
*Plist=NULL; *Plist=NULL;
} }
*/ */
static int get_rcfile_name(int n, char *rc_copy)
{
DIR *dir;
struct dirent *dirent;
char full_name[FILENAME_MAX];
int i;
char filename[FILENAME_MAX];
int found, count;
struct name_list *temp_list, *new_entry;
if (dir_list == NULL) {
i = found = count = 0;
sprintf(filename, "%s/%s/%s/", BASE_DIR, "share", EPN);
jp_logf(JP_LOG_DEBUG, "opening dir %s\n", filename);
dir = opendir(filename);
if (dir) {
for(i=0; (dirent = readdir(dir)); i++) {
sprintf(filename, "%s%s", EPN, "rc");
if (strncmp(filename, dirent->d_name, strlen(filename))) {
continue;
} else {
jp_logf(JP_LOG_DEBUG, "found %s\n", dirent->d_name);
new_entry = malloc(sizeof(struct name_list));
if (!new_entry) {
jp_logf(JP_LOG_FATAL, "get_rcfile_name(): %s\n", _("Out of mem
ory"));
return EXIT_FAILURE;
}
new_entry->name = strdup(dirent->d_name);
new_entry->next = dir_list;
dir_list = new_entry;
}
}
}
if (dir) {
closedir(dir);
}
get_home_file_name("", full_name, sizeof(full_name));
jp_logf(JP_LOG_DEBUG, "opening dir %s\n", full_name);
dir = opendir(full_name);
if (dir) {
for(; (dirent = readdir(dir)); i++) {
sprintf(filename, "%s%s", EPN, "rc");
if (strncmp(filename, dirent->d_name, strlen(filename))) {
continue;
} else {
jp_logf(JP_LOG_DEBUG, "found %s\n", dirent->d_name);
new_entry = malloc(sizeof(struct name_list));
if (!new_entry) {
jp_logf(JP_LOG_FATAL, "get_rcfile_name(): %s 2\n", _("Out of m
emory"));
return EXIT_FAILURE;
}
new_entry->name = strdup(dirent->d_name);
new_entry->next = dir_list;
dir_list = new_entry;
}
}
}
if (dir) {
closedir(dir);
}
}
found = 0;
for (i=0, temp_list=dir_list; temp_list; temp_list=temp_list->next, i++) {
if (i == n) {
g_strlcpy(rc_copy, temp_list->name, MAX_PREF_LEN);
found=1;
break;
}
}
if (found) {
return EXIT_SUCCESS;
} else {
rc_copy[0]='\0';
return EXIT_FAILURE;
}
}
/* if n is out of range then this function will fail */ /* if n is out of range then this function will fail */
int get_pref_possibility(int which, int n, char *pref_str) int get_pref_possibility(int which, int n, char *pref_str)
{ {
const char *short_date_formats[] = { const char *short_date_formats[] = {
"%m/%d/%y", "%m/%d/%y",
"%d/%m/%y", "%d/%m/%y",
"%d.%m.%y", "%d.%m.%y",
"%d-%m-%y", "%d-%m-%y",
"%y/%m/%d", "%y/%m/%d",
"%y.%m.%d", "%y.%m.%d",
skipping to change at line 716 skipping to change at line 634
if (which >= NUM_PREFS) { if (which >= NUM_PREFS) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (glob_prefs[which].usertype == CHARTYPE) { if (glob_prefs[which].usertype == CHARTYPE) {
get_pref_possibility(which, n, svalue); get_pref_possibility(which, n, svalue);
str=svalue; str=svalue;
} }
r = jp_set_pref(glob_prefs, which, n, str); r = jp_set_pref(glob_prefs, which, n, str);
if (save) { if (save) {
pref_write_rc_file(); pref_write_rc_file();
} }
if (PREF_CHAR_SET == which) if (PREF_CHAR_SET == which)
if (otherconv_init()) if (otherconv_init())
printf("Error: could not set charset encoding\n"); printf("Error: could not set charset encoding\n");
return r; return r;
} }
static int validate_glob_prefs(void) static int validate_glob_prefs(void)
skipping to change at line 896 skipping to change at line 815
line[sizeof(line)-1] = '\0'; line[sizeof(line)-1] = '\0';
field1 = strtok(line, " "); field1 = strtok(line, " ");
field2 = (field1 != NULL) ? strtok(NULL, "\n") : NULL; field2 = (field1 != NULL) ? strtok(NULL, "\n") : NULL;
if ((field1 == NULL) || (field2 == NULL)) { if ((field1 == NULL) || (field2 == NULL)) {
continue; continue;
} }
if ((Pc = (char *)index(field2, '\n'))) { if ((Pc = (char *)index(field2, '\n'))) {
Pc[0]='\0'; Pc[0]='\0';
} }
for(i=0; i<num_prefs; i++) { for(i=0; i<num_prefs; i++) {
//attempt to convert to new css file if
// pref file has old rc name in it.
if(using_old_rc_name_in_pref_file(field1)){
field1 = "jpilotcss";
field2 = get_new_css_name(field2);
}
if (!strcmp(prefs[i].name, field1)) { if (!strcmp(prefs[i].name, field1)) {
if (prefs[i].filetype == INTTYPE) { if (prefs[i].filetype == INTTYPE) {
prefs[i].ivalue = atoi(field2); prefs[i].ivalue = atoi(field2);
} }
if (prefs[i].filetype == CHARTYPE) { if (prefs[i].filetype == CHARTYPE) {
if (pref_lstrncpy_realloc(&(prefs[i].svalue), field2, if (pref_lstrncpy_realloc(&(prefs[i].svalue), field2,
&(prefs[i].svalue_size), &(prefs[i].svalue_size),
MAX_PREF_LEN)==NULL) { MAX_PREF_LEN)==NULL) {
jp_logf(JP_LOG_WARN, "read_rc_file(): %s\n", _("Out of memory" )); jp_logf(JP_LOG_WARN, "read_rc_file(): %s\n", _("Out of memory" ));
continue; continue;
} }
} }
} }
} }
} }
fclose(in); fclose(in);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
gboolean using_old_rc_name_in_pref_file(const char *field1) {
return (gboolean) (field1 != NULL && strcmp("jpilotrc", field1) == 0);
}
char *get_new_css_name(char *field2) {
if(field2 != NULL){
if(strcmp(field2, "jpilotrc.green") == 0){
field2 = "jpilotcss.green";
}else if(strcmp(field2,"jpilotrc.blue") == 0){
field2 = "jpilotcss.blue";
}else if(strcmp(field2,"jpilotrc.purple") == 0){
field2 = "jpilotcss.purple";
}else if(strcmp(field2,"jpilotrc.steel") == 0){
field2 = "jpilotcss.steel";
}else {
// not using one of the old default rc files,
// so revert to default.
field2 = "jpilotcss.default";
}
}
return field2;
}
int pref_read_rc_file(void) int pref_read_rc_file(void)
{ {
int r; int r;
r = jp_pref_read_rc_file(EPN".rc", glob_prefs, NUM_PREFS); r = jp_pref_read_rc_file(EPN".rc", glob_prefs, NUM_PREFS);
validate_glob_prefs(); validate_glob_prefs();
return r; return r;
} }
 End of changes. 9 change blocks. 
89 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)