]> andersk Git - moira.git/blobdiff - gen/network.pc
Code style cleanup. (No functional changes)
[moira.git] / gen / network.pc
index 655e1797056ad4b772fa7c70f5c23f151df0cc24..3bbc8bbb666c2c0c27e8813e1434ecdd975a0617 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <mit-copyright.h>
+#include <errno.h>
 #include <stdio.h>
 #include <moira.h>
 #include <sys/types.h>
 
 EXEC SQL INCLUDE sqlca;
 
-extern int errno;
 char *whoami = "network.gen";
 char *db = "moira/moira";
 
-main(argc, argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
 {
-    FILE *out = stdout;
-    char *outf = NULL, outft[64], *p, buf[256];
-    struct stat sb;
-    struct timeval now;
-    struct in_addr addr;
-    int flag1, i;
-    EXEC SQL BEGIN DECLARE SECTION;
-    int id, saddr;
-    char name[65], description[65];
-    EXEC SQL END DECLARE SECTION;
+  FILE *out = stdout;
+  char *outf = NULL, outft[64], *p, buf[256];
+  struct stat sb;
+  struct timeval now;
+  struct in_addr addr;
+  int flag1, i;
+  EXEC SQL BEGIN DECLARE SECTION;
+  int id, saddr;
+  char name[65], description[65];
+  EXEC SQL END DECLARE SECTION;
 
-    EXEC SQL CONNECT :db;
+  EXEC SQL CONNECT :db;
 
-    if (argc == 2) { 
-       if (stat(argv[1], &sb) == 0) { 
-           if (ModDiff(&flag1, "subnet", sb.st_mtime))
-             exit(MR_DATE);
-           if (flag1 < 0) {
-               fprintf(stderr, "File %s does not need to be rebuilt.\n",
-                       argv[1]);
-               exit(MR_NO_CHANGE);
-           } 
+  if (argc == 2)
+    {
+      if (stat(argv[1], &sb) == 0)
+       {
+         if (ModDiff(&flag1, "subnet", sb.st_mtime))
+           exit(MR_DATE);
+         if (flag1 < 0)
+           {
+             fprintf(stderr, "File %s does not need to be rebuilt.\n",
+                     argv[1]);
+             exit(MR_NO_CHANGE);
+           }
        }
-       outf = argv[1];
-       sprintf(outft, "%s~", outf);
-       if ((out = fopen(outft, "w")) == NULL) {
-           fprintf(stderr, "unable to open %s for output\n", outf);
-           exit(MR_OCONFIG);
+      outf = argv[1];
+      sprintf(outft, "%s~", outf);
+      if (!(out = fopen(outft, "w")))
+       {
+         fprintf(stderr, "unable to open %s for output\n", outf);
+         exit(MR_OCONFIG);
        }
-    } else if (argc != 1) {
-       fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
-       exit(MR_ARGS);
-    } else {
-       outf = NULL;
     }
+  else if (argc != 1)
+    {
+      fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
+      exit(MR_ARGS);
+    }
+  else
+    outf = NULL;
+
+  EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
 
-    EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
+  gettimeofday(&now, NULL);
 
-    gettimeofday(&now, NULL);
-    
-    fprintf(out, "; MIT Network Table\n;\n");
-    fprintf(out, "; \t%cAuthor: $\n", '$');
-    fprintf(out, "; \t%cDate: $\n", '$');
-    fprintf(out, "; \t%cRevision: $\n;\n", '$');
-    fprintf(out, "; Network table generated by Moira at %s;\n",
-           ctime(&now.tv_sec));
+  fprintf(out, "; MIT Network Table\n;\n");
+  fprintf(out, "; \t%cAuthor: $\n", '$');
+  fprintf(out, "; \t%cDate: $\n", '$');
+  fprintf(out, "; \t%cRevision: $\n;\n", '$');
+  fprintf(out, "; Network table generated by Moira at %s;\n",
+         ctime(&now.tv_sec));
 
-    EXEC SQL DECLARE x CURSOR FOR SELECT 
-      name, snet_id, saddr, description
-      FROM subnet ORDER BY saddr;
-    EXEC SQL OPEN x;
-    while (1) {
-       EXEC SQL FETCH x INTO :name, :id, :saddr, :description;
-       if (sqlca.sqlcode != 0) break;
-       if (id == 0) continue;
-       if (*strtrim(name) == 0) continue;
-       addr.s_addr=htonl(saddr);
-       fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name,
-               inet_ntoa(addr), 
-          strtrim(description));
+  EXEC SQL DECLARE x CURSOR FOR SELECT
+    name, snet_id, saddr, description
+    FROM subnet ORDER BY saddr;
+  EXEC SQL OPEN x;
+  while (1)
+    {
+      EXEC SQL FETCH x INTO :name, :id, :saddr, :description;
+      if (sqlca.sqlcode)
+       break;
+      if (id == 0)
+       continue;
+      if (!*strtrim(name))
+       continue;
+      addr.s_addr = htonl(saddr);
+      fprintf(out, "NETWORK : %-16.16s : %-12.12s : %s\n", name,
+             inet_ntoa(addr), strtrim(description));
     }
 
-    EXEC SQL CLOSE x;
+  EXEC SQL CLOSE x;
 
-    EXEC SQL COMMIT;
+  EXEC SQL COMMIT;
 
-    fprintf(out, "; End of automatically generated network table\n");
-    if (fclose(out)) {
-       perror("close failed");
-       exit(MR_CCONFIG);
+  fprintf(out, "; End of automatically generated network table\n");
+  if (fclose(out))
+    {
+      perror("close failed");
+      exit(MR_CCONFIG);
     }
-    if (outf)
-      fix_file(outf);
-    exit(MR_SUCCESS);
+  if (outf)
+    fix_file(outf);
+  exit(MR_SUCCESS);
 
- sqlerr:
-    db_error(sqlca.sqlcode);
-    exit(MR_DBMS_ERR);
+sqlerr:
+  db_error(sqlca.sqlcode);
+  exit(MR_DBMS_ERR);
 }
This page took 0.04793 seconds and 4 git commands to generate.