MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / el_source

Function el_source

extern/editline/src/el.c:536–587  ·  view source on GitHub ↗

el_source(): * Source a file */

Source from the content-addressed store, hash-verified

534 * Source a file
535 */
536public int
537el_source(EditLine *el, const char *fname)
538{
539 FILE *fp;
540 size_t len;
541 char *ptr;
542 char *path = NULL;
543 const Char *dptr;
544 int error = 0;
545
546 fp = NULL;
547 if (fname == NULL) {
548 static const char elpath[] = "/.editrc";
549 size_t plen = sizeof(elpath);
550
551 if ((ptr = secure_getenv("HOME")) == NULL)
552 return -1;
553 plen += strlen(ptr);
554 if ((path = el_malloc(plen * sizeof(*path))) == NULL)
555 return -1;
556 (void)snprintf(path, plen, "%s%s", ptr, elpath);
557 fname = path;
558 }
559 if (fp == NULL)
560 fp = fopen(fname, "r");
561 if (fp == NULL) {
562 el_free(path);
563 return -1;
564 }
565
566 while ((ptr = fgetln(fp, &len)) != NULL) {
567 if (*ptr == '\n')
568 continue; /* Empty line. */
569 dptr = ct_decode_string(ptr, &el->el_scratch);
570 if (!dptr)
571 continue;
572 if (len > 0 && dptr[len - 1] == '\n')
573 --len;
574
575 /* loop until first non-space char or EOL */
576 while (*dptr != '\0' && Isspace(*dptr))
577 dptr++;
578 if (*dptr == '#')
579 continue; /* ignore, this is a comment line */
580 if ((error = parse_line(el, dptr)) == -1)
581 break;
582 }
583
584 el_free(path);
585 (void) fclose(fp);
586 return error;
587}
588
589
590/* el_resize():

Callers 2

rl_initializeFunction · 0.85
rl_read_init_fileFunction · 0.85

Calls 7

secure_getenvFunction · 0.85
fgetlnFunction · 0.85
ct_decode_stringFunction · 0.85
parse_lineFunction · 0.85
fcloseFunction · 0.85
snprintfFunction · 0.50
fopenFunction · 0.50

Tested by

no test coverage detected