From: phfr24 Date: Sun, 24 May 2026 16:03:19 +0000 (-0300) Subject: formatting and portability X-Git-Url: https://git.wirehaze.ovh/graph-theory.git/commitdiff_plain/d8af4076c2a05a741d1218ba850ff7f288ad267c?ds=sidebyside formatting and portability --- diff --git a/graph/adj.h b/graph/adj.h index 2ec54a3..86381f9 100644 --- a/graph/adj.h +++ b/graph/adj.h @@ -19,7 +19,7 @@ struct edge /* probably not a good name for this */ struct graph { struct vertex *v; /* array of vertices */ - unsigned int nv; /* number of vertices */ + unsigned int nv; /* number of vertices */ }; struct graph *new_graph (unsigned int nv); diff --git a/gt.c b/gt.c index 0013cf9..a3c112a 100644 --- a/gt.c +++ b/gt.c @@ -1,10 +1,10 @@ #define _GNU_SOURCE +#include "graph/adj.h" +#include "graph/dfs.h" +#include "lib/dbg.h" #include #include #include -#include "lib/dbg.h" -#include "graph/adj.h" -#include "graph/dfs.h" #define bfs dfs /* stub until tomorrow */ @@ -67,11 +67,9 @@ main (int argc, char **argv) unsigned int nv, u, v; int i; - static struct option long_opts[] = { - {"dfs", no_argument, 0, 'd'}, - {"bfs", no_argument, 0, 'b'}, - {0, 0, 0, 0} - }; + static struct option long_opts[] = { { "dfs", no_argument, 0, 'd' }, + { "bfs", no_argument, 0, 'b' }, + { 0, 0, 0, 0 } }; while ((c = getopt_long (argc, argv, "db", long_opts, NULL)) != -1) { @@ -84,7 +82,8 @@ main (int argc, char **argv) a = ALGO_BFS; break; default: - fprintf (stderr, "Usage: %s [--dfs|--bfs] [u1 v1 ...]\n", argv[0]); + fprintf (stderr, "Usage: %s [--dfs|--bfs] [u1 v1 ...]\n", + argv[0]); exit (EXIT_FAILURE); } } @@ -95,14 +94,14 @@ main (int argc, char **argv) if (optind >= argc) fatal ("missing number of vertices"); - nv = (unsigned int) atoi (argv[optind]); + nv = (unsigned int)atoi (argv[optind]); if (!(g = new_graph (nv))) fatal ("new_graph ()"); for (i = optind + 1; i < argc - 1; i += 2) { - u = (unsigned int) atoi (argv[i]); - v = (unsigned int) atoi (argv[i + 1]); + u = (unsigned int)atoi (argv[i]); + v = (unsigned int)atoi (argv[i + 1]); if (add_edge (g, u, v)) fatal ("add_edge ()"); } diff --git a/lib/dbg.h b/lib/dbg.h index 422c681..8e34e51 100644 --- a/lib/dbg.h +++ b/lib/dbg.h @@ -12,7 +12,7 @@ do \ { \ fprintf (stderr, "(%s:%d) %s () failed: %s errno: %s\n", __FILE__, \ - __LINE__, __func__, x, strerror (errno)); \ + __LINE__, __extension__ __func__, x, strerror (errno)); \ exit (EXIT_FAILURE); \ } \ while (0)