home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / workbench / stickit2 / source.lha / source / utility.c < prev   
C/C++ Source or Header  |  1995-01-09  |  3KB  |  142 lines

  1. /***********************************************
  2.  **************   utility.c   ******************
  3.  ***********************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "consts.h"
  11. #include "structs.h"
  12. #include "proto.h"
  13.  
  14. extern prj_p prj;
  15.  
  16. /*
  17. Function : void remove_char_from_string(char *c)
  18. Purpose : c is a pointer to a character in a note->text string. The operation
  19.     is as follows:
  20.             string\0        tring\0
  21.              cp-^       ---> cp-^
  22. */
  23.  
  24. void remove_char_from_string(char *cp)
  25. {
  26.     int l = 0;
  27.  
  28.     /* Move characters down */
  29.  
  30.     while (cp[l] != '\0') {
  31.         cp[l] = cp[l + 1];
  32.         l++;
  33.     }
  34. }
  35.  
  36. /*
  37. Function : void add_char_to_string(char *cp,char c)
  38. Purpose : Given a pointer to a character in a string, adds the character c
  39.     in that position and moves the rest of the characters along. As
  40.     follows:
  41.             tring\0            string\0
  42.          cp-^          --->      cp-^
  43. */
  44.  
  45. void add_char_to_string(char *cp,char c)
  46. {
  47.     int l;
  48.  
  49.     for (l = strlen(cp); l >= 0; l--)
  50.         cp[l + 1] = cp[l];
  51.  
  52.     cp[0] = c;
  53. }
  54.  
  55. /*
  56. Function : int next_free_note()
  57. Purpose : Returns the position in the note pointer array of the next free note
  58.     position. Returns NO_FREE_NOTES if unsuccessful.
  59. */
  60.  
  61. int next_free_note()
  62. {
  63.     int l;
  64.  
  65.     for (l = 0; l < NO_NOTES; l++)
  66.         if (!(prj->notes[l]))
  67.             return(l);
  68.  
  69.     /* No notes free */
  70.  
  71.     return(NO_FREE_NOTES);
  72. }
  73.  
  74. /*
  75. Function : void replace_chrs(char *str,char chr_old,char chr_new)
  76. Purpose : Given a string, will replace the first occurance of chr_old with
  77.     chr_new.
  78. */
  79.  
  80. void replace_chrs(char *str,char chr_old,char chr_new)
  81. {
  82.     char *c;
  83.  
  84.     for (c = str; ((*c != '\0') && (*c != chr_old)); c++);
  85.  
  86.     if (*c == '\0')
  87.         return;
  88.  
  89.     if (*c == chr_old)
  90.         *c = chr_new;
  91. }
  92.  
  93. /*
  94. Function : void build_fontstring(note_p curr_note)
  95. Purpose : Build nice fontstring.
  96. */
  97.  
  98. void build_fontstring(note_p curr_note)
  99. {
  100.     char *c,temp_str[STRLEN_FONTNAME];
  101.     int n;
  102.  
  103.     if (curr_note->fontname[0] == '\0') {
  104.         curr_note->fontstring[0] = '\0';
  105.         return;
  106.     }
  107.  
  108.     c = strstr(curr_note->fontname,".font");
  109.  
  110.     if (!c) {
  111.         curr_note->fontstring[0] = '\0';
  112.         return;
  113.     }
  114.  
  115.     n = c-curr_note->fontname;
  116.     strncpy(temp_str,curr_note->fontname,n);
  117.     temp_str[n] = '\0';
  118.  
  119.     sprintf(curr_note->fontstring,"%s %d",temp_str,
  120. curr_note->textattr.ta_YSize);
  121. }
  122.  
  123. /*
  124. Function : int positionfromnote(note_p curr_note)
  125. Purpose : Given an array pointer, returns the position in the prj->notes[]
  126.     array. Returns NOT_IN_ARRAY if can't find it.
  127. */
  128.  
  129. int positionfromnote(note_p curr_note)
  130. {
  131.     int l;
  132.  
  133.     for (l = 0; l < NO_NOTES; l++) {
  134.         if (prj->notes[l] == curr_note)
  135.             return(l);
  136.     }
  137.  
  138.     /* Can't find it */
  139.  
  140.     return(NOT_IN_ARRAY);
  141. }
  142.