add stuff

This commit is contained in:
Artur Tamborski 2019-06-14 20:04:43 +02:00
commit dcd63bfd99
71 changed files with 2177 additions and 0 deletions

43
baci/main.cm Normal file
View File

@ -0,0 +1,43 @@
binarysem sem_produce;
binarysem sem_consume;
int g_value;
void produce(char id)
{
int r;
wait(sem_produce);
r = random(100);
cout << "Producer " << id << " made: " << r << endl;
g_value = r;
signal(sem_consume);
}
void consume(char id)
{
wait(sem_consume);
cout << "Consumer " << id << " ate: " << g_value << endl;
signal(sem_produce);
}
main()
{
initialsem(sem_produce, 1);
initialsem(sem_consume, 1);
cobegin {
produce('A');
produce('B');
consume('A');
consume('B');
consume('C');
}
cout << "done." << endl;
}

46
baci/main.lst Normal file
View File

@ -0,0 +1,46 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: main.cm Sat Dec 1 11:07:53 2018
line pc
1 0 binarysem sem_produce;
2 0 binarysem sem_consume;
3 0
4 0 int g_value;
5 0
6 0 void produce(char id)
7 0 {
8 0 int r;
9 0
10 0 wait(sem_produce);
11 2
12 2 r = random(100);
13 6 cout << "Producer " << id << " made: " << r << endl;
14 13 g_value = r;
15 16
16 16 signal(sem_consume);
17 18 }
18 19
19 19 void consume(char id)
20 19 {
21 19 wait(sem_consume);
22 21
23 21 cout << "Consumer " << id << " ate: " << g_value << endl;
24 28
25 28 signal(sem_produce);
26 30 }
27 31
28 31 main()
29 32 {
30 32 initialsem(sem_produce, 1);
31 35 initialsem(sem_consume, 1);
32 38
33 38 cobegin {
34 39 produce('A');
35 43 produce('B');
36 47
37 47 consume('A');
38 51 consume('B');
39 55 consume('C');
40 59 }
41 60
42 60 cout << "done." << endl;
43 62 }

BIN
baci/main.pco Normal file

Binary file not shown.

11
baci/makefile Normal file
View File

@ -0,0 +1,11 @@
all: compile run
echo "Done"
compile:
rm main.lst
bacc main.cm
run:
bainterp main.pco
.PHONY: all compile run

42
kolos/main.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp, *targetfp;
char *target;
int chr, i;
if (argc < 3)
{
printf("%s <file1> <fileN...> <file to copy to>\n", argv[0]);
puts("not enough args, quitting");
return 1;
}
/* last argument is treated as target file name */
target = argv[argc-1];
targetfp = fopen(target, "a");
for (i = 1; i < argc - 1; i++)
{
if ((fp = fopen(argv[i], "r")) == NULL)
{
printf("could not open file %s, quitting.", argv[i]);
fflush(targetfp);
fclose(targetfp);
return 2;
}
while ((chr = fgetc(fp)) != EOF)
{
fputc(chr, targetfp);
}
fflush(targetfp);
fclose(fp);
}
fclose(targetfp);
return 0;
}

42
kolos/makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS =
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

11
os/Makefile Normal file
View File

@ -0,0 +1,11 @@
TARGETS = all clean
SUBDIRS = $(wildcard */.)
$(TARGETS): $(SUBDIRS)
@echo Done.
$(SUBDIRS):
@$(MAKE) -C $@ $(MAKECMDGOALS)
.PHONY: $(TARGETS) $(SUBDIRS)

22
os/baci/main.cm Normal file
View File

@ -0,0 +1,22 @@
void p1(void)
{
cout << "p1()" << endl;
}
void p2(void)
{
cout << "p2()" << endl;
}
void p3(void)
{
cout << "p3()" << endl;
}
main()
{
cobegin {
}
cout << "done." << endl;
}

24
os/baci/main.lst Normal file
View File

@ -0,0 +1,24 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: main.cm Sat Nov 17 11:13:44 2018
line pc
1 0 binarysem print_semaphore;
2 0
3 0 void hello (char id)
4 0 {
5 0 wait(print_semaphore);
6 2 cout << "Hi! I am a process!" << endl;
7 4 cout << "My ID is: " << id << endl;
8 8 cout << "Bye!" << endl;
9 10 signal(print_semaphore);
10 12 }
11 13
12 13 main()
13 14 {
14 14 initialsem(print_semaphore,1);
15 17 cobegin {
16 18 hello('A'); hello('B'); hello('C');
17 30 }
18 31
19 31 cout << "All processes finished" << endl;
20 33 }
21 35

BIN
os/baci/main.pco Normal file

Binary file not shown.

11
os/baci/makefile Normal file
View File

@ -0,0 +1,11 @@
all: compile run
echo "Done"
compile:
rm main.lst
bacc main.cm
run:
bainterp main.pco
.PHONY: all compile run

42
os/c1/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

8
os/c1/main.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
int main(int argc, char **argv)
{
puts("Hello world!");
return (0);
}

42
os/c10/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

26
os/c10/main.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>
unsigned toDec(char *s, int base)
{
int idx, ret, len, old_base;
ret = 0;
len = strlen(s);
old_base = base;
while (len--)
{
idx = s[len] < '9' ? s[len] - 48 : s[len] - 55;
ret += idx * base;
base *= old_base;
}
return ret / old_base;
}
int main(int argc, char **argv)
{
printf("%d \n", toDec("128", 10));
printf("%X \n", toDec("EF", 16));
}

42
os/c11/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

62
os/c11/main.c Normal file
View File

@ -0,0 +1,62 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
unsigned toDec(char *s, int base)
{
int idx, ret, len, old_base;
ret = 0;
len = strlen(s);
old_base = base;
while (len--)
{
idx = s[len] < '9' ? s[len] - 48 : s[len] - 55;
ret += idx * base;
base *= old_base;
}
return ret / old_base;
}
char *fromDec(unsigned int x, int base)
{
static char buf[80] = {0};
char *p = &buf[sizeof(buf) - 2];
do {
*p = (x % base) + 48;
*p += *p < '9' ? 0 : 7;
p -= 1;
} while (x /= base);
return ++p;
}
int main(int argc, char **argv)
{
int number, from, to;
to = toInt(argv[3]);
from = toInt(argv[2]);
number = toDec(argv[1], from);
puts(fromDec(number, to));
}

42
os/c2/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

13
os/c2/main.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 100; i++)
if (i % 3 == 0)
printf("%d%c", i, i % 10 == 0 ? '\n' : '\t');
puts("");
return (0);
}

42
os/c3/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

19
os/c3/main.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main(void)
{
int x = 1;
int i, j;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
{
x = i * j;
printf("%*d", 4, x);
}
puts("");
}
return (0);
}

42
os/c4/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

25
os/c4/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
printf("%d\n", toInt(argv[1]));
}

42
os/c5/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

21
os/c5/main.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
int nwd(int a, int b)
{
int c;
while (b != 0)
{
c = a % b;
a = b;
b = c;
}
return (a);
}
int main(void)
{
printf("%d\n", nwd(36, 48));
}

42
os/c6/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

10
os/c6/main.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++)
puts(argv[i]);
}

42
os/c7/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

44
os/c7/main.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
int nwd(int a, int b)
{
int c;
while (b != 0)
{
c = a % b;
a = b;
b = c;
}
return (a);
}
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
int a, b;
a = toInt(argv[1]);
b = toInt(argv[2]);
printf("%d\n", nwd(a, b));
}

42
os/c8/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

22
os/c8/main.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
int toHex(unsigned x)
{
unsigned char *p;
int i;
p = (unsigned char *)&x;
for (i = 0; i < sizeof(x); i++)
printf("%x\n", p[i]);
return -1;
}
int main(int argc, char **argv)
{
unsigned int x = 0xdeadbeef;
printf("%x\n", toHex(x));
}

42
os/c9/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

20
os/c9/main.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
char *fromDec(unsigned int x, int base)
{
static char buf[128] = {0};
char *p = &buf[sizeof(buf) - 2];
do {
*p = (x % base) + 48;
*p += *p < '9' ? 0 : 7;
p -= 1;
} while (x /= base);
return ++p;
}
int main(int argc, char **argv)
{
puts(fromDec(0xaa, 16));
}

11
os/os/Makefile Normal file
View File

@ -0,0 +1,11 @@
TARGETS = all clean
SUBDIRS = $(wildcard */.)
$(TARGETS): $(SUBDIRS)
@echo Done.
$(SUBDIRS):
@$(MAKE) -C $@ $(MAKECMDGOALS)
.PHONY: $(TARGETS) $(SUBDIRS)

42
os/os/c1/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

8
os/os/c1/main.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
int main(int argc, char **argv)
{
puts("Hello world!");
return (0);
}

42
os/os/c10/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

26
os/os/c10/main.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>
unsigned toDec(char *s, int base)
{
int idx, ret, len, old_base;
ret = 0;
len = strlen(s);
old_base = base;
while (len--)
{
idx = s[len] < '9' ? s[len] - 48 : s[len] - 55;
ret += idx * base;
base *= old_base;
}
return ret / old_base;
}
int main(int argc, char **argv)
{
printf("%d \n", toDec("128", 10));
printf("%X \n", toDec("EF", 16));
}

42
os/os/c11/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

62
os/os/c11/main.c Normal file
View File

@ -0,0 +1,62 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
unsigned toDec(char *s, int base)
{
int idx, ret, len, old_base;
ret = 0;
len = strlen(s);
old_base = base;
while (len--)
{
idx = s[len] < '9' ? s[len] - 48 : s[len] - 55;
ret += idx * base;
base *= old_base;
}
return ret / old_base;
}
char *fromDec(unsigned int x, int base)
{
static char buf[80] = {0};
char *p = &buf[sizeof(buf) - 2];
do {
*p = (x % base) + 48;
*p += *p < '9' ? 0 : 7;
p -= 1;
} while (x /= base);
return ++p;
}
int main(int argc, char **argv)
{
int number, from, to;
to = toInt(argv[3]);
from = toInt(argv[2]);
number = toDec(argv[1], from);
puts(fromDec(number, to));
}

42
os/os/c2/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

13
os/os/c2/main.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 100; i++)
if (i % 3 == 0)
printf("%d%c", i, i % 10 == 0 ? '\n' : '\t');
puts("");
return (0);
}

42
os/os/c3/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

19
os/os/c3/main.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main(void)
{
int x = 1;
int i, j;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
{
x = i * j;
printf("%*d", 4, x);
}
puts("");
}
return (0);
}

42
os/os/c4/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

25
os/os/c4/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
printf("%d\n", toInt(argv[1]));
}

42
os/os/c5/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

21
os/os/c5/main.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
int nwd(int a, int b)
{
int c;
while (b != 0)
{
c = a % b;
a = b;
b = c;
}
return (a);
}
int main(void)
{
printf("%d\n", nwd(36, 48));
}

42
os/os/c6/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

10
os/os/c6/main.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++)
puts(argv[i]);
}

42
os/os/c7/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

44
os/os/c7/main.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
int nwd(int a, int b)
{
int c;
while (b != 0)
{
c = a % b;
a = b;
b = c;
}
return (a);
}
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
int a, b;
a = toInt(argv[1]);
b = toInt(argv[2]);
printf("%d\n", nwd(a, b));
}

42
os/os/c8/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

22
os/os/c8/main.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
int toHex(unsigned x)
{
unsigned char *p;
int i;
p = (unsigned char *)&x;
for (i = 0; i < sizeof(x); i++)
printf("%x\n", p[i]);
return -1;
}
int main(int argc, char **argv)
{
unsigned int x = 0xdeadbeef;
printf("%x\n", toHex(x));
}

42
os/os/c9/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

20
os/os/c9/main.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
char *fromDec(unsigned int x, int base)
{
static char buf[128] = {0};
char *p = &buf[sizeof(buf) - 2];
do {
*p = (x % base) + 48;
*p += *p < '9' ? 0 : 7;
p -= 1;
} while (x /= base);
return ++p;
}
int main(int argc, char **argv)
{
puts(fromDec(0xaa, 16));
}

42
os/p/c1/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

10
os/p/c1/main.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main(int argc, char **argv)
{
while (--argc > 0)
printf("%s ", argv[argc]);
puts("");
return (0);
}

42
os/p/c2/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

15
os/p/c2/main.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main(void)
{
int input, sum = 0;
puts("Press CTRL+D to stop reading");
while (scanf("%i", &input) != EOF)
sum += input;
puts("-- sum --");
printf("%d\n", sum);
return (0);
}

42
os/p/c3/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

25
os/p/c3/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
printf("%d\n", toInt(argv[1]));
}

42
os/psh/makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

41
os/psh/src/main.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* should be enough */
#define LINE_MAX 1024
#define PATH_MAX 4096
int
main(int argc, char **argv)
{
char line[LINE_MAX];
char cwd[PATH_MAX];
char *pline = line;
for (;;)
{
if (getcwd(cwd, sizeof(cwd)) == NULL)
{
perror("getcwd()");
exit(-1);
}
printf("[%s] ", cwd);
fgets(line, sizeof(line), stdin);
if (strncmp("cd ", line, sizeof("cd ")))
{
while (*pline != ' ')
pline++;
chdir(pline);
}
}
return 0;
}

42
p/c1/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

24
p/c1/main.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
struct c
{
void *a;
int b;
char c[10];
};
int main(int argc, char **argv)
{
struct c cc[10];
printf("%zu \n", sizeof(struct c));
printf("%zu \n", sizeof(cc));
printf("%zu \n", sizeof(cc[0]));
printf("%zu \n", sizeof(*cc));
while (--argc > 0)
printf("%s ", argv[argc]);
puts("");
return (0);
}

42
p/c2/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

15
p/c2/main.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main(void)
{
int input, sum = 0;
puts("Press CTRL+D to stop reading");
while (scanf("%i", &input) != EOF)
sum += input;
puts("-- sum --");
printf("%d\n", sum);
return (0);
}

42
p/c3/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET = $(notdir $(CURDIR))
SRCEXT = .c
INCEXT = .h
OBJEXT = .o
SRCDIR = .
INCDIR = .
OBJDIR = .
CC = gcc
LD = gcc
LDFLAGS = -lm -lpthread
CCFLAGS = -std=gnu99 -g -ggdb -Og -Wall -Wextra -pedantic
SRCTREE = $(shell find $(SRCDIR) -type d)
INCS = $(shell find $(INCDIR) -type f -name '*$(INCEXT)')
SRCS = $(shell find $(SRCDIR) -type f -name '*$(SRCEXT)')
OBJTREE = $(foreach D,$(SRCTREE),$(shell echo $(D) | sed 's/$(SRCDIR)/$(OBJDIR)/'))
OBJSTMP = $(foreach F,$(SRCS),$(shell echo $(F) | sed -e 's/$(SRCDIR)/$(OBJDIR)/'))
OBJS = $(foreach O,$(OBJSTMP),$(shell echo $(O) | sed -e 's/\$(SRCEXT)/\$(OBJEXT)/'))
all: $(TARGET)
@echo Done.
run: $(TARGET)
@./$(TARGET)
clean:
@rm -r $(TARGET) $(OBJS) $(OBJDIR) 2>/dev/null || true
$(TARGET): $(OBJS) | $(OBJDIR)
@$(LD) $(LDFLAGS) -L$(OBJDIR) -o $@ $^
$(OBJS): $(OBJDIR)/%$(OBJEXT) : $(SRCDIR)/%$(SRCEXT) | $(OBJDIR)
@$(CC) $(CCFLAGS) -I$(INCDIR) -c -o $@ $?
$(OBJDIR):
@mkdir -p $(OBJDIR) $(OBJTREE)
.PHONY: all run clean

25
p/c3/main.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
int toInt(char *s)
{
int ret = 0, base = 1;
int len;
len = strlen(s);
while (s[--len] >= '0')
{
ret += (s[len] - '0') * base;
base *= 10;
}
if (s[0] == '-')
ret *= -1;
return (ret);
}
int main(int argc, char **argv)
{
printf("%d\n", toInt(argv[1]));
}

1
psh Submodule

@ -0,0 +1 @@
Subproject commit 360cf24ae24b92e11232dd587534c33d238539b3