Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <string.h>
- #include <stdlib.h>
- #define YEAR_START 1900
- #ifdef _WIN32
- #define WINDOWS 1
- #else
- #define WINDOWS 0
- #endif
- typedef char* string;
- int main(int argc, string argv[])
- {
- // getting the current date
- time_t t = time(NULL);
- struct tm date = *localtime(&t);
- string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- string month = months[date.tm_mon];
- int day = date.tm_mday;
- int year = date.tm_year + YEAR_START;
- char cd = '*';
- // checking to make sure usage is correct
- if (argc < 2 && argc > 3) {
- printf("Usage: ./genheader filename.c <-c or -m, default=-c>\n");
- return 1;
- }
- // selecting the right comment delimeter for the file type
- if (argc == 3 && strlen(argv[2]) == 2)
- {
- char user_option = argv[2][1];
- switch (user_option)
- {
- case 'c':
- cd = '*';
- break;
- case 'm':
- cd = '#';
- break;
- default:
- break;
- }
- }
- string file_name = argv[1];
- FILE *fout = fopen(file_name, "w");
- fprintf(fout, "/%c %s\n %c by Name\n %c %s %i, %i\n %c\n %c Program Assignment: P##\n %c Due Date: \n %c Program Description\n %c/\n\n#include <stdio.h>\n\n/%c\n %c\t\tMain Function\n %c/\nint main(void)\n{\n\n\treturn 0;\n}\n",
- cd, file_name, cd, cd, month, day, year, cd, cd, cd, cd, cd, cd, cd, cd);
- fclose(fout);
- // if we're not running Windows creating a makefile, we use head and cut utilities to trim our file
- if (!WINDOWS && cd == '#')
- {
- char cmd[128];
- snprintf(cmd, 128," head -3 %s | cut -c 2- > %s", file_name, file_name);
- printf("Running: %s\n", cmd);
- system(cmd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement