예제 #1
0
파일: gui.c 프로젝트: outgame/CrayonPhysics
void *client_recv1(void *gui){
  while(1){
    char buff[MAXLINE];
    int bytes = client_recv(((Gui*)gui)->sockfd, buff);
    buff[bytes] = '\0';

    if (buff[0] != '\0'){
      gchar *new_tab = "> ";
      add_to_text(gui, new_tab);
      
      add_to_text(gui, buff);
      
      gchar *new_line = "\n";
      add_to_text(gui, new_line);
    }    

    buff[0] = '\0';

    sleep(.1);
  }
}
예제 #2
0
파일: gui.c 프로젝트: outgame/CrayonPhysics
static gboolean send_cb(GtkWidget *widget, Gui *gui){
  //get text from entry
  gchar *text = gtk_entry_get_text(GTK_ENTRY(gui->entry));

  //  fprintf(stdout, "Text in the entry is %s\n", text);

  //this is where we send the text, currently just adding it to the text window
  gchar *new_tab = "> ";
  add_to_text(gui, new_tab);
  
  add_to_text(gui, text); 
  client_send(gui->sockfd, text);
  
  gchar *new_line = "\n";
  add_to_text(gui, new_line);

  //clear the text entry box
  const char *clear = "";
  gtk_entry_set_text(GTK_ENTRY(gui->entry), clear);

  return TRUE;
}
예제 #3
0
void settings_save(Settings *s)
{
    char *sav_file = find_in_share("req_settings.txt");
    if (sav_file && fileExists(sav_file)) {
        // update an existing file
        printf("Found settings file: %s\n", sav_file);
        char *new_sav_txt = MALLOC(sizeof(char)*1024);
        strcpy(new_sav_txt, "");
        int i,len=2048;
        int wrote_csv=FALSE,
            wrote_output=FALSE,
            wrote_obs_req_num=FALSE,
            wrote_obs_req_id_aadn=FALSE,
            wrote_obs_req_id_tdrs=FALSE,
            wrote_acq_req_num=FALSE,
            wrote_odl0_seq_num=FALSE,
            wrote_odl0_req_id=FALSE,
            wrote_station_code=FALSE;

        int wrote_acq_req_id[MAX_STATIONS];
        int wrote_acq_req_stn_code[MAX_STATIONS];
        for (i=0; i<MAX_STATIONS; ++i) {
            wrote_acq_req_id[i] = FALSE;
            wrote_acq_req_stn_code[i] = FALSE;
        }

        FILE *fp = FOPEN(sav_file, "r");
        if (!fp) {
            message_box("Error opening output file!\n");
            return;
        }

        char buf[1024];
        while (fgets(buf, 1024, fp) != NULL) {
            if (s->csv_dir && matches(buf, csv_dir_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", csv_dir_key, s->csv_dir);
                wrote_csv = TRUE;
            } else if (s->output_dir && matches(buf, output_dir_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", output_dir_key, s->output_dir);
                wrote_output = TRUE;
            } else if (matches(buf, obs_req_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
                wrote_obs_req_num = TRUE;
            } else if (matches(buf, obs_req_id_aadn_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
                wrote_obs_req_id_aadn = TRUE;
            } else if (matches(buf, obs_req_id_tdrs_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
                wrote_obs_req_id_tdrs = TRUE;
            } else if (matches(buf, acq_req_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
                wrote_acq_req_num = TRUE;
            } else if (matches(buf, odl0_seq_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
                wrote_odl0_seq_num = TRUE;
            } else if (matches(buf, odl0_req_id_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", odl0_req_id_key, s->odl0_req_id);
                wrote_odl0_req_id = TRUE;
            } else if (s->station_code && matches(buf, station_code_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", station_code_key, s->station_code);
                wrote_station_code = TRUE;
            } else {
                int found=0;
                for (i=0; i<MAX_STATIONS; ++i) {
                    char id_key[128], stn_code_key[128];
                    snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                    snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                    if (matches(buf, id_key)) {
                        found = TRUE;
                        add_to_text(&new_sav_txt, &len, "%s = %s\r\n",
                            stn_code_key, s->acq_req_stn_codes[i]);
                        wrote_acq_req_stn_code[i] = TRUE;
                    } else if (matches(buf, stn_code_key)) {
                        found = TRUE;
                        add_to_text(&new_sav_txt, &len, "%s = %d\r\n",
                            id_key, s->acq_req_ids[i]);
                        wrote_acq_req_id[i] = TRUE;
                    }
                }
                if (!found)
                    add_to_text(&new_sav_txt, &len, "%s", buf);
            }
        }
        FCLOSE(fp);

        if (s->csv_dir && !wrote_csv)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", csv_dir_key, s->csv_dir);
        if (s->output_dir && !wrote_output)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", output_dir_key, s->output_dir);
        if (!wrote_obs_req_num && s->obs_req_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
        if (!wrote_obs_req_id_aadn && s->obs_req_id_aadn > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
        if (!wrote_obs_req_id_tdrs && s->obs_req_id_tdrs > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
        if (!wrote_acq_req_num && s->acq_req_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
        if (!wrote_odl0_seq_num && s->odl0_seq_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
        if (!wrote_odl0_req_id && s->odl0_req_id > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", s->odl0_req_id);
        if (s->station_code && !wrote_station_code)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", station_code_key, s->station_code);

        for (i=0; i<MAX_STATIONS; ++i) {
            if (!wrote_acq_req_id[i] && s->acq_req_ids[i] > 0 &&
                !wrote_acq_req_stn_code[i] &&
                strlen(s->acq_req_stn_codes[i]) > 0)
            {
                char id_key[128], stn_code_key[128];
                snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", stn_code_key, s->acq_req_stn_codes[i]);
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", id_key, s->acq_req_ids[i]);
            }
        }

        fp = FOPEN(sav_file, "w");
        fprintf(fp, "%s", new_sav_txt);
        FCLOSE(fp);
    } else {
        sav_file = MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+32));
        sprintf(sav_file, "%s/req_settings.txt", get_asf_share_dir());
        // write a new file
        FILE *fp = FOPEN(sav_file, "w");
        if (s->csv_dir)
            fprintf(fp, "%s = %s\r\n", csv_dir_key, s->csv_dir);
        if (s->output_dir)
            fprintf(fp, "%s = %s\r\n", output_dir_key, s->output_dir);
        fprintf(fp, "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
        fprintf(fp, "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
        fprintf(fp, "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
        fprintf(fp, "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
        fprintf(fp, "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
        fprintf(fp, "%s = %d\r\n", odl0_req_id_key, s->odl0_req_id);

        int i;
        for (i=0; i<MAX_STATIONS; ++i) {
            if (s->acq_req_ids[i] > 0 && strlen(s->acq_req_stn_codes[i]) > 0) {
                char id_key[128], stn_code_key[128];
                snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                fprintf(fp, "%s = %s\r\n", stn_code_key, s->acq_req_stn_codes[i]);
                snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                fprintf(fp, "%s = %d\r\n", id_key, s->acq_req_ids[i]);
            }
        }
        if (s->station_code)
            fprintf(fp, "%s = %s\r\n", station_code_key, s->station_code);
        FCLOSE(fp);
    }
    free(sav_file);
}