mIRC Home    About    Download    Register    News    Help

Print Thread
#271814 02/07/23 04:29 PM
Joined: Apr 2022
Posts: 25
Z
Zenti Offline OP
Ameglian cow
OP Offline
Ameglian cow
Z
Joined: Apr 2022
Posts: 25
Does anyone know of a method in mirc that can be used to read yml files should work similarly to $read and $readini.

I only know that yml files are structured differently. and I can hardly read them out via $read or $readini..

Joined: Jan 2012
Posts: 314
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 314
Originally Posted by Zenti
Does anyone know of a method in mirc that can be used to read yml files ...
mIRC does not have such a built-in method, but you can create it yourself in the form of $your_identifier() using aliases, and add your own switches, parameters and properties to it, which will help process data in different ways when extracting text from a yml file.

🕮 https://en.wikichip.org/wiki/mirc/aliases


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Apr 2022
Posts: 25
Z
Zenti Offline OP
Ameglian cow
OP Offline
Ameglian cow
Z
Joined: Apr 2022
Posts: 25
i Need a Feature or a funtions to read and write to yml files similar to the $readini $read and /write funktion in Mirc.

The reason why I need this is because mirc doesn't take spaces and indentations or tabs etc into account and so it's not possible to set a variable in the following form.

An example:

In a Test.yml
There is the following entry.

Quote
BlackListedBlocks:
- BEDROCK
- OBSIDIAN
- DIAMOND
- DIORITE

I would have to be able to address the section using the new function, which is similar to the $readini function.

The new function would have to be called as follows.

$readyml(file, Section)

So now if I use $readyml(test.yml, BlacklistedBlocks)

The input should reflect the following, taking into account the indentation and spaces.

The output should then be:

Quote
- BEDROCK
- OBSIDIAN
- DIAMOND
- DIORITE

It would be nice if someone could put something like that together for me.

I can't solve this using $read and $readini because readini only recognizes a section marked with [] and 2. doesn't take spaces or indents or tabs into account

/set %var also doesn't work because it also eats up the spaces.

Joined: Jan 2012
Posts: 314
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 314
I have created this script for you that will work as your own identifier "$readyml()" to read files "yml".
But I'm not sure that it will work as effectively if there is another data structure that is different from the one you provided in the example.

Try testing this script code with your file:
Code
alias readyml {
  if (!$1) || (!$2) { echo -a 10* ERROR incorrect parameters: $eval($readyml(filename, section [,N]),0) | halt }
  if (!$exists($1)) { echo -a 10* ERROR file does not exist: $1 | halt }
  var %s $read($1,ntw,$+($2,:)), %r $readn
  if (!%s) { echo -a 10* ERROR section does not exist: $2 | halt }
  if ($readyml_section($1,%r)) {
    if ($3 != $null) {
      if ($3 == 0) return $hget(yml_sect,0).item
      if ($3 > 0) {
        if ($3 > $hget(yml_sect,0).item) { echo -a 10* ERROR there are items in the section: $v2 | halt }
        return $hget(yml_sect,$3)
      }
    }
    else { var %i 1 | while (%i <= $hget(yml_sect,0).item) { echo -a $hget(yml_sect,%i) | inc %i } | halt }
  }
}
alias -l readyml_section {
  .hfree -sw yml_sect | var %p $1, %r $2, %n 1
  while ($true) {
    var %c $calc(%r + %n), %i $read(%p,%c)
    if ($right(%i,1) == :) || (%i == $null) || (%c > $lines(%p)) { return $true }
    if ($left(%i,1) == -) .hadd -m yml_sect %n %i
    inc %n
  }
}


Syntax: $readyml(filename, section [,N])


Test1 - (get all items of a section): //echo -a $readyml(test.yml, BlacklistedBlocks)
Quote
- BEDROCK
- OBSIDIAN
- DIAMOND
- DIORITE

Test2 - (get 3rd item of section): //echo -a $readyml(test.yml, BlacklistedBlocks, 3)
Quote
- DIAMOND

Test3 - (get the number of section items): //echo -a $readyml(test.yml, BlacklistedBlocks, 0)
Quote
4

Test4 - (get the 5th item of the section): //echo -a $readyml(test.yml, BlacklistedBlocks, 5)
Quote
* ERROR there are items in the section: 4


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Apr 2022
Posts: 25
Z
Zenti Offline OP
Ameglian cow
OP Offline
Ameglian cow
Z
Joined: Apr 2022
Posts: 25
Thanks for i the given example was only a example of a section of a yml file...
But the forum here eats spaces too...

the structure of a orginal yml are so:

Quote
BlackListedBlocks:
..- BEDROCK
..- OBSIDIAN
..- DIAMOND
..- DIORITE

the white points befor the -
Serve to display the spaces.

The correct output would then be:
Quote
..- BEDROCK
..- OBSIDIAN
..- DIAMOND
..- DIORITE

However, the structure of the yml should be taken into account when outputting, i.e.: If in the example yml under Blacklistedblocks there are entries with spaces, they should not be missing in the output...

Note
Other yml files could store a different structure so that the given code no longer works, so there must be a general code for all yml files.

Not that an extra alias has to be written for each yml in order to read it out. That's not the case with $read or $readini either... $read randomly reads a line from a file. The disadvantage is that it eats the spaces at the beginning of a file, so $read doesn't work with yml files.

The same applies to $readini..

With Readini, the sections have to be marked with [], so it doesn't work with yml files either.

So we are looking for a function similar to $read and $readini that works for yml files.

Joined: Jan 2012
Posts: 314
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 314
If you want the help provided to you by the developers to be more effective in the form of working code, then it will be better if you attach a link to your post to the "file.yml" you are using for efficient testing and so as not to encounter distortions in the data structure when directly publishing data excerpts from a file.

It would also be a good idea to add links to reference documentation that describe various variations of the data structure of the file with the "yml" extension.

Apparently, the usual built-in mIRC tools will not be able to read and get the result from this file type the way you want.
Either will have to develop a third-party application for reading and writing "yml" files that will be able to interact with mIRC, or will need to leave a request for the required functionality.


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples

Link Copied to Clipboard