Advertisement
BrokeMansPC

Untitled

Jun 8th, 2020
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     //arguement checker, program exits if an error happens
  8.     switch(argc) {
  9.     case 1:
  10.         printf("DEBUG: No params\n");
  11.         return 10;
  12.         break;
  13.     case 2:
  14.         printf("DEBUG: No source file\n");
  15.         return 11;
  16.         break;
  17.     case 3:
  18.         printf("DEBUG: 3 Args found, executing case 3.\n");
  19.         if (*argv[1] == 'c') //tells program to convert KovCode to SL YAML
  20.             convertToYAML(argv[2], "blank");
  21.         else if (*argv[1] == 'd') //tells program to convert SL YAML to KovCode
  22.             convertToKovCode(argv[2], "blank");
  23.         else {
  24.             printf("Invalid operation mode");
  25.             return 12;
  26.         }
  27.         break;
  28.     case 4:
  29.         printf("DEBUG: 4 Args found, executing case 4.\n");
  30.         if (*argv[1] == 'c') //tells program to convert KovCode to SL YAML
  31.             convertToYAML(argv[2], argv[3]);
  32.         else if (*argv[1] == 'd') //tells program to convert SL YAML to KovCode
  33.             convertToKovCode(argv[2], argv[3]);
  34.         else {
  35.             printf("Invalid operation mode");
  36.             return 12;
  37.         }
  38.         break;
  39.  
  40.  
  41.  
  42.     }
  43.     return 0;
  44. }
  45.  
  46. int convertToYAML(char source[], char destination[]) {
  47.     char var[50];
  48.     char *buff;
  49.     char cursor;
  50.     char *value;
  51.     char regularMark[] = ":%:"; //variable_name: value
  52.     char array1Mark[] = ":%1:"; //variable_name: - 7777 -7778 -7779 etc
  53.     char array2Mark[] = ":%2:"; //variable_name: [1,2,3,4,5,6]
  54.     int i;
  55.     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
  56.     //This is probably a shitty way to get enough space to store values for writing, I don't know any other way.
  57.     buff = (char *) calloc(1024, sizeof(char));
  58.     printf("DEBUG: Variables initialized, opening file stream targeting %s", source);
  59.     FILE *fp = fopen(source, "r");
  60.     FILE *of;
  61.  
  62.     if(strcmp(destination, "blank") == 0) {
  63.     of = fopen("output.txt", "w");
  64.     } else {
  65.     of = fopen(destination, "w");
  66.     }
  67.  
  68.     cursor = fgetc(fp);
  69.     while (!feof(fp)){
  70.             i = 0;
  71.  
  72.         while(cursor != '\n') {
  73.             *(buff+i) = cursor;
  74.             cursor = fgetc(fp);
  75.             i++;
  76.         }
  77.         *(buff+i+1) = '\0';
  78.  
  79.  
  80.         if (strstr(buff, regularMark) != 0)
  81.             toYAMLKeyPair(&buff, strstr(buff, regularMark), of);
  82.         /*else if(strstr(buff, array1Mark) != 0)
  83.             toYAMLArray1(&buff, strstr(buff, array1Mark), of);
  84.         else if(strstr(buff, array2Mark) != 0)
  85.             toYAMLArray2(&buff, strstr(buff, array2Mark), of);
  86.         else
  87.             return 14;*/
  88.     }
  89.     fclose(fp);
  90.     fclose(of);
  91. }
  92.  
  93. int toYAMLKeyPair(char *rawLine, char *separatorLoc, FILE *output) {
  94.     int i = 0;
  95.     printf("%c", *rawLine);
  96.     while((rawLine+i) != separatorLoc) {
  97.         printf("%c", *(rawLine+i));
  98.         fprintf(output, "%c", *(rawLine+i));
  99.         i++;
  100.     }
  101.  
  102. }
  103.  
  104. /*int toYAMLArray1(){
  105.  
  106. }
  107.  
  108. int toYAMLArray2(){
  109.  
  110. }*/
  111.  
  112. int convertToKovCode(char *source, char *destination) {
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement