Keywords: xcoral

Next: version.sc Up: SmacLib Previous: top-ten.sc

# utilities.sc

This file contains some general functions frequently used in SMACLIB.

- char *basename(char *path); extracts a filename from a full pathname. This function uses the UNIX basename command.

  Attention Be careful, the string is allocated each time the function is called, use free() to release it.

- char *dirname(char *path); extracts a dirname from a full pathname. This function uses the UNIX dirname command.

  Attention Be careful, the string is allocated each time the function is called, use free() to release it.

- void insert_chars(int n, char repeated_char); inserts at the current position n times repeated_char.
- void delete_chars(int ndel); deletes forward ndel characters from the current position.
- void delete_to_beginning_of_line(); deletes characters from the current position to the beginning of the line.
- void delete_to_end_of_line(); deletes characters from the current position to the end of the line.
- void delete_region(int start, int end); deletes characters from start position to end position.
- int does_file_exist(char *filename); returns True if the file filename exist.
- int does_unix_command_exist(char *unix_cmd); returns True if the command unix_cmd exists.
- void print_ascii(); prints the characters from 0 to 255 with the current font.
- void change_return_to_newline(); replaces `\`r with `\`n from the current position to the end of file.
- char * concat(char *s1, char *s2); returns a string which is the concatenation of s1 and s2.

  Attention Be careful, the string is allocated each time the function is called, use free() to release it.

- char *substring (char *s, int n, int m); returns m characters from position n in s (i.e. substring ("chapeau", 2, 3) = "ape").

  Attention Be careful, the string is allocated each time the function is called, use free() to release it.

- char* file_type(char* filename); returns the type of the f ile filename. This function uses the UNIX file command.

  Examples:

  - file_type("smaclib.tex") returns the string ascii text
  - file_type("/bin/ls") returns the string mc68020 pure dynamically linked executable (on a SUN 3/60).

- int is_dir(char* filename); returns True if filename is a directory.
- int is_file(char* filename); returns True if filename is a regular file (i.e. not a directory nor a link, socket or special).
- void wait_for_file(char *filename); waits until the file filename be present.
- void wait_for_nofile(char *filename); waits until the file filename be removed.
- void purge(); closes all text windows which content are already saved.
- char* window_substring(int start, int end); extracts a string in the current window from start position to end position.

  Attention Be careful, the string is allocated each time the function is called, use free() to release it.

- void center_line(); centers the current line within a width of 80 characters.
- void center_line_within(int width); centers the current line within a width of width characters.
- void delete_line_blanks(); deletes blanks and tabs just before current position and behind if current character is a blank or a tab.
- void just_one_blank(); calls the previous function and inserts a blank.
- void delete_previous_char(); deletes the previous character preceding the current position.
- int gets_string_cancelled(char* str); returns True if the string str is neither null nor equal to `^`g (ASCII code 7). Useful after a call to the gets functions.
- int is_num(char *str); returns True if the string str is numeric (12.34 is valid).
- int read_int_from_string(char* str); reads an int from the string str and returns it.
- void recenter(); recenters current position vertically in window.
- void sleep(s); waits s seconds.
- void transpose_chars(); transpose current and preceding character.

Next: version.sc Up: SmacLib Previous: top-ten.sc