[asterisk-users] Custom langagues

Steve Edwards asterisk.org at sedwards.com
Tue Jan 1 19:00:48 CST 2019


On Tue, 1 Jan 2019, Dovid Bender wrote:

> Hi,
> I am working on writing my own custom language (Yiddish) which resembles de. I found de to be mainly in main/say.c. I am a novice when it comes to c. Would changing:
> } else if (!strncasecmp(lang, "de", 2)) {
> to:
> } else if (!strncasecmp(lang, "de", 2) ||!strncasecmp(lang, "yiddish", 2)) {
> do the trick or am I better of adding where ever I see:
>        } else if (!strncasecmp(lang, "de", 2)) { /* German syntax */
>                 return ast_say_date_de(chan, t, ints, lang);
>  
> 
> to add:
>        } else if (!strncasecmp(lang, "yiddish", 2)) { /* Yiddish syntax (like German) */
>                 return ast_say_date_de(chan, t, ints, lang);

(The 3rd parameter of strncasecmp is the number of bytes to compare. Thus, 
'yippie ki-yay' will match 'yiddish.')

As I interpret your question, is it better to 'piggy-back' on 'de' or 
replicate code for 'yi[ddish]?'

I have no experience with this code and I don't know the magnitude of the 
changes, but if the changes don't involve large blocks of code, my 
personal preference would be to replicate.

It will establish a precedence for future additions. Trying to accommodate 
a multitude of languages with 'if a or b but not c or d...' can lead to 
difficult to comprehend and maintain code.

If you do find some subtle differences, it will be easier to handle.

While 'piggy-backing' may be slightly more efficient (in run time and 
memory), ease of comprehension and maintenance are more important.

As an aside, why is strncasecmp() being used instead of strncmp()? 
Wouldn't it be better to 'down-case' lang once instead of every time it is 
used? (Or is this the only time it is used?)

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
             https://www.linkedin.com/in/steve-edwards-4244281


More information about the asterisk-users mailing list