home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  17.5 KB  |  394 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31. /**************************************************************************/
  32. /* XBBS Files-mode module                                                 */
  33. /**************************************************************************/
  34.  
  35. #include "msg.h"
  36. #include "xext.h"
  37.  
  38. void xfile (char *fname,char statnum) {
  39.  
  40.    char filename[133];
  41.    char string[256];
  42.    char tempstring[49];
  43.    struct ffblk f;
  44.    static char comstring[26]="";
  45.    int comval=0;
  46.    char command=0;
  47.    struct _fboard *fb;
  48.    struct _fboard ff;
  49.    struct _mboard mb;
  50.    char *p;
  51.    word x;
  52.    char listing;
  53.    struct dfree drivefree;
  54.    char lastcommand=0,highcommand,wascommand=0;
  55.    char *divie[28];
  56.    char prettystring[256];
  57.  
  58.       if(!fname || !*fname) strcpy(filename,say_prompt(446));
  59.       else strcpy(filename,fname);
  60.       if(findfirst(filename,&f,0)) return;
  61.  
  62.       statnum=min(statnum,9);
  63.       memcpy(&mb,&mboard,sizeof(struct _mboard));
  64.       memcpy(&ff,&fboard,sizeof(struct _fboard));
  65.       strcpy(string,say_prompt(486));
  66.       if(!find_msgarea(string,fboard.name,0)) {
  67.           memcpy(&mboard,&mb,sizeof(struct _mboard));
  68.       }
  69.       if(!*comstring) {
  70.         strncpy(comstring,say_prompt(206),26);
  71.         say_prompt(500);
  72.       }
  73.       strncpy(prettystring,say_prompt(583),256);
  74.       prettystring[255]=0;
  75.       divie[0]=strtok(prettystring," ");
  76.       if(divie[0]) {
  77.           x=1;
  78.           while((divie[x]=strtok(0," ")) && x<26) {
  79.  
  80.               char *p;
  81.  
  82.               while(p=strchr(divie[x],'_')) *p=' ';
  83.               x++;
  84.           }
  85.           highcommand=(char)x-1;
  86.       }
  87.  
  88.   ReList:
  89.       command=0;
  90.       while(1) {
  91. FancyReDo:
  92.           comval=0;
  93.           gprintf(0,say_prompt(103),fboard.name);   /* Current area */
  94.           sprintf(string,"%sFILES.BBS",fboard.dpath);
  95.           if(findfirst(string,&f,0)) say_prompt(106); /* No files.bbs */
  96.           if ((user.ansimenus || !user.graphics) || !divie[0]) {
  97.               say_prompt(452); /* Menu */
  98.               helpnum=590;
  99.               command=*genin(1,0,1,1,ALLL);
  100.           }
  101.           else {
  102.                 say_prompt(584);
  103. FancyRepeat:
  104.                 printm(divie[lastcommand]);
  105. FancyNull:
  106.                 helpnum=0;
  107.                 command=*genin(1,0,1,1,HYPER);
  108.                 wascommand=lastcommand;
  109.                 switch((int)command) {
  110.                     case 0:   command=toupper(*divie[lastcommand]);
  111.                               backup(divie[lastcommand]);
  112.                               gprintf(0,"%c",*divie[lastcommand]);
  113.                               goto DirectEntry;
  114.                     case 1:
  115.                     case 4:
  116.                     case '4':
  117.                     case '8': if(lastcommand==0) lastcommand=highcommand;
  118.                               else lastcommand--;
  119.                               break;
  120.                     case 5:
  121.                     case 2:
  122.                     case '6':
  123.                     case '2': if(lastcommand==highcommand) lastcommand=0;
  124.                               else lastcommand++;
  125.                               break;
  126.                     case 11:
  127.                     case 27:  printm("\n");
  128.                               say_prompt(452);
  129.                               printm("\n");
  130.                               goto FancyReDo;
  131.                     case 3:   printm("\n");
  132.                               goto FancyReDo;
  133.                     default:  for(x=0;x<(int)(highcommand+1);x++) {
  134.                                 if(toupper(command)==toupper(*divie[x])) {
  135.                                     lastcommand=(char)x;
  136.                                     backup(divie[wascommand]);
  137.                                     gprintf(0,"%c",*divie[lastcommand]);
  138.                                     goto DirectEntry;
  139.                                 }
  140.                               }
  141.                               backup(divie[wascommand]);
  142.                               gprintf(0,"%c",toupper(command));
  143.                               goto DirectEntry;
  144.                 }
  145.                 backup(divie[wascommand]);
  146.                 goto FancyRepeat;
  147.           }
  148. DirectEntry:
  149.           for(x=0;x<27;x++) {
  150.                 if(!comstring[x])break;
  151.                 if(command==comstring[x]) {
  152.                     command=(char)x+1;
  153.                     break;
  154.                 }
  155.           }
  156.           helpnum=0;
  157.           switch ((int)command) {
  158.               case '*': readfile("FILEXTRA.XBS",0,0,1);
  159.                         break;
  160.               case 1:   memcpy(&mboard,&mb,sizeof(struct _mboard));
  161.                         memcpy(&fboard,&ff,sizeof(struct _fboard));
  162.                         return;
  163.               case 2:   if(filesbbs("FILES.BBS",0|8,saydate(&user.lastdate),NULL)==3) goto DownLoad;
  164.                         break;
  165.               case 3:   if(filesbbs("FILES.BBS",2|8,saydate(&user.lastdate),NULL)==3) goto DownLoad;
  166.                         break;
  167.               case 4:   say_prompt(482);
  168.                         helpnum=595;
  169.                         strcpy(tempstring,genin(8,0,1,0,DATE));
  170.                         helpnum=0;
  171.                         if(strlen(tempstring)<8) {
  172.                             strcpy(tempstring,saydate(&user.lastdate));
  173.                             say_prompt(483);
  174.                         }
  175.                         else {
  176.                             printm("\n");
  177.                             sprintf(string,"%2.2s/%2.2s/%4.4s",tempstring,&tempstring[2],&tempstring[4]);
  178.                             strcpy(tempstring,string);
  179.                         }
  180.                         if(filesbbs("FILES.BBS",2|8,tempstring,NULL)==3) goto DownLoad;
  181.                         break;
  182.               case 5:
  183.               case 6:
  184.               case 7:   fb=(struct _fboard*)mmalloc(sizeof(struct _fboard));
  185.                         if(fb==NULL) {
  186.                             say_prompt(459);
  187.                             break;
  188.                         }
  189.                         memcpy(fb,&fboard,sizeof(struct _fboard));
  190.                         if(command==7) {
  191.                             say_prompt(484);
  192.                             helpnum=596;
  193.                             strcpy(tempstring,genin(8,0,1,0,FLE));
  194.                             helpnum=0;
  195.                             if(p=strchr(tempstring,'.')) *p=0;
  196.                         }
  197.                         else if(command==6) {
  198.                             say_prompt(485);
  199.                             helpnum=597;
  200.                             strcpy(tempstring,genin(25,0,1,0,ALLL));
  201.                             helpnum=0;
  202.                         }
  203.                         if(command!=5)if(!*tempstring) goto SearchDone;
  204.                         say_prompt(498);
  205.                         next_filearea(NULL,0);
  206.                         level=0;
  207.                         while((listing=next_filearea(say_prompt(446),user.stat[statnum]))) {
  208.                             if(level) {
  209.                                 level=0;
  210.                                 break;
  211.                             }
  212.                             if(!stricmp(fboard.dpath,"NUL") || !stricmp(fboard.dpath,"NUL\\")) {
  213.                                 continue;
  214.                             }
  215.                             if(command==7) {
  216.                                 sprintf(string,"%s%s.*",fboard.dpath,tempstring);
  217.                                 if(!findfirst(string,&f,0)) {
  218.                                     gprintf(0,say_prompt(497),fboard.name);
  219.                                     level=filesbbs("FILES.BBS",4|8,saydate(&user.lastdate),tempstring);
  220.                                     if(level!=0 && level!=2 && level!=4) break;
  221.                                     printm("\n");
  222.                                     check_dls(string,&x,1);
  223.                                     say_prompt(496);
  224.                                 }
  225.                             }
  226.                             else {
  227.                                 if(command==6) {
  228.                                     gprintf(0,say_prompt(495),fboard.name);
  229.                                     level=filesbbs("FILES.BBS",4|8,saydate(&user.lastdate),tempstring);
  230.                                     if(level!=0 && level!=2 && level!=4) break;
  231.                                 }
  232.                                 else {
  233.                                     gprintf(0,say_prompt(495),fboard.name);
  234.                                     level=filesbbs("FILES.BBS",2|8,saydate(&user.lastdate),NULL);
  235.                                     if(level!=0 && level!=2 && level!=4)break;
  236.                                 }
  237.                             }
  238.                         }
  239.                         if(level==0 || level==2 || level==4 || !listing) say_prompt(494);
  240.                         else say_prompt(460);
  241. SearchDone:
  242.                         if(fb) {
  243.                             if(level!=3) memcpy(&fboard,fb,sizeof(struct _fboard));
  244.                             ffree(fb);
  245.                             fb=NULL;
  246.                         }
  247.                         if(level==3) {
  248.                             printm("\n");
  249.                             goto DownLoad;
  250.                         }
  251.                         break;
  252.               case 8:   rawdir(fboard.dpath,0);
  253.                         break;
  254.               case 9:   goto Filelistings;
  255.               case 10:
  256. DownLoad:
  257.                         say_prompt(464);
  258.                         if(isleech(fboard.leechpercent)) {
  259.                             say_prompt(598);
  260.                             break;
  261.                         }
  262.                         strcpy(string,filename);
  263.                         x=(word)*genin(1,0,1,1,ALPHA);
  264.                         printm("\n");
  265.                         if(x!=(word)'A') askdl("NULL",statnum,string,0);
  266.                         else askdl("NULL",0,"NULL",0);
  267.                         break;
  268.               case 11:  comval=1;
  269.                         say_prompt(473);
  270.                         gprintf(0,say_prompt(490),fboard.name);
  271.                         say_prompt(489);
  272.                         if(*genin(1,0,1,1,YESNO)=='Y') goto Filelistings;
  273.                         printm("\n");
  274. ReUp:
  275.                         if(fboard.upath==NULL || !*fboard.upath || !strcmp(fboard.upath,"NUL") ||
  276.                           !strcmp(fboard.upath,"NUL\\")) {
  277.                               say_prompt(451);
  278.                               break;
  279.                         }
  280.                         printm("\n");
  281.                         getdfree((toupper(*fboard.upath)-'@'),&drivefree);
  282.                         gprintf(0,"%lu bytes free\n",(long)drivefree.df_avail*(drivefree.df_bsec*drivefree.df_sclus));
  283.                         if ((long)drivefree.df_avail*(drivefree.df_bsec*drivefree.df_sclus)<atol(say_prompt(487))) {
  284.                             say_prompt(488);
  285.                             break;
  286.                         }
  287.                         upload(NULL,0);
  288.                         break;
  289.               case 12:  say_prompt(109);
  290.                         break;
  291.               case 0:   break;
  292.               case 13:  say_prompt(6);
  293.                         strcpy(tempstring,genin(13,0,1,0,FLE));
  294.                         printm("\n");
  295.                         if(!*tempstring) break;
  296.                         sprintf(string,"%s%s",fboard.dpath,tempstring);
  297.                         if(!findfirst(string,&f,0)) {
  298.  
  299.                             char dostring[256];
  300.                             char *p;
  301.  
  302.                             p=strrchr(string,'.');
  303.                             if(p) p++;
  304.                             if(!p || !*p) {
  305.                                 readtext(string);
  306.                                 break;
  307.                             }
  308.                             sprintf(dostring,"%sARCHIVERS.XBS",conf.homepath);
  309.                             if(!findfirst(dostring,&f,0)) {
  310.  
  311.                                 int handle;
  312.                                 char ok=0;
  313.  
  314.                                 handle=oopen(dostring,O_RDONLY | O_BINARY | O_DENYNONE);
  315.                                 if(handle!=-1) {
  316.                                     while(!eof(handle)) {
  317.                                         if(!fgetsx(dostring,145,handle)) break;
  318.                                         if(!strnicmp(dostring,p,3)) {
  319.                                             stripcr(dostring);
  320.                                             lstrip(rstrip(dostring));
  321.                                             ok=1;
  322.                                             break;
  323.                                         }
  324.                                     }
  325.                                     cclose(handle);
  326.                                     if(!ok) {
  327.                                         readtext(string);
  328.                                         break;
  329.                                     }
  330.                                     else {
  331.  
  332.                                         FILE *fptr;
  333.                                         char tmpnm[133];
  334.  
  335.                                         strcpy(tmpnm,say_prompt(9));
  336.                                         if(!(fptr=freopen(tmpnm,"w",stdout))) {
  337.                                             break;
  338.                                         }
  339.                                         strcat(dostring," ");
  340.                                         strcat(dostring,string);
  341.                                         spawnit(&dostring[4],0,0);
  342.                                         fclose(fptr);
  343.                                         freopen("CON","w",stdout);
  344.                                         setbuf(stdout,NULL);
  345.                                         readtext(tmpnm);
  346.                                         break;
  347.                                     }
  348.                                 }
  349.                             }
  350.                         }
  351.                         else {
  352.                             say_prompt(7);
  353.                         }
  354.                         break;
  355.               default:  sprintf(string,"XFILE%03hu.XBS",command);
  356.                         readfile(string,1,1,1);
  357.                         printm("\n");
  358.                         break;
  359.           }
  360.       }
  361.  
  362. Filelistings:
  363.       gprintf(0,say_prompt(490),fboard.name);
  364.       say_prompt(449);  /* Change current file area */
  365.       helpnum=592;
  366.       strcpy(tempstring,genin(48,0,1,0,ALLL));
  367.       helpnum=0;
  368.       printm("\n");
  369.       if(*tempstring=='?') {
  370.         sprintf(string,"%sAREALIST.XBS",conf.menupath);
  371.         if(findfirst(string,&f,0)) find_filearea(filename,"___",user.stat[statnum]);
  372.         else readfile("arealist.xbs",1,1,1);
  373.         goto Filelistings;
  374.       }
  375.       if(*tempstring) {
  376.           if(atol(tempstring)) {
  377.             strcpy(string,"#");
  378.             strcat(string,tempstring);
  379.           }
  380.           else strcpy(string,tempstring);
  381.           if(!find_filearea(filename,string,user.stat[statnum])) {
  382.                 say_prompt(450);
  383.           }
  384.           else {
  385.             sprintf(string,"%s",say_prompt(486));
  386.             if(!find_msgarea(string,fboard.name,0)) {
  387.                 memcpy(&mboard,&mb,sizeof(struct _mboard));
  388.             }
  389.           }
  390.       }
  391.       if(comval) goto ReUp;
  392.       else goto ReList;
  393. }
  394.