Commits

Chad Perrin  committed d6fea57

adding ini parsing routines

  • Participants
  • Parent commits 213ef0a

Comments (0)

Files changed (1)

 #include <string.h>
 #include <unistd.h>
 
+#include <iniparser.h>
+
 static char interfaces_fname[] = "/etc/network/interfaces";
 
 static char minterfaces[] = "auto lo\niface lo inet loopback\n\n"
 	printf("OR OTHER DEALINGS IN THE WORK.\n\n");
 }
 
+
+/*
+
+   The following ini file routines require the iniparser library.
+
+   iniparser site: http://ndevilla.free.fr/iniparser/
+   iniparser docs: http://ndevilla.free.fr/iniparser/html/index.html
+   iniparser repo: https://github.com/ndevilla/iniparser
+
+   iniparser license: Copyfree Initiative Certified MIT/X11 License
+
+   So far, these functions are not actually used by nw.
+
+*/
+
+/* begin ini file routines */
+
+void create_net_file(void) {
+	FILE * ini;
+
+	ini = fopen("net.ini", "w");
+	fprintf(
+		ini,
+		"[Home]\n"
+		"description = Home network\n"
+		"interface	 = wlan0\n"
+		"wpa-ssid	 = foo\n"
+		"wpa-psk	 = deadbeef\n"
+	);
+	fclose(ini);
+}
+
+void create_nw_file(void) {
+	FILE * ini;
+
+	ini = fopen("nw.ini", "w");
+	fprintf(
+		ini,
+		"[OS]\n"
+		"name		 = Debian\n"
+	);
+	fclose(ini);
+}
+
+int parse_ini_file(char * ini_name) {
+	dictionary * ini;
+
+	ini = iniparser_load(ini_name);
+	if (ini == NULL) {
+		fprintf(stderr, "cannot parse file: %s\n", ini_name);
+		return -1;
+	}
+	iniparser_dump(ini, stderr);
+
+	iniparser_freedict(ini);
+	return 0;
+}
+
+/* end ini file routines */
+
+
 int cmd_kill() {
 	system("ifdown wlan0");
 	return 0;