Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment

2022-09-05 Thread BoQsc via Digitalmars-d-learn

On Sunday, 4 September 2022 at 22:05:24 UTC, ShadoLight wrote:

On Sunday, 4 September 2022 at 15:16:47 UTC, BoQsc wrote:


**Folder structure**

.\msvcr120.dll
.\folder1\HelloWorld.exe
.\folder2\HelloWorld.exe



You don't need to do this. msvcr120.dll is already shipped with 
the DMD compiler at 
[DMD-install-folder]\windows\bin64\msvcr120.dll. (It is also in 
[DMD-install-folder]\windows\bin). You can access it directly 
from there.


The problem is, D Language Compiler is not included along the 
Windows Operating System.
Neither msvcr120.dll is included along the Windows Operating 
System.

You have to download it. No other way.

How can you download it, if your .exe binary that has the 
functionality to download it, cannot even be started due to 
msvcr120.dll not existing on the operating system.


You can try to use pre-existing Command Line Utilities like 
bitsadmin (Windows 7), curl (Windows 10), but really how can you 
interact with them from within D Language Binary if it can't even 
launch.


You can try to write a batch script for all that.

I really do not want to write batch scripts for the rest of my 
life,

that's why I'm here in the D Language Forum.


Copy the DLL to C:\Windows\System32\


It required administrator privilegies and this is only a 
HelloWorld example
of the D language deployed on computers, where the D language is 
yet to be installed.


How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment

2022-09-04 Thread BoQsc via Digitalmars-d-learn

![HelloWorld](https://i.imgur.com/5BjVIU9.png)

**Folder structure**

.\msvcr120.dll
.\folder1\HelloWorld.exe
.\folder2\HelloWorld.exe


 Basic binaries produced by DMD.exe compiler require 
Microsoft Compiler Runtime DLL
As you might know that a basic D Language example 
`HelloWorld.exe` requires `msvcr120.dll` to work.



 Linking inverse recursively?
**To not include** `msvcr120.dll` into every `.exe` executable's 
`.\folder\` **and to not marginally increase the overall size of 
the project**: I'd like to link every `.\folder\.exe` binary to 
the `.\msvcr120.dll` dynamic library.


**Notice**
Launching the `.exe` binary with external script to change the 
`path` variable is not a solution.
I'd like the `.exe` binary to "know" and try to search for 
`.\msvcr120.dll` by itself after clicking it to launch.




Importing module from the perspective of submodule.

2022-07-02 Thread BoQsc via Digitalmars-d-learn
Is it possible to import module that is not in the module's 
current directory's folder or subfolders?


For example:

I want to import `somemodule2.d` and `somemodule3.d` into a 
**`somemodule.d`**


**.\somefolder\somemodule.d**
.\somemodule2.d
.\someotherfolder\somemodule3.d


What exact debugging information is added to the binary and how to parse it all?

2022-05-13 Thread BoQsc via Digitalmars-d-learn
Haven't used debuggers or debugged a lot just yet, but I've had 
this question in my mind and I'd like to inspect some debugging 
information manually. Are there some kind of documentation or 
specification and are there a lot of information that is hidden 
in a an average "debuggable" binary?


Re: DUB issues

2022-04-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote:

Hey All,

For some reason I cannot reset my password to get into dub 
(https://code.dlang.org/), after trying I never receive the 
email to reset my password.


I was unsure at first if I had signed up at all, but trying to 
make a new account tells me my email address is already in use.


Any ideas how to get into contact/fix this issue ?


I tried to look around and it seems that there are no direct 
contacts.
There is old inactive forum. 
https://forum.rejectedsoftware.com/groups/rejectedsoftware.dub/


You can try this general email: i...@rejectedsoftware.com
This one is for both vibe.d and dub.

If no response, there will be a need to try to contact the dub 
authors personally about this issue.


I think it's kind of frustrating. If there is a need, I can try 
to annoy them on the social media, maybe they'll turn up.


Collect the arguments of all the function calls at a compile time in the whole program.

2022-04-15 Thread BoQsc via Digitalmars-d-learn

Let's say I have this example program.
I want to get the arguments of all the `some_function();` in the 
whole program.
**Even if the scope of the function call is never executed.** 
(Ex. due to IF statement being negative.)


I tried to use `__traits` but it seems to not gather any 
information about function calls.

Or I'm missing something.


```
import std.stdio;
import std.traits;


void some_function(string argument){}


void main(){
  some_function("someargument1");
  some_function("someargument2");

  if (false){
some_function("someargument3");
  }


/* __traits allMembers does not print function calls.
 I tried to use allMembers of __traits, but it does not contain 
the function calls.

 Only the functions definitions/declarations inside a module.
*/
foreach(memberss; __traits(allMembers, mixin(__MODULE__))){
write(" ", isSomeFunction!(mixin(memberss)));
writeln(" \t", fullyQualifiedName!(mixin(memberss)));

}

```

```
```


Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn

On Thursday, 7 April 2022 at 12:51:26 UTC, Stanislav Blinov wrote:

On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote:


wchar_t* clang_string = cast(wchar_t *)"AA";


You're witnessing undefined behavior. "AA" is a string 
literal and is stored in the data segment. Mere cast to 
wchar_t* does not make writing through that pointer legal. 
Moreover, even if it was legal to write through it, that alone 
wouldn't be sufficient. From documentation of `wcsncat`:


The behavior is undefined if the destination array is not 
large enough for the contents of both str and dest and the 
terminating null wide character.


`wcsncat` does not allocate memory, it expects you to provide a 
sufficiently large mutable buffer. For example, like this:


```d
// ...
auto cls = new wchar_t[256];
cls[] = 0;
cls[0..10] = 'A';
wchar_t* clang_string = cls.ptr;
// ...
```


That is correct, the results are satisfying. I believe this 
thread is resolved.


```
import std.stdio;

@system void main(){

import std.utf: toUTF16z, toUTF16;
import core.stdc.wchar_   : wcsncat, wcslen, wprintf;
import core.stdc.stdlib   : wchar_t;
import core.sys.windows.winnt : LPCWSTR;


auto cls = new wchar_t[256];
cls[] = 0;
cls[0..10] = 'A';
wchar_t* clang_string = cls.ptr;

//wchar_t*  clang_string = cast(wchar_t *)"AA";
	wstring   dlang_string = "BB"w; //< NEW, 
same results

LPCWSTR   winpointer_to_string = "CC";

	wcsncat(clang_string, dlang_string.toUTF16z, 
wcslen(dlang_string.toUTF16z));

//   String output: AABB

	wcsncat(clang_string, winpointer_to_string, 
wcslen(winpointer_to_string));

//   String output: AABBCC
// Expected string: AABBCC

wprintf(clang_string);
//   String output: AABBCC
// Expected string: AABBCC

}
```


Re: A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn

On Thursday, 7 April 2022 at 11:03:39 UTC, Tejas wrote:

On Thursday, 7 April 2022 at 10:50:35 UTC, BoQsc wrote:
Here I try to concatenate three character strings using 
`wcsncat()`.


[...]


Maybe try using `wstring` instead of string? Also use the `w` 
postfix


```d
wstring dlang_string = "BBB"w;

I can't test because I'm not on my PC and I don't use Windows


Exactly same results. `AA`

```
import std.stdio;

@system void main(){

import std.utf: toUTF16z, toUTF16;
import core.stdc.wchar_   : wcsncat, wcslen, wprintf;
import core.stdc.stdlib   : wchar_t;
import core.sys.windows.winnt : LPCWSTR;

wchar_t*  clang_string = cast(wchar_t *)"AA";
	wstring   dlang_string = "BBB"w; //< NEW, 
same results

LPCWSTR   winpointer_to_string = "CC";

	wcsncat(clang_string, dlang_string.toUTF16z, 
wcslen(dlang_string.toUTF16z));

//   String output: AABBB

	wcsncat(clang_string, winpointer_to_string, 
wcslen(winpointer_to_string));

//   String output: AA
// Expected string: AABBBCC

wprintf(clang_string);
//   String output: AA
// Expected string: AABBBCC

}
```


A weird example of .toUTF16z concatination side-effects in wcsncat

2022-04-07 Thread BoQsc via Digitalmars-d-learn
Here I try to concatenate three character strings using 
`wcsncat()`.


`clang_string` AA
`dlang_string` BBB
`winpointer_to_string` CC


```
import std.stdio;

@system void main(){

import std.utf: toUTF16z, toUTF16;
import core.stdc.wchar_   : wcsncat, wcslen, wprintf;
import core.stdc.stdlib   : wchar_t;
import core.sys.windows.winnt : LPCWSTR;

wchar_t* clang_string = cast(wchar_t *)"AA";
string   dlang_string = "BBB";
LPCWSTR  winpointer_to_string = "CC";

	wcsncat(clang_string, dlang_string.toUTF16z, 
wcslen(dlang_string.toUTF16z));

//   String output: AABBB

	wcsncat(clang_string, winpointer_to_string, 
wcslen(winpointer_to_string));

//   String output: AA
// Expected string: AABBBCC

wprintf(clang_string);
//   String output: AA
// Expected string: AABBBCC

}


```

**Problem:**
Any *following concatenated string* after "`wcsncat()` 
concatenation of `dlang_string.toUTF16z` string", happen to not 
be printed and gets overwritten.


**The Expected output:**
I was expecting the `wprintf()` **result** to be 
`AABBBCC`
The `wprintf() `  **result** I've received is this:  
`AA`




How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread BoQsc via Digitalmars-d-learn
I have a feeling that some parts of my code contains unterminated 
strings and they do overflow into other string that is to be 
combined. I'd like to take a look at strings, analyse them 
manually and see if any of them end up terminated or not.


Please provide any relevant examples of how you do this.



Re: Check if Key exists in Associative Array using D language.

2022-04-05 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 5 April 2022 at 11:53:19 UTC, Dennis wrote:

On Tuesday, 5 April 2022 at 11:26:27 UTC, BoQsc wrote:
I'd like to know if there is similar function: that can check 
if a **key** inside a [Associative Array][2] can be found.


You can use the `in` operator for that:
https://dlang.org/spec/hash-map.html#testing_membership


This is brilliant, thank you.


Check if Key exists in Associative Array using D language.

2022-04-05 Thread BoQsc via Digitalmars-d-learn
I've found [std.algorithm: canFind][1] to be useful on a 
**regular arrays**.


I'd like to know if there is similar function: that can check if 
a **key** inside a [Associative Array][2] can be found.


[1]:https://dlang.org/phobos/std_algorithm_searching.html#.canFind
[2]:https://dlang.org/spec/hash-map.html


Re: How to exclude function from being imported in D language?

2022-03-09 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 8 March 2022 at 22:28:27 UTC, bauss wrote:

On Tuesday, 8 March 2022 at 20:12:40 UTC, BoQsc wrote:
I think D Language needs and lacks conditional compilation 
condition and attribute of "exclude". The exclude keyword or 
code block in the exclude, would be made sure to not be 
imported by any means. Now it seems all to be only workarounds.


What D just needs is a way to specify the entry point, in which 
it just defaults to the first main function found, but could be 
any function given.


Yeah that would be as great. Without this, the project modules 
feel non-interactive and always depending on other modules. 
Dependant modules do not feel modular, if you can't bring them to 
other project as a standalone module.


Re: How to exclude function from being imported in D language?

2022-03-08 Thread BoQsc via Digitalmars-d-learn
I think D Language needs and lacks conditional compilation 
condition and attribute of "exclude". The exclude keyword or code 
block in the exclude, would be made sure to not be imported by 
any means. Now it seems all to be only workarounds.


How to exclude function from being imported in D language?

2022-03-08 Thread BoQsc via Digitalmars-d-learn
Premise: In D language, only one main(){} function can exist in a 
program.

Having two `main()` functions throws an error.

Let's say I want to use some functionality of another program, 
but it has a `main(){}`
function. How can I import and use functions without importing 
the `main(){}` function?




Re: SendMessageTimeoutW requires casting string to uint?

2022-03-05 Thread BoQsc via Digitalmars-d-learn

Update: 2022-03-04
ChangeLog:
* Fixed Typos
* Added Switch Statement for Command Line Interface Arguments
* Added Switch Statement for Policy, intl, Environment
* Added Switch Statement for Error handling: Exit status, 
Error level

* Increased window "timeout" from 1 to 1000
https://github.com/vaido-world/WM_SETTINGCHANGE


Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread BoQsc via Digitalmars-d-learn

On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:

I need to check if a string contains integers,
and if it contains integers, remove all the regular string 
characters.
I've looked around and it seems using regex is the only closest 
solution.


```
import std.stdio;

void main(string[] args){

if (args.length > 1){

write(args[1]); // Needs to print only integers.

} else {
write("Please write an argument.");
}
}
```

 Regular expression solution
```
import std.stdio;
import std.regex;
import std.string: isNumeric;
import std.conv;

void main(string[] args){

if (args.length > 1){

writeln(args[1]); // Needs to print only integers.

		string argument1 = args[1].replaceAll(regex(r"[^0-9.]","g"), 
"");

if (argument1.isNumeric){
writeln(std.conv.to!uint(argument1));
} else {
writeln("Invalid value: ", args[1]," (must be int 
integer)");
}

} else {
write("Please write an argument.");
}
}
```


Re: How to remove all characters from a string, except the integers?

2022-03-03 Thread BoQsc via Digitalmars-d-learn

On Thursday, 3 March 2022 at 13:25:32 UTC, Stanislav Blinov wrote:

On Thursday, 3 March 2022 at 12:14:13 UTC, BoQsc wrote:


I need to check if a string contains integers,
and if it contains integers, remove all the regular string 
characters.
I've looked around and it seems using regex is the only 
closest solution.


```d
import std.stdio;
import std.algorithm : find, filter;
import std.conv : to;
import std.uni : isNumber;

void main(string[] args){
if (args.length > 1){

auto filtered = () {
auto r = args[1].find!isNumber; // check if a 
string contains integers

return r.length ?
   r.filter!isNumber.to!string // and if it 
does, keep only integers
   : args[1];  // otherwise 
keep original

} ();

filtered.writeln;

} else {
write("Please write an argument.");
}
}
```


D language should be renamed into Exclamation-mark language.
It feels overused everywhere and without a better alternative.


How to remove all characters from a string, except the integers?

2022-03-03 Thread BoQsc via Digitalmars-d-learn

I need to check if a string contains integers,
and if it contains integers, remove all the regular string 
characters.
I've looked around and it seems using regex is the only closest 
solution.


```
import std.stdio;

void main(string[] args){

if (args.length > 1){

write(args[1]); // Needs to print only integers.

} else {
write("Please write an argument.");
}
}
```


How to convert a string command line argument to an int?

2022-03-02 Thread BoQsc via Digitalmars-d-learn

I tried to use `std.conv.parse(args[2])`,

```
import std.stdio;

import std.conv;

 void main(string[] args){

if (args.length > 1) {
writeln(broadcastSettingChange(args[1]));
if (args.length == 2) {
// TODO: second argument needs parse to uint
			writeln(broadcastSettingChange(args[1], 
std.conv.parse(args[2])));


}

} else {

writeln(broadcastSettingChange());
}
write(args.length > 1);


 }
```

### But I'm getting this error

```
(21): Error: template `std.conv.parse` cannot deduce function 
from argument types `!()(string)`
.\..\..\src\phobos\std\conv.d(2263):Candidates are: 
`parse(Target, Source, Flag doCount = No.doCount)(ref Source 
source)`
.\..\..\src\phobos\std\conv.d(2382):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s)`
.\..\..\src\phobos\std\conv.d(2804):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source 
source, uint radix)`
.\..\..\src\phobos\std\conv.d(2973):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s)`
.\..\..\src\phobos\std\conv.d(3084):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source 
source)`
.\..\..\src\phobos\std\conv.d(3776):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s)`
.\..\..\src\phobos\std\conv.d(3833):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s)`
.\..\..\src\phobos\std\conv.d(3918):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s)`
.\..\..\src\phobos\std\conv.d(4031):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s, 
dchar lbracket = '[', dchar rbracket = ']', dchar comma = ',')`
.\..\..\src\phobos\std\conv.d(4218):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s, 
dchar lbracket = '[', dchar rbracket = ']', dchar comma = ',')`
.\..\..\src\phobos\std\conv.d(4327):
`parse(Target, Source, Flag doCount = No.doCount)(ref Source s, 
dchar lbracket = '[', dchar rbracket = ']', dchar keyval = ':', 
dchar comma = ',')`
WM_SETTINGCHANGE.d(21):All possible candidates are marked 
as `deprecated` or `@disable`
Failed: 
["C:\\Users\\Windows10\\Desktop\\dmd2\\windows\\bin\\dmd.exe", 
"-v", "-o-", "WM_SETTINGCHANGE.d", "-I."]

```



Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread BoQsc via Digitalmars-d-learn

`bool nextArgumentDoesNotReachEndOfArray = i + 1 < args.length;`

How can I declare it out of scope and reuse it in any scope that 
has `i` and `args.length` declared?




Re: Is this Windows Win32 fileapi.h header accessible in D language?

2022-02-08 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 8 February 2022 at 18:21:46 UTC, duser wrote:

On Tuesday, 8 February 2022 at 16:10:19 UTC, BoQsc wrote:
Unsure where to start, so I decided to ask here how to get use 
of this win32 header.


https://docs.microsoft.com/en-us/windows/win32/api/fileapi/


the specific module containing that is 
`core.sys.windows.winbase`


my trick to find these is to use github search with the 
function you want:


  https://github.com/dlang/druntime/search?q=AreFileApisANSI


This is great.
Thanks for now.


Is this Windows Win32 fileapi.h header accessible in D language?

2022-02-08 Thread BoQsc via Digitalmars-d-learn
Unsure where to start, so I decided to ask here how to get use of 
this win32 header.


https://docs.microsoft.com/en-us/windows/win32/api/fileapi/


Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:

On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:

Let's say I want to skip characters and build a new string.

The string example to loop/iterate:

```
import std.stdio;

void main()
{
string a="abc;def;ab";

}
```

The character I want to skip: `;`

Expected result:
```
abcdefab
```


string b = a.replace(";", "");


Thanks, that's what I used to do few years ago.
It's a great solution I forget about and it works.

```
import std.stdio;
import std.array;

void main()
{
string a="abc;def;ab";
string b = a.replace(";", "");
writeln(b);
}
```



Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 8 December 2021 at 12:49:39 UTC, Adam D Ruppe wrote:

On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:

The string example to loop/iterate:


foreach(ch; a) {

}

does the individual chars of the string you can also

foreach(dchar ch; a) {

}

to decode the utf 8


Thanks Adam.

This is how it would look implemented.

```
import std.stdio;

void main()
{
string a = "abc;def;ab";
string b;

foreach(ch; a) {
if (ch != ';'){
b ~= ch;
}

writeln(ch);
}

writeln(b);
}
```


Re: How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 8 December 2021 at 11:35:39 UTC, Biotronic wrote:

On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:

Let's say I want to skip characters and build a new string.

The string example to loop/iterate:

```
import std.stdio;

void main()
{
string a="abc;def;ab";

}
```

The character I want to skip: `;`

Expected result:
```
abcdefab
```

[..]
string b = a.filter!(c => c != ';').to!string;
writeln(b);
}


I somehow have universal cross language hate for this kind of 
algorithm.
I'm not getting used to the syntax and that leads to poor 
readability.

But that might be just me.

Anyways,
Here is what I've come up with.

```
import std.stdio;

void main()
{
string a = "abc;def;ab";
string b;

for(int i=0; i

How to loop through characters of a string in D language?

2021-12-08 Thread BoQsc via Digitalmars-d-learn

Let's say I want to skip characters and build a new string.

The string example to loop/iterate:

```
import std.stdio;

void main()
{
string a="abc;def;ab";

}
```

The character I want to skip: `;`

Expected result:
```
abcdefab
```


Re: How to use std.windows.registry, there are no documentations.

2021-11-30 Thread BoQsc via Digitalmars-d-learn

On Saturday, 27 November 2021 at 19:59:24 UTC, Imperatorn wrote:

On Wednesday, 24 November 2021 at 12:07:44 UTC, BoQsc wrote:

On Thursday, 11 July 2019 at 08:53:35 UTC, BoQsc wrote:

[...]


```

import std.stdio;
import std.windows.registry;

[...]


You could add some examples to the documentation if you like ☀️


I'll certaintly will, as that's the only way to keep some kind of 
reference point and not make it all lost. It might take a while 
since various things going on at the same time for the next few 
months.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 24 November 2021 at 20:29:36 UTC, Imperatorn wrote:

On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote:
On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe 
wrote:

On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:
The many times I tried this pragma, it did not even get 
recognised as pragma at all.


You need to use `dmd -m32mscoff` or `dmd -m64`. Plain `dmd` 
won't work.


If -m32mscoff and -m64 still don't work, what's your dmd 
version? It was added in 2.083.0, November 2018.


Thanks, seems to work now.

I had to add these two pragmas to the `winsamp.d`
```
pragma(linkerDirective, "/subsystem:windows");
pragma(lib, "user32.lib");
```

And as you mentioned give additional`-m32mscoff` flag to the 
compiler.


`dmd winsamp.d -m32mscoff`

**The obvious problem now is:** How can you compile without 
specifying the flags. With plain dmd.


Just a quick question before going deeper. Why do you not want 
to supply the definition file?


To have a single standalone .d script file, that's the end goal.
I want to have everything in one .d source file and run it 
without specifying additional files or flags.

In other words: as simple as possible to use.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
Since the **linkerDirective pragma** is not supported for OMF 
object file.

Linker directives are only supported for MS-COFF output.

https://dlang.org/spec/pragma.html#linkerDirective

I doubt that this thread is completely resolved.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote:

[...]
**The obvious problem now is:** How can you compile without 
specifying the flags. With plain dmd.



It probably has to do something with the default target of dmd 
(`-m32`) generating **OMF object file**.

https://dlang.org/dmd-windows.html#switch-m32

`-m32mscoff` and `-m64` both generate **MS-COFF Object file** 
instead of **OMF object file**.


---
The below error is caused when the compilation target is **OMF 
object file** instead of **MS-COFF Object file**.

```
winsamp.d(11): Error: unrecognized pragma(linkerDirective)
```


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe 
wrote:

On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:
The many times I tried this pragma, it did not even get 
recognised as pragma at all.


You need to use `dmd -m32mscoff` or `dmd -m64`. Plain `dmd` 
won't work.


If -m32mscoff and -m64 still don't work, what's your dmd 
version? It was added in 2.083.0, November 2018.


Thanks, seems to work now.

I had to add these two pragmas to the `winsamp.d`
```
pragma(linkerDirective, "/subsystem:windows");
pragma(lib, "user32.lib");
```

And as you mentioned give additional`-m32mscoff` flag to the 
compiler.


`dmd winsamp.d -m32mscoff`

**The obvious problem now is:** How can you compile without 
specifying the flags. With plain dmd.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 24 November 2021 at 17:14:42 UTC, Adam D Ruppe 
wrote:

On Wednesday, 24 November 2021 at 17:06:21 UTC, BoQsc wrote:
**The question:** Is there a way to include the `.def` file 
instructions inside `.d` file, so that there won't be a need 
for additional `.def` file when compiling. (`dmd winsamp`)


https://dlang.org/spec/pragma.html#linkerDirective


The many times I tried this pragma, it did not even get 
recognised as pragma at all.
Essentialy it did not work. Mind giving a demonstration of this 
pragma?

```
dmd winsamp.d
winsamp.d(13): Error: unrecognized `pragma(linkerDirective)`
```


Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
I'm not sure if I have sucessfully achieved something like this 
before or is it even possible right now, but there is a sample 
file that comes with DMD compiler: `D\dmd2\samples\d\winsamp.d`


**The problem:** `winsamp.d` have to be compiled with `.def` file.
```
/+ Compile with:
 +  dmd winsamp winsamp.def
 + or:
 +  dmd winsamp -L-Subsystem:Windows
 +
 + 64 bit version:
 +  dmd -m64 winsamp -L-Subsystem:Windows user32.lib
 +/
```

This is how the `.def` file looks like
(`D\dmd2\samples\d\winsamp.def`):
```
EXETYPE NT
SUBSYSTEM WINDOWS

```

**The question:** Is there a way to include the `.def` file 
instructions inside `.d` file, so that there won't be a need for 
additional `.def` file when compiling. (`dmd winsamp`)





How to use std.windows.registry, there are no documentations.

2021-11-24 Thread BoQsc via Digitalmars-d-learn

On Thursday, 11 July 2019 at 08:53:35 UTC, BoQsc wrote:

https://dlang.org/phobos/std_windows_registry.html
https://github.com/dlang/phobos/blob/master/std/windows/registry.d

Can someone provide some examples on how to:
set, change, receive something from the Windows registry using 
Phobos std.windows.registry library?


```

import std.stdio;
import std.windows.registry;

void main(string[] args)
{
writeln("hello world");
writefln("args.length = %d", args.length);

foreach (index, arg; args)
{
writefln("args[%d] = '%s'", index, arg);
}
writeln();
writeln(Registry.localMachine().name);

writeln(Registry.localMachine().getKey("System\\CurrentControlSet\\Control\\Session 
Manager\\Environment").name);
writeln(Registry.localMachine().getKey("System").keyCount);
writeln(Registry.localMachine().getKey("System").valueCount);

writeln(Registry.localMachine().getKey("System\\CurrentControlSet\\Control\\Session 
Manager\\Environment").valueCount);
write(Registry.localMachine().getKey("System\\CurrentControlSet\\Control\\Session 
Manager\\Environment").getValue("Path").value_EXPAND_SZ);
Registry.currentUser().createKey("test");

}

```


How to make a new dub subpackage? [Answered]

2021-11-20 Thread BoQsc via Digitalmars-d-learn

Note: It is not possible to make subpackage inside subpackage.


To make a subpackage with dub; follow these general guidelines.

**General guidelines**

1. Create a new folder.
2. Open the folder.
3. Initialise a new package. (`dub init`)
4. Open `dub.json` file
   * Append this:
   ```
 "subPackages": [
"./component1/"
 ]
  ```
6. Create a new inner folder named `component1`
7. Initialise a new package inside the inner folder (`dub init`)
8. Open the previous package folder.
9. Run the subpackage as a test. (`dub run :component1`)

___


**This is how it is made in Windows 10:**
(I use Windows 10, please excuse for not giving Linux directions.)


mkdir "NewPackage"
cd "./NewPackage"
dub init
notepad dub.json


"subPackages": [
"./component1/"
]


mkdir "component1"
cd "./component1"
dub init
cd "../"
dub run :component1


___

More information can be found: 
https://dub.pm/package-format-json#sub-packages
For SDL Package File Format: 
https://dub.pm/package-format-sdl#sub-packages


Re: How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn

On Friday, 19 November 2021 at 18:01:57 UTC, Adam D Ruppe wrote:

On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote:
Let's say I want to write a simple program that asks for an 
input of a single character.
After pressing a single key on a keyboard, the character is 
printed out and the program  should stop.


This is platform specific. About 10 lines of code for a minimum 
implementation per OS, but if you don't wanna do it that way my 
library has a function for it with a prepackaged sample:


http://arsd-official.dpldocs.info/arsd.terminal.html#single-key

that's arsd-official:terminal on dub or you can grab the file 
from my github repo.


I guess you could view my source to see the impl but I don't 
feel like pulling it out right now.


Thanks Adam.
I've tested and it does work on Windows 10.


mkdir "read_character_project"
cd "read_character_project"
dub init
dub add arsd-official:terminal
notepad ./source/app.d


import arsd.terminal;

void main() {
auto terminal = Terminal(ConsoleOutputType.linear);
	auto input = RealTimeConsoleInput(, 
ConsoleInputFlags.raw);


terminal.writeln("Press any key to continue...");
auto ch = input.getch();
terminal.writeln("You pressed ", ch);
}



dub run


Performing "debug" build using C:\Program Files\LDC 
1.28\bin\ldc2.exe for x86_64.
arsd-official:terminal 10.3.10: target for configuration "normal" 
is up to date.
arsd ~master: target for configuration "application" is up to 
date.

To force a rebuild of up-to-date targets, run again with --force.
Running arsd.exe
Press any key to continue...
You pressed u

___

Of interest, I also tried to look up getch() inside
http://arsd-official.dpldocs.info/source/arsd.terminal.d.html#L2867

But the source file overwhelmed me by its size.

For now I'm still interested in a more simple standalone 
implementation that would be more learning friendly, or at least 
with little explanation of basic things behind the code and how 
it is interfacing with the operating system, the native library.




How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn
Let's say I want to write a simple program that asks for an input 
of a single character.
After pressing a single key on a keyboard, the character is 
printed out and the program  should stop.


Re: Find a char among string (string.findAmong.char)

2021-07-07 Thread BoQsc via Digitalmars-d-learn

I think nested foreach loops are more readable.

```
import std;
void main()
{
alias alphabet = letters;
char[26] letters = ['a','b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'];

string wordExample = "Book.";
foreach (letter; wordExample){
foreach (alphabetLetter; letters){
if (letter == alphabetLetter) {
writeln(letter);
}
}

}

}
```


Re: Find a char among string (string.findAmong.char)

2021-07-06 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 6 July 2021 at 15:48:35 UTC, rassoc wrote:

You can also do:

```d
import std;
void main()
{
// https://dlang.org/phobos/std_ascii.html#.lowercase
"Book.".filter!(c => lowercase.canFind(c))
   .each!(c => writeln(c, " found"));

// Output:
// o found
// o found
// k found
}
```


I really don't like reading arrow functions.
It takes some more effort to understand, follow and get used to 
them.
I'd like something simple and effortless looking and feeling that 
would make code readable similarly to an english sentence.


Such as this, but as noted, this does not work as 
intended/assumed by me:

```
if (letter.findAmong(alphabet)){
 write("found");
 }
```


Re: Find a char among string (string.findAmong.char)

2021-07-06 Thread BoQsc via Digitalmars-d-learn

On Monday, 5 July 2021 at 19:48:13 UTC, jfondren wrote:

On Monday, 5 July 2021 at 19:34:14 UTC, BoQsc wrote:


But I really don't like how it looks less readable and makes 
less sense on first look.

`if (([letter].findAmong(alphabet)).length)`
I'd like to use some method on the `letter` instead of []
And `.length` does not make a lot of sense when reading like 
an english sentence.


I suggest canFind, like in my earlier example. findAmong is 
like "consume this range until you find one of these things, 
and then return the remainder of the range". It doesn't really 
fit your use.


I tried out .canFind method, and to test it I removed the letter 
'o' from the Alphabet.
Weirdly enough .canFind method still found 'o' letter among the 
Alphabet.


https://run.dlang.io/is/2Fvenf



Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn

On Monday, 5 July 2021 at 19:25:23 UTC, jfondren wrote:

On Monday, 5 July 2021 at 19:19:19 UTC, BoQsc wrote:
If I use `[letter].findAmong(alphabet)` in my code, it 
considers a dot (.) punctuation character as a letter.

You can see it here:
https://run.dlang.io/is/YWmaXU


It returns a zero-length array that, because it's not null, is 
true. That's why I used .length in my example.


```
$ rdmd --eval 'writeln("str"[$..$].length); writeln("str"[$..$] 
? true : false)'

0
true
$ rdmd --eval 'writeln([].length); writeln([] ? true : false)'
0
false
```


Oh alright I think I fixed it with your guidance.
```
import std;
void main()
{
alias alphabet = letters;
char[26] letters = ['a','b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'];

string wordExample = "Book.";
foreach (letter; wordExample){
if (([letter].findAmong(alphabet)).length){

write(letter);
write(" letter is found among the alphabet.");
writeln;
}

}

}
```

But I really don't like how it looks less readable and makes less 
sense on first look.

`if (([letter].findAmong(alphabet)).length)`
I'd like to use some method on the `letter` instead of []
And `.length` does not make a lot of sense when reading like an 
english sentence.




Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn

On Monday, 5 July 2021 at 18:59:09 UTC, jfondren wrote:

On Monday, 5 July 2021 at 18:53:27 UTC, jfondren wrote:


If you replace the findAmong call with 
`[letter].findAmong(alphabet)`, this works.


Consider:

```d
import std;

void main() {
import std.ascii : alphabet = letters;

string wordExample = "Book.";
foreach (letter; wordExample) {
writefln!"%c is %sa letter"(letter, 
[letter].findAmong(alphabet).length ? "" : "not ");
writefln!"%c is %sa letter"(letter, 
alphabet.canFind(letter) ? "" : "not ");

}
writeln("___>>___finally some letters".findAmong(alphabet));
}
```


If I use `[letter].findAmong(alphabet)` in my code, it considers 
a dot (.) punctuation character as a letter.

You can see it here:
https://run.dlang.io/is/YWmaXU



Find a char among string (string.findAmong.char)

2021-07-05 Thread BoQsc via Digitalmars-d-learn

I get an error when I try to find that letter is among alphabet.
onlineapp.d(13): Error: template 
`std.algorithm.searching.findAmong` cannot deduce function from 
argument types `!()(immutable(char), immutable(string))`, 
candidates are:

/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/searching.d(2694):
`findAmong(alias pred = "a == b", InputRange, ForwardRange)(InputRange seq, 
ForwardRange choices)`
  with `pred = "a == b",
   InputRange = immutable(char),
   ForwardRange = string`
  must satisfy the following constraint:
`   isInputRange!InputRange`



This is the code: You can run it at: 
https://run.dlang.io/is/5cvuUZ

 import std;
 void main()
 {
 alias alphabet = letters;
 char[26] letters = ['a','b', 'c', 'd', 'e',
 'f', 'g', 'h', 'i', 'j',
 'k', 'l', 'm', 'n', 'o',
 'p', 'q', 'r', 's', 't',
 'u', 'v', 'w', 'x', 'y', 'z'];

 string wordExample = "Book.";
 foreach (letter; wordExample){
 if (letter.findAmong(alphabet)){
 write("found");
 }
write(letter);
 }

 }





Download a file into array (using std.net.curl.download)

2021-07-05 Thread BoQsc via Digitalmars-d-learn

Let's say I can't store information into files.
Is it possible to download a file into an array.


This is what I have now. It saves a download into a file named: 
file.txt

import std;
import std.net.curl;


void main()
{
writeln("Hello D");

download("https://gist.githubusercontent.com/deekayen/4148741/raw/98d35708fa344717d8eee15d11987de6c8e26d7d/1-1000.txt;, "file.txt");

}



Also run.dlang.io seems to be blocking and not letting me to run 
curl requests. I'm feeling sad right now.


https://run.dlang.io/?compiler=dmd=import%20std;%0Aimport%20std.net.curl;%0A%0A%0Avoid%20main()%0A%7B%0A%20%20%20%20writeln(%22Hello%20D%22);%0A%20%20%20%20download(%22https:%2F%2Fgist.githubusercontent.com%2Fdeekayen%2F4148741%2Fraw%2F98d35708fa344717d8eee15d11987de6c8e26d7d%2F1-1000.txt%22,%20%22.%22);%0A%7D


Re: Is there an alias for standard libraries to use in import statement?

2021-07-04 Thread BoQsc via Digitalmars-d-learn

On Sunday, 4 July 2021 at 08:50:54 UTC, Mike Parker wrote:


You can use named imports, but then you have to use the name as 
a namespace:


```
import system = std;
void main()
{
system.writeln("Hello D");
}
```



These were the examples that might feel more readable and 
natural than simply a three letter junction:

import std;



What do you think?


If you're worried about the readability of `std` by itself, 
don't use it by itself. Import the specific modules you want:


```
import std.algorithm, std.range, std.stdio;
```



Thank you for showing the alternative.


or whatever. It's a non-issue, IMO. It's not like anyone using 
D doesn't know what std is.


It's not about knowing or not knowing, it's about the reading 
flow and ease on the thinking.
For me, it's always better to have things spelled correctly. 
Constant abbrevations do feel unnatural to me, even if I'm 
familiar of the complexity behind it.


Anyways, even if it is possible as you shown. I'm feeling like 
it's still non standard way and might confuse people when the 
whole D code base with community is about importing std library 
directly. But I'm glad I won't have to think about this problem 
anymore and that's important to have less important questions 
answered for more important things to accomplish.


Is there an alias for standard libraries to use in import statement?

2021-07-04 Thread BoQsc via Digitalmars-d-learn
I just started with a fresh look at the D language and would like 
to be able to rewrite this code:



import std;
void main()
{
writeln("Hello D");
}


Into more readable standard library name:


import system;
void main()
{
writeln("Hello D");
}


Or into this


import library.standard;
void main()
{
writeln("Hello D");
}



Or into this:


import library phobos;
void main()
{
writeln("Hello D");
}


These were the examples that might feel more readable and natural 
than simply a three letter junction:

import std;



What do you think?


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote:

On Wednesday, 3 June 2020 at 19:53:03 UTC, BoQsc wrote:

Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, 
so this is only initial proof.



Improved example with the above comments resolved.


That works, but consider using chomp() instead.

https://dlang.org/phobos/std_string.html#.chomp


Chomp sounds kind of funny hahaha.
Who came up with these function names? Walter Bright?
Anyways, Chomp's way looks way more simple. Thanks.


import std.stdio;
import std.algorithm;
import std.string;
import std.uni : lineSep;

int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
			writeln(lineNumber, ". hahahahahahaha", chomp(line, "\r"), " 
nononono");


} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, so 
this is only initial proof.



Improved example with the above comments resolved.

testingGround.d

import std.stdio;
import std.algorithm;



int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
if (line[line.length -1] == '\u000D'){
line = line.remove(line.length - 1);
}
writeln(lineNumber, ". hahahahahahaha", line, " 
nononono");

} else {
writeln( lineNumber, ". ", line[line.length -1]);
}

lineNumber++;
}
}


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 18:49:38 UTC, ttk wrote:

On Wednesday, 3 June 2020 at 18:23:51 UTC, BoQsc wrote:
Here you can see ". hahahahahahaha" and "nononono" and even 
lineNumber is being merged into the same position. Why is this 
happening and can this be simply resolved?


Your string in "line" has a carriage return character at the 
end, which moves the cursor to the beginning of the display row.


If you remove this trailing carriage return character (0x0D) it 
will display correctly.


With the carriage return character in place, everything written 
to your terminal after the carriage return starts at the 
beginning of the row.


It seems to be correct.
Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, so 
this is only initial proof.


Command Prompt Output
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd 
associativeArraySorting.d

0.  The quick brown fox jumps over the lazy dog
1. hahahahahahaha Sphinx of black quartz, judge my vow.nononono
2. # How vexingly quick daft zebras jump!
3. # The five boxing wizards jump quickly
4. # Maecenas consectetur risus a lacus sodales iaculis.
5. # Morbi sed tortor sollicitudin, pharetra massa egestas, 
congue massa.

6. # Sed sit amet nisi at ligula ultrices posuere quis nec est.
7. # Mauris vel purus viverra, pellentesque elit id, consequat 
felis.



testingGround.d

import std.stdio;
import std.algorithm;



int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
			writeln(lineNumber, ". hahahahahahaha", 
line.remove(line.length - 1), " nononono");


} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd 
testingGround.d

0.  The quick brown fox jumps over the lazy dog
nonononoahahahaha Sphinx of black quartz, judge my vow.
2. # How vexingly quick daft zebras jump!
3. # The five boxing wizards jump quickly
4. # Maecenas consectetur risus a lacus sodales iaculis.
5. # Morbi sed tortor sollicitudin, pharetra massa egestas, 
congue massa.

6. # Sed sit amet nisi at ligula ultrices posuere quis nec est.
7. # Mauris vel purus viverra, pellentesque elit id, consequat 
felis.


Here you can see ". hahahahahahaha" and "nononono" and even 
lineNumber is being merged into the same position. Why is this 
happening and can this be simply resolved?



testingGround.d

import std.stdio;
import std.algorithm;

int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
writeln(lineNumber, ". hahahahahahaha", line, 
"nononono");

} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


exampleText.txt

 The quick brown fox jumps over the lazy dog
 Sphinx of black quartz, judge my vow.
# How vexingly quick daft zebras jump!
# The five boxing wizards jump quickly
# Maecenas consectetur risus a lacus sodales iaculis.
# Morbi sed tortor sollicitudin, pharetra massa egestas, congue 
massa.

# Sed sit amet nisi at ligula ultrices posuere quis nec est.
# Mauris vel purus viverra, pellentesque elit id, consequat 
felis.


How to efficiently resolve Associative Arrays not being sorted?

2020-06-02 Thread BoQsc via Digitalmars-d-learn
I want to read a file, put it into an array, make some search and 
replace on the content and output the modified text. However 
Associative Arrays seem to be unsorted by default. Should I drop 
the Associative Arrays and use something else? What are the ways 
to resolve this randomness in Associative Arrays?


ReadfileAndCopyContentIntoArray.d

import std.stdio;

int lineNumber = 0;
char[][int] fileInArray;

void main(){
File exampleFile = File("exampleText.txt");
foreach(line; exampleFile.byLine){

lineNumber++;
fileInArray[lineNumber] ~= line;

}
writeln(fileInArray);
}


exampleText.txt

The quick brown fox jumps over the lazy dog
Sphinx of black quartz, judge my vow.
How vexingly quick daft zebras jump!
The five boxing wizards jump quickly
Maecenas consectetur risus a lacus sodales iaculis.
Morbi sed tortor sollicitudin, pharetra massa egestas, congue 
massa.

Sed sit amet nisi at ligula ultrices posuere quis nec est.
Mauris vel purus viverra, pellentesque elit id, consequat felis.


The Command Prompt Output
[6:"Morbi sed tortor sollicitudin, pharetra massa egestas, 
congue massa.\r", 7:"Sed sit amet nisi at ligula ultrices pos
uere quis nec est.\r", 2:"Sphinx of black quartz, judge my 
vow.\r", 3:"How vexingly quick daft zebras jump!\r", 1:"The q
uick brown fox jumps over the lazy dog\r", 8:"Mauris vel purus 
viverra, pellentesque elit id, consequat felis.", 5:"Maec
enas consectetur risus a lacus sodales iaculis.\r", 4:"The five 
boxing wizards jump quickly\r"]


As can be seen in the Command Prompt Output, the array is not 
ordered correctly.

It goes: 6: 7: 2: 3: 1: 8: 5: 4:
Instead of 1: 2: 3: 4: 5: 6: 7: 8:



[Windows]Need an example: How to read and list names of USB devices via Windows API without using Utilities

2020-05-27 Thread BoQsc via Digitalmars-d-learn
I always wanted to know if there is any proven example on how to 
interface with USB devices by using Windows operating system. Any 
explanations, snippets in relation to topic would help.


What I expect:
Being able to detect if a new USB device is connected.
Being able to read USB device name.
Being able to read USB device partition/s name/s.
Being able to list all USB devices.

What is required and are there any critical problems with 
achieving any of this?


Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 27 May 2020 at 11:13:09 UTC, Simen Kjærås wrote:

On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote:
I'm lacking knowledge on how to achieve what I want and 
getting an error.
What is the correct way to do what I tried to achieve in this 
code?
Everything was intuitive until I started to add notice 
variable to the writeln. Rdmd says  variable `notice` is 
shadowing variable.



if (driveLetter.exists){
auto directory = "/Backup";
if ((driveLetter ~ directory).exists){
auto notice = "Backup directory exists.";

}
writeln(driveLetter, notice);
}


Variables only live in a specified scope, starting from where 
they are declared, and ending when they reach the '}' 
indicating the end of said scope.


In you case, 'notice' only lives inside the if ((driveLetter ~ 
directory).exists) scope, and doesn't exist outside. In order 
to fix this, you will need to declare it outside:


if (driveLetter.exists) {
auto directory = "/Backup";
auto notice = "Backup directory does not exist.";
if ((driveLetter ~ directory).exists) {
notice = "Backup directory exists.";
}
writeln(driveLetter, notice);
}

This also makes it clearer what value 'notice' will have when 
the backup directory doesn't exist - in your case you haven't 
assigned it any value in that case.


--
  Simen


That's correct. Thanks Simen.


import std.stdio : writeln;
import std.file;
void main(){

auto drivesLetters = [
"A:", "I:", "Q:", "Y:",
"B:", "J:", "R:", "Z:",
"C:", "K:", "S:", "D:", "L:", "T:",
"E:", "M:", "U:",
"F:", "N:", "V:",
"G:", "O:", "W:",
"H:", "P:", "X:",
];

foreach (string driveLetter; drivesLetters) {
if (driveLetter.exists) {
auto notice = "";
if ((driveLetter ~ "/Boot").exists) {
notice ~= "\\Boot directory exists";
notice ~= " ";
}
if ((driveLetter ~ "/Windows").exists) {
notice ~= "\\Windows folder exists";
notice ~= " ";
}
writeln(driveLetter, notice);
}

}


}


Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread BoQsc via Digitalmars-d-learn
I'm lacking knowledge on how to achieve what I want and getting 
an error.
What is the correct way to do what I tried to achieve in this 
code?
Everything was intuitive until I started to add notice variable 
to the writeln. Rdmd says  variable `notice` is shadowing 
variable.


rdmd output:

C:\Users\vaida\Desktop>rdmd searchDirectory.d
searchDirectory.d(21): Error: variable `notice` is shadowing 
variable `searchDirectory.main.notice`
Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", 
"searchDirectory.d", "-I."]


searchDirectory.d

import std.stdio : writeln;
import std.file;
void main(){

auto drivesLetters = [
"A:", "I:", "Q:", "Y:",
"B:", "J:", "R:", "Z:",
"C:", "K:", "S:", "D:", "L:", "T:",
"E:", "M:", "U:",
"F:", "N:", "V:",
"G:", "O:", "W:",
"H:", "P:", "X:",
];

foreach (string driveLetter; drivesLetters) {
string notice;
if (driveLetter.exists){
auto directory = "/Backup";
if ((driveLetter ~ directory).exists){
auto notice = "Backup directory exists.";

}
writeln(driveLetter, notice);
}

}


}




Re: Spawn a Command Line application Window and output log information

2020-05-23 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 10:05:00 UTC, BoQsc wrote:

On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote:


I'm kind of stuck right now on how.



Some more Updates and it seems that it is impossible to scroll 
the history of the output.




Some relevant discussion: 
https://stackoverflow.com/a/5779422/3789797




Re: Spawn a Command Line application Window and output log information

2020-05-19 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote:


I'm kind of stuck right now on how.



Some more Updates and it seems that it is impossible to scroll 
the history of the output.



import std.stdio   : write, writeln, readln, writefln;
import std.process : spawnShell, wait, executeShell, kill, 
thisProcessID;

import core.thread.osthread : getpid;
import std.process : environment;
import std.file : getcwd;
import std.file : thisExePath;

void main() {
spawnShell( "cls" ).wait;
executeShell("title HelloWorld");
executeShell("chcp 65001");
executeShell("mode con: cols=120 lines=30");




writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•
The Adventures of HelloWorld");
writeln("
   ┌──┐
   ▒░░░┼┐ ≡▒░ ¦
___▒▒┼┤┼▒▒▓");

writeln("
   ~¨(··)¸
 <│ >
‗┌═¬‗´
  ");

writeln("Path to executable and the filename: ", thisExePath());
writeln("Current Working Directory: ", getcwd());
writeln();
writeln("Accessible files from these Environment Paths");
writeln(environment["PATH"]);
writeln();
	writeln("Access TEMP environmental variable: ", 
environment.get("TEMP"));

writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
if (line == "exit\x0a") {
writeln("Going down");
return;
}
write(line);
write("Your Input: ");
}
}


Re: None of the overloads of kill are callable using argument types:

2020-05-19 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 20:40:47 UTC, Adam D. Ruppe wrote:

On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote:

I'm trying to kill my own process


Don't kill yourself, just `return` from main.


Returning does what I need, however I still need to get a working 
example on killing/terminating for the future reference, just in 
case. However as Ali Çehreli stated, there seems to be a bigger 
problem, to why it is not possible right now.



import std.stdio   : write, writeln, readln, writefln;
import std.process : spawnShell, wait, executeShell, kill, 
thisProcessID;

import core.thread.osthread : getpid;

void main() {
spawnShell( "cls" ).wait;
executeShell("title HelloWorld");
executeShell("chcp 65001");
executeShell("mode con: cols=120 lines=30");




writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•
A Tale of HelloWorld");
writeln("
   ┌──┐
   ▒░░░┼┐ ≡▒░ ¦
___▒▒┼┤┼▒▒▓");

  writeln("
   ~¨(··)¸
 <│ >
‗┌═¬‗´
  ");
writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
if (line == "exit\x0a") {
writeln("Going down");
return;
}
write(line);
write("Your Input: ");


}
}


None of the overloads of kill are callable using argument types:

2020-05-18 Thread BoQsc via Digitalmars-d-learn
I'm trying to kill my own process, but I'm being unsuccessful at 
the compilation of the program. It seems that neither getpid nor 
thisProcessID returns a correct type value for the kill function.


HelloWorld.d(24): Error: none of the overloads of kill are 
callable using argument types (int), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2327):   
 std.process.kill(Pid pid)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2338):   
 std.process.kill(Pid pid, int codeOrSignal)



HelloWorld.d


import std.stdio   : write, writeln, readln, writefln;
import std.process : executeShell, kill, thisProcessID;
import core.thread.osthread : getpid;

void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");
writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
writeln(line);
kill(thisProcessID());
write("Your Input: ");

}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 18:10:06 UTC, BoQsc wrote:
Also, if you want some kind of Fancy ASCII art in your 
application


Since I started this thread, I might share some more improvements.

In this Update I managed to get the PID of the current process and
in the future I hope the HelloWorld program process could be 
killed,

I'm kind of stuck right now on how.

Right now a complete Command Line command to compile HelloWorld 
example with a working Command Line Interface looks like this:

dmd HelloWorld.d whatever.res && start "" "HelloWorld.exe"



whatever.res - look at above posts on how to generate whatever.res

HelloWorld.d

import std.stdio   : write, writeln, readln, writefln;
import std.process : executeShell, kill, thisProcessID;
import core.thread.osthread : getpid;

void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");
writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
writeln(line);
write("Your Input: ");

}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:51:54 UTC, BoQsc wrote:

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


Forever thankful to Adam D. Ruppe
It is possible to embed icon into the Windows executable.
The Original Adam's thread: 
https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org


The instructions:
Download a valid Windows 3.0 icon resource
Examples: 
http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip


Download the tools to embed the Icon for the .exe executable.
http://ftp.digitalmars.com/bup.zip

Create a new text file named whatever.rc with the content 
similar to this:



IDI_ICON1   ICONDISCARDABLE "iconfil.ico"


Use rcc.exe tool and whatever.rc file to generate whatever.res 
file.

rcc.exe whatever.rc


Use dmd.exe compiler to embed newly created whatever.res file 
into your .exe file while compiling:

dmd.exe whatever.res


You should see that the newly compiled .exe file is now with an 
Icon.

And when launched the icon will be used by the Command Prompt.


Also, if you want some kind of Fancy ASCII art in your 
application:


Look at the Google for any ASCII Art generator:  
http://patorjk.com/software/taag/#p=display=Elite=Hello%20World


Add this line and insert your ASCII art in a writeln function.

executeShell("chcp 65001");

to your D language program source code

More about chcp can be found here: https://ss64.com/nt/chcp.html
Or here: 
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/chcp



import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");


string line;
while ((line = readln()) !is null)
write(line);
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


Forever thankful to Adam D. Ruppe
It is possible to embed icon into the Windows executable.
The Original Adam's thread: 
https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org


The instructions:
Download a valid Windows 3.0 icon resource
Examples: 
http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip


Download the tools to embed the Icon for the .exe executable.
http://ftp.digitalmars.com/bup.zip

Create a new text file named whatever.rc with the content similar 
to this:



IDI_ICON1   ICONDISCARDABLE "iconfil.ico"


Use rcc.exe tool and whatever.rc file to generate whatever.res 
file.

rcc.exe whatever.rc


Use dmd.exe compiler to embed newly created whatever.res file 
into your .exe file while compiling:

dmd.exe whatever.res


You should see that the newly compiled .exe file is now with an 
Icon.

And when launched the icon will be used by the Command Prompt.






Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:08:41 UTC, Kagamin wrote:

On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
The important question is: how can we change the name/title of 
this Command Line application.


As the simplest solution, you can set the window title in 
shortcut properties.


It seems that all the Command Prompt Batch command of windows 
such as "title" do work well.
By using executeShell I was able to change the title of the 
Command Line that runs my program.


import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
writeln("Hello, World!");
executeShell("title HelloWorld");
string line;
while ((line = readln()) !is null)
write(line);
}


import std.file : mkdir;

It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. But 
I have a bad feeling that it is probably not possible without a 
GUI library.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:40:24 UTC, Panke wrote:

On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
I'd like to have application as small as possible with a 
simple Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?


If you do not want to create the library yourself, you could 
spawn a terminal application like konsole or kitty and start a 
simple cli app.


You'd need to have some form of inter process communication 
setup for this though.


On Windows 10, this example, when compiled and clicked on the 
executable - spawns a command line with the "Hello World" output 
shown.



import std.stdio;

void main() {
write("Hello, World!");

string line;
while ((line = readln()) !is null)
write(line);
}


The important question is: how can we change the name/title of 
this Command Line application.


Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn
I'd like to have application as small as possible with a simple 
Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?




Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 15:49:06 UTC, Adam D. Ruppe wrote:

On Monday, 18 May 2020 at 15:47:40 UTC, BoQsc wrote:
It seems strange that on the first run after D language 
compilation. Hello World program takes 1-3 seconds to launch.


That's the Windows virus scanner again.

It sees D programs as unusual and gives them additional 
scrutiny...


You can set an exception in the windows virus scanner settings 
for the folder where you work with D.


That's exactly what it was. I disabled the Windows Security 
Real-Time Protection,

and tested few more times. The execution was immediate.

Thanks Adam.


After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread BoQsc via Digitalmars-d-learn

I use Windows 10.
I tried exactly like mentioned here:
http://ddili.org/ders/d.en/hello_world.html

It seems strange that on the first run after D language 
compilation. Hello World program takes 1-3 seconds to launch.


While C Hello World program simply executes in a second or less.

Why is that, and what can we do about it.


[GTK-D] dub run leads to lld-link: error: could not open libcmt.lib: no such file or directory

2020-05-13 Thread BoQsc via Digitalmars-d-learn

A simple example I tried to run.

#!/usr/bin/env dub
/+ dub.sdl:
name "hello"
dependency "gtk-d" version="~>3.9.0"
+/

import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
Main.init(args);
MainWindow win = new MainWindow("Hello World");
win.setDefaultSize(200, 100);
win.add(new Label("Hello World"));
win.showAll();
Main.run();
}


This is how I tried to run it.

C:\Users\vaida\Desktop\Command prompt shell>dub run --single gui.d
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.
gtk-d:gtkd 3.9.0: target for configuration "library" is up to 
date.
gtk-d:gstreamer 3.9.0: target for configuration "library" is up 
to date.
gtk-d:peas 3.9.0: target for configuration "library" is up to 
date.

gtk-d:sv 3.9.0: target for configuration "library" is up to date.
gtk-d:vte 3.9.0: target for configuration "library" is up to date.
hello ~master: building configuration "application"...
Linking...
lld-link: error: could not open libcmt.lib: no such file or 
directory
lld-link: error: could not open OLDNAMES.lib: no such file or 
directory

Error: linker exited with status 1
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.


Concatenation/joining strings together in a more readable way

2019-12-25 Thread BoQsc via Digitalmars-d-learn
Are there any other ways to join two strings without Tilde ~ 
character?
I can't seems to find anything about Tilde character 
concatenation easily, nor the alternatives to it. Can someone 
share some knowledge on this or at least point out useful 
links/resources?


What would it take to bring preinstalled D language compiler in the major Linux Distributions?

2019-12-23 Thread BoQsc via Digitalmars-d-learn
I would love to see D language available out of box in major 
Linux distributions and use without much care of installation. 
Anyone have a though about it? Was there any serious efforts to 
bring D language to Major distributions?




What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-22 Thread BoQsc via Digitalmars-d-learn
There are lots of editors/IDE's that support D language: 
https://wiki.dlang.org/Editors


What kind of editor/IDE are you using and which one do you like 
the most?


Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread BoQsc via Digitalmars-d-learn
I don't like to see exclamation marks in my code in as weird 
syntax as these ones:

to!ushort(args[1])
s.formattedRead!"%s!%s:%s"(a, b, c);


I'm not sure why, but template instantiation syntax is prevalent 
in the documentation examples of d lang libraries. It almost 
seems like every other example contains at least one or two  of 
them.


It look horrible, and I'm feeling like I'm being forced/coerced 
to learn from examples that do not provide alternatives to the 
template instantiation syntax. Even if the alternative examples 
were provided, why would anyone want to have syntax as ugly and 
weird as current template instantiation syntax with exclamation 
point in the middle of the statement with all other things that 
come with it.




When should we use Modules and when Should we use Classes?

2019-09-18 Thread BoQsc via Digitalmars-d-learn

Would be nice to have a short summary or detailed answer on this.

Some resources to discuss this topic:
https://dlang.org/spec/class.html
https://dlang.org/spec/module.html


Make executable archive just like Java's .jar archive?

2019-09-12 Thread BoQsc via Digitalmars-d-learn
Is there a way to archive multiple .d source code files and make 
that archive executable, or something similar?


Re: Make executable archive just like Java's .jar archive?

2019-09-12 Thread BoQsc via Digitalmars-d-learn

On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote:
Is there a way to archive multiple .d source code files and 
make that archive executable, or something similar?


https://en.wikipedia.org/wiki/JAR_(file_format)


What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread BoQsc via Digitalmars-d-learn

Hello everyone, again,

I had an idea that I want some colors in the output of Command 
Line (For Windows) and

the Terminal (For Linux)

I found https://dlang.org/phobos/dmd_console.html and wanted to 
use it.
But it seems I'm not being successful, and I do not understand 
why.


Here, you can see that I'm trying to import dmd.console;


import std.stdio : writeln;
import dmd.console;

void main()
{
writeln("Hello World");
}


And the output says that, dmd.console; do not exist?
What are these Internal APIs for?

C:\Users\Juozas\Desktop>rdmd color.d
color.d(2): Error: module `console` is in file 'dmd\console.d' 
which cannot be read


Re: Downloading a file and showing progress via curl.

2019-08-20 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 20 August 2019 at 11:51:03 UTC, Daniel Kozak wrote:

For that you can use https://dlang.org/phobos/std_file#append


Thank you, seems to work.


import std.net.curl : HTTP;
import std.stdio: writeln;
import std.file : append;

void main()
{
auto http = HTTP();
// Track progress
http.method = HTTP.Method.get;
http.url = 
"https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;;

http.onReceive = (ubyte[] data) {
append("Wikipedia-logo-en-big.png", data);
return data.length;
};
http.onProgress = (size_t dltotal, size_t dlnow, size_t 
ultotal, size_t ulnow) {
writeln("Progress ", dltotal, ", ", dlnow, ", ", 
ultotal, ", ", ulnow);

return 0;
};
http.perform();
}


Downloading a file and showing progress via curl.

2019-08-20 Thread BoQsc via Digitalmars-d-learn

Hello everyone,
I found this snippet on 
https://dlang.org/phobos/std_net_curl.html#.HTTP



import std.net.curl : HTTP;
import std.stdio : writeln;

void main()
{
auto http = HTTP();
// Track progress
http.method = HTTP.Method.get;
http.url = 
"https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;;

http.onReceive = (ubyte[] data) { return data.length; };
http.onProgress = (size_t dltotal, size_t dlnow, size_t 
ultotal, size_t ulnow) {
writeln("Progress ", dltotal, ", ", dlnow, ", ", 
ultotal, ", ", ulnow);

return 0;
};
http.perform();
}


This snippet is showing Download Progress in bytes, but I'm 
unsure how to save the

downloaded file into filesystem after download is completed.


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 14:19:20 UTC, bachmeier wrote:

is going to compile every time it runs, which makes the program 
unnecessarily slow


If only I could add

dub --single --rdmd

to the shebang, I think dub might stop compiling every time.

However as pointed out in the above post, I'm unable to use 
options in shebang since apache is throwing header error for 
unknown reasons.





Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn
However I tried to add options (--single) to the dub shebang and 
apache now throwing: "bad header error"


Without "--single" option seems to work.



#!/usr/bin/env -vS dub --single
/+ dub.sdl:
   name "application"
   dependency "arsd-official:dom" version="4.0.2"
+/
import std.stdio;
import arsd.dom;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`test`);

}





split -S:  'dub --single'
into:'dub'
&'--single'
executing: dub
  arg[0]= 'dub'
  arg[1]= '--single'
  arg[2]= '/usr/lib/cgi-bin/example.d'
[Wed Jul 31 19:57:56.892522 2019] [cgid:error] [pid 833:tid 
140583783876352] [client >127.0.0.1:43598] malformed header from 
script 'example.d': Bad header: Performing "debug" >build using


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn
is going to compile every time it runs, which makes the program 
unnecessarily slow, and if it's used heavily, will add quite a 
load to the server.


I finally done it, and I'm not sure if it compiles every time. It 
opens the page lightning fast since I use SSD drive. I'm not sure 
how to check if it compiles every time.


Right now, I'm logged in as root and chmoded recursively the 
whole /usr/lib/cgi-bin/ folder

and it succeed.



#!/usr/bin/env dub /+ dub.sdl:
   name "application"
   dependency "arsd-official:dom" version="4.0.2"
   subConfiguration "arsd-official:cgi" "cgi"
+/
import std.stdio;
import arsd.dom;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);

   auto document = new 
Document("paragraph");

   document.root.innerHTML = "hey";
   writeln(document);

//writeln(`CGI D 
Example`);


}


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn
Hmm, it seems that once I remove sudo from the shebang, the error 
disappears and Internal Server Error disappears.


example.d - does not work

#!/usr/bin/env -S sudo dub /+ dub.sdl:
name "hello"


+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}



/var/log/apache2/error.log

[Wed Jul 31 15:48:07.769766 2019] [cgid:error] [pid 4012:tid 
140324198397696] [client >127.0.0.1:51736] End of script output 
before headers: example.d



example.d - Works perfectly, no errors in the log

#!/usr/bin/env -S dub /+ dub.sdl:
name "hello"


+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote:

On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:

And this is the error I get now:
[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 
140153708345088] [client >127.0.0.1:50318] End of script 
output before headers: example.d


And I have no idea how to deal with it. Cgi shows Internal 
Server Error, because of that "End of script output before 
headers" error.



It seems like apache does not like what dub package manager is 
doing, as dub does something before cgi script outputs anything.

https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:

And this is the error I get now:
[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 
140153708345088] [client >127.0.0.1:50318] End of script output 
before headers: example.d


And I have no idea how to deal with it. Cgi shows Internal Server 
Error, because of that "End of script output before headers" 
error.




#!/usr/bin/env -S sudo dub run --quiet --single
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}


Maybe it is not possible to use dub this way.



Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 08:32:43 UTC, BoQsc wrote:
Added sudo to the shebang, it started to say that sudo requires 
tty, meaning that there is no graphical interface for user to 
input the password.


So, I remove the need to type password when using sudo command, 
by following these instructions:

https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/

And this is the error I get now:
[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 
140153708345088] [client >127.0.0.1:50318] End of script output 
before headers: example.d





Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 07:57:01 UTC, BoQsc wrote:
[Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 
140090256426752] [client >127.0.0.1:57052] malformed header 
from script 'example.d': Bad header: Fetching arsd-official 
4.0.1 (

/usr/lib/cgi-bin/.dub/packages/: Permission denied


Added sudo to the shebang, it started to say that sudo requires 
tty, meaning that there is no graphical interface for user to 
input the password.


[Wed Jul 31 11:14:53.183607 2019] [cgid:error] [pid 6207:tid 
140374439274240] [client >127.0.0.1:57400] End of script output 
before headers: example.d

sudo: no tty present and no askpass program specified


Script:

#!/usr/bin/env -S sudo dub run --single
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}







Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 07:42:22 UTC, BoQsc wrote:

This seems to work well when running not from cgi, so there is
That was not true, it didn't work even from Linux Shell, I 
corrected shebang, now it works from Linux Shell.


An, unexpected thing: It did require permissions: sudo 
./example.d  which was not the case with rdmd.




cgi still shows Internal Server Error.

Maybe cgi cannot run this script due to lacking sudo 
permissions required by dub? Unsure.




#!/usr/bin/env -S dub run --single
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}



It seems that /var/log/apache2/error.log shows Permission denied 
error.


[Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 
140090256426752] [client >127.0.0.1:57052] malformed header from 
script 'example.d': Bad header: Fetching arsd-official 4.0.1 (

/usr/lib/cgi-bin/.dub/packages/: Permission denied





Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

This seems to work well when running not from cgi, so there is
That was not true, it didn't work even from Linux Shell, I 
corrected shebang, now it works from Linux Shell.


An, unexpected thing: It did require permissions: sudo 
./example.d  which was not the case with rdmd.




cgi still shows Internal Server Error.

Maybe cgi cannot run this script due to lacking sudo permissions 
required by dub? Unsure.




#!/usr/bin/env -S dub run --single
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}




Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn
I tried to change shebang, but: Internal Server Error still 
appears.



#!/usr/bin/env dub run --single
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}




Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn
There are some other bad news, I switched from rdmd to dub 
package manager since I need a package from Adam D. Ruppe.


It is all good and well: this one works perfectly.

#!/usr/bin/env dub
/+ dub.sdl:
name "hello"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);




}


But, once I add dub dependency, the error appears: Internal 
Server Error

#!/usr/bin/env dub
/+ dub.sdl:
name "hello"
dependency "arsd-official" version="~>4.0.1"

+/
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);




}

This seems to work well when running not from cgi, so there is no 
syntax error.


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 06:52:46 UTC, 0xEAB wrote:

On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote:
This can be solved by using single quotes in the argument 
content places

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Content-type: text/html");
   writeln("");
   writeln("CGI D 
Example");


}


Does the job but is a bad fix.

Use `` quotes for the string literal instead.
Further info: https://dlang.org/spec/lex.html#wysiwyg


 - Elias


I wasn't aware of Wysiwyg Strings, thanks,
seems to work very well.


#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln(`Content-type: text/html`);
   writeln(``);
   writeln(`CGI D 
Example`);


}





Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 06:55:06 UTC, 0xEAB wrote:

On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote:

On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote:

what causes the Internal Server Error.


Internal Server Error might as well appear when D language 
syntax is not correct.


Maybe you want to use some wrapper around rdmd that does output 
a proper CGI response on error. Since this error occurs because 
rdmd's error message as-is is not valid for CGI.



 - Elias


I'm kind of new to everything, I'm not sure how this have to be 
done.


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote:

what causes the Internal Server Error.


Internal Server Error might as well appear when D language syntax 
is not correct.


Considering this: this example has Internal Server Error, since 
writeln argument and argument content cannot contain the same 
type quotes: Internal Server Error

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Content-type: text/html");
   writeln("");
   writeln("CGI D 
Example");


}


This can be solved by using single quotes in the argument content 
places

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Content-type: text/html");
   writeln("");
   writeln("CGI D 
Example");


}



Or even escaping argument content quotes:

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Content-type: text/html");
   writeln("");
   writeln("CGI D 
Example");


}


That is good to know.


Re: How to setup D language with Apache httpd cgi?

2019-07-31 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 30 July 2019 at 21:55:00 UTC, Adam D. Ruppe wrote:

the required blank line to separate headers from content.



That's exactly what causes the Internal Server Error.

This is a working example.d

#!/usr/bin/env rdmd
import std.stdio;
void main()
{

   writeln("");


}


And this one, even produce HTML content to the HTML body tag:

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Content-type: text/html");
   writeln("");
   writeln("CGI D Example");

}


Thanks, Adam D. Ruppe, it works.


How to setup D language with Apache httpd cgi?

2019-07-30 Thread BoQsc via Digitalmars-d-learn
Hello, I would like to know how to setup D language project, so 
that it would work with Apache httpd cgi.


Do I need some kind of cgi library for D language? Right now all 
I'm getting is internal server error.


Btw. Unix Bash script examples seems to work well with with 
Apache httpd cgi, they do not show internal server error.



Before trying examples below, it is required that you install 
apache httpd:

sudo apt-get install apache2


And enable cgi module

sudo a2enmod cgi
sudo service apache2 restart


Here are examples:

D language example, this one does not work. Give internal error.

/usr/lib/cgi-bin/example.d

#!/usr/bin/env rdmd
import std.stdio;
void main()
{
   writeln("Hello, world with automated script running!");
}



Bash example, this one working perfectly.

/usr/lib/cgi-bin/example.sh

#!/bin/bash
echo "Content-type: text/html"
echo ''
echo 'CGI Bash Example'



Also remember to chmod the examples, before opening them:

sudo chmod 755 /usr/lib/cgi-bin/example.sh
sudo chmod 755 /usr/lib/cgi-bin/example.d


Calling / running / executing .d script from another .d script

2019-07-28 Thread BoQsc via Digitalmars-d-learn
Right now, I'm thinking what is correct way to run another .d 
script from a .d script. Do you have any suggestions?


Is it possible to disallow import for certain functions?

2019-07-27 Thread BoQsc via Digitalmars-d-learn
I would like to make sure that function in module that I have 
won't be imported, is this possible to achieve?


Test subject:


mainFile.d

import otherFile;
void main(){

}


otherFile.d

import std.stdio : writeln;
import std.file  : mkdir;

int main(){
writeln("test ");
return 0;
}



Error, main() method has been imported:
how to disallow main() method from being imported?
otherFile.d(5): Error: only one main, WinMain, or DllMain 
allowed. Previously found main at mainFile.d(3)


Re: Blog Post #0052: MVC V - ComboBox with Integers

2019-07-12 Thread BoQsc via Digitalmars-d-learn

On Friday, 12 July 2019 at 11:13:31 UTC, Ron Tarrant wrote:
Today's post deals with integers in a ComboBox. It's not 
exactly tricky, but a little clarification never hurts, right?


Here's where you'll find it: 
https://gtkdcoding.com/2019/07/12/0052-mvc-v-int-combobox.html


Gnome project should just rewrite everything in D language, 
especially the Gnome Shell. At least that would be a right 
direction.


Thanks for the texts Ron, it is so nice to see images - visuals, 
showing the result and they fit so nicely with your article. The 
more visuals and working examples - the easier for some of us to 
understand. :)


Re: Is it possible to execute a function inside .d script that has no main function?

2019-07-12 Thread BoQsc via Digitalmars-d-learn

On Thursday, 11 July 2019 at 10:41:38 UTC, Alex wrote:

On Thursday, 11 July 2019 at 09:43:55 UTC, BoQsc wrote:

Here I have a file named: module.d


[...]


There is no main() function since, I want to import this 
module, into another .d file.


( If I try to import and module.d does have main() function I 
get this error: )

[...]






I would like to launch function "interestingFunction()" 
directly using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

[...]


If you are trying to test a function separately from other 
functions, e.g. for testing, then you are approaching unit 
testing.
You could write a unit test block just under the function to 
test like

unittest
{
  interestingFunction;
}

and launch it via rdmd... don't know the syntax right now. But 
here is something:

https://stackoverflow.com/questions/10694994/rdmd-is-not-running-unit-tests

So, I assume something like
rdmd -unittest --main module.d


Hmm, maybe I'll just rename module.d to module_library.d and 
place it in a folder,
then create a new module_run.d file that would launch the 
functions of module_library.d



module\module_library.d
module\module_run.d
README.md


Maybe even place a README.md file explaining how I come up with 
this idea.


And when in need of executing it, I'll just type:

rdmd module\module_run.d


Is it possible to execute a function inside .d script that has no main function?

2019-07-11 Thread BoQsc via Digitalmars-d-learn

Here I have a file named: module.d


import std.stdio   : writeln;

void interestingFunction(){
writeln("Testing");
}


There is no main() function since, I want to import this module, 
into another .d file.


( If I try to import and module.d does have main() function I get 
this error: )
otherFile.d(13): Error: only one main, WinMain, or DllMain 
allowed. Previously found main at module.d(3)






I would like to launch function "interestingFunction()" directly 
using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

C:\Users\User\Desktop\Environment variables>rdmd module.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 134: No Start Address


  1   2   >