WriteLine(); being funky

I'm writing a linker and for some reason print is doing REALLY weird things, as you see in the image
string filedir = Path.GetDirectoryName(mainfile);
filedir = filedir + "\\";
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = filedir + includefile;
//check if the file exists
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (includedfiles.Contains(line.Split(' ')[1]))
{
//if the included file is not in pragmaoncefiles, then open it and append to entirenewfile withouth the includes
if (!pragmaoncefiles.Contains(line.Split(' ')[1]))
{
string[] filecontents = File.ReadAllLines(line.Split(' ')[1]);
foreach (string fileline in filecontents)
{
if (fileline.Contains("%include"))
{
continue;
}
entirenewfile.Append(fileline);
}
}
continue;
}
string include = line.Split(' ')[1];
//remove quotes
include = include.Replace("\"", "");
includes.Add(include);
string filedir = Path.GetDirectoryName(mainfile);
filedir = filedir + "\\";
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = filedir + includefile;
//check if the file exists
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (includedfiles.Contains(line.Split(' ')[1]))
{
//if the included file is not in pragmaoncefiles, then open it and append to entirenewfile withouth the includes
if (!pragmaoncefiles.Contains(line.Split(' ')[1]))
{
string[] filecontents = File.ReadAllLines(line.Split(' ')[1]);
foreach (string fileline in filecontents)
{
if (fileline.Contains("%include"))
{
continue;
}
entirenewfile.Append(fileline);
}
}
continue;
}
string include = line.Split(' ')[1];
//remove quotes
include = include.Replace("\"", "");
includes.Add(include);
No description
69 Replies
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
This chunk has the code for printing
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
if (!File.Exists(fullincludefile))
{
//Throw error, file does not exist, cannot include, and the line number. then underline the line with ^^^
Console.WriteLine($"Error: File {fullincludefile} does not exist, cannot include, line {cline}");
Console.WriteLine();

Console.WriteLine(line);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(new string('^', line.Length - 1));
Console.ResetColor();
FailedLink = true;
}
leowest
leowest12mo ago
can you provide a bit more code explaining/showing what line is also to avoid issues I would change this bit
string filedir = Path.GetDirectoryName(mainfile);
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = Path.Combine(filedir, includefile);
string filedir = Path.GetDirectoryName(mainfile);
//get the include file
string includefile = line.Split(' ')[1];
//remove quotes
includefile = includefile.Replace("\"", "");
//replace / with \
includefile = includefile.Replace("/", "\\");
string fullincludefile = Path.Combine(filedir, includefile);
Depending what line is I might use different methods to get the filename this removes the need to add \\ at the end of filedir and potentially avoid duplicated empty dir
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Mainfile is passed here
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Hydro.Lexing;
using Hydro.Tokens;
using Hydro.Parsing;
using Hydro.Linking;
namespace Hydro
{
public class Program
{
public string gccpath = ".\\mingw64\\bin\\g++.exe";
public static void Main(string[] args)
{
HydroLinker linker = new HydroLinker(args[0]);
linker.Link();
if (linker.FailedLink)
{
Console.WriteLine("Linking failed");
}
else
{
Console.WriteLine("Linking succeeded");
}
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Hydro.Lexing;
using Hydro.Tokens;
using Hydro.Parsing;
using Hydro.Linking;
namespace Hydro
{
public class Program
{
public string gccpath = ".\\mingw64\\bin\\g++.exe";
public static void Main(string[] args)
{
HydroLinker linker = new HydroLinker(args[0]);
linker.Link();
if (linker.FailedLink)
{
Console.WriteLine("Linking failed");
}
else
{
Console.WriteLine("Linking succeeded");
}
}
}
}
it gets the file path and then check if it exists, pretty simple, then if it doesnt, it throws an error and for some reason print is screwing up
public void Link()
{
//open main file and get includes, then open those files and get includes, etc.
string mainfilecontents = File.ReadAllText(mainfile);
//get full path of main file
mainfile = Path.GetFullPath(mainfile);
string[] includes = getIncludes(mainfilecontents, mainfile);
}
public void Link()
{
//open main file and get includes, then open those files and get includes, etc.
string mainfilecontents = File.ReadAllText(mainfile);
//get full path of main file
mainfile = Path.GetFullPath(mainfile);
string[] includes = getIncludes(mainfilecontents, mainfile);
}
leowest
leowest12mo ago
I think the red checks u see are a powershell thing, try running your code from prompt instead I would assume % evaluates to something in powershell and its marking it as wrong syntax or something
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No, if you look at the code, It is there made by me Console.WriteLine(new string('^', line.Length - 1)); It all works fine, but for some reason it can't print right
leowest
leowest12mo ago
you mean this part not printing to the console?
No description
leowest
leowest12mo ago
or what is not right I might be missing something and have u tried it outside powershell to see if the result is the same out of curiosity
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Power shell shouldn’t be the issue, but I can try I don’t like cmd But if it works it works It is not a power shell issue, just tried
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Fixed it
No description
leowest
leowest12mo ago
yeah I am just rying to rule out the output being the issue
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
it was windows adding a "\r"
leowest
leowest12mo ago
ah from the line input yeah makes sense
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
I hate that, bash doesnt do that, but ol windows and it's \n\r
leowest
leowest12mo ago
u could just have a [1].Trim()
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
true ig but I've been programing on linux for a few weeks so I forgot
leowest
leowest12mo ago
yeah that was one of the reasons I was curious about what the line was because u were oddly removing some stuff from it
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
It was so It looked print friendly the path would look like this "..\..\..\standard\hello.hyd" plus "F:\Projects\Hydro\bin\debug\net8.0\..\..\..\standard\hello.hyd like that
leowest
leowest12mo ago
yeah that's awful
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
truly this "F:\Projects\Hydro\bin\debug\net8.0/../../../standard/hello.hyd" imagine that
leowest
leowest12mo ago
but if all u want is hyd files can't u just do a recursive file search on root and that gives u all hyd files with their respective full path
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
well it's a programming language
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"
![pragma] once
int main()
{
hello("Hello, world!");
}
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"
![pragma] once
int main()
{
hello("Hello, world!");
}
I only want to link what the user wants
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
leowest
leowest12mo ago
I see so, I guess you're doing - read file selected by user - get the includes from the top of that file - format the includes - verify the include exists
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
It doesn't get them from the top, it gets them from anywhere, and yes
leowest
leowest12mo ago
sure you read all lines for what starts with %include
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
yeah
leowest
leowest12mo ago
well glad you figured it out 😉
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
let me find one thing
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"

![pragma] once
int main()
{
%include "this.hyd"
hello("Hello, world!");
}
//Useless
%include "standard/uselessfile.hyd"
// Hydro Test Program
// This program is a simple test program for the Hydro language.
%include "standard/hello.hyd"

![pragma] once
int main()
{
%include "this.hyd"
hello("Hello, world!");
}
//Useless
%include "standard/uselessfile.hyd"
includes anywhere now let me make that file path and hope it works
leowest
leowest12mo ago
when u distribute the files do u expect it to be on the root of the executable or what
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
As in? It gets the path of the main hyd file and bases it off that
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
lets go
leowest
leowest12mo ago
ah I see so if I pass in the command line argument c:\x\y\z.hyd it will assume c:\x\y
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
yeah as the dir Im so proud bc I program in C and ASM so high level langs like this are a bit odd to me classes
leowest
leowest12mo ago
I mean u could have done it in c just as easily then
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
yeah but it's a lot more work bc I have to use malloc and free ALL the time I cant just do char* hello = "Hello"; char* world = "World"; hello += world; bc char pointers I have to use strcpy(hello, world, strlen(world)); or
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* response = malloc(100);
printf("Name?");
scanf("%s", response);
printf("Your name is: %s", response);
free(response);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* response = malloc(100);
printf("Name?");
scanf("%s", response);
printf("Your name is: %s", response);
free(response);
return 0;
}
that is C right there painful but useful
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
leowest
leowest12mo ago
I mean I know c and c++ all I am saying is that not a whole lot of more code to make it so incovinient
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
I know but memory management in a compiler is hard and C# just had so many features useful to it Plus I use C differently
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
I love my OSDEV
leowest
leowest12mo ago
GC is not always that great thou keep that in mind
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
I know but im lazy so C is too much work unless adhd hyperfixation
leowest
leowest12mo ago
var path = Path.GetDirectoryName(filename);
foreach (var line in File.ReadAllLines(filename))
{
if (string.IsNullOrEmpty(line)) continue;
if (line.Contains("%include"))
{
var library = line.Trim().Split(' ')[1].Replace("\"", "");
Console.WriteLine(Path.Combine(path, library));
}
}
var path = Path.GetDirectoryName(filename);
foreach (var line in File.ReadAllLines(filename))
{
if (string.IsNullOrEmpty(line)) continue;
if (line.Contains("%include"))
{
var library = line.Trim().Split(' ')[1].Replace("\"", "");
Console.WriteLine(Path.Combine(path, library));
}
}
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Looks clean
leowest
leowest12mo ago
reason I am not replacing / is because windows recognizes both patterns so not sure its actually needed. for folder path
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
I replace it so it looks nice to the user
leowest
leowest12mo ago
yeah normalized I would say but you probably have more checks in place in the event split fails or the result is empty I assume
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
:) this should answer ur question
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
it's a feature now if you make a typo sure that works
leowest
leowest12mo ago
split on the quote instead 😛
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
nahhhh I got a new feature
leowest
leowest12mo ago
what the a symbolizes in this new feature
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
if you make a typo it errors perfect
leowest
leowest12mo ago
Never heard of hydro got to check that later
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Not much rn
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
fear my void pointer
No description
leowest
leowest12mo ago
is that a language you're creating or
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
Yeah
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
yummy
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
aww
No description
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
it couldnt handle the void pointer
No description
leowest
leowest12mo ago
u would have to do something like
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
No description
leowest
leowest12mo ago
fixed code that gets the entrypoint and dereference it
🧵Stellar 🪡
🧵Stellar 🪡OP12mo ago
it's horrible and amazing putting the C in C#

Did you find this page helpful?