Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 13th, 2011  |  syntax: C  |  size: 2.35 KB  |  hits: 79  |  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. /*
  2.  *    AGROS - The new Limited Shell
  3.  *
  4.  *    Author: Joe "rahmu" Hakim Rahme <joe.hakim.rahme@gmail.com>
  5.  *
  6.  *
  7.  *    This file is part of AGROS.
  8.  *
  9.  *    This program is free software: you can redistribute it and/or modify
  10.  *    it under the terms of the GNU General Public License as published by
  11.  *    the Free Software Foundation, either version 3 of the License, or
  12.  *    (at your option) any later version.
  13.  *
  14.  *    This program is distributed in the hope that it will be useful,
  15.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *    GNU General Public License for more details.
  18.  *
  19.  *    You should have received a copy of the GNU General Public License
  20.  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.  */
  22.  
  23.  
  24. #define MAX_LINE_LEN 256
  25. #define MAX_ARGS (MAX_LINE_LEN/2)
  26. #define WHITESPACE " \t\n"
  27.  
  28. #define OTHER_CMD   0
  29. #define EMPTY_CMD   1
  30. #define CD_CMD      2
  31. #define HELP_CMD    3
  32. #define EXIT_CMD    4
  33.  
  34.  
  35. /*
  36.  * This structure allows me to handle built-in commands with a switch statement
  37.  * instead of multiple ifs. Since I cannot switch on a string, I associate a
  38.  * command_code to each built-in command. The codes are define as preprocessor
  39.  * instructions.
  40.  */
  41.  
  42. typedef struct built_in_commands built_in_commands;
  43. struct built_in_commands{
  44.     char command_name[MAX_LINE_LEN];
  45.     int command_code;
  46. };
  47.  
  48. /* This structure holds user input. 3 fields:
  49.  *   - argv: an array of strings. Each word of the input is a case of the array.
  50.  *   - name: the name of the executable called. By default it's argv[0]
  51.  *   - argc: the number of words given in input. It's equivalent to the length of argv.
  52.  *
  53.  * Note: Some filenames have a space character (" ") in their names. I will have
  54.  * to deal with that properly ... someday.
  55.  */
  56.  
  57. typedef struct command_t command_t;
  58. struct command_t{              
  59.     char* name;
  60.     int argc;
  61.     char* argv[MAX_ARGS+1];
  62. };
  63.  
  64.  
  65. /*
  66.  * These are the functions called by AGROS. These declarations are pretty explicit.
  67.  * More detailed comments can be found in source files.
  68.  *
  69.  */
  70.  
  71. void parse_command(char *cmdline, command_t *cmd);
  72. int read_input(char* string, int num);
  73. char* return_prompt(void);
  74. void print_help(void);
  75. void change_directory(char* PATH);
  76. char* concat_spaces(char** string_array);
  77. int get_cmd_code(char* cmd_name);
  78. char* ag_readline(char* prompt);