Changeset 38cf544c


Ignore:
Timestamp:
Jun 4, 2003, 12:04:54 AM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
96f8e5b
Parents:
fd93b41
Message:
Added the 'startup' and 'unstartup' commands
The $HOME/.owl directory is created on startup if it does not exist
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rfd93b41 r38cf544c  
    8282          WORK yet
    8383        Removed a bit of faim code that allowed commands to be executed.
    84        
     84        The 'B' key is now bound to 'alist'
     85        Added the 'startup' and 'unstartup' commands
     86        The $HOME/.owl directory is created on startup if it does not exist
    8587       
    86881.2.8
  • buddylist.c

    raa5f725 r38cf544c  
    7272
    7373void owl_buddylist_clear(owl_buddylist *b) {
    74   int i, j;
    75 
    7674  owl_list_free_all(&(b->buddies), owl_free);
    7775  owl_list_create(&(b->buddies));
  • commands.c

    rfd93b41 r38cf544c  
    159159              "are used print the value of all variables.\n"),
    160160
     161  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
     162              "run a command and set it to be run at every Owl startup",
     163              "startup <commands> ...",
     164              "Everything on the command line after the startup command\n"
     165              "is executed as a normal owl command and is also placed in\n"
     166              "a file so that the command is executed every time owl\n"
     167              "is started"),
     168
     169  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
     170              "remove a command from the list of those to be run at Owl startup",
     171              "unstartup <commands> ...",
     172              ""),
     173
    161174  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
    162175              "print the version of the running owl", "", ""),
     
    201214              "add a buddy to a buddylist",
    202215              "addbuddy aim <screenname>",
    203               "Add the named buddy to your buddylist.  Eventually other protocols,"
    204               "such as zephyr, will also be able to use this command.  For now the"
     216              "Add the named buddy to your buddylist.  Eventually other protocols,\n"
     217              "such as zephyr, will also be able to use this command.  For now the\n"
    205218              "only available protocol is 'aim', specified as the first argument."),
    206219
     
    208221              "delete a buddy from a buddylist",
    209222              "delbuddy aim <screenname>",
    210               "Delete the named buddy to your buddylist.  Eventually other protocols,"
    211               "such as zephyr, will also be able to use this command.  For now the"
    212               "only available protocol is 'aim', specified as the first argument."),
     223              "Delete the named buddy to your buddylist.  Eventually other protocols,\n"
     224              "such as zephyr, will also be able to use this command.  For now the\n"
     225              "only available protocol is 'aim', specified as the first argument.\n"),
    213226
    214227  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
     
    909922  owl_aim_delbuddy(argv[2]);
    910923  owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
     924
     925  return(NULL);
     926}
     927
     928char *owl_command_startup(int argc, char **argv, char *buff)
     929{
     930  char *ptr;
     931
     932  if (argc<2) {
     933    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
     934    return(NULL);
     935  }
     936
     937  /* we'll be pedantic here, just in case this command gets another name
     938   *  (or is aliased) start after the first space on the line
     939   */
     940  ptr=strchr(buff, ' ');
     941  if (!ptr) {
     942    owl_function_makemsg("Parse error finding command for startup");
     943    return(NULL);
     944  }
     945
     946  owl_function_command(ptr+1);
     947  owl_function_addstartup(ptr+1);
     948
     949  return(NULL);
     950}
     951
     952char *owl_command_unstartup(int argc, char **argv, char *buff)
     953{
     954  char *ptr;
     955
     956  if (argc<2) {
     957    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
     958    return(NULL);
     959  }
     960
     961  /* we'll be pedantic here, just in case this command gets another name
     962   *  (or is aliased) start after the first space on the line
     963   */
     964  ptr=strchr(buff, ' ');
     965  if (!ptr) {
     966    owl_function_makemsg("Parse error finding command for unstartup");
     967    return(NULL);
     968  }
     969
     970  owl_function_delstartup(ptr+1);
    911971
    912972  return(NULL);
  • functions.c

    raa5f725 r38cf544c  
    28952895  printf("\033[1t");
    28962896}
     2897
     2898/* Add the specified command to the startup file.  Eventually this
     2899 * should be clever, and rewriting settings that will obviosly
     2900 * override earlier settings with 'set' 'bindkey' and 'alias'
     2901 * commands.  For now though we just append to the startupfile.
     2902 */
     2903void owl_function_addstartup(char *buff)
     2904{
     2905  FILE *file;
     2906  char *filename;
     2907
     2908  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     2909  file=fopen(filename, "a");
     2910  owl_free(filename);
     2911  if (!file) {
     2912    owl_function_makemsg("Error opening startupfile for new command");
     2913    return;
     2914  }
     2915  fprintf(file, "%s\n", buff);
     2916  fclose(file);
     2917}
     2918
     2919/* Remove the specified command from the startup file. */
     2920void owl_function_delstartup(char *buff)
     2921{
     2922  char *filename;
     2923  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     2924  owl_util_file_deleteline(filename, buff, 1);
     2925  owl_free(filename);
     2926}
     2927
     2928void owl_function_execstartup(void)
     2929{
     2930  FILE *file;
     2931  char *filename;
     2932  char buff[LINE];
     2933
     2934  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     2935  file=fopen(filename, "r");
     2936  owl_free(filename);
     2937  if (!file) {
     2938    /* just fail silently if it doesn't exist */
     2939    return;
     2940  }
     2941  while (fgets(buff, LINE, file)!=NULL) {
     2942    buff[strlen(buff)-1]='\0';
     2943    owl_function_command(buff);
     2944  }
     2945  fclose(file);
     2946}
  • keys.c

    raa5f725 r38cf544c  
    242242  BIND_CMD("i",   "info",             "");
    243243  BIND_CMD("l",   "blist",            "");
     244  BIND_CMD("B",   "alist",            "");
    244245  BIND_CMD("M",   "pop-message",      "");
    245246  BIND_CMD("T",   "delete trash",     "mark all 'trash' messages for deletion");
  • owl.c

    r3abf28b r38cf544c  
    2222#include <sys/param.h>
    2323#include <sys/types.h>
     24#include <sys/stat.h>
    2425#include "owl.h"
    2526
     
    3738  time_t nexttime, now;
    3839  struct tm *today;
     40  char *dir;
    3941
    4042  argcsave=argc;
     
    123125    init_pair(OWL_COLOR_WHITE,   COLOR_WHITE,   -1);
    124126  }
     127
    125128   
    126129  /* owl init */
     
    128131  if (debug) owl_global_set_debug_on(&g);
    129132  owl_global_set_startupargs(&g, argcsave, argvsave);
    130   owl_context_set_readconfig(owl_global_get_context(&g));
     133
     134  /* create the owl directory, in case it does not exist */
     135  dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR);
     136  mkdir(dir, S_IRWXU);
     137  owl_free(dir);
    131138
    132139  /* set the tty, either from the command line, or by figuring it out */
     
    138145
    139146  /* setup the default filters */
    140 
    141147  /* the personal filter will need to change again when AIM chat's are
    142148   *  included.  Also, there should be an %aimme% */
     
    191197  owl_view_create(owl_global_get_current_view(&g), f);
    192198
     199  /* process the startup file */
     200  owl_function_execstartup();
     201
     202
    193203  /* read the config file */
     204  owl_context_set_readconfig(owl_global_get_context(&g));
    194205  ret=owl_readconfig(configfile);
    195206  if (ret) {
  • owl.h

    raa5f725 r38cf544c  
    1919#define OWL_DEBUG 0
    2020#define OWL_DEBUG_FILE "/var/tmp/owldebug"
     21
     22#define OWL_CONFIG_DIR "/.owl"           /* this is relative to the user's home directory */
     23#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
    2124
    2225#define OWL_FMTEXT_ATTR_NONE      0
  • owl_prototypes.h

    rfd93b41 r38cf544c  
    6161extern char *owl_command_addbuddy(int argc, char **argv, char *buff);
    6262extern char *owl_command_delbuddy(int argc, char **argv, char *buff);
     63extern char *owl_command_startup(int argc, char **argv, char *buff);
     64extern char *owl_command_unstartup(int argc, char **argv, char *buff);
    6365extern char *owl_command_dump(int argc, char **argv, char *buff);
    6466extern char *owl_command_next(int argc, char **argv, char *buff);
     
    395397extern void owl_function_xterm_raise(void);
    396398extern void owl_function_xterm_deiconify(void);
     399extern void owl_function_addstartup(char *buff);
     400extern void owl_function_delstartup(char *buff);
     401extern void owl_function_execstartup(void);
    397402
    398403/* -------------------------------- global.c -------------------------------- */
     
    740745extern void owl_hack_animate();
    741746extern char *owl_util_stripnewlines(char *in);
     747extern void owl_util_file_deleteline(char *filename, char *line, int backup);
    742748extern int owl_util_regtest(void);
    743749
  • util.c

    r7c8060d0 r38cf544c  
    648648}
    649649
     650/* Delete the line matching "line" from the named file.  If no such
     651 * line is found the file is left intact.  If backup==1 then create a
     652 * backupfile containing the original contents.  This is an
     653 * inefficient impelementation which reads the entire file into
     654 * memory.
     655 */
     656void owl_util_file_deleteline(char *filename, char *line, int backup)
     657{
     658  char buff[LINE], *text;
     659  char *backupfilename;
     660  FILE *file, *backupfile;
     661  int size, newline;
     662
     663  /* open the file for reading */
     664  file=fopen(filename, "r");
     665  if (!file) {
     666    owl_function_makemsg("Error opening file %s", filename);
     667    return;
     668  }
     669 
     670  /* open the backup file for writing */
     671  if (backup) {
     672    backupfilename=owl_sprintf("%s.backup", filename);
     673    backupfile=fopen(backupfilename, "w");
     674    owl_free(backupfilename);
     675    if (!backupfile) {
     676      owl_function_makemsg("Error opening file %s for writing", backupfilename);
     677      return;
     678    }
     679  }
     680
     681  /* we'll read the entire file into memory, minus the line we don't want and
     682   * and at the same time create the backup file if necessary
     683   */
     684  text=owl_malloc(LINE);
     685  strcpy(text, "");
     686  size=LINE;
     687  while (fgets(buff, LINE, file)!=NULL) {
     688    /* strip the newline */
     689    newline=0;
     690    if (buff[strlen(buff)-1]=='\n') {
     691      buff[strlen(buff)-1]='\0';
     692      newline=1;
     693    }
     694   
     695    /* if we don't match the line, add to saved text in memory */
     696    if (strcasecmp(buff, line)) {
     697      size+=LINE;
     698      text=owl_realloc(text, size);
     699      strcat(text, buff);
     700      if (newline) strcat(text, "\n");
     701    }
     702
     703    /* write to backupfile if necessary */
     704    if (backup) fputs(buff, backupfile);
     705  }
     706  fclose(backupfile);
     707  fclose(file);
     708
     709  /* now rewrite the original file from memory */
     710  file=fopen(filename, "w");
     711  if (!file) {
     712    owl_function_makemsg("WARNING: Error opening %s for writing.  Use %s to restore.", filename, backupfilename);
     713    owl_function_beep();
     714    owl_free(line);
     715    return;
     716  }
     717
     718  fputs(text, file);
     719  fclose(file);
     720}
     721
    650722/**************************************************************************/
    651723/************************* REGRESSION TESTS *******************************/
Note: See TracChangeset for help on using the changeset viewer.