💾 Archived View for gmi.noulin.net › gitRepositories › systemSetup › file › dotfiles › vop.c.gmi captured on 2024-07-09 at 02:59:56. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
vop.c (985B)
1 #! /usr/bin/env sheepy 2 #include "libsheepyObject.h" 3 #include <unistd.h> 4 5 void open(char *s) { 6 if (hasG(s, ':')) { 7 var sp = splitG(s, ':'); 8 if (lenG(sp) > 1) { 9 systemf("vim %s +%s", sp[0], sp[1]); 10 } 11 freeG(sp); 12 } 13 else systemf("vim %s", s); 14 } 15 16 int main(int ARGC, char** ARGV) { 17 18 if (ARGC > 1) { 19 open(ARGV[1]); 20 } 21 else { 22 // no arguments 23 // check stdin 24 25 // input string 26 char *s = NULL; 27 28 // read all the data from stdin to s 29 fd_set readfds; 30 FD_ZERO(&readfds); 31 FD_SET(STDIN_FILENO, &readfds); 32 33 struct timeval timeout; 34 timeout.tv_sec = 0; 35 timeout.tv_usec = 0; 36 37 int chr; 38 39 int sel_rv = select(1, &readfds, NULL, NULL, &timeout); 40 if (sel_rv > 0) { 41 while ((chr = getchar()) != EOF) appendG(&s,chr); 42 } else if (sel_rv == -1) { 43 perror("select failed"); 44 } 45 46 //logVarG(s); 47 if (isEmptyG(s)) { 48 XSUCCESS; 49 } 50 51 open(s); 52 free(s); 53 } 54 55 } 56 // vim: set expandtab ts=2 sw=2: