home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / pgmutil / val_link.zip / USERINP.C < prev    next >
Text File  |  1989-02-18  |  10KB  |  240 lines

  1. /*                                 USERINP.C                               */
  2.  
  3. /*+-------------------------------------------------------------------------+
  4.   |                                                                         |
  5.   |                      get_filenames_from_user                            |
  6.   |                                                                         |
  7.   +-------------------------------------------------------------------------+*/
  8. void get_filenames_from_user(bit_16 argc, byte *argv[])
  9. BeginDeclarations
  10. byte                                  *env_var;
  11. bit_16                                 i;
  12. file_info_ptr                          file_entry;
  13. #define File_entry                     (*file_entry)
  14. token_stack_ptr                        source_element;
  15. #define Source_element                 (*source_element)
  16. EndDeclarations
  17. BeginCode
  18.  
  19.  user_input_start_time = Now;
  20.  
  21. /*+-------------------------------------------------------------------------+
  22.   |                                                                         |
  23.   |           concatenate the environment files into parm_string            |
  24.   |                                                                         |
  25.   +-------------------------------------------------------------------------+*/
  26.  copy_string(parm_string, null_string);
  27.  copy_string(default_filename, program_directory_string);
  28.  change_extension(default_filename, env_extension_string);
  29.  If file_exists(default_filename, 0)
  30.   Then
  31.    concat_string(parm_string, at_string);
  32.    concat_string(parm_string, default_filename);
  33.    concat_string(parm_string, space_string);
  34.   EndIf;
  35.  copy_string(token, default_filename);
  36.  cut_string(token,
  37.             0,
  38.             reverse_index_string(token, 
  39.                                  0xFFFF, 
  40.                                  backslash_string) + 1);
  41.  process_filename(token);
  42.  If (file_exists(token, 0)) AndIf 
  43.     (compare_string(token, default_filename) IsNotZero)
  44.   Then
  45.    concat_string(parm_string, at_string);
  46.    concat_string(parm_string, token);
  47.    concat_string(parm_string, space_string);
  48.   EndIf;
  49. /*+-------------------------------------------------------------------------+
  50.   |                                                                         |
  51.   |       concatenate the LINK environment variable into parm_string        |
  52.   |                                                                         |
  53.   +-------------------------------------------------------------------------+*/
  54.  env_var = (byte *) getenv("LINK");
  55.  If env_var IsNull
  56.   Then
  57.    env_var = (byte *) "";
  58.   EndIf;
  59.  concat_string(parm_string, string(BytePtr(env_var)));
  60.  concat_string(parm_string, space_string);
  61. /*+-------------------------------------------------------------------------+
  62.   |                                                                         |
  63.   |               concatenate the parm line into parm_string                |
  64.   |                                                                         |
  65.   +-------------------------------------------------------------------------+*/
  66.  For i=1; i<argc; i++
  67.   BeginFor
  68.    If i Exceeds 1
  69.     Then
  70.      concat_string(parm_string, space_string);
  71.     EndIf;
  72.    concat_string(parm_string, string(BytePtr(argv[i])));
  73.   EndFor;
  74. /*+-------------------------------------------------------------------------+
  75.   |                                                                         |
  76.   |             Start input processing with the parm line.                  |
  77.   |                                                                         |
  78.   +-------------------------------------------------------------------------+*/
  79.  
  80.  source_element                    = get_free_token_source_element();
  81.  Source_element.source_file        = Null;
  82.  Source_element.token_string       = parm_string;
  83.  Source_element.token_string_index = 0;
  84.  Push source_element OnTo token_stack EndPush;
  85.  token_break_char                  = ' ';
  86.  
  87. /*+-------------------------------------------------------------------------+
  88.   |                                                                         |
  89.   |                       Process OBJ file list                             |
  90.   |                                                                         |
  91.   +-------------------------------------------------------------------------+*/
  92.  
  93.  default_extension = obj_extension_string;
  94.  copy_string(default_filename, null_string);
  95.  default_prompt    = "OBJ file(s)%Fs:  ";
  96.  prompting_for     = 1;
  97.  process_user_input_files(Addr(obj_file_list),
  98.                           True);
  99.  
  100. /*+-------------------------------------------------------------------------+
  101.   |                                                                         |
  102.   |                         Process EXE file                                |
  103.   |                                                                         |
  104.   +-------------------------------------------------------------------------+*/
  105.  
  106.  If comfile.val IsTrue
  107.   Then
  108.    default_extension = com_extension_string;
  109.    default_prompt = "COM file[%Fs]:  ";
  110.   Else
  111.    If sysfile.val IsTrue
  112.     Then
  113.      default_extension = sys_extension_string;
  114.      default_prompt = "SYS file[%Fs]:  ";
  115.     Else
  116.      default_extension = exe_extension_string;
  117.      default_prompt = "EXE file[%Fs]:  ";
  118.     EndIf;
  119.   EndIf;
  120.  
  121.  copy_string(default_filename, string((*(obj_file_list.first)).filename));
  122.  change_extension(default_filename, default_extension);
  123.  prompting_for = 2;
  124.  process_user_output_file(Addr(exe_file_list),
  125.                           False);
  126.  
  127. /*+-------------------------------------------------------------------------+
  128.   |                                                                         |
  129.   |                         Process LST file                                |
  130.   |                                                                         |
  131.   +-------------------------------------------------------------------------+*/
  132.  
  133.  default_extension = lst_extension_string;
  134.  copy_string(default_filename, null_string);
  135.  default_prompt    = "LST file:%Fs  ";
  136.  prompting_for     = 3;
  137.  process_user_output_file(Addr(lst_file_list),
  138.                           False);
  139.  If (First(lst_file_list) IsNull)                 AndIf
  140.     ((map.set IsTrue) OrIf (detail_level.val Exceeds 0))
  141.   Then
  142.    copy_string(token, string((*(exe_file_list.first)).filename));
  143.    change_extension(token, lst_extension_string);
  144.    file_entry = (file_info_ptr)
  145.                  allocate_memory(Addr(static_pool),
  146.                                  Bit_32(sizeof(file_info_type)) +
  147.                                  Bit_32(Length(token)));
  148.    far_move(File_entry.filename, String(token), Length(token)+1);
  149.    Insert file_entry AtEnd InList lst_file_list EndInsert;
  150.   EndIf;
  151.  
  152. /*+-------------------------------------------------------------------------+
  153.   |                                                                         |
  154.   |                       Process LIB file list                             |
  155.   |                                                                         |
  156.   +-------------------------------------------------------------------------+*/
  157.  
  158.  default_extension = lib_extension_string;
  159.  copy_string(default_filename, null_string);
  160.  default_prompt    = "LIB file(s):%Fs  ";
  161.  prompting_for     = 4;
  162.  process_user_input_files(Addr(lib_file_list),
  163.                           False);
  164.  return;
  165. EndCode
  166. #undef File_entry
  167. #undef Source_element
  168.  
  169. /*+-------------------------------------------------------------------------+
  170.   |                                                                         |
  171.   |                      process_user_input_files                           |
  172.   |                                                                         |
  173.   +-------------------------------------------------------------------------+*/
  174. void process_user_input_files(file_info_list *list,
  175.                               bit_16          required)
  176. BeginDeclarations
  177. #define List                           (*list)
  178. EndDeclarations
  179. BeginCode
  180.  scan_out_token();
  181.  Repeat
  182.   BeginRepeat
  183.    get_filename_token(required, list);
  184.    If Length(token) Exceeds 0
  185.     Then
  186.      process_filename(token);
  187.       If index_string(token, 0, colon_string) IsNot 1
  188.        Then
  189.         linker_error(4, "\"%Fs\" is an illegal input file name.\n",
  190.                         String(token));
  191.        Else
  192.          add_extension_to_file(token,default_extension);
  193.          add_files_to_list(list, token);
  194.        EndIf;
  195.     EndIf;
  196.    RepeatIf more_tokens
  197.   EndRepeat;
  198.  return;
  199. EndCode
  200. #undef List
  201.  
  202. /*+-------------------------------------------------------------------------+
  203.   |                                                                         |
  204.   |                      process_user_output_file                           |
  205.   |                                                                         |
  206.   +-------------------------------------------------------------------------+*/
  207. void process_user_output_file(file_info_list *list,
  208.                               bit_16          required)
  209. BeginDeclarations
  210. file_info_ptr                          file_entry;
  211. #define File_entry                     (*file_entry)
  212. #define List                           (*list)
  213. EndDeclarations
  214. BeginCode
  215.  scan_out_token();
  216.  Repeat
  217.   BeginRepeat
  218.    get_filename_token(required, list);
  219.    If Length(token) Exceeds 0
  220.     Then
  221.      process_filename(token);
  222.      add_extension_to_file(token,default_extension);
  223.      If List.first IsNull
  224.       Then
  225.        file_entry = (file_info_ptr)
  226.                      allocate_memory(Addr(static_pool),
  227.                                      Bit_32(sizeof(file_info_type)) +
  228.                                      Bit_32(Length(token)));
  229.        far_move(File_entry.filename, String(token), Length(token)+1);
  230.        Insert file_entry AtEnd InList List EndInsert;
  231.       EndIf;
  232.     EndIf;
  233.    RepeatIf more_tokens
  234.   EndRepeat;
  235.  return;
  236. EndCode
  237. #undef File_entry
  238. #undef List
  239.  
  240.