File echo.c changed (mode: 100644) (index 0f2b94b..3f3c327) |
1 |
1 |
/* |
/* |
2 |
|
Copyright 2019 Matthew Graham <sl@airmail.cc> |
|
|
2 |
|
Copyright (c) 2019 Matthew Graham |
3 |
3 |
|
|
4 |
4 |
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
5 |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
|
... |
... |
int main(int argc, char *argv[]) |
24 |
24 |
printf("%s%c", argv[i], i==argc? '\n':' '); |
printf("%s%c", argv[i], i==argc? '\n':' '); |
25 |
25 |
return 0; |
return 0; |
26 |
26 |
} |
} |
|
27 |
|
) |
|
28 |
|
if (memcmp(tester, delim, sizeof(delim)-1)==0) |
|
29 |
|
end++; |
|
30 |
|
rewind(filep); |
|
31 |
|
|
|
32 |
|
if (ocountflag) { |
|
33 |
|
printf("%ld\n", end); |
|
34 |
|
goto ending; /* stops program after outputting count */ |
|
35 |
|
} |
|
36 |
|
|
|
37 |
|
if (end==0) { |
|
38 |
|
fputs("nothing to act on\n", stderr); |
|
39 |
|
fclose(filep); |
|
40 |
|
exit(1); |
|
41 |
|
} |
|
42 |
|
if (to>end) { |
|
43 |
|
fputs("clip: end point too big\n", stderr); |
|
44 |
|
fclose(filep); |
|
45 |
|
exit(1); |
|
46 |
|
} |
|
47 |
|
if (!from && !to && commaflag) { from=1; to=end; } |
|
48 |
|
if (!from && !to && !commaflag) { from = end; to = end; } |
|
49 |
|
if (from && !to && commaflag) to = end; |
|
50 |
|
if (delflag) { |
|
51 |
|
int delimflag=0; |
|
52 |
|
if ((tdelfilep=fopen(".clipboard~~~", "w+"))==NULL) { |
|
53 |
|
fputs("clip: cannot create temporary file\n", stderr); |
|
54 |
|
fclose(filep); |
|
55 |
|
exit(1); |
|
56 |
|
} |
|
57 |
|
while (counter <= end && fgets(tester, sizeof(tester), filep)) { |
|
58 |
|
if (memcmp(tester, delim, sizeof(delim)-1)==0) { |
|
59 |
|
counter++; |
|
60 |
|
delimflag=1; |
|
61 |
|
continue; |
|
62 |
|
} |
|
63 |
|
if (counter < from || counter > to) { |
|
64 |
|
fprintf(tdelfilep, "%s%s", delimflag?delim:"", tester); |
|
65 |
|
delimflag=0; |
|
66 |
|
} |
|
67 |
|
} |
|
68 |
|
rename(".clipboard~~~", filename); |
|
69 |
|
goto ending; |
|
70 |
|
} |
|
71 |
|
|
|
72 |
|
if (outflag) { |
|
73 |
|
while (counter <= end && fgets(tester, sizeof(tester), filep)) { |
|
74 |
|
if (memcmp(tester, delim, sizeof(delim)-1)==0) { |
|
75 |
|
counter++; |
|
76 |
|
continue; |
|
77 |
|
} |
|
78 |
|
if (counter >= from && counter <= to) { |
|
79 |
|
fputs(tester, stdout); |
|
80 |
|
} |
|
81 |
|
} |
|
82 |
|
} |
|
83 |
|
ending: |
|
84 |
|
fclose(filep); |
|
85 |
|
exit(0); |
|
86 |
|
} |
File ins.c changed (mode: 100644) (index 21b792b..29646d8) |
1 |
1 |
/* |
/* |
2 |
|
Copyright 2019 Matthew Graham <sl@airmail.cc> |
|
|
2 |
|
Copyright (c) 2019 Matthew Graham |
3 |
3 |
|
|
4 |
4 |
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
5 |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
|
... |
... |
int main(int argc, char *argv[]) |
24 |
24 |
FILE *fp, *tfp; |
FILE *fp, *tfp; |
25 |
25 |
char *fbuf; |
char *fbuf; |
26 |
26 |
char *buf; |
char *buf; |
|
27 |
|
char *null=0; |
27 |
28 |
long fsize, tsize; |
long fsize, tsize; |
28 |
29 |
char instext[100000]; |
char instext[100000]; |
29 |
30 |
fread(instext, sizeof(instext), 1, stdin); |
fread(instext, sizeof(instext), 1, stdin); |
|
... |
... |
int main(int argc, char *argv[]) |
45 |
46 |
strcat(buf, fbuf); |
strcat(buf, fbuf); |
46 |
47 |
fputs(buf, tfp); |
fputs(buf, tfp); |
47 |
48 |
rename(".instemp~~~", argv[i]); |
rename(".instemp~~~", argv[i]); |
|
49 |
|
strcpy(buf, null); |
48 |
50 |
free(buf); |
free(buf); |
|
51 |
|
strcpy(fbuf, null); |
49 |
52 |
free(fbuf); |
free(fbuf); |
50 |
53 |
fclose(fp); |
fclose(fp); |
51 |
54 |
fclose(tfp); |
fclose(tfp); |
File sc.c changed (mode: 100644) (index 7dbeee4..d59401d) |
1 |
1 |
/* |
/* |
2 |
|
Copyright 2019 Matthew Graham <sl@airmail.cc> |
|
|
2 |
|
Copyright (c) 2019 Matthew Graham |
3 |
3 |
|
|
4 |
4 |
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
5 |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
|
... |
... |
GNU General Public License for more details. |
14 |
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 |
16 |
*/ |
*/ |
17 |
|
|
|
18 |
17 |
#include <stdio.h> |
#include <stdio.h> |
19 |
|
#include <stdlib.h> |
|
20 |
18 |
|
|
21 |
19 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
22 |
20 |
{ |
{ |
23 |
|
char *buf; |
|
|
21 |
|
int character; |
24 |
22 |
unsigned int ccase = 0; |
unsigned int ccase = 0; |
25 |
|
long size; |
|
26 |
|
int i = 1; |
|
27 |
|
FILE *fp = stdin; |
|
|
23 |
|
int iter = 1; |
|
24 |
|
FILE *filep = stdin; |
28 |
25 |
if (argv[1] && argv[1][0]=='-' && argv[1][1]) { |
if (argv[1] && argv[1][0]=='-' && argv[1][1]) { |
29 |
26 |
switch (argv[1][1]) { |
switch (argv[1][1]) { |
30 |
27 |
case 'l': ccase = 'l'; break; |
case 'l': ccase = 'l'; break; |
|
... |
... |
int main(int argc, char *argv[]) |
40 |
37 |
argv++; |
argv++; |
41 |
38 |
|
|
42 |
39 |
do { |
do { |
43 |
|
if (argc > 1 && (fp=fopen(argv[i], "r"))==NULL) { |
|
44 |
|
fprintf(stderr, "sc: unable to open %s\n", argv[i]); |
|
|
40 |
|
if (argc > 1 && (filep=fopen(argv[iter], "r"))==NULL) { |
|
41 |
|
fprintf(stderr, "sc: unable to open %s\n", argv[iter]); |
45 |
42 |
continue; |
continue; |
46 |
43 |
} |
} |
47 |
|
fseek(fp, 0L, SEEK_END); |
|
48 |
|
size = ftell(fp); |
|
49 |
|
rewind(fp); |
|
50 |
|
buf = malloc(size+1); |
|
51 |
|
fread(buf, size, 1, fp); |
|
|
44 |
|
|
52 |
45 |
switch (ccase) { |
switch (ccase) { |
53 |
46 |
case 'l': |
case 'l': |
54 |
|
for (int a=0; buf[a]; a++) { |
|
55 |
|
if (buf[a] >= 'A' && buf[a] <= 'Z') |
|
56 |
|
buf[a] += 32; |
|
57 |
|
putchar(buf[a]); |
|
|
47 |
|
while ((character = fgetc(filep))!=EOF) { |
|
48 |
|
if (character >= 'A' && character <= 'A') |
|
49 |
|
character += 32; |
|
50 |
|
putchar(character); |
58 |
51 |
} |
} |
59 |
52 |
break; |
break; |
60 |
53 |
|
|
61 |
54 |
case 'u': |
case 'u': |
62 |
|
for (int b=0; buf[b]; b++) { |
|
63 |
|
if (buf[b] >= 'a' && buf[b] <= 'z') |
|
64 |
|
buf[b] -= 32; |
|
65 |
|
putchar(buf[b]); |
|
|
55 |
|
while ((character = fgetc(filep))!=EOF) { |
|
56 |
|
if (character >= 'a' && character <= 'z') |
|
57 |
|
character -= 32; |
|
58 |
|
putchar(character); |
66 |
59 |
} |
} |
67 |
60 |
break; |
break; |
68 |
61 |
|
|
69 |
62 |
case 's': |
case 's': |
70 |
|
for (int c=0; buf[c]; c++) { |
|
71 |
|
if (buf[c] >= 'a' && buf[c] <= 'z') { |
|
72 |
|
buf[c] -= 32; |
|
73 |
|
putchar(buf[c]); |
|
|
63 |
|
while ((character = fgetc(filep))!=EOF) { |
|
64 |
|
if (character >= 'a' && character <= 'z') { |
|
65 |
|
character -= 32; |
|
66 |
|
putchar(character); |
74 |
67 |
continue; |
continue; |
75 |
68 |
} |
} |
76 |
|
else if (buf[c] >= 'A' && buf[c] <= 'Z') { |
|
77 |
|
buf[c] += 32; |
|
78 |
|
putchar(buf[c]); |
|
|
69 |
|
else if (character >= 'A' && character <= 'Z') { |
|
70 |
|
character += 32; |
|
71 |
|
putchar(character); |
79 |
72 |
continue; |
continue; |
80 |
73 |
} |
} |
81 |
|
putchar(buf[c]); |
|
|
74 |
|
putchar(character); |
82 |
75 |
} |
} |
83 |
76 |
break; |
break; |
84 |
77 |
} |
} |
85 |
|
free(buf); |
|
86 |
|
} while (++i<argc); |
|
|
78 |
|
} while (++iter<argc); |
87 |
79 |
return 0; |
return 0; |
88 |
80 |
} |
} |
File yes.c changed (mode: 100644) (index b2f6b39..e69de29) |
1 |
|
/* |
|
2 |
|
Copyright 2019 Matthew Graham <sl@airmail.cc> |
|
3 |
|
|
|
4 |
|
This program is free software: you can redistribute it and/or modify |
|
5 |
|
it under the terms of the GNU General Public License as published by |
|
6 |
|
the Free Software Foundation, either version 3 of the License, or |
|
7 |
|
(at your option) any later version. |
|
8 |
|
|
|
9 |
|
This program is distributed in the hope that it will be useful, |
|
10 |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
|
GNU General Public License for more details. |
|
13 |
|
|
|
14 |
|
You should have received a copy of the GNU General Public License |
|
15 |
|
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
16 |
|
*/ |
|
17 |
|
|
|
18 |
|
#include <stdio.h> |
|
19 |
|
|
|
20 |
|
int main(int argc, char *argv[]) |
|
21 |
|
{ |
|
22 |
|
if (argc==1) |
|
23 |
|
for(;;) |
|
24 |
|
puts("y"); |
|
25 |
|
else |
|
26 |
|
for (;;) |
|
27 |
|
puts(argv[1]); |
|
28 |
|
return 1; |
|
29 |
|
} |
|