diskspace.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
  3. * http://www.trevorwishart.co.uk
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <sfsys.h>
  25. #include <math.h>
  26. #include <osbind.h>
  27. char errstr[2400];
  28. #define MONO (1)
  29. #define STEREO (2)
  30. #define ENDOFSTR ('\0')
  31. #define LEAVESPACE (10*1024)
  32. void splice_multiline_string(char *str,char *prefix);
  33. const char* cdp_version = "7.1.0";
  34. /*RWD Jan 2014 updated getdrivefreespace(), corrected INFO output format for unsigned long */
  35. /************************************ CHECK_AVAILABLE_DISKSPACE ********************************/
  36. int main(int argc,char *argv[])
  37. {
  38. double srate, secs, mins, hrs;
  39. unsigned int outsamps = 0, orig_outsamps;
  40. int m, k, kk, spacecnt;
  41. char temp[800];
  42. unsigned int freespace = getdrivefreespace(/*"temp"*/".") - LEAVESPACE;
  43. unsigned int start = hz1000();
  44. if((argc==2) && strcmp(argv[1],"--version")==0) {
  45. fprintf(stdout,"%s\n",cdp_version);
  46. fflush(stdout);
  47. return 0;
  48. }
  49. //start = hz1000();
  50. if(argc!=2) {
  51. fprintf(stdout,"ERROR: Cannot run this process.\n");
  52. fflush(stdout);
  53. //TW UPDATE
  54. while(!(hz1000() - start))
  55. ;
  56. return 1;
  57. }
  58. if(sscanf(argv[1],"%lf",&srate)!=1) {
  59. fprintf(stdout,"ERROR: Cannot read sample rate.\n");
  60. fflush(stdout);
  61. //TW UPDATE
  62. while(!(hz1000() - start))
  63. ;
  64. return 1;
  65. }
  66. sprintf(errstr,"AVAILABLE DISK SPACE\n");
  67. sprintf(temp,"%u",freespace);
  68. strcat(errstr,temp);
  69. spacecnt = 13 - strlen(temp);
  70. for(k=0;k<spacecnt;k++)
  71. strcat(errstr," ");
  72. strcat(errstr,"bytes\n");
  73. splice_multiline_string(errstr,"INFO:");
  74. fflush(stdout);
  75. kk = 0;
  76. while (kk < 4) {
  77. errstr[0] = ENDOFSTR;
  78. switch(kk) {
  79. case(0): outsamps = freespace/2; break;
  80. case(1): outsamps = freespace/3; break;
  81. case(2): outsamps = freespace/4; break;
  82. case(3): outsamps = freespace/sizeof(float); break;
  83. }
  84. sprintf(temp,"%d",outsamps);
  85. strcat(errstr,temp);
  86. spacecnt = 13 - strlen(temp);
  87. for(k=0;k<spacecnt;k++)
  88. strcat(errstr," ");
  89. switch(kk) {
  90. case(0): strcat(errstr,"16-bit samples\n"); break;
  91. case(1): strcat(errstr,"24-bit samples\n"); break;
  92. case(2): strcat(errstr,"32-bit samples\n"); break;
  93. case(3): strcat(errstr,"float samples\n"); break;
  94. }
  95. orig_outsamps = outsamps;
  96. for(m=MONO;m<=STEREO;m++) {
  97. switch(m) {
  98. case(MONO):
  99. outsamps = orig_outsamps;
  100. sprintf(temp,"IN MONO : ");
  101. strcat(errstr,temp);
  102. break;
  103. case(STEREO):
  104. outsamps /= 2;
  105. sprintf(temp,"IN STEREO : ");
  106. strcat(errstr,temp);
  107. break;
  108. }
  109. secs = (double)outsamps/srate;
  110. mins = floor(secs/60.0);
  111. secs -= mins * 60.0;
  112. hrs = floor(mins/60.0);
  113. mins -= hrs * 60.0;
  114. if(hrs > 0.0) {
  115. sprintf(temp,"%.0lf",hrs);
  116. strcat(errstr,temp);
  117. spacecnt = 3 - strlen(temp);
  118. for(k=0;k<spacecnt;k++)
  119. strcat(errstr," ");
  120. strcat(errstr,"hours ");
  121. } else {
  122. for(k=0;k<4 + (int)strlen("hours");k++)
  123. strcat(errstr," ");
  124. }
  125. if(mins > 0.0) {
  126. sprintf(temp,"%.0lf",mins);
  127. strcat(errstr,temp);
  128. spacecnt = 3 - strlen(temp);
  129. for(k=0;k<spacecnt;k++)
  130. strcat(errstr," ");
  131. strcat(errstr,"mins ");
  132. } else {
  133. for(k=0;k<4 + (int)strlen("mins");k++)
  134. strcat(errstr," ");
  135. }
  136. sprintf(temp,"%.3lf",secs);
  137. strcat(errstr,temp);
  138. spacecnt = 7 - strlen(temp);
  139. for(k=0;k<spacecnt;k++)
  140. strcat(errstr," ");
  141. strcat(errstr,"secs\n");
  142. }
  143. splice_multiline_string(errstr,"INFO:");
  144. fflush(stdout);
  145. kk++;
  146. }
  147. //TW UPDATE
  148. while(!(hz1000() - start))
  149. ;
  150. return 0;
  151. }
  152. /****************************** SPLICE_MULTILINE_STRING ******************************/
  153. void splice_multiline_string(char *str,char *prefix)
  154. {
  155. char *p, *q, c;
  156. p = str;
  157. q = str;
  158. while(*q != ENDOFSTR) {
  159. while(*p != '\n' && *p != ENDOFSTR)
  160. p++;
  161. c = *p;
  162. *p = ENDOFSTR;
  163. fprintf(stdout,"%s %s\n",prefix,q);
  164. *p = c;
  165. if(*p == '\n')
  166. p++;
  167. while(*p == '\n') {
  168. fprintf(stdout,"%s \n",prefix);
  169. p++;
  170. }
  171. q = p;
  172. p++;
  173. }
  174. }