multi.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "sam.h"
  10. List file = { 'p' };
  11. ushort tag;
  12. File *
  13. newfile(void)
  14. {
  15. File *f;
  16. f = fileopen();
  17. inslist(&file, 0, f);
  18. f->tag = tag++;
  19. if(downloaded)
  20. outTs(Hnewname, f->tag);
  21. /* already sorted; file name is "" */
  22. return f;
  23. }
  24. int
  25. whichmenu(File *f)
  26. {
  27. int i;
  28. for(i=0; i<file.nused; i++)
  29. if(file.filepptr[i]==f)
  30. return i;
  31. return -1;
  32. }
  33. void
  34. delfile(File *f)
  35. {
  36. int w = whichmenu(f);
  37. if(w < 0) /* e.g. x/./D */
  38. return;
  39. if(downloaded)
  40. outTs(Hdelname, f->tag);
  41. dellist(&file, w);
  42. fileclose(f);
  43. }
  44. void
  45. fullname(String *name)
  46. {
  47. if(name->n > 0 && name->s[0]!='/' && name->s[0]!=0)
  48. Strinsert(name, &curwd, (Posn)0);
  49. }
  50. void
  51. fixname(String *name)
  52. {
  53. String *t;
  54. char *s;
  55. fullname(name);
  56. s = Strtoc(name);
  57. if(strlen(s) > 0)
  58. s = cleanname(s);
  59. t = tmpcstr(s);
  60. Strduplstr(name, t);
  61. free(s);
  62. freetmpstr(t);
  63. if(Strispre(&curwd, name))
  64. Strdelete(name, 0, curwd.n);
  65. }
  66. void
  67. sortname(File *f)
  68. {
  69. int i, cmp, w;
  70. int dupwarned;
  71. w = whichmenu(f);
  72. dupwarned = FALSE;
  73. dellist(&file, w);
  74. if(f == cmd)
  75. i = 0;
  76. else{
  77. for(i=0; i<file.nused; i++){
  78. cmp = Strcmp(&f->name, &file.filepptr[i]->name);
  79. if(cmp==0 && !dupwarned){
  80. dupwarned = TRUE;
  81. warn_S(Wdupname, &f->name);
  82. }else if(cmp<0 && (i>0 || cmd==0))
  83. break;
  84. }
  85. }
  86. inslist(&file, i, f);
  87. if(downloaded)
  88. outTsS(Hmovname, f->tag, &f->name);
  89. }
  90. void
  91. state(File *f, int cleandirty)
  92. {
  93. if(f == cmd)
  94. return;
  95. f->unread = FALSE;
  96. if(downloaded && whichmenu(f)>=0){ /* else flist or menu */
  97. if(f->mod && cleandirty!=Dirty)
  98. outTs(Hclean, f->tag);
  99. else if(!f->mod && cleandirty==Dirty)
  100. outTs(Hdirty, f->tag);
  101. }
  102. if(cleandirty == Clean)
  103. f->mod = FALSE;
  104. else
  105. f->mod = TRUE;
  106. }
  107. File *
  108. lookfile(String *s)
  109. {
  110. int i;
  111. for(i=0; i<file.nused; i++)
  112. if(Strcmp(&file.filepptr[i]->name, s) == 0)
  113. return file.filepptr[i];
  114. return 0;
  115. }