62
errorPrint("@reallocMem(p,0)");
62
i_printfExit(MSG_ReallocP);
64
errorPrint("@reallocMem(0,%d)", n);
64
i_printfExit(MSG_Realloc0, n);
65
65
if(p == EMPTYSTRING)
66
66
return allocMem(n);
67
67
if(!(s = realloc(p, n)))
68
errorPrint("@error re-allocating %u bytes", n);
68
i_printfExit(MSG_ErrorRealloc, n);
555
555
return c == '"' || c == '\'';
558
/* Gather at most 5 parameters from a vararg list
559
* and place them in local variables.
560
* Only take as many as indicated by the percents in a sprintf string.
561
* If we blindly take more, we risk core dumps, at least on the Sun. */
564
varargLocals(va_list p, const char *msg, long *locals)
569
for(cnt = 0; cnt < 5; msg = s) {
570
s = strchr(msg, '%');
578
if(strchr("-.0123456789lhusdfxco", *s)) {
579
long n = va_arg(p, long);
582
} /* while finding percents in msg */
584
/* a little protection, in case they pass too few arguments */
586
locals[cnt++] = (long)"argmissing";
589
558
/* print an error message */
591
560
errorPrint(const char *msg, ...)
593
562
char bailflag = 0;
596
565
va_start(p, msg);
597
varargLocals(p, msg, a);
600
567
if(*msg == '@') {
570
/* I should internationalize this, but it's never suppose to happen! */
603
571
fprintf(stderr, "disaster, ");
604
572
} else if(isdigitByte(*msg)) {
606
573
bailflag = *msg - '0';
609
fprintf(stderr, msg, a[0], a[1], a[2], a[3], a[4]);
577
vfprintf(stderr, msg, p);
610
578
fprintf(stderr, "\n");
617
586
debugPrint(int lev, const char *msg, ...)
621
589
if(lev > debugLevel)
623
591
va_start(p, msg);
624
varargLocals(p, msg, a);
626
printf(msg, a[0], a[1], a[2], a[3], a[4]);
628
595
if(lev == 0 && !memcmp(msg, "warning", 7))
630
597
} /* debugPrint */
633
/* Show the error message, not just the question mark, after these commands. */
634
static const char showerror_cmd[] = "AbefMqrw^";
636
/* Set the error message. Type h to see the message. */
638
setError(const char *msg, ...)
649
varargLocals(p, msg, a);
651
/* Yeah I know, there's a va_list sprintf call; this is old code. */
652
sprintf(errorMsg, msg, a[0], a[1], a[2], a[3], a[4]);
655
if(strlen(errorMsg) >= sizeof (errorMsg)) {
656
printf("disaster, error message, length %d is too long\n",
666
printf("%s\n", errorMsg[0] ? errorMsg : "no errors");
670
showErrorConditional(char cmd)
672
if(helpMessagesOn || strchr(showerror_cmd, cmd))
676
} /* showErrorConditional */
681
errorPrint("1%s", errorMsg);
682
} /* showErrorAbort */
685
browseError(const char *msg, ...)
694
varargLocals(p, msg, a);
697
printf("line %d: ", browseLine);
698
cw->labels[4] = browseLine;
700
printf("browse error: ");
701
printf(msg, a[0], a[1], a[2], a[3], a[4]);
706
/* Javascript errors, we need to see these no matter what. */
708
runningError(const char *msg, ...)
715
varargLocals(p, msg, a);
718
printf("line %d: ", browseLine);
719
cw->labels[4] = browseLine;
721
printf(msg, a[0], a[1], a[2], a[3], a[4]);
726
605
/* Turn perl string into C string, and complain about nulls. */
778
657
char ftype = fileTypeByName(filename, false);
779
658
if(ftype && ftype != 'f') {
780
setError("%s is not a regular file", filename);
659
setError(MSG_RegularFile, filename);
783
662
fh = open(filename, O_RDONLY | O_BINARY);
785
setError("cannot open %s", filename);
664
setError(MSG_NoOpen, filename);
788
667
length = fileSizeByName(filename);
801
680
n = read(fh, buf, length);
802
681
close(fh); /* don't need that any more */
804
setError("cannot read the contents of %s", filename);
683
setError(MSG_NoRead2, filename);
1255
1133
cc = badBrackets = false;
1256
1134
while(c = *s) {
1257
1135
if(t >= re + sizeof (re) - 3) {
1258
setError("shell pattern is too long");
1136
setError(MSG_ShellPatternLong);
1261
1139
if(c == '\\') {
1263
("sorry, I don't know how to expand filenames with \\ in them");
1140
setError(MSG_ExpandBackslash);
1266
1143
/* things we need to escape */
1288
1165
if(badBrackets | cc) {
1289
setError("improperly formed [] pattern");
1166
setError(MSG_ShellSyntax);
1293
1170
debugPrint(7, "shell regexp %s", re);
1294
1171
re_cc = pcre_compile(re, 0, &re_error, &re_offset, 0);
1296
setError("error compiling the shell pattern, %s", re_error);
1173
setError(MSG_ShellCompile, re_error);
1312
1189
re_count = pcre_exec(re_cc, 0, file, strlen(file), 0, 0, re_vector, 3);
1313
1190
if(re_count < -1) {
1314
1191
pcre_free(re_cc);
1315
setError("unexpected error while evaluating the shell pattern");
1192
setError(MSG_ShellExpand);
1318
1195
if(re_count < 0)
1379
1255
if(*mode == 'r')
1380
errorPrint("2cannot open %s", name);
1256
i_printfExit(MSG_OpenFail, name);
1381
1257
else if(*mode == 'w' || *mode == 'a')
1382
errorPrint("2cannot create or write to %s", name);
1258
i_printfExit(MSG_CreateFail, name);
1384
errorPrint("@calling fopen() with invalid mode %s", mode);
1260
i_printfExit(MSG_InvalidFopen, mode);