list.c
author viric@mandarina
Mon, 05 May 2008 23:14:22 +0200
changeset 216 b4476e12a717
parent 170 dbe96af9e310
child 219 c24a1f5c1715
permissions -rw-r--r--
Moving versions to 0.5.4.1 for debianers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
125
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     1
/*
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     2
    Task Spooler - a task queue system for the unix user
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     3
    Copyright (C) 2007  LluĂ­s Batlle i Rossell
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     4
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     5
    Please find the license in the provided COPYING file.
b60f173b1489 Copyright for list.c
viric@llimona
parents: 122
diff changeset
     6
*/
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
     7
#include <stdio.h>
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
     8
#include <stdlib.h>
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
     9
#include <string.h>
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 125
diff changeset
    10
#include <sys/time.h>
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    11
#include "main.h"
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    12
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    13
char * joblistdump_headers()
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    14
{
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    15
    char * line;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    16
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    17
    line = malloc(600);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
    18
    snprintf(line, 600, "#!/bin/sh\n# - task spooler (ts) job dump\n"
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    19
            "# This file has been created because a SIGTERM killed\n"
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    20
            "# your queue server.\n"
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    21
            "# The finished commands are listed first.\n"
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    22
            "# The commands running or to be run are stored as you would\n"
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    23
            "# probably run them. Take care - some quotes may have got"
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    24
            " broken\n\n");
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    25
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    26
    return line;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    27
}
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    28
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    29
char * joblist_headers()
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    30
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    31
    char * line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    32
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    33
    line = malloc(100);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
    34
    snprintf(line, 100, "%-4s %-10s %-20s %-8s %-14s %s\n",
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    35
            "ID",
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    36
            "State",
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    37
            "Output",
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    38
            "E-Level",
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    39
            "Times(r/u/s)",
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    40
            "Command");
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    41
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    42
    return line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    43
}
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    44
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    45
static int max(int a, int b)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    46
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    47
    if (a > b)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    48
        return a;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    49
    return b;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    50
}
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    51
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    52
static const char * ofilename_shown(const struct Job *p)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    53
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    54
    const char * output_filename;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    55
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
    56
    if (p->state == SKIPPED)
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
    57
    {
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
    58
        output_filename = "(no output)";
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
    59
    } else if (p->store_output)
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    60
    {
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    61
        if (p->state == QUEUED)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    62
        {
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    63
            output_filename = "(file)";
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    64
        } else
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    65
        {
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    66
            if (p->output_filename == 0)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    67
                /* This may happen due to concurrency
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    68
                 * problems */
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    69
                output_filename = "(...)";
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    70
            else
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    71
                output_filename = p->output_filename;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    72
        }
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    73
    } else
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    74
        output_filename = "stdout";
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    75
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
    76
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    77
    return output_filename;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    78
}
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    79
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    80
static char * print_noresult(const struct Job *p)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    81
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    82
    const char * jobstate;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    83
    const char * output_filename;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    84
    int maxlen;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    85
    char * line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    86
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    87
    jobstate = jstate2string(p->state);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    88
    output_filename = ofilename_shown(p);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    89
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    90
    maxlen = 4 + 1 + 10 + 1 + max(20, strlen(output_filename)) + 1 + 8 + 1
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    91
        + 14 + 1 + strlen(p->command) + 20; /* 20 is the margin for errors */
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    92
170
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
    93
    if (p->label)
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
    94
        maxlen += 3 + strlen(p->label);
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
    95
    if (p->depend)
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
    96
        maxlen += 3;
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
    97
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    98
    line = (char *) malloc(maxlen);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
    99
    if (line == NULL)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   100
        error("Malloc for %i failed.\n", maxlen);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   101
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   102
    if (p->label)
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 150
diff changeset
   103
        snprintf(line, maxlen, "%-4i %-10s %-20s %-8s %14s %s[%s]%s\n",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   104
                p->jobid,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   105
                jobstate,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   106
                output_filename,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   107
                "",
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   108
                "",
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   109
		p->depend?"&& ":"",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   110
                p->label,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   111
                p->command);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   112
    else
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 150
diff changeset
   113
        snprintf(line, maxlen, "%-4i %-10s %-20s %-8s %14s %s%s\n",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   114
                p->jobid,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   115
                jobstate,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   116
                output_filename,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   117
                "",
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   118
                "",
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   119
		p->depend?"&& ":"",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   120
                p->command);
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   121
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   122
    return line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   123
}
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   124
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   125
static char * print_result(const struct Job *p)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   126
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   127
    const char * jobstate;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   128
    int maxlen;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   129
    char * line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   130
    const char * output_filename;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   131
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   132
    jobstate = jstate2string(p->state);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   133
    output_filename = ofilename_shown(p);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   134
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   135
    maxlen = 4 + 1 + 10 + 1 + max(20, strlen(output_filename)) + 1 + 8 + 1
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   136
        + 14 + 1 + strlen(p->command) + 20; /* 20 is the margin for errors */
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   137
170
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
   138
    if (p->label)
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
   139
        maxlen += 3 + strlen(p->label);
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
   140
    if (p->depend)
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
   141
        maxlen += 3;
dbe96af9e310 The labels where not considered in size when listing.
lbatlle@npdl268.bpo.hp.com
parents: 156
diff changeset
   142
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   143
    line = (char *) malloc(maxlen);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   144
    if (line == NULL)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   145
        error("Malloc for %i failed.\n", maxlen);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   146
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   147
    if (p->label)
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 150
diff changeset
   148
        snprintf(line, maxlen, "%-4i %-10s %-20s %-8i %0.2f/%0.2f/%0.2f %s[%s]"
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   149
                "%s\n",
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   150
                p->jobid,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   151
                jobstate,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   152
                output_filename,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   153
                p->result.errorlevel,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   154
                p->result.real_ms,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   155
                p->result.user_ms,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   156
                p->result.system_ms,
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   157
		p->depend?"&& ":"",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   158
                p->label,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   159
                p->command);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   160
    else
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 150
diff changeset
   161
        snprintf(line, maxlen, "%-4i %-10s %-20s %-8i %0.2f/%0.2f/%0.2f %s%s\n",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   162
                p->jobid,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   163
                jobstate,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   164
                output_filename,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   165
                p->result.errorlevel,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   166
                p->result.real_ms,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   167
                p->result.user_ms,
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   168
                p->result.system_ms,
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   169
		p->depend?"&& ":"",
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   170
                p->command);
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   171
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   172
    return line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   173
}
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   174
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   175
char * joblist_line(const struct Job *p)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   176
{
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   177
    char * line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   178
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   179
    if (p->state == FINISHED)
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   180
        line = print_result(p);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   181
    else
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   182
        line = print_noresult(p);
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   183
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   184
    return line;
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents:
diff changeset
   185
}
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   186
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   187
char * joblistdump_torun(const struct Job *p)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   188
{
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   189
    int maxlen;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   190
    char * line;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   191
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   192
    maxlen = 10 + strlen(p->command) + 20; /* 20 is the margin for errors */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   193
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   194
    line = (char *) malloc(maxlen);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   195
    if (line == NULL)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   196
        error("Malloc for %i failed.\n", maxlen);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   197
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 146
diff changeset
   198
    snprintf(line, maxlen, "ts %s\n", p->command);
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   199
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   200
    return line;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   201
}