| 107 | } |
| 108 | |
| 109 | RESTORE_WARNING_FORMAT_NONLITERAL |
| 110 | |
| 111 | /* exclude_cookie is a hack used because we sometimes want to get rumors in a |
| 112 | * context where messages such as "You swallowed the fortune!" that refer to |
| 113 | * cookies should not appear. This has no effect for true rumors since none |
| 114 | * of them contain such references anyway. |
| 115 | */ |
| 116 | char * |
| 117 | getrumor( |
| 118 | int truth, /* 1=true, -1=false, 0=either */ |
| 119 | char *rumor_buf, |
| 120 | boolean exclude_cookie) |
| 121 | { |
| 122 | dlb *rumors; |
| 123 | long beginning, ending; |
| 124 | char line[BUFSZ]; |
| 125 | static const char *cookie_marker = "[cookie] "; |
| 126 | const int marklen = strlen(cookie_marker); |
| 127 | |
| 128 | rumor_buf[0] = '\0'; |
| 129 | if (gt.true_rumor_size < 0L) /* a previous try failed to open RUMORFILE */ |
| 130 | return rumor_buf; |
| 131 | |
| 132 | rumors = dlb_fopen(RUMORFILE, "r"); |
| 133 | if (rumors) { |
| 134 | int count = 0; |
| 135 | int adjtruth; |
| 136 | |
| 137 | do { |
| 138 | rumor_buf[0] = '\0'; |
| 139 | if (gt.true_rumor_size == 0L) { /* if this is 1st outrumor() */ |
| 140 | init_rumors(rumors); |
| 141 | if (gt.true_rumor_size < 0L) { /* init failed */ |
| 142 | Sprintf(rumor_buf, "Error reading \"%.80s\".", RUMORFILE); |
| 143 | return rumor_buf; |
| 144 | } |
| 145 | } |
| 146 | /* |
| 147 | * input: 1 0 -1 |
| 148 | * rn2 \ +1 2=T 1=T 0=F |
| 149 | * adj./ +0 1=T 0=F -1=F |
| 150 | */ |
| 151 | switch (adjtruth = truth + rn2(2)) { |
| 152 | case 2: /*(might let a bogus input arg sneak thru)*/ |
| 153 | case 1: |
| 154 | beginning = (long) gt.true_rumor_start; |
| 155 | ending = gt.true_rumor_end; |
| 156 | break; |
| 157 | case 0: /* once here, 0 => false rather than "either"*/ |
| 158 | case -1: |
| 159 | beginning = (long) gf.false_rumor_start; |
| 160 | ending = gf.false_rumor_end; |
| 161 | break; |
| 162 | default: |
| 163 | impossible("strange truth value for rumor"); |
| 164 | return strcpy(rumor_buf, "Oops..."); |
| 165 | } |
| 166 | Strcpy(rumor_buf, |
no test coverage detected