Hi Viliam,

> ++void
> ++saveSession(void)
> ++{
> ++    FILE *fw = fopen(SESSION_FILE, "w");
> ++    for (Client *c = selmon->clients; c != NULL; c = c->next) { // get all 
> the clients with their tags and write them to the file
> ++            fprintf(fw, "%lu %u
> ", c->win, c->tags);
> ++    }
> ++    fclose(fw);
> ++}

`fw` should be checked for NULL to prevent surprises.
The line break in fprintf(3) is unnecessary, as well as the curley brackets.

> ++
> ++void
> ++restoreSession(void)
> ++{
> ++    // restore session
> ++    FILE *fr = fopen(SESSION_FILE, "r");
> ++    if (!fr)
> ++            return;
> ++
> ++    char *str = malloc(23 * sizeof(char)); // allocate enough space for 
> excepted input from text file
> ++    while (fscanf(fr, "%[^
> ] ", str) != EOF) { // read file till the end
> ++            long unsigned int winId;
> ++            unsigned int tagsForWin;
> ++            int check = sscanf(str, "%lu %u", &winId, &tagsForWin); // get 
> data
> ++            if (check != 2) // break loop if data wasn't read correctly
> ++                    break;
> ++            
> ++            for (Client *c = selmon->clients; c ; c = c->next) { // add 
> tags to every window by winId
> ++                    if (c->win == winId) {
> ++                            c->tags = tagsForWin;
> ++                            break;
> ++                    }
> ++            }
> ++    }
> ++
> ++    for (Client *c = selmon->clients; c ; c = c->next) { // refocus on 
> windows
> ++            focus(c);
> ++            restack(c->mon);
> ++    }
> ++
> ++    for (Monitor *m = selmon; m; m = m->next) // rearrange all monitors
> ++            arrange(m);
> ++
> ++    free(str);
> ++    fclose(fr);
> ++    
> ++    // delete a file
> ++    remove(SESSION_FILE);
> ++}

You should *really* check the return value of malloc(3).
dwm even provides a function, ecalloc(), which you could use here.
You might consider dropping `sizeof(char)`, since `char` is defined
to always have a size of one. But I'd let the readability point count in this 
case.

The line break in fscanf(3) is unnecessery, too.


Some notes on the style:
Initial declarations in `for` loops shouldn't be used.
The same applies to C99 comments.
You also mix up a lot of declarations and code. Consider splitting them up a 
bit more

Also, think about what your comments try to document.
It looks like you're commenting for the sake of commenting.

-- 
Best Regards,
Tom Schwindl

Reply via email to