Created
March 14, 2015 21:35
-
-
Save cf/02ae3f8157fbb6066ccd to your computer and use it in GitHub Desktop.
CCJS Website Designer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
-- Imports from msvcrt -- | |
strlen | |
calloc | |
memset | |
malloc | |
memcpy | |
free | |
printf | |
system | |
strtok | |
gets | |
atoi | |
getchar | |
strcpy | |
fopen | |
fclose | |
fwrite | |
*/ | |
char * titlePtr; | |
char * logoUrl; | |
char * bodyContent; | |
char * bodyBackground; | |
char * fontFamily; | |
char * textColor; | |
int displayMenu(char* title, char* optionsTemplate) | |
{ | |
system("cls"); | |
int titleLength=strlen(title); | |
char* padDash=calloc(titleLength+1,1); | |
memset(padDash,45,titleLength);//The ascii value of - is 45 | |
int optionsLength=strlen(optionsTemplate)+1; | |
char * options=malloc(optionsLength); | |
memcpy(options,optionsTemplate,optionsLength); | |
printf("--------%s--------\n",padDash); | |
printf("------[ %s ]------\n",title); | |
printf("--------%s--------\n\n",padDash); | |
printf("Options:\n0: Return Home\n"); | |
free(padDash); | |
int ctr=1; | |
char * curOption=strtok(options,"|"); | |
while(curOption!=0) | |
{ | |
printf("%d: %s\n",ctr, curOption); | |
curOption=strtok(0,"|"); | |
ctr+=1; | |
} | |
free(options); | |
int buf=malloc(256); | |
int sel=-1; | |
while(sel>=ctr||sel<0) | |
{ | |
printf("\nYour Selection: "); | |
gets(buf); | |
sel=atoi(buf); | |
} | |
free(buf); | |
return sel; | |
} | |
void editTitle() | |
{ | |
system("cls"); | |
printf("-- Title Editor --\nCurrent Tile: %s\nPlease enter the new page title below:\nPage Title: ",titlePtr); | |
gets(titlePtr); | |
while(strlen(titlePtr)<1) | |
{ | |
printf("\nPage Title: "); | |
gets(titlePtr); | |
} | |
printf("Page title set to '%s'!, press Enter to continue...\n",titlePtr); | |
getchar(); | |
} | |
void editLogo() | |
{ | |
system("cls"); | |
printf("-- Logo Editor --\nCurrent Logo URL: %s\nPlease enter the new url for the site logo below:\nLogo URL: ",logoUrl); | |
gets(logoUrl); | |
while(strlen(logoUrl)<1) | |
{ | |
printf("\nLogo URL: "); | |
gets(logoUrl); | |
} | |
printf("Logo url set to '%s'!, press Enter to continue...\n",logoUrl); | |
getchar(); | |
} | |
void editBody() | |
{ | |
system("cls"); | |
printf("-- Body Text Editor --\nPlease enter the new body text for the site below:\nBody Text: "); | |
gets(bodyContent); | |
while(strlen(bodyContent)<1) | |
{ | |
printf("\nBody Text: "); | |
gets(bodyContent); | |
} | |
printf("Body content set to '%s'!, press Enter to continue...\n",bodyContent); | |
getchar(); | |
} | |
void editBackground() | |
{ | |
system("cls"); | |
printf("-- Background Editor --\nCurrent Value: %s\nPlease enter in the CSS color value for the site background below:\nBackground Color: ",bodyBackground); | |
gets(bodyBackground); | |
while(strlen(bodyBackground)<1) | |
{ | |
printf("\nBackground Color: "); | |
gets(bodyBackground); | |
} | |
printf("Background Color set to '%s'!, press Enter to continue...\n",bodyBackground); | |
getchar(); | |
} | |
void editColor() | |
{ | |
system("cls"); | |
printf("-- Text Color Editor --\nCurrent Text Color: %s\nPlease enter in the CSS color value for the site text below:\nText Color: ",textColor); | |
gets(textColor); | |
while(strlen(textColor)<1) | |
{ | |
printf("\nText Color: "); | |
gets(textColor); | |
} | |
printf("Text Color set to '%s'!, press Enter to continue...\n",textColor); | |
getchar(); | |
} | |
void editFont() | |
{ | |
system("cls"); | |
printf("-- Font Family Editor --\nCurrent Font: %s\nPlease enter in the default font for the site text below:\nFont Name: ",fontFamily); | |
gets(fontFamily); | |
while(strlen(fontFamily)<1) | |
{ | |
printf("\nFont Name: "); | |
gets(fontFamily); | |
} | |
printf("Default font set to '%s'!, press Enter to continue...\n",fontFamily); | |
getchar(); | |
} | |
void saveFile() | |
{ | |
system("cls"); | |
printf("Writing to file 'index.html'...\n"); | |
int file=fopen("index.html","w"); | |
fwrite("<!DOCTYPE html><html><head><meta charset='utf-8'><title>",1,56,file); | |
fwrite(titlePtr,1,strlen(titlePtr),file); | |
fwrite("</title><style type='text/css'>body{color:",1,42,file); | |
fwrite(textColor,1,strlen(textColor),file); | |
fwrite(";background:",1,12,file); | |
fwrite(bodyBackground,1,strlen(bodyBackground),file); | |
fwrite(";font-family:",1,13,file); | |
fwrite(fontFamily,1,strlen(fontFamily),file); | |
fwrite(";position:absolute;left:0;top:0;padding:0;margin:0;width:100%;height:100%;}#logo{position:relative;display:block;top:30px;left:17%;}#main{position:relative;display:block;top:20px;left:15%;width:60%;padding-left:5%;padding-right:5%;padding-top:30px;padding-bottom:30px;background:#fff;min-height:500px;}</style></head><body><img id='logo' src='",1,343,file); | |
fwrite(logoUrl,1,strlen(logoUrl),file); | |
fwrite("' /><br /><div id='main'>",1,25,file); | |
fwrite(bodyContent,1,strlen(bodyContent),file); | |
fwrite("</div></body></html>",1,20,file); | |
fclose(file); | |
printf("File saved to index.html!\nPress enter to continue..."); | |
getchar(); | |
} | |
void styleMenu() | |
{ | |
int sel=displayMenu("Style Editor","Change Page Background|Change Text Color|Change Font Family"); | |
if(sel==0) | |
{ | |
return; | |
}else if(sel==1) | |
{ | |
editBackground(); | |
}else if(sel==2) | |
{ | |
editColor(); | |
}else if(sel==3) | |
{ | |
editFont(); | |
} | |
styleMenu(); | |
} | |
void homeMenu() | |
{ | |
int sel=displayMenu("Webpage Editor","Edit the Page Title|Change the Logo|Edit Body Text|Open Style Editor|Save index.html|Quit Editor"); | |
if(sel==1) | |
{ | |
editTitle(); | |
}else if(sel==2){ | |
editLogo(); | |
}else if(sel==3){ | |
editBody(); | |
}else if(sel==4){ | |
styleMenu(); | |
}else if(sel==5){ | |
saveFile(); | |
}else if(sel==6) | |
{ | |
return; | |
} | |
homeMenu(); | |
} | |
int main() | |
{ | |
titlePtr = calloc(512,1); | |
strcpy(titlePtr,"Default Title"); | |
logoUrl=calloc(512,1); | |
strcpy(logoUrl,"http://cf.gy/demoLogo.png"); | |
bodyContent=calloc(4096,1); | |
strcpy(bodyContent,"Sample Content<br />I <b>love</b> html!<br />Made by Carter Feldman! =)"); | |
bodyBackground=calloc(256,1); | |
strcpy(bodyBackground,"#eee"); | |
fontFamily=calloc(128,1); | |
strcpy(fontFamily,"Arial"); | |
textColor=calloc(48,1); | |
strcpy(textColor,"#333"); | |
system("cls"); | |
homeMenu(); | |
free(titlePtr); | |
free(logoUrl); | |
free(bodyContent); | |
free(bodyBackground); | |
free(fontFamily); | |
free(textColor); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment