Fix prefix in section

This commit is contained in:
Aoran Zeng 2025-07-14 04:05:09 +08:00
parent 685ae27d23
commit 572851f576
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 35 additions and 14 deletions

View File

@ -47,7 +47,7 @@ wr_anaconda_setsrc (char *option)
{
chsrc_yield_source_and_confirm (wr_anaconda);
char *w = xy_str_gsub (_rawstr4c_condarc, "@1@", source.url);
char *w = xy_str_gsub (RAWSTR_wr_anaconda_condarc, "@1@", source.url);
/* Windows 也是在这里 */
char *configfile = xy_2strjoin (xy_os_home, "/.condarc");

View File

@ -1,10 +1,10 @@
#pragma once
/**
* Generated by rawstr4c v0.1.0-2025/07/14
* Generated by rawstr4c v0.1.0.1-2025/07/14
*
* Date: 2025-07-14T03:39:05.341580+08:00
* Date: 2025-07-14T04:00:07.816167+08:00
*/
char _rawstr4c_condarc[] = "\143\150\141\156\156\145\154\163\072\012\040\040\055\040\144\145\146\141\165\154\164\163\012\163\150\157\167\137\143\150\141\156\156\145\154\137\165\162\154\163\072\040\164\162\165\145\012\144\145\146\141\165\154\164\137\143\150\141\156\156\145\154\163\072\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\155\141\151\156\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\162\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\155\163\171\163\062\012\143\165\163\164\157\155\137\143\150\141\156\156\145\154\163\072\012\040\040\143\157\156\144\141\055\146\157\162\147\145\072\040\100\061\100\057\141\156\141\143\157\156\144\141\057\143\154\157\165\144\012\040\040\160\171\164\157\162\143\150\072\040\100\061\100\057\141\156\141\143\157\156\144\141\057\143\154\157\165\144\012";
char RAWSTR_wr_anaconda_condarc[] = "\143\150\141\156\156\145\154\163\072\012\040\040\055\040\144\145\146\141\165\154\164\163\012\163\150\157\167\137\143\150\141\156\156\145\154\137\165\162\154\163\072\040\164\162\165\145\012\144\145\146\141\165\154\164\137\143\150\141\156\156\145\154\163\072\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\155\141\151\156\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\162\012\040\040\055\040\100\061\100\057\141\156\141\143\157\156\144\141\057\160\153\147\163\057\155\163\171\163\062\012\143\165\163\164\157\155\137\143\150\141\156\156\145\154\163\072\012\040\040\143\157\156\144\141\055\146\157\162\147\145\072\040\100\061\100\057\141\156\141\143\157\156\144\141\057\143\154\157\165\144\012\040\040\160\171\164\157\162\143\150\072\040\100\061\100\057\141\156\141\143\157\156\144\141\057\143\154\157\165\144\012";

View File

@ -63,12 +63,21 @@ my class CVariableNameGenerator {
return $section-config.get('name', $title.lc).as-string();
}
my $prefix = $global-config.get('prefix', '_rawstr4c').as-string();
my $language = $section-config.get('language').as-string();
my $postfix = self.resolve-postfix($global-config, $language);
# 优先从 section-config 获取配置,如果没有则从 global-config 获取
my $prefix = $section-config.exist('prefix') ??
$section-config.get('prefix').as-string() !!
$global-config.get('prefix', '_rawstr4c').as-string();
my $keep-prefix = $section-config.get('keep-prefix', 'true').as-bool();
my $keep-postfix = $section-config.get('keep-postfix', 'true').as-bool();
my $language = $section-config.get('language').as-string();
my $postfix = self.resolve-postfix($global-config, $section-config, $language);
my $keep-prefix = $section-config.exist('keep-prefix') ??
$section-config.get('keep-prefix').as-bool() !!
$global-config.get('keep-prefix', 'true').as-bool();
my $keep-postfix = $section-config.exist('keep-postfix') ??
$section-config.get('keep-postfix').as-bool() !!
$global-config.get('keep-postfix', 'true').as-bool();
my $name = $section-config.get('name', $title.lc).as-string();
$name = $name.subst(/\s+/, '_', :g);
@ -84,8 +93,11 @@ my class CVariableNameGenerator {
return $var-name || "unnamed_var";
}
method resolve-postfix($global-config, $language) {
my $postfix = $global-config.get('postfix');
method resolve-postfix($global-config, $section-config, $language) {
# 优先从 section-config 获取 postfix
my $postfix = $section-config.exist('postfix') ??
$section-config.get('postfix') !!
$global-config.get('postfix');
if $postfix.is-mode() && $postfix.as-mode() eq 'use-language' {
return $language ?? 'in_' ~ $language !! '';
@ -204,9 +216,16 @@ class Generator {
}
method get-config-value($global-config, $section-config, $key, $default = '') {
return $section-config.exist($key) ??
$section-config.get($key) !!
$global-config.get($key, $default);
# 优先级section-config > global-config > default
if $section-config && $section-config.exist($key) {
return $section-config.get($key);
}
elsif $global-config && $global-config.exist($key) {
return $global-config.get($key);
}
else {
return $global-config.get($key, $default);
}
}
@ -233,7 +252,9 @@ class Generator {
say "Output mode = $output-mode";
my $language = $section-config.get('language', 'None').as-string();
my $prefix = self.get-config-value($global-config, $section-config, 'prefix', '_rawstr4c').as-string();
say "Language = $language";
say "Prefix = $prefix (from " ~ ($section-config.exist('prefix') ?? 'section' !! 'global') ~ ")";
say '';
}