Skip to content
Draft

fixes #130

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cligen_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ vcprintf(cbuf *cb,
*/
int
cbuf_append_str(cbuf *cb,
char *str)
const char *str)
{
size_t len0;
size_t len;
Expand Down
2 changes: 1 addition & 1 deletion cligen_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int cprintf(cbuf *cb, const char *format, ...) __attribute__ ((format (prin
int vcprintf(cbuf *cb, const char *format, va_list ap);
void cbuf_reset(cbuf *cb);
int cbuf_append(cbuf *cb, int c);
int cbuf_append_str(cbuf *cb, char *str);
int cbuf_append_str(cbuf *cb, const char *str);
int cbuf_append_buf(cbuf *cb, void *src, size_t n);
int cbuf_trunc(cbuf *cb, size_t i);

Expand Down
12 changes: 6 additions & 6 deletions cligen_cv.c
Comment thread
klement marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
/*
* URL protocol strings
*/
static char *cg_urlprotostr[] = {
static const char *cg_urlprotostr[] = {
NULL,
"file",
"flash",
Expand Down Expand Up @@ -1336,7 +1336,7 @@ parse_dec64(char *str,

if (n<=0 || n>18){
if (reason != NULL)
if ((*reason = cligen_reason("%s: fraction-digit=%d given but should be in interval [1:18]", __FUNCTION__, n)) == NULL){
if ((*reason = cligen_reason("%s: fraction-digit=%d given but should be in interval [1:18]", __func__, n)) == NULL){
Comment thread
klement marked this conversation as resolved.
goto done;
}
retval = 0;
Expand Down Expand Up @@ -2089,7 +2089,7 @@ cv_str2type(const char *str)
const char *
cv_type2str(enum cv_type type)
{
char *str = NULL;
const char *str = NULL;
switch (type){
case CGV_ERR:
str="err";
Expand Down Expand Up @@ -2164,7 +2164,7 @@ cv_type2str(enum cv_type type)
str="empty";
break;
default:
fprintf(stderr, "%s: invalid type: %d\n", __FUNCTION__, type);
fprintf(stderr, "%s: invalid type: %d\n", __func__, type);
break;
}
return str;
Expand Down Expand Up @@ -2510,14 +2510,14 @@ cv2str(cg_var *cv,
cv->var_ipv4masklen);
break;
case CGV_IPV6ADDR:
if (inet_ntop(AF_INET6, &cv->var_ipv6addr, straddr, sizeof(straddr)) < 0){
if (NULL == inet_ntop(AF_INET6, &cv->var_ipv6addr, straddr, sizeof(straddr))){
fprintf(stderr, "inet_ntop: %s\n", strerror(errno));
return -1;
}
len = snprintf(str, size, "%s", straddr);
break;
case CGV_IPV6PFX:
if (inet_ntop(AF_INET6, &cv->var_ipv6addr, straddr, sizeof(straddr)) < 0){
if (NULL == inet_ntop(AF_INET6, &cv->var_ipv6addr, straddr, sizeof(straddr))){
fprintf(stderr, "inet_ntop: %s\n", strerror(errno));
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions cligen_cvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ next_token(char **s0,

s = *s0;
if (s==NULL){
fprintf(stderr, "%s: null string\n", __FUNCTION__);
fprintf(stderr, "%s: null string\n", __func__);
return -1;
}
for (s=*s0; *s; s++){ /* First iterate through delimiters */
Expand Down Expand Up @@ -818,7 +818,7 @@ next_token(char **s0,
}
}
if ((token=malloc(len+1)) == NULL){
fprintf(stderr, "%s: malloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: malloc: %s\n", __func__, strerror(errno));
return -1;
}
memcpy(token, st, len);
Expand Down
16 changes: 8 additions & 8 deletions cligen_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ co_expand_sub(cg_obj *co0,
co_up_set(con, coparent);
if (co0->co_command)
if ((con->co_command = strdup(co0->co_command)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_prefix)
if ((con->co_prefix = strdup(co0->co_prefix)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_cvec)
Expand All @@ -126,20 +126,20 @@ co_expand_sub(cg_obj *co0,
if (co0->co_type == CO_VARIABLE){
if (co0->co_expand_fn_str)
if ((con->co_expand_fn_str = strdup(co0->co_expand_fn_str)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_expand_fn_vec)
if ((con->co_expand_fn_vec = cvec_dup(co0->co_expand_fn_vec)) == NULL)
goto done;
if (co0->co_translate_fn_str)
if ((con->co_translate_fn_str = strdup(co0->co_translate_fn_str)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_show)
if ((con->co_show = strdup(co0->co_show)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_rangecvv_low)
Expand All @@ -150,12 +150,12 @@ co_expand_sub(cg_obj *co0,
goto done;
if (co0->co_choice)
if ((con->co_choice = strdup(co0->co_choice)) == NULL){
fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: strdup: %s\n", __func__, strerror(errno));
goto done;
}
if (co0->co_regex)
if ((con->co_regex = cvec_dup(co0->co_regex)) == NULL){
fprintf(stderr, "%s: cvec_dup: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: cvec_dup: %s\n", __func__, strerror(errno));
goto done;
}
} /* CO_VARIABLE */
Expand Down Expand Up @@ -962,7 +962,7 @@ pt_expand(cligen_handle h,
*/
cligen_parsetree_sort(ptn, 0);
if (cligen_logsyntax(h) > 0){
fprintf(stderr, "%s:\n", __FUNCTION__);
fprintf(stderr, "%s:\n", __func__);
pt_print1(stderr, ptn, 0);
}
ok:
Expand Down
26 changes: 13 additions & 13 deletions cligen_getline.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ static void gl_init1(void); /* prepare to edit a line */
static void gl_cleanup(void); /* to undo gl_init1 */
void gl_char_init(void); /* get ready for no echo input */
void gl_char_cleanup(void); /* undo gl_char_init */
static size_t (*gl_strlen)(const char *) = (size_t(*)())strlen;
static size_t (*gl_strlen)(const char *) = strlen;
/* returns printable prompt width */

static int gl_addchar(cligen_handle h, int c); /* install specified char */
static void gl_del(cligen_handle h, int loc); /* del, either left (-1) or cur (0) */
static inline void gl_fixup(cligen_handle h, char*,int,int);/* fixup state variables and screen */
static inline void gl_fixup(cligen_handle h, const char*,int,int);/* fixup state variables and screen */
static int gl_getc(cligen_handle h); /* read one char from terminal */
static void gl_kill(cligen_handle h, int pos); /* delete to EOL */
static void gl_kill_begin(cligen_handle h, int pos); /* delete to BEGIN of line */
static int gl_kill_word(cligen_handle h, int pos); /* delete word */
static void gl_newline(cligen_handle); /* handle \n or \r */
static int gl_puts(char *buf); /* write a line to terminal */
static int gl_puts(const char *buf); /* write a line to terminal */

static void gl_transpose(cligen_handle h); /* transpose two chars */
static int gl_yank(cligen_handle h); /* yank killed text */
Expand Down Expand Up @@ -488,7 +488,7 @@ gl_putc(int c)
/******************** fairly portable part *********************************/

static int
gl_puts(char *buf)
gl_puts(const char *buf)
{
int len;

Expand Down Expand Up @@ -586,7 +586,7 @@ gl_getline(cligen_handle h,
int c;
int loc;
int tmp;
char *gl_prompt;
const char *gl_prompt;
int escape = 0;
#ifdef __unix__
int sig;
Expand Down Expand Up @@ -1172,7 +1172,7 @@ gl_redraw(cligen_handle h)
*/
static void
gl_fixup_noscroll(cligen_handle h,
char *prompt,
const char *prompt,
int change,
int cursor)
{
Expand Down Expand Up @@ -1286,7 +1286,7 @@ gl_fixup_noscroll(cligen_handle h,
*/
static void
gl_fixup_scroll(cligen_handle h,
char *prompt,
const char *prompt,
int change,
int cursor)
{
Expand Down Expand Up @@ -1396,20 +1396,20 @@ gl_fixup_scroll(cligen_handle h,

static inline void
gl_fixup(cligen_handle h,
char *prompt,
const char *prompt,
int change,
int cursor)
{
if (gl_scrolling_mode)
return gl_fixup_scroll(h, prompt, change, cursor);
gl_fixup_scroll(h, prompt, change, cursor);
else
return gl_fixup_noscroll(h, prompt, change, cursor);
gl_fixup_noscroll(h, prompt, change, cursor);
}

/******************* strlen stuff **************************************/

void
gl_strwidth(size_t (*func)())
gl_strwidth(size_t (*func)(const char*))
{
if (func != 0) {
gl_strlen = func;
Expand Down Expand Up @@ -1509,7 +1509,7 @@ search_back(cligen_handle h,
int new_search)
{
int found = 0;
char *p, *loc;
const char *p, *loc;
int last;

search_forw_flg = 0;
Expand Down Expand Up @@ -1550,7 +1550,7 @@ search_forw(cligen_handle h,
int new_search)
{
int found = 0;
char *p, *loc;
const char *p, *loc;
int last;

search_forw_flg = 1;
Expand Down
2 changes: 1 addition & 1 deletion cligen_getline.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/*
* Types
*/
typedef size_t (*gl_strwidth_proc)(char *);
typedef size_t (*gl_strwidth_proc)(const char *);

/*
* Prototypes
Expand Down
14 changes: 7 additions & 7 deletions cligen_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cligen_init(void)
struct sigaction sigh;

if ((ch = malloc(sizeof(*ch))) == NULL){
fprintf(stderr, "%s: malloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s: malloc: %s\n", __func__, strerror(errno));
goto done;
}
memset(ch, 0, sizeof(*ch));
Expand Down Expand Up @@ -303,7 +303,7 @@ cligen_prompt(cligen_handle h)
*/
int
cligen_prompt_set(cligen_handle h,
char *prompt)
const char *prompt)
{
struct cligen_handle *ch = handle(h);

Expand Down Expand Up @@ -372,7 +372,7 @@ cligen_pt_head_active_set(cligen_handle h,
* bar @bar;
* y;
*/
char*
const char*
cligen_treename_keyword(cligen_handle h)
{
struct cligen_handle *ch = handle(h);
Expand Down Expand Up @@ -1106,12 +1106,12 @@ cligen_buf_init(cligen_handle h)
struct cligen_handle *ch = handle(h);

if ((ch->ch_buf = malloc(_getline_bufsize)) == NULL){
fprintf(stderr, "%s malloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s malloc: %s\n", __func__, strerror(errno));
return -1;
}
memset(ch->ch_buf, 0, _getline_bufsize);
if ((ch->ch_killbuf = malloc(_getline_killbufsize)) == NULL){
fprintf(stderr, "%s malloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s malloc: %s\n", __func__, strerror(errno));
return -1;
}
memset(ch->ch_killbuf, 0, _getline_killbufsize);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ cligen_buf_increase(cligen_handle h,
while (_getline_bufsize < len1 + 1)
_getline_bufsize *= 2;
if ((ch->ch_buf = realloc(ch->ch_buf, _getline_bufsize)) == NULL){
fprintf(stderr, "%s realloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s realloc: %s\n", __func__, strerror(errno));
return -1;
}
memset(ch->ch_buf+len0, 0, _getline_bufsize-len0);
Expand All @@ -1163,7 +1163,7 @@ cligen_killbuf_increase(cligen_handle h,
while (_getline_killbufsize < len1 + 1)
_getline_killbufsize *= 2;
if ((ch->ch_killbuf = realloc(ch->ch_killbuf, _getline_killbufsize)) == NULL){
fprintf(stderr, "%s realloc: %s\n", __FUNCTION__, strerror(errno));
fprintf(stderr, "%s realloc: %s\n", __func__, strerror(errno));
return -1;
}
memset(ch->ch_killbuf+len0, 0, _getline_killbufsize-len0);
Expand Down
8 changes: 4 additions & 4 deletions cligen_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
* @retval -1 Error
* @code
* void *wh = NULL;
* cligen_eval_wrap_cb(h, &wh, "myfn", __FUNCTION__);
* cligen_eval_wrap_cb(h, &wh, "myfn", __func__);
* .. User callback
* cligen_eval_wrap_cb(h, &wh, "myfn", __FUNCTION__);
* cligen_eval_wrap_cb(h, &wh, "myfn", __func__);
* See cligen_eval
*/
typedef int (cligen_eval_wrap_fn)(void *arg, void **wh, const char *name, const char *fn);
Expand Down Expand Up @@ -117,15 +117,15 @@ char cligen_comment(cligen_handle h);
int cligen_comment_set(cligen_handle h, char c);

char* cligen_prompt(cligen_handle h);
int cligen_prompt_set(cligen_handle h, char *prompt);
int cligen_prompt_set(cligen_handle h, const char *prompt);

pt_head *cligen_pt_head_get(cligen_handle h);
int cligen_pt_head_set(cligen_handle h, pt_head *ph);

pt_head *cligen_pt_head_active_get(cligen_handle h);
int cligen_pt_head_active_set(cligen_handle h, pt_head *ph);

char *cligen_treename_keyword(cligen_handle h);
const char *cligen_treename_keyword(cligen_handle h);
int cligen_treename_keyword_set(cligen_handle h, char *name);

/* After an evaluation (callback), which node in the parse-tree? */
Expand Down
2 changes: 1 addition & 1 deletion cligen_hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ str2fn(char *name,
}

/*! The command syntax specification */
static char *hello_syntax = "prompt=\"hello> \";\n"
static const char *hello_syntax = "prompt=\"hello> \";\n"
"hello(\"Greet the world\") world, cb(\"Hello World!\");"
;

Expand Down
Loading