Main Page | Directories | File List | Globals

pcibus_names_gen.c

Go to the documentation of this file.
00001 /*
00002  * kernel_drivers/adi_buses/pci/pcibus_names_gen.c
00003  *
00004  * Copyright (c) 2003-2005 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2005/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        pcibus_names_gen.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <fcntl.h>
00017 #include <memory.h>
00018 
00019 #define MAX_BUF_LEN     0x200
00020 #define MAX_VENDORS     2000
00021 #define MAX_DEVICES     10000
00022 
00023 int buf_check(char *buf, int len)
00024 {
00025     int i, j;
00026 
00027     for (i = 0; i < len; i++) {
00028         if (buf[i] == '"') {
00029         
00030             for (j = len; j >= i + 1; j--) {
00031                 buf[j] = buf[j - 1];
00032             }
00033         
00034             buf[i] = '\\';
00035             buf[i + 1] = '"';
00036             i++;
00037             len++;
00038         }
00039     }
00040     
00041     return len;
00042 }
00043 
00044 char vendor_names[MAX_VENDORS][MAX_BUF_LEN];
00045 int  vendor_names_count = 0;
00046 
00047 char device_names[MAX_DEVICES][MAX_BUF_LEN];
00048 int  device_names_count = 0;
00049 
00050 
00051 int vendor_check_redund(char *name) {
00052     int i;
00053     
00054     for (i = 0; i < vendor_names_count; i++) {
00055         if (!strcmp(vendor_names[i], name))
00056             return 1;
00057     }
00058     
00059     return 0;
00060 }
00061 
00062 int device_check_redund(char *name) {
00063     int i;
00064     
00065     for (i = 0; i < device_names_count; i++) {
00066         if (!strcmp(device_names[i], name))
00067             return 1;
00068     }
00069     
00070     return 0;
00071 }
00072 
00073 
00074 int main(void)
00075 {
00076     FILE *fin;
00077     FILE *fout_v, *fout_d, *fout_h;
00078     char buf[MAX_BUF_LEN];
00079     char *buf_2;
00080     unsigned long vendor_id;
00081     unsigned long device_id;
00082     char vendor_name[MAX_BUF_LEN];
00083     char device_name[MAX_BUF_LEN];
00084     char define_name[MAX_BUF_LEN];
00085     char tmp_name[MAX_BUF_LEN];
00086     int tmp_name_id;
00087     int i;
00088     char name[MAX_BUF_LEN];
00089 
00090     fin  = fopen("pcibus_names.ids", "r");
00091     fout_v = fopen("pcibus_vendor_names.c", "w");    
00092     fout_d = fopen("pcibus_device_names.c", "w");    
00093     fout_h = fopen("pcibus_define_names.h", "w");    
00094 
00095     fprintf(fout_v, "/* \n");
00096     fprintf(fout_v, " * kernel_drivers/adi_buses/pci/pcibus_vendor_names.c\n");
00097     fprintf(fout_v, " * \n");
00098     fprintf(fout_v, " * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>\n");
00099     fprintf(fout_v, " * All Rights Reserved\n");
00100     fprintf(fout_v, " * \n");
00101     fprintf(fout_v, " * Date:   2004/06\n");
00102     fprintf(fout_v, " * Author:         Lukasz Dembinski\n");
00103     fprintf(fout_v, " * Info:   pcibus_vendor_names.c core file\n");
00104     fprintf(fout_v, " * Contact:        mailto: <dembol@nasa.com.pl>\n");
00105     fprintf(fout_v, " * \n");
00106     fprintf(fout_v, " */\n\n");
00107 
00108     fprintf(fout_v, "#include <agnix/agnix.h>\n");
00109     fprintf(fout_v, "#include <agnix/adi/adi.h>\n\n");
00110     fprintf(fout_v, "struct pcibus_vendor_name_s pcibus_vendor_names[] = {\n");
00111 
00112     while(fgets(buf, MAX_BUF_LEN - 1, fin)) {
00113         if (buf[0] == '#')
00114             continue;
00115 
00116         buf[strlen(buf) - 1] = 0;
00117 
00118         if (buf[0] != '\t') {
00119             if (sscanf(buf, "%04x", &vendor_id) > 0) {
00120                 fprintf(fout_v, "\t{ 0x%04x, \"%s\" }, \n", vendor_id, buf + 6);
00121                     
00122                 if (vendor_id == 0xffff)
00123                     break;
00124             }
00125         }
00126         
00127         memset(buf, 0, MAX_BUF_LEN);    
00128     }
00129     fprintf(fout_v, "};\n\n");
00130 
00131     fseek(fin, 0, 0);
00132     
00133 
00134     fprintf(fout_d, "/* \n");
00135     fprintf(fout_d, " * kernel_drivers/adi_buses/pci/pcibus_device_names.c\n");
00136     fprintf(fout_d, " * \n");
00137     fprintf(fout_d, " * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>\n");
00138     fprintf(fout_d, " * All Rights Reserved\n");
00139     fprintf(fout_d, " * \n");
00140     fprintf(fout_d, " * Date:   2004/06\n");
00141     fprintf(fout_d, " * Author:         Lukasz Dembinski\n");
00142     fprintf(fout_d, " * Info:   pcibus_device_names.c core file\n");
00143     fprintf(fout_d, " * Contact:        mailto: <dembol@nasa.com.pl>\n");
00144     fprintf(fout_d, " * \n");
00145     fprintf(fout_d, " */\n\n");
00146 
00147     fprintf(fout_d, "#include <agnix/agnix.h>\n");
00148     fprintf(fout_d, "#include <agnix/adi/adi.h>\n\n");
00149         
00150     fprintf(fout_d, "struct pcibus_device_name_s pcibus_device_names[] = {\n");
00151 
00152     while(fgets(buf, MAX_BUF_LEN - 1, fin)) {
00153         if (buf[0] == '#')
00154             continue;
00155 
00156         buf[strlen(buf) - 1] = 0;
00157 
00158         if (buf[0] != '\t') {
00159             if (sscanf(buf, "%04x", &vendor_id) > 0) {
00160                 if (vendor_id == 0xffff)
00161                     break;
00162             }
00163         } else 
00164         if (buf[1] != '\t') {
00165             if (sscanf(buf, "%04x", &device_id) > 0) {
00166                 buf_check(buf + 7, strlen(buf) - 7);
00167             
00168                 fprintf(fout_d, "\t{ 0x%04x, 0x%04x, \"%s\" }, \n", vendor_id, device_id, buf + 7);
00169             }
00170         }
00171         
00172         memset(buf, 0, MAX_BUF_LEN);    
00173         
00174     }
00175     fprintf(fout_d, "};\n\n");
00176 
00177 
00178     fprintf(fout_h, "#ifndef _AGNIX_ADI_DEFINE_NAMES_H_\n");
00179     fprintf(fout_h, "#define _AGNIX_ADI_DEFINE_NAMES_H_\n\n");
00180 
00181     fseek(fin, 0, 0);
00182 
00183     while(fgets(buf, MAX_BUF_LEN - 1, fin)) {
00184         if (buf[0] == '#')
00185             continue;
00186 
00187         memset(name, 0, MAX_BUF_LEN);   
00188         buf[strlen(buf) - 1] = 0;
00189 
00190         if (buf[0] != '\t') {
00191             
00192             if (sscanf(buf, "%04x", &vendor_id) > 0) {
00193                 buf_2 = buf + 6;
00194                 for (i = 0; i < strlen(buf_2); i++) {
00195                 
00196                     if (buf_2[i] == ' ' || buf_2[i] == ',')
00197                         break;
00198                     
00199                     if (buf_2[i] == '\'' || buf_2[i] == ':' || buf_2[i] == '.' || buf_2[i] == '+' || buf_2[i] == '-' || buf_2[i] == '/' || buf_2[i] == '\\')
00200                         buf_2[i] = '_';
00201                     
00202                     if (buf_2[i] == '&')
00203                         buf_2[i] = 'N';
00204                 
00205                     if (buf_2[i] == '?')
00206                         buf_2[i] = 'x';
00207 
00208                     if (buf_2[i] == '[' || buf_2[i] == ']')
00209                         buf_2[i] = '_';
00210 
00211                     if (buf_2[i] >= 'a' && buf_2[i] <= 'z')             
00212                         buf_2[i] = buf_2[i] - 32;
00213                 }
00214                 
00215                 strncpy(name, buf_2, i);
00216                 
00217                 if (vendor_check_redund(name))
00218                     continue;
00219 
00220                 strcpy(vendor_names[vendor_names_count++], name);
00221                                 
00222                 sprintf(define_name, "#define PCIBUS_VENDOR_%s_ID", name);
00223                 
00224                 fprintf(fout_h, "%-040s\t0x%04x\n", define_name, vendor_id);
00225                     
00226                 if (vendor_id == 0xffff)
00227                     break;
00228             }
00229         }
00230         
00231         memset(buf, 0, MAX_BUF_LEN);    
00232     }
00233 
00234 
00235     fprintf(fout_h, "\n\n");
00236 
00237     fseek(fin, 0, 0);
00238 
00239     while(fgets(buf, MAX_BUF_LEN - 1, fin)) {
00240         if (buf[0] == '#')
00241             continue;
00242 
00243         memset(name, 0, MAX_BUF_LEN);   
00244         buf[strlen(buf) - 1] = 0;
00245 
00246 
00247         if (buf[0] != '\t') {
00248             if (sscanf(buf, "%04x", &vendor_id) > 0) {
00249                 if (vendor_id == 0xffff)
00250                     break;
00251             }
00252         } else 
00253         if (buf[1] != '\t') {
00254             if (sscanf(buf, "%04x", &device_id) > 0) {
00255                 buf_check(buf + 7, strlen(buf) - 7);
00256             
00257             if (sscanf(buf, "%04x", &vendor_id) > 0) {
00258                 buf_2 = buf + 7;
00259                 for (i = 0; i < strlen(buf_2); i++) {
00260                 
00261                     if (buf_2[i] == ' ' || buf_2[i] == ',' || buf_2[i] == '\\' || buf_2[i] == '/' || buf_2[i] == '!')
00262                         break;
00263 
00264                     if (buf_2[i] == '\'' || buf_2[i] == ':' || buf_2[i] == '.' || buf_2[i] == '+' || buf_2[i] == '-' || buf_2[i] == '/' || buf_2[i] == '\\')
00265                         buf_2[i] = '_';
00266 
00267                     if (buf_2[i] == '&')
00268                         buf_2[i] = 'N';
00269 
00270                     if (buf_2[i] == '?')
00271                         buf_2[i] = 'x';
00272 
00273                     if (buf_2[i] == '[' || buf_2[i] == ']')
00274                         buf_2[i] = '_';
00275 
00276                 
00277                     if (buf_2[i] >= 'a' && buf_2[i] <= 'z')             
00278                         buf_2[i] = buf_2[i] - 32;
00279 
00280                     if (buf_2[i] == '(')
00281                         buf_2[i] = '_';
00282 
00283                     if (buf_2[i] == ')')
00284                         buf_2[i] = '_';
00285 
00286                 }
00287                 
00288                 strncpy(name, buf_2, i);
00289                 
00290                 strcpy(tmp_name, name);
00291                 tmp_name_id = 1;
00292                 
00293                 while(device_check_redund(tmp_name)) {
00294                     sprintf(tmp_name, "%s_%d", name, tmp_name_id++);
00295                 }
00296 
00297                 strcpy(device_names[device_names_count++], tmp_name);
00298                                 
00299                 sprintf(define_name, "#define PCIBUS_DEVICE_%s_ID", tmp_name);
00300                 
00301                 fprintf(fout_h, "%-040s\t0x%04x\n", define_name, device_id);
00302 
00303                 }
00304             }
00305         }
00306         
00307         memset(buf, 0, MAX_BUF_LEN);    
00308     }
00309 
00310     
00311     fprintf(fout_h, "\n#endif\n\n");
00312     
00313     fclose(fin);
00314     fclose(fout_v);
00315     fclose(fout_d);
00316     fclose(fout_h);
00317 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix