#address $7000 #reserve 6 #copyright "Renumber.cmd Copyright 1995 K-Products" #version $50 #define DISK2 2 #define INDEX_SIZE 2560 #include runtime.h #include bbs_pro.h /* * Message base index record * ------------------------- */ char index_buffer [0]; /* buffer read into here */ char i_name [21]; /* name of this message base */ byte i_chunks; /* number of chunks per message */ int i_totbytes; /* max bytes allowed per message */ byte i_maxmsgs; /* max messages allocated for */ byte i_inuse; /* # of slots currently in use */ int i_posted; /* total msgs posted here */ byte i_graphics; /* $80=allow /Graphics, 0=don't */ byte i_msgptr [251]; /* 250 message pointers */ byte i_flag [251]; /* locked/received */ byte i_msgnlo [251]; /* message numbers lo */ byte i_msgnhi [251]; /* hi */ byte i_tolo [251]; /* to user number lo */ byte i_tohi [251]; /* hi */ byte i_fromlo [251]; /* from user number lo */ byte i_fromhi [251]; /* hi */ byte i_replylo [251]; /* msg # this is a reply to lo */ byte i_replyhi [251]; /* hi */ byte i_filler [21]; /* fill out to a chunk boundary */ byte stackptr, keypress = 764; int message_number; /* used to count from 1 up */ byte old_numlo [251], old_numhi [251]; main() { byte current_base; if (ignore_modem == 0) { echof ("This command must be run locally\from the sysop's keyboard%e"); return; } MIOsuspend(); #asm { tsx stx stackptr; } printf("%e%e Message Base Renumber%e%e"); printf("This program will renumber all of%e"); printf("your messages starting with the%e"); printf("message number of one. It will then%e"); printf("update all userlog records so that%e"); printf("NO message will be 'new' anymore.%e%e"); printf("Are you SURE you want to do this? "); if (y_or_n() == 'N') { MIOresume(); return; } printf("%e%eHere we go!%e"); message_number = 1; for (current_base = 1; current_base < 33; ++current_base) { if (s_msgbdr [current_base-1] > 0) { renumber_base (current_base); } } s_himsg = message_number; update_userlog(); /* change hi message numbers */ ++s_himsg; printf("%e%eMessage base renumber complete!%e%e"); printf("When you press a key, I'm going to%e"); printf("log you off so the SYSDATA file will%e"); printf("get written back out.%e%e"); printf("As soon as you get back to the%e"); printf("WAITCALL screen (and NOT before!),%e"); printf("press RESET and re-run the BBS so%e"); printf("that the quickscan hi message%e"); printf("numbers will get reloaded.%e%e"); printf("Press any key to logoff..."); keypress = 255; get_key(); usernum = 0; /* so we won't rewrite sysop record */ reset_bbs(); printf("%e%eBYE!%e"); } renumber_base (byte baseno) { char base_name [30]; byte idx, x; strcpy (base_name, "Dx:>PRO>BASES>BASE_xx.DAT"); base_name [2] = s_msgbdr [baseno-1]; base_name [20] = baseno / 10 + '0'; base_name [21] = baseno % 10 + '0'; printf ("%e%eRenumbering message base #%d%e%e", baseno); file_stat (base_name); if (open (DISK2, base_name, 12, 0) != OK) critical_error ("opening", baseno); if (blockread (DISK2, index_buffer, INDEX_SIZE) != INDEX_SIZE) critical_error ("reading", baseno); /* First, renumber each message, saving its old message number */ /* ----------------------------------------------------------- */ printf ("Renumbering messages..."); for (idx = 1; idx <= i_inuse; ++idx) { old_numlo [idx] = i_msgnlo [idx]; old_numhi [idx] = i_msgnhi [idx]; i_msgnlo [idx] = message_number & $ff; i_msgnhi [idx] = message_number >> 8; ++message_number; } printf ("done.%e"); /* Next, change the message thread fields to the new numbers */ /* --------------------------------------------------------- */ printf ("Resolving message threads..."); for (idx = 1; idx <= i_inuse; ++idx) { if (i_replylo [idx] > 0 || i_replyhi [idx] > 0) { for (x = 1; x <= i_inuse; ++x) { if (i_replylo [idx] == old_numlo [x] && i_replyhi [idx] == old_numhi [x]) { i_replylo [idx] = i_msgnlo [x]; i_replyhi [idx] = i_msgnhi [x]; break; } } } } printf ("done.%e"); /* Now, just rewrite the index back to disk and cross your fingers */ /* --------------------------------------------------------------- */ printf ("Rewriting base index..."); if (point_zero (DISK2) != OK) critical_error ("pointing", baseno); if (blockwrite (DISK2, index_buffer, INDEX_SIZE) != INDEX_SIZE) critical_error ("writing", baseno); printf("done%e"); close (DISK2); } critical_error (char *msg; byte base) { if (base > 0) printf("%e%e%cERROR - %s message base #%d%e%e", 253, msg, base); else printf("%e%e%cERROR - %s%e", 253, msg); printf("Press any key to abort renumber..."); get_key(); #asm { ldx stackptr txs rts } } point_zero (byte devno) { #asm { lda .devno asl ; * 2 asl ; * 4 asl ; * 8 asl ; * 16 tax lda #37 ;point to 0th byte sta $342,x lda #0 sta $34c,x sta $34d,x sta $34e,x jsr $e456 tya ;return result code ldx #0 rts } } update_userlog() { int user; byte pr_count; printf ("%eUpdating user hi message counters%e"); if (open_ulog() > 127) critical_error ("Unable to open USERLOG!", 0); for (user = 10; user < 9999; ++user) { if (ck_range (user) != OK) break; if (read_user (user) != OK) break; if (pr_count == 0) printf ("%cUpdating user: %d ", 156, user); ++pr_count; pr_count = pr_count & 15; t_lastread = s_himsg; if (write_user (user) != OK) critical_error ("Unable to write record!", 0); } printf ("%cUser: %d ", 156, user); close_ulog(); printf ("Userlog update complete.%e"); }