Results 1 to 4 of 4

Thread: Keywords, constants, UDTs and classes for each module

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Lightbulb Keywords, constants, UDTs and classes for each module

    Hello Eros,

    to make the idea proposed here possible, I created for you a clumsy, but working generator of list of all the module keywords, constants, UDTs and classes :P

    We have app_listKeywords, app_listEquates, app_listUdts and app_listClasses at disposal, however they list items for all currently imported modules.
    How to workaround it? I generate script for each of detected modules and execute it alone, with just that module used. And then I subtract the Core items, which I cannot filter out otherwise.

    Hellish? Yes. Works? Yes! :P
    uses "file", "os", "console", "ini"
    
    
    function TBMain()
      string moduleName()
      long moduleCount = module_getNames(moduleName)
      
      printl strformat$("Found {1} modules", moduleCount)
      
      ' -- Prepare and clean output directory
      string tokenExporterPath = app_sourcepath + "tokenExporters\"
      if not dir_exists(tokenExporterPath) then dir_make(tokenExporterPath)
      file_kill(tokenExporterPath+"*.*")
      
      ' -- Create generator scripts
      module_createCoreTokenExporter(tokenExporterPath)
      
      printl               
      print "Creating generator for "
      for i as long = 1 to moduleCount
        if moduleName(i) = "trace" then iterate for
        
        print moduleName(i) + iif$(i < moduleCount, ",", "") in 14
        module_createTokenExporter(tokenExporterPath, moduleName(i))
      next
      
      ' -- Launch generator scripts
      string generator()
      long generatorCount = dir_listarray(generator, tokenExporterPath, "*.tBasic", %FILE_NORMAL | %FILE_ADDPATH)
      
      printl
      printl
      print "Launching generator for "
      for i = 1 to generatorCount
        print moduleName(i) + iif$(i < moduleCount, ",", "") in 14
        os_shell(app_path + app_name + " " + generator(i), %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
      next
      
      ' -- Generate INI file
      string outputFile = app_sourcepath + "moduleTokens.ini"
      if file_exists(outputFile) then file_kill(outputFile)
      
      string csvFile()
      long csvFileCount = dir_listarray(csvFile, tokenExporterPath, "*.csv", %FILE_NORMAL | %FILE_ADDPATH)
      
      string coreKeywords()
      parse(file tokenExporterPath + "core.csv", coreKeywords, ",")
      
      string csvKeywords()
    
    
      printl
      printl
      print "Generating output file " + outputFile  
      for i = 1 to csvFileCount
        if endswith(csvFile(i), "\core.csv") then iterate for
        print "."
        
        parse(file csvFile(i), csvKeywords, ",")
        
        array_removeItems(csvKeywords, coreKeywords)
        ini_setKey(outputFile, "Modules", file_pathsplit(csvFile(i), %PATH_FILE), join$(csvKeywords, ",")) 
      next
      
      printl "DONE" in 10
      waitkey
    
    
    end function
    
    
    function module_getNames(byRef moduleName() as string) as long
    
    
      string modules()  
      long   moduleCount = dir_listarray(modules, app_path + "Lib", "thinBasic_*", %FILE_NORMAL)
      redim  moduleName(moduleCount)
      
      for i as long = 1 to moduleCount
        moduleName(i) = lcase$(modules(i))
        moduleName(i) = grab$(moduleName(i), "_", ".dll")
      next
      
      return moduleCount
    
    
    end function
    
    
    function module_createCoreTokenExporter(path as string)
    
    
      string fileName = path + "core_tokenExporter.tBasic"                                                                                          
                                                                         
      file_save(fileName, "save_file("""+path+"core.csv"", app_listKeywords("","") + "","" + app_listEquates("","") + "","" + app_listUdts("","") + app_listClasses("",""))")
    
    
    end function
    
    
    function module_createTokenExporter(path as string, moduleName as string)
    
    
      string fileName = path + moduleName + "_tokenExporter.tBasic"
                                
      file_save(fileName, "uses """+moduleName+"""
                           save_file("""+path+""+moduleName+".csv"", app_listKeywords("","") + "","" + app_listEquates("","") + "","" + app_listUdts("","") + app_listClasses("",""))")
    
    
    end function
    
    
    function array_removeItems(byRef baseArray() as string, byRef items() as string)
      string baseArrayContent = "," + join$(baseArray, ",") + ","
      
      string token
      for i as long = 1 to countof(items)
        token = ","+items(i)+"," 
        if instr(baseArrayContent, token) then
          baseArrayContent = replace$(baseArrayContent, token, ",")
        end if
      next
      
      baseArrayContent = trim$(baseArrayContent, ",")
      parse(baseArrayContent, baseArray, ",")
    end function
    
    Petr
    Last edited by Petr Schreiber; 08-02-2018 at 21:39.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. Doubt about classes in another module
    By kcvinu in forum Module Classes
    Replies: 10
    Last Post: 08-11-2016, 20:09
  2. Module classes
    By ErosOlmi in forum thinBasic vaporware
    Replies: 19
    Last Post: 02-12-2011, 12:15
  3. Article: Module classes
    By ErosOlmi in forum vBCms Comments
    Replies: 9
    Last Post: 30-06-2011, 16:38
  4. KeywordDocumenter, optional tool to document module keywords
    By Petr Schreiber in forum thinBasic SDK
    Replies: 6
    Last Post: 27-02-2011, 23:10

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •