Menu

Command "source" with a .cir file path include space and Chinese characters

fiveight
2017-04-21
2017-04-21
  • fiveight

    fiveight - 2017-04-21

    Hi All:
    I use command "source" to send a .cir file to ngspice. If this file path include space and Chinese characters. The command failed.
    How can I resolve this problem? Thanks!

     
  • Holger Vogt

    Holger Vogt - 2017-04-21

    To cope with spaces, please use single quotes like 'path/filename' .

    Standard ngspice does understand plain ascii only. There is a development branch utf-8 in our git system. It contains a ngspice version that handles UNICODE characters, using utf-8 encoding. Please check https://sourceforge.net/p/ngspice/ngspice/ci/utf-8/tree/ . You may download this version of ngspice via git or as a snapshot from this web page. You will then have to compile it yourself. If on Windows, you also may download 64 bit binaries ready to use from http://ngspice.sourceforge.net/download.html .

    Holger

     
  • fiveight

    fiveight - 2017-04-26

    Thank you very much!
    But I notice that the command function still use ascii string argument like

    / Caller may send ngspice commands to ngspice.dll.
    Commands are executed immediately
    /
    IMPEXP
    int ngSpice_Command(char* command);

    How can I send unicode command string to this function?

     
    • Holger Vogt

      Holger Vogt - 2017-04-26

      The interface will not change. Your calling program has to offer a
      char *command
      string that is utf-8 encoded.

      This encoding translates UNICODE characters into a series of characters that may be stored in a char* string. Standard Visual C programs do not use utf-8 to encode UNICODE, but wide chars with utf-16. Unfortunately this is not portable. You will have to use functions like WideCharToMultiByte to translate your calling program's wide char strings into utf-8 strings before sending them to ngspice.

      But:
      I did not care about shared ngspice during setting up utf-8 compatibility. I'll have to check if shared ngspice is already enabled to read utf-8 encoded commands. If not, some additions to the source code are due (will also be made available in the utf-8 branch). That may take some time. Please test it using the recommendations from above.

      Holger

       

      Last edit: Holger Vogt 2017-04-27
  • Holger Vogt

    Holger Vogt - 2017-04-28

    Below you will find a short extension to main.c of the controlling program from http://ngspice.sourceforge.net/ngspice-shared-lib/ngspice_cb.7z to send utf-8 commands to ngspice containing UNICODE characters in path and file names.
    No change to the sources of ngspice.dll from the utf-8 branch is needed.

    #else
    #ifdef UTF8
        /* the path and file name with UNICOE characters */
        wchar_t *wcommand = L"source ../../examples-utf-8/стекло/adder_उससे_mos.cir";
        /*get the utf-8 string size required*/
        size_t sreq = WideCharToMultiByte(CP_UTF8, 0, wcommand, -1, NULL, 0, NULL, NULL);
        char *ucommand = (char*)malloc(sreq + 1);
        /*convert the wide char utf-16 to utf-8*/
        WideCharToMultiByte(CP_UTF8, 0, wcommand, -1, ucommand, sreq, NULL, NULL);
        /* send the utf-8 encoded string, process it immediately */
        ret = ((int * (*)(char*)) ngSpice_Command_handle)(ucommand);
        free(ucommand);
    #else
        ret = ((int * (*)(char*)) ngSpice_Command_handle)("source ../../examples/adder_mos.cir");
    #endif
    #endif
    

    Holger

     

Log in to post a comment.