home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / xbbs / part03 < prev    next >
Encoding:
Text File  |  1992-09-08  |  63.6 KB  |  2,789 lines

  1. Newsgroups: comp.sources.misc
  2. From: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  3. Subject:  v32i018:  xbbs - A Bulletin Board System for System V, Part03/11
  4. Message-ID: <1992Sep9.044907.25825@sparky.imd.sterling.com>
  5. X-Md4-Signature: baf031bae7063d7034fa461ced244e24
  6. Date: Wed, 9 Sep 1992 04:49:07 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  10. Posting-number: Volume 32, Issue 18
  11. Archive-name: xbbs/part03
  12. Environment: SYSV, Xenix
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  bbsc2.c bbscfile.c bbscmisc.c
  19. # Wrapped by kent@sparky on Fri Sep  4 12:48:48 1992
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 3 (of 11)."'
  23. if test -f 'bbsc2.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'bbsc2.c'\"
  25. else
  26.   echo shar: Extracting \"'bbsc2.c'\" \(42113 characters\)
  27.   sed "s/^X//" >'bbsc2.c' <<'END_OF_FILE'
  28. X/* bbsc2.c    */
  29. X
  30. X#include "bbsc12.h"
  31. X
  32. Xint             contin;
  33. Xextern int      zip;
  34. X
  35. Xeditline(line_no, tflag)
  36. X    int             line_no;
  37. X    char            tflag;
  38. X{
  39. X    char           *work_ptr,    /* pointers */
  40. X                   *msg_ptr, *new_ptr, tmp_tmp[3], byte;
  41. X    int             i;    /* a counter */
  42. X
  43. X    work_msg[0] = '\0';    /* init strings */
  44. X    buf128[0] = '\0';
  45. X    strcpy(tmp_tmp, " ");
  46. X    i = 1;            /* assume at line one */
  47. X
  48. X    work_ptr = work_msg;    /* put the addr of work_msg in the pointer */
  49. X    msg_ptr = msg_text;    /* put the addr of the global message in ptr */
  50. X    new_ptr = buf128;    /* the new line too */
  51. X
  52. X    while (byte = *msg_ptr) {    /* if at the line then found it's
  53. X                     * start */
  54. X        if (line_no == i)
  55. X            break;    /* found the line        */
  56. X        while (byte = *msg_ptr++) {    /* move msg to work area *//* u
  57. X                         * ntil end of msg */
  58. X            *work_ptr++ = byte;
  59. X            if (byte == '\n') {    /* end of line? */
  60. X                i++;
  61. X                break;    /* then stop moving */
  62. X            }
  63. X        }
  64. X    }
  65. X    if (byte == 0) {    /* if true then there ain't no such beast */
  66. X        portsout("Hmmm, can't seem to find that line");
  67. X        portsout(CRLF);
  68. X        portsout("   give me another chance, ok?");
  69. X        portsout(CRLF);
  70. X        return;        /* here we go round the mulberry bush */
  71. X    }
  72. X
  73. X    portsout(CRLF);
  74. X    portsout("Line to ");
  75. X    if (tflag == 'E') {
  76. X        portsout("edit");
  77. X    } else if (tflag == 'I') {
  78. X        portsout("insert after");
  79. X    } else if (tflag == 'D') {
  80. X        portsout("delete");
  81. X    } else if (tflag == 'R') {
  82. X        portsout("replace");
  83. X    } else if (tflag == 'N') {
  84. X        portsout("center");
  85. X    } else if (tflag == 'B') {
  86. X        portsout("block");
  87. X    } else
  88. X        return;
  89. X
  90. X    portsout(" is:");
  91. X    portsout(CRLF);
  92. X    portsout(">");
  93. X    x_pathandfile[0] = '\0';
  94. X
  95. X    while (byte = *msg_ptr++) {    /* show the line to edit */
  96. X        tmp_tmp[0] = byte;
  97. X        strcat(x_pathandfile, tmp_tmp);
  98. X        if (tflag == 'I') {
  99. X            *work_ptr++ = byte;    /* if adding new line copy */
  100. X        }
  101. X        if (byte == '\n')
  102. X            break;
  103. X        portout(byte);
  104. X    }
  105. X    portsout(CRLF);
  106. X
  107. X    if (tflag == 'D') {
  108. X        portsout("Are you sure? (y/N) ==> ");
  109. X        byte = portin();/* get answer */
  110. X        portout(byte);    /* send it back */
  111. X        if ((byte != 'Y') && (byte != 'y'))
  112. X            return;
  113. X        cnt1--;
  114. X    } else {
  115. X        if (tflag == 'E') {
  116. X            if (substs() == 1)
  117. X                return;
  118. X        }
  119. X        if (tflag == 'N') {
  120. X            center_text();
  121. X        }
  122. X        if (tflag == 'B') {
  123. X            block_text();
  124. X        }
  125. X        if (tflag == 'R') {
  126. X            portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  127. X            portsout(CRLF);
  128. X            portsout("R: ");
  129. X            portsin(buf128, 72);
  130. X            strcat(buf128, "\n\0");
  131. X            portsout(CRLF);
  132. X        }
  133. X        if (tflag == 'I') {
  134. X            portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  135. X            portsout(CRLF);
  136. X            portsout("I: ");
  137. X            portsin(buf128, 72);
  138. X            strcat(buf128, "\n\0");
  139. X            portsout(CRLF);
  140. X            cnt1++;
  141. X        }
  142. X        while (*work_ptr++ = *new_ptr++) { /* tag on new line to */ ;
  143. X        }        /* work area */
  144. X        *work_ptr--;    /* back up one */
  145. X    }
  146. X
  147. X    while (*work_ptr++ = *msg_ptr++) { /* now move in rest of */ ;
  148. X    }            /* message to work area */
  149. X    *work_ptr++ = '\0';    /* for luck */
  150. X
  151. X    strcpy(msg_text, work_msg);    /* replace the message with the */
  152. X    /* new line inserted */
  153. X}
  154. Xblock_text()
  155. X{
  156. X    char buffer[82], *ptr;
  157. X    int len, i, j, k;
  158. X    int stt, stp;
  159. X    int spaces[80], words[80], spaces2add[80];
  160. X    for (i=0; i<80; i++) {
  161. X        spaces[i] = -1;
  162. X        words[i] = -1;
  163. X        spaces2add[i] = 0;
  164. X    }
  165. X    ptr = x_pathandfile;
  166. X    len = strlen(x_pathandfile);
  167. X    if( len < 55 )  {
  168. X        strcpy(buf128, x_pathandfile);
  169. X        return;
  170. X    }
  171. X    while ( *ptr == (char) ' ') {       /* get rid of initial spaces */
  172. X        ptr++;
  173. X        len--;
  174. X    }
  175. X    if( len < 55 ) {
  176. X        strcpy(buf128, ptr);
  177. X        return;
  178. X    }
  179. X    strcpy(buffer, ptr);
  180. X    buffer[73]='\0';
  181. X    i = 0;
  182. X    ptr = strrchr( buffer, '\n');
  183. X    if ( ptr != NULL ) {
  184. X        *ptr = '\0';
  185. X        i=1;
  186. X        ptr--;
  187. X    }
  188. X    else {
  189. X        ptr = buffer + strlen(buffer) - 1;
  190. X    }
  191. X    if( *ptr == (char) '\r' ) {
  192. X        *ptr = '\0';
  193. X        ptr--;
  194. X    }
  195. X    len = strlen(buffer);
  196. X    while (*ptr) {
  197. X        if( *ptr == (char)' ') {        /* get rid of terminal spaces */
  198. X            *ptr = '\0';
  199. X            if( ptr == buffer) {
  200. X                strcpy(buf128, x_pathandfile);
  201. X                return;
  202. X            }
  203. X            ptr--;
  204. X            len--;
  205. X        }
  206. X        else
  207. X            break;
  208. X    }    
  209. X    if(len >= 72) {
  210. X        strcpy(buf128, x_pathandfile);
  211. X        return;
  212. X    }
  213. X    ptr = buffer;
  214. X    j = 0;
  215. X    while (*ptr) {
  216. X        if( *ptr == (char) ' ') {
  217. X            spaces[j] = 0;
  218. X            *ptr = '\0';
  219. X        }
  220. X        else
  221. X            spaces[j] = 1;
  222. X        ptr++; j++;
  223. X    }
  224. X    j=0;
  225. X    stt=0;
  226. X    while ( 1 ) {
  227. X        for(stp = stt; stp < 80; stp++ ) {
  228. X            if( spaces[stp] == -1 )
  229. X                goto Out_loop;
  230. X            if( spaces[stp] == 0) {
  231. X                words[j] = stp - stt;
  232. X                stt = stp + 1;
  233. X                j++;
  234. X                break;
  235. X            }
  236. X        }
  237. X    }
  238. XOut_loop:
  239. X
  240. X    stp = len;
  241. X    k=1;
  242. X    while(1) {
  243. X        for ( j=0; j<80; j++ ) {
  244. X            if(words[j] == -1 )
  245. X                break;
  246. X            if( words[j] == k ) {
  247. X                spaces2add[j]++;    
  248. X                stp++;
  249. X                if(stp == 72)
  250. X                    goto Out_loop2;
  251. X            }
  252. X        }
  253. X        k++;
  254. X        if( k > 72)
  255. X            k = 1;
  256. X    }
  257. XOut_loop2:
  258. X    j=0;
  259. X    ptr = buffer;
  260. X    strcpy(buf128, buffer);
  261. X    while ( words[j] != -1 ) {
  262. X        while(*ptr != (char) '\0')
  263. X            ptr++;
  264. X        ptr++;
  265. X        strcat(buf128, " ");
  266. X        for (k=0; k < spaces2add[j]; k++)
  267. X            strcat(buf128, " ");
  268. X        strcat(buf128, ptr);
  269. X        j++;
  270. X        if(( k=strlen(buf128)) >= 72)
  271. X            break;
  272. X    }
  273. X    if(i)
  274. X        strcat(buf128,"\n");        
  275. X        
  276. X}
  277. X    
  278. X        
  279. X    
  280. X
  281. Xcenter_text()
  282. X{
  283. X    int len;
  284. X    int newline;
  285. X    char *ptr;
  286. X    newline = 0;
  287. X    ptr = x_pathandfile;
  288. X    len = strlen(x_pathandfile);
  289. X    if (len <= 0) {
  290. X        strcpy(buf128, x_pathandfile);
  291. X        return;
  292. X    }
  293. X    ptr = x_pathandfile + len -1;
  294. X    if( *ptr = '\n') {
  295. X        *ptr = '\0';
  296. X        ptr --;
  297. X        newline = 1;
  298. X    }
  299. X
  300. X    while ( *ptr == ' ') {
  301. X        *ptr = '\0';
  302. X        ptr--;
  303. X        if( ptr < x_pathandfile) {
  304. X            strcpy(buf128, x_pathandfile);
  305. X            return;
  306. X        }
  307. X    }
  308. X    len = strlen(x_pathandfile);
  309. X    if( len <= 0) {
  310. X        strcpy( buf128, x_pathandfile);
  311. X        return;
  312. X    }
  313. X    ptr = x_pathandfile;
  314. X    while (*ptr == ' ') {
  315. X        if( *ptr == '\0') {
  316. X            strcpy(buf128, x_pathandfile);
  317. X            return;
  318. X        }
  319. X        ptr++;
  320. X    }
  321. X    strcpy(buf128, ptr);
  322. X    len = (72 - (strlen(buf128)))/2;
  323. X    x_pathandfile[0] = '\0';
  324. X    ptr = x_pathandfile;
  325. X    while ( len ) {
  326. X        *ptr = ' ';
  327. X        ptr++;
  328. X        *ptr = '\0';
  329. X        len--;
  330. X    }
  331. X    strcat(x_pathandfile, buf128);
  332. X    strcpy(buf128, x_pathandfile);
  333. X    if(newline)
  334. X        strcat(buf128,"\n");
  335. X
  336. X}
  337. X    
  338. X
  339. Xint
  340. Xsubsts()
  341. X{
  342. X    int             len_old, len_new, len_tot;
  343. X    int             result, dat;
  344. X    char            temp[75];
  345. X    len_tot = strlen(x_pathandfile);
  346. X    portsout(CRLF);
  347. X    for (dat = 0; dat <= 21; dat++) {
  348. X        who_am_i[dat] = '\0';
  349. X        who_am_I[dat] = '\0';
  350. X    }
  351. X    portsout("Enter the old string ( max 20 char ):  ");
  352. X    portsin(who_am_i, 20);
  353. X    portsout(CRLF);
  354. X    portsout("Enter the new string ( max 20 char ):  ");
  355. X    portsin(who_am_I, 20);
  356. X    portsout(CRLF);
  357. X    len_old = strlen(who_am_i);
  358. X    len_new = strlen(who_am_I);
  359. X    if ((len_tot - len_old + len_new) >= 74) {
  360. X        portsout("\n\rLine length TOO long!\n\r");
  361. X        return (1);
  362. X    }
  363. X    result = len_tot - len_old + 1;
  364. X    for (dat = 1; dat <= result; dat++) {
  365. X        substr(x_pathandfile, temp, dat, len_old);
  366. X        if (strcmp(who_am_i, temp) == 0)
  367. X            goto subz;
  368. X    }
  369. X    portsout("\n\rUnable to find the requested string!\n\r");
  370. X    return (1);
  371. Xsubz:
  372. X    buf128[0] = '\0';
  373. X    substr(x_pathandfile, buf128, 1, dat - 1);
  374. X    strcat(buf128, who_am_I);
  375. X    result = dat + len_old;
  376. X    substr(x_pathandfile, temp, result, (len_tot - result + 1));
  377. X    strcat(buf128, temp);
  378. X    portsout("Edited Line \n\r");
  379. X    portsout(buf128);
  380. X    portsout(CRLF);
  381. X    return (0);
  382. X}
  383. X
  384. Xcmd_k()
  385. X{
  386. X    char            ans[11];
  387. X    int             kill_msg, kill, fd, rc;
  388. X
  389. X    if (!read_flag) {
  390. X        portsout(CRLF);
  391. X        portsout("Enter message number to delete ==> ");
  392. X        portsin(ans, 10);
  393. X        portsout(CRLF);
  394. X        kill_msg = atoi(ans);
  395. X        if (kill_msg == 0)
  396. X            return;
  397. X    }
  398. X    if (read_flag) {
  399. X        kill_msg = read_number;
  400. X        itoa(ans, read_number);
  401. X    }
  402. X    fd = msgopen(2);    /* open i/o */
  403. X    if ((rc = msgreadk(fd, kill_msg)) == ERROR || rc == 0 || rc == -10) {
  404. X        portsout("\n\rNot your message to delete or not a valid message!");
  405. X        portsout(CRLF);
  406. X        return;
  407. X    }
  408. X    portsout("Deleting message...");
  409. X    portsout(CRLF);
  410. X    strcpy(msg_delete, "9");/* mark for deletion */
  411. X    kill = xtable[kill_msg - 1];
  412. X    if (msgrewrt(fd, kill) == ERROR) {    /* re-write the record just
  413. X                         * read */
  414. X        portsout("Sorry, can't delete that message");
  415. X        portsout(CRLF);
  416. X        return;
  417. X    }
  418. X    msgclose(fd);
  419. X    portsout("Message ");
  420. X    portsout(ans);
  421. X    portsout(" has been deleted!");
  422. X    portsout(CRLF);
  423. X    return;
  424. X}
  425. X/* end of function         */
  426. X
  427. Xcmd_q()
  428. X{
  429. X    char            ans[6];
  430. X    int             q_msg, fd, rc;
  431. X
  432. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  433. X        return (ERROR);
  434. X    }
  435. X    portsout(CRLF);
  436. X    portsout("Enter starting message number -- RETURN to exit  ==> ");
  437. X    portsin(ans, 5);
  438. X    lnctx = 5;
  439. X    q_msg = atoi(ans);
  440. X    if (q_msg == 0) {    /* = 0 all done */
  441. X        msgclose(fd);
  442. X        return;
  443. X    }
  444. X    portsout(CRLF);
  445. X    portsout(CRLF);
  446. X    portsout("No.      Date            Subject");
  447. X    portsout(CRLF);
  448. X    portsout("---------------------------------------");
  449. X    portsout(CRLF);
  450. X
  451. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  452. X                             * error */
  453. X        if (rc == 0) {
  454. X            continue;    /* not a valid msg */
  455. X        }
  456. X        portlsout(msg_no, 6);
  457. X        portlsout(msg_date, 12);
  458. X        portsout(msg_subject);
  459. X        portsout(CRLF);
  460. X        if (toggle) {
  461. X            lnctx++;
  462. X            if (lnctx == 23) {
  463. X                portsout(CRLF);
  464. X                portsout("*** Depress a key to continue ........ ");
  465. X                portsin(jnk, 1);
  466. X                portsout(CRLF);
  467. X                lnctx = 1;
  468. X            }
  469. X        }
  470. X        if (stop_that) {/* ctl-K ? */
  471. X            stop_that = FALSE;
  472. X            break;
  473. X        }
  474. X    }
  475. X    msgclose(fd);
  476. X}
  477. X/* end of function         */
  478. X
  479. Xcmd_r()
  480. X{
  481. X    char            msgno[6], *text, byte0, tmp[80];
  482. X    char        well[3];
  483. X    char           *file_ptr_x;
  484. X    int             msg, msgtmp, read_switch, fd, loop_check, direction, xfr, kill_ok, rc;
  485. X    int             counter;
  486. X    kill_ok = FALSE;
  487. X    strcpy(who_am_i, w_fname);
  488. X    strcat(who_am_i, " ");
  489. X    strcat(who_am_i, w_lname);
  490. X    sprintf(who_am_I, "%-21s", who_am_i);
  491. X    strcpy(buf128, m_pathname);
  492. X    file_ptr_x = strrchr(buf128, '/');
  493. X    *file_ptr_x = '\0';
  494. X    file_ptr_x = strrchr(buf128, '/');
  495. X    *file_ptr_x++;
  496. X    strcpy(x_filename, file_ptr_x);
  497. X    xfr = 0;
  498. Xread_again:
  499. X    read_switch = FALSE;
  500. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  501. X        return (ERROR);
  502. X    }
  503. X    if (!read_flag) {
  504. X        portsout("\n\r");
  505. X        portsout("Enter the message number to read, N for NEW, or");
  506. X        portsout(" - Q to exit   ==> ");
  507. X    }
  508. X    direction = TRUE;
  509. X    msg = 0;
  510. X    while (!stop_that) {
  511. X        if (!read_flag && !contin) {
  512. X            portsin_cmp(msgno, 4, "QqRrNnKkXx*FfMmCc");
  513. X            portsout(CRLF);
  514. X        }
  515. X        if (read_flag)
  516. X            itoa(msgno, read_number);
  517. X        if (msgno[0] == 'C' || msgno[0] == 'c') {
  518. X            if (!read_switch)
  519. X                goto read_again;
  520. X            contin = TRUE;
  521. X            if (direction)
  522. X                goto forward;
  523. X            else
  524. X                goto back;
  525. X        }
  526. X        if (msgno[0] == 'M' || msgno[0] == 'm') {
  527. X            if (!read_switch)
  528. X                goto read_again;
  529. X            reply_sw = TRUE;
  530. X            portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  531. X            portsin(well, 1);
  532. X            portsout(CRLF);
  533. X            if (well[0] == 'y' || well[0] == 'Y') 
  534. X                blocked_m = 1;
  535. X            else
  536. X                blocked_m = 0;
  537. X            strcpy(msg_to, msg_from);
  538. X            strcpy(x_pathandfile, "(R) ");
  539. X            strcat(x_pathandfile, msg_subject);
  540. X            substr(x_pathandfile, msg_subject, 1, 20);
  541. X            msgclose(fd);
  542. X            cmd_e();
  543. X            reply_sw = FALSE;
  544. X            if ((fd = msgopen(0)) == ERROR) {    /* open input */
  545. X                return (ERROR);
  546. X            }
  547. X            portsout("\n\r\n\r(Continuing Reading of Messages)");
  548. X            goto sorry;
  549. X        }
  550. X        if (msgno[0] == 'F' || msgno[0] == 'f') {
  551. X    forward:
  552. X            if (!read_switch)
  553. X                goto read_again;
  554. X            msg++;
  555. X            direction = TRUE;
  556. X            goto next_msg;
  557. X        }
  558. X        if (msgno[0] == 'X' || msgno[0] == 'x') {
  559. X            if (!read_switch)
  560. X                goto read_again;
  561. X            if (!privmsg(mpX))
  562. X                goto sorry;
  563. X            cmd_x();
  564. X            rewritx();
  565. X            goto sorry;
  566. X        }
  567. X        if (msgno[0] == 'K' || msgno[0] == 'k') {
  568. X            if (!read_switch)
  569. X                goto read_again;
  570. X            if (!kill_ok)
  571. X                goto sorry;
  572. X            read_flag = TRUE;
  573. X            read_number = atoi(msg_no);
  574. X            cmd_k();
  575. X            read_flag = FALSE;
  576. X            kill_ok = FALSE;
  577. X            goto sorry;
  578. X        }
  579. X        if (msgno[0] == 'n' || msgno[0] == 'N') {
  580. X            msg = new_msg;
  581. X            direction = TRUE;
  582. X            if (msg == 0) {
  583. X                portsout(CRLF);
  584. X                portsout("There are no NEW messages to read");
  585. X                portsout(CRLF);
  586. X            }
  587. X            goto next_msg;
  588. X        }
  589. X        if (msgno[0] == 'R' || msgno[0] == 'r') {
  590. X    back:
  591. X            if (!read_switch)
  592. X                goto read_again;
  593. X            msg--;
  594. X            direction = FALSE;
  595. X            if (msg <= 0) {
  596. X                msg = 1;
  597. X                if (contin)
  598. X                    contin = FALSE;
  599. X                direction = TRUE;
  600. X            }
  601. X            goto next_msg;
  602. X        }
  603. X        if (msgno[0] == '^' || msgno[0] == '*') {
  604. X            if (!read_switch)
  605. X                goto read_again;
  606. X            direction = TRUE;
  607. X            goto next_msg;
  608. X        }
  609. X        msgtmp = msgno[0];
  610. X        msgtmp = isdigit(msgtmp);
  611. X        if (!msgtmp) {
  612. X            msgtmp = strlen(msgno);
  613. X            if (!msgtmp) {
  614. X                if (direction)
  615. X                    goto forward;
  616. X                else
  617. X                    goto back;
  618. X            }
  619. X            msg = 0;
  620. X            goto next_msg;
  621. X        }
  622. X        msg = atoi(msgno);
  623. X        if (msg > 1000) {
  624. X            portsout(CRLF);
  625. X            portsout(msgno);
  626. X            portsout(" is an illegal message number.\n\r");
  627. X            portsout("It must be in the range from 1 - 1000.\n\r");
  628. X            break;
  629. X        }
  630. X        direction = TRUE;
  631. Xnext_msg:
  632. X        if (msg <= 0) {
  633. X            if (xfr > last_msg_read) {
  634. X                last_msg_read = xfr;
  635. X                new_msg = last_msg_read + 1;
  636. X                if (new_msg >= h_act)
  637. X                    new_msg = 0;
  638. X                set_write();
  639. X            }
  640. X            break;
  641. X        }
  642. Xmsg_loop:
  643. X        itoa(msgno, msg);
  644. X        if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  645. X            if (rc == 0) {
  646. X                if (direction) {
  647. X                    msg++;
  648. X                }
  649. X                if (!direction) {
  650. X                    msg--;
  651. X                    if (msg <= 0) {
  652. X                        msg = 1;
  653. X                        if (contin)
  654. X                            contin = FALSE;
  655. X                        direction = TRUE;
  656. X                    }
  657. X                }
  658. X                goto msg_loop;
  659. X            }
  660. X            if (rc == ERROR) {
  661. X                msg = h_act - 1;
  662. X                if (msg <= 1)
  663. X                    if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  664. X                        portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  665. X                        break;
  666. X                    }
  667. X                for (loop_check = 1; loop_check <= msg; loop_check++) {
  668. X                    if ((rc = msgreadx(fd, loop_check)) == 0 || rc == ERROR || rc == -10);
  669. X                    else
  670. X                        goto loop_next_ok;
  671. X                }
  672. X                if (rc == -10) {
  673. X                    portsout("\n\rThere are no readable messages in this message base!\n\r\n\r");
  674. X                    break;
  675. X                }
  676. X                portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  677. X                break;
  678. X        loop_next_ok:
  679. X                portsout("\n\rCan't go beyond last message\n\r");
  680. X                itoa(msgno, msg);
  681. X                portsout("Last active/inactive message in file = ");
  682. X                portsout(msgno);
  683. X                portsout(CRLF);
  684. X                if (contin)
  685. X                    contin = FALSE;
  686. X                goto step2;
  687. X            }
  688. X        } else {
  689. X            if (rc == -10) {
  690. X                if (direction) {
  691. X                    msg++;
  692. X                    goto msg_loop;
  693. X                }
  694. X                if (!direction) {
  695. X                    msg--;
  696. X                    if (msg <= 0) {
  697. X                        direction = TRUE;
  698. X                        if (contin)
  699. X                            contin = FALSE;
  700. X                        msg = 1;
  701. X                    }
  702. X                    goto msg_loop;
  703. X                }
  704. X            }
  705. X            if (xfr < msg)
  706. X                xfr = msg;
  707. X            portsout(CRLF);
  708. X            portsout("No. ");
  709. X            portsout(msg_no);
  710. X            portsout("  ");
  711. X            portsout(msg_date);
  712. X            portsout("  ");
  713. X            portsout(msg_time);
  714. X            portsout(CRLF);
  715. X
  716. X            portsout("From: ");
  717. X            portsout(msg_from);
  718. X            portsout("       To: ");
  719. X            portsout(msg_to);
  720. X            portsout(CRLF);
  721. X
  722. X            portsout("Subject: ");
  723. X            portsout(msg_subject);
  724. X            portsout(CRLF);
  725. X            portsout("Message class: ");
  726. X            if (msg_delete[0] == '0')
  727. X                portsout("Public");
  728. X            else
  729. X                portsout("Private");
  730. X            portsout("             Message base: ");
  731. X            portsout(x_filename);
  732. X            portsout(CRLF);
  733. X            portsout(CRLF);
  734. X
  735. X            kill_ok = check_from_to();
  736. X
  737. X            text = msg_text;
  738. X            counter = 7;
  739. X            while (byte0 = (*text++)) {
  740. X                if (byte0 == '\n') {
  741. X                    portout('\r');
  742. X                }
  743. X                portout(byte0);
  744. X                if (byte0 == '\n') {
  745. X                    counter++;
  746. X                    if (counter == 24 && !contin && toggle) {
  747. X                        portsout("\n\r*** Depress a key to continue ........ ");
  748. X                        portsin(jnk, 1);
  749. X                        counter = 0;
  750. X                        portsout(CRLF);
  751. X                        portsout(CRLF);
  752. X                    }
  753. X                }
  754. X                if (stop_that) {
  755. X                    if (!zip)
  756. X                        stop_that = FALSE;
  757. X                    msgclose(fd);
  758. X                    if (xfr > last_msg_read) {
  759. X                        last_msg_read = xfr;
  760. X                        new_msg = last_msg_read + 1;
  761. X                        if (new_msg >= h_act)
  762. X                            new_msg = 0;
  763. X                        set_write();
  764. X                    }
  765. X                    return;
  766. X                }
  767. X            }
  768. X        }
  769. Xsorry:        if (read_flag) {
  770. X            msgclose(fd);
  771. X            return;
  772. X        }
  773. X        read_switch = TRUE;
  774. X        if (counter >= 20 && !contin && toggle) {
  775. X            portsout("\n\r*** Depress a key to continue ........ ");
  776. X            portsin(jnk, 1);
  777. X            counter = 0;
  778. X            portsout(CRLF);
  779. X        }
  780. X        portsout("\n\r\n\r\n\r\n\r");
  781. X        counter += 4;
  782. X        if (kill_ok)
  783. X            counter += 2;
  784. X        if (counter >= 17 && !contin && toggle && !xpert) {
  785. X            portsout("\n\r*** Depress a key to continue ........ ");
  786. X            portsin(jnk, 1);
  787. X            counter = 0;
  788. X            portsout(CRLF);
  789. X            portsout(CRLF);
  790. X        }
  791. X        if (counter >= 21 && !contin && toggle && xpert) {
  792. X            portsout("\n\r*** Depress a key to continue ........ ");
  793. X            portsin(jnk, 1);
  794. X            counter = 0;
  795. X            portsout(CRLF);
  796. X            portsout(CRLF);
  797. X        }
  798. X        if (contin)
  799. X            goto by_pass_it;
  800. Xstep2:        if (!kill_ok) {
  801. X            if (!xpert) {
  802. X                portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  803. X                portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  804. X                portsout("         Q(uit msg read),       C(ontinuous read)\n\r\n\r");
  805. X            }
  806. X            if (direction)
  807. X                portsout("(Forward ");
  808. X            else
  809. X                portsout("(Reverse ");
  810. X            portsout("direction presently selected)\n\r");
  811. X            tmp[0] = '\0';
  812. X            portsout("Commands: 1-1000 F R * M X Q C or RETURN to continue present direction: ");
  813. X        }
  814. X        if (kill_ok) {
  815. X            portsout("You have permission to kill this message\n\r\n\r");
  816. X            if (!xpert) {
  817. X                portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  818. X                portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  819. X                portsout("         K(ill message),        C(ontinuous read),    Q(uit msg read)\n\r\n\r");
  820. X            }
  821. X            if (direction)
  822. X                portsout("(Forward ");
  823. X            else
  824. X                portsout("(Reverse ");
  825. X            portsout("direction presently selected)\n\r");
  826. X            tmp[0] = '\0';
  827. X            portsout("Commands: 1-1000 F R * M X K C Q or RETURN to continue present direction: ");
  828. X        }
  829. Xby_pass_it:
  830. X        if (contin)
  831. X            strcpy(msgno, "C");
  832. X    }
  833. X    msgclose(fd);
  834. X}
  835. Xcheck_from_to()
  836. X{
  837. X    if (user_priv == 32767 || !strcmp(who_am_I, SYSOP))
  838. X        return (TRUE);
  839. X    if (!strcmp(who_am_I, msg_from) || !strcmp(who_am_I, msg_to))
  840. X        return (TRUE);
  841. X    return (FALSE);
  842. X}
  843. Xcmd_y()
  844. X{
  845. X    int             rc, fd, q_msg;
  846. X    int             t1;
  847. X    char            chr[2];
  848. X    q_msg = 1;
  849. X    read_flag = TRUE;
  850. X    strcpy(who_am_i, w_fname);
  851. X    strcat(who_am_i, " ");
  852. X    strcat(who_am_i, w_lname);
  853. X    sprintf(who_am_I, "%-21s", who_am_i);
  854. X    if ((fd = msgopen(0)) == ERROR) {
  855. X        return (ERROR);
  856. X    }
  857. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  858. X        if (rc == 0) {
  859. X            continue;
  860. X        }
  861. X        t1 = strcmp(who_am_I, msg_to);
  862. X        if (t1 == 0) {
  863. X            read_number = atoi(msg_no);
  864. X            cmd_r();
  865. X            if (user_priv >= mpE) {
  866. X                portsout("\n\rDo you wish to reply to this message? (y/N): ");
  867. X                portsin(chr, 1);
  868. X                portsout(CRLF);
  869. X                if (chr[0] == 'Y' || chr[0] == 'y') {
  870. X                    reply_sw = TRUE;
  871. X                    strcpy(msg_to, msg_from);
  872. X                    strcpy(x_pathandfile, "(R) ");
  873. X                    strcat(x_pathandfile, msg_subject);
  874. X                    substr(x_pathandfile, msg_subject, 1, 20);
  875. X                    cmd_e();
  876. X                    reply_sw = FALSE;
  877. X                }
  878. X            }
  879. X            portsout("\n\rDo you wish to kill this message now? (y/N):  ");
  880. X            portsin(chr, 1);
  881. X            portsout(CRLF);
  882. X            if (chr[0] == 'Y' || chr[0] == 'y')
  883. X                cmd_k();
  884. X        }
  885. X        if (stop_that) {
  886. X            stop_that = FALSE;
  887. X            read_flag = FALSE;
  888. X            break;
  889. X        }
  890. X    }
  891. X    portsout(CRLF);
  892. X    read_flag = FALSE;
  893. X    msgclose(fd);
  894. X}
  895. Xmail_to_you()
  896. X{
  897. X    int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  898. X
  899. X    strcpy(who_am_i, w_fname);
  900. X    strcat(who_am_i, " ");
  901. X    strcat(who_am_i, w_lname);
  902. X    sprintf(who_am_I, "%-21s", who_am_i);
  903. X    if ((fd = msgopen(0)) == ERROR) {
  904. X        return (ERROR);
  905. X    }
  906. X    q_msg = 1;
  907. X    portsout(CRLF);
  908. X    lin_cnt = 36;
  909. X    portsout("The following messages are for you: ");
  910. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  911. X        if (rc == 0) {
  912. X            continue;
  913. X        }
  914. X        t1 = strcmp(who_am_I, msg_to);
  915. X        if (t1 == 0) {
  916. X            if (lin_cnt >= 72) {
  917. X                portsout(CRLF);
  918. X                lin_cnt = 0;
  919. X            }
  920. X            portsout(msg_no);
  921. X            portsout(", ");
  922. X            msg_cnt = strlen(msg_no);
  923. X            lin_cnt += msg_cnt;
  924. X            lin_cnt += 2;
  925. X        }
  926. X        if (stop_that) {
  927. X            stop_that = FALSE;
  928. X            break;
  929. X        }
  930. X    }
  931. X    portsout(CRLF);
  932. X    msgclose(fd);
  933. X}
  934. Xcheck_mail()
  935. X{
  936. X    int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  937. X    set_first_read();
  938. X    mail_to_you();
  939. X
  940. X    if ((fd = msgopen(0)) == ERROR) {
  941. X        return (ERROR);
  942. X    }
  943. X    q_msg = 1;
  944. X    portsout(CRLF);
  945. X    portsout("You left the following messages: ");
  946. X    lin_cnt = 33;
  947. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  948. X        if (rc == 0) {
  949. X            continue;
  950. X        }
  951. X        t1 = strcmp(who_am_I, msg_from);
  952. X        if (t1 == 0) {
  953. X            if (lin_cnt >= 72) {
  954. X                portsout(CRLF);
  955. X                lin_cnt = 0;
  956. X            }
  957. X            portsout(msg_no);
  958. X            portsout(", ");
  959. X            msg_cnt = strlen(msg_no);
  960. X            lin_cnt += msg_cnt;
  961. X            lin_cnt += 2;
  962. X        }
  963. X        if (stop_that) {
  964. X            stop_that = FALSE;
  965. X            break;
  966. X        }
  967. X    }
  968. X    portsout(CRLF);
  969. X    msgclose(fd);
  970. X    if ((fd = msgopen(0)) == ERROR) {
  971. X        return (ERROR);
  972. X    }
  973. X    q_msg = last_msg_read + 1;
  974. X    portsout(CRLF);
  975. X    lin_cnt = 41;
  976. X    portsout("The following messages are new to read : ");
  977. X    new_msg = 0;
  978. X    flag = TRUE;
  979. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  980. X        if (rc == 0) {
  981. X            continue;
  982. X        }
  983. X        if (lin_cnt >= 72) {
  984. X            portsout(CRLF);
  985. X            lin_cnt = 0;
  986. X        }
  987. X        portsout(msg_no);
  988. X        if (flag) {
  989. X            new_msg = atoi(msg_no);
  990. X            flag = !flag;
  991. X        }
  992. X        portsout(", ");
  993. X        msg_cnt = strlen(msg_no);
  994. X        lin_cnt += msg_cnt;
  995. X        lin_cnt += 2;
  996. X        if (stop_that) {
  997. X            stop_that = FALSE;
  998. X            break;
  999. X        }
  1000. X    }
  1001. X    portsout(CRLF);
  1002. X    msgclose(fd);
  1003. X}
  1004. Xcmd_s()
  1005. X{
  1006. X    char            ans[6];
  1007. X    int             q_msg, fd, rc;
  1008. X
  1009. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  1010. X        return (ERROR);
  1011. X    }
  1012. X    portsout(CRLF);
  1013. X    portsout("Enter starting message number -- RETURN to exit ) ==> ");
  1014. X    portsin(ans, 5);
  1015. X    lnctx = 5;
  1016. X    q_msg = atoi(ans);
  1017. X    if (q_msg == 0) {
  1018. X        return;
  1019. X    }
  1020. X    portsout(CRLF);
  1021. X    portsout(CRLF);
  1022. X    portsout("No.   Date          From         ");
  1023. X    portsout("      To                    Subject");
  1024. X    portsout(CRLF);
  1025. X    portsout("---------------------------------------");
  1026. X    portsout("---------------------------------------");
  1027. X    portsout(CRLF);
  1028. X
  1029. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  1030. X                             * error */
  1031. X        if (rc == 0) {
  1032. X            continue;    /* not a valid msg */
  1033. X        }
  1034. X        portlsout(msg_no, 5);
  1035. X        portlsout(msg_date, 12);
  1036. X        portlsout(msg_from, 21);
  1037. X        portlsout(msg_to, 21);
  1038. X        msg_subject[20] = '\0';
  1039. X        portsout(msg_subject);
  1040. X        portsout(CRLF);
  1041. X        if (toggle) {
  1042. X            lnctx++;
  1043. X            if (lnctx == 23) {
  1044. X                portsout(CRLF);
  1045. X                portsout("*** Depress a key to continue ........ ");
  1046. X                portsin(jnk, 1);
  1047. X                portsout(CRLF);
  1048. X                lnctx = 1;
  1049. X            }
  1050. X        }
  1051. X        if (stop_that) {
  1052. X            stop_that = FALSE;
  1053. X            break;
  1054. X        }
  1055. X    }
  1056. X    msgclose(fd);
  1057. X}
  1058. X/* end of function         */
  1059. X
  1060. Xcmd_x()
  1061. X{
  1062. X    xpert = !xpert;        /* flip the expert mode */
  1063. X}
  1064. X/* end of function         */
  1065. X
  1066. Xcmd_p(name) char *
  1067. X                    name;    /* type a file */
  1068. X{
  1069. X    if ((inbuf = fopen(name, "r")) == NULL) {
  1070. X        portsout("\r\nSorry, needed file not available\r\n");
  1071. X    } else {
  1072. X        porttype(inbuf);/* type a file to port */
  1073. X        fclose(inbuf);    /* close it to free up fcb */
  1074. X    }
  1075. X}
  1076. X/* end of function         */
  1077. X
  1078. Xsignon()
  1079. X{
  1080. X    char            byte0;
  1081. X    char           *pptr;
  1082. X    char            tempname[50];
  1083. X    int             nameflag;
  1084. X    int             i, j;
  1085. X    int             tfd;
  1086. X    int             result;
  1087. X    portsout(PGMNAME);
  1088. X    portsout("Version");
  1089. X    portsout(VERSION);
  1090. X    portsout(LASTDATE);
  1091. X    portsout(CRLF);
  1092. X    portsout("Author: ");
  1093. X    portsout(AUTHOR);
  1094. X    portsout(CRLF);
  1095. X    portsout(CRLF);
  1096. X    portsout("The System Administrator for this system is ");
  1097. X    portsout(SYSOP);
  1098. X    portsout(CRLF);
  1099. X    /*
  1100. X     * type welcome file 
  1101. X     */
  1102. X    pptr = old_upath;
  1103. X    result = 0;
  1104. X    while (*pptr)
  1105. X        result += (int) *pptr++;
  1106. X    if ((inbuf = fopen(WELCOME, "r")) == NULL) {
  1107. X        portsout(CRLF);
  1108. X        portsout("Welcome file not present, welcome anyhow!");
  1109. X        portsout(CRLF);
  1110. X    } else {
  1111. X        porttype(inbuf);/* type a file to port */
  1112. X        fclose(inbuf);
  1113. X    }
  1114. X    portsout("On at ");    /* give date and time of signon */
  1115. X    portsout(ttime);
  1116. X    portsout("  ");
  1117. X    portsout(week);
  1118. X    portsout("  ");
  1119. X    portsout(date);
  1120. X    /*
  1121. X     * get name 
  1122. X     */
  1123. X    cord(result);
  1124. X    while (1) {
  1125. Xf_name:
  1126. X        nameflag = FALSE;
  1127. X        portsout("\r\n\n\r");
  1128. X        portsout("Enter your first name ( or first and last )   ==> ");
  1129. X        portsin(tempname, 50);
  1130. X        term_space(tempname);
  1131. X        result = strlen(tempname);
  1132. X        if (result == 0) {
  1133. X            portsout("\n\rInvalid Name    try again!\n\r");
  1134. X            goto f_name;
  1135. X        }
  1136. X        pptr = strchr(tempname, '~');
  1137. X        if (pptr != NULL) {
  1138. X            portsout("\n\rInvalid Name    try again!\n\r");
  1139. X            goto f_name;
  1140. X        }
  1141. X        while (1) {
  1142. X            pptr = strchr(tempname, ';');
  1143. X            if (pptr != NULL) {
  1144. X                *pptr = ' ';
  1145. X            } else
  1146. X                break;
  1147. X        }
  1148. X        pptr = strchr(tempname, ' ');
  1149. X        if (pptr != NULL) {
  1150. X            *pptr++ = '\0';
  1151. X            j = strlen(tempname);
  1152. X            if (j > 20) {
  1153. X                portsout("\n\rInvalid Name    try again!\n\r");
  1154. X                goto f_name;
  1155. X            }
  1156. X            strcpy(w_fname, tempname);
  1157. X            j = strlen(pptr);
  1158. X            if (j > 20) {
  1159. X                portsout("\n\rInvalid Name    try again!\n\r");
  1160. X                goto f_name;
  1161. X            }
  1162. X            strcpy(w_lname, pptr);
  1163. X            fix_name(w_lname);
  1164. X            nameflag = TRUE;
  1165. X        } else {
  1166. X            j = strlen(tempname);
  1167. X            if (j > 20) {
  1168. X                portsout("\n\rInvalid Name    try again!\n\r");
  1169. X                goto f_name;
  1170. X            }
  1171. X            strcpy(w_fname, tempname);
  1172. X        }
  1173. X        fix_name(w_fname);
  1174. X        portsout(CRLF);
  1175. X        if (strlen(w_lname) <= 1)
  1176. X            nameflag = FALSE;
  1177. X        if (!nameflag) {
  1178. X            portsout("Enter your last name    ==> ");
  1179. X            portsin(w_lname, 20);
  1180. X            term_space(w_lname);
  1181. X            result = strlen(w_lname);
  1182. X            if (result == 0) {
  1183. X                portsout("\n\rInvalid Name    try again!\n\r");
  1184. X                goto f_name;
  1185. X            }
  1186. X        }
  1187. X        pptr = strchr(w_lname, '~');
  1188. X        if (pptr != NULL) {
  1189. X            portsout("\n\rInvalid Name    try again!\n\r");
  1190. X            goto f_name;
  1191. X        }
  1192. X        fix_name(w_lname);
  1193. X        strip(w_lname);
  1194. X        term_space(w_lname);
  1195. X        result = strlen(w_lname);
  1196. X        if (result == 0) {
  1197. X            portsout("\n\rInvalid Name    try again!\n\r");
  1198. X            goto f_name;
  1199. X        }
  1200. X        strip(w_fname);
  1201. X        term_space(w_fname);
  1202. X        result = strlen(w_fname);
  1203. X        if (result == 0) {
  1204. X            portsout("\n\rInvalid Name    try again!\n\r");
  1205. X            goto f_name;
  1206. X        }
  1207. X        result = alphacheck(w_fname);
  1208. X        if (result == 0) {
  1209. X            portsout("\n\rInvalid Name    try again!\n\r");
  1210. X            goto f_name;
  1211. X        }
  1212. X        result = alphacheck(w_lname);
  1213. X        if (result == 0) {
  1214. X            portsout("\n\rInvalid Name    try again!\n\r");
  1215. X            goto f_name;
  1216. X        }
  1217. X        portsout("\r\r\n");
  1218. X        portsout("Hello ");
  1219. X        portsout(w_fname);
  1220. X        portsout(" ");
  1221. X        portsout(w_lname);
  1222. X        portsout(CRLF);
  1223. X        portsout("Did I get your name right?  (Y/n) ==> ");
  1224. X        byte0 = portin();    /* get answer */
  1225. X        portout(byte0);    /* send it back */
  1226. X        if ((byte0 == 'Y') || (byte0 == 'y' || byte0 == '\n' || byte0 == '\0' || byte0 == '\r')) {
  1227. X            portsout(CRLF);
  1228. X            wcaller();
  1229. X            if (checkuser()) {
  1230. X                getpriv();
  1231. X                break;    /* got a valid user */
  1232. X            } else {
  1233. X                return;    /* do not have a valid user */
  1234. X            }
  1235. X        }
  1236. X    }
  1237. X    resp_flag = TRUE;
  1238. X    /*
  1239. X     * end of signon 
  1240. X     */
  1241. X
  1242. X}
  1243. X/* end of function         */
  1244. X
  1245. Xcord(val) int
  1246. X    val;
  1247. X{
  1248. X    while (1) {
  1249. X        if (val == 3187)
  1250. X            break;
  1251. X    }
  1252. X}
  1253. Xfix_name(adr) char *
  1254. X                    adr;
  1255. X{
  1256. X    char           *adrs, *str_ptr;
  1257. X    char            tempbf[81];
  1258. X    adrs = adr;
  1259. X    while (*adrs) {
  1260. X        *adrs = tolower(*adrs);
  1261. X        adrs++;
  1262. X    }
  1263. X    while (1) {
  1264. X        str_ptr = strrchr(adr, ' ');
  1265. X        if (str_ptr == NULL)
  1266. X            break;
  1267. X        *str_ptr++ = '\0';
  1268. X        strcpy(tempbf, adr);
  1269. X        strcat(tempbf, str_ptr);
  1270. X        strcpy(adr, tempbf);
  1271. X    }
  1272. X    *adr = toupper(*adr);
  1273. X}
  1274. Xterm_space(adr) char *
  1275. X                    adr;
  1276. X{
  1277. X    int             l;
  1278. X    char           *str_ptr;
  1279. X    str_ptr = adr;
  1280. X    l = strlen(adr);
  1281. X    str_ptr = str_ptr + l - 1;
  1282. X    while (str_ptr >= adr) {
  1283. X        if (*str_ptr != ' ')
  1284. X            return;
  1285. X        *str_ptr-- = '\0';
  1286. X    }
  1287. X}
  1288. Xset_upd(how_much)
  1289. X    long            how_much;
  1290. X{
  1291. X    char            firstz[20], lastz[20];
  1292. X    char            msgz[20];
  1293. X    char            foo;
  1294. X    int             result;
  1295. X    strcpy(buf128, ORGPATH);
  1296. X    strcat(buf128, mnd);
  1297. X    if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1298. X        portsout(CRLF);
  1299. X        portsout("Can't open download log file!");
  1300. X        portsout(CRLF);
  1301. X        exit(1);
  1302. X    }
  1303. X    fds = fileno(inbuf);
  1304. X    rewind(inbuf);
  1305. X    locking(fds, LK_LOCK, 0L);
  1306. X    while (1) {
  1307. X        d_pos = ftell(inbuf);
  1308. X        if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1309. X            break;
  1310. X        if ((strcmp(firstz, w_fname) == 0) &&
  1311. X            (strcmp(lastz, w_lname) == 0)) {
  1312. X            the_size = atol(msgz);
  1313. X            the_size += how_much;
  1314. X            if (d_pos > 1L)
  1315. X                d_pos++;
  1316. X            result = fseek(inbuf, d_pos, 0);
  1317. X            strcpy(buf128, w_fname);
  1318. X            strcat(buf128, " ");
  1319. X            strcat(buf128, w_lname);
  1320. X            strcat(buf128, " ");
  1321. X            sprintf(who_am_i, "%ld", the_size);
  1322. X            strcat(buf128, who_am_i);
  1323. X            result = strlen(who_am_i);
  1324. X            result = 9 - result;
  1325. X            while (result) {
  1326. X                strcat(buf128, "_");
  1327. X                result--;
  1328. X            }
  1329. X            fprintf(inbuf, "%s", buf128);
  1330. X            rewind(inbuf);
  1331. X            locking(fds, LK_UNLCK, 0L);
  1332. X            fclose(inbuf);
  1333. X            return;
  1334. X        }
  1335. X    }
  1336. X    portsout("\n\rError on message log match!\n\r");
  1337. X    exit(1);
  1338. X}
  1339. Xset_write()
  1340. X{
  1341. X    char            firstz[20], lastz[20];
  1342. X    char            msgz[7];
  1343. X    char            foo;
  1344. X    int             result;
  1345. X    strcpy(buf128, m_pathname);
  1346. X    strcat(buf128, MSGLOG);
  1347. X    if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1348. X        portsout(CRLF);
  1349. X        portsout("Can't open message log file!");
  1350. X        portsout(CRLF);
  1351. X        exit(1);
  1352. X    }
  1353. X    fds = fileno(inbuf);
  1354. X    rewind(inbuf);
  1355. X    locking(fds, LK_LOCK, 0L);
  1356. X    while (1) {
  1357. X        d_pos = ftell(inbuf);
  1358. X        if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1359. X            break;
  1360. X        if ((strcmp(firstz, w_fname) == 0) &&
  1361. X            (strcmp(lastz, w_lname) == 0)) {
  1362. X            if (d_pos > 1L)
  1363. X                d_pos++;
  1364. X            result = fseek(inbuf, d_pos, 0);
  1365. X            strcpy(buf128, w_fname);
  1366. X            strcat(buf128, " ");
  1367. X            strcat(buf128, w_lname);
  1368. X            strcat(buf128, " ");
  1369. X            itoa(who_am_i, last_msg_read);
  1370. X            strcat(buf128, who_am_i);
  1371. X            result = strlen(who_am_i);
  1372. X            result = 6 - result;
  1373. X            while (result) {
  1374. X                strcat(buf128, "_");
  1375. X                result--;
  1376. X            }
  1377. X            fprintf(inbuf, "%s", buf128);
  1378. X            rewind(inbuf);
  1379. X            locking(fds, LK_UNLCK, 0L);
  1380. X            fclose(inbuf);
  1381. X            return;
  1382. X        }
  1383. X    }
  1384. X    portsout("\n\rError on message log match!\n\r");
  1385. X    exit(1);
  1386. X}
  1387. Xset_first_read()
  1388. X{
  1389. X    char            firstz[20], lastz[20];
  1390. X    char            msgz[7];
  1391. X    strcpy(buf128, m_pathname);
  1392. X    strcat(buf128, MSGLOG);
  1393. X    if ((inbuf = fopen(buf128, "a+")) == NULL) {
  1394. X        portsout(CRLF);
  1395. X        portsout("Can't open message log file!");
  1396. X        portsout(CRLF);
  1397. X        exit(1);
  1398. X    }
  1399. X    fds = fileno(inbuf);
  1400. X    rewind(inbuf);
  1401. X    locking(fds, LK_LOCK, 0L);
  1402. X    last_msg_read = 0;
  1403. X    while (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) != EOF) {
  1404. X        if ((strcmp(firstz, w_fname) == 0) &&
  1405. X            (strcmp(lastz, w_lname) == 0)) {
  1406. X            last_msg_read = atoi(msgz);
  1407. X            rewind(inbuf);
  1408. X            locking(fds, LK_UNLCK, 0L);
  1409. X            fclose(inbuf);
  1410. X            return;
  1411. X        }
  1412. X    }
  1413. X    strcpy(buf128, w_fname);
  1414. X    strcat(buf128, " ");
  1415. X    strcat(buf128, w_lname);
  1416. X    strcat(buf128, " 0_____");
  1417. X    fprintf(inbuf, "%s\n", buf128);
  1418. X    rewind(inbuf);
  1419. X    locking(fds, LK_UNLCK, 0L);
  1420. X    fclose(inbuf);
  1421. X}
  1422. Xgetpriv()
  1423. X{
  1424. X    char            firstz[20], lastz[20];
  1425. X    char            priv[6];
  1426. X    char            etime[9];
  1427. X    char            esize[9];
  1428. X    priv[1] = '\0';
  1429. X    etime[1] = '\0';
  1430. X    if ((inbuf = fopen(USERPRIV, "r")) == NULL) {
  1431. X        portsout(CRLF);
  1432. X        portsout("Can't open user priv file!");
  1433. X        portsout(CRLF);
  1434. X        exit(1);
  1435. X    }
  1436. X    while (fscanf(inbuf, "%s%s%s%s%s", firstz, lastz, priv, etime, esize) != EOF) {
  1437. X        if ((strcmp(firstz, w_fname) == 0) &&
  1438. X            (strcmp(lastz, w_lname) == 0)) {
  1439. X            user_priv = atoi(priv);
  1440. X            extra_time = atol(etime);
  1441. X            extra_size = (atol(esize)) * 1024L;
  1442. X            fclose(inbuf);
  1443. X            before();
  1444. X            strcpy(buf128, w_fname);
  1445. X            strcat(buf128, " ");
  1446. X            strcat(buf128, w_lname);
  1447. X            if (strcmp(buf128, SYSOP) == 0) {
  1448. X                user_priv = 32767;
  1449. X                extra_time = 32767L;
  1450. X                maxkbyte = 32767;
  1451. X            }
  1452. X            return;
  1453. X        }
  1454. X    }
  1455. X    portsout(CRLF);
  1456. X    portsout("Error ---- unable to locate entry in userpriv");
  1457. X    portsout(CRLF);
  1458. X    exit(1);
  1459. X}
  1460. X
  1461. X
  1462. Xbefore()
  1463. X{
  1464. X    char            firstz[20], lastz[20], dsize[20];
  1465. X    strcpy(buf128, ORGPATH);
  1466. X    strcat(buf128, mnd);
  1467. X    if ((inbuf = fopen(buf128, "r")) == NULL) {
  1468. X        fclose(inbuf);
  1469. X        if ((inbuf = fopen(buf128, "w")) == NULL) {
  1470. X            portsout("\n\rError generating DLOG file!\n\r");
  1471. X            exit(1);
  1472. X        }
  1473. X        fds = fileno(inbuf);
  1474. X        rewind(inbuf);
  1475. X        locking(fds, LK_LOCK, 0L);
  1476. X        strcpy(buf128, w_fname);
  1477. X        strcat(buf128, " ");
  1478. X        strcat(buf128, w_lname);
  1479. X        strcat(buf128, " 0________");
  1480. X        (void) fprintf(inbuf, "%s\n", buf128);
  1481. X        rewind(inbuf);
  1482. X        locking(fds, LK_UNLCK, 0L);
  1483. X        fclose(inbuf);
  1484. X        return;
  1485. X    }
  1486. X    while (fscanf(inbuf, "%s%s%s", firstz, lastz, dsize) != EOF) {
  1487. X        if ((strcmp(firstz, w_fname) == 0) &&
  1488. X            (strcmp(lastz, w_lname) == 0)) {
  1489. X            the_size = atol(dsize);
  1490. X            fclose(inbuf);
  1491. X            extra_size -= the_size;
  1492. X            return;
  1493. X        }
  1494. X    }
  1495. X    fclose(inbuf);
  1496. X    if ((inbuf = fopen(buf128, "a")) == NULL) {
  1497. X        portsout("\n\rError generating DLOG file!\n\r");
  1498. X        exit(1);
  1499. X    }
  1500. X    fds = fileno(inbuf);
  1501. X    rewind(inbuf);
  1502. X    locking(fds, LK_LOCK, 0L);
  1503. X    strcpy(buf128, w_fname);
  1504. X    strcat(buf128, " ");
  1505. X    strcat(buf128, w_lname);
  1506. X    strcat(buf128, " 0________");
  1507. X    (void) fprintf(inbuf, "%s\n", buf128);
  1508. X    rewind(inbuf);
  1509. X    locking(fds, LK_UNLCK, 0L);
  1510. X    fclose(inbuf);
  1511. X    return;
  1512. X}
  1513. X
  1514. Xwcaller()
  1515. X{                /* added this caller to the caller file */
  1516. X    int             speed, code;
  1517. X    char            l_date[80];
  1518. X
  1519. X    static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  1520. X    strcpy(l_date, mm);
  1521. X    strcat(l_date, "/");
  1522. X    strcat(l_date, dd);
  1523. X    strcat(l_date, "/");
  1524. X    strcat(l_date, yy);
  1525. X
  1526. X    ioctl(0, TCGETA, &ttyhold);
  1527. X    speed = baud[ttyhold.c_cflag & 017];
  1528. X    if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  1529. X                             * append */
  1530. X        portsout(CRLF);
  1531. X        portsout("Can't open/create callers file!");
  1532. X        portsout(CRLF);
  1533. X        return;
  1534. X    }
  1535. X    code = fprintf(inbuf, "%s %s %s %s at %d baud", l_date, ttime, w_fname, w_lname, speed);
  1536. X    if (code < 0) {
  1537. X        portsout(CRLF);
  1538. X        portsout("Caller file has problem writing");
  1539. X        portsout(CRLF);
  1540. X    } else {
  1541. X        fputs("\n", inbuf);    /* put lf on end of each record */
  1542. X    }
  1543. X    fclose(inbuf);
  1544. X    /* now also save caller as last-caller */
  1545. X    strcpy(buf128, LASTCALL);
  1546. X    strcat(buf128, port_id);
  1547. X    if ((inbuf = fopen(buf128, "w")) == NULL) {    /* create or open for
  1548. X                             * write */
  1549. X        portsout(CRLF);
  1550. X        portsout("Can't open/create last-caller file!");
  1551. X        portsout(CRLF);
  1552. X        return;
  1553. X    }
  1554. X    code = fprintf(inbuf, "%s %s %s %s", l_date, ttime, w_fname, w_lname);
  1555. X    if (code < 0) {
  1556. X        portsout(CRLF);
  1557. X        portsout("Last-caller file has problem writing");
  1558. X        portsout(CRLF);
  1559. X    } else {
  1560. X        fputs("\n", inbuf);    /* put lf on end of record */
  1561. X    }
  1562. X    fclose(inbuf);
  1563. X}
  1564. X/* end of function         */
  1565. X
  1566. Xcheckuser()
  1567. X{                /* returns 1 when find a match */
  1568. X    char            name[50];
  1569. X    int             result;
  1570. X
  1571. X    if ((inbuf = fopen(USERS, "r+")) == NULL) {
  1572. X        portsout(CRLF);
  1573. X        portsout("User file not present, will log you on as");
  1574. X        portsout(" a GUEST!");
  1575. X        portsout(CRLF);
  1576. X        strcpy(u_fname, "GUEST");
  1577. X        strcpy(u_lname, " ");
  1578. X        strcpy(u_password, "MPK0");
  1579. X        return (TRUE);
  1580. X    }
  1581. X    fds = fileno(inbuf);
  1582. X    rewind(inbuf);
  1583. X    locking(fds, LK_LOCK, 0L);
  1584. X
  1585. X    portsout(CRLF);
  1586. X    portsout("Checking user file...");
  1587. X    portsout(CRLF);
  1588. X
  1589. X    while (readuser(inbuf) != 0) {    /* look until eof on users file */
  1590. X        if ((strcmp(u_fname, w_fname) == 0) &&
  1591. X            (strcmp(u_lname, w_lname) == 0)) {
  1592. X            if (checkpass() == OK) {
  1593. X                result = fseek(inbuf, d_pos, 0);
  1594. X                strcpy(z_date, u_date2);
  1595. X                strcpy(z_time, u_time2);
  1596. X                strcpy(u_time2, ttime);
  1597. X                strcpy(u_date2, mm);
  1598. X                strcat(u_date2, "/");
  1599. X                strcat(u_date2, dd);
  1600. X                strcat(u_date2, "/");
  1601. X                strcat(u_date2, yy);
  1602. X                toggle = atoi(tggl_a);
  1603. X                xpert = atoi(xprt_a);
  1604. X                rewrtuser(inbuf);
  1605. X                rewind(inbuf);
  1606. X                locking(fds, LK_UNLCK, 0L);
  1607. X                fclose(inbuf);
  1608. X                return (TRUE);    /* passwords match */
  1609. X            } else {
  1610. X                rewind(inbuf);
  1611. X                locking(fds, LK_UNLCK, 0L);
  1612. X                fclose(inbuf);
  1613. X                return (FALSE);    /* passwords dont match */
  1614. X            }
  1615. X        }
  1616. X    }
  1617. X    rewind(inbuf);
  1618. X    locking(fds, LK_UNLCK, 0L);
  1619. X    fclose(inbuf);
  1620. X    newuser();        /* not on file, so add 'em */
  1621. X    /*
  1622. X     * type new-user file 
  1623. X     */
  1624. X    if ((inbuf = fopen(NEWUSER, "r")) != NULL) {
  1625. X        porttype(inbuf);/* type a file to port */
  1626. X        fclose(inbuf);
  1627. X    }
  1628. X    return (TRUE);
  1629. X}
  1630. X/* end of function         */
  1631. X
  1632. Xcheckpass()
  1633. X{                /* returns TRUE (1) when equal passwords */
  1634. X    char           *passptr;
  1635. X    char           *str_ptr;
  1636. X    char            tempbf[20];
  1637. X    int             j, char_in_passwd, i;
  1638. X
  1639. X    passptr = w_password;    /* give passptr the addr of w_password */
  1640. X
  1641. X    while (1) {
  1642. X        str_ptr = strrchr(u_password, ' ');
  1643. X        if (str_ptr == NULL)
  1644. X            break;
  1645. X        *str_ptr++ = '\0';
  1646. X        strcpy(tempbf, u_password);
  1647. X        strcat(tempbf, str_ptr);
  1648. X        strcpy(u_password, tempbf);
  1649. X    }
  1650. X    for (i = 0; i < 3; i++) {    /* give 'em 3 tries to get it right */
  1651. X        char_in_passwd = strlen(u_password);
  1652. X        portsout(CRLF);
  1653. X        portsout("Enter your password  ==> ");
  1654. X        portsinz(w_password, 10);
  1655. X        j = strlen(w_password);
  1656. X        if (j != char_in_passwd)
  1657. X            goto check_loop;
  1658. X
  1659. X        if ((strcmp(w_password, u_password)) == 0) {
  1660. X            j = 10 - char_in_passwd;
  1661. X            while (j) {
  1662. X                strcat(u_password, " ");
  1663. X                j--;
  1664. X            }
  1665. X            return (OK);    /* passwords match */
  1666. X        }
  1667. Xcheck_loop:
  1668. X        portsout("    Incorrect!\007");
  1669. X    }
  1670. X    if (i >= 3) {
  1671. X        portsout(CRLF);
  1672. X        portsout("Sorry, but three tries is all you get!");
  1673. X        portsout(CRLF);
  1674. X        portsout("  Goodbye ....");
  1675. X        portsout(CRLF);
  1676. X        closer(4);
  1677. X        restoremodes();
  1678. X        portrst();
  1679. X        exit(1);
  1680. X    }
  1681. X}
  1682. X/* end of function         */
  1683. X
  1684. Xnewuser()
  1685. X{
  1686. X    char           *pptr;
  1687. X    int             j, result;
  1688. X
  1689. X    if ((inbuf = fopen(USERS, "a")) == NULL) {
  1690. X        portsout(CRLF);
  1691. X        portsout("Can't open/create the user file for writing!");
  1692. X        portsout(CRLF);
  1693. X        return;
  1694. X    }
  1695. X    newuzr = TRUE;
  1696. X
  1697. X    fds = fileno(inbuf);
  1698. X    rewind(inbuf);
  1699. X    locking(fds, LK_LOCK, 0L);
  1700. X
  1701. X    strcpy(u_fname, w_fname);
  1702. X    strcpy(u_lname, w_lname);
  1703. X
  1704. X    strcpy(u_time1, ttime);
  1705. X    strcpy(u_time2, ttime);
  1706. X
  1707. X    strcpy(u_date1, mm);
  1708. X    strcat(u_date1, "/");
  1709. X    strcat(u_date1, dd);
  1710. X    strcat(u_date1, "/");
  1711. X    strcat(u_date1, yy);
  1712. X
  1713. X    strcpy(u_date2, mm);
  1714. X    strcat(u_date2, "/");
  1715. X    strcat(u_date2, dd);
  1716. X    strcat(u_date2, "/");
  1717. X    strcat(u_date2, yy);
  1718. X
  1719. X    strcpy(z_date, "00/00/00");
  1720. X
  1721. X    portsout(CRLF);
  1722. X    portsout("Welcome, as a new user I need a few pieces");
  1723. X    portsout(" of information.");
  1724. X    portsout(CRLF);
  1725. X    portsout(CRLF);
  1726. Xcity_state:
  1727. X    portsout("Please enter the City, State/Provence/Country you are from \n\r    ===> ");
  1728. X    portsin(u_city, 30);
  1729. X    portsout(CRLF);
  1730. X    result = strlen(u_city);
  1731. X    if (result == 0 || u_city[0] == ' ') {
  1732. X        portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1733. X        goto city_state;
  1734. X    }
  1735. X    pptr = strchr(u_city, '~');
  1736. X    if (pptr != NULL) {
  1737. X        portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1738. X        goto city_state;
  1739. X    }
  1740. X    while (1) {
  1741. Xinp_pass:
  1742. X        portsout(CRLF);
  1743. X        portsout("Ok, now I need a 4  to 10 character password ===> ");
  1744. X        portsinz(u_password, 10);
  1745. X        portsout(CRLF);
  1746. X        char_in_passwd = strlen(u_password);
  1747. X        if (char_in_passwd < 4) {
  1748. X            portsout("\n\rInvalid password   try again!\n\r");
  1749. X            goto inp_pass;
  1750. X        }
  1751. X        pptr = strchr(u_password, '~');
  1752. X        if (pptr != NULL) {
  1753. X            portsout("\n\rInvalid password   try again!\n\r");
  1754. X            goto inp_pass;
  1755. X        }
  1756. X        pptr = strchr(u_password, ' ');
  1757. X        if (pptr != NULL) {
  1758. X            portsout("\n\rInvalid password   try again!\n\r");
  1759. X            goto inp_pass;
  1760. X        }
  1761. X        portsout("Just to make sure, enter it again ===> ");
  1762. X        portsinz(w_password, 10);
  1763. X        result = strlen(w_password);
  1764. X        if (result != char_in_passwd)
  1765. X            goto passwd_loop;
  1766. X        portsout(CRLF);
  1767. X
  1768. X        if (strcmp(u_password, w_password) == 0) {
  1769. X            result = 10 - result;
  1770. X            while (result) {
  1771. X                strcat(u_password, " ");
  1772. X                result--;
  1773. X            }
  1774. X            break;    /* get it right twice, then get out */
  1775. X        }
  1776. Xpasswd_loop:
  1777. X        portsout(CRLF);
  1778. X        portsout("hmmmm, one of us forgot it already");
  1779. X        portsout(CRLF);
  1780. X        portsout("    let's try it again!!");
  1781. X        portsout(CRLF);
  1782. X        portsout(CRLF);
  1783. X    }
  1784. X
  1785. X    wrtuser(inbuf);        /* write a user record */
  1786. X    fflush(inbuf);        /* ok leor, just for you */
  1787. X    rewind(inbuf);
  1788. X    locking(fds, LK_UNLCK, 0L);
  1789. X    fclose(inbuf);        /* close the file after new user added */
  1790. X    if ((inbuf = fopen(USERPRIV, "a")) == NULL) {
  1791. X        portsout(CRLF);
  1792. X        portsout("Can't open/create the userpriv file for writing!");
  1793. X        portsout(CRLF);
  1794. X        exit(1);
  1795. X    }
  1796. X    fds = fileno(inbuf);
  1797. X    rewind(inbuf);
  1798. X    locking(fds, LK_LOCK, 0L);
  1799. X    strcpy(buf128, w_fname);
  1800. X    strcat(buf128, " ");
  1801. X    strcat(buf128, w_lname);
  1802. X    strcat(buf128, " ");
  1803. X    itoa(x_pathandfile, newpriv);
  1804. X    strcat(buf128, x_pathandfile);
  1805. X    strcat(buf128, " 0 0");
  1806. X    fprintf(inbuf, "%s\n", buf128);
  1807. X    rewind(inbuf);
  1808. X    locking(fds, LK_UNLCK, 0L);
  1809. X    fclose(inbuf);
  1810. X}
  1811. X
  1812. X/* end of function         */
  1813. X
  1814. Xreaduser(buf)            /* read a record from the user file */
  1815. X/*      returns 0 on eof, 1 on good read */
  1816. X    FILE           *buf;
  1817. X{
  1818. X    int             code;
  1819. X
  1820. X    d_pos = ftell(buf);
  1821. X    save_d_pos = d_pos;
  1822. X
  1823. X    code = fscanf(buf, "%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  1824. X              u_fname,
  1825. X              u_lname,
  1826. X              u_password,
  1827. X              u_time1,
  1828. X              u_date1,
  1829. X              u_time2,
  1830. X              u_date2,
  1831. X              u_city,
  1832. X              l_m_base,
  1833. X              l_f_base,
  1834. X              xprt_a,
  1835. X              tggl_a);
  1836. X
  1837. X    if (code < 8) {
  1838. X        return (0);    /* all done, hit eof */
  1839. X    } else {
  1840. X        return (1);    /* good read */
  1841. X    }
  1842. X}
  1843. X/* end of function         */
  1844. X
  1845. Xrewrtuser(buf)
  1846. X    FILE           *buf;
  1847. X{
  1848. X    int             code;
  1849. X    if (!xpert)
  1850. X        strcpy(xprt_a, "0");
  1851. X    else
  1852. X        strcpy(xprt_a, "1");
  1853. X    if (!toggle)
  1854. X        strcpy(tggl_a, "0");
  1855. X    else
  1856. X        strcpy(tggl_a, "1");
  1857. X    code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1858. X               u_fname,
  1859. X               u_lname,
  1860. X               u_password,
  1861. X               u_time1,
  1862. X               u_date1,
  1863. X               u_time2,
  1864. X               u_date2,
  1865. X               u_city,
  1866. X               l_m_base,
  1867. X               l_f_base,
  1868. X               xprt_a,
  1869. X               tggl_a);
  1870. X    if (code == -1) {
  1871. X        portsout("User file has problem writing\r\n");
  1872. X    } else {
  1873. X        fputs(" ", buf);/* put lf on end of each record */
  1874. X    }
  1875. X}
  1876. X/* end of function         */
  1877. Xwrtuser(buf)
  1878. X    FILE           *buf;
  1879. X{
  1880. X    int             code;
  1881. X    strcpy(l_f_base, "00");
  1882. X    strcpy(l_m_base, "00");
  1883. X    strcpy(xprt_a, "0");
  1884. X    strcpy(tggl_a, "1");
  1885. X    code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1886. X               u_fname,
  1887. X               u_lname,
  1888. X               u_password,
  1889. X               u_time1,
  1890. X               u_date1,
  1891. X               u_time2,
  1892. X               u_date2,
  1893. X               u_city,
  1894. X               l_m_base,
  1895. X               l_f_base,
  1896. X               xprt_a,
  1897. X               tggl_a);
  1898. X    if (code == -1) {
  1899. X        portsout("User file has problem writing\r\n");
  1900. X    } else {
  1901. X        fputs("\n", buf);    /* put lf on end of each record */
  1902. X    }
  1903. X}
  1904. X/* end of function         */
  1905. X
  1906. Xerror_config()
  1907. X{
  1908. X    portsout("\n\rError reading entry in config file!\n\r");
  1909. X    exit(1);
  1910. X}
  1911. Xstrip(datar) char *
  1912. X                    datar;
  1913. X{
  1914. X    int             length;
  1915. X    char           *data_ptr;
  1916. X    while (1) {
  1917. X        data_ptr = strrchr(datar, '\n');
  1918. X        if (data_ptr == NULL)
  1919. X            return;
  1920. X        *data_ptr = '\0';
  1921. X    }
  1922. X}
  1923. Xtoday_msg()
  1924. X{
  1925. X    int             result;
  1926. X    strcpy(buf128, ORGPATH);
  1927. X    strcat(buf128, mnd);
  1928. X    strcat(buf128, ".msg");
  1929. X    result = stat(buf128, &statbuf);
  1930. X    if (!result) {
  1931. X        portsout("\n\r\n\r");
  1932. X        portsout("                               Message of the Day");
  1933. X        portsout("\n\r\n\r");
  1934. X        no_cntrl_k = TRUE;
  1935. X        cmd_p(buf128);
  1936. X        no_cntrl_k = FALSE;
  1937. X        portsout(CRLF);
  1938. X    }
  1939. X}
  1940. Xsetmodes()
  1941. X{
  1942. X    ioctl(0, TCGETA, &ttys);
  1943. X    tty = ttyname(0);
  1944. X
  1945. X
  1946. X    ttysnew = ttys;
  1947. X    ttysnew.c_cflag &= ~CSIZE;
  1948. X    ttysnew.c_cflag |= CS8;
  1949. X    ttysnew.c_cflag &= ~PARENB;
  1950. X
  1951. X    /* set new paramters */
  1952. X    ioctl(0, TCSETAF, &ttysnew);
  1953. X
  1954. X
  1955. X
  1956. X}
  1957. X
  1958. X/* restore normal tty modes */
  1959. Xrestoremodes()
  1960. X{
  1961. X
  1962. X
  1963. X    ioctl(0, TCSETAF, &ttys);
  1964. X
  1965. X
  1966. X}
  1967. Xint alphacheck(strng)
  1968. Xchar *strng;
  1969. X{
  1970. X    int y;
  1971. X    while( *strng ) {
  1972. X        y = isalpha((int)*strng++);
  1973. X        if( !y )
  1974. X            return(y);
  1975. X    }
  1976. X    return(1);
  1977. X}
  1978. X
  1979. X
  1980. X/* end of program       */
  1981. END_OF_FILE
  1982.   if test 42113 -ne `wc -c <'bbsc2.c'`; then
  1983.     echo shar: \"'bbsc2.c'\" unpacked with wrong size!
  1984.   fi
  1985.   # end of 'bbsc2.c'
  1986. fi
  1987. if test -f 'bbscfile.c' -a "${1}" != "-c" ; then 
  1988.   echo shar: Will not clobber existing file \"'bbscfile.c'\"
  1989. else
  1990.   echo shar: Extracting \"'bbscfile.c'\" \(15763 characters\)
  1991.   sed "s/^X//" >'bbscfile.c' <<'END_OF_FILE'
  1992. X/*
  1993. X    bbscfile.c
  1994. X
  1995. X*/
  1996. X
  1997. X/* #define DEBUG 1 */
  1998. X
  1999. X#include "bbscdef.h"
  2000. X#include <string.h>
  2001. X#include <sys/types.h>     /* For compatibility */
  2002. X#include <sys/locking.h>
  2003. X
  2004. X#define LASTDATE  " 04/21/90 "
  2005. X
  2006. X#define PGMNAME "BBSCFILE "
  2007. X#define VERSION " 7.92 "
  2008. Xextern int user_priv;
  2009. X
  2010. X    static    char    bufmsg0[MSG1MAX+1],
  2011. X        buftmp[MSGSECT+256],
  2012. X        this1[11],
  2013. X        next1[11];
  2014. Xhdrwrt()        /* write the header from memory variables */
  2015. X    {        /* header is a 1 record file */
  2016. X    int    fd;
  2017. X    int    fd1;
  2018. X
  2019. X    strcpy(who_am_i, m_pathname);
  2020. X    strcat(who_am_i, HEADER);
  2021. X    if ((fd = open(who_am_i,WRITE,0666)) < 0)    /* open i/o */
  2022. X        {
  2023. X        portsout("Can't open header-file, will create it!") ;
  2024. X        portsout(CRLF) ;
  2025. X        if ((fd = creat(who_am_i,0666)) < 0)
  2026. X            {
  2027. X            portsout("Can't create header-file, aborting!") ;
  2028. X            portsout(CRLF) ;
  2029. X            return(ERROR) ;
  2030. X            }
  2031. X        }
  2032. X    lseek(fd, 0L, 0);
  2033. X    locking(fd, LK_LOCK, 0L);
  2034. X    strcpy(who_am_i, m_pathname);
  2035. X    strcat(who_am_i, CROSSREF);
  2036. X    if ((fd1 = open(who_am_i,WRITE,0666)) < 0)
  2037. X        {
  2038. X        portsout("Can't open xref file, will create it!");
  2039. X        portsout(CRLF) ;
  2040. X        if ((fd1 = creat(who_am_i,0666)) < 0)
  2041. X            {
  2042. X            portsout(" XREF creation error! -- abort!");
  2043. X            portsout(CRLF);
  2044. X            return(ERROR) ;
  2045. X            }
  2046. X        }
  2047. X    lseek(fd1, 0L, 0);
  2048. X    locking(fd1, LK_LOCK, 0L);
  2049. X    itoa(h_next_msg,h_next) ;    /* convert int to char */
  2050. X    itoa(h_act_msg,h_act) ;
  2051. X    strfill(buf128,26,MSGSECT) ;    /* init buf128 to all hex 1a */
  2052. X    sprintf(buf128,"%s~%s~%s~",    /* build record */
  2053. X        h_next_msg,
  2054. X        h_act_msg,
  2055. X        h_date) ;
  2056. X    write(fd,buf128,MSGSECT) ;    /* write it */
  2057. X    lseek(fd, 0L, 0);
  2058. X    locking(fd, LK_UNLCK, 0L);
  2059. X    close(fd) ;            /* no need to leave it open */
  2060. X    write(fd1,xtable,4000);
  2061. X    lseek(fd1, 0L, 0);
  2062. X    locking(fd1, LK_UNLCK, 0L);
  2063. X    close(fd1) ;
  2064. X    return(OK) ;
  2065. X    }
  2066. X
  2067. Xhdrread()        /* read the header file into memory */
  2068. X    {
  2069. X    int    fd,
  2070. X        i,
  2071. X        cnt1,
  2072. X        cnt;
  2073. X
  2074. X    strcpy(who_am_i, m_pathname);
  2075. X    strcat(who_am_i, HEADER);
  2076. X    if ((fd = open(who_am_i,READ,0666)) < 0)    /* open input */
  2077. X        {
  2078. X        portsout("Can't open header-file, using inital values!") ;
  2079. X        portsout(CRLF) ;
  2080. X        h_next = 1 ;
  2081. X        h_next_msg[0] = '1' ; h_next_msg[1] = 0 ;
  2082. X        h_act = 1 ;
  2083. X        h_act_msg[0] = '1' ; h_act_msg[1] = 0 ;
  2084. X        h_date[0] = '0' ; h_date[1] = 0 ;
  2085. X        hdrwrt() ; goto next;
  2086. X        }
  2087. X    lseek(fd, 0L, 0);
  2088. X    locking(fd, LK_LOCK, 0L);
  2089. X    if((cnt=read(fd,buf128,MSGSECT)) != MSGSECT)
  2090. X        {
  2091. X        portsout(CRLF) ;
  2092. X            portsout("<<< header read error >>>") ;
  2093. X        portsout(CRLF) ;
  2094. X        return(ERROR) ;
  2095. X        }
  2096. X    cnt = sscanf(buf128,"%[^~]~%[^~]~%[^~]~", 
  2097. X            h_next_msg,
  2098. X            h_act_msg,
  2099. X            h_date) ;
  2100. Xnext:
  2101. X    lseek(fd, 0L, 0);
  2102. X    locking(fd, LK_UNLCK, 0L);
  2103. X    close(fd) ;        /* no need to leave it open */
  2104. X    strcpy(who_am_i, m_pathname);
  2105. X    strcat(who_am_i, CROSSREF);
  2106. X    if ((fd = open(who_am_i,READ,0666)) < 0)
  2107. X        {
  2108. X        portsout("Can't open xref file --- setting values!");
  2109. X        portsout(CRLF);
  2110. X        xtable[0] = 1L;
  2111. X        for (i = 1; i <= 999; i++)
  2112. X            xtable[i] = 0L;
  2113. X        return ;
  2114. X        }
  2115. X    lseek(fd, 0L, 0);
  2116. X    locking(fd, LK_LOCK, 0L);
  2117. X    if ((cnt1=read(fd, xtable, 4000)) != 4000)
  2118. X        {
  2119. X        portsout(CRLF) ;
  2120. X        portsout("<<< xref read error >>>");
  2121. X        portsout(CRLF);
  2122. X        return(ERROR);
  2123. X        }
  2124. X    lseek(fd, 0L, 0);
  2125. X    locking(fd, LK_UNLCK, 0L);
  2126. X    close (fd);
  2127. X/*
  2128. X
  2129. X    if (cnt != 2)
  2130. X        {
  2131. X        return(ERROR) ;
  2132. X        }
  2133. X*/
  2134. X    h_next = atoi(h_next_msg) ;
  2135. X    h_act = atoi(h_act_msg) ;
  2136. X    return(OK) ;
  2137. X    }
  2138. X
  2139. Xmsgopen(how)
  2140. Xint    how ;        /* how to open 0=input, 1=output, 2=i/o */
  2141. X    {
  2142. X    int    fd ;
  2143. X
  2144. X    strcpy(who_am_i, m_pathname);
  2145. X    strcat(who_am_i, MESSAGES);
  2146. X    if ((fd = open(who_am_i,how,0666)) < 0)    /* open i/o */
  2147. X        {
  2148. X        portsout("can't open message-file, will create it!") ;
  2149. X        portsout(CRLF) ;
  2150. X        if ((fd = creat(who_am_i,0666)) < 0)
  2151. X            {
  2152. X            portsout("can't create message-file, aborting!") ;
  2153. X            portsout(CRLF) ;
  2154. X            return(ERROR) ;
  2155. X            }
  2156. X        }
  2157. X    lseek(fd, 0L, 0);
  2158. X    locking(fd, LK_RLCK, 0L);
  2159. X    return(fd) ;
  2160. X    }
  2161. X
  2162. Xmsgclose(fd)
  2163. Xint    fd ;
  2164. X    {
  2165. X    lseek(fd, 0L, 0);
  2166. X    locking(fd, LK_UNLCK, 0L);
  2167. X    return(close(fd)) ;
  2168. X    }
  2169. X
  2170. Xmsgwrt(fd)        /* write the message file from memory variables */
  2171. Xint    fd;        /* writes a message starting with the h_next msg # */
  2172. X    {
  2173. X    int    rc,            /* return code */
  2174. X        cnt1,
  2175. X        cnt2,
  2176. X        len;
  2177. X
  2178. X    rc = cnt1 = len = cnt2 = 0 ;
  2179. X    itoa(this1,h_next) ;                /* convert int to char */
  2180. X    xtable[h_act - 1] = h_next;
  2181. X    for( len=h_act; len < 1000; len++)
  2182. X        xtable[len] = 0L;        /* guarantee clean table */
  2183. X    h_act++;
  2184. X    rc = seek(fd,h_next - 1,0) ;        /* seek next available sector */
  2185. X    h_next++ ;
  2186. X    itoa(next1,h_next) ;
  2187. X    strfill(buf128,0,MSGSECT) ;        /* init buf128 to all hex 00 */
  2188. X/*
  2189. X*            build first piece of msg record
  2190. X*/
  2191. X    sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  2192. X        this1,                    /* this rcd # */
  2193. X        next1,                    /*  points next rcd # */
  2194. X        msg_delete,                /* delete byte */
  2195. X        msg_date,
  2196. X        msg_time,
  2197. X        msg_to,
  2198. X        msg_from,
  2199. X        msg_pass,
  2200. X        msg_subject);
  2201. X    rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  2202. X                    /*  for a message record */
  2203. X/*
  2204. X*            build the n+1 piece of msg record
  2205. X*/
  2206. X
  2207. X    len = (strlen(msg_text) / MSG1MAX) + 1; /* calc how many more 128 */
  2208. X                        /*  byte records to write */
  2209. X    cnt2 = 1 ;                /* init for substr */
  2210. X    while (len--)
  2211. X        {
  2212. X        itoa(this1,h_next);        /* calc/convert record #'s */
  2213. X        h_next++;                      
  2214. X        if (len == 0)
  2215. X            {
  2216. X            strcpy(next1,"0");    /* marks last 128 byte piece */
  2217. X            }            /*  of a msg */
  2218. X        else
  2219. X            {
  2220. X            itoa(next1,h_next);
  2221. X            }
  2222. X        strfill(bufmsg0,0,MSG1MAX);
  2223. X        substr(msg_text,bufmsg0,cnt2,MSG1MAX); /* mv MSG1MAX to buff */
  2224. X        cnt2 += MSG1MAX;        /* up cnt2 by MSG1MAX */
  2225. X        strfill(buf128,0,MSGSECT);    /* init buf128 to all hex 00 */
  2226. X        sprintf(buf128,"%-10s~%-10s~%-2s~%-102s~",
  2227. X            this1,            /* this rcd # */
  2228. X            next1,            /* point to next rcd # */
  2229. X            msg_delete,        /* delete byte */
  2230. X            bufmsg0);        /* piece of msg */
  2231. X        rc = write(fd,buf128,MSGSECT);    /* write n+1 128 byte record */
  2232. X        }
  2233. X
  2234. X    strfill(buf128,26,MSGSECT);        /* fill with all hex 1a */
  2235. X    rc = write(fd,buf128,MSGSECT);    /* write all hex 1a 128 byte record */
  2236. X    return(OK);
  2237. X    }
  2238. X
  2239. Xmsgrewrt(fd,r_msg)    /* re-write the message file from memory variables */
  2240. Xint    fd,        /* re-writes only the 1st part of a message */
  2241. X    r_msg;        /* used to update the delete byte */
  2242. X    {
  2243. X    int    rc,            /* return code */
  2244. X        cnt1,
  2245. X        file_size;
  2246. X
  2247. X    rc = cnt1 = 0;
  2248. X    if (r_msg > h_next)    /* don't try to seek past end of file */
  2249. X        {
  2250. X        return(ERROR);
  2251. X        }
  2252. X    if ((rc = seek(fd,r_msg-1,0)) == ERROR)    /* seek to requested sector */
  2253. X        {
  2254. X        return(ERROR);
  2255. X        }
  2256. X    itoa(this1,r_msg);        /* convert int to char */
  2257. X    r_msg++;
  2258. X    itoa(next1,r_msg);
  2259. X    strfill(buf128,0,MSGSECT);        /* init buf128 to all hex 00 */
  2260. X/*
  2261. X*            build first piece of msg record
  2262. X*/
  2263. X    sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  2264. X        this1,                    /* this rcd # */
  2265. X        next1,                    /* points next rcd # */
  2266. X        msg_delete,                /* delete byte */
  2267. X        msg_date,
  2268. X        msg_time,
  2269. X        msg_to,
  2270. X        msg_from,
  2271. X        msg_pass,
  2272. X        msg_subject);
  2273. X    rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  2274. X                    /*  for a message record */
  2275. X    return(OK);
  2276. X    }
  2277. X
  2278. X
  2279. Xmsgread(fd,msgno)        /* read message number requested */
  2280. Xint    fd,            /* returns ERROR if msg past eof */
  2281. X    msgno;            /* returns 0 if msg is not 1st piece */
  2282. X                /*   of a message */
  2283. X                /* returns 0 if msg is deleted */
  2284. X                /* returns msg # if successful */
  2285. X    {
  2286. X    int    rc,            /* return code */
  2287. X        msgac,
  2288. X        cnt1,
  2289. X        cnt2,
  2290. X        len,
  2291. X        next,
  2292. X        ret_this,
  2293. X        file_size;
  2294. X    char     act[11];
  2295. X
  2296. X    msgac = xtable[msgno - 1];
  2297. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2298. X        {
  2299. X        return(ERROR);
  2300. X        }
  2301. X    if (msgac == 0)
  2302. X        {
  2303. X        return(ERROR);
  2304. X        }
  2305. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2306. X        {
  2307. X        portsout(CRLF) ;
  2308. X        portsout("Can't seek on message-file!") ;
  2309. X        portsout(CRLF) ;
  2310. X        return(ERROR);        /* when cant find it */
  2311. X        }
  2312. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2313. X        {
  2314. X        portsout(CRLF) ;
  2315. X        portsout("Can't read in message-file!") ;
  2316. X        portsout(CRLF) ;
  2317. X        return(ERROR);
  2318. X        }
  2319. X/*
  2320. X*            get first piece of msg record
  2321. X*/
  2322. X/* do trial read, since if not first record, fields might overflow */
  2323. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2324. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2325. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2326. X        {        /*  of a message and not in the middle */
  2327. X        return(0);    /* 0 when is not the msg header */
  2328. X        }
  2329. X/* now do the real read since looks like is a good record */
  2330. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2331. X        this1,                /* this rcd # */
  2332. X        next1,                /*  points to next rcd # */
  2333. X        msg_delete,            /* delete byte */
  2334. X        msg_date,
  2335. X        msg_time,
  2336. X        msg_to,
  2337. X        msg_from,
  2338. X        msg_pass,
  2339. X        msg_subject);
  2340. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2341. X        {        /*  of a message and not in the middle */
  2342. X        return(0);    /* 0 when is not the msg header */
  2343. X        }
  2344. X
  2345. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2346. X        {            /*  if so, return as if not found */
  2347. X        return(0);
  2348. X        }
  2349. X
  2350. X    ret_this = atoi(this1);    /* return this msg no. */
  2351. X    next = atoi(next1);
  2352. X    itoa(act,msgno);
  2353. X    strcpy(msg_no,act);
  2354. X    if(msg_delete[0] == '5')
  2355. X        {
  2356. X        strcat(msg_no,"*");
  2357. X        strcpy(msg_subject,"< Private Msg >");
  2358. X        }
  2359. X    msg_text[0] = '\0';
  2360. X    while (next)            /* read until no more pieces for */
  2361. X        {            /*  this message */
  2362. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2363. X            {
  2364. X            portsout(CRLF) ;
  2365. X            portsout("Can't read in message-file(2)!") ;
  2366. X            portsout(CRLF) ;
  2367. X            return(ERROR);
  2368. X            }
  2369. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2370. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2371. X            this1,            /* this rcd # */
  2372. X            next1,            /* point to next rcd # */
  2373. X            msg_delete,        /* delete byte */
  2374. X            bufmsg0);        /* piece of msg */
  2375. X        next = atoi(next1);
  2376. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2377. X                        /*  whole msg array */
  2378. X        }
  2379. X    return(ret_this);    /* if all ok, return the msg no. found */
  2380. X    }
  2381. X
  2382. Xmsgreadx(fd,msgno)        /* read message number requested */
  2383. Xint    fd,            /* returns ERROR if msg past eof */
  2384. X    msgno;            /* returns 0 if msg is not 1st piece */
  2385. X                /*   of a message */
  2386. X                /* returns 0 if msg is deleted */
  2387. X                /* returns msg # if successful */
  2388. X    {
  2389. X    int    rc,            /* return code */
  2390. X        msgac,
  2391. X        cnt1,
  2392. X        cnt2,
  2393. X        len,
  2394. X        next,
  2395. X        ret_this,
  2396. X        t1,
  2397. X        t2,
  2398. X        t3,
  2399. X        file_size;
  2400. X    char    who_am_i[99],
  2401. X        who_am_I[99],
  2402. X        sysop[99],
  2403. X        Sysop[99],
  2404. X        act[11];
  2405. X
  2406. X    msgac = xtable[msgno - 1];
  2407. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2408. X        {
  2409. X        return(ERROR);
  2410. X        }
  2411. X    if (msgac == 0)
  2412. X        {
  2413. X        return(ERROR);
  2414. X        }
  2415. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2416. X        {
  2417. X        portsout(CRLF) ;
  2418. X        portsout("Can't seek on message-file!") ;
  2419. X        portsout(CRLF) ;
  2420. X        return(ERROR);        /* when cant find it */
  2421. X        }
  2422. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2423. X        {
  2424. X        portsout(CRLF) ;
  2425. X        portsout("Can't read in message-file!") ;
  2426. X        portsout(CRLF) ;
  2427. X        return(ERROR);
  2428. X        }
  2429. X/*
  2430. X*            get first piece of msg record
  2431. X*/
  2432. X/* do trial read, since if not first record, fields might overflow */
  2433. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2434. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2435. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2436. X        {        /*  of a message and not in the middle */
  2437. X        return(0);    /* 0 when is not the msg header */
  2438. X        }
  2439. X/* now do the real read since looks like is a good record */
  2440. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2441. X        this1,
  2442. X        next1,                /*  points to next rcd # */
  2443. X        msg_delete,            /* delete byte */
  2444. X        msg_date,
  2445. X        msg_time,
  2446. X        msg_to,
  2447. X        msg_from,
  2448. X        msg_pass,
  2449. X        msg_subject);
  2450. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2451. X        {        /*  of a message and not in the middle */
  2452. X        return(0);    /* 0 when is not the msg header */
  2453. X        }
  2454. X
  2455. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2456. X        {            /*  if so, return as if not found */
  2457. X        return(0);
  2458. X        }
  2459. X    if (msg_delete[0] == '5')    /* protected msg */
  2460. X        {
  2461. X        strcpy(who_am_i,w_fname);
  2462. X        strcat(who_am_i," ");
  2463. X        strcat(who_am_i,w_lname);
  2464. X        strcpy(Sysop,SYSOP);
  2465. X        sprintf(sysop,"%-21s",Sysop);
  2466. X        sprintf(who_am_I,"%-21s",who_am_i);
  2467. X        t1=strcmp(who_am_I,sysop);
  2468. X        t2=strcmp(who_am_I,msg_to);
  2469. X        t3=strcmp(who_am_I,msg_from);
  2470. X        if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  2471. X            {
  2472. X            goto zzzz;
  2473. X            }
  2474. X        return(-10);
  2475. X        }
  2476. Xzzzz:
  2477. X
  2478. X    ret_this = atoi(this1);    /* return this msg no. */
  2479. X    next = atoi(next1);
  2480. X    itoa(act,msgno);
  2481. X    strcpy(msg_no,act);
  2482. X    msg_text[0] = '\0';
  2483. X    while (next)            /* read until no more pieces for */
  2484. X        {            /*  this message */
  2485. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2486. X            {
  2487. X            portsout(CRLF) ;
  2488. X            portsout("Can't read in message-file(2)!") ;
  2489. X            portsout(CRLF) ;
  2490. X            return(ERROR);
  2491. X            }
  2492. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2493. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2494. X            this1,            /* this rcd # */
  2495. X            next1,            /* point to next rcd # */
  2496. X            msg_delete,        /* delete byte */
  2497. X            bufmsg0);        /* piece of msg */
  2498. X        next = atoi(next1);
  2499. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2500. X                        /*  whole msg array */
  2501. X        }
  2502. X    return(ret_this);    /* if all ok, return the msg no. found */
  2503. X    }
  2504. Xmsgreadk(fd,msgno)        /* read message number requested */
  2505. Xint    fd,            /* returns ERROR if msg past eof */
  2506. X    msgno;            /* returns 0 if msg is not 1st piece */
  2507. X                /*   of a message */
  2508. X                /* returns 0 if msg is deleted */
  2509. X                /* returns msg # if successful */
  2510. X    {
  2511. X    int    rc,            /* return code */
  2512. X        msgac,
  2513. X        cnt1,
  2514. X        cnt2,
  2515. X        len,
  2516. X        next,
  2517. X        ret_this,
  2518. X        t1,
  2519. X        t2,
  2520. X        t3,
  2521. X        file_size;
  2522. X    char    who_am_i[99],
  2523. X        who_am_I[99],
  2524. X        sysop[99],
  2525. X        Sysop[99],
  2526. X        act[11];
  2527. X
  2528. X    msgac = xtable[msgno - 1];
  2529. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2530. X        {
  2531. X        return(ERROR);
  2532. X        }
  2533. X    if (msgac == 0)
  2534. X        {
  2535. X        return(ERROR);
  2536. X        }
  2537. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2538. X        {
  2539. X        portsout(CRLF) ;
  2540. X        portsout("Can't seek on message-file!") ;
  2541. X        portsout(CRLF) ;
  2542. X        return(ERROR);        /* when cant find it */
  2543. X        }
  2544. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2545. X        {
  2546. X        portsout(CRLF) ;
  2547. X        portsout("Can't read in message-file!") ;
  2548. X        portsout(CRLF) ;
  2549. X        return(ERROR);
  2550. X        }
  2551. X/*
  2552. X*            get first piece of msg record
  2553. X*/
  2554. X/* do trial read, since if not first record, fields might overflow */
  2555. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2556. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2557. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2558. X        {        /*  of a message and not in the middle */
  2559. X        return(0);    /* 0 when is not the msg header */
  2560. X        }
  2561. X/* now do the real read since looks like is a good record */
  2562. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2563. X        this1,
  2564. X        next1,                /*  points to next rcd # */
  2565. X        msg_delete,            /* delete byte */
  2566. X        msg_date,
  2567. X        msg_time,
  2568. X        msg_to,
  2569. X        msg_from,
  2570. X        msg_pass,
  2571. X        msg_subject);
  2572. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2573. X        {        /*  of a message and not in the middle */
  2574. X        return(0);    /* 0 when is not the msg header */
  2575. X        }
  2576. X
  2577. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2578. X        {            /*  if so, return as if not found */
  2579. X        return(0);
  2580. X        }
  2581. X    strcpy(who_am_i,w_fname);
  2582. X    strcat(who_am_i," ");
  2583. X    strcat(who_am_i,w_lname);
  2584. X    strcpy(Sysop,SYSOP);
  2585. X    sprintf(sysop,"%-21s",Sysop);
  2586. X    sprintf(who_am_I,"%-21s",who_am_i);
  2587. X    t1=strcmp(who_am_I,sysop);
  2588. X    t2=strcmp(who_am_I,msg_to);
  2589. X    t3=strcmp(who_am_I,msg_from);
  2590. X    if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  2591. X        {
  2592. X        goto yyyy;
  2593. X        }
  2594. X    return(-10);
  2595. Xyyyy:
  2596. X
  2597. X    ret_this = atoi(this1);    /* return this msg no. */
  2598. X    next = atoi(next1);
  2599. X    itoa(act,msgno);
  2600. X    strcpy(msg_no,act);
  2601. X    msg_text[0] = '\0';
  2602. X    while (next)            /* read until no more pieces for */
  2603. X        {            /*  this message */
  2604. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2605. X            {
  2606. X            portsout(CRLF) ;
  2607. X            portsout("Can't read in message-file(2)!") ;
  2608. X            portsout(CRLF) ;
  2609. X            return(ERROR);
  2610. X            }
  2611. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2612. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2613. X            this1,            /* this rcd # */
  2614. X            next1,            /* point to next rcd # */
  2615. X            msg_delete,        /* delete byte */
  2616. X            bufmsg0);        /* piece of msg */
  2617. X        next = atoi(next1);
  2618. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2619. X                        /*  whole msg array */
  2620. X        }
  2621. X    return(ret_this);    /* if all ok, return the msg no. found */
  2622. X    }
  2623. X/*    end of program      */
  2624. END_OF_FILE
  2625.   if test 15763 -ne `wc -c <'bbscfile.c'`; then
  2626.     echo shar: \"'bbscfile.c'\" unpacked with wrong size!
  2627.   fi
  2628.   # end of 'bbscfile.c'
  2629. fi
  2630. if test -f 'bbscmisc.c' -a "${1}" != "-c" ; then 
  2631.   echo shar: Will not clobber existing file \"'bbscmisc.c'\"
  2632. else
  2633.   echo shar: Extracting \"'bbscmisc.c'\" \(2034 characters\)
  2634.   sed "s/^X//" >'bbscmisc.c' <<'END_OF_FILE'
  2635. X
  2636. X#include "bbscdef.h"
  2637. X#include <string.h>
  2638. X#include <ctype.h>
  2639. X#include <sys/types.h>
  2640. X#include <sys/stat.h>
  2641. X
  2642. Xstrfill(buf,fillchar,length)    /* fill a string with fillchar */
  2643. Xchar    *buf;            /*  for length -1 */
  2644. Xint    fillchar,
  2645. X    length;
  2646. X    {
  2647. X    while(--length)        /* really is length -1 */
  2648. X        {
  2649. X        *buf++ = fillchar;
  2650. X        }
  2651. X    *buf++ = '\0';        /* need room for this */
  2652. X    }
  2653. X#ifndef ATT3B1
  2654. X
  2655. Xsubstr(from,to,start,length)    /* moves chars from "from" to "to" */
  2656. Xchar    *from, *to ;        /*  starting at "start" for */
  2657. X                    /*  "length" number of chars */
  2658. Xint    start, length ;        /* for beginning of string use 1, not 0 */
  2659. X    {
  2660. X    int    cnt;
  2661. X
  2662. X    cnt = 0;
  2663. X
  2664. X    while(--start)        /* adjust sending field pointer */
  2665. X        {
  2666. X        from++;        
  2667. X        }
  2668. X
  2669. X    while((cnt < length) && (*to++ = *from++))    /* do the moving */
  2670. X        {
  2671. X        cnt++;        
  2672. X        }
  2673. X    
  2674. X    *to = '\0';
  2675. X
  2676. X    }
  2677. X#endif
  2678. X
  2679. X#ifdef ATT3B1
  2680. X
  2681. Xsubstr(from,to,start,length)
  2682. Xchar *from,*to;
  2683. Xint start,length;
  2684. X{
  2685. X   int cnt, i;
  2686. X
  2687. X   cnt = 0;
  2688. X   while(--start)
  2689. X       from++;
  2690. X
  2691. X   i=0;
  2692. X   while(cnt < length)
  2693. X      if (from[i] == NULL)
  2694. X         break;
  2695. X      else {
  2696. X         to[i] = from[i];
  2697. X         i++;
  2698. X         cnt++;
  2699. X     }
  2700. X
  2701. X   to[i] = NULL;
  2702. X}
  2703. X
  2704. X#endif
  2705. X
  2706. Xitoa(str,n)        /* taken from float.c */
  2707. Xchar *str;
  2708. X    {
  2709. X    sprintf(str,"%d",n) ;
  2710. X    }
  2711. X/*    end of function        */
  2712. X
  2713. Xseek(fildes,posit,dummy) int fildes,posit,dummy ;
  2714. X    {
  2715. Xlong    pos;
  2716. X    pos = posit * 128L ;
  2717. X/*    return(lseek(fildes,posit << 7,0)) ;    */
  2718. X    return(lseek(fildes,pos,0)) ;
  2719. X    }
  2720. X/*    end of function        */
  2721. X
  2722. Xchar *basename(x)  char *x;
  2723. X{
  2724. X    char *ptr;
  2725. X    ptr = strrchr(x, '/');
  2726. X    if ( ptr == (char *)NULL )
  2727. X        return(x);
  2728. X    else
  2729. X        return(++ptr);
  2730. X}
  2731. X
  2732. Xint legalname( co, strg )
  2733. Xchar *co, *strg;
  2734. X{
  2735. X    char *ptr, *indx;
  2736. X    int i;
  2737. X    ptr = co;
  2738. X    while ( *ptr ) {
  2739. X        i = (int) *ptr++;
  2740. X        indx = strchr(strg, i);
  2741. X        if ( indx != NULL )
  2742. X            return(0);
  2743. X    }
  2744. X    return(1);
  2745. X}
  2746. X
  2747. Xint asciicheck(fne)
  2748. Xchar *fne;
  2749. X{
  2750. X    FILE *tbuf;
  2751. X    int datar;
  2752. X    if((tbuf = fopen(fne, "r")) == NULL )
  2753. X        return(0);
  2754. X    while ((datar = getc(tbuf)) != EOF ) {
  2755. X        if(isprint(datar) == 0 && isspace(datar) == 0) {
  2756. X            fclose(tbuf);
  2757. X            return(0);
  2758. X        }
  2759. X    }
  2760. X    fclose(tbuf);
  2761. X    return(1);
  2762. X}
  2763. X    
  2764. X    
  2765. X/*    end of program      */
  2766. END_OF_FILE
  2767.   if test 2034 -ne `wc -c <'bbscmisc.c'`; then
  2768.     echo shar: \"'bbscmisc.c'\" unpacked with wrong size!
  2769.   fi
  2770.   # end of 'bbscmisc.c'
  2771. fi
  2772. echo shar: End of archive 3 \(of 11\).
  2773. cp /dev/null ark3isdone
  2774. MISSING=""
  2775. for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
  2776.     if test ! -f ark${I}isdone ; then
  2777.     MISSING="${MISSING} ${I}"
  2778.     fi
  2779. done
  2780. if test "${MISSING}" = "" ; then
  2781.     echo You have unpacked all 11 archives.
  2782.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2783. else
  2784.     echo You still must unpack the following archives:
  2785.     echo "        " ${MISSING}
  2786. fi
  2787. exit 0
  2788. exit 0 # Just in case...
  2789.