constexpr int c_trimSize = 1024;
constexpr int c_maxBufSize = 5;
-static char *trim_string(const char *s, char *out, int maxlen)
+static char* trim_string(const char* s, char* out, int maxlen)
/*
* Returns a pointer to a static area which contains a copy
* of s without leading or trailing spaces. Strings are
{
int len, i;
- if (strlen(s) > static_cast<size_t>(maxlen-1))
+ if (strlen(s) > static_cast<size_t>(maxlen - 1))
{
- gmx_fatal(FARGS, "String '%s' (%zu) is longer than buffer (%d).\n",
- s, strlen(s), maxlen-1);
+ gmx_fatal(FARGS, "String '%s' (%zu) is longer than buffer (%d).\n", s, strlen(s), maxlen - 1);
}
- for (; (*s) == ' '; s++)
- {
- ;
- }
+ for (; (*s) == ' '; s++) {}
for (len = strlen(s); (len > 0); len--)
{
- if (s[len-1] != ' ')
+ if (s[len - 1] != ' ')
{
break;
}
}
if (len >= c_trimSize)
{
- len = c_trimSize-1;
+ len = c_trimSize - 1;
}
for (i = 0; i < len; i++)
{
return out;
}
-int lookup_symtab(t_symtab *symtab, char **name)
+int lookup_symtab(t_symtab* symtab, char** name)
{
int base;
- t_symbuf *symbuf;
+ t_symbuf* symbuf;
base = 0;
symbuf = symtab->symbuf;
while (symbuf != nullptr)
{
- const int index = name-symbuf->buf;
- if ( ( index >= 0 ) && ( index < symbuf->bufsize ) )
+ const int index = name - symbuf->buf;
+ if ((index >= 0) && (index < symbuf->bufsize))
{
- return index+base;
+ return index + base;
}
else
{
- base += symbuf->bufsize;
+ base += symbuf->bufsize;
symbuf = symbuf->next;
}
}
gmx_fatal(FARGS, "symtab lookup \"%s\" not found", *name);
}
-char **get_symtab_handle(t_symtab *symtab, int name)
+char** get_symtab_handle(t_symtab* symtab, int name)
{
- t_symbuf *symbuf;
+ t_symbuf* symbuf;
symbuf = symtab->symbuf;
while (symbuf != nullptr)
}
else
{
- name -= symbuf->bufsize;
+ name -= symbuf->bufsize;
symbuf = symbuf->next;
}
}
gmx_fatal(FARGS, "symtab get_symtab_handle %d not found", name);
}
-static t_symbuf *new_symbuf()
+static t_symbuf* new_symbuf()
{
- t_symbuf *symbuf;
+ t_symbuf* symbuf;
snew(symbuf, 1);
symbuf->bufsize = c_maxBufSize;
return symbuf;
}
-static char **enter_buf(t_symtab *symtab, char *name)
+static char** enter_buf(t_symtab* symtab, char* name)
{
- int i;
- t_symbuf *symbuf;
- gmx_bool bCont;
+ int i;
+ t_symbuf* symbuf;
+ gmx_bool bCont;
if (symtab->symbuf == nullptr)
{
{
bCont = FALSE;
}
- }
- while (bCont);
+ } while (bCont);
symbuf->next = new_symbuf();
symbuf = symbuf->next;
return &(symbuf->buf[0]);
}
-char **put_symtab(t_symtab *symtab, const char *name)
+char** put_symtab(t_symtab* symtab, const char* name)
{
char buf[1024];
return enter_buf(symtab, trim_string(name, buf, 1023));
}
-void open_symtab(t_symtab *symtab)
+void open_symtab(t_symtab* symtab)
{
symtab->nr = 0;
symtab->symbuf = nullptr;
}
-void close_symtab(t_symtab gmx_unused *symtab)
-{
-}
+void close_symtab(t_symtab gmx_unused* symtab) {}
// TODO this will go away when we use a
// std::list<std::vector<std::string>>> for t_symtab.
-t_symtab *duplicateSymtab(const t_symtab *symtab)
+t_symtab* duplicateSymtab(const t_symtab* symtab)
{
- t_symtab *copySymtab;
+ t_symtab* copySymtab;
snew(copySymtab, 1);
open_symtab(copySymtab);
- t_symbuf *symbuf = symtab->symbuf;
+ t_symbuf* symbuf = symtab->symbuf;
if (symbuf != nullptr)
{
snew(copySymtab->symbuf, 1);
}
- t_symbuf *copySymbuf = copySymtab->symbuf;
+ t_symbuf* copySymbuf = copySymtab->symbuf;
while (symbuf != nullptr)
{
snew(copySymbuf->buf, symbuf->bufsize);
return copySymtab;
}
-void done_symtab(t_symtab *symtab)
+void done_symtab(t_symtab* symtab)
{
int i;
t_symbuf *symbuf, *freeptr;
}
}
-void free_symtab(t_symtab *symtab)
+void free_symtab(t_symtab* symtab)
{
t_symbuf *symbuf, *freeptr;
while (symbuf != nullptr)
{
symtab->nr -= std::min(symbuf->bufsize, symtab->nr);
- freeptr = symbuf;
- symbuf = symbuf->next;
+ freeptr = symbuf;
+ symbuf = symbuf->next;
sfree(freeptr);
}
symtab->symbuf = nullptr;
}
}
-void pr_symtab(FILE *fp, int indent, const char *title, t_symtab *symtab)
+void pr_symtab(FILE* fp, int indent, const char* title, t_symtab* symtab)
{
int i, j, nr;
- t_symbuf *symbuf;
+ t_symbuf* symbuf;
if (available(fp, symtab, indent, title))
{
for (j = 0; (j < symbuf->bufsize) && (j < nr); j++)
{
pr_indent(fp, indent);
- (void) fprintf(fp, "%s[%d]=\"%s\"\n", title, i++, symbuf->buf[j]);
+ (void)fprintf(fp, "%s[%d]=\"%s\"\n", title, i++, symbuf->buf[j]);
}
- nr -= j;
+ nr -= j;
symbuf = symbuf->next;
}
if (nr != 0)