/[xlog]/xlog/src/logfile/trlog.c
ViewVC logotype

Diff of /xlog/src/logfile/trlog.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by pa4tu, Sun May 9 21:21:07 2004 UTC revision 1.6 by pa4tu, Sat Aug 21 11:13:01 2004 UTC
# Line 24  Line 24 
24  #include <stdlib.h>  #include <stdlib.h>
25  #include <stdio.h>  #include <stdio.h>
26  #include <string.h>  #include <string.h>
27    #include <locale.h>
28    #ifndef __USE_XOPEN
29    #define __USE_XOPEN
30    #endif
31    #include <time.h>
32  #include <glib.h>  #include <glib.h>
33    
34  #include "logfile.h"  #include "logfile.h"
35  #include "types.h"  #include "types.h"
36    
   
37  /*  /*
38   * file fields   * file fields
39   */   */
# Line 61  gint Line 65  gint
65  trlog_open (LOGDB * handle)  trlog_open (LOGDB * handle)
66  {  {
67          FILE *fp;          FILE *fp;
68    const gint xlog_fields [] = {DATE, GMT, CALL, BAND, MODE, RST, MYRST};          const gint xlog_fields [] = {DATE, GMT, CALL, BAND, MODE, RST, MYRST};
69    
70          fp = fopen (handle->path, "r");          fp = fopen (handle->path, "r");
71          if (!fp) return -1;          if (!fp) return -1;
# Line 70  trlog_open (LOGDB * handle) Line 74  trlog_open (LOGDB * handle)
74          /* set columns to be used in xlog */          /* set columns to be used in xlog */
75          handle->column_nr = 7;          handle->column_nr = 7;
76          memcpy (handle->column_fields, xlog_fields, sizeof (xlog_fields));          memcpy (handle->column_fields, xlog_fields, sizeof (xlog_fields));
77    /* TODO: set and use handle->column_widths */          /* TODO: set and use handle->column_widths */
78          return 0;          return 0;
79  }  }
80    
# Line 118  trlog_qso_append (LOGDB * handle, const Line 122  trlog_qso_append (LOGDB * handle, const
122                  gmt[5] = '\0';                  gmt[5] = '\0';
123          }          }
124    
125  // 80CW  21-Feb-04 23:41 0053  VY2LZ          599  599  PEI           PEI      3    // 80CW 21-Feb-04 23:41 0053    VY2LZ                                   599     599     PEI                                      PEI                    3      
126    
127          fprintf (fp, "%3s%-3s%9s %5s %-4s        %-15s%-5s%-5s%-7s\n",          fprintf (fp, "%3s%-3s%9s %5s %-4s        %-15s%-5s%-5s%-7s\n",
128                   q[BAND], q[MODE], q[DATE], gmt, exch, q[CALL], q[RST], q[MYRST], rxexch);                  q[BAND], q[MODE], q[DATE], gmt, exch, q[CALL], q[RST], q[MYRST], rxexch);
129          return 0;          return 0;
130  }  }
131    
# Line 133  gint trlog_qso_foreach Line 137  gint trlog_qso_foreach
137          FILE *fp = (FILE *) handle->priv;          FILE *fp = (FILE *) handle->priv;
138          gint i, ret;          gint i, ret;
139          qso_t q[QSO_FIELDS];          qso_t q[QSO_FIELDS];
140          gchar *field, *end, buffer[MAXROWLEN+1];          gchar *field, *end, buffer[MAXROWLEN+1], *curlocale, *d, *res = NULL,
141                    buf[20];
142          const gint *widths = trlog_widths;          const gint *widths = trlog_widths;
143            struct tm tm_trlog;
144    
145            /* get current language settings and set environment for trlog import */
146            curlocale = setlocale (LC_ALL, NULL);
147            setlocale (LC_ALL, "C");
148    
149          while (!feof (fp))          while (!feof (fp))
150          {          {
# Line 154  gint trlog_qso_foreach Line 164  gint trlog_qso_foreach
164                  for (i = 0; i < trlog_field_nr; i++)                  for (i = 0; i < trlog_field_nr; i++)
165                  {                  {
166    
167  // 80CW  21-Feb-04 23:41 0053  VY2LZ          599  599  PEI           PEI      3    // 80CW 21-Feb-04 23:41 0053    VY2LZ                                   599     599     PEI                                      PEI                    3      
168                          end = field + widths[i];                          end = field + widths[i];
169                          *end = '\0';                          *end = '\0';
170    
# Line 198  gint trlog_qso_foreach Line 208  gint trlog_qso_foreach
208                                  field[2] = ' ';                                  field[2] = ' ';
209                                  field[6] = '\0';                                  field[6] = '\0';
210                                  if (field[7] == '0' || field[7] == '1')                                  if (field[7] == '0' || field[7] == '1')
211                                          q[trlog_fields[i]] = g_strdup_printf ("%s 20%s", field, field + 7);                                          d = g_strdup_printf ("%s 20%s", field, field + 7);
212                                  else                                  else
213                                          q[trlog_fields[i]] = g_strdup_printf ("%s 19%s", field, field + 7);                                          d = g_strdup_printf ("%s 19%s", field, field + 7);
214                                    /* convert string to current locale */
215                                    res = strptime (d, "%d %b %Y", &tm_trlog);
216                                    if (res != NULL)
217                                    {
218                                            setlocale (LC_ALL, curlocale);
219                                            strftime (buf, 20, "%d %b %Y", &tm_trlog);
220                                            q[trlog_fields[i]] = g_strdup (buf);
221                                            setlocale (LC_ALL, "C");
222                                    }
223                                    else
224                                            q[trlog_fields[i]] = g_strdup (d);
225                                    g_free (d);
226                          }                          }
227                          else                          else
228                                  q[trlog_fields[i]] = g_strdup (g_strstrip (field));                                  q[trlog_fields[i]] = g_strdup (g_strstrip (field));
229                          field = end + 1;                          field = end + 1;
230                  }                  }
231                    /* restore locale */
232                    setlocale (LC_ALL, curlocale);
233                  ret = (*fn) (handle, q, arg);                  ret = (*fn) (handle, q, arg);
234                  if (ret) return ret;                  if (ret) return ret;
235                  }                  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26