driver-gen/xml-lib: Search for version header files in the correct dir
[driver-gen.git] / serviceOptions.c
blob8533b1df40a3780d1205c6aa9857eca4fb2e7cfc
1 /**
2 * @file serviceOptions.c
4 * @brief
6 * @author Copyright (C) 2004 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
8 * @date Created on 27/02/2004
10 * @section license_sec License
11 * Released under the GPL
13 #include "serviceOptions.h"
14 #include "driverGen.h"
16 static srvopt_c srv_opt_c; /* container that holds command line args */
18 /**
19 * @brief Arguments amount and their forman supposed to be correct! No
20 * checking is performed.
22 * @param cur_arg -
23 * @param ... -
25 * @return 0 - all OK
26 * @return 1 - error occurs.
28 int SetSrvOptArgs(srvarg cur_arg, ...)
30 va_list ap;
32 va_start(ap, cur_arg);
34 switch (cur_arg) {
35 case SRV_VF_DRVR:
36 case SRV_VF_SIM:
37 vsnprintf(srv_opt_c.srv_vf_dir, sizeof(srv_opt_c.srv_vf_dir),
38 "%s", ap);
39 break;
40 default:
41 break;
44 va_end(ap);
46 return 0; /* OK */
49 /**
50 * @brief All service driverGen options are processed here.
52 * @param cur_arg --
53 * @param pn -- prog name
55 * To call service option you should call dgII with -srv option:
56 * dgII -srv [args]
58 * Supported service options are:
59 * 1. Creating of the version file within already existing driver directory.
60 * Arguments are:
61 * a. drvrvers/simvers
62 * b. driver directory, where to create versioin files.
64 * @return 0 - all OK
65 * @return negative value - error occurs.
67 int ProcessSrvOpt(srvarg cur_arg, char *pn)
69 struct stat status;
70 FILE *file;
71 char file_path[128];
72 char *file_name;
73 FILETYPE cur_ft; /* current file type */
74 rstat cc; /* driverGen error codes */
76 switch (cur_arg) {
77 case SRV_VF_DRVR:
78 case SRV_VF_SIM:
79 /* version files will be created only if appropriate destanation
80 directory already exist and version file is not yet created.
81 Existing version files will not be corrupted in this case.
83 Parameters for this service command are:
84 1. Module name
85 2. Bus type
86 3. Driver directory */
87 if (cur_arg == SRV_VF_DRVR) {
88 cur_ft = DRIVER_FT;
89 TranslationSetDriverType("DRVR");
90 TranslationSetFancyString("Driver");
91 } else {
92 cur_ft = SIM_FT;
93 TranslationSetDriverType("SIM");
94 TranslationSetFancyString("Simulator");
97 /* first, check if driver directory exist */
98 snprintf(file_path, sizeof(file_path), "%s/%s", get_mid(NULL),
99 srv_opt_c.srv_vf_dir);
100 if (stat(file_path, &status)) {
101 fprintf(stderr, "[%s] %s: Module driver directory"
102 " doesn't exist!\n", pn, file_path);
103 return -1; /* fail */
106 /* second, check if expected user directory is in the place */
107 snprintf(file_path, sizeof(file_path), "%s/%s/%s/%s",
108 get_mid(NULL), srv_opt_c.srv_vf_dir, LOCAL_INCL_DIR,
109 LOCAL_USER_DIR);
110 cc = MakeSafeDir(file_path);
111 if (cc < 0)
112 return cc;
114 /* now check if version file is already exist */
115 GenerateFilename(cur_ft, file_path, "Version", ".h", file_path);
116 file_name = rindex(file_path, '/');
117 ++file_name;
118 if (!stat(file_path, &status)) {
119 fprintf(stderr, "%s Version file (%s) already exist!\n",
120 (cur_arg == SRV_VF_DRVR) ? "Driver" :
121 "Simulator", file_name);
122 return -1; /* error */
125 /* ok - we are cool. Proceed... */
126 file = fopen(file_path, "w"); /* create version file */
127 Translate(file, "common", "driver/userPart/uepVers.h");
128 fclose(file);
129 break;
130 default:
131 break;
134 return 0; /* success */