home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12266.ZIP / FNDFILE.C next >
C/C++ Source or Header  |  1989-04-27  |  3KB  |  125 lines

  1.  
  2. /*  Source code for FNDFILE.C */
  3.  
  4.  
  5. #define    INCL_ERRORS
  6.  
  7. #include    <stdio.h>
  8. #include    <stdlib.h>
  9. #include    <os2.h>
  10. #include    <dos.h>
  11. #include    <string.h>
  12.  
  13.  
  14. USHORT    far    _loadds    pascal debug(USHORT);
  15. USHORT    far    _loadds pascal do_find(PSZ, PHDIR, USHORT,
  16.         PFILEFINDBUF, USHORT, PUSHORT, ULONG);
  17. USHORT    far    _loadds pascal do_list(PSZ, PHDIR, USHORT,
  18.         PFILEFINDBUF, USHORT, PUSHORT, ULONG);
  19.  
  20. void    do_usage(void);
  21. void    main(void);
  22.  
  23. void
  24. show(PFILEFINDBUF f_ptr, USHORT cnt)
  25. {
  26.     while (cnt--)
  27.     {
  28.         printf("Len is: %2d. Filename is:%s\n",
  29.                 (int)(f_ptr->cchName), f_ptr->achName );
  30.         f_ptr = (PFILEFINDBUF) ((char far *)f_ptr + 24 +
  31.                 (int)(f_ptr->cchName));
  32.     }
  33. }
  34.  
  35. void
  36. do_usage()
  37. {
  38.     printf("\n\nexit        - to exit\n");
  39.     printf("file=<filename> - enter name of message file\ \n");
  40.     printf("hand=<val>      - 1 = default, 0xffff = create\  new handle\n");
  41.     printf("attrb=<attrb>   - Attributes: see pg 98 of Ref\  Manual\n");
  42.     printf("len=<buf_len>   - length of output buffer to\  use. Allocated\n");
  43.     printf("cnt=<cnt>       - Maximum number of files to\  return\n");
  44.     printf("debug=on|off    - turn debug mode on or\  off\n");
  45.     printf("show            - show buffer contents...\n");
  46.     printf("list            - show current parameter\  settings\n");
  47.     printf("go              - call DosFindFirst()\n");
  48. }
  49.  
  50. void
  51. main()
  52. {
  53. CHAR        tmp_buf[256];
  54. CHAR        name[64];
  55. USHORT    max_len = 0;
  56. char        *buf_ptr = (char *)NULL;
  57. HDIR        handle = 1;
  58. USHORT    attrb = 0;
  59. USHORT    num_files = 0;
  60.  
  61.     if(!debug(FALSE))
  62.     {
  63.         printf("Error in initial call to debug\n");
  64.         exit(1);
  65.     }
  66.     *name = (CHAR)NULL;
  67.     while(TRUE)
  68.     {
  69.         printf(">");
  70.         gets(tmp_buf);
  71.         strlwr(tmp_buf);
  72.         if(!strncmp(tmp_buf, "exit", 4))
  73.             exit(1);
  74.         else
  75.         if(!strncmp(tmp_buf, "file=", 5))
  76.             strcpy(name, tmp_buf + 5);
  77.         else
  78.         if(!strncmp(tmp_buf, "len=", 4))
  79.         {
  80.             if(buf_ptr)
  81.                 free(buf_ptr);
  82.             max_len = atoi(tmp_buf + 4);
  83.             buf_ptr = calloc(max_len, 1);
  84.         }
  85.         else
  86.         if(!strncmp(tmp_buf, "cnt=", 4))
  87.             num_files = atoi(tmp_buf + 4);
  88.         else
  89.         if(!strncmp(tmp_buf, "hand=", 5))
  90.             sscanf(tmp_buf + 5, "%x", &handle);
  91.         else
  92.         if(!strncmp(tmp_buf, "attrb=", 6))
  93.             sscanf(tmp_buf + 6, "%x", &attrb);
  94.         else
  95.         if(!strncmp(tmp_buf, "list", 4))
  96.             do_list(name, (PHDIR)&handle, attrb,
  97.             (PFILEFINDBUF)buf_ptr, max_len,
  98.             (PUSHORT)&num_files, (ULONG)0);
  99.         else
  100.         if(!strncmp(tmp_buf, "debug=", 6))
  101.         {
  102.             if(!debug(!strncmp(tmp_buf + 6, "on", 2)))
  103.             {
  104.                 printf("Error in subsequent call to\  debug\n");
  105.                 exit(1);
  106.             }
  107.         }
  108.         else
  109.         if(!strncmp(tmp_buf, "show", 4))
  110.             show((PFILEFINDBUF)buf_ptr, num_files);
  111.         else
  112.         if(!strncmp(tmp_buf, "go", 2))
  113.             do_find(name, (PHDIR)&handle, attrb,
  114.             (PFILEFINDBUF)buf_ptr, max_len,
  115.             (PUSHORT)&num_files, (ULONG)0);
  116.         else
  117.         if(*tmp_buf == '?')
  118.             do_usage();
  119.         else
  120.             printf("?Huh?\n");
  121.     }
  122.  
  123. }
  124.  
  125.