Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void pHelp();
- char* createString(int len);
- void notif(char *command);
- int main (int argc, char *argv[]) {
- if(argc !=2 || strcmp(argv[1], "--help") == 0) {
- pHelp();
- } else {
- notif(argv[1]);
- }
- return 0;
- }
- void notif (char* command) {
- int commLen = strlen(command);
- if(system(command) == 0) { //zero is success for _most_ UNIX binaries, but evaluates to false in C. so == 0 is necessary
- char* buff = createString(commLen +29);
- strcat(buff, "notif finished\" \"Command: '");
- strcat(buff, command);
- strcat(buff, "'\"");
- system(buff);
- } else {
- char* buff = createString(commLen +56);
- strcat(buff, "notif failed\" \"Command: '");
- strcat(buff, command);
- strcat(buff, "' did not execute as expected.\"");
- system(buff);
- }
- }
- char* createString(int len) {
- char* str = malloc(len +14); //Size of len, plus 1 for the string terminator plus the length of the string added in this method (13 currently)
- if (!str) { //if malloc returned NULL
- printf("notif couldn't free enough memory,\nterminating");
- exit(EXIT_FAILURE);
- }
- str[0] = '\0';
- strcat (str, "notify-send \""); //specific, because both times this function is used need this as start of the string
- return str;
- }
- void pHelp () {
- printf("usage: notif [CMND...]\n\tCMND being the command to loop over.\n\tCMND shoud be quoted if it contains whitespace characters.\n\n(note that command aliases are currently ignored.)\n\n'notif --help' displays this message\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement