--- io.c.orig 2007-07-01 15:19:57.000000000 -0400 +++ io.c 2007-11-24 18:14:00.000000000 -0500 @@ -17,6 +17,7 @@ static void rewrite_contest_file(void); static void write_call_library_file(void); static gint process_tmp_file(const gchar *filnam); +static char* chomp(char *s); static void fill_iend_array(void) { @@ -99,24 +100,22 @@ strcat(contest_line, cr_array[qnum].tx); strcpy(field_hold, cr_array[qnum].prefix); right_blank_pad(field_hold, sizeof(cr_array[qnum].prefix)); - strcat(contest_line, field_hold); - add_eol_chars (contest_line); + sprintf(contest_line,"%s%s\n",contest_line,field_hold); } static void read_ini_file(void) { FILE *fp; gchar filnam[13], msg[49], contest_ini_line[76]; - gint i, icolon, lcil, socil; + gint i, socil; + char *token; guint answer; - strcpy(filnam, contest_file_base); - strcat(filnam, ".INI"); + snprintf(filnam,sizeof(filnam), "%s.INI", contest_file_base); fp = fopen(filnam, "r"); if(fp==NULL) { - strcpy(msg, filnam); - strcat(msg, " does not exist. Use default? (Y/N)"); + snprintf(msg,sizeof(msg),"%s does not exist. Use default? (Y/N)"); play_bells (DUPE_SOUND); answer = boxed_message (msg, 0, LT_GRAY); if(toupper_ui(answer)=='Y') fp = fopen("DEFAULT.INI","r"); @@ -125,53 +124,41 @@ socil = sizeof(contest_ini_line); for(i=0; i-1) - { - lcil = strlen(contest_ini_line); - if(contest_ini_line[lcil-1]=='\n') contest_ini_line[lcil-1] = '\0'; - if(contest_ini_line[lcil-2]=='\r') contest_ini_line[lcil-2] = '\0'; - lcil = strlen(contest_ini_line); - if(lcil>icolon+1) - concat(init_screen_choices[i], contest_ini_line, - icolon+1, lcil-1, COPY); - } + if(fgets(contest_ini_line, socil, fp) == NULL) + break; + token = strtok(contest_ini_line, ":\r\n"); + if (token != NULL) + { + token = strtok(NULL,":\r\n"); + if (token != NULL) + strcpy(init_screen_choices[i], token); + } } for(i=0; i-1) - { - lcil = strlen(contest_ini_line); - if(contest_ini_line[lcil-1]=='\n') contest_ini_line[lcil-1] = '\0'; - if(contest_ini_line[lcil-2]=='\r') contest_ini_line[lcil-2] = '\0'; - lcil = strlen(contest_ini_line); - if(lcil>icolon+1) - concat(set_screen_choices[i], contest_ini_line, - icolon+1, lcil-1, COPY); - } + if(fgets(contest_ini_line, socil, fp) == NULL) + break; + token = strtok(contest_ini_line, ":\r\n"); + if (token != NULL) + { + token = strtok(NULL,":\r\n"); + if (token != NULL) + strcpy(set_screen_choices[i], token); + } } if(!strcmp(set_screen_choices[1], "")) strcpy(set_screen_choices[1], dupe_bracket[0]); for(i=0; i-1) - { - lcil = strlen(contest_ini_line); - if(contest_ini_line[lcil-1]=='\n') contest_ini_line[lcil-1] = '\0'; - if(contest_ini_line[lcil-2]=='\r') contest_ini_line[lcil-2] = '\0'; - lcil = strlen(contest_ini_line); - if(lcil>icolon+1) - concat(keyer_screen_choices[i], contest_ini_line, - icolon+1, lcil-1, COPY); - } + if(fgets(contest_ini_line, socil, fp) == NULL) + break; + token = strtok(contest_ini_line, ":\r\n"); + if(token != NULL) + { + token = strtok(NULL,":\r\n"); + if (token != NULL) + strcpy(keyer_screen_choices[i], token); + } } fclose(fp); } @@ -187,17 +174,14 @@ fp = fopen(filnam, "r"); if(fp==NULL) { - strcpy(msg, "Error reading "); - strcat(msg, filnam); + snprintf(msg, sizeof(msg), "Error reading %s", filnam); rw_error_box (main_drawing_area, msg); return; } icall_count = 0; socl = sizeof(contest_line); - for( ; ; ) + while(fgets(contest_line, socl, fp) != NULL) { - fgets(contest_line, socl, fp); - if(feof(fp)) break; icall_count++; fill_cr_array_all (contest_line, icall_count); } @@ -257,16 +241,13 @@ gchar filnam[13], contest_line[76]; ded_num = 0; - strcpy(filnam, contest_file_base); - strcat(filnam, ".DED"); + sprintf(filnam,"%s.DED", filnam); fp = fopen(filnam, "r"); if(fp==NULL) return; socl = sizeof(contest_line); - for( ; ; ) + while(fgets(contest_line, socl, fp) != NULL) { - fgets(contest_line, socl, fp); - if(feof(fp)) break; ded_num++; strcpy(ded_array[ded_num], contest_line); } @@ -276,7 +257,7 @@ static void read_locus_file(void) { FILE *fp; - gint i, j, lcil, icn, soli; + gint i, j, icn, soli; gchar filnam[13], msg[49], clat[5], clong[6]; gchar line_in[80]; gint n=0; @@ -320,20 +301,14 @@ fp = fopen(filnam, "r"); if(fp==NULL) { - strcpy(msg, "Error reading "); - strcat(msg, filnam); + snprintf(msg,sizeof(msg),"Error reading %s",filnam); rw_error_box (main_drawing_area, msg); return; } soli = sizeof(line_in); - for( ; ; ) + while(fgets(line_in, soli, fp) != NULL) { - fgets(line_in, soli, fp); - if(feof(fp)) break; - lcil = strlen(line_in); - if(line_in[lcil-1]=='\n') line_in[lcil-1] = '\0'; - if(line_in[lcil-2]=='\r') line_in[lcil-2] = '\0'; - lcil = strlen(line_in); + chomp(line_in); n++; concat(loci.locus_name[n], line_in, col_num[icn][0], col_num[icn][1], COPY); @@ -376,8 +351,7 @@ fp = fopen(filnam, "r"); if(fp==NULL) { - strcpy(msg, "Error reading "); - strcat(msg, filnam); + snprintf(msg, sizeof(msg), "Error reading %s",filnam); rw_error_box (main_drawing_area, msg); return; } @@ -385,12 +359,12 @@ contest_nc[i][0] = '\0'; for(i=0; i "); - strcat(system_line, filnam_hold); - system(system_line); - fp = fopen(filnam_hold, "r"); - if(fp!=NULL) + snprintf(system_line, sizeof(system_line) - 1, "ps|grep %s|grep -v grep", + filnam); + pfp = popen(system_line, "r"); + if(pfp!=NULL) { - fgets(psc_line, sizeof(psc_line), fp); + fgets(psc_line, sizeof(psc_line), pfp); if(kb_index (psc_line, filnam)>-1) ami_running = 0; - fclose(fp); - remove(filnam_hold); + fclose(pfp); } return ami_running; } + +static char* +chomp(char *s) +{ + char *p; + + p = strchr(s, '\n'); + if (p != NULL) + { + *p = '\0'; + p--; + if (*p == '\r') + *p = '\0'; + } +} +