mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fixing dive notes escape characters in worldmap exporter
Replacing the newlines in the string with <br> and changing the single quote to its HTML number. Also minor coding style updates to previous commit. Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3485c6c260
commit
c268b757df
1 changed files with 79 additions and 32 deletions
|
@ -27,10 +27,59 @@ void put_HTML_temp(struct membuffer *b,struct dive *dive)
|
||||||
put_temperature(b, dive->watertemp, "<p>Water Temp: ", " C\\'</p>");
|
put_temperature(b, dive->watertemp, "<p>Water Temp: ", " C\\'</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *replace_char(char *str, char replace, char *replace_by)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
this fumction can't replace a character with a substring
|
||||||
|
where the substring contains the character, infinte loop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int i = 0, char_count = 0, new_size;
|
||||||
|
|
||||||
|
while (str[i] != '\0') {
|
||||||
|
if (str[i] == replace)
|
||||||
|
char_count++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_size = strlen(str) + char_count * strlen(replace_by) + 1;
|
||||||
|
char *result = malloc(new_size);
|
||||||
|
char *temp = strdup(str);
|
||||||
|
char *p0, *p1;
|
||||||
|
if (!result || !temp)
|
||||||
|
return 0;
|
||||||
|
result[0] = '\0';
|
||||||
|
p0 = temp;
|
||||||
|
p1 = strchr(temp, replace);
|
||||||
|
while (p1) {
|
||||||
|
*p1 = '\0';
|
||||||
|
strcat(result, p0);
|
||||||
|
strcat(result, replace_by);
|
||||||
|
p0 = p1 + 1;
|
||||||
|
p1 = strchr(p0, replace);
|
||||||
|
}
|
||||||
|
strcat(result, p0); /*concat the rest of the string*/
|
||||||
|
free(temp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *quote(char *string)
|
||||||
|
{
|
||||||
|
char *new_line_removed = replace_char(string, '\n', "<br>");
|
||||||
|
char *single_quotes_removed = replace_char(new_line_removed, '\'', "'");
|
||||||
|
free(new_line_removed);
|
||||||
|
return single_quotes_removed;
|
||||||
|
}
|
||||||
|
|
||||||
void put_HTML_notes(struct membuffer *b, struct dive *dive)
|
void put_HTML_notes(struct membuffer *b, struct dive *dive)
|
||||||
{
|
{
|
||||||
if (dive->notes) {
|
if (dive->notes) {
|
||||||
put_format(b,"<p>Notes : %s </p>",dive->notes);
|
char *notes = quote(dive->notes);
|
||||||
|
put_format(b,"<p>Notes : %s </p>", notes);
|
||||||
|
free(notes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +91,8 @@ void writeMarkers(struct membuffer *b)
|
||||||
for_each_dive(i, dive) {
|
for_each_dive(i, dive) {
|
||||||
/*export selected dives only ?*/
|
/*export selected dives only ?*/
|
||||||
|
|
||||||
if (dive->latitude.udeg==0 && dive->longitude.udeg==0) {
|
if (dive->latitude.udeg == 0 && dive->longitude.udeg == 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
put_format(b, "temp = new google.maps.Marker({position: new google.maps.LatLng(%f,%f)});\n",
|
put_format(b, "temp = new google.maps.Marker({position: new google.maps.LatLng(%f,%f)});\n",
|
||||||
dive->latitude.udeg/1000000.0, dive->longitude.udeg/1000000.0);
|
dive->latitude.udeg/1000000.0, dive->longitude.udeg/1000000.0);
|
||||||
|
@ -100,9 +148,8 @@ void export_worldmap_HTML(const char* file_name)
|
||||||
export(&buf);
|
export(&buf);
|
||||||
|
|
||||||
f = fopen(file_name, "w+");
|
f = fopen(file_name, "w+");
|
||||||
if (!f) {
|
if (!f)
|
||||||
printf("error"); /*report error*/
|
printf("error"); /*report error*/
|
||||||
}
|
|
||||||
|
|
||||||
flush_buffer(&buf, f); /*check for writing errors? */
|
flush_buffer(&buf, f); /*check for writing errors? */
|
||||||
free_buffer(&buf);
|
free_buffer(&buf);
|
||||||
|
|
Loading…
Add table
Reference in a new issue