/branches/Branch-observer/gpsim/main.cc

# · C++ · 256 lines · 171 code · 59 blank · 26 comment · 15 complexity · 817600e8908f53e78a1774e9f275043f MD5 · raw file

  1. /*
  2. Copyright (C) 1998 T. Scott Dattalo
  3. This file is part of gpsim.
  4. gpsim is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. gpsim is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with gpsim; see the file COPYING. If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. // Portions of this files are (C) by Ian King:
  17. /* picdis.c - pic disassembler */
  18. /* version 0.1 */
  19. /* (c) I.King 1994 */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <iostream.h>
  24. #include <iomanip.h>
  25. #include <string>
  26. #include <list>
  27. #include "../cli/command.h"
  28. #include "../cli/input.h"
  29. #include "../src/gpsim_def.h"
  30. #include "../src/interface.h"
  31. extern "C" {
  32. int gui_init (int argc, char **argv);
  33. void gui_main(void);
  34. void gpsim_interface_init(void);
  35. }
  36. extern int server_main (int argc, char *argv[]);
  37. void initialize_gpsim(void);
  38. unsigned int config_word; //%%%FIX_ME%%%
  39. int yyparse(void);
  40. int parse_string(char *cmd_string);
  41. extern int yydebug;
  42. extern int quit_parse;
  43. void gpsim_version(void)
  44. {
  45. cout << GPSIM_VERSION << '\n';
  46. }
  47. void
  48. helpme (char *iam)
  49. {
  50. printf ("\n\nuseage:\n%s [-h] [-p <device> [<hex_file>]] [-c <stc_file>]\n", iam);
  51. printf ("\t-h : this help list\n");
  52. printf ("\t-p <device> : processor (e.g. -pp16c84 for the 'c84)\n");
  53. printf ("\t<hex_file> : input file in \"intelhex16\" format\n");
  54. printf ("\t-c <stc_file> : startup command file\n");
  55. printf ("\t-s <cod_file> : .cod symbol file\n\n");
  56. printf ("\t-v : gpsim version\n");
  57. }
  58. void welcome(void)
  59. {
  60. cout << "\ngpsim - the GNUPIC simulator\
  61. \nversion: " << GPSIM_VERSION << "\n\ntype help for help\n";
  62. }
  63. void
  64. main (int argc, char *argv[])
  65. {
  66. FILE *inputfile = stdin, *startup=NULL;
  67. #define FILE_STRING_LENGTH 50
  68. char
  69. startup_name[FILE_STRING_LENGTH] = "",
  70. pic_name[FILE_STRING_LENGTH] = "",
  71. cod_name[FILE_STRING_LENGTH] = "",
  72. hex_name[FILE_STRING_LENGTH] = "";
  73. int i;
  74. int j;
  75. int c,usage=0;
  76. char command_str[256];
  77. char *b;
  78. int architecture;
  79. welcome();
  80. cout << hex ;
  81. cin >> hex;
  82. #if 0
  83. i = 1;
  84. while(i < argc)
  85. {
  86. if (argv[i][0] == '-')
  87. switch (argv[i][1])
  88. {
  89. case 'P':
  90. case 'p':
  91. strncpy(pic_name, &argv[i][2],FILE_STRING_LENGTH);
  92. break;
  93. case 'C':
  94. case 'c':
  95. printf("%s %s\n", &argv[i][0], &argv[i][2]);
  96. strncpy (startup_name, &argv[i][2],FILE_STRING_LENGTH);
  97. break;
  98. case 'S':
  99. case 's':
  100. printf("%s %s\n", &argv[i][0], &argv[i][2]);
  101. strncpy (cod_name, &argv[i][2],FILE_STRING_LENGTH);
  102. break;
  103. case 'V':
  104. case 'v':
  105. printf("%s\n",GPSIM_VERSION);
  106. break;
  107. case 'H':
  108. case 'h':
  109. default:
  110. helpme (argv[0]);
  111. exit (1);
  112. }
  113. else
  114. {
  115. strncpy(hex_name, argv[i],FILE_STRING_LENGTH);
  116. }
  117. i++;
  118. }
  119. #endif
  120. while ((c = getopt(argc, argv, "h?p:c:s:v")) != EOF) {
  121. switch (c) {
  122. case '?':
  123. case 'h':
  124. usage = 1;
  125. break;
  126. case 'p':
  127. strncpy(pic_name, optarg,FILE_STRING_LENGTH);
  128. break;
  129. case 'c':
  130. strncpy(startup_name, optarg,FILE_STRING_LENGTH);
  131. break;
  132. case 's':
  133. strncpy(cod_name, optarg,FILE_STRING_LENGTH);
  134. break;
  135. case 'v':
  136. printf("%s\n",GPSIM_VERSION);
  137. break;
  138. }
  139. if (usage)
  140. break;
  141. }
  142. if (optind < argc)
  143. strncpy(hex_name, argv[optind],FILE_STRING_LENGTH);
  144. else
  145. usage = 1;
  146. if (usage)
  147. helpme(argv[0]);
  148. initialize_gpsim();
  149. init_parser();
  150. initialize_readline();
  151. gpsim_interface_init();
  152. // initialize the gui
  153. #ifdef HAVE_GUI
  154. i = gui_init (argc,argv);
  155. #endif
  156. initialization_is_complete();
  157. yydebug = 0;
  158. quit_parse = 0;
  159. if(*pic_name)
  160. {
  161. strcpy(command_str, "processor ");
  162. strcat(command_str, pic_name);
  163. parse_string(command_str);
  164. }
  165. if(*hex_name)
  166. {
  167. strcpy(command_str, "load h ");
  168. strcat(command_str, hex_name);
  169. parse_string(command_str);
  170. }
  171. if(*cod_name)
  172. {
  173. strcpy(command_str, "load s ");
  174. strcat(command_str, cod_name);
  175. parse_string(command_str);
  176. }
  177. if(*startup_name)
  178. {
  179. strcpy(command_str, "load c ");
  180. strcat(command_str, startup_name);
  181. parse_string(command_str);
  182. }
  183. // Now enter the event loop and start processing user
  184. // commands.
  185. #ifdef HAVE_GUI
  186. gui_main();
  187. #else
  188. do {
  189. init_parser();
  190. i = yyparse();
  191. } while(!quit_parse);
  192. #endif
  193. }