Skip to content

Commit

Permalink
- fix some typos in strings
Browse files Browse the repository at this point in the history
- fixed calculation of escaped string length
- optimized some string operations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15758 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Apr 8, 2013
1 parent baeebde commit e344a6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions SimulationRuntime/c/util/modelica_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ modelica_string_const modelica_real_to_modelica_string_format(modelica_real r,mo
char formatStr[40];
char buf[400];
formatStr[0]='%';
sprintf(&formatStr[1], "%s", format);
strcpy(&formatStr[1], format);
sprintf(buf,formatStr,r);
return init_modelica_string(buf);
}
Expand All @@ -63,7 +63,7 @@ modelica_string_const modelica_integer_to_modelica_string_format(modelica_intege
char formatStr[40];
char buf[400];
formatStr[0]='%';
sprintf(&formatStr[1], "%s", format);
strcpy(&formatStr[1], format);
sprintf(buf,formatStr,i);
return init_modelica_string(buf);
}
Expand All @@ -73,14 +73,14 @@ modelica_string_const modelica_string_to_modelica_string_format(modelica_string_
char formatStr[40];
char buf[4000];
formatStr[0]='%';
sprintf(&formatStr[1], "%s", format);
strcpy(&formatStr[1], format);
sprintf(buf,formatStr,s);
return init_modelica_string(buf);
}

/* Convert a modelica_integer to a modelica_string, used in String(i) */

modelica_string_const modelica_integer_to_modelica_string(modelica_integer i, modelica_integer minLen,modelica_boolean leftJustified)
modelica_string_const modelica_integer_to_modelica_string(modelica_integer i, modelica_integer minLen, modelica_boolean leftJustified)
{
char formatStr[40];
char buf[400];
Expand Down Expand Up @@ -134,9 +134,7 @@ modelica_string_const init_modelica_string(modelica_string_const str)
int i;
int length = strlen(str);
modelica_string_t dest = alloc_modelica_string(length);
for(i = 0; i<length; ++i) {
dest[i] = str[i];
}
memcpy(dest, str, length);
return dest;
}

Expand All @@ -151,19 +149,20 @@ modelica_string_t alloc_modelica_string(int length)

void free_modelica_string(modelica_string_t* a)
{
int length;
/* int length; */

assert(modelica_string_ok(a));

length = modelica_string_length(*a);
/* length = modelica_string_length(*a); */
/* Free also null terminator.*/
/* free(a); */ /* char_free(length+1); */
}

modelica_string_const copy_modelica_string(modelica_string_const source)
{
modelica_string_t dest = alloc_modelica_string(modelica_string_length(source));
memcpy(dest, source, modelica_string_length(source)+1);
int len = strlen(source);
modelica_string_t dest = alloc_modelica_string(len);
memcpy(dest, source, len);
return dest;
}

Expand All @@ -174,7 +173,7 @@ modelica_string_const cat_modelica_string(modelica_string_const s1, modelica_str
int len2 = modelica_string_length(s2);
dest = alloc_modelica_string(len1+len2);
memcpy(dest, s1, len1);
memcpy(dest + len1, s2, len2 + 1);
memcpy(dest + len1, s2, len2);
return dest;
}

Expand All @@ -188,11 +187,12 @@ extern int omc__escapedStringLength(const char* str, int nl)
case '\a':
case '\b':
case '\f':
case '\v': i++;
case '\r': i++; if(nl && str[1] == '\n') str++;
case '\n': i++; if(nl && str[1] == '\r') str++;
default: i++;
case '\v': i++; break;
case '\r': if(nl) {i++; if(str[1] == '\n') str++;} break;
case '\n': if(nl) {i++; if(str[1] == '\r') str++;} break;
default: break;
}
i++;
str++;
}
return i;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/util/omc_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const char *LOG_STREAM_DESC[LOG_MAX] = {
"additional information about dassl solver", /* LOG_DDASRT */
"additional debug information", /* LOG_DEBUG */
"outputs information about dynamic state selection", /* LOG_DSS */
"outputs jacobain of the dynamic state selection", /* LOG_DSS_JAC */
"outputs jacobian of the dynamic state selection", /* LOG_DSS_JAC */
"additional information during event iteration", /* LOG_EVENTS */
"verbose logging of event system", /* LOG_EVENTS_V */
"additional information during initialization", /* LOG_INIT */
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/util/simulation_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_CLOCK */ "selects the type of clock to use -clock=RT or -clock=CPU",
/* FLAG_CPU */ "dumps the cpu-time into the results-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag",
/* FLAG_HELP */ "get detailed information that specifies the command-line flag",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method",
/* FLAG_IIT */ "[double] value specifies a time for the initialization of the model",
Expand Down Expand Up @@ -96,7 +96,7 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
/* FLAG_CLOCK */ "selects the type of clock to use -clock=RT or -clock=CPU\n RT=monotonic real-time clock, CPU=process-based CPU-time",
/* FLAG_CPU */ " - dumps the cpu-time into the result-file\n - $cpuTime is the variable name inside the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag\n e.g. -help=f prints detaild information for command-line flag f",
/* FLAG_HELP */ "get detailed information that specifies the command-line flag\n e.g. -help=f prints detailed information for command-line flag f",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method\n none\n numeric\n symbolic",
/* FLAG_IIT */ "value specifies a time for the initialization of the model",
Expand Down

0 comments on commit e344a6c

Please sign in to comment.