spicylord / clutils (public) (License: GPLv3) (since 2019-07-04) (hash sha1)
An assortment of new and rewritten preexisting tools written by me.
List of commits:
Subject Hash Author Date (UTC)
initial commit 484a7ed27b1835a962cec85cc6f55a20d4a95b46 spicylord 2019-07-04 02:50:23
Commit 484a7ed27b1835a962cec85cc6f55a20d4a95b46 - initial commit
Author: spicylord
Author date (UTC): 2019-07-04 02:50
Committer name: spicylord
Committer date (UTC): 2019-07-04 02:50
Parent(s):
Signing key:
Tree: f2ec4dab5531930155bf9005fc2293ff37644f6c
File Lines added Lines deleted
COPYING 33 0
INSTALL 26 0
README 34 0
clp.c 160 0
echo.c 8 0
nl.l 23 0
sc.c 64 0
spng.c 18 0
tee.c 27 0
wc.c 75 0
yes.c 10 0
File COPYING added (mode: 100644) (index 0000000..4f3466d)
1 FPDL(License) LOCAL FPDL(License)
2
3 NAME
4 Free Public Domain License
5
6 PREAMBLE
7 Ensures Your Freedom.
8 Nothing in this document is binding other than what is in the PERMISSIONS
9 and LEGAL sections. Abiding by what is in the REQUESTS section is
10 optional. This license is completely permissive and simply requests that
11 the author keeps the source open and gives credit.
12
13 PERMISSIONS
14 Both this document and works under this document are in the public
15 domain. Permission is hereby granted to do what you will with both,
16 including, but not limited to, modifying this document and relicensing
17 works already under this document. All that's asked is for the REQUESTS
18 section to be heeded, though that's not required.
19
20 REQUESTS
21 1. Keep all source code in this project open.
22 2. Give proper credit where it's due.
23
24 LEGAL
25 The software is provided "as is", without warranty of any kind, express
26 or implied, including but not limited to the warranties of merchantabil-
27 ity, fitness for a particular purpose and noninfringement. In no event
28 shall the authors be liable for any claim, damages or other liability,
29 whether in an action of contract, tort or otherwise, arising from, out of
30 or in connection with the software or the use or other dealings in the
31 software.
32
33 ALL June 27, 2019 ALL
File INSTALL added (mode: 100755) (index 0000000..8baf428)
1 #!/bin/sh
2 # for installation. nl.l requires lex/flex.
3 # in my experience, the lex that comes with
4 # your linux distro by default may not produce a working
5 # c file, but you can try if you want. I recommend
6 # getting it from your distro repositories
7
8 if [ "$1" = "" ]; then
9 echo "gcc clp.c -o clp"
10 gcc clb.c -o clb
11 echo "gcc echo.c -o echo"
12 gcc echo.c -o echo
13 echo "gcc sc.c -o sc"
14 gcc sc.c -o sc
15 echo "gcc spng.c -o spng"
16 gcc spng.c -o spng
17 echo "gcc tee.c -o tee"
18 gcc tee.c -o tee
19 echo "gcc wc.c -o wc"
20 gcc wc.c -o wc
21 echo "gcc yes.c -o yes"
22 gcc yes.c -o yes
23 echo "lex nl.l && gcc lex.yy.c -o nl.l -lfl && rm lex.yy.c"
24 lex nl.l && gcc lex.yy.c -o nl -lfl && rm lex.yy.c
25 fi
26 [ "$1" = "clean" ] && rm clp echo sc spng tee wc yes nl
File README added (mode: 100644) (index 0000000..bc124fd)
1 this is a collection of programs that I wrote for fun.
2 Some, like spng, are programs that I thought were
3 unnecessarily large (referring to "sponge" from
4 the moreutils project, its like 300 lines, where
5 mine is only 18.) I am even writing my own original
6 software, like clp. Its like a clipboard/clipboard
7 manager for standard input and output.
8
9
10 clp:
11 Insert by piping in standard input ex.
12 echo lmao | clb i
13 that uses its "i" option. This will copy the stdin
14 into your ~/.clipboard file as an entry.
15 the -f option will set your clipboard file to be
16 whatever you want for that command: echo lmao | clip -f altclipboard i
17 the following commands use ed-like addressing.
18 clp ,p will print (paste) your entire clipboard,
19 clp 1,2p will print the earliest 2 entries,
20 and clp p will print the latest entry.
21 the same works with the "d" option, except
22 it deletes the entries.
23 clp c just counts the entries and ends the program.
24
25 spng:
26 allows you to pipe things from a file back into that file
27 in the same pipe line.
28 ex. gofmt file.go | spng file.go
29
30
31 To compile, type "./INSTALL". I do not recommend replacing
32 the versions already in your /usr/bin or /bin,
33
34
File clp.c added (mode: 100644) (index 0000000..193c45d)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define maxtofrom 10
6 /* ocountflag means that it will only count
7 how many entries there are then quit */
8
9 long from=0, to=0, end=0;
10 int inflag=0, outflag=0, ocountflag=0, delflag=0, commaflag=0;
11 char tester[100000]; /* if you have a line longer than this then you have a problem. */
12 char *filename;
13
14 void prepcomms(char *where)
15 {
16 int fromcount=0, tocount=0;
17 char cfrom[maxtofrom+8];
18 char cto[maxtofrom+8];
19 for (int j=0; where[j] && j<=(maxtofrom*2+8); j++) {
20 if (where[j]==',') { commaflag=1; continue; }
21 switch (where[j]) {
22 case 'i': inflag = 1;
23 break;
24 case 'p': outflag = 1;
25 break;
26 case 'd': delflag = 1;;
27 break;
28 case 'c': ocountflag = 1;
29 break;
30 }
31 if (!commaflag) cfrom[fromcount++] = where[j];
32 else cto[tocount++] = where[j];
33 }
34 if (commaflag) {
35 from = atol(cfrom);
36 to = atol(cto);
37 } else {
38 to = (from=atol(cfrom));
39 }
40 if (!from && commaflag && to) {
41 fputs("clip: must have a number before comma\n", stderr);
42 free(filename);
43 exit(1);
44 }
45 if (from > to) {
46 fputs("clip: first number must be less than second\n", stderr);
47 free(filename);
48 exit(1);
49 }
50 }
51
52 void cookargs(int c, char *v[])
53 {
54 if (c>1) {
55 for (int i=1; v[i]; i++) {
56 if (v[i][0]=='-' && v[i][1] && v[i][1]=='f' && v[i+1]) {
57 filename = v[i+1];
58 i++; /* makes cursor skip file name */
59 }
60 else prepcomms(v[i]);
61 }
62 if (!inflag && !outflag && !delflag && !ocountflag) {
63 fputs("usage: clip [-f filename] [justcount|in|out #,#|delete #,#]\n", stderr);
64 free(filename);
65 exit(1);
66 }
67 } else {
68 fputs("usage: clip [-f filename] [count|in|print #,#|delete #,#]\n", stderr);
69 free(filename);
70 exit(1);
71 }
72 }
73
74 int main(int argc, char *argv[])
75 {
76 filename = malloc(3000);
77 sprintf(filename, "%s/%s", getenv("HOME"), ".clipboard");
78 char delim[31] = "------------------------------\n";
79 FILE *filep;
80 long counter = 0;
81 cookargs(argc, argv); /* can change file name based on what comes after "-f" */
82
83 if ((filep=fopen(filename, "a+"))==NULL) {
84 fprintf(stderr, "clip: cannot open %s", filename);
85 free(filename);
86 exit(1);
87 }
88 if (inflag) {
89 char inbuf[1000000];
90 fread(inbuf, sizeof(inbuf), 1, stdin);
91 fprintf(filep, "%s%s", delim, inbuf);
92 fclose(filep);
93 free(filename);
94 exit(1);
95 }
96
97 while (fgets(tester, sizeof(tester), filep))
98 if (memcmp(tester, delim, sizeof(delim))==0)
99 end++;
100
101 rewind(filep);
102 if (ocountflag) {
103 printf("%ld\n", end);
104 goto ending; /* stops program after outputting count */
105 }
106
107 if (end==0) {
108 fputs("nothing to act on\n", stderr);
109 fclose(filep);
110 free(filename);
111 exit(1);
112 }
113 if (to>end) {
114 fputs("clip: end point too big\n", stderr);
115 fclose(filep);
116 free(filename);
117 exit(1);
118 }
119 if (!from && !to && commaflag) { from=1; to=end; }
120 if (!from && !to && !commaflag) { from = end; to = end; }
121 if (delflag) {
122 FILE *tdelfilep;
123 int delimflag=0;
124 if ((tdelfilep=fopen(".clipboard~~~", "w+"))==NULL) {
125 fputs("clip: cannot create temporary file\n", stderr);
126 fclose(filep);
127 free(filename);
128 exit(1);
129 }
130 while (counter <= end && fgets(tester, sizeof(tester), filep)) {
131 if (memcmp(tester, delim, sizeof(delim))==0) {
132 counter++;
133 delimflag=1;
134 continue;
135 }
136 if (counter < from || counter > to) {
137 fprintf(tdelfilep, "%s%s", delimflag?delim:"", tester);
138 delimflag=0;
139 }
140 }
141 rename(".clipboard~~~", filename);
142 goto ending;
143 }
144
145 if (outflag) {
146 while (counter <= end && fgets(tester, sizeof(tester), filep)) {
147 if (memcmp(tester, delim, sizeof(delim))==0) {
148 counter++;
149 continue;
150 }
151 if (counter >= from && counter <= to) {
152 fputs(tester, stdout);
153 }
154 }
155 }
156 ending:
157 free(filename);
158 fclose(filep);
159 return 0;
160 }
File echo.c added (mode: 100644) (index 0000000..66ddd77)
1 #include <stdio.h>
2
3 void main(int argc, char *argv[])
4 {
5 argc--;
6 for (int i=1; i<=argc; i++)
7 printf("%s%c", argv[i], i==argc? '\n':' ');
8 }
File nl.l added (mode: 100644) (index 0000000..b285e64)
1 %{
2 #include <stdio.h>
3 int linenum = 0;
4 %}
5 %%
6 printf("%s", yytext);
7 ^. printf("%6i%3c", ++linenum, yytext[0]);
8 ^\n printf("%6i%3c", ++linenum, yytext[0]);
9 %%
10
11 int main(int argc, char *argv[])
12 {
13 int i = 1;
14 do {
15 if (argc > 1 && (yyin = fopen(argv[i], "r")) == NULL) {
16 fprintf(stderr, "nl: unable to open %s\n", argv[i]);
17 continue;
18 }
19 yylex();
20 fclose(yyin);
21 } while (argc>++i);
22 return 0;
23 }
File sc.c added (mode: 100644) (index 0000000..5d13cc0)
1 #include <stdio.h>
2
3 int main(int argc, char *argv[])
4 {
5 int character;
6 unsigned int ccase = 0;
7 int iter = 1;
8 FILE *filep = stdin;
9 if (argv[1] && argv[1][0]=='-' && argv[1][1]) {
10 switch (argv[1][1]) {
11 case 'l': ccase = 'l'; break;
12 case 'u': ccase = 'u'; break;
13 case 's': ccase = 's'; break;
14 }
15 }
16 else {
17 fprintf(stderr, "sc: usage: sc -[ l|u|s ] [file...]\n");
18 return 1;
19 }
20 argc--;
21 argv++;
22
23 do {
24 if (argc > 1 && (filep=fopen(argv[iter], "r"))==NULL) {
25 fprintf(stderr, "sc: unable to open %s\n", argv[iter]);
26 continue;
27 }
28
29 switch (ccase) {
30 case 'l':
31 while ((character = fgetc(filep))!=EOF) {
32 if (character >= 'a' && character <= 'z')
33 character += 32;
34 putchar(character);
35 }
36 break;
37
38 case 'u':
39 while ((character = fgetc(filep))!=EOF) {
40 if (character >= 'a' && character <= 'z')
41 character -= 32;
42 putchar(character);
43 }
44 break;
45
46 case 's':
47 while ((character = fgetc(filep))!=EOF) {
48 if (character >= 'a' && character <= 'z') {
49 character -= 32;
50 putchar(character);
51 continue;
52 }
53 else if (character >= 'a' && character <= 'z') {
54 character += 32;
55 putchar(character);
56 continue;
57 }
58 putchar(character);
59 }
60 break;
61 }
62 } while (++iter<argc);
63 return 0;
64 }
File spng.c added (mode: 100644) (index 0000000..0a5de08)
1 #include <stdio.h>
2
3 void main(int argc, char *argv[])
4 {
5 char buf[100000];
6 FILE *filep = stdin;
7
8 fread(buf, sizeof(buf), 1, filep);
9
10 for (int i=1; i<argc; i++) {
11 if (argc > 1 && (filep = fopen(argv[i], "w+"))==NULL) {
12 fprintf(stderr, "spng: unable to open %s\n", argv[i]);
13 continue;
14 }
15 fputs(buf, filep);
16 fclose(filep);
17 }
18 }
File tee.c added (mode: 100644) (index 0000000..1ad1125)
1 #include <stdio.h>
2
3 #define MAXBYTES 100000
4
5 void main(int argc, char *argv[])
6 {
7 unsigned int aflag=0;
8 char buf[MAXBYTES];
9 FILE *filep;
10
11 fread(buf, sizeof(buf), 1, stdin);
12 printf("%s", buf);
13
14 if (argc > 1) for (int i=1; argv[i]; i++) {
15 if (argv[i][0] == '-')
16 switch(argv[i][1])
17 case 'a': aflag = 1;
18 else {
19 if ((filep = fopen(argv[i], aflag? "a+":"w+"))==NULL) {
20 fprintf(stderr, "tee: unable to write to %s\n", argv[i]);
21 continue;
22 }
23 fputs(buf, filep);
24 fclose(filep);
25 }
26 }
27 }
File wc.c added (mode: 100644) (index 0000000..d3316c6)
1 #include <stdio.h>
2
3 void wcout(char *wd, int lines, int words, int bytes, char name[])
4 {
5 while (*wd) switch(*wd++) {
6 case 'l':
7 printf("%7i", lines);
8 break;
9 case 'w':
10 printf("%7i", words);
11 break;
12 case 'c':
13 printf("%8i", bytes);
14 break;
15 }
16 printf("%12s\n", name);
17 }
18
19 int main(int argc, char *argv[])
20 {
21 int character;
22 int linec=0, wordc=0, bytec=0, iter = 1;
23 int tlinec=0, twordc=0, tbytec=0;
24 unsigned int spaceflag, lineflag, tabflag;
25 char *wd = "lwc";
26 FILE *filep = stdin;
27
28 if (argc > 1 && argv[1][0]=='-') {
29 wd = ++argv[1];
30 argc--;
31 argv++;
32 }
33
34 do {
35 lineflag=1;
36 if (argc > 1 && (filep = fopen(argv[iter], "r"))==NULL) {
37 fprintf(stderr, "wc: unable to open %s\n", argv[iter]);
38 continue;
39 }
40 while ((character = fgetc(filep)) != EOF) {
41 bytec++;
42 if (character>='A' && character<='z' && (spaceflag==1||lineflag==1||tabflag==1)) {
43 wordc++;
44 spaceflag=0;
45 lineflag=0;
46 tabflag=0;
47 }
48 switch(character) {
49 case '\n': linec++;
50 lineflag=1;
51 break;
52 case ' ': spaceflag=1;
53 break;
54 case '\t': tabflag=1;
55 break;
56 }
57 } fclose(filep);
58
59 if (argc > 2) {
60 tlinec += linec;
61 twordc += wordc;
62 tbytec += bytec;
63 }
64 if (argc > 1)
65 wcout(wd, linec, wordc, bytec, argv[iter]);
66 else
67 wcout(wd, linec, wordc, bytec, "");
68
69 linec = 0;
70 wordc = 0;
71 bytec = 0;
72 } while (++iter<argc);
73 if (argc > 2)
74 wcout(wd, tlinec, twordc, tbytec, "total");
75 }
File yes.c added (mode: 100644) (index 0000000..17ddde7)
1 #include <stdio.h>
2 void main(int argc, char *argv[])
3 {
4 if (argc==1)
5 for(;;)
6 puts("y");
7 else
8 for (;;)
9 puts(argv[1]);
10 }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/spicylord/clutils

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/spicylord/clutils

Clone this repository using git:
git clone git://git.rocketgit.com/user/spicylord/clutils

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main