Skip to content

Commit

Permalink
add cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
liyanboy74 committed Dec 9, 2021
1 parent 50f1d79 commit 394b710
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.6)

project(htmixer)

add_executable(${PROJECT_NAME} htmixer.c)

install(TARGETS htmixer DESTINATION bin)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ HTMixer is a Static HTML page generator. this tool can combine different pages a

[Read More](https://liyanboy74.github.io/htmixer/)

## Compile & Install
```
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
sudo make install
```

## Example Generate
```
cd ../example
make
```
37 changes: 14 additions & 23 deletions Makefile → example/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
# Makefile Template for HTMixer
# by liyanboy74

# Generate Dir
generate-dir = gh-pages

default : compile

# Compice C prog using GCC
compile :
rm -rf build
mkdir build
gcc htmixer.c -o ./build/htmixer

# Remove Compiled app and Generated files
clean :
rm -rf $(generate-dir)
rm -rf build

# Deploy on Github Pages, branch [gh-pages]
# more on : https://pypi.org/project/ghp-import/
# Add CNAME by '-c SITENAME' command
deploy:
ghp-import -p $(generate-dir)
htmixer = "../build/htmixer"
generate-dir = gh-pages

default : generate
##################################### GENARATE ########################################
# Use 'build/htmixer' for mix 'Doc' and 'Var' files.
# Use 'htmixer' for mix 'Doc' and 'Var' files.
# for Example: htmixer OUTPUT_FILR -d DOC1 DOC2 -v VAR1 VAR2 VAR3
# The Var replace by same name in Doc file

Expand All @@ -37,6 +19,15 @@ generate :
cp -r ./doc/htmixer.png ./$(generate-dir)/htmixer.png

# Run Mixer
./build/htmixer ./$(generate-dir)/index.html -d ./doc/home.html -v ./var/home.txt
$(htmixer) ./$(generate-dir)/index.html -d ./doc/home.html -v ./var/home.txt


##################################### DEPLOY ##########################################
# Deploy on Github Pages, branch [gh-pages]
# more on : https://pypi.org/project/ghp-import/
# Add CNAME by '-c SITENAME' command
deploy:
ghp-import -p $(generate-dir)


#######################################################################################
File renamed without changes.
File renamed without changes
File renamed without changes.
95 changes: 55 additions & 40 deletions htmixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ void catch_var_list(char * fileName)
fclose(fp);
}

void replace_var_list(char * inputFileName,char* outputFileName)
void replace_var_list(char * FileName)
{
FILE *fp,*fpt;
size_t s,i,k;

char var_name[SIZE_OF_NAME];
int ss=-1;

fp=fopen(inputFileName,"r");
fpt=fopen(outputFileName,"w");
char Tempfile[]="rvl.tmp";

fp=fopen(FileName,"r");
fpt=fopen(Tempfile,"w");

s=fread(buff,1,SIZE_OF_BUFFER,fp);
for(i=0;i<s;i++)
Expand Down Expand Up @@ -147,18 +149,22 @@ void replace_var_list(char * inputFileName,char* outputFileName)
}
fclose(fp);
fclose(fpt);
remove(FileName);
rename(Tempfile,FileName);
}

void latest_replace_var_list(char * inputFileName,char* outputFileName)
void latest_replace_var_list(char * FileName)
{
FILE *fp,*fpt;
size_t s,i,k;

char var_name[SIZE_OF_NAME];
int ss=-1;

fp=fopen(inputFileName,"r");
fpt=fopen(outputFileName,"w");
char TempFile[]="lrvl.tmp";

fp=fopen(FileName,"r");
fpt=fopen(TempFile,"w");

s=fread(buff,1,SIZE_OF_BUFFER,fp);
for(i=0;i<s;i++)
Expand Down Expand Up @@ -201,9 +207,11 @@ void latest_replace_var_list(char * inputFileName,char* outputFileName)
}
fclose(fp);
fclose(fpt);
remove(FileName);
rename(TempFile,FileName);
}

void cheack_loops(char * inputFileName,char* outputFileName)
void cheack_loops(char * FileName)
{
FILE *fp,*fpt;
size_t s,i,k,l;
Expand All @@ -215,8 +223,10 @@ void cheack_loops(char * inputFileName,char* outputFileName)
char CBuff[SIZE_OF_NAME];
int for_f=0,for_c=0;

fpt=fopen(outputFileName,"w");
fp=fopen(inputFileName,"r");
char TempFile[]="cl.tmp";

fp=fopen(FileName,"r");
fpt=fopen(TempFile,"w");

s=fread(buff,1,SIZE_OF_BUFFER,fp);

Expand Down Expand Up @@ -286,6 +296,8 @@ void cheack_loops(char * inputFileName,char* outputFileName)
}
fclose(fp);
fclose(fpt);
remove(FileName);
rename(TempFile,FileName);
}

void clear_var_list()
Expand All @@ -300,15 +312,16 @@ void clear_var_list()
void cat_files(FILE *fpt,char * fileName)
{
FILE *fp;
size_t s,i;
size_t s;

fp=fopen(fileName,"r");
s=fread(buff,1,SIZE_OF_BUFFER,fp);
for(i=0;i<s;i++)
if(fp=fopen(fileName,"r"),fp!=NULL)
{
fwrite(&buff[i],1,1,fpt);
while (s=fread(buff,1,SIZE_OF_BUFFER,fp),s>0)
{
fwrite(buff,1,s,fpt);
}
fclose(fp);
}
fclose(fp);
}

int main(int argc,char* argv[])
Expand All @@ -322,10 +335,7 @@ int main(int argc,char* argv[])
char var[MAX_INPUT_FILE][SIZE_OF_NAME];
char doc[MAX_INPUT_FILE][SIZE_OF_NAME];

char genFileName[SIZE_OF_NAME];

char tmp1[]="htmixer-tmp1.tmp";
char tmp2[]="htmixer-tmp2.tmp";
char genFileName[SIZE_OF_NAME]="\0";

for(j=1;argc>j;j++)
{
Expand Down Expand Up @@ -356,31 +366,36 @@ int main(int argc,char* argv[])
}
}

for(j=0;j<var_c;j++)
if(genFileName[0]!='\0')
{
catch_var_list(var[j]);
}
//print_var_list();
for(j=0;j<var_c;j++)
{
catch_var_list(var[j]);
}
//print_var_list();

fpt=fopen(tmp1,"w");
for(j=0;j<doc_c;j++)
{
cat_files(fpt,doc[j]);
}
fclose(fpt);
if(fpt=fopen(genFileName,"w"),fpt!=NULL)
{
for(j=0;j<doc_c;j++)
{
cat_files(fpt,doc[j]);
}
fclose(fpt);
}

cheack_loops(tmp1,tmp2);
cheack_loops(tmp2,tmp1);
for(j=0;j<2;j++)
{
cheack_loops(genFileName);
}

for(j=0;j<5;j++)
{
replace_var_list(genFileName);
}

replace_var_list(tmp1,tmp2);
replace_var_list(tmp2,tmp1);
replace_var_list(tmp1,tmp2);
replace_var_list(tmp2,tmp1);
replace_var_list(tmp1,tmp2);
latest_replace_var_list(tmp2,genFileName);
latest_replace_var_list(genFileName);

remove(tmp1);
remove(tmp2);
clear_var_list();
clear_var_list();
}
return 0;
}

0 comments on commit 394b710

Please sign in to comment.