home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / bbbsr2.zip / scripts / error.bz < prev    next >
Text File  |  1997-06-26  |  5KB  |  171 lines

  1. /*
  2.  * Error.bz - Run when an unknown command occures
  3.  *
  4.  * See script.gui for more information about parsecom and other bz commands.
  5.  * Remember to recompile this script after you've done some changes.
  6.  *
  7.  * This script has some commands that are allready defined. These are:
  8.  *
  9.  *         User Commands:
  10.  *         glob: REGEXP          Gives help about Regular expressions
  11.  *         glob: CLS             Clears the screen
  12.  *         glob: ADDON           Shows the files USERMENU.GR and USERMENS.GR
  13.  *                               Theese files must reside in one of your
  14.  *                               menu directories.
  15.  *         util: FILT            MBBS Compability dummy-command.
  16.  *         util: GR              MBBS Compability dummy-command.
  17.  *
  18.  *         Sysop Commands:
  19.  *         glob: RUN             Runs an external script.
  20.  */
  21.  
  22. #include <stdlib.bzh>
  23.  
  24. int usermenu() {
  25.   int f;
  26.  
  27.   if (bu_language>0) {
  28.     if ((f=fopen(sprintf("%s%s%u",bl_menudir,"usermenu.gr",bu_language),"rt"))!=-1) {
  29.       fclose(f);
  30.       showfile(sprintf("%s%s%u",bl_menudir,"usermenu.gr",bu_language));
  31.     } else showfile(sprintf("%s%s%u",bg_menudir,"usermenu.gr",bu_language));
  32.     if (bu_access & 255) {
  33.       if ((f=fopen(sprintf("%s%s%u",bl_menudir,"usermens.gr",bu_language),"rt"))!=-1) {
  34.         fclose(f);
  35.         showfile(sprintf("%s%s%u",bl_menudir,"usermens.gr",bu_language));
  36.       } else showfile(sprintf("%s%s%u",bg_menudir,"usermens.gr",bu_language));
  37.     }
  38.   } else {
  39.     if ((f=fopen(strcat(bl_menudir,"usermenu.gr"),"rt"))!=-1) {
  40.       fclose(f);
  41.       showfile(strcat(bl_menudir,"usermenu.gr"));
  42.     } else showfile(strcat(bg_menudir,"usermenu.gr"));
  43.     if (bu_access & 255) {
  44.       if ((f=fopen(strcat(bl_menudir,"usermens.gr"),"rt"))!=-1) {
  45.         fclose(f);
  46.         showfile(strcat(bl_menudir,"usermens.gr"));
  47.       } else showfile(strcat(bg_menudir,"usermens.gr"));
  48.     }
  49.   }
  50. }
  51.  
  52. int main(char com, int tomenu) {
  53. /*
  54.  * tomenu: 1=read, 2=main, 3=util, 4=file, 5=chat, 6=outb, 7=ftp
  55.  *         128=join_no_access, 129=file_cd_no_access, 130=bz::file4()
  56.  *         131=feelings
  57.  */
  58.   char s, r;
  59.   int f;
  60.  
  61. /*
  62. File format for commands.bbb is:
  63.  
  64. --cut--
  65. ;Command                Menu   Script, *bbbs_command or !os_command
  66. ;==================================================================
  67.  
  68. FOObar                  2      unpack
  69. TEST                    1      *!This is a test.
  70. ACCess       !,fsysop,  1      *>b You have access!
  71. --cut--
  72.  
  73. Optional "!regexp_of_groups" can be added before menu parameter.
  74. Use lowercase characters!
  75. */
  76.  
  77.   if ((f=fopen("commands.bbb","rt"))!=-1) {
  78.     do {
  79.       s=fgets(f);
  80.       if (s!="" && copy(s,1,1)!=";" && pos(" ",s)) {
  81.         r=copy(s,1,pos(" ",s)-1);
  82.         if (parsecom(r,com)==1) {
  83.           s=delete(s,1,strlen(r));
  84.           while (copy(s,1,1)==" ") s=delete(s,1,1);
  85.           if (pos(" ",s)) {
  86.             r=copy(s,1,pos(" ",s)-1);
  87.             if (copy(r,1,1)=="!") {
  88.               if (!regexp(copy(r,2,255),bv_groups)) r="";
  89.               else {
  90.                 s=delete(s,1,strlen(r));
  91.                 while (copy(s,1,1)==" ") s=delete(s,1,1);
  92.                 if (pos(" ",s)) r=copy(s,1,pos(" ",s)-1);
  93.               }
  94.             }
  95.             if ((r=="*" || r==tomenu) && pos(" ",s)) {
  96.               s=delete(s,1,strlen(r));
  97.               while (copy(s,1,1)==" ") s=delete(s,1,1);
  98.               fclose(f);
  99.               if (copy(s,1,1)=="*") bbbs(copy(s,2,256));
  100.               else
  101.                 if (copy(s,1,1)=="!") system(copy(s,2,256),1);
  102.                 else spawn(s);
  103.               exit(0);
  104.             }
  105.           }
  106.         }
  107.       }
  108.     } while (!feof(f));
  109.     fclose(f);
  110.   }
  111.  
  112.   /* Local commands */
  113.  
  114.   switch (parsecom("FILT/GR",com)) {
  115.     case 1:{                   /* FILT */
  116.             if (tomenu==3) {   /* utilmenu */
  117.               printf("Noise filter disabled.\n");
  118.               exit(0);
  119.             }
  120.             break;
  121.            }
  122.     case 2:{                   /* GR */
  123.             if (tomenu==3) {   /* utilmenu */
  124.               printf("G&R commands disabled.\n");
  125.               exit(0);
  126.             }
  127.             break;
  128.            }
  129.   }
  130.  
  131.   /* Global commands */
  132.  
  133.   if (tomenu!=131)
  134.     switch (parsecom("REGEXP/CLS/ADDON/RUN",com)) {
  135.       case 1:{                    /* REGEXP */
  136.               help("","regexp");
  137.               exit(0);
  138.              }
  139.       case 2:{                    /* CLS */
  140.               printf("\e[1;1H\e[2J");
  141.               exit(0);
  142.              }
  143.       case 3:{                    /* ADDON */
  144.               usermenu();
  145.               exit(0);
  146.              }
  147.       case 4:{                    /* RUN */
  148.               if (bu_access & 1) {
  149.                 s=input("Script: ",69,1);
  150.                 if (s!="") spawn(s);
  151.               }
  152.               exit(0);
  153.              }
  154.     }
  155.  
  156.   /* Just print the error message */
  157.  
  158.   if (bn_zstatus!=5 && bn_zstatus!=6 && bn_zstatus!=9) {
  159.     if (tomenu==128) printf("%s\n",bv_txt[22]);       /* join_no_access */
  160.     else
  161.       if (tomenu==129) printf(bv_txt[629]);           /* file_cd_no_access */
  162.       else
  163.         if (tomenu==131) printf(bv_txt[23],com);      /* chat */
  164.         else
  165.           printf(bv_txt[23],com);                     /* invalid command */
  166.   }
  167.   bv_comstring="";
  168.   exit(0);
  169. }
  170.  
  171.