home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / cnvpciid.zip / CnvPciID.CMD
OS/2 REXX Batch file  |  2002-04-26  |  6KB  |  242 lines

  1. /* $Id: CnvPciID.CMD,v 1.2 2002/04/26 23:09:43 smilcke Exp $ */
  2.  
  3. /* Generates files from pci.ids
  4.    Copyright (c) 2001-2001 by Stefan Milcke
  5.                               Küferstraße 45
  6.                               28779 Bremen
  7.  
  8.    Datum der Erstellung: 06.10.2001
  9.    Letzte Aenderung am:  06.10.2001
  10. */
  11. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs';
  12. Call SysLoadFuncs;
  13.  
  14. Parse Arg dFile sFile .
  15.  
  16. If Length(dFile)<1 Then
  17. Do
  18.  Say "Usage: CnvPciID.CMD <TARGET_FILE> [<PCIID_FILE>]"
  19.  Say "       TARGET_FILE = Target file (pci-nc.c for BT drivers)"
  20.  Say "       PCIID_FILE  = List of pci id's (normally pci.ids)"
  21.  Exit
  22. End
  23.  
  24. If Length(Stream(dFile,'C','QUERY EXISTS'))>0 Then Call SysFileDelete dFile
  25. rc=Stream(dFile,'C','OPEN WRITE')
  26. If Length(sFile)<1 Then
  27. Do
  28.  rc=WritePartFromCmd(dFile,'common_head')
  29.  rc=WritePartFromCmd(dFile,'foot_nonames')
  30.  rc=WritePartFromCmd(dFile,'common_foot')
  31.  rc=Stream(dFile,'C','CLOSE')
  32.  Exit
  33. End
  34. rc=Stream(sFile,'C','OPEN READ')
  35.  
  36. /* Write structure definitions */
  37. rc=WritePartFromCmd(dFile,'common_head')
  38. rc=WritePartFromCmd(dFile,'head_fullnames')
  39.  
  40. vendor.0=0
  41. device.0=0
  42. subsys.0=0
  43. class.0=0
  44. dn=0
  45.  
  46. Line=NextValidLine(sFile,'')
  47.  
  48. Do While(Lines(sFile))
  49.  If Lines(sFile)>0 Then
  50.  Do
  51.   If Left(Line,1)='C' Then
  52.   Do
  53.    Line=NextValidLine(sFile,LineIn(sFile))
  54.    Do While Left(Line,1)=D2C(9)
  55.     Line=NextValidLine(sFile,LineIn(sFile))
  56.    End
  57.   End
  58.   Else
  59.   Do
  60.    v=vendor.0+1
  61.    vendor.0=v
  62.    vendor.v.id='0x'Left(Line,4)
  63.    vendor.v.name=Translate(Right(Line,Length(Line)-6),',','"')
  64.    vendor.v.firstd=dn
  65.    vendor.v.lastd=dn
  66.    Line=NextValidLine(sFile,LineIn(sFile))
  67.    Do While(Lines(sFile) & Left(Line,1)=D2C(9) )
  68.     Do While Left(Line,2)=D2C(9)D2C(9)
  69.      s=subsys.0+1
  70.      subsys.0=s
  71.      subsys.s.vendorid=vendor.v.id
  72.      subsys.s.deviceid=device.d.id
  73.      subsys.s.vid=Right(Left(Line,6),4)
  74.      subsys.s.did=Right(Left(Line,10),4)
  75.      subsys.s.name=Translate(Right(Line,Length(Line)-13),',','"')
  76.      Line=NextValidLine(sFile,LineIn(sFile))
  77.     End
  78.     d=device.0+1
  79.     dn=dn+1
  80.     vendor.v.lastd=dn
  81.     device.0=d
  82.     device.d.vendorid=vendor.v.id
  83.     device.d.id='0x'Right(Left(Line,5),4)
  84.     device.d.name=Translate(Right(Line,Length(Line)-7),',','"')
  85.     Line=NextValidLine(sFile,LineIn(sFile))
  86.    End
  87.   End
  88.  End
  89. End
  90.  
  91. rc=LineOut(dFile,'/* List of all known devices */')
  92. rc=LineOut(dFile,'static struct pci_device_info devices[]= {')
  93. Do i=1 To device.0
  94.  rc=LineOut(dFile,' {'device.i.id',0,"'device.i.name'"},')
  95. End
  96. rc=LineOut(dFile,'};')
  97. rc=LineOut(dFile,'')
  98. rc=LineOut(dFile,'/* List of all known vendors */')
  99. rc=LineOut(dFile,'static struct pci_vendor_info vendors[]= {')
  100. Do i=1 To vendor.0
  101.  If vendor.i.lastd=vendor.i.firstd Then
  102.  Do
  103.   rc=LineOut(dFile,' {'vendor.i.id',0,"'vendor.i.name'",0,0},')
  104.  End
  105.  Else
  106.  Do
  107.   rc=LineOut(dFile,' {'vendor.i.id',0,"'vendor.i.name'",'vendor.i.lastd-vendor.i.firstd',&(devices['vendor.i.firstd'])},')
  108.  End
  109. End
  110. rc=LineOut(dFile,'};')
  111.  
  112. rc=WritePartFromCmd(dFile,'foot_fullnames')
  113. rc=WritePartFromCmd(dFile,'common_foot')
  114.  
  115. Exit
  116.  
  117. NextValidLine: Procedure
  118.  sFile=Arg(1)
  119.  Line=Arg(2)
  120.  Do While( Lines(sFile) & (Length(Line)=0 | Left(Line,1)='#') )
  121.   Line=LineIn(sFile)
  122.  End
  123. Return Line
  124.  
  125. WritePartFromCmd: Procedure
  126.  dFile=Arg(1)
  127.  delim=Arg(2)
  128.  rc=0
  129.  Do i=1 To SourceLine()
  130.   If SourceLine(i)='<'delim'>' Then
  131.   Do
  132.    rc=1
  133.    i=i+1
  134.    Do While (SourceLine(i)<>'</'delim'>') & i<SourceLine()
  135.     rc=LineOut(dFile,SourceLine(i))
  136.     i=i+1
  137.    End
  138.    Leave
  139.   End
  140.  End
  141. Return rc
  142.  
  143. /* The following lines are copied to the generated source */
  144. <common_head>
  145. /*
  146.  * pci-nc.c
  147.  * Autor:    Automatic generation from CnvPciID.CMD
  148.  *
  149.  *
  150. */
  151.  
  152. #include <linux/types.h>
  153. #include <linux/kernel.h>
  154. #include <linux/pci.h>
  155. #include <linux/init.h>
  156.  
  157. struct pci_device_info
  158. {
  159.  unsigned short device;
  160.  unsigned short seen;
  161.  const char *name;
  162. };
  163.  
  164. struct pci_vendor_info
  165. {
  166.  unsigned short vendor;
  167.  unsigned short nr;
  168.  const char *name;
  169.  unsigned short num_devices;
  170.  struct pci_device_info *devices;
  171. };
  172.  
  173. </common_head>
  174.  
  175. <head_fullnames>
  176. #ifdef FULLPCINAMES_INTERNALLY
  177. </head_fullnames>
  178.  
  179. <foot_fullnames>
  180.  
  181. #define VENDORS (sizeof(vendors)/sizeof(struct pci_vendor_info))
  182. #define DEVICES (sizeof(devices)/sizeof(struct pci_device_info))
  183. static int num_pci_device_infos=DEVICES;
  184. static int num_pci_vendor_infos=VENDORS;
  185.  
  186. #else
  187.  
  188. static struct pci_device_info *devices=0;
  189. static struct pci_vendor_info *vendors=0;
  190. static int num_pci_device_infos=0;
  191. static int num_pci_vendor_infos=0;
  192.  
  193. #endif // FULLPCINAMES
  194.  
  195. </foot_fullnames>
  196.  
  197. <foot_nonames>
  198. static struct pci_device_info *devices=0;
  199. static struct pci_vendor_info *vendors=0;
  200. static int num_pci_device_infos=0;
  201. static int num_pci_vendor_infos=0;
  202.  
  203. </foot_nonames>
  204.  
  205. <common_foot>
  206. void pci_name_device_init(char __far *pci_list_file)
  207. {
  208. }
  209.  
  210. void pci_name_device_free(void)
  211. {
  212. }
  213.  
  214. void pci_name_device(struct pci_dev *dev)
  215. {
  216.  int i=0;
  217.  struct pci_device_info *pdev=(struct pci_device_info *)0;
  218.  struct pci_vendor_info *pven=vendors;
  219.  for(i=0;i<num_pci_vendor_infos;i++,pven++)
  220.   if(pven->vendor==dev->vendor)
  221.    goto match_vendor;
  222.  sprintf(dev->name,"PCI device %04x:%04x",dev->vendor,dev->device);
  223.  return;
  224. match_vendor:
  225.  {
  226.   pdev=pven->devices;
  227.   for(i=0;i<pven->num_devices;i++)
  228.   {
  229.    if(pdev->device==dev->device)
  230.     goto match_device;
  231.    pdev++;
  232.   }
  233.   sprintf(dev->name,"PCI device %04x:%04x (%s)",dev->vendor,dev->device,pven->name);
  234.   return;
  235.  }
  236. match_device:
  237.  sprintf(dev->name,"%s %s",pven->name,pdev->name);
  238.  pdev->seen=pdev->seen+1;
  239. }
  240.  
  241. </common_foot>
  242.