Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/cgram cgram: indent



details:   https://anonhg.NetBSD.org/src/rev/8ac71806fd72
branches:  trunk
changeset: 980898:8ac71806fd72
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 21 15:41:04 2021 +0000

description:
cgram: indent

With manual corrections afterwards:

- indent removes empty lines between statement and declaration.  This
  had been a syntax error in C90, since C99 this is common style and
  should be accepted by indent.

- indent didn't format the first line of main for whatever reason, did
  that manually.

- indent removed the empty line above the '/////' separators.  It should
  have left these empty lines as-is.

diffstat:

 games/cgram/cgram.c |  522 +++++++++++++++++++++++++++------------------------
 1 files changed, 273 insertions(+), 249 deletions(-)

diffs (truncated from 587 to 300 lines):

diff -r e6464c383a29 -r 8ac71806fd72 games/cgram/cgram.c
--- a/games/cgram/cgram.c       Sun Feb 21 15:02:16 2021 +0000
+++ b/games/cgram/cgram.c       Sun Feb 21 15:41:04 2021 +0000
@@ -1,3 +1,5 @@
+/* $NetBSD */
+
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -39,40 +41,48 @@
 
 ////////////////////////////////////////////////////////////
 
-static char *xstrdup(const char *s) {
-   char *ret;
+static char *
+xstrdup(const char *s)
+{
+       char *ret;
 
-   ret = malloc(strlen(s) + 1);
-   if (ret == NULL) {
-      errx(1, "Out of memory");
-   }
-   strcpy(ret, s);
-   return ret;
+       ret = malloc(strlen(s) + 1);
+       if (ret == NULL) {
+               errx(1, "Out of memory");
+       }
+       strcpy(ret, s);
+       return ret;
 }
 
 ////////////////////////////////////////////////////////////
 
 struct stringarray {
-   char **v;
-   int num;
+       char **v;
+       int num;
 };
 
-static void stringarray_init(struct stringarray *a) {
-   a->v = NULL;
-   a->num = 0;
+static void
+stringarray_init(struct stringarray *a)
+{
+       a->v = NULL;
+       a->num = 0;
 }
 
-static void stringarray_cleanup(struct stringarray *a) {
-   free(a->v);
+static void
+stringarray_cleanup(struct stringarray *a)
+{
+       free(a->v);
 }
 
-static void stringarray_add(struct stringarray *a, const char *s) {
-   a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0]));
-   if (a->v == NULL) {
-      errx(1, "Out of memory");
-   }
-   a->v[a->num] = xstrdup(s);
-   a->num++;
+static void
+stringarray_add(struct stringarray *a, const char *s)
+{
+       a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0]));
+       if (a->v == NULL) {
+               errx(1, "Out of memory");
+       }
+       a->v[a->num] = xstrdup(s);
+       a->num++;
 }
 
 ////////////////////////////////////////////////////////////
@@ -84,265 +94,279 @@
 static unsigned curx;
 static int cury;
 
-static void readquote(void) {
-   FILE *f = popen(_PATH_FORTUNE, "r");
-   if (!f) {
-      err(1, "%s", _PATH_FORTUNE);
-   }
+static void
+readquote(void)
+{
+       FILE *f = popen(_PATH_FORTUNE, "r");
+       if (!f) {
+               err(1, "%s", _PATH_FORTUNE);
+       }
 
-   char buf[128], buf2[8*sizeof(buf)];
-   while (fgets(buf, sizeof(buf), f)) {
-      char *s = strrchr(buf, '\n');
-      assert(s);
-      assert(strlen(s)==1);
-      *s = 0;
+       char buf[128], buf2[8 * sizeof(buf)];
+       while (fgets(buf, sizeof(buf), f)) {
+               char *s = strrchr(buf, '\n');
+               assert(s);
+               assert(strlen(s) == 1);
+               *s = 0;
 
-      int i,j;
-      for (i=j=0; buf[i]; i++) {
-        if (buf[i]=='\t') {
-           buf2[j++] = ' ';
-           while (j%8) buf2[j++] = ' ';
-        }
-        else if (buf[i]=='\b') {
-           if (j>0) j--;
-        }
-        else {
-           buf2[j++] = buf[i];
-        }
-      }
-      buf2[j] = 0;
+               int i, j;
+               for (i = j = 0; buf[i]; i++) {
+                       if (buf[i] == '\t') {
+                               buf2[j++] = ' ';
+                               while (j % 8)
+                                       buf2[j++] = ' ';
+                       } else if (buf[i] == '\b') {
+                               if (j > 0)
+                                       j--;
+                       } else {
+                               buf2[j++] = buf[i];
+                       }
+               }
+               buf2[j] = 0;
 
-      stringarray_add(&lines, buf2);
-      stringarray_add(&sollines, buf2);
-   }
+               stringarray_add(&lines, buf2);
+               stringarray_add(&sollines, buf2);
+       }
 
-   pclose(f);
+       pclose(f);
 }
 
-static void encode(void) {
-   int key[26];
-   for (int i=0; i<26; i++) key[i] = i;
-   for (int i=26; i>1; i--) {
-      int c = random() % i;
-      int t = key[i-1];
-      key[i-1] = key[c];
-      key[c] = t;
-   }
+static void
+encode(void)
+{
+       int key[26];
+       for (int i = 0; i < 26; i++)
+               key[i] = i;
+       for (int i = 26; i > 1; i--) {
+               int c = random() % i;
+               int t = key[i - 1];
+               key[i - 1] = key[c];
+               key[c] = t;
+       }
 
-   for (int y=0; y<lines.num; y++) {
-      for (unsigned x=0; lines.v[y][x]; x++) {
-        if (islower((unsigned char)lines.v[y][x])) {
-           int q = lines.v[y][x]-'a';
-           lines.v[y][x] = 'a'+key[q];
-        }
-        if (isupper((unsigned char)lines.v[y][x])) {
-           int q = lines.v[y][x]-'A';
-           lines.v[y][x] = 'A'+key[q];
-        }
-      }
-   }
+       for (int y = 0; y < lines.num; y++) {
+               for (unsigned x = 0; lines.v[y][x]; x++) {
+                       if (islower((unsigned char)lines.v[y][x])) {
+                               int q = lines.v[y][x] - 'a';
+                               lines.v[y][x] = 'a' + key[q];
+                       }
+                       if (isupper((unsigned char)lines.v[y][x])) {
+                               int q = lines.v[y][x] - 'A';
+                               lines.v[y][x] = 'A' + key[q];
+                       }
+               }
+       }
 }
 
-static int substitute(int ch) {
-   assert(cury>=0 && cury<lines.num);
-   if (curx >= strlen(lines.v[cury])) {
-      beep();
-      return -1;
-   }
+static int
+substitute(int ch)
+{
+       assert(cury >= 0 && cury < lines.num);
+       if (curx >= strlen(lines.v[cury])) {
+               beep();
+               return -1;
+       }
 
-   int och = lines.v[cury][curx];
-   if (!isalpha((unsigned char)och)) {
-      beep();
-      return -1;
-   }
-
-   int loch = tolower((unsigned char)och);
-   int uoch = toupper((unsigned char)och);
-   int lch = tolower((unsigned char)ch);
-   int uch = toupper((unsigned char)ch);
+       int och = lines.v[cury][curx];
+       if (!isalpha((unsigned char)och)) {
+               beep();
+               return -1;
+       }
 
-   for (int y=0; y<lines.num; y++) {
-      for (unsigned x=0; lines.v[y][x]; x++) {
-        if (lines.v[y][x]==loch) {
-           lines.v[y][x] = lch;
-        }
-        else if (lines.v[y][x]==uoch) {
-           lines.v[y][x] = uch;
-        }
-        else if (lines.v[y][x]==lch) {
-           lines.v[y][x] = loch;
-        }
-        else if (lines.v[y][x]==uch) {
-           lines.v[y][x] = uoch;
-        }
-      }
-   }
-   return 0;
+       int loch = tolower((unsigned char)och);
+       int uoch = toupper((unsigned char)och);
+       int lch = tolower((unsigned char)ch);
+       int uch = toupper((unsigned char)ch);
+
+       for (int y = 0; y < lines.num; y++) {
+               for (unsigned x = 0; lines.v[y][x]; x++) {
+                       if (lines.v[y][x] == loch) {
+                               lines.v[y][x] = lch;
+                       } else if (lines.v[y][x] == uoch) {
+                               lines.v[y][x] = uch;
+                       } else if (lines.v[y][x] == lch) {
+                               lines.v[y][x] = loch;
+                       } else if (lines.v[y][x] == uch) {
+                               lines.v[y][x] = uoch;
+                       }
+               }
+       }
+       return 0;
 }
 
 ////////////////////////////////////////////////////////////
 
-static void redraw(void) {
-   erase();
-   bool won = true;
-   for (int i=0; i<LINES-1; i++) {
-      move(i, 0);
-      int ln = i+scrolldown;
-      if (ln < lines.num) {
-        for (unsigned j=0; lines.v[i][j]; j++) {
-           int ch = lines.v[i][j];
-           if (ch != sollines.v[i][j] && isalpha((unsigned char)ch)) {
-              won = false;
-           }
-           bool bold=false;
-           if (hinting && ch==sollines.v[i][j] &&
-               isalpha((unsigned char)ch)) {
-              bold = true;
-              attron(A_BOLD);
-           }
-           addch(lines.v[i][j]);
-           if (bold) {
-              attroff(A_BOLD);
-           }
-        }
-      }
-      clrtoeol();
-   }
+static void
+redraw(void)
+{
+       erase();
+       bool won = true;



Home | Main Index | Thread Index | Old Index