version 1.21, 2012/07/10 11:53:01 |
version 1.22, 2012/07/11 07:10:15 |
|
|
* Loads a paste buffer from a file. |
* Loads a paste buffer from a file. |
*/ |
*/ |
|
|
int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *); |
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *); |
void cmd_load_buffer_callback(struct client *, int, void *); |
void cmd_load_buffer_callback(struct client *, int, void *); |
|
|
const struct cmd_entry cmd_load_buffer_entry = { |
const struct cmd_entry cmd_load_buffer_entry = { |
"load-buffer", "loadb", |
"load-buffer", "loadb", |
|
|
cmd_load_buffer_exec |
cmd_load_buffer_exec |
}; |
}; |
|
|
int |
enum cmd_retval |
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) |
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
|
|
if (cause != NULL) { |
if (cause != NULL) { |
ctx->error(ctx, "buffer %s", cause); |
ctx->error(ctx, "buffer %s", cause); |
free(cause); |
free(cause); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
} |
} |
|
|
|
|
if (error != 0) { |
if (error != 0) { |
ctx->error(ctx, "%s: %s", path, cause); |
ctx->error(ctx, "%s: %s", path, cause); |
free(cause); |
free(cause); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
return (1); |
return (CMD_RETURN_YIELD); |
} |
} |
|
|
if (c != NULL) |
if (c != NULL) |
|
|
} |
} |
if ((f = fopen(path, "rb")) == NULL) { |
if ((f = fopen(path, "rb")) == NULL) { |
ctx->error(ctx, "%s: %s", path, strerror(errno)); |
ctx->error(ctx, "%s: %s", path, strerror(errno)); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
pdata = NULL; |
pdata = NULL; |
|
|
limit = options_get_number(&global_options, "buffer-limit"); |
limit = options_get_number(&global_options, "buffer-limit"); |
if (buffer == -1) { |
if (buffer == -1) { |
paste_add(&global_buffers, pdata, psize, limit); |
paste_add(&global_buffers, pdata, psize, limit); |
return (0); |
return (CMD_RETURN_NORMAL); |
} |
} |
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { |
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { |
ctx->error(ctx, "no buffer %d", buffer); |
ctx->error(ctx, "no buffer %d", buffer); |
free(pdata); |
free(pdata); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
return (0); |
return (CMD_RETURN_NORMAL); |
|
|
error: |
error: |
free(pdata); |
free(pdata); |
if (f != NULL) |
if (f != NULL) |
fclose(f); |
fclose(f); |
return (-1); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
void |
void |