emcargs.cc
1 /******************************************************************** 2 * Description: emcargs.cc 3 * Globals initialized to values in emccfg.h 4 * 5 * Derived from a work by Fred Proctor & Will Shackleford 6 * 7 * Author: 8 * License: GPL Version 2 9 * System: Linux 10 * 11 * Copyright (c) 2004 All rights reserved. 12 * 13 * Last change: 14 ********************************************************************/ 15 16 #include <string.h> /* strcpy() */ 17 #include <stdio.h> /* fgets() */ 18 #include "nml.hh" /* nmlSetHostAlias */ 19 #include "emcglb.h" /* these decls */ 20 #include "emccfg.h" /* their initial values */ 21 #include "rcs_print.hh" 22 23 int emcGetArgs(int argc, char *argv[]) 24 { 25 int t; 26 27 /* process command line args, indexing argv[] from [1] */ 28 for (t = 1; t < argc; t++) { 29 if (!strcmp(argv[t], "-ini")) { 30 if (t == argc - 1) { 31 return -1; 32 } else { 33 if (strlen(argv[t+1]) >= LINELEN) { 34 fprintf(stderr, "ini file name too long (max %d):\n", LINELEN); 35 fprintf(stderr, " %s\n", argv[t+1]); 36 return -1; 37 } 38 strcpy(emc_inifile, argv[t + 1]); 39 t++; 40 } 41 continue; 42 } 43 if (!strcmp(argv[t], "-rcsdebug")) { 44 set_rcs_print_flag(PRINT_EVERYTHING); 45 max_rcs_errors_to_print = -1; 46 continue; 47 } 48 49 if (!strcmp(argv[t], "-queryhost")) { 50 char qhost[80]; 51 printf("EMC Host?"); 52 if(!fgets(qhost, 80, stdin)) return -1; 53 for (int i = 0; i < 80; i++) { 54 if (qhost[i] == '\r' || qhost[i] == '\n' 55 || qhost[i] == ' ') { 56 qhost[i] = 0; 57 break; 58 } 59 } 60 nmlSetHostAlias(qhost, "localhost"); /* If localhost 61 appears in .nml 62 file it will 63 overriden by this 64 argument. */ 65 nmlForceRemoteConnection(); 66 /* The only good reason for aliasing the host that I know of is 67 to connect to a remote server so we will ignore the 68 LOCAL/REMOTE field in the .nml file and always connect 69 remotely. */ 70 continue; 71 } 72 if (!strcmp(argv[t], "-host")) { 73 if (t == argc - 1) { 74 return -1; 75 } else { 76 nmlSetHostAlias(argv[t + 1], "localhost"); /* If 77 localhost 78 appears in 79 .nml file 80 it will 81 overriden 82 by this 83 argument. */ 84 nmlForceRemoteConnection(); 85 /* The only good reason for aliasing the host that I know of 86 is to connect to a remote server so we will ignore the 87 LOCAL/REMOTE field in the .nml file and always connect 88 remotely. */ 89 t++; 90 } 91 continue; 92 } 93 } 94 /* else not recognized-- ignore */ 95 96 return 0; 97 }