p2 = *p + strlen(*p);
len = p2 - *p - ((*p2 == '\"')?1:0);
buf = smalloc(len + 1);
- memcpy(buf, *p, len);
+ memcpy(buf, *p + ((delim == '\"')?1:0), len);
buf[len] = 0;
*p = p2 + ((*p2 == '\"')?1:0);
for(p2 = buf; *p2; p2++, len--) {
return(rv);
}
-void writeconfig(void)
+int writeconfig(void)
{
FILE *cf;
struct cfvar *var;
if((cf = fopen(cfname, "w")) == NULL) {
msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not open the configuration file for writing: %s"), strerror(errno));
- return;
+ return(-1);
}
fputs("# This file was generated by dolconf v" VERSION "\n\n", cf);
for(var = config; var->name != NULL; var++) {
}
fclose(cf);
dirty = 0;
+ return(0);
}
void fillcfw(void)
gtk_widget_set_sensitive(GTK_WIDGET(cfw_uibox), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
}
-void cb_cfw_hup_activate(GtkWidget *widget, gpointer uudata)
+int hupserver(int disperr)
{
- int tag;
+ int tag, ret;
struct dc_response *resp;
if(dc_connectsync2(dc_srv_local, DC_LATEST) < 0) {
- msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
- return;
+ if(disperr)
+ msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
+ return(-1);
}
if(dc_login(NULL, 1, dc_convnone, NULL) != DC_LOGIN_ERR_SUCCESS) {
dc_disconnect();
- msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
- return;
+ if(disperr)
+ msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
+ return(-1);
}
+ ret = 0;
tag = dc_queuecmd(NULL, NULL, L"hup", NULL);
if((resp = dc_gettaggedrespsync(tag)) != NULL) {
- if(resp->code != 200)
- msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
+ if(resp->code != 200) {
+ if(disperr)
+ msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect to server"));
+ ret = -1;
+ }
dc_freeresp(resp);
}
dc_disconnect();
+ return(ret);
+}
+
+int saveconfig(void)
+{
+ struct cfvar *cv;
+
+ cfw2conf();
+ if((cv = cfwvalid()) != NULL) {
+ msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, cv->vld->invmsg, cv->rname);
+ return(-1);
+ }
+ return(writeconfig());
+}
+
+/*
+void cb_cfw_hup_activate(GtkWidget *widget, gpointer uudata)
+{
+ hupserver(1);
}
void cb_cfw_save_activate(GtkWidget *widget, gpointer uudata)
gtk_main_quit();
state = -1;
}
+*/
+
+void cb_cfw_ok_clicked(GtkWidget *widget, gpointer uudata)
+{
+ if(saveconfig())
+ return;
+ hupserver(0);
+ gtk_main_quit();
+ state = -1;
+}
+
+void cb_cfw_cancel_clicked(GtkWidget *widget, gpointer uudata)
+{
+ gtk_main_quit();
+ state = -1;
+}
+
+void cb_cfw_apply_clicked(GtkWidget *widget, gpointer uudata)
+{
+ if(saveconfig())
+ return;
+ hupserver(1);
+}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
state = -1;
- while((c = getopt(argc, argv, "haw")) != -1) {
+ while((c = getopt(argc, argv, "hawV")) != -1) {
switch(c) {
case 'a':
state = 1;
printf("\t-h\tDisplay this help message\n");
printf("\t-a\tGo directly to the assistant\n");
printf("\t-w\tGo directly to the standard window\n");
+ printf("\t-V\tDisplay version info and exit\n");
+ exit(0);
+ case 'V':
+ printf("%s", RELEASEINFO);
exit(0);
default:
- fprintf(stderr, "usage: dolconf [-haw]\n");
+ fprintf(stderr, "usage: dolconf [-hawV]\n");
exit(1);
}
}