Skip to content

Commit

Permalink
Merge pull request #1 from alimkoca/main
Browse files Browse the repository at this point in the history
güzel değişiklik olmuş tekrardan teşekkür ederiz, aramıza hoş geldiniz :)
  • Loading branch information
lazypwny751 authored Feb 4, 2022
2 parents 02fe83c + c9cac91 commit c3ea6e2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define build_baml
gcc main.c baml.c -o baml
gcc main.c -o baml
endef

define test_baml
Expand All @@ -12,11 +12,14 @@ 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
35 changes: 0 additions & 35 deletions baml.h

This file was deleted.

52 changes: 49 additions & 3 deletions baml.c → libbaml/baml.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#include "baml.h"
#pragma once
# 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.
*/

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

}

/*
* Checks valid tokens like space and tab
*/
size_t valid_token(char *store)
{
size_t offset = 0;
Expand All @@ -41,28 +71,41 @@ 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++;
scan++; // Increase scan for while
}
istr[trimmer + 1] = 0;
if (memory == 0)
Expand All @@ -71,6 +114,7 @@ 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 @@ -94,6 +138,7 @@ 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 @@ -119,12 +164,13 @@ 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));
base = realloc(base, sizeof(char) * (blen + tlen + 1)); // Allocate memory
for (size_t i = blen; i < blen + tlen; i++)
{
base[i] = *tail;
Expand Down
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 "baml.h"
#include "libbaml/baml.h"

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

0 comments on commit c3ea6e2

Please sign in to comment.