|
|
1.1 ! root 1: #include "contents.h" ! 2: #include <stdio.h> ! 3: #include <curses.h> ! 4: ! 5: char selection[15]; ! 6: char filenames [MAXRECORDS][15]; ! 7: char workfile[15]; ! 8: char workstring[80]; ! 9: char getfiles[26][115]; ! 10: char open_mode; ! 11: int place[MAXRECORDS]; ! 12: int limit, screen_num; ! 13: ! 14: void bubble(); /* this is a bubble sort */ ! 15: void show_files(); /* this should display the filenames on a curses screen */ ! 16: int lite(); /* inverse/normal video display of a filename */ ! 17: int rfile(); /* read records from a given file */ ! 18: void write_win(); /*does the actual work of writing filenames to a window */ ! 19: void display_form(); /* for for displaying selected filename */ ! 20: void display_record(); /* display selected filename */ ! 21: void menu(); /* menu printed at bottom of screen */ ! 22: void del_rec(); /* this will be used to delete records */ ! 23: void add_rec(); /* this will be used to add records */ ! 24: void getstring(); /* this will be called by add_rec to get input */ ! 25: void build_uucp(); /* this will build multiple uucp requests */ ! 26: ! 27: struct entry{ ! 28: char filename [15]; ! 29: char filesize [10]; ! 30: char date[7]; ! 31: char description [78]; ! 32: char requires [60]; ! 33: char notes [78]; ! 34: char pathname [60]; ! 35: int noparts; ! 36: } ! 37: ! 38: ! 39: main(argc, argv) ! 40: int argc; ! 41: char *argv[]; ! 42: { ! 43: ! 44: int x; ! 45: ! 46: ! 47: if(argc < 2) ! 48: { ! 49: printf("Usage: mwcbbs [adr] filename\n"); ! 50: printf("[a] add\n[d] download\n[r] remove\n"); ! 51: exit(1); ! 52: } ! 53: ! 54: ! 55: if(strlen(argv[2]) == 0) ! 56: { ! 57: printf("filename not specified. Please enter a filename: "); ! 58: gets (workfile); ! 59: } ! 60: else ! 61: ! 62: strcpy(workfile, argv[2]); ! 63: ! 64: if(argv[1][0] != 'a') ! 65: if(argv[1][0] != 'd') ! 66: if(argv[1][0] != 'r') ! 67: { ! 68: printf("Option %c not recognized!\n",argv[1][0]); ! 69: exit(1); ! 70: } ! 71: ! 72: open_mode = argv[1][0]; ! 73: ! 74: screen_num = 0; ! 75: ! 76: x = rfile(); ! 77: show_files (x); ! 78: ! 79: } ! 80: ! 81: ! 82: ! 83: ! 84: /* show_files() ! 85: * This function will display the filenames read to a curses ! 86: * screen. ! 87: */ ! 88: ! 89: ! 90: void show_files(EOF_FLAG) ! 91: int EOF_FLAG; ! 92: ! 93: { ! 94: char arrow; ! 95: int prevcol =1; ! 96: int prevrow =0; /* prevcol = column before arrow */ ! 97: int newrow =0; /* prevrow = row before arrow */ ! 98: int newcol =1; /* newrow = row after arrow */ ! 99: int counter = 0; /* newcol = column after arrow */ ! 100: ! 101: ! 102: WINDOW *win1, *win2; ! 103: ! 104: initscr(); ! 105: noecho(); ! 106: raw(); ! 107: ! 108: /* allocate memory for window. print message on failure. */ ! 109: ! 110: if((win1=newwin(20, 79, 0,0)) == NULL) ! 111: { ! 112: printf("\007Window Memroy allocation for win1 failed!\n"); ! 113: exit(1); ! 114: } ! 115: ! 116: if((win2=newwin(20, 79, 0,0)) == NULL) ! 117: { ! 118: printf("\007Window Memroy allocation for win2 failed!\n"); ! 119: exit(1); ! 120: } ! 121: ! 122: write_win(win1); ! 123: menu(); ! 124: ! 125: ! 126: /* highlite a filename. This is accomplished by going to a designated ! 127: * row and column, as determined by the row and counter nested loops. ! 128: * The innermost loop gets the character found, copies the retrieved ! 129: * character into a string and deletes the character from the screen. ! 130: * When the filename has been deleted from the screen, it is reprinted ! 131: * to the screen with highliting turned on. Padding for spaces must be ! 132: * accounted for since deleting chars shifts everything on the line one ! 133: * space to the left. ! 134: */ ! 135: ! 136: /* print the first file in inverse video */ ! 137: ! 138: lite (win1, prevrow, prevcol, 1); ! 139: ! 140: do ! 141: { ! 142: ! 143: /* now we need to get a key (preferably an arrow) */ ! 144: ! 145: ! 146: ! 147: arrow = getch(); /* This stupid code should allow to use arrows keys */ ! 148: if (arrow == 27) /* that looks more frendly than hjkl. Vlad 8/15/91 */ ! 149: { ! 150: getch(); ! 151: arrow = getch(); /* When an arrow key is pressed, an escape */ ! 152: if (arrow == 68) /* sequence is returned. The value '27' */ ! 153: arrow = 'h'; /* begins the sequence and the relevant */ ! 154: if (arrow == 67) /* values needed end the sequence. The */ ! 155: arrow = 'l'; /* middle value is not needed, so it is */ ! 156: if (arrow == 66) /* skipped over with a getch() statement */ ! 157: arrow = 'j'; ! 158: if (arrow == 65) ! 159: arrow = 'k'; ! 160: } ! 161: ! 162: ! 163: /* each movement case in the following switch...case will test to see if the ! 164: * new position returns a space. If a space is returned, then we will hit ! 165: * an empty field, which we don't want to do. If we hit an empty space, ! 166: * then don't move the cursor. ! 167: */ ! 168: ! 169: switch(arrow) ! 170: { ! 171: case 'h': /* move left */ ! 172: newcol = prevcol - 15; ! 173: if (newcol < 1) ! 174: newcol = 61; ! 175: if (' ' == mvwinch(win1,newrow,newcol)) ! 176: newcol = 1; ! 177: break; ! 178: ! 179: ! 180: case 'l': /* move right */ ! 181: newcol = prevcol + 15; ! 182: if (newcol > 61) ! 183: newcol = 1; ! 184: if (' ' == mvwinch(win1,newrow,newcol)) ! 185: newcol = 1; ! 186: break; ! 187: ! 188: ! 189: case 'j': /* move down */ ! 190: newrow = prevrow + 1; ! 191: if (newrow == 20) ! 192: newrow = 0; ! 193: if (' ' == mvwinch(win1,newrow,newcol)) ! 194: newrow = 0; ! 195: break; ! 196: ! 197: ! 198: case 'k': /* move up */ ! 199: newrow = prevrow -1; ! 200: if (newrow == -1) ! 201: newrow = 19; ! 202: if (' ' == mvwinch(win1,newrow,newcol)) ! 203: newrow = 0; ! 204: break; ! 205: ! 206: ! 207: case 'p': ! 208: screen_num --; ! 209: newrow = 0; ! 210: newcol = 1; ! 211: if (screen_num < 0) ! 212: screen_num = 0; ! 213: else ! 214: { ! 215: EOF_FLAG = rfile(); ! 216: write_win(win1); ! 217: } ! 218: break; ! 219: ! 220: ! 221: case 'n': ! 222: newrow = 0; ! 223: newcol = 1; ! 224: if (EOF_FLAG == -1) ! 225: break; ! 226: else ! 227: { ! 228: screen_num ++; ! 229: EOF_FLAG = rfile(); ! 230: write_win(win1); ! 231: } ! 232: break; ! 233: ! 234: ! 235: case 'q': ! 236: break; ! 237: ! 238: case 'Q': ! 239: break; ! 240: ! 241: case 'S': ! 242: case 's': ! 243: wclear(win1); ! 244: wrefresh(win1); ! 245: wclear(win2); ! 246: display_form(win2); ! 247: if (open_mode == 'a') ! 248: add_rec(win2, prevrow, prevcol, screen_num); ! 249: else ! 250: display_record(win2,prevrow, prevcol, screen_num); ! 251: clear(); ! 252: menu(); ! 253: if( open_mode == 'a' || open_mode == 'r') ! 254: { ! 255: wmove (win2,0,0); ! 256: waddstr(win2,"Reading file. Please wait..."); ! 257: wrefresh(win2); ! 258: rfile(); ! 259: } ! 260: write_win(win1); ! 261: wclear(win2); ! 262: wrefresh(win2); ! 263: refresh(); ! 264: wrefresh(win1); ! 265: break; ! 266: ! 267: default: ! 268: newcol = prevcol; ! 269: newrow = prevrow; ! 270: break; ! 271: ! 272: } ! 273: ! 274: /* print previous file highlited in normal video */ ! 275: lite (win1, prevrow, prevcol, 0); ! 276: ! 277: /* print new filename selection in inverse video */ ! 278: ! 279: lite (win1, newrow, newcol, 1); ! 280: ! 281: /* set our previous coordinates so that we can go back ! 282: * and unlite a field when the next directin is given. ! 283: */ ! 284: ! 285: prevrow = newrow; ! 286: prevcol = newcol; ! 287: ! 288: ! 289: } ! 290: while (arrow != 'q'); ! 291: ! 292: echo(); ! 293: noraw(); ! 294: endwin(); ! 295: } ! 296: ! 297: ! 298: ! 299: ! 300: /* this routine will take a pointer to a window and row/col ! 301: * coordinates and print a filename found at the coordinates ! 302: * in INVERSE video. ! 303: */ ! 304: ! 305: int lite(win1, row, col, liteflag) ! 306: ! 307: WINDOW *win1; ! 308: int row, col, liteflag; ! 309: ! 310: { ! 311: ! 312: int x,y; ! 313: char litestring[15]; ! 314: ! 315: wmove(win1, row,col); ! 316: ! 317: /* get existing filename char by char, deleting each ! 318: * char as it is read into a string variable. ! 319: */ ! 320: ! 321: for(x=0; x<15; x++) ! 322: { ! 323: litestring[x] = winch(win1); ! 324: /* if we hit a space, we've hit the end of the filename */ ! 325: if(litestring[x] == ' ') ! 326: break; ! 327: wdelch(win1); ! 328: } ! 329: ! 330: litestring[x] = '\0'; ! 331: ! 332: ! 333: /* repad the spaces to keep the remaning filenames ! 334: * on this row in their proper columns. ! 335: */ ! 336: ! 337: for(y=0;y<x;y++) ! 338: winsch(win1,' '); ! 339: ! 340: if (liteflag == 1) ! 341: wstandout(win1); ! 342: ! 343: waddstr(win1, litestring); ! 344: wmove(win1, row, col); ! 345: ! 346: if (liteflag == 1) ! 347: wstandend(win1); ! 348: ! 349: ! 350: /* copy filename to a string to be displayed on stdscr. ! 351: * as a filename is highlited, it is also displayed on ! 352: * stdscr. 'selection' will be used in case the user ! 353: * hits return to locate the filename's entry in the ! 354: * Contents file. ! 355: */ ! 356: ! 357: strcpy(selection, litestring); ! 358: move (23,0); ! 359: printw("Selected filename is: %14s", selection); ! 360: ! 361: refresh(); ! 362: wrefresh(win1); ! 363: ! 364: return(0); ! 365: ! 366: } ! 367: ! 368: ! 369: ! 370: ! 371: ! 372: int rfile() ! 373: ! 374: { ! 375: struct entry record; ! 376: FILE *infp; ! 377: int EOF_FLAG; ! 378: ! 379: /* open file, abort on error */ ! 380: ! 381: if ((infp = fopen(workfile,"r")) == NULL) ! 382: { ! 383: printf("\007ERROR opening file for input!\n"); ! 384: exit(1); ! 385: } ! 386: ! 387: /* open a file then go to a an offset calculated by a ! 388: * value passed from the calling program. Once we hit ! 389: * the max number of records that can be held by a screen, ! 390: * terminate the read and set a flag to show that we did ! 391: * not hit EOF. If we did hit EOF, terminate the loop ! 392: * and set a flag to show that we did hit EOF. ! 393: */ ! 394: ! 395: /* start reading from a specified point in the file */ ! 396: fseek(infp, (sizeof (struct entry) * (screen_num * 100)), 0l); ! 397: ! 398: limit = 0; ! 399: while((fread(&record, sizeof(struct entry),1, infp)) != 0) ! 400: { ! 401: strcpy(filenames[limit], record.filename); ! 402: place[limit] = limit; ! 403: limit++; ! 404: if (limit == 100) ! 405: break; ! 406: } ! 407: ! 408: /* if x made it to 100, then we did NOT hit EOF */ ! 409: ! 410: if ( (limit == 100) && (fread (&record,sizeof(struct entry),1,infp)) != 0) ! 411: EOF_FLAG = 0; ! 412: else ! 413: EOF_FLAG = -1; ! 414: ! 415: fclose(infp); ! 416: return (EOF_FLAG); ! 417: ! 418: } ! 419: ! 420: ! 421: ! 422: /* ! 423: * writewin(); ! 424: * this routine does the actual work of writing filenames to a window ! 425: */ ! 426: ! 427: void write_win(win1) ! 428: ! 429: WINDOW *win1; ! 430: ! 431: { ! 432: ! 433: int r,c; /* these are our rows and columns */ ! 434: int counter = 0; /* this counts the number of files written */ ! 435: ! 436: ! 437: ! 438: /* clear the window */ ! 439: wclear(win1); ! 440: ! 441: /* the following loop will write the filenames to the window. ! 442: * 15 characters per screen field are allowed, since a filename ! 443: * can only be 14 chars in length. This will leave at least one ! 444: * space between filenames. ! 445: */ ! 446: ! 447: for (r = 0; r < 20; r++) ! 448: { ! 449: ! 450: /* if we've run out of files, terminate loop */ ! 451: ! 452: if (counter == limit) ! 453: break; ! 454: ! 455: /* increment column by 15 positions. This ! 456: * will cause the filenames to line up ! 457: * on the window. ! 458: */ ! 459: ! 460: for (c = 1; c < 75; c+= 15) ! 461: { ! 462: wmove(win1, r, c); ! 463: waddstr(win1, filenames[counter]); ! 464: ! 465: /* increment counter. When it equals the number of ! 466: * records, passed as 'limit', the loop should ! 467: * terminate. ! 468: */ ! 469: ! 470: counter ++; ! 471: if (counter == limit) ! 472: break; ! 473: } ! 474: } ! 475: ! 476: ! 477: } ! 478: ! 479: /* this function will draw a template for the selected record */ ! 480: ! 481: void display_form(win2) ! 482: WINDOW *win2; ! 483: ! 484: ! 485: { ! 486: int x; ! 487: ! 488: clear(); ! 489: wclear(win2); ! 490: ! 491: /* print field labels */ ! 492: ! 493: wmove (win2, NAMELOCATE ); ! 494: waddstr (win2,"Filename:"); ! 495: ! 496: wmove (win2, DESCLOCATE); ! 497: waddstr(win2,"Description:"); ! 498: ! 499: wmove(win2, DATELOCATE ); ! 500: waddstr(win2,"Date added/modified:"); ! 501: ! 502: wmove(win2, SIZELOCATE); ! 503: waddstr(win2,"File size:"); ! 504: ! 505: if(open_mode != 'd') ! 506: { ! 507: wmove(win2, PARTLOCATE);; ! 508: waddstr(win2,"Number of parts to download:"); ! 509: } ! 510: ! 511: wmove(win2, REQLOCATE ); ! 512: waddstr(win2,"Requires these other files:"); ! 513: ! 514: wmove(win2, NOTELOCATE); ! 515: waddstr(win2,"Other notes:"); ! 516: ! 517: if(open_mode != 'd') ! 518: { ! 519: wmove(win2, PATHLOCATE); ! 520: waddstr(win2, "Path to download file... Must give complete path including filename."); ! 521: wmove (win2, PATHLOCATE2); ! 522: waddstr(win2,"If a file is split into several parts, enter the first filename part"); ! 523: wmove (win2, PATHLOCATE3); ! 524: waddstr(win2,"leaving the LAST character off of the filename:"); ! 525: } ! 526: ! 527: ! 528: /* highlite available fields */ ! 529: ! 530: wstandout(win2); ! 531: ! 532: wmove (win2, NAMEHI); ! 533: waddstr(win2," "); ! 534: ! 535: wmove (win2,DESCHI); ! 536: for (x=1;x<79;x++) ! 537: waddstr(win2," "); ! 538: ! 539: wmove(win2, DATEHI); ! 540: waddstr(win2," "); ! 541: ! 542: wmove(win2, SIZEHI); ! 543: waddstr(win2," "); ! 544: ! 545: if (open_mode != 'd') ! 546: { ! 547: wmove(win2,PARTHI); ! 548: waddstr(win2," "); ! 549: } ! 550: ! 551: wmove (win2,REQHI); ! 552: for (x=1;x<61;x++) ! 553: waddstr(win2," "); ! 554: ! 555: wmove (win2,NOTEHI); ! 556: for (x=1;x<69;x++) ! 557: waddstr(win2," "); ! 558: ! 559: if(open_mode != 'd') ! 560: { ! 561: wmove (win2, PATHHI); ! 562: waddstr(win2,PATHNAME); ! 563: for (x=23;x<61;x++) ! 564: waddstr(win2," "); ! 565: } ! 566: ! 567: wstandend(win2); ! 568: refresh(); ! 569: wrefresh(win2); ! 570: ! 571: ! 572: ! 573: } ! 574: ! 575: /* following function prints the menu at the bottom of stdscr */ ! 576: ! 577: void menu() ! 578: ! 579: { ! 580: /* print a menu of options to stdscr. They will appear at the bottom of ! 581: * the screen with the first letter highlited as an indication to ! 582: * the user that pressing the highlited key will result in the indicated ! 583: * action. ! 584: */ ! 585: ! 586: if(open_mode =='r') ! 587: { ! 588: move (21,0); ! 589: printw("Select file to delete"); ! 590: refresh(); ! 591: } ! 592: ! 593: if(open_mode == 'a') ! 594: { ! 595: move (21,0); ! 596: printw("select file that will FOLLOW"); ! 597: move (22,0); ! 598: printw("the file to be added."); ! 599: refresh(); ! 600: } ! 601: ! 602: if(open_mode == 'd') ! 603: { ! 604: move (21,0); ! 605: printw("Select file to download."); ! 606: refresh(); ! 607: } ! 608: ! 609: move(21, 50); ! 610: standout(); ! 611: printw("Options:"); ! 612: move(22,46); ! 613: printw("n"); ! 614: move(23,46); ! 615: printw("p"); ! 616: move(22,60); ! 617: printw("q"); ! 618: move(23,60); ! 619: printw("s"); ! 620: standend(); ! 621: move(22,47); ! 622: addstr("ext page"); ! 623: move(23,47); ! 624: addstr("rev. page"); ! 625: move(22,61); ! 626: addstr("uit"); ! 627: move(23,61); ! 628: addstr("elect file"); ! 629: ! 630: ! 631: } ! 632: ! 633: ! 634: /* this function will open the file and read the appropriate record, ! 635: * then display it on the window in the approp. positions. ! 636: */ ! 637: ! 638: void display_record (win2, row, col, screen_num) ! 639: WINDOW *win2; ! 640: int row, col, screen_num; ! 641: ! 642: { ! 643: WINDOW *win3; ! 644: struct entry record; ! 645: char choice; ! 646: FILE *infp; ! 647: int x; ! 648: ! 649: if ((infp = fopen(workfile,"r")) == NULL) ! 650: { ! 651: printf("\007ERROR opening file for input!\n"); ! 652: exit(1); ! 653: } ! 654: ! 655: fseek(infp,REC_FORMULA, 0l); ! 656: fread(&record, sizeof (struct entry),1,infp); ! 657: fclose (infp); ! 658: ! 659: wstandout(win2); ! 660: ! 661: wmove(win2,NAMEHI); ! 662: waddstr(win2,record.filename); ! 663: ! 664: wmove(win2,DESCHI); ! 665: waddstr(win2,record.description); ! 666: ! 667: wmove(win2,DATEHI); ! 668: wprintw(win2,"%.6s",record.date); ! 669: ! 670: wmove(win2,SIZEHI); ! 671: waddstr(win2,record.filesize); ! 672: ! 673: if(open_mode != 'd') ! 674: { ! 675: wmove(win2,PARTHI); ! 676: wprintw(win2,"%.2d",record.noparts); ! 677: } ! 678: ! 679: wmove(win2,REQHI); ! 680: waddstr(win2,record.requires); ! 681: ! 682: wmove(win2,NOTEHI); ! 683: waddstr(win2,record.notes); ! 684: ! 685: if(open_mode != 'd') ! 686: { ! 687: wmove(win2,PATHHI); ! 688: waddstr(win2,record.pathname); ! 689: } ! 690: ! 691: wrefresh(win2); ! 692: wstandend(win2); ! 693: ! 694: ! 695: /* allocate another window as a message area */ ! 696: ! 697: if ( (win3=newwin(2,40,20,0)) == NULL) ! 698: { ! 699: printf("Memory allocation for win3 failed!\n"); ! 700: exit(1); ! 701: } ! 702: ! 703: /* the following tests for 'd' for delete from command line. If the user ! 704: * used a 'd' on the command line, make sure that he/she really wants to ! 705: * delete the record, then call the del_reocrd function. ! 706: */ ! 707: if(open_mode == 'r') ! 708: { ! 709: wmove (win3,0,0); ! 710: waddstr(win3,"Do you wish to delete this record?"); ! 711: wmove(win3,1,0); ! 712: waddstr(win3, "[y] yes; any other key to abort."); ! 713: wrefresh(win3); ! 714: ! 715: choice = '\0'; ! 716: while (choice == '\0') ! 717: choice = wgetch(win3); ! 718: ! 719: if ((choice == 'y') || (choice == 'Y')) ! 720: { ! 721: wclear(win3); ! 722: wmove(win3,0,0); ! 723: waddstr(win3,"working... please wait"); ! 724: wrefresh(win3); ! 725: del_rec(win3, row, col, screen_num); ! 726: } ! 727: ! 728: wclear(win3); ! 729: wmove(win3,0,0); ! 730: waddstr(win3,"Press RETURN to continue..."); ! 731: wrefresh(win3); ! 732: while(13 != wgetch(win3)) ! 733: ; ! 734: wclear(win3); ! 735: wrefresh(win3); ! 736: delwin(win3); ! 737: } ! 738: ! 739: /* we are in download mode, so prompt for the next data screen */ ! 740: else ! 741: { ! 742: wclear(win3); ! 743: wmove(win3,0,0); ! 744: waddstr(win3,"Press <RETURN> for next screen."); ! 745: wrefresh(win3); ! 746: while(13 != wgetch(win3)) ! 747: ; ! 748: wclear(win2); ! 749: wmove(win2,1,0); ! 750: waddstr(win2,"Size of file is: "); ! 751: wmove(win2,1,40); ! 752: waddstr(win2,"Number of parts to download: "); ! 753: wstandout(win2); ! 754: wmove(win2,1,18); ! 755: waddstr(win2,record.filesize); ! 756: wmove(win2,1,69); ! 757: record.noparts = (record.noparts == 0) ? 1 : record.noparts; ! 758: wprintw(win2,"%d",record.noparts); ! 759: wstandend(win2); ! 760: wmove(win2,3,5); ! 761: wprintw(win2,"The following commands will be needed to download "); ! 762: wstandout(win2); ! 763: waddstr(win2,record.filename); ! 764: wstandend(win2); ! 765: ! 766: /* if there is more than one part to download, call a function to generate ! 767: * the multiple uucp requests necessary to grab each piece from mwcbbs. ! 768: */ ! 769: ! 770: if (record.noparts >1) ! 771: { ! 772: build_uucp(record); ! 773: for (x=0;x<record.noparts;x++) ! 774: { ! 775: ! 776: /* limit ourselves to 10 displayed commands */ ! 777: if (x==10) ! 778: { ! 779: wmove(win2,16,0); ! 780: wprintw(win2,"There are %d more parts to download which do not appear on ths screen.", (record.noparts - x)); ! 781: break; ! 782: } ! 783: ! 784: wmove(win2,5+x,0); ! 785: waddstr(win2,getfiles[x]); ! 786: } ! 787: } ! 788: else ! 789: { ! 790: strcpy(getfiles[0],HOST); ! 791: strcat(getfiles[0],record.pathname); ! 792: strcat(getfiles[0],RECEIVER); ! 793: wmove(win2,5,0); ! 794: waddstr(win2,getfiles); ! 795: wrefresh(win2); ! 796: } ! 797: ! 798: wclear(win3); ! 799: wmove(win3,0,0); ! 800: waddstr(win3,"Do you wish to download this file?"); ! 801: wmove(win3,1,0); ! 802: waddstr(win3,"[y] yes or any other key to abort."); ! 803: wrefresh(win2); ! 804: wrefresh(win3); ! 805: choice = '\0'; ! 806: while(choice == '\0') ! 807: choice = wgetch(win3); ! 808: ! 809: if(choice == 'y' || choice == 'Y') ! 810: { ! 811: wclear(win3); ! 812: wmove(win3,0,0); ! 813: waddstr(win3,"Processing requests..."); ! 814: wrefresh(win3); ! 815: for(x = 0; x < record.noparts; x++) ! 816: system(getfiles[x]); ! 817: wclear(win3); ! 818: wmove(win3,0,0); ! 819: waddstr(win3,"Press <RETURN> to continue."); ! 820: wrefresh(win3); ! 821: while(13 != wgetch(win3)) ! 822: ; ! 823: } ! 824: } ! 825: } ! 826: ! 827: ! 828: void del_rec(win3,row,col,screen_num,rec_add) ! 829: WINDOW *win3; ! 830: int row,col,screen_num; ! 831: struct entry *rec_add; ! 832: ! 833: { ! 834: int x; ! 835: struct entry record; ! 836: FILE *infp,*outfp; ! 837: int rec_mark = POS_FORMULA; ! 838: ! 839: if ( (infp=fopen(workfile,"r"))==NULL) ! 840: { ! 841: printf("Error opening file %s for input!\n",workfile); ! 842: exit(1); ! 843: } ! 844: ! 845: /* delete any previous temporary file that may be here */ ! 846: ! 847: if (unlink(TEMPFILE)==-1); ! 848: ! 849: if ( (outfp=fopen(TEMPFILE,"a"))==NULL) ! 850: { ! 851: printf("Error opening \"/tmp/mwcbbs.tmp\" for output!\n"); ! 852: exit(1); ! 853: } ! 854: ! 855: ! 856: /* we will now read each record until we hit the record number ! 857: * calculated by rec_mark. to delete, we will simply exit the ! 858: * loop when we hit the correct record, skip the record with a ! 859: * read, then follow that with another read/write loop to finish ! 860: * off the file. ! 861: */ ! 862: ! 863: ! 864: for(x=0;x<rec_mark;x++) ! 865: { ! 866: fread(&record, sizeof(struct entry),1,infp); ! 867: wmove(win3,1,0); ! 868: wprintw(win3,"Reading:"); ! 869: wrefresh(win3); ! 870: fwrite(&record, sizeof(struct entry),1,outfp); ! 871: wmove(win3,1,0); ! 872: wprintw(win3,"Writing:"); ! 873: wrefresh(win3); ! 874: } ! 875: ! 876: /* this will delete the record by using a dummy record to skip it */ ! 877: ! 878: if(open_mode == 'r') ! 879: fread(&record, sizeof(struct entry),1,infp); ! 880: ! 881: ! 882: /* this will write in a new record, if invoked in 'add' mode */ ! 883: if(open_mode == 'a') ! 884: fwrite(&rec_add, sizeof(struct entry),1,outfp); ! 885: ! 886: /* this will finish off the file. */ ! 887: ! 888: while((fread(&record, sizeof(struct entry),1,infp)) != 0) ! 889: { ! 890: ! 891: wmove(win3,1,0); ! 892: wprintw(win3,"Reading"); ! 893: wrefresh(win3); ! 894: fwrite(&record, sizeof(struct entry),1,outfp); ! 895: wmove(win3,1,0); ! 896: wprintw(win3,"Writing:"); ! 897: wrefresh(win3); ! 898: } ! 899: ! 900: /* close the files and move around as appropriate (delete the old then ! 901: * move the new to old ! 902: */ ! 903: ! 904: fclose(infp); ! 905: fclose(outfp); ! 906: if(unlink(workfile) == -1) ! 907: { ! 908: endwin(); ! 909: printf("Could not remove old file!\n"); ! 910: printf("Updated file could be found as %s\n",TEMPFILE); ! 911: exit(1); ! 912: } ! 913: ! 914: if( link(TEMPFILE,workfile) == -1) ! 915: { ! 916: endwin(); ! 917: printf("Could not link new file!\n"); ! 918: exit(1); ! 919: } ! 920: ! 921: if( unlink(TEMPFILE) == -1) ! 922: { ! 923: endwin(); ! 924: printf("Could not remove temporary file!\n"); ! 925: exit(1); ! 926: } ! 927: ! 928: } ! 929: ! 930: /* this function will get the input and write it to a file */ ! 931: ! 932: void add_rec(win2, row, col, screen_num) ! 933: WINDOW *win2; ! 934: ! 935: { ! 936: struct entry new_record; ! 937: ! 938: FILE *infp; ! 939: WINDOW *win3; ! 940: int x; ! 941: char choice; ! 942: ! 943: ! 944: wrefresh(win2); ! 945: ! 946: if( (win3=newwin(4,79,20,0)) == NULL ) ! 947: { ! 948: wclear(win2); ! 949: wmove(win2,0,0); ! 950: wstandout(win2); ! 951: waddstr(win2,"\007Error allocating memory for win3. Press <RETURN>"); ! 952: wrefresh(win2); ! 953: while('\n' != getch()) ! 954: ; ! 955: exit(1); ! 956: } ! 957: ! 958: wclear(win3); ! 959: wmove(win3,1,1); ! 960: waddstr(win3,"Enter filename or <RETURN> to exit."); ! 961: wrefresh(win3); ! 962: getstring(win2, NAMEHI); ! 963: strcpy(new_record.filename, workstring); ! 964: if(strlen(new_record.filename) == 0) ! 965: return; ! 966: ! 967: for(x=strlen(workstring);x < sizeof (new_record.filename) ; x++) ! 968: new_record.filename[x] = '\0'; ! 969: ! 970: ! 971: wclear(win3); ! 972: wmove(win3,1,1); ! 973: waddstr(win3,"Describe the uses of this package"); ! 974: wrefresh(win3); ! 975: ! 976: getstring(win2, DESCHI); ! 977: strcpy(new_record.description, workstring); ! 978: ! 979: for(x=strlen(workstring);x < sizeof (new_record.description) ; x++) ! 980: new_record.description[x] = '\0'; ! 981: ! 982: ! 983: ! 984: wclear(win3); ! 985: wmove(win3,1,1); ! 986: waddstr(win3,"Enter the date that the file was added or last modified"); ! 987: wmove(win3,2,1); ! 988: waddstr(win3,"Enter no more than 6 characters"); ! 989: wrefresh(win3); ! 990: ! 991: getstring(win2,DATEHI); ! 992: strcpy(new_record.date, workstring); ! 993: for(x=strlen(workstring);x < sizeof (new_record.date) ; x++) ! 994: new_record.date[x] = '\0'; ! 995: ! 996: wclear(win3); ! 997: wmove(win3,1,1); ! 998: waddstr(win3,"Enter the file size in number of bytes"); ! 999: wrefresh(win3); ! 1000: getstring(win2, SIZEHI); ! 1001: strcpy(new_record.filesize, workstring); ! 1002: for(x=strlen(workstring);x < sizeof (new_record.filesize) ; x++) ! 1003: new_record.filesize[x] = '\0'; ! 1004: ! 1005: ! 1006: wclear(win3); ! 1007: wmove(win3,3,1); ! 1008: waddstr(win3,"Enter the number of parts that this file is divided into"); ! 1009: wrefresh(win3); ! 1010: getstring(win2, PARTHI); ! 1011: new_record.noparts = atoi(workstring); ! 1012: ! 1013: ! 1014: /* if the number of parts is 0 (not a split file), then we can ! 1015: * cat the filename on to the end of the pathname. We can later ! 1016: * test the length of the pathname to determine whether or not ! 1017: * to ask for a pathname, as would be required for a split file. ! 1018: */ ! 1019: ! 1020: ! 1021: if(new_record.noparts ==0) ! 1022: { ! 1023: strcpy(new_record.pathname, PATHNAME); ! 1024: strcat(new_record.pathname, new_record.filename); ! 1025: wmove(win2,PATHHI); ! 1026: wstandout(win2); ! 1027: waddstr(win2, new_record.pathname); ! 1028: wstandend(win2); ! 1029: wrefresh(win2); ! 1030: } ! 1031: ! 1032: ! 1033: wclear(win3); ! 1034: wmove(win3,3,1); ! 1035: waddstr(win3,"Enter the names of any support files required"); ! 1036: wrefresh(win3); ! 1037: getstring(win2, REQHI); ! 1038: ! 1039: if(strlen(workstring) == 0 ) ! 1040: { ! 1041: wmove(win2, REQHI); ! 1042: wstandout(win2); ! 1043: waddstr(win2,"none"); ! 1044: wstandend(win2); ! 1045: wrefresh(win2); ! 1046: strcpy(new_record.requires, "none"); ! 1047: } ! 1048: else ! 1049: strcpy(new_record.requires, workstring); ! 1050: ! 1051: for(x=strlen(new_record.requires);x < sizeof (new_record.requires) ; x++) ! 1052: new_record.requires[x] = '\0'; ! 1053: ! 1054: wclear(win3); ! 1055: wmove(win3,3,1); ! 1056: waddstr(win3,"Enter any relevant notes about this file"); ! 1057: wrefresh(win3); ! 1058: getstring(win2, NOTEHI); ! 1059: if(strlen(workstring) == 0) ! 1060: { ! 1061: wmove(win2,NOTEHI); ! 1062: wstandout(win2); ! 1063: waddstr(win2,"none"); ! 1064: wstandend(win2); ! 1065: wrefresh(win2); ! 1066: strcpy(new_record.notes, "none"); ! 1067: } ! 1068: ! 1069: else ! 1070: strcpy(new_record.notes, workstring); ! 1071: for(x=strlen(new_record.notes);x < sizeof (new_record.notes) ; x++) ! 1072: new_record.notes[x] = '\0'; ! 1073: ! 1074: /* if there is more than one part to download, or number of ! 1075: * parts is not zero, we need to complete the pathlist. ! 1076: */ ! 1077: ! 1078: if(new_record.noparts != 0) ! 1079: { ! 1080: wclear(win3); ! 1081: wmove(win3,3,1); ! 1082: waddstr(win3,"Complete the pathlist to this file."); ! 1083: wrefresh(win3); ! 1084: wmove(win2,PATHHI); ! 1085: wstandout(win2); ! 1086: waddstr(win2, PATHNAME); ! 1087: wstandend(win2); ! 1088: wrefresh(win2); ! 1089: getstring(win2, PATHHI2); ! 1090: strcpy(new_record.pathname, PATHNAME); ! 1091: strcat(new_record.pathname, workstring); ! 1092: } ! 1093: for(x=strlen(new_record.pathname);x < sizeof (new_record.pathname) ; x++) ! 1094: new_record.pathname[x] = '\0'; ! 1095: ! 1096: ! 1097: wclear(win3); ! 1098: wmove(win3,0,0); ! 1099: waddstr(win3,"Do you wish to write the record?"); ! 1100: wmove(win3,1,0); ! 1101: waddstr(win3,"[y]es or any other to abort."); ! 1102: wrefresh(win3); ! 1103: choice ='\0'; ! 1104: while(choice == '\0') ! 1105: choice = wgetch(win3); ! 1106: ! 1107: if(choice == 'y' || choice == 'Y') ! 1108: { ! 1109: wclear(win3); ! 1110: wmove(win3,0,0); ! 1111: waddstr(win3,"Updating..."); ! 1112: wrefresh(win3); ! 1113: del_rec(win3,row,col,screen_num, new_record); ! 1114: } ! 1115: ! 1116: delwin(win3); ! 1117: ! 1118: } ! 1119: ! 1120: ! 1121: /* this function will get a string and print to the approp field ! 1122: * on win2. This is to prevent people from entering too many characters. ! 1123: */ ! 1124: ! 1125: void getstring (win2, row, col) ! 1126: ! 1127: WINDOW *win2; ! 1128: int row, col; ! 1129: ! 1130: { ! 1131: ! 1132: ! 1133: noraw(); ! 1134: echo(); ! 1135: wmove(win2,row,col); ! 1136: wrefresh(win2); ! 1137: wgetstr(win2,workstring); ! 1138: wstandout(win2); ! 1139: wmove(win2,row,col); ! 1140: wprintw(win2,"%s",workstring); ! 1141: wstandend(win2); ! 1142: wrefresh(win2); ! 1143: noecho(); ! 1144: raw(); ! 1145: ! 1146: ! 1147: ! 1148: } ! 1149: /* this function will take the pathname and append the necessary ! 1150: * character(s) to generate the multiple requests necessary to ! 1151: * download multipart files. ! 1152: */ ! 1153: ! 1154: void build_uucp(record) ! 1155: struct entry *record; ! 1156: ! 1157: { ! 1158: int x,y; ! 1159: ! 1160: y = strlen(record.pathname); ! 1161: ! 1162: for(x=0;x< record.noparts;x++) ! 1163: { ! 1164: strcpy(getfiles[x],HOST); ! 1165: record.pathname[y] = 97 + x; ! 1166: strcat(getfiles[x],record.pathname); ! 1167: strcat(getfiles[x],RECEIVER); ! 1168: } ! 1169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.