Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 18th, 2012  |  syntax: None  |  size: 3.69 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include "y.tab.h"
  6.  
  7. int main()
  8. {
  9.         printf("/////////////////////////////\n");
  10.         printf("///\tThe Nutshell\n");
  11.         printf("///\tPATH=/bin/\n");
  12.         printf("///\tWHEN ENTERING COMMANDS, SEPARATE WITH TILDES\n");
  13.         printf("///\t e.g. ls~-al~folder [ not ls - al folder ]\n");
  14.         putenv("PATH=/bin/");
  15.         putenv("PRMPT=LOL");
  16.         int i = 0;
  17.         while(1)
  18.         {
  19.                 char * prompt;
  20.                 prompt = getenv("PRMPT");
  21.                 printf("%s %d: ",prompt,i++);
  22.                 yyparse();
  23.         }
  24. }
  25.  
  26. /*
  27. void outRedir(char *outFile)
  28. {
  29.         int x;
  30.         char name[100];
  31.         char command[100];
  32.         FILE *ofp;
  33.         fp = fopen(outFile,"r");
  34.         ofp = fopen("temp","w");
  35.         while (fscanf(ifp,"%s %s",name,command) != EOF)
  36.         {
  37.                 x=strcmp(name,search);
  38.                 if (x!=0)
  39.                 {
  40.                         fprintf(ofp,"%s %s\n",name,command);
  41.                 }                      
  42.         }
  43.         fclose(ifp);
  44.         fclose(ofp);
  45.         unlink("alias");
  46.         rename("temp","alias");
  47. }
  48.  
  49. void outRedira(char *input, char* outFile)
  50. {      
  51.         int x;
  52.         char name[100];
  53.         char command[100];
  54.         FILE *ifp, *ofp;
  55.         ifp = fopen("alias","r");
  56.         ofp = fopen("temp","w");
  57.         while (fscanf(ifp,"%s %s",name,command) != EOF)
  58.         {
  59.                 x=strcmp(name,search);
  60.                 if (x!=0)
  61.                 {
  62.                         fprintf(ofp,"%s %s\n",name,command);
  63.                 }                      
  64.         }
  65.         fclose(ifp);
  66.         fclose(ofp);
  67.         unlink("alias");
  68.         rename("temp","alias");
  69. }*/
  70.  
  71. void bye()
  72. {
  73.         printf("\tbye'd\n");
  74.         exit(1);
  75. }
  76.  
  77. void set()
  78. {
  79.         printf("\tPath: %s\n",getenv("PATH"));
  80.         printf("\tPrompt: %s\n",getenv("PRMPT"));
  81. }
  82.  
  83. void setp(char *prm)
  84. {
  85.         char *var = "PRMPT=";
  86.         char *val = prm;
  87.         char *str3;
  88.         str3 = (char *)calloc(strlen(var)+strlen(val)+1,sizeof(char));
  89.         strcat(str3,var);
  90.         strcat(str3,val);
  91.         printf("\t%s\n",str3);
  92.         putenv(str3);
  93. }
  94.  
  95. void setpa(char *pat)
  96. {
  97.         char *var = "PATH=";
  98.         char *val = pat;
  99.         char *str3;
  100.         str3 = (char *)calloc(strlen(var)+strlen(val)+1,sizeof(char));
  101.         strcat(str3,var);
  102.         strcat(str3,val);
  103.         printf("\t%s\n",str3);
  104.         putenv(str3);
  105. }
  106.  
  107. void cd()
  108. {
  109.         chdir("/home");
  110. }
  111.  
  112. void cdd(char *dir)
  113. {
  114.         int error = chdir(dir);
  115.         if (error != 0) {printf("Error, directory unchanged");}
  116. }
  117.  
  118. void run(char *com)
  119. {
  120.         char *var = "PATH=";
  121.         char *val = com;
  122.         char *str3;
  123.         str3 = (char *)calloc(strlen(var)+strlen(val)+1,sizeof(char));
  124.         strcat(str3,var);
  125.         strcat(str3,val);
  126.         printf("\t%s\n",str3);
  127.         system(str3);
  128. }
  129.  
  130. void aliasList()
  131. {
  132.         char name[10];
  133.         char command[100];
  134.         FILE *fp;
  135.         fp = fopen("alias","r");
  136.  
  137.         while (fscanf(fp,"%s %s",name,command) != EOF)
  138.                 printf("%s = %s\n",name,command);
  139.  
  140.         fclose(fp);
  141. }
  142.  
  143. void alias(char *name, char *command)
  144. {
  145.         FILE *ofp;
  146.         ofp = fopen("alias","a");
  147.         fprintf(ofp,"%s %s\n",name,command);
  148.         fclose(ofp);
  149. }
  150.  
  151. void pip(char * arg1, char * arg2)
  152. {
  153.         printf("\targ1: %s\n",arg1);
  154.         printf("\targ2: %s\n",arg2);
  155.         printf("\t%s | %s\n",arg1,arg2);
  156. }
  157.  
  158. void unalias(char *search)
  159. {
  160.         char name[10];
  161.         char command[100];
  162.         FILE *ifp, *ofp;
  163.         ifp = fopen("alias","r");
  164.         ofp = fopen("temp","w");
  165.  
  166.         while (fscanf(ifp,"%s %s",name,command) != EOF)
  167.                 if (strcmp(name,search)!=0)
  168.                         fprintf(ofp,"%s %s\n",name,command);
  169.  
  170.         fclose(ifp);
  171.         fclose(ofp);
  172.         unlink("alias");
  173.         rename("temp","alias");
  174. }
  175.  
  176. int aliasCheck(char *search)
  177. {
  178.         int bool;
  179.         char name[10];
  180.         char command[100];
  181.         FILE *ifp;
  182.  
  183.         if(ifp = fopen("alias","r"))
  184.         {
  185.                 while (fscanf(ifp,"%s %s",name,command) != EOF)
  186.                         if (strcmp(name,search)!=0)
  187.                                 bool=0;
  188.                         else
  189.                                 return 1;
  190.  
  191.                 fclose(ifp);
  192.                 return bool;
  193.         }
  194.         return 0;
  195. }
  196.  
  197. void aliasExec(char *search)
  198. {
  199.         char name[10];
  200.         char command[100];
  201.         FILE *ifp;
  202.  
  203.         if(ifp = fopen("alias","r"))
  204.         {
  205.                 while (fscanf(ifp,"%s %s",name,command) != EOF)
  206.                         if (strcmp(name,search)==0)
  207.                                 system(command);
  208.  
  209.                 fclose(ifp);
  210.         }
  211. }