aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2021-11-21 18:16:07 -0800
committerTrumeet <yuuta@yuuta.moe>2021-11-21 18:16:07 -0800
commit7b0205a20a6bfcae8ae9090b3a544bdd2c691a05 (patch)
tree01d101b735a6d873b3dcff00d3487c400f792ccc
parent265c8542c4710a73fb278339d8485daac81ceea3 (diff)
downloadmcal-7b0205a20a6bfcae8ae9090b3a544bdd2c691a05.tar
mcal-7b0205a20a6bfcae8ae9090b3a544bdd2c691a05.tar.gz
mcal-7b0205a20a6bfcae8ae9090b3a544bdd2c691a05.tar.bz2
mcal-7b0205a20a6bfcae8ae9090b3a544bdd2c691a05.zip
refactor(expvc/common): move common structs and functions to common.h
-rw-r--r--Makefile1
-rw-r--r--common.h48
-rw-r--r--expvc.c44
3 files changed, 50 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index f53dfc5..45abb28 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
.POSIX:
+CFLAGS += -I.
CFLAGS += -std=c99
CFLAGS += -Wall
LDLIBS += -lm
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..30620fd
--- /dev/null
+++ b/common.h
@@ -0,0 +1,48 @@
+#ifndef _COMMON_H
+#define _COMMON_H
+
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+
+struct vec3d {
+ double x;
+ double y;
+ double z;
+};
+
+static int vec3d_parse(char *in, struct vec3d *out)
+{
+ int i = 0;
+ char *p = strtok(in, ",");
+ while (p != NULL)
+ {
+ double *ptr;
+ switch (i ++)
+ {
+ case 0:
+ ptr = &out->x;
+ break;
+ case 1:
+ ptr = &out->y;
+ break;
+ case 2:
+ ptr = &out->z;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ sscanf(p, "%lf", ptr);
+ p = strtok(NULL, ",");
+ }
+ if (i != 3)
+ {
+ fprintf(stderr, "Invalid Vec3D: %s. Example: -1,1,1.\n", in);
+ return 64;
+ }
+ return 0;
+}
+
+#endif /* _COMMON_H */
diff --git a/expvc.c b/expvc.c
index 96e0d14..dc7637f 100644
--- a/expvc.c
+++ b/expvc.c
@@ -4,49 +4,7 @@
* @1.17.1
*
*/
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-#include <math.h>
-
-struct vec3d {
- double x;
- double y;
- double z;
-};
-
-static int vec3d_parse(char *in, struct vec3d *out)
-{
- int i = 0;
- char *p = strtok(in, ",");
- while (p != NULL)
- {
- double *ptr;
- switch (i ++)
- {
- case 0:
- ptr = &out->x;
- break;
- case 1:
- ptr = &out->y;
- break;
- case 2:
- ptr = &out->z;
- break;
- default:
- assert(0);
- break;
- }
- sscanf(p, "%lf", ptr);
- p = strtok(NULL, ",");
- }
- if (i != 3)
- {
- fprintf(stderr, "Invalid Vec3D: %s. Example: -1,1,1.\n", in);
- return 64;
- }
- return 0;
-}
+#include "common.h"
int main(int argc, char **argv)
{