Skip to content

Commit

Permalink
Merge pull request #3 from themispkg/revert-1-main
Browse files Browse the repository at this point in the history
Revert "Kütüphane desteği sayılır"
  • Loading branch information
lazypwny751 authored Feb 4, 2022
2 parents c3ea6e2 + 44cb755 commit 293ec5b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 54 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define build_baml
gcc main.c -o baml
gcc main.c baml.c -o baml
endef

define test_baml
Expand All @@ -12,14 +12,11 @@ endef

build:
$(build_baml)
@cp libbaml/baml.h /usr/include/


install:
$(build_baml)
install -m 755 ./baml /usr/bin/baml
@$(test_baml)
@cp libbaml/baml.h /usr/include/

uninstall:
rm /usr/bin/baml
Expand Down
52 changes: 3 additions & 49 deletions libbaml/baml.h → baml.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
#pragma once
# define ENTRYTOKEN "->"
# define HEADERTOKEN ';'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "baml.h"

/*
* "valid_arg" takes the first argument and returns output format string list
* if the argument is valid. returns NULL if the argument is invalid.
* "valid_token" takes the line read from the file and check whether it has a
* valid entry token, returns index position located after the token. returns
* zero if the argument is invalid.
* "pheader" takes the line "hstr" comprising a valid token and prints header
* output according to the "format"; "hopen" is passed 0 when there is no
* previous header in the file.
* "pentry" takes the line "hstr" comprising a valid token and prints entry
* output according to the "format"; "hopen" is passed 1 when there is no
* previous entry in the header, it is set to 2 when an entry is inserted.
* "pitem" takes the target string and prints it by adding '\' for any quote
* character and trimming the end of it.
* "dstr" takes a "base" string and concatenates "tail" by dynamically
* allocating memory. this function is used to store a complete line from
* the file.
*/

/*
* Checks valid arguments for baml
*/
char **valid_arg(char *arg)
{
char **format;
Expand Down Expand Up @@ -57,9 +30,6 @@ char **valid_arg(char *arg)

}

/*
* Checks valid tokens like space and tab
*/
size_t valid_token(char *store)
{
size_t offset = 0;
Expand All @@ -71,41 +41,28 @@ size_t valid_token(char *store)
return (0);
}

/*
* Check items for any bugs in parsing (in 69. line)
*/
void pitem(char *istr)
{

// Required definitions
size_t isize = strlen(istr);
size_t scan = 0;
size_t checkp = 0;
size_t trimmer = 0;
unsigned char memory = 0;

// If size of istr greater than scan -> loop
while (scan < isize)
{
// If 0 numbered member of istr greater than 32 -> trimmer equals to scan
if (istr[scan] > 32 )
trimmer = scan;
// If scan numbered member of istr equals to \' or \" or ' -->
if (istr[scan] == '\'' || istr[scan] == '\"' || istr[scan] == '`')
{
// Memory equals scan numbered member of istr
memory = istr[scan];
// Scan numbered member of istr is equals to 0
istr[scan] = 0;
// Print result
printf("%s\\%c", &istr[checkp], memory);
// Scan numbered member of istr to memory
istr[scan] = memory;
// Increase and equals to checkp(0)
checkp = ++scan;
continue ;
}
scan++; // Increase scan for while
scan++;
}
istr[trimmer + 1] = 0;
if (memory == 0)
Expand All @@ -114,7 +71,6 @@ void pitem(char *istr)
printf("%s", &istr[checkp]);
}

// Check headers for tabs and spaces
void pheader(char *hstr, char **format, char *hopen)
{
size_t scan;
Expand All @@ -138,7 +94,6 @@ void pheader(char *hstr, char **format, char *hopen)
*hopen = 1;
}

// Check entry ```->hey``` with spaces and tabs again
void pentry(char *estr, char **format, char *hopen)
{
size_t scan;
Expand All @@ -164,13 +119,12 @@ void pentry(char *estr, char **format, char *hopen)
printf("%s", format[2]);
}

// Change some things with strings
size_t dstr(char *base, char *tail)
{
size_t blen = strlen(base);
size_t tlen = strlen(tail);

base = realloc(base, sizeof(char) * (blen + tlen + 1)); // Allocate memory
base = realloc(base, sizeof(char) * (blen + tlen + 1));
for (size_t i = blen; i < blen + tlen; i++)
{
base[i] = *tail;
Expand Down
35 changes: 35 additions & 0 deletions baml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef BAML_H
# define BAML_H
# define ENTRYTOKEN "->"
# define HEADERTOKEN ';'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
* "valid_arg" takes the first argument and returns output format string list
* if the argument is valid. returns NULL if the argument is invalid.
* "valid_token" takes the line read from the file and check whether it has a
* valid entry token, returns index position located after the token. returns
* zero if the argument is invalid.
* "pheader" takes the line "hstr" comprising a valid token and prints header
* output according to the "format"; "hopen" is passed 0 when there is no
* previous header in the file.
* "pentry" takes the line "hstr" comprising a valid token and prints entry
* output according to the "format"; "hopen" is passed 1 when there is no
* previous entry in the header, it is set to 2 when an entry is inserted.
* "pitem" takes the target string and prints it by adding '\' for any quote
* character and trimming the end of it.
* "dstr" takes a "base" string and concatenates "tail" by dynamically
* allocating memory. this function is used to store a complete line from
* the file.
*/

char **valid_arg(char *arg);
size_t valid_token(char *store);
void pitem(char *istr);
void pheader(char *hstr, char **format, char *hopen);
void pentry(char *estr, char **format, char *hopen);
size_t dstr(char *base, char *tail);

#endif
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "libbaml/baml.h"
#include "baml.h"

int main(int ac, char **av)
{
Expand Down

0 comments on commit 293ec5b

Please sign in to comment.