+ if(argc > 1) {
+ struct stat s;
+ if(stat(argv[1], &s)) {
+ fprintf(stderr, "Cannot open file: %s\n", argv[1]);
+ perror("");
+ return 1;
+ }
+ open_file_arg = argv[1];
+ }
+
+ // load settings
+ if(load_config()) {
+ return 1;
+ }
+
+ // try single instance open
+ if(open_file_arg) {
+ char *instance_path = InstanceFilePath(display);
+ int instance_fd = ConnectToInstance(instance_path);
+ free(instance_path);
+
+ if(instance_fd >= 0) {
+ write(instance_fd, "open ", 5);
+ write(instance_fd, open_file_arg, strlen(open_file_arg));
+ write(instance_fd, "\n", 1);
+ close(instance_fd);
+ return 0;
+ }
+ }
+