/* there might be a mimic here posing as an object */
mtmp = m_at(x, y);
if (mtmp && mtmp->m_ap_type == M_AP_OBJECT &&
- mtmp->mappearance == glyphotyp) otmp = 0;
+ mtmp->mappearance == (unsigned)glyphotyp) otmp = 0;
else mtmp = 0;
if (!otmp || otmp->otyp != glyphotyp) {
dlb *fp;
char buf[BUFSZ], newstr[BUFSZ];
char *ep, *dbase_str;
- long txt_offset;
+ unsigned long txt_offset;
int chk_skip;
boolean found_in_file = FALSE, skipping_entry = FALSE;
impossible("can't read 'data' file");
(void) dlb_fclose(fp);
return;
- } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0)
+ } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset == 0L)
goto bad_data_file;
/* look for the appropriate entry */
if (user_typed_name || without_asking || yn("More info?") == 'y') {
winid datawin;
- if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) {
+ if (dlb_fseek(fp, (long)txt_offset + entry_offset, SEEK_SET) < 0) {
pline("? Seek error on 'data' file!");
(void) dlb_fclose(fp);
return;
STATIC_DCL void FDECL(init_rumors, (dlb *));
STATIC_DCL void FDECL(init_oracles, (dlb *));
-static long true_rumor_start, true_rumor_size, true_rumor_end,
- false_rumor_start, false_rumor_size, false_rumor_end;
+/* rumor size variables are signed so that value -1 can be used as a flag */
+static long true_rumor_size = 0L, false_rumor_size;
+/* rumor start offsets are unsigned because they're handled via %lx format */
+static unsigned long true_rumor_start, false_rumor_start;
+/* rumor end offsets are signed because they're compared with [dlb_]ftell() */
+static long true_rumor_end, false_rumor_end;
+/* oracles are handled differently from rumors... */
static int oracle_flg = 0; /* -1=>don't use, 0=>need init, 1=>init done */
static unsigned oracle_cnt = 0;
-static long *oracle_loc = 0;
+static unsigned long *oracle_loc = 0;
STATIC_OVL void
init_rumors(fp)
{
static const char rumors_header[] = "%d,%ld,%lx;%d,%ld,%lx;0,0,%lx\n";
int true_count, false_count; /* in file but not used here */
- long eof_offset;
+ unsigned long eof_offset;
char line[BUFSZ];
(void) dlb_fgets(line, sizeof line, fp); /* skip "don't edit" comment */
&false_count, &false_rumor_size, &false_rumor_start,
&eof_offset) == 7 &&
true_rumor_size > 0L && false_rumor_size > 0L) {
- true_rumor_end = true_rumor_start + true_rumor_size;
+ true_rumor_end = (long)true_rumor_start + true_rumor_size;
/* assert( true_rumor_end == false_rumor_start ); */
- false_rumor_end = false_rumor_start + false_rumor_size;
+ false_rumor_end = (long)false_rumor_start + false_rumor_size;
/* assert( false_rumor_end == eof_offset ); */
} else {
true_rumor_size = -1L; /* init failed */
boolean exclude_cookie;
{
dlb *rumors;
- long tidbit, beginning;
+ long tidbit, beginning;
char *endp, line[BUFSZ], xbuf[BUFSZ];
rumor_buf[0] = '\0';
*/
switch (adjtruth = truth + rn2(2)) {
case 2: /*(might let a bogus input arg sneak thru)*/
- case 1: beginning = true_rumor_start;
+ case 1: beginning = (long)true_rumor_start;
tidbit = Rand() % true_rumor_size;
break;
case 0: /* once here, 0 => false rather than "either"*/
- case -1: beginning = false_rumor_start;
+ case -1: beginning = (long)false_rumor_start;
tidbit = Rand() % false_rumor_size;
break;
default:
/* remove padding */
{
char *x = eos(rumor_buf) - 1;
+
while(x > rumor_buf && *x=='_') x--;
*++x = '\n';
*x = '\0';
if (rumors) {
long ftell_rumor_start = 0L;
+
rumor_buf[0] = '\0';
if (true_rumor_size == 0L) { /* if this is 1st outrumor() */
init_rumors(rumors);
Sprintf(rumor_buf,
"T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
- true_rumor_start, true_rumor_start,
- true_rumor_end, true_rumor_end,
- true_rumor_size, true_rumor_size);
+ (long)true_rumor_start, true_rumor_start,
+ true_rumor_end, (unsigned long)true_rumor_end,
+ true_rumor_size, (unsigned long)true_rumor_size);
putstr(tmpwin, 0, rumor_buf);
Sprintf(rumor_buf,
"F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
- false_rumor_start, false_rumor_start,
- false_rumor_end, false_rumor_end,
- false_rumor_size, false_rumor_size);
+ (long)false_rumor_start, false_rumor_start,
+ false_rumor_end, (unsigned long)false_rumor_end,
+ false_rumor_size, (unsigned long)false_rumor_size);
putstr(tmpwin, 0, rumor_buf);
/*
* the value read in rumors, and display it.
*/
rumor_buf[0] = '\0';
- (void) dlb_fseek(rumors, true_rumor_start, SEEK_SET);
+ (void) dlb_fseek(rumors, (long)true_rumor_start, SEEK_SET);
ftell_rumor_start = dlb_ftell(rumors);
(void) dlb_fgets(line, sizeof line, rumors);
if ((endp = index(line, '\n')) != 0) *endp = 0;
putstr(tmpwin, 0, rumor_buf);
rumor_buf[0] = '\0';
- (void) dlb_fseek(rumors, false_rumor_start, SEEK_SET);
+ (void) dlb_fseek(rumors, (long)false_rumor_start, SEEK_SET);
ftell_rumor_start = dlb_ftell(rumors);
(void) dlb_fgets(line, sizeof line, rumors);
if ((endp = index(line, '\n')) != 0) *endp = 0;
(void) dlb_fgets(line, sizeof line, fp);
if (sscanf(line, "%5d\n", &cnt) == 1 && cnt > 0) {
oracle_cnt = (unsigned) cnt;
- oracle_loc = (long *) alloc((unsigned)cnt * sizeof (long));
+ oracle_loc = (unsigned long *)alloc((unsigned)cnt * sizeof (long));
for (i = 0; i < cnt; i++) {
(void) dlb_fgets(line, sizeof line, fp);
(void) sscanf(line, "%5lx\n", &oracle_loc[i]);
{
mread(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt);
if (oracle_cnt) {
- oracle_loc = (long *) alloc(oracle_cnt * sizeof (long));
+ oracle_loc = (unsigned long *)alloc(oracle_cnt * sizeof (long));
mread(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof (long));
oracle_flg = 1; /* no need to call init_oracles() */
}
/* oracle_loc[1..oracle_cnt-1] are normal ones */
if (oracle_cnt <= 1 && !special) return; /*(shouldn't happen)*/
oracle_idx = special ? 0 : rnd((int) oracle_cnt - 1);
- (void) dlb_fseek(oracles, oracle_loc[oracle_idx], SEEK_SET);
- if (!special) oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt];
+ (void) dlb_fseek(oracles, (long)oracle_loc[oracle_idx],
+ SEEK_SET);
+ if (!special) /* move offset of very last one into this slot */
+ oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt];
tmpwin = create_nhwindow(NHW_TEXT);
if (delphi)
static char *FDECL(version_id_string, (char *,const char *));
static char *FDECL(bannerc_string, (char *,const char *));
static char *FDECL(xcrypt, (const char *));
+static unsigned long FDECL(read_rumors_file,
+ (const char *,int *,long *,unsigned long));
static int FDECL(check_control, (char *));
static char *FDECL(without_control, (char *));
static boolean FDECL(d_filter, (char *));
#define PAD_RUMORS_TO 60
/* common code for do_rumors(). Return 0 on error. */
-static long
-read_rumors_file(
- const char *file_ext,
- int *rumor_count,
- long *rumor_size,
- long old_rumor_offset
-){
+static unsigned long
+read_rumors_file(file_ext, rumor_count, rumor_size, old_rumor_offset)
+const char *file_ext;
+int *rumor_count;
+long *rumor_size;
+unsigned long old_rumor_offset;
+{
char infile[600];
- long rumor_offset;
+ unsigned long rumor_offset;
+
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, file_ext);
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
- return 0;
+ return 0L;
}
/* copy the rumors */
*base = '\0';
}
#endif
-
- (*rumor_count)++;
+ (*rumor_count)++;
#if 0
/*[if we forced binary output, this would be sufficient]*/
*rumor_size += strlen(in_line); /* includes newline */
(void) fputs(xcrypt(in_line), tfp);
}
/* record the current position; next rumors section will start here */
- rumor_offset = ftell(tfp);
+ rumor_offset = (unsigned long)ftell(tfp);
Fclose(ifp); /* all done with rumors.file_ext */
/* the calculated value for *_rumor_count assumes that
which use two byte CR+LF, we need to override that value
[it's much simpler to do so unconditionally, rendering
the loop's accumulation above obsolete] */
-
- *rumor_size = rumor_offset - old_rumor_offset;
+ *rumor_size = (long)(rumor_offset - old_rumor_offset);
return rumor_offset;
}
"%s%04d,%06ld,%06lx;%04d,%06ld,%06lx;0,0,%06lx\n";
char tempfile[600];
int true_rumor_count, false_rumor_count;
- long true_rumor_size, false_rumor_size,
- true_rumor_offset, false_rumor_offset, eof_offset;
+ long true_rumor_size, false_rumor_size;
+ unsigned long true_rumor_offset, false_rumor_offset, eof_offset;
Sprintf(tempfile, DATA_TEMPLATE, "rumors.tmp");
filename[0]='\0';
/* record the current position; true rumors will start here */
true_rumor_offset = ftell(tfp);
- false_rumor_offset = read_rumors_file(
- ".tru", &true_rumor_count,
- &true_rumor_size, true_rumor_offset);
+ false_rumor_offset = read_rumors_file(".tru", &true_rumor_count,
+ &true_rumor_size, true_rumor_offset);
if(!false_rumor_offset) goto rumors_failure;
- eof_offset = read_rumors_file(
- ".fal", &false_rumor_count,
- &false_rumor_size, false_rumor_offset);
+ eof_offset = read_rumors_file(".fal", &false_rumor_count,
+ &false_rumor_size, false_rumor_offset);
if(!eof_offset) goto rumors_failure;
/* get ready to transfer the contents of temp file to output file */
ok = (rewind(ofp) == 0);
if (ok) {
Sprintf(in_line, "header rewrite of \"%s\"", filename);
- ok = (fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, txt_offset) >= 0);
+ ok = (fprintf(ofp, "%s%08lx\n", Dont_Edit_Data,
+ (unsigned long)txt_offset) >= 0);
}
if (!ok) {
dead_data: perror(in_line); /* report the problem */
{
char infile[60], tempfile[60];
boolean in_oracle, ok;
- long txt_offset, offset, fpos;
+ long fpos;
+ unsigned long txt_offset, offset;
int oracle_cnt;
register int i;
/* handle special oracle; it must come first */
(void) fputs("---\n", tfp);
- Fprintf(ofp, "%05lx\n", ftell(tfp)); /* start pos of special oracle */
+ offset = (unsigned long)ftell(tfp);
+ Fprintf(ofp, "%05lx\n", offset); /* start pos of special oracle */
for (i = 0; i < SIZE(special_oracle); i++) {
(void) fputs(xcrypt(special_oracle[i]), tfp);
(void) fputc('\n', tfp);
oracle_cnt = 1;
(void) fputs("---\n", tfp);
- Fprintf(ofp, "%05lx\n", ftell(tfp)); /* start pos of first oracle */
+ offset = (unsigned long)ftell(tfp);
+ Fprintf(ofp, "%05lx\n", offset); /* start pos of first oracle */
in_oracle = FALSE;
while (fgets(in_line, sizeof in_line, ifp)) {
in_oracle = FALSE;
oracle_cnt++;
(void) fputs("---\n", tfp);
- Fprintf(ofp, "%05lx\n", ftell(tfp));
- /* start pos of this oracle */
+ offset = (unsigned long)ftell(tfp);
+ Fprintf(ofp, "%05lx\n", offset); /* start pos of this oracle */
} else {
in_oracle = TRUE;
(void) fputs(xcrypt(in_line), tfp);
if (in_oracle) { /* need to terminate last oracle */
oracle_cnt++;
(void) fputs("---\n", tfp);
- Fprintf(ofp, "%05lx\n", ftell(tfp)); /* eof position */
+ offset = (unsigned long)ftell(tfp);
+ Fprintf(ofp, "%05lx\n", offset); /* eof position */
}
/* record the current position */
- txt_offset = ftell(ofp);
+ txt_offset = (unsigned long)ftell(ofp);
Fclose(ifp); /* all done with original input file */
/* reprocess the scratch file; 1st format an error msg, just in case */
#endif
if (!(ok = (fpos = ftell(ofp)) >= 0)) break;
if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break;
- {
- /* gcc's format checking issues a warning when using
- %lx to read into a signed long, so force unsigned;
- casting &offset to unsigned long * works but is iffy */
- unsigned long uloffset;
- int itmp = fscanf(ofp, "%5lx", &uloffset);
-
- offset = (long)uloffset;
- if (!(ok = (itmp == 1))) break;
- }
+ if (!(ok = (fscanf(ofp, "%5lx", &offset) == 1))) break;
#ifdef MAC
# ifdef __MWERKS__
/*
# endif
#endif
if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break;
- if (!(ok = (fprintf(ofp, "%05lx\n", offset + txt_offset) >= 0)))
- break;
+ offset += txt_offset;
+ if (!(ok = (fprintf(ofp, "%05lx\n", offset) >= 0))) break;
}
}
if (!ok) {