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