src/mess/tools/dat2html/dat2html.c
| r4862 | r4863 | |
| 23 | 23 | if (!strchr(src, '<') && !strchr(src, '>')) |
| 24 | 24 | return; |
| 25 | 25 | |
| 26 | | while( *src ) |
| 26 | while( *src ) |
| 27 | 27 | { |
| 28 | 28 | if( *src == '<' ) |
| 29 | 29 | dst += sprintf(dst, "<"); |
| 30 | 30 | else |
| 31 | | if( *src == '>' ) |
| 31 | if( *src == '>' ) |
| 32 | 32 | dst += sprintf(dst, ">"); |
| 33 | 33 | else |
| 34 | 34 | *dst++ = *src; |
| r4862 | r4863 | |
| 54 | 54 | /* terminate URL */ |
| 55 | 55 | c = *url_end; |
| 56 | 56 | *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'; |
| 59 | 59 | /* add <a href=" to the buffer */ |
| 60 | 60 | strcat(buff, "<a href=\""); |
| 61 | 61 | strcat(buff, url_beg); |
| r4862 | r4863 | |
| 85 | 85 | |
| 86 | 86 | tm = time(NULL); |
| 87 | 87 | |
| 88 | | if( ac > 1 ) |
| 88 | if( ac > 1 ) |
| 89 | 89 | { |
| 90 | 90 | strcpy(dat_filename, av[1]); |
| 91 | 91 | if( ac > 2 ) |
| r4862 | r4863 | |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | | dat = fopen(dat_filename, "r"); |
| 101 | dat = fopen(dat_filename, "r"); |
| 102 | 102 | if( !dat ) |
| 103 | 103 | { |
| 104 | 104 | fprintf(stderr, "cannot open input file '%s'.\n", dat_filename); |
| r4862 | r4863 | |
| 111 | 111 | fclose(dat); |
| 112 | 112 | fprintf(stderr, "cannot create output file '%s'.\n", html_filename); |
| 113 | 113 | return 1; |
| 114 | | } |
| 114 | } |
| 115 | 115 | |
| 116 | 116 | osd_mkdir(html_directory); |
| 117 | 117 | |
| 118 | 118 | /* Head of the index html file */ |
| 119 | | fprintf(html, "<html>\n"); |
| 119 | fprintf(html, "<html>\n"); |
| 120 | 120 | fprintf(html, "<head>\n"); |
| 121 | 121 | fprintf(html, "<title>Contents of %s</title>\n", dat_filename); |
| 122 | 122 | fprintf(html, "</head>\n"); |
| r4862 | r4863 | |
| 125 | 125 | fprintf(html, "<hr>\n"); |
| 126 | 126 | fprintf(html, "<p>\n"); |
| 127 | 127 | |
| 128 | | while( !feof(dat) ) |
| 128 | while( !feof(dat) ) |
| 129 | 129 | { |
| 130 | 130 | char line[1024], *eol; |
| 131 | 131 | |
| r4862 | r4863 | |
| 135 | 135 | *eol = '\0'; |
| 136 | 136 | eol = strchr(line, '\r'); |
| 137 | 137 | if( eol ) |
| 138 | | *eol = '\0'; |
| 139 | | if( line[0] != '#' ) |
| 138 | *eol = '\0'; |
| 139 | if( line[0] != '#' ) |
| 140 | 140 | { |
| 141 | 141 | if( line[0] == '$' ) |
| 142 | 142 | { |
| r4862 | r4863 | |
| 150 | 150 | |
| 151 | 151 | systemcount++; |
| 152 | 152 | |
| 153 | | html_system = fopen(system_filename, "w"); |
| 153 | html_system = fopen(system_filename, "w"); |
| 154 | 154 | |
| 155 | 155 | if( !html_system ) |
| 156 | 156 | { |
| 157 | fclose(html); |
| 158 | fclose(dat); |
| 157 | 159 | fprintf(stderr, "cannot create system_name file '%s'.\n", system_filename); |
| 158 | 160 | return 1; |
| 159 | | } |
| 161 | } |
| 160 | 162 | |
| 161 | 163 | /* Head of the system html code */ |
| 162 | 164 | fprintf(html_system, "<html>\n"); |
| 163 | | fprintf(html_system, "<head>\n"); |
| 165 | fprintf(html_system, "<head>\n"); |
| 164 | 166 | 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"); |
| 167 | 169 | fprintf(html_system, "<table width=100%%>\n"); |
| 168 | 170 | fprintf(html_system, "<tr>\n"); |
| 169 | 171 | fprintf(html_system, "<td width=25%%><h4><a href=\"../%s\">Back to index</a></h4></td>\n", html_filename); |
| 170 | 172 | fprintf(html_system, "<td><h1>Info for %s</h1></td>\n", system_name); |
| 171 | 173 | fprintf(html_system, "</tr>\n"); |
| 172 | 174 | fprintf(html_system, "</table>\n"); |
| 173 | | fprintf(html_system, "<hr>\n"); |
| 175 | fprintf(html_system, "<hr>\n"); |
| 174 | 176 | linecount = 0; |
| 175 | 177 | emptycount = 0; |
| 176 | | } |
| 178 | } |
| 177 | 179 | else |
| 178 | 180 | if( mame_strnicmp(line + 1, "bio", 3) == 0 ) |
| 179 | | { |
| 181 | { |
| 180 | 182 | /* that's just fine... */ |
| 181 | 183 | } |
| 182 | 184 | else |
| r4862 | r4863 | |
| 204 | 206 | } |
| 205 | 207 | else |
| 206 | 208 | { |
| 207 | | replace_lt_gt(line); |
| 209 | replace_lt_gt(line); |
| 208 | 210 | a_href_url(line); |
| 209 | 211 | emptycount = 0; |
| 210 | 212 | if ( linecount == 0 ) |
| r4862 | r4863 | |
| 222 | 224 | int ul = 0; |
| 223 | 225 | while( line[ul] && isspace(line[ul]) ) |
| 224 | 226 | ul++; |
| 225 | | /* lines beginning with a dash are lists!? */ |
| 227 | /* lines beginning with a dash are lists!? */ |
| 226 | 228 | if( ul > 0 && line[ul] == '-' ) |
| 227 | | { |
| 229 | { |
| 228 | 230 | if( ulcount == 0 ) |
| 229 | 231 | fprintf(html_system, "<ul>\n"); |
| 230 | 232 | fprintf(html_system, "<li>%s\n", line + ul + 1); |
| 231 | 233 | ulcount++; |
| 232 | | } |
| 233 | | else |
| 234 | } |
| 235 | else |
| 234 | 236 | { |
| 235 | 237 | if( ulcount ) |
| 236 | 238 | fprintf(html_system, "</ul>\n"); |
| r4862 | r4863 | |
| 250 | 252 | } |
| 251 | 253 | |
| 252 | 254 | fprintf(html, "</p>\n"); |
| 253 | | fprintf(html, "<hr>\n"); |
| 255 | fprintf(html, "<hr>\n"); |
| 254 | 256 | fprintf(html, "<center><font size=-2>Generated on %s</font></center>\n", ctime(&tm)); |
| 255 | 257 | fprintf(html, "</body>\n"); |
| 256 | 258 | fprintf(html, "</html>\n"); |
| 257 | | fclose(html); |
| 259 | fclose(html); |
| 258 | 260 | fclose(dat); |
| 259 | 261 | return 0; |
| 260 | 262 | } |