Skip to content

Commit

Permalink
Added Append and Write Commands (-A, -W), Now Version 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarouf committed Mar 6, 2021
1 parent 050ffa5 commit 0870ec9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
65 changes: 56 additions & 9 deletions ccc-extended.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ typedef struct colALLEncompass
int size;
}CCC_Color_t;

#define WRITE_FILENAME_SIZE 64
char WRITE_FILENAME[WRITE_FILENAME_SIZE] = "tmp_colortxt";

//______CCC_COMMANDS_START_______//
typedef float(*ccc_command_t)(float);
Expand Down Expand Up @@ -545,7 +547,9 @@ static void ccc_Manupilation(char *arg[], int at, int count, colrgb_t *rgb, colh
if (arg[at + 1] == NULL)
return;

char *token = strtok(arg[at+1], ",");
char *tmpstff = malloc(64);
sprintf(tmpstff, "%s", arg[at+1]);
char *token = strtok(tmpstff, ",");

/* Token types (char = actual variable it is representing)
i = it
Expand Down Expand Up @@ -629,10 +633,12 @@ static void ccc_Manupilation(char *arg[], int at, int count, colrgb_t *rgb, colh
token = strtok(NULL, ",");

}
}

free(tmpstff);
}
}


colrgb_t tmpRGB = *rgb;
colhsv_t tmpHSV = *hsv;

Expand Down Expand Up @@ -701,6 +707,20 @@ static char * ccc_ReadFromFile(char *file, int * string_size)
*string_size = fsize;
return string;
}
static void ccc_WriteToFile(char *fname, char md[], char pattern[],char **ls, int x, int y)
{
FILE *f = fopen(fname, md);
if (f == NULL)
return;

for (int i = 0; i < y; ++i)
{
fprintf(f, pattern, ls[i]);
}
fclose(f);

}


// Break String into List of String (Into Tokens)
static int ccc_BreakStringInto2DString_ASTOKENS (char ** buffer2D ,int buffXsize, int buffYsize, char *buffer, char *token_breaker)
Expand Down Expand Up @@ -801,6 +821,7 @@ static void ccc_RunFile(char * file, CCC_Color_t color)
}

// Main Command Phrasing

static int ccc_commandPhrasing(char *arg[], int count, CCC_Color_t color)
{
// Create Temperory for Hard Reset.
Expand Down Expand Up @@ -916,6 +937,27 @@ static int ccc_commandPhrasing(char *arg[], int count, CCC_Color_t color)
ccc_RunFile(arg[i+1], color);
}
break;
case 'A':
if (arg[i+1] != NULL)
{
snprintf(WRITE_FILENAME, WRITE_FILENAME_SIZE ,"%s", arg[i+1]);
ccc_WriteToFile(WRITE_FILENAME, "a", "%s \n" , &arg[1], 0, count-3);
printf("%s\n", arg[5]);
} else {
ccc_WriteToFile(WRITE_FILENAME, "a", "%s \n" , &arg[1], 0, count-3);
}
break;
case 'W':
if (arg[i+1] != NULL)
{
snprintf(WRITE_FILENAME, WRITE_FILENAME_SIZE ,"%s", arg[i+1]);
ccc_WriteToFile(WRITE_FILENAME, "w", "%s \n" , &arg[1], 0, count-3);
printf("%s\n", arg[5]);
} else {
ccc_WriteToFile(WRITE_FILENAME, "w", "%s \n" , &arg[1], 0, count-3);
}
break;
// Copy Color
case 'C':
if (arg[i+1] != NULL)
{
Expand Down Expand Up @@ -962,18 +1004,23 @@ static void ccc_interactive_mode (CCC_Color_t color)

while (!quit)
{
color_set(255, 0, 0); printf("%d", At);
color_set(0, 255, 0); printf(">");
color_set(0, 0, 255); printf("> ");

color256_set(1); printf("%d", At);
color256_set(4); printf(">");
color256_set(3); printf("> ");
color_reset();
color256_set(15);

// Read From User, `%[^\n]%*c` for Taking in Space-seperated Tokens
scanf("%[^\n]%*c", buffer);

// Check if User typed `\q` to quit
if (buffer[0] == '\\' && buffer[1] == 'q')
if (buffer[0] == '\\')
{
quit = 1;
if (buffer[1] == 'q')
{
quit = 1;
}
}

// Read from user-input buffer, breaks into token convert's in Array of String. Returns nos. of Token read.
Expand All @@ -992,8 +1039,8 @@ CCC_Color_t color_init_empty(int size)
{
return (CCC_Color_t) {
.size = size,
.rgb = malloc(sizeof(colrgb_t) * size),
.hsv = malloc(sizeof(colhsv_t) * size)
.rgb = calloc(size, sizeof(colrgb_t)),
.hsv = calloc(size, sizeof(colhsv_t))
};
}

Expand Down
4 changes: 3 additions & 1 deletion ccc_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ZAKAROUF_CCC_DEFINITION
/*----------------------------*/

#define ZAKAROUF_CCC_VERSION "0.2.0"
#define ZAKAROUF_CCC_VERSION "0.2.3"
#define ZAKAROUF_CCC_YEAR "2021-2022"
#define ZAKAROUF_CCC_HOSTPAGE "github.com/zakarouf/colorcodeconverter"

Expand Down Expand Up @@ -40,6 +40,8 @@
" -C [Value], Copy Color Value To self\n"\
"\n"\
" -F [FILENAME], Read Commnads From A File\n"\
" -A [FILENAME], Append The Commands to File, If unspecified Last File is Used\n"\
" -W [FILENAME], Write The Commands to File, If unspecified Last File is Used\n"\
"\n"\
"Examples:\n"\
\
Expand Down
4 changes: 2 additions & 2 deletions color.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
printf("\x1b[38;2;%d;%d;%d;48;2;%d;%d;%dm", r, g, b, br, bg, bb)

#define color256_set(code)\
printf("\x1b[38;5;%d", code)
printf("\x1b[38;5;%dm", code)

#define color256B_set(code)\
printf("\x1b[48;5;%d", code)
printf("\x1b[48;5;%dm", code)

#endif

0 comments on commit 0870ec9

Please sign in to comment.