Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eimon96 committed May 1, 2022
1 parent 4b7590f commit 4b8ed25
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion FileInputUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ unsigned int get_file_size(char fname[])
}

// open, read file, save content into string variable
void get_file_content(char fname[],char content[], unsigned int flen)
void get_file_content(char fname[],char content[])
{
FILE *fp;
fp = fopen(fname, "r");
Expand Down
70 changes: 34 additions & 36 deletions vbs2exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,47 @@ int main(int argc, char *argv[])
instructions();
exit(1);
}
else

// check argv[1l length
if (strlen(argv[1]) > 20)
{
// chech argv[1l length
if (strlen(argv[1]) > 20)
{
printf("Name must be 20 characters long max.");
exit(4);
}
printf("Name must be 20 characters long max.");
exit(4);
}

// get file name
strcpy(fname, argv[1]);
// get file name
strcpy(fname, argv[1]);

// add vbs extension if necessary
if (!check_vbs_extension(fname))
{
strcat(fname, ".vbs");
}
// add vbs extension if necessary
if (!check_vbs_extension(fname))
{
strcat(fname, ".vbs");
}

// check file existence
if (!file_exists(fname))
{
printf("File not found.");
exit(2);
}
// check file existence
if (!file_exists(fname))
{
printf("File not found.");
exit(2);
}

// count chars of file and malloc
flen = get_file_size(fname);
if (flen == 0)
{
printf("File is empty.");
exit(3);
}
fcontent = (char *) malloc((flen + 1)* (sizeof(char *)));
// content of the file is into the string now
get_file_content(fname, fcontent, flen);
// count chars of file and malloc
flen = get_file_size(fname);
if (flen == 0)
{
printf("File is empty.");
exit(3);
}

fcontent = (char *) malloc((flen + 1)* (sizeof(char *)));
// content of the file is into the string now
get_file_content(fname, fcontent);

// create the exe file
create_exe_file(fname, fcontent);
// create the exe file
create_exe_file(fname, fcontent);

// freedom
free(fcontent);
}
// freedom
free(fcontent);

return 0;
}
Expand Down

0 comments on commit 4b8ed25

Please sign in to comment.