Sophie

Sophie

distrib > Mageia > 3 > x86_64 > media > core-release-src > by-pkgid > 17f95da751a01c3eef3610c51e3de98d > files > 1

jpilot-1.8.1-3.mga3.src.rpm

--- jpilot-0.99.1u/plugins.c.chmou	Fri Jan  4 03:43:26 2002
+++ jpilot-0.99.1u/plugins.c	Tue Jan 15 15:48:42 2002
@@ -429,4 +429,113 @@
    }
    *sr = NULL;
 }
+
+/* Jason Day contributed code - Start */
+/*
+ * WARNING
+ * Caller must ensure that which is not out of range!
+ */
+int jp_set_pref_int (prefType prefs[], int which, long n)
+{
+    if (which < 0) {
+        return -1;
+    }
+    prefs[which].ivalue = n;
+    /*
+    if (prefs[which]->usertype == CHARTYPE) {
+        get_pref_possibility(which, glob_prefs[which].ivalue, glob_prefs[which].svalue);
+    }
+    */
+    return 0;
+}
+
+/*
+ * WARNING
+ * Caller must ensure that which is not out of range!
+ */
+int jp_set_pref_char (prefType prefs[], int which, char *string)
+{
+    if (which < 0) {
+        return -1;
+    }
+    if (string == NULL) {
+        prefs[which].svalue[0] = '\0';
+        return 0;
+    }
+    if (prefs[which].filetype == CHARTYPE) {
+        strncpy (prefs[which].svalue, string, MAX_PREF_VALUE);
+        prefs[which].svalue[MAX_PREF_VALUE - 1] = '\0';
+    }
+    return 0;
+}
+
+
+int jp_read_rc_file (char *filename, prefType prefs[], int num_prefs)
+{
+    int i;
+    FILE *in;
+    char line[256];
+    char *field1, *field2;
+    char *pc;
+
+    in = jp_open_home_file (filename, "r");
+    if (!in) {
+        return -1;
+    }
+
+    while (!feof (in)) {
+        fgets (line, 255, in);
+        line[254] = ' ';
+        line[255] = '\0';
+        field1 = strtok (line, " ");
+        field2 = (field1 != NULL) ? strtok (NULL, "\n") : NULL;/* jonh */
+        if ((field1 == NULL) || (field2 == NULL)) {
+            continue;
+        }
+        if ((pc = (char *)index (field2, '\n'))) {
+            pc[0] = '\0';
+        }
+        for (i = 0; i < num_prefs; i++) {
+            if (!strcmp (prefs[i].name, field1)) {
+                if (prefs[i].filetype == INTTYPE) {
+                    prefs[i].ivalue = atoi (field2);
+                }
+                if (prefs[i].filetype == CHARTYPE) {
+                    strncpy (prefs[i].svalue, field2, MAX_PREF_VALUE);
+                    prefs[i].svalue[MAX_PREF_VALUE - 1] = '\0';
+                }
+            }
+        }
+    }
+    fclose (in);
+
+    return 0;
+}
+
+int jp_write_rc_file (char *filename, prefType prefs[], int num_prefs)
+{
+    int i;
+    FILE *out;
+
+    out = jp_open_home_file (filename, "w" );
+    if (!out) {
+        return -1;
+    }
+
+    for (i = 0; i < num_prefs; i++) {
+
+        if (prefs[i].filetype == INTTYPE) {
+            fprintf (out, "%s %ld\n", prefs[i].name, prefs[i].ivalue);
+        }
+
+        if (prefs[i].filetype == CHARTYPE) {
+            fprintf (out, "%s %s\n", prefs[i].name, prefs[i].svalue);
+        }
+    }
+    fclose (out);
+
+    return 0;
+}
+/* Jason Day contributed code - End */
+
 #endif  /* ENABLE_PLUGINS */