Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- //arguement checker, program exits if an error happens
- switch(argc) {
- case 1:
- printf("DEBUG: No params\n");
- return 10;
- break;
- case 2:
- printf("DEBUG: No source file\n");
- return 11;
- break;
- case 3:
- printf("DEBUG: 3 Args found, executing case 3.\n");
- if (*argv[1] == 'c') //tells program to convert KovCode to SL YAML
- convertToYAML(argv[2], "blank");
- else if (*argv[1] == 'd') //tells program to convert SL YAML to KovCode
- convertToKovCode(argv[2], "blank");
- else {
- printf("Invalid operation mode");
- return 12;
- }
- break;
- case 4:
- printf("DEBUG: 4 Args found, executing case 4.\n");
- if (*argv[1] == 'c') //tells program to convert KovCode to SL YAML
- convertToYAML(argv[2], argv[3]);
- else if (*argv[1] == 'd') //tells program to convert SL YAML to KovCode
- convertToKovCode(argv[2], argv[3]);
- else {
- printf("Invalid operation mode");
- return 12;
- }
- break;
- }
- return 0;
- }
- int convertToYAML(char source[], char destination[]) {
- char var[50];
- char *buff;
- char cursor;
- char *value;
- char regularMark[] = ":%:"; //variable_name: value
- char array1Mark[] = ":%1:"; //variable_name: - 7777 -7778 -7779 etc
- char array2Mark[] = ":%2:"; //variable_name: [1,2,3,4,5,6]
- int i;
- value = (char *) calloc(1024, sizeof(char)); //needs to be rewritten to wchar_t to allow for UTF encoded texts, this is working fine for now. ONLY ANSI ENCODED TEXT FILES WORK
- //This is probably a shitty way to get enough space to store values for writing, I don't know any other way.
- buff = (char *) calloc(1024, sizeof(char));
- printf("DEBUG: Variables initialized, opening file stream targeting %s", source);
- FILE *fp = fopen(source, "r");
- FILE *of;
- if(strcmp(destination, "blank") == 0) {
- of = fopen("output.txt", "w");
- } else {
- of = fopen(destination, "w");
- }
- cursor = fgetc(fp);
- while (!feof(fp)){
- i = 0;
- while(cursor != '\n') {
- *(buff+i) = cursor;
- cursor = fgetc(fp);
- i++;
- }
- *(buff+i+1) = '\0';
- if (strstr(buff, regularMark) != 0)
- toYAMLKeyPair(&buff, strstr(buff, regularMark), of);
- /*else if(strstr(buff, array1Mark) != 0)
- toYAMLArray1(&buff, strstr(buff, array1Mark), of);
- else if(strstr(buff, array2Mark) != 0)
- toYAMLArray2(&buff, strstr(buff, array2Mark), of);
- else
- return 14;*/
- }
- fclose(fp);
- fclose(of);
- }
- int toYAMLKeyPair(char *rawLine, char *separatorLoc, FILE *output) {
- int i = 0;
- printf("%c", *rawLine);
- while((rawLine+i) != separatorLoc) {
- printf("%c", *(rawLine+i));
- fprintf(output, "%c", *(rawLine+i));
- i++;
- }
- }
- /*int toYAMLArray1(){
- }
- int toYAMLArray2(){
- }*/
- int convertToKovCode(char *source, char *destination) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement