Run through clang-format.

This commit is contained in:
David Given 2018-06-23 23:46:44 +02:00
parent fd94e219d4
commit 205c8d0a35

View file

@ -41,18 +41,21 @@ int setval(int, char *);
int quoted(char**);
void DoFile(char*);
int
main(int argc, char *argv[])
int main(int argc, char* argv[])
{
ProgCall = *argv++;
argc--;
while (argc-- > 0) {
if (**argv == COMCOM) {
while (argc-- > 0)
{
if (**argv == COMCOM)
{
option(*argv++);
}
else {
if (! process(*argv++, InputForm)) {
else
{
if (!process(*argv++, InputForm))
{
exit(1);
}
}
@ -61,25 +64,25 @@ main(int argc, char *argv[])
/*NOTREACHED*/
}
char *
Salloc(char *s)
char* Salloc(char* s)
{
char* ns = strdup(s);
if (!ns) {
if (!ns)
{
fprintf(stderr, "%s: out of memory\n", ProgCall);
exit(1);
}
return ns;
}
void
option(char *str)
void option(char* str)
{
/* note that *str indicates the source of the option:
either COMCOM (from command line) or FILECOM (from a file).
*/
switch (*++str) {
switch (*++str)
{
case ' ': /* command */
case '\t':
@ -89,7 +92,8 @@ option(char *str)
InputForm = *++str;
break;
case 'f': /* input from file ... */
if (*++str == '\0') {
if (*++str == '\0')
{
fprintf(stderr, "%s: -f: name expected\n", ProgCall);
exit(1);
}
@ -108,20 +112,24 @@ option(char *str)
InitTable((char*)0);
break;
case 'i': /* initialize table with given value */
if (*++str == '\0') {
if (*++str == '\0')
{
InitTable((char*)0);
}
else InitTable(str);
else
InitTable(str);
break;
case 'S':
{
int i = atoi(++str);
if (i <= 0 || i > MAXTAB) {
if (i <= 0 || i > MAXTAB)
{
fprintf(stderr, "%s: size would exceed maximum\n",
ProgCall);
}
else {
else
{
TabSize = i;
}
break;
@ -131,8 +139,7 @@ option(char *str)
}
}
void
option_F(char *form)
void option_F(char* form)
{
int len;
char* cp;
@ -154,54 +161,60 @@ bad:
exit(1);
}
void
InitTable(char *ival)
void InitTable(char* ival)
{
int i;
for (i = 0; i < TabSize; i++) {
for (i = 0; i < TabSize; i++)
{
Table[i] = 0;
}
InitialValue = 0;
if (ival) {
if (ival)
{
InitialValue = Salloc(ival);
}
}
void
PrintTable(void)
void PrintTable(void)
{
int i;
for (i = 0; i < TabSize; i++) {
if (Table[i]) {
for (i = 0; i < TabSize; i++)
{
if (Table[i])
{
printf(OutputForm, Table[i]);
}
else if (InitialValue) {
else if (InitialValue)
{
printf(OutputForm, InitialValue);
}
else {
else
{
printf(OutputForm, "0");
}
}
}
int
process(char *str, int format)
int process(char* str, int format)
{
char* cstr = str;
char* Name = cstr; /* overwrite original string! */
/* strip of the entry name
*/
while (*str && *str != ':') {
if (*str == '\\') {
while (*str && *str != ':')
{
if (*str == '\\')
{
++str;
}
*cstr++ = *str++;
}
if (*str != ':') {
if (*str != ':')
{
fprintf(stderr, "%s: bad specification: \"%s\", ignored\n",
ProgCall, Name);
return 0;
@ -209,7 +222,8 @@ process(char *str, int format)
*cstr = '\0';
str++;
switch (format) {
switch (format)
{
case 'c':
return c_proc(str, Name);
@ -219,76 +233,91 @@ process(char *str, int format)
return 0;
}
int
c_proc(char *str, char *Name)
int c_proc(char* str, char* Name)
{
int ch, ch2;
char* name = Salloc(Name);
while (*str) {
if (*str == '\\') {
while (*str)
{
if (*str == '\\')
{
ch = quoted(&str);
}
else {
else
{
ch = *str++ & 0377;
}
if (*str == '-') {
if (*++str == '\\') {
if (*str == '-')
{
if (*++str == '\\')
{
ch2 = quoted(&str);
}
else {
else
{
ch2 = (*str++ & 0377);
if (!ch2) str--;
if (!ch2)
str--;
}
if (ch > ch2) {
if (ch > ch2)
{
fprintf(stderr, "%s: bad range\n", ProgCall);
return 0;
}
while (ch <= ch2) {
if (! setval(ch, name)) return 0;
while (ch <= ch2)
{
if (!setval(ch, name))
return 0;
ch++;
}
}
else {
if (! setval(ch, name)) return 0;
else
{
if (!setval(ch, name))
return 0;
}
}
return 1;
}
int
setval(int ch, char *nm)
int setval(int ch, char* nm)
{
char** p = &Table[ch];
if (ch < 0 || ch >= TabSize) {
if (ch < 0 || ch >= TabSize)
{
fprintf(stderr, "Illegal index: %d\n", ch);
return 0;
}
if (*(p = &Table[ch])) {
if (*(p = &Table[ch]))
{
fprintf(stderr, "Warning: redefinition of index %d\n", ch);
}
*p = nm;
return 1;
}
int
quoted(char **pstr)
int quoted(char** pstr)
{
int ch;
int i;
char* str = *pstr;
if ((*++str >= '0') && (*str <= '9')) {
if ((*++str >= '0') && (*str <= '9'))
{
ch = 0;
for (i = 0; i < 3; i++) {
for (i = 0; i < 3; i++)
{
ch = 8 * ch + (*str - '0');
if (*++str < '0' || *str > '9')
break;
}
}
else {
switch (*str++) {
else
{
switch (*str++)
{
case 'n':
ch = '\n';
break;
@ -316,18 +345,19 @@ quoted(char **pstr)
return ch & 0377;
}
char *
getln(char *s, int n, FILE *fp)
char* getln(char* s, int n, FILE* fp)
{
int c = getc(fp);
char* str = s;
while (n--) {
if (c == EOF) {
while (n--)
{
if (c == EOF)
{
return NULL;
}
else
if (c == '\n') {
else if (c == '\n')
{
*str++ = '\0';
return s;
}
@ -340,22 +370,26 @@ getln(char *s, int n, FILE *fp)
#define BUFSIZE 1024
void
DoFile(char *name)
void DoFile(char* name)
{
char text[BUFSIZE];
FILE* fp;
if ((fp = fopen(name, "r")) == NULL) {
if ((fp = fopen(name, "r")) == NULL)
{
fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name);
exit(1);
}
while (getln(text, BUFSIZE, fp) != NULL) {
if (text[0] == FILECOM) {
while (getln(text, BUFSIZE, fp) != NULL)
{
if (text[0] == FILECOM)
{
option(text);
}
else {
if (! process(text, InputForm)) {
else
{
if (!process(text, InputForm))
{
exit(1);
}
}