hmm:
This commit is contained in:
parent
289b4d8d66
commit
5dae148967
102
main.c
102
main.c
|
|
@ -1,14 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define MAX_LENGTH 1000
|
||||
|
||||
typedef struct markdown {
|
||||
int bold;
|
||||
int quote;
|
||||
int italic;
|
||||
int headingone;
|
||||
int headingtwo;
|
||||
int headingthree;
|
||||
} markdown;
|
||||
|
||||
markdown mdt;
|
||||
|
||||
FILE *fptr;
|
||||
|
||||
void checker() {
|
||||
fptr = fopen("./source/data.txt", "rb+");
|
||||
|
||||
if (fptr == NULL) {
|
||||
perror("Galat checker buat ./source/data.txt");
|
||||
exit(1);
|
||||
|
|
@ -17,49 +28,54 @@ void checker() {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
printf("Penggunaan: %s <berkas_input>\natau %s -h untuk info lebih lanjut\n", argv[0], argv[0]);
|
||||
printf("penggunaan: %s <berkas_input>\natau %s -h untuk info lebih lanjut\n", argv[0], argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp("-v", argv[i]) == 0) {
|
||||
printf("daisy © radhitya.org\n");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
else if(strcmp("-h", argv[i]) == 0) {
|
||||
printf("ini -h\n");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
else if(strcmp("new", argv[i]) == 0) {
|
||||
struct stat st;
|
||||
|
||||
if(stat("./source", &st) == 0 || stat("./target", &st) == 0) {
|
||||
if(stat("./source", &st) == 0) {
|
||||
if(stat("./target", &st) == 0) {
|
||||
printf("./source dan ./target telah dibuat\n");
|
||||
} else {
|
||||
mkdir("./target", 0700);
|
||||
}
|
||||
|
||||
if(stat("./source", &st) == -1) {
|
||||
} else {
|
||||
mkdir("./source", 0700);
|
||||
}
|
||||
|
||||
if(stat("./target", &st) == -1) {
|
||||
mkdir("./target", 0700);
|
||||
}
|
||||
|
||||
fptr = fopen("./source/data.txt", "rb+");
|
||||
if (fptr == NULL) {
|
||||
printf("Sukses buat ./source/data.txt\n");
|
||||
fptr = fopen("./source/data.txt", "wb");
|
||||
if (fptr == NULL) {
|
||||
perror("Galat buat ./source/data.txt");
|
||||
perror("galat buat ./source/data.txt (fptr)");
|
||||
exit(1);
|
||||
} else {
|
||||
printf("sukses buat ./source/data.txt\n");
|
||||
}
|
||||
} else {
|
||||
printf("./source/data.txt sudah ada\n");
|
||||
fclose(fptr);
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char txt[50], of[50];
|
||||
int i, len, in_italic = 0;
|
||||
char txt[MAX_LENGTH], of[MAX_LENGTH];
|
||||
|
||||
int i, len;
|
||||
mdt.italic = 0, mdt.bold = 0, mdt.quote = 0;
|
||||
|
||||
const char *file_name = strrchr(argv[1], '/');
|
||||
if (file_name == NULL) {
|
||||
file_name = argv[1];
|
||||
|
|
@ -69,7 +85,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
snprintf(of, sizeof(of), "target/%s.html", file_name);
|
||||
|
||||
|
||||
fptr = fopen(argv[1], "rt");
|
||||
if (fptr == NULL) {
|
||||
perror("Galat membuka masukan berkas fptr\n");
|
||||
|
|
@ -84,32 +99,71 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
fprintf(fpto, "<html>\n<body>\n");
|
||||
while (fgets(txt, 50, fptr) != NULL) {
|
||||
while (fgets(txt, MAX_LENGTH, fptr) != NULL) {
|
||||
len = strlen(txt);
|
||||
|
||||
if (len > 0 && txt[len-1] == '\n') {
|
||||
txt[--len] = '\0';
|
||||
}
|
||||
|
||||
mdt.headingone = 0;
|
||||
mdt.quote = 0;
|
||||
if(len > 0 && txt[0] == '#' && )
|
||||
fprintf(fpto, "<p>");
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
|
||||
if (txt[i] == '_' && (i == 0 || txt[i-1] != '\\')) {
|
||||
if(!in_italic) {
|
||||
if(!mdt.italic) {
|
||||
fprintf(fpto, "<i>");
|
||||
in_italic = 1;
|
||||
mdt.italic = 1;
|
||||
} else {
|
||||
fprintf(fpto, "</i>");
|
||||
in_italic = 0;
|
||||
mdt.italic = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (i + 1 < len && txt[i] == '*' && txt[i+1] == '*' && (i == 0 || txt[i-1] != '\\')) {
|
||||
if(mdt.bold) {
|
||||
fprintf(fpto, "<b>");
|
||||
mdt.bold = 1;
|
||||
i++;
|
||||
} else {
|
||||
fprintf(fpto, "</b>");
|
||||
mdt.bold = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
else if (txt[i] == '>' && (i == 0 || txt[i-1] != '\\')) {
|
||||
if(!mdt.quote) {
|
||||
fprintf(fpto, "<blockquote>");
|
||||
mdt.quote = 1;
|
||||
} else {
|
||||
fprintf(fpto, "</blockquote>");
|
||||
mdt.quote = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
fputc(txt[i], fpto);
|
||||
}
|
||||
}
|
||||
|
||||
if(in_italic) {
|
||||
if(mdt.italic) {
|
||||
fprintf(fpto, "</i>");
|
||||
};
|
||||
if(mdt.bold) {
|
||||
fprintf(fpto, "</b>");
|
||||
}
|
||||
if(mdt.quote) {
|
||||
fprintf(fpto, "</blockquote>");
|
||||
}
|
||||
if(mdt.headingone) {
|
||||
fprintf(fpto, "</h1>");
|
||||
}
|
||||
fprintf(fpto, "</p>\n");
|
||||
in_italic = 0;
|
||||
mdt.italic = mdt.bold = mdt.quote = mdt.headingone = 0;
|
||||
}
|
||||
|
||||
fprintf(fpto, "</body>\n</html>");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user