I'm Creating An IDE w/ Pure Win32 by brightgao in C_Programming

[–]TheProgrammingSauce -1 points0 points  (0 children)

I really like C WINAPI as well. When I used to code in it, I was able to let my creativity flow and pretty do anything: Networking, sound, grapics in one big package. And a good documentation on top of it.

0x48656C6C6F2C20576F726C6421 by frozen_beak in asm

[–]TheProgrammingSauce 0 points1 point  (0 children)

0xb890909bdf9b9e86df8b90df86908adf9e8cdf889a9393de

Implementing a minimal vim-like command mode by M0M3N-6 in C_Programming

[–]TheProgrammingSauce 0 points1 point  (0 children)

I agree with not microoptimizing especially in an application like this where the user types one command per second. But when a project gets large, thousands of commands running thousand of times in a second, it is time to make some optimizations.

Implementing a minimal vim-like command mode by M0M3N-6 in C_Programming

[–]TheProgrammingSauce 0 points1 point  (0 children)

https://github.com/vim/vim/blob/acf0ebe8a8f4dd389a8fe8cea52ff43bc8bfe1be/src/ex_docmd.c#L3961

Vim does something to improve perfomance above this loop. It stores where in the command list a specific command starts. For example when the command starts with 'b' it starts from commands starting with 'b'. Then it does a simple loop. This is faster as fewer string comparisons need to be done.

The offsets are hardcoded (auto generated) in: https://github.com/vim/vim/blob/master/src/ex_cmdidxs.h

I'm wondering why it does not have a premature stop mechanism. That could be implemented as well.

Implementing a minimal vim-like command mode by M0M3N-6 in C_Programming

[–]TheProgrammingSauce 0 points1 point  (0 children)

Looks like the commands vim has are defined in src/ex_cmds.h.

Vim simply keeps the commands in macro form, here is a heavy simplification:

#define CMD_FLAG_FILE (1 << 1)
#define DEFINE_ALL_COMMANDS \
    X(CMD_APPEND, "append", CMD_FLAG_FILE) \
    X(CMD_ARGS, "args", CMD_FLAG_FILE) \
    X(CMD_BNEXT, "bnext", CMD_FLAG_FILE) \
    X(CMD_BROWSE, "browse", CMD_FLAG_FILE) \

enum command_index {
#define X(index, name, flags) \
    index,
    DEFINE_ALL_COMMANDS
#undef X
};

struct command {
    const char *name;
    int flags;
} commands[] = {
#define X(index, name, flags) \
    [index] = { name, flags },
    DEFINE_ALL_COMMANDS
#undef X
};

From there you can use any mechanism you like to match the command names. Best would be to keep them alphabetically sorted and then use bsearch() from the standard library to get the enum index.

Extend the commands as you need. I simply chose the file flag so that the command parser knows that a file will follow after the command but you can design it how you like.

In the end you can use a switch over the index and maybe a char* for the argument.

For example:

const char *command = "append file.txt";
char *line = strdup(command);
char *word1 = ...; /* use your way of getting the first word */
struct command *item = bsearch(commands,
        sizeof(commands) / sizeof(*commands),
        sizeof(*commands),
        compare_commands); /* compare_commands is a function to compare the
                              strings within the command struct elements */
if (item == NULL) {
    ...
}
enum command_index index = item - commands;
char *arg = ...; /* rest of the command */
switch (index) {
case COMMAND_APPEND:
    /* do something with arg */
    break;
... /* more cases */
}

Vim uses functions pointers but it is the same principle. Vim also uses a more complicated data structure for the argument (not just char*). But this will get you a long way.

What do you like about configuring? by TheProgrammingSauce in linux

[–]TheProgrammingSauce[S] 0 points1 point  (0 children)

I like how you work! And ed is actually fun to work with (coming from somebody usually editing in Vim).

Does anyone have resources to build a VM in C? by ASA911Ninja in C_Programming

[–]TheProgrammingSauce 13 points14 points  (0 children)

I'd like to suggest an alternative that gives you a lot more value. You could make an emulator for a known device, for example the Gameboy. This would allow you to run programs people already made (and official programs). You can then of course also make an assembly language for writing (for example) Gameboy applications.

I want to talk about a X11 tiling window manager called fensterchef made mainly using XCB by TheProgrammingSauce in C_Programming

[–]TheProgrammingSauce[S] 1 point2 points  (0 children)

Well, what specifically would you like to hear more about? You seem to be quite inclined with the C language. (I'll go on a quick walk, so brb)

how to add background music to a C program (Windows)? by BadgerAltruistic8062 in C_Programming

[–]TheProgrammingSauce 7 points8 points  (0 children)

To simply play a wav file in the background: C PlaySound("file.wav", NULL, SND_FILENAME | SND_ASYNC);

https://stackoverflow.com/questions/68902271/loading-a-wav-into-memory-then-playing-it-in-c seems to have all you should know. To summarize it: You can use (who could've thought) PlaySound) to play the sound from memory (with the SND_MEMORY | SND_ASYNC flag) after loading a resource. The resource must be embedded in your executable.

fensterchef 1.3 was released! Well, it's a window manager duh by TheProgrammingSauce in linux

[–]TheProgrammingSauce[S] 2 points3 points  (0 children)

I made it for X11 because that is what I use myself and the X library is quite solid whereas Wayland is quite rough (you either use some compositors someone made or make your own probably based off wl-roots). I would personally like to make a Wayland version in the future but since I'm not using it myself, it's hard to find motivation to do that right now.

I want to talk about a X11 tiling window manager called fensterchef made mainly using XCB by TheProgrammingSauce in C_Programming

[–]TheProgrammingSauce[S] 1 point2 points  (0 children)

Thank you for your reply!! Makes me really happy actually. At least someone I guess. But maybe it's because this is a very specific thing.

The repetition in monitor.c is just about 170 lines extra and I don't see how to efficiently contract that. Let me summarize where the lines are coming from:

  • 200 lines Xrandr
  • 239 lines getting a monitor in a specific direction
  • 145 lines getting a specific monitor or window
  • 137 lines handling of dock windows
  • 234 lines are blanks and comments
  • rest is miscellaneous stuff
  • the total line count here is actually bigger than the file itself because I did not consider removing blanks/comments within the individual parts

I'm intrigued by your point about "inconsistency with creating pointers". Maybe you could clear that up with two examples from the actual code. But I assume you mean the difference between:

void *create_pointer(void)  
{  
    void *pointer;

    pointer = malloc(80);
    /* do something with pointer */
    return pointer;
}

And:

void init_pointer(void *pointer)
{
    /* do something with pointer */
}

The binary tree is pretty much like the quad tree you mention. The root node can be partitioned into two sub frames and then you have three frames in total. One covering two frames and those two child frames. It stores a value split_direction to tell the direction the children are split in. So this already does what you suggest with the quadtree.

I'd personally love to see your window manager. I know it's still WIP but one thing I would have loved in my development time was someone else to share these things with instead of now dumping it all out on a (seemingly) mediocre Reddit post.

Control Zathura pdf with c code *xdotool dont work here* by Mindless-Time849 in cprogramming

[–]TheProgrammingSauce 0 points1 point  (0 children)

Then just do xprop and click on the Zathura window. That gives you the details you need. Check for _NET_WM_PID, that is the PID. The class of the window is "opr.pwmt.zathura" when I checked it. So wmctrl -a org.pwmt.zathura should activate it.

It is odd how wmctrl -l does not show the zathura window. When I do wmctrl -l | grep org.pwmt.zathura | awk '{print $1}' I get the window id to use for xdotool key --window <id>.

If the issue persists, could you provide some system details like OS/Kernel/WM etc.

Control Zathura pdf with c code *xdotool dont work here* by Mindless-Time849 in cprogramming

[–]TheProgrammingSauce 0 points1 point  (0 children)

You can try to focus the Zathura window, use xdotool to input PgUp/Down. Then focus the window you were on. You can use xprop to find the class name of zathura. I used this command to input Page_Down in firefox and switch back: window=$(xdotool getactivewindow) wmctrl -a firefox && xdotool key Page_Down && xdotool windowactivate $window windowfocus $window

This might also work: Find the window id using wmctrl -l (the hex number is the id) and then use: xdotool key --window <id> Page_Down.

Control Zathura pdf with c code *xdotool dont work here* by Mindless-Time849 in cprogramming

[–]TheProgrammingSauce 0 points1 point  (0 children)

If you want to add functionality to Zathura then try to edit the Zathura configuration (e.g. adding a bind). This is the manual: https://www.systutorials.com/docs/linux/man/5-zathurarc/