Giter VIP home page Giter VIP logo

Comments (5)

DanielGavin avatar DanielGavin commented on June 23, 2024 1

Thanks Simon.

I can make the small change. Yeah I forgot to assign after the replace.

from ols.

DanielGavin avatar DanielGavin commented on June 23, 2024

It already does.

It works fine for Linux, so someone with a MacOS has to figure out why this doesn't work:

home := os.get_env("HOME", context.temp_allocator)
strings.replace(forward_path, "~", home, 1, context.temp_allocator)

from ols.

wiremoons avatar wiremoons commented on June 23, 2024

Hi @DanielGavin

Thought I would try to help with this bug report as I use Odin and macOS.

I tested the above suggested code on macOS and found the code suggested does not work as expected. It does not work on Linux (Ubuntu 22.04.2 LTS on Raspberry Pi) either.

The example output from the test code below on both macOS and Linux is:

% odin run dir_test.odin -file

example path: '~/.Odin'
checking 'forward_path[0]': '126' [~]
env HOME is: '/Users/simon'
Orignal OLS code - updated 'forward_path' is: '~/.Odin'
New code - updated 'forward_path' is: '/Users/simon/.Odin'

Example code used to test:

// run with:  odin run dir_test.odin -file
package main

import "core:fmt"
import "core:strings"
import "core:os"

main :: proc() {
    // create an example path to test in macOS
    forward_path : string = "~/.Odin"
    fmt.printf("\nexample path: '%s'\n",forward_path)
    // Lines below extract from: ols/src/server/requests.odin lines 515-530
    // with additional 'fmt.printf' statements added.
    //
    //Support a basic use of '~'
    when ODIN_OS != .Windows {
        fmt.printf("checking 'forward_path[0]': '%v' [%c]\n",forward_path[0],i32(forward_path[0]))
        if forward_path[0] == '~' {
            home := os.get_env(
                "HOME",
                context.temp_allocator,
            )
            fmt.printf("env HOME is: '%s'\n",home)
            strings.replace(
                forward_path,
                "~",
                home,
                1,
                context.temp_allocator,
            )
            fmt.printf("Orignal OLS code - updated 'forward_path' is: '%s'\n",forward_path)
            //
            // new code below - capture the 'replace' proc returned value
            forward_path, _ := strings.replace(
                forward_path,
                "~",
                home,
                1,
                context.temp_allocator,
            )
            fmt.printf("New code - updated 'forward_path' is: '%s'\n",forward_path)
        }
    }
}

Odin version used:

Odin: dev-2023-06:d97dd99d
OS:   macOS Unknown (build: 22F66, kernel: 22.5.0)
CPU:  ARM64
RAM:  8192 MiB

Odin: dev-2023-06:4c17e2e9
OS:   Ubuntu 22.04.2 LTS, Linux 5.15.0-1029-raspi
CPU:  ARM64
RAM:  7807 MiB

I could not see how to find the OLS version being used - but the last update made was:

commit 6b8e30e7ce91d24389a7ed20a6958f5272b10bfb (HEAD -> master, origin/master, origin/HEAD)
error: cannot run gpg: No such file or directory
Author: DanielGavin <[email protected]>
Date:   Mon Jun 12 13:33:06 2023 +0200

    Update README.md

Do you want me to create a PR with the above change to fix the use of strings.replace or would you rather look at it yourself?

Hope that helps :)

Simon

from ols.

DanielGavin avatar DanielGavin commented on June 23, 2024

The code has been pushed.

from ols.

wiremoons avatar wiremoons commented on June 23, 2024

That's great @DanielGavin - glad it was useful.

from ols.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.