Compare commits

...

3 Commits

Author SHA1 Message Date
vedri 9cf6d57ceb Add compare content 2021-08-08 15:05:45 +02:00
vedri 10cdbca4e3 Add makefile content 2021-08-08 14:40:36 +02:00
vedri a361a0b0f2 Expand initial README 2021-08-08 14:11:51 +02:00
6 changed files with 145 additions and 2 deletions

10
2105-makefile/Makefile Normal file
View File

@ -0,0 +1,10 @@
## Simple Makefile by botanicals
## Code available at https://git.disroot.org/botanicals/blog-files
# Compiler and flags
CC=gcc
CFLAGS=-Wall -Wextra -pedantic
LDLIBS=-lm # math.h library
# No recipes necessary.
# `make` builds using implicit rules.

32
2105-makefile/README.md Normal file
View File

@ -0,0 +1,32 @@
# Simple Makefile
Originally posted May 1st, 2021 on [Dreamwidth](https://campanilla.dreamwidth.org/4024.html).
## Idea
We were supposed to use CodeBlocks for programming classes at my school, but CodeBlocks kept breaking on me. I switched to using emacs as my text editor, and building and testing in the command line. For practice, we have to write a lot of short C programs. I saved each under their own name so I'd be able to comeback and analyze it when needed. To skip writing many flags recommended for beginners, i wrote a short makefile with help from folks on weirder.earth.
For more background, check out the blog post.
## Prerequisites
- [GNU make](https://gnu.org/software/make)
- [gcc](https://gnu.org/software/gcc)
## Usage
Download the Makefile from this folder and save it into the folder with your source files.
Example of usage and output in the command line:
``` sh
[directory]$ ls
4-1-13.c Makefile
[directory]$ make 4-1-13
gcc -Wall -Wextra -pedantic 4-1-13.c -lm -o 4-1-13
[directory]$ ls
4-1-13.c 4-1-13 Makefile
[directory]$ ./4-1-13
# code runs
```

10
2108-compare/Makefile Normal file
View File

@ -0,0 +1,10 @@
## Simple Makefile by botanicals
## Code available at https://git.disroot.org/botanicals/blog-files
# Compiler and flags
CC=gcc
CFLAGS=-Wall -Wextra -pedantic
LDLIBS=-lm # math.h library
# No recipes necessary.
# `make` builds using implicit rules.

41
2108-compare/README.md Normal file
View File

@ -0,0 +1,41 @@
# Compare SHA Sums
## Idea
I wanted to practice working with files in C programs and at the same time check if the SHA sums for a Manjaro ISO file were the same.
## Prerequisites
- [GNU make](https://gnu.org/software/make)
- [gcc](https://gnu.org/software/gcc)
## Usage
Place the `compare.c` and `Makefile` in the same directory. Build `compare`.
``` sh
make compare
```
Either download or create a text file. The first line of the text file should contain only the SHA sum provided by the developer.
Example of `sha-test.txt`:
``` txt
6ff0ebecb9813542e1fa81bbe897bb59039bb00d
```
Append to the file a SHA sum you generated yourself.
``` sh
sha1sum ISO >> sha-test.txt
```
Run `compare` and enter the name of the file with SHA sums when prompted.
``` sh
$ ./compare
Filename: sha-test.txt
# The program prints whether SHA sums match or not.
```

45
2108-compare/compare.c Normal file
View File

@ -0,0 +1,45 @@
/* Compare by botanicals
* Available at https://git.disroot.org/botanicals/blog-files
*
* This program compares two strings, each in its own line,
* of SHA sums read from a file.
*
* Read the projects README for more details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
// Declarations
FILE *sha;
char name[100];
char sha1[100];
char sha2[100];
char c[2];
// Collect the relevant filename
printf("Filename: ");
scanf("%s", name);
// Open file
if ((sha = fopen(name, "rt")) == NULL) {
printf("Cannot open file!\n");
exit(EXIT_FAILURE);
}
// Read the file content; run the compare function
fscanf(sha, "%[^\n]", sha1);
fscanf(sha, "%[\n]", c);
fscanf(sha, "%[^ ]", sha2);
if (strcmp(sha1, sha2) == 0)
printf("SHA sums are the same!\n");
else
printf("SHA sums are not the same! Do not use.\n");
// Close file; exit program
fclose(sha);
return 0;
}

View File

@ -1,3 +1,8 @@
# blog-files
# Blog Files
Some files referenced in posts I make elsewhere on the web.
Blog Files is a repository for all the assorted files I reference in other posts around the internet. This is to make them easy to download without any copy-paste shenanigans. The files are sorted into folders, each with it's own README file that outlines the intended usage.
## Index
[Makefile](/2105-makefile/README.md) contains a simple makefile for C files.
[Compare SHA sums](/2108-compare/README.md) contains a short program written in C that compares two SHA sums.