home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / MAKETAGS.E < prev    next >
Text File  |  1995-04-01  |  17KB  |  455 lines

  1. compile if not defined(SMALL)  -- If SMALL not defined, then being separately
  2.  define INCLUDING_FILE = 'MAKETAGS.E'
  3. const
  4.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  5.  
  6.  compile if not defined(SITE_CONFIG)
  7.     const SITE_CONFIG = 'SITECNF.E'
  8.  compile endif
  9.  compile if SITE_CONFIG
  10.     tryinclude SITE_CONFIG
  11.  compile endif
  12.  
  13. const
  14.  compile if not defined(NLS_LANGUAGE)
  15.    NLS_LANGUAGE = 'ENGLISH'
  16.  compile endif
  17. include NLS_LANGUAGE'.e'
  18. include 'stdconst.e'
  19.  compile if EVERSION >= 6
  20.    EA_comment 'This defines the MAKETAGS command; it is intended to be executed directly.'
  21.  compile endif
  22. compile endif
  23.  
  24. compile if not defined(SHOW_EACH_PROCEDURE)
  25. const SHOW_EACH_PROCEDURE = 0
  26. compile endif
  27.  
  28. compile if not defined(TRACE_TIMES)
  29.    const TRACE_TIMES = 0
  30. compile endif
  31.  
  32. compile if not defined(LOG_TAG_MATCHES)
  33.    const LOG_TAG_MATCHES = 0
  34. compile endif
  35.  
  36. defmain
  37.    'maketags' arg(1)
  38.  
  39. defc maketags
  40. compile if LOG_TAG_MATCHES
  41.    universal TAG_LOG_FID
  42. compile endif
  43.    universal tags_fileid
  44.    if arg(1)='' | arg(1)='?' then
  45.       sayerror 'Args:  [@]file ...   where @ specifies list file.'
  46.       return
  47.    endif
  48.    params=arg(1)
  49.    if params='*' then
  50.       parse value entrybox(MAKETAGS__MSG '-' tags_filename(),
  51.              '/'OK__MSG'/'Cancel__MSG'/'Help__MSG'/',
  52.              checkini(0, 'MAKETAGS_PARM', ''),'',200,
  53.              atoi(1) || atoi(6080) || gethwndc(APP_HANDLE) ||
  54.              MAKETAGS_PROMPT__MSG) with button 2 params \0
  55.       if button<>\1 then return; endif
  56.    endif
  57.    if params<>'' & params<>'=' then
  58.       call setini('MAKETAGS_PARM', params)
  59.    endif
  60.    prev_file = .filename
  61. compile if LOG_TAG_MATCHES
  62.    'xcom e /c tags.log'
  63.    if rc<>-282 then  -- -282 = sayerror("New file")
  64.       return
  65.    endif
  66.    getfileid TAG_LOG_FID
  67.    .autosave=0
  68.    parse value getdate(1) with today';' .  /* Discard MonthNum. */
  69.    parse value gettime(1) with now';' .    /* Discard Hour24. */
  70.    replaceline 'MakeTags started at' now 'on' today':' params
  71.    .filename = 'tags.log'
  72.    .modify = 0
  73. compile endif
  74.    'xcom e /d' tags_filename()
  75.    if rc<>0 & rc<>-282 then  -- -282 = sayerror("New file")
  76.       return
  77.    endif
  78.    if rc=-282 then
  79.       delete
  80.    endif
  81.    -- Defer this until after tags file loaded, because TagsFileList might want
  82.    -- to edit the tags file in order to check its EPM.TAGSARGS EA
  83.    if arg(1) = '=' then
  84.       params = TagsFileList(.filename)
  85.       if params='' then
  86.          sayerror 'MakeTags parameters could not be determined.'
  87.          return
  88.       endif
  89.       call setini('MAKETAGS_PARM', params)
  90.    endif
  91.    original_arg = params
  92.    msgl_on_off = queryframecontrol(2)   -- Remember if messageline on or off
  93.    'toggleframe 2 1'                    -- Force it on
  94.    'setmessageline' MAKETAGS_PROCESSING__MSG
  95.    oldfile = .last  -- will be 0 (FALSE) if new file
  96.    .autosave=0
  97.    .modify = 0
  98.    getfileid tag_fid
  99.    list_fid=''; list_stack=''
  100.    status=0
  101.    filecount = 0; skipped = 0
  102.    path_prefix=''
  103.    loop
  104.       if list_fid<>'' then  -- We're processing a file containing a list of files
  105.          activatefile list_fid
  106.          if .line = .last then
  107.             'quit'
  108.             parse value list_stack with list_fid path_prefix list_stack
  109.             iterate
  110.          endif
  111.          '+1'
  112.          getline params
  113.          activatefile tag_fid
  114.       endif
  115.       filename=parse_file(params, prev_file, listflag)
  116.       if listflag then  /* specify list? */
  117.          If not(verify(filename,'\:','M')) then
  118.             filename=path_prefix||filename
  119.          endif
  120.          'e /d' filename
  121.          if rc then
  122.             if rc=-282 then  -- -282 = sayerror("New file")
  123.                'quit'
  124.                msg="'"filename"' not found."
  125.             else
  126.                msg=sayerrortext(rc)
  127.             endif
  128.             sayerror "Error reading list '"filename"'.  "msg
  129.             status=1
  130.             leave
  131.          endif
  132.          prev_file = .filename
  133.          list_stack=list_fid path_prefix list_stack
  134.          getfileid list_fid
  135.          path_prefix=substr(.filename,1,lastpos('\', .filename))
  136.          '0'
  137.          iterate
  138.       endif
  139.       if filename='' then
  140.          leave
  141.       endif
  142.       If not(verify(filename,'\:','M')) then
  143.          filename=path_prefix||filename
  144.       endif
  145.       if verify(filename,'?*','M') then  -- If wildcards
  146.          wildcards = 1
  147.          wild_prefix=substr(filename,1,lastpos('\', filename))
  148.          namez    = filename\0    -- ASCIIZ
  149.          resultbuf = copies(\0, 300)  -- Might need to allocate a buffer if < EPM 5.60
  150.          attribute = 1         -- Want to see normal & read-only file entries
  151. compile if EVERSION >= 6  -- EPM32:  32-bit version
  152.          searchcnt = atol(1)   -- Search count; we're only asking for 1 file at a time here.
  153.          dirhandle = \xff\xff\xff\xff  -- Ask system to assign us a handle
  154.          result=dynalink32('DOSCALLS',             -- dynamic link library name
  155.                            '#264',                 -- ordinal value for DOS32FINDFIRST
  156.                            address(namez)      ||  -- Filename we're looking for
  157.                            address(dirhandle)  ||  -- Pointer to the handle
  158.                            atol(attribute)     ||  -- Attribute value describing desired files
  159.                            address(resultbuf)  ||  -- string address
  160.                            atol(length(resultbuf)) ||
  161.                            address(searchcnt)  ||  -- Pointer to the count; system updates
  162.                            atol(1), 2)             -- File info level 1 requested
  163. compile else
  164.          searchcnt = atoi(1)   -- Search count; we're only asking for 1 file at a time here.
  165.          dirhandle = \xff\xff  -- Ask system to assign us a handle
  166.          result=dynalink('DOSCALLS',             -- dynamic link library name
  167.                          '#64',                  -- ordinal value for DOSFINDFIRST
  168.                          address(namez)      ||  -- Filename we're looking for
  169.                          address(dirhandle)  ||  -- Pointer to the handle
  170.                          atoi(attribute)     ||  -- Attribute value describing desired files
  171.                          address(resultbuf)  ||  -- string address
  172.                          atoi(length(resultbuf)) ||
  173.                          address(searchcnt)  ||  -- Pointer to the count; system updates
  174.                          atol(0))               -- reserved
  175. compile endif -- EVERSION >= 6
  176.  
  177.          if result then
  178.                 if result = 2   then msg = 'FILE NOT FOUND'
  179.             elseif result = 3   then msg = 'PATH NOT FOUND'
  180.             elseif result = 6   then msg = 'INVALID HANDLE'
  181.             elseif result = 18  then msg = 'NO MORE FILES'
  182.             elseif result = 26  then msg = 'NOT DOS DISK'
  183.             elseif result = 87  then msg = 'INVALID PARAMETER'
  184.             elseif result = 108 then msg = 'DRIVE LOCKED'
  185.             elseif result = 111 then msg = 'BUFFER OVERFLOW'
  186.             elseif result = 113 then msg = 'NO MORE SEARCH HANDLES'
  187.             elseif result = 206 then msg = 'FILENAME EXCED RANGE'
  188.             endif
  189.             sayerror 'Error' result '('msg') for "'filename'"'
  190.             status=1
  191.             leave
  192.          endif
  193. compile if EVERSION >= 6  -- EPM32:  32-bit version
  194.          filename = wild_prefix || substr(resultbuf, 30, asc(substr(resultbuf, 29, 1)))
  195.          filedate = ltoa(substr(resultbuf, 13, 4), 16)
  196. compile else
  197.          filename = wild_prefix || substr(resultbuf, 24, asc(substr(resultbuf, 23, 1)))
  198.          filedate = ltoa(substr(resultbuf, 9, 4), 16)
  199. compile endif -- EVERSION >= 6
  200.       else
  201.          wildcards = 0
  202.          filedate = get_file_date(filename)
  203.       endif
  204.       loop
  205.          if oldfile then
  206.             getfileid tempfid
  207.             activatefile tag_fid
  208.             0
  209.             display -2
  210.             'xcom l /'filename'/c'
  211.             if rc then  -- Filename not found in existing tags file
  212.                verb = 'Adding'
  213.             else
  214.                parse_tagline(temp_proc, temp_name, temp_line, temp_date)
  215.                if temp_date=filedate then  -- Up-to-date
  216.                   verb = 'Skipping'
  217.                   skipped = skipped + 1
  218.                else
  219.                   verb = 'Refreshing'
  220.                   while not rc do
  221.                      delete
  222.                      begin_line
  223.                      repeat_find
  224.                   endwhile
  225.                endif
  226.             endif
  227.             display 2
  228.             activatefile tempfid
  229.          else
  230.             verb = 'Searching'
  231.          endif
  232. compile if TRACE_TIMES
  233.          if verb<>'Skipping' then
  234.             parse value gettime(1) with now';' .    /* Discard Hour24. */
  235.             'setmessageline' now '-' verb "'"filename"'..."
  236.          endif
  237. compile endif 
  238.          display -8
  239.          sayerror verb "'"filename"'..."
  240.          display 8
  241. compile if LOG_TAG_MATCHES
  242.          insertline '', TAG_LOG_FID.last+1, TAG_LOG_FID
  243.          if verb='Refreshing' then
  244.             tmp = ' (timestamp was' timestamp(temp_date)'; now' timestamp(filedate)') '
  245.          else
  246.             tmp = ''
  247.          endif
  248.          insertline verb "'"filename"'"tmp"...", TAG_LOG_FID.last+1, TAG_LOG_FID
  249. compile endif
  250.          if verb<>'Skipping' then
  251.             start_size = tag_fid.last
  252.             if add_tags(filename, tag_fid, filedate) then
  253.                status=1
  254.                leave
  255.             endif
  256.             filecount = filecount + 1
  257.             if start_size = tag_fid.last then  -- No tags added?  Record date anyway.
  258.                insertline '*' filename 0 filedate, tag_fid.last+1, tag_fid
  259.             endif
  260.          endif
  261.          if not wildcards then
  262.             leave
  263.          endif
  264. compile if EVERSION >= 6  -- EPM32:  32-bit version
  265.          result=dynalink32('DOSCALLS',             -- dynamic link library name
  266.                           '#265',                 -- ordinal value for DOS32FINDNEXT
  267.                           dirhandle           ||  -- Directory handle, returned by DosFindFirst(2)
  268.                           address(resultbuf)  ||  -- address of result buffer
  269.                           atol(length(resultbuf)) ||
  270.                           address(searchcnt), 2)  -- Pointer to the count; system updates
  271. compile else
  272.          result=dynalink('DOSCALLS',             -- dynamic link library name
  273.                          '#65',                  -- ordinal value for DOSFINDNEXT
  274.                          dirhandle           ||  -- Directory handle, returned by DosFindFirst(2)
  275.                          address(resultbuf)  ||  -- address of result buffer
  276.                          atoi(length(resultbuf)) ||
  277.                          address(searchcnt) )    -- Pointer to the count; system updates
  278. compile endif -- EVERSION >= 6
  279.          if result then
  280. compile if EVERSION >= 6  -- EPM32:  32-bit version
  281.             call dynalink32('DOSCALLS',             -- dynamic link library name
  282.                             '#263',                 -- ordinal value for DOS32FINDCLOSE
  283.                             dirhandle)              -- Directory handle, returned by DosFindFirst(2)
  284. compile else
  285.             call dynalink('DOSCALLS',             -- dynamic link library name
  286.                           '#63',                  -- ordinal value for DOSFINDCLOSE
  287.                           dirhandle)              -- Directory handle, returned by DosFindFirst(2)
  288. compile endif -- EVERSION >= 6
  289.             if result<>18 then
  290.                sayerror 'Unexpected error' result 'from DosFindNext'
  291.                status=1
  292.             endif
  293.             leave
  294.          endif
  295. compile if EVERSION >= 6  -- EPM32:  32-bit version
  296.          filename = wild_prefix || substr(resultbuf, 30, asc(substr(resultbuf, 29, 1)))
  297.          filedate = ltoa(substr(resultbuf, 13, 4), 16)
  298. compile else
  299.          filename = wild_prefix || substr(resultbuf, 24, asc(substr(resultbuf, 23, 1)))
  300.          filedate = ltoa(substr(resultbuf, 9, 4), 16)
  301. compile endif -- EVERSION >= 6
  302.       endloop
  303.       if status then
  304.          leave
  305.       endif
  306.    endloop
  307. compile if LOG_TAG_MATCHES
  308.    insertline '', TAG_LOG_FID.last+1, TAG_LOG_FID
  309.    insertline copies('=',72), TAG_LOG_FID.last+1, TAG_LOG_FID
  310.    parse value getdate(1) with today';' .  /* Discard MonthNum. */
  311.    parse value gettime(1) with now';' .    /* Discard Hour24. */
  312.    insertline 'MakeTags ended at' now 'on' today'.  Status =' status, TAG_LOG_FID.last+1, TAG_LOG_FID
  313. compile endif
  314.    'setmessageline '\0
  315.    'toggleframe 2' msgl_on_off
  316.    if status then
  317.       'quit'
  318.       return 1
  319.    endif
  320.    if not .last then
  321.       sayerror 'No tags found.'
  322. compile if LOG_TAG_MATCHES
  323.       insertline 'No tags found.', TAG_LOG_FID.last+1, TAG_LOG_FID
  324.       TAG_LOG_FID.modify = 0
  325. compile endif
  326.       return 1
  327.    endif
  328.    tagcount = .last
  329.    if tag_fid.modify then
  330.       sayerror 'Sorting' .last 'tags...'
  331.       call sort(1, .last, 1, 40, tag_fid, 'i')
  332.       call delete_ea('EPM.TAGSARGS')
  333.       'add_ea EPM.TAGSARGS' original_arg
  334.       already_loaded = 0
  335.       if tags_fileid then
  336.          if tags_fileid.filename = tag_fid.filename then
  337.             already_loaded = 1
  338.          endif
  339.       endif
  340.       if already_loaded then
  341.          activatefile tags_fileid
  342.          'quit'
  343.          activatefile tag_fid
  344.          tags_fileid = tag_fid  -- Update universal variable
  345.          'save'
  346.          if not rc then
  347.             .visible = 0
  348.             prevfile
  349.          endif
  350.       else
  351.          'file'
  352.       endif
  353.    else
  354.       'quit'  -- Must be an old tags file here, or we would have said "No tags found" above.
  355.       sayerror 'Tags file was up-to-date.  (Scanned' filecount 'files; skipped' skipped')'
  356. compile if LOG_TAG_MATCHES
  357.       insertline 'Tags file was up-to-date.  (Scanned' filecount 'files; skipped' skipped')', TAG_LOG_FID.last+1, TAG_LOG_FID
  358.       TAG_LOG_FID.modify = 0
  359. compile endif
  360.       return rc
  361.    endif
  362.    if oldfile then
  363.       sayerror 'Scanned' filecount 'files; skipped' skipped'; total number of tags now' tagcount '(was' oldfile')'
  364. compile if LOG_TAG_MATCHES
  365.       insertline 'Scanned' filecount 'files; skipped' skipped'; total number of tags now' tagcount '(was' oldfile')', TAG_LOG_FID.last+1, TAG_LOG_FID
  366.       TAG_LOG_FID.modify = 0
  367. compile endif
  368.    else
  369.       sayerror 'Found' tagcount 'tags in' filecount 'files.'
  370. compile if LOG_TAG_MATCHES
  371.       insertline 'Found' tagcount 'tags in' filecount 'files.', TAG_LOG_FID.last+1, TAG_LOG_FID
  372.       TAG_LOG_FID.modify = 0
  373. compile endif
  374.    endif
  375.    return rc
  376.  
  377.  
  378. defproc add_tags(filename, tag_fid, filedate)
  379.    'e /d' filename
  380.    if rc then
  381.       if rc=-282 then  -- -282 = sayerror("New file")
  382.          'quit'
  383.          msg='File not found.'
  384.       else
  385.          msg=sayerrortext(rc)
  386.       endif
  387.       sayerror 'Error reading file "'filename'".  'msg
  388.       return rc
  389.    endif
  390.    if verify(.filename, " '[]", 'M') then
  391.       filename='"'.filename'"'
  392.    else
  393.       filename=.filename
  394.    endif
  395.    ext=filetype()
  396.    if not tags_supported(ext) then
  397.       sayerror "Don't know how to do tags for file of type '"ext"'"
  398.       'quit'
  399.       return 1
  400.    endif
  401.    proc_name=''
  402.    rc=proc_search(proc_name,1,ext)
  403.    while not rc do
  404. compile if SHOW_EACH_PROCEDURE  -- Display progress messages
  405.       display -8
  406.       sayerror "...found '"proc_name"' in" filename
  407.       display 8
  408. compile endif
  409.       insertline proc_name filename .line filedate, tag_fid.last+1, tag_fid
  410.       proc_name=''
  411.       end_line
  412.       rc=proc_search(proc_name,0,ext)
  413.    endwhile
  414.    'quit'
  415.    return 0
  416.  
  417. defproc parse_file(var string, prev_file, var list_flag)
  418.    if leftstr(word(string,1),1)='@' then
  419.       list_flag = 1
  420.       parse value string with '@' string
  421.    else
  422.       list_flag = 0
  423.    endif
  424.    string=strip(string)
  425.    if leftstr(string,1)='"' then
  426.       end_quote=pos('"',string,2)
  427.       if not end_quote then
  428.          end_quote=length(string)
  429.       endif
  430.       file=substr(string,1,end_quote)
  431.       string=strip(substr(string,end_quote+1))
  432.    else
  433.       parse value string with file string
  434.       call parse_filename(file, prev_file)
  435.    endif
  436.    return file
  437.  
  438. compile if LOG_TAG_MATCHES
  439. defproc timestamp(ts)
  440.    hexes = '0123456789ABCDEF'
  441.    datetime = upcase(rightstr(ts, 8, '0'))
  442.    date = 0; time = 0
  443.    do i=1 to 4
  444.       time = 16 * time + pos(substr(datetime,   i, 1), hexes) - 1
  445.       date = 16 * date + pos(substr(datetime, 4+i, 1), hexes) - 1
  446.    enddo
  447.    year = date % 512; date = date // 512
  448.    month = date % 32; day = date // 32 % 1     -- %1 to drop fraction.
  449.    date = year+80'/'rightstr(month, 2, 0)'/'rightstr(day, 2, 0)
  450.    hour = time % 2048; time = time // 2048
  451.    min = time % 32; sec = time // 32 * 2 % 1
  452.    time = hour':'rightstr(min, 2, 0)':'rightstr(sec, 2, 0)
  453.    return date time
  454. compile endif
  455.