hi, i'm trying to make a zsh-like shell for windows, but i'm having some trouble to do command parsing, pipe handling, etc on windows because every tutorial i found on the internet only works for linux, and i want to do the command parsing part first before the rest.
is there any way to do at least the command parsing part on windows? here's my code: https://pastebin.com/nSDkZ9D2
You may want to consider handling each keypress interactively to support command completion. You'll need to use platform specific features for this, plus wide character support.
something i could do is to use the zsh source code as the base for my code, instead of trying to convert the code to windows.
well, technically i'm converting the code to windows, but you got the point.
Cygwin has a zshell, and I think most if not all of their source code is out there on the web. Could study it but its probably a complicated port of unix source code.
The cygwin port won't help, it's probably just the Linux code compiled against the cygwin runtime. So the code won't need to be ported.
When all this port to Windows business started, GNU tools were rewritten for Windows and ran natively. There was the MKS Toolkit that did what Cygwin does, present a Unix layer for Windows. But that was a commercial product (money, licence, ...). Redhat worked on cygwin, and the rest is history. Most Unix apps now run on Windows under some kind of Unix emulation, like cygwin.
You're proposing writing a native zsh. It's a daunting task. You could start with your own Bourne Shell, and use the experience gained from that for your zsh. It's not a trivial task.
i could start by using the debian almquist shell source, and then, in the future, use the zsh source code as the base, so it would look like a bit mixed between two different shells.
There's lots of stuff in a shell, much of which you're probably not aware of right now. I suggest you start with one feature at a time, starting with the ability to start a program. This way you'll become more knowledgeable about all shells.
You'll also learn about differences between fundamental things in both platforms that you'd not have considered before; like controlling terminals in Unix, and controlling consoles in Windows, differences in process creation and management, IPC, security, ...
It's not a waste of time, even if you don't finish it.
My best suggestion is to learn how to write a parser. YACC (or BISON if using GNU) is a great tool. Very useful in writing command parsers, languages and interpreters.
At the simplest level a parser takes input (text) tokens and converts them to "productions". A production is a combination of one or more tokens that represents an element of a command or language. Productions are combined and reduced until the entire input has been processed.