Previous 15994 Revisions Next

r4863 Thursday 28th May, 2009 at 06:32:35 UTC by Firewave
{DAT2HTML] fixed poental resource leaks reported by cppcheck / replaced whitespaces with real TABs
[src/mess/tools/dat2html]dat2html.c

src/mess/tools/dat2html/dat2html.c
r4862r4863
2323   if (!strchr(src, '<') && !strchr(src, '>'))
2424      return;
2525
26    while( *src )
26   while( *src )
2727   {
2828      if( *src == '<' )
2929         dst += sprintf(dst, "&lt;");
3030      else
31        if( *src == '>' )
31      if( *src == '>' )
3232         dst += sprintf(dst, "&gt;");
3333      else
3434         *dst++ = *src;
r4862r4863
5454   /* terminate URL */
5555   c = *url_end;
5656   *url_end = '\0';
57    /* terminate buffer right before the URL */
58    buff[(int)(url_beg - line)] = '\0';
57   /* terminate buffer right before the URL */
58   buff[(int)(url_beg - line)] = '\0';
5959   /* add <a href=" to the buffer */
6060   strcat(buff, "<a href=\"");
6161   strcat(buff, url_beg);
r4862r4863
8585
8686   tm = time(NULL);
8787
88    if( ac > 1 )
88   if( ac > 1 )
8989   {
9090      strcpy(dat_filename, av[1]);
9191      if( ac > 2 )
r4862r4863
9898      }
9999   }
100100
101    dat = fopen(dat_filename, "r");
101   dat = fopen(dat_filename, "r");
102102   if( !dat )
103103   {
104104      fprintf(stderr, "cannot open input file '%s'.\n", dat_filename);
r4862r4863
111111      fclose(dat);
112112      fprintf(stderr, "cannot create output file '%s'.\n", html_filename);
113113      return 1;
114    }
114   }
115115
116116   osd_mkdir(html_directory);
117117
118118   /* Head of the index html file */
119       fprintf(html, "<html>\n");
119   fprintf(html, "<html>\n");
120120   fprintf(html, "<head>\n");
121121   fprintf(html, "<title>Contents of %s</title>\n", dat_filename);
122122   fprintf(html, "</head>\n");
r4862r4863
125125   fprintf(html, "<hr>\n");
126126   fprintf(html, "<p>\n");
127127
128    while( !feof(dat) )
128   while( !feof(dat) )
129129   {
130130      char line[1024], *eol;
131131
r4862r4863
135135         *eol = '\0';
136136      eol = strchr(line, '\r');
137137      if( eol )
138            *eol = '\0';
139        if( line[0] != '#' )
138         *eol = '\0';
139      if( line[0] != '#' )
140140      {
141141         if( line[0] == '$' )
142142         {
r4862r4863
150150
151151               systemcount++;
152152
153                             html_system = fopen(system_filename, "w");
153               html_system = fopen(system_filename, "w");
154154
155155               if( !html_system )
156156               {
157                  fclose(html);
158                  fclose(dat);
157159                  fprintf(stderr, "cannot create system_name file '%s'.\n", system_filename);
158160                  return 1;
159                             }
161               }
160162
161163               /* Head of the system html code */
162164               fprintf(html_system, "<html>\n");
163                             fprintf(html_system, "<head>\n");
165               fprintf(html_system, "<head>\n");
164166               fprintf(html_system, "<title>Info for %s</title>\n", system_name);
165                         fprintf(html_system, "</head>\n");
166                             fprintf(html_system, "<body leftmargin= 20 rightmargin = 20>\n");
167               fprintf(html_system, "</head>\n");
168               fprintf(html_system, "<body leftmargin= 20 rightmargin = 20>\n");
167169               fprintf(html_system, "<table width=100%%>\n");
168170               fprintf(html_system, "<tr>\n");
169171               fprintf(html_system, "<td width=25%%><h4><a href=\"../%s\">Back to index</a></h4></td>\n", html_filename);
170172               fprintf(html_system, "<td><h1>Info for %s</h1></td>\n", system_name);
171173               fprintf(html_system, "</tr>\n");
172174               fprintf(html_system, "</table>\n");
173                             fprintf(html_system, "<hr>\n");
175               fprintf(html_system, "<hr>\n");
174176               linecount = 0;
175177               emptycount = 0;
176                }
178            }
177179            else
178180            if( mame_strnicmp(line + 1, "bio", 3) == 0 )
179                {
181            {
180182               /* that's just fine... */
181183            }
182184            else
r4862r4863
204206               }
205207               else
206208               {
207                                 replace_lt_gt(line);
209                  replace_lt_gt(line);
208210                  a_href_url(line);
209211                  emptycount = 0;
210212                  if ( linecount == 0 )
r4862r4863
222224                     int ul = 0;
223225                     while( line[ul] && isspace(line[ul]) )
224226                        ul++;
225                            /* lines beginning with a dash are lists!? */
227                     /* lines beginning with a dash are lists!? */
226228                     if( ul > 0 && line[ul] == '-' )
227                            {
229                     {
228230                        if( ulcount == 0 )
229231                           fprintf(html_system, "<ul>\n");
230232                        fprintf(html_system, "<li>%s\n", line + ul + 1);
231233                        ulcount++;
232                            }
233                            else
234                     }
235                     else
234236                     {
235237                        if( ulcount )
236238                           fprintf(html_system, "</ul>\n");
r4862r4863
250252   }
251253
252254   fprintf(html, "</p>\n");
253    fprintf(html, "<hr>\n");
255   fprintf(html, "<hr>\n");
254256   fprintf(html, "<center><font size=-2>Generated on %s</font></center>\n", ctime(&tm));
255257   fprintf(html, "</body>\n");
256258   fprintf(html, "</html>\n");
257    fclose(html);
259   fclose(html);
258260   fclose(dat);
259261   return 0;
260262}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team