Ejemplo n.º 1
0
TNC_Result TNC_TNCS_ReportMessageTypesLong(
/*in*/  TNC_IMVID imvID,
/*in*/  TNC_VendorIDList supportedVendorIDs,
/*in*/  TNC_MessageSubtypeList supportedSubtypes,
/*in*/  TNC_UInt32 typeCount)
{
    unsigned i;

    if( typeCount > g_nImvMessageLongSubtypesCount )
	{
		g_pImvMessageLongSubtypes = (TNC_MessageSubtypeList) realloc( g_pImvMessageLongSubtypes, sizeof( *supportedSubtypes ) * typeCount );
		g_pImvVendorIDs = (TNC_VendorIDList) realloc( g_pImvVendorIDs, sizeof(TNC_VendorID) * typeCount );
	}

    outfmt( OUT_LEVEL_NORMAL, "< TNC_TNCS_ReportMessageTypesLong (IMV %d)", imvID );
    if( typeCount > 0 )
    {
        memcpy( g_pImvMessageLongSubtypes, supportedSubtypes, sizeof( *supportedSubtypes ) * typeCount );
		memcpy( g_pImvVendorIDs, supportedVendorIDs, sizeof( *supportedVendorIDs ) * typeCount );
        g_nImvMessageLongSubtypesCount = typeCount;

        for( i=0; i < typeCount; ++i )
			outfmt( OUT_LEVEL_NORMAL, "%c(vendor ID %#x, message subtype %#x)%c", 
                0 == i ? '\n' : ' ', 
				g_pImvVendorIDs[i],
                g_pImvMessageLongSubtypes[i], 
                i == typeCount - 1 ? '\n' : ',' );
    }
    else
	{
        outfmt( OUT_LEVEL_NORMAL, "\nEmpty message list. No messages will be delivered to this IMV!\n" );
	}

    return TNC_RESULT_SUCCESS;
}
Ejemplo n.º 2
0
TNC_Result TNC_TNCS_SendMessageLong(
/*in*/  TNC_IMVID imvID,
/*in*/  TNC_ConnectionID connectionID,
/*in*/  TNC_UInt32 messageFlags,
/*in*/  TNC_BufferReference message,
/*in*/  TNC_UInt32 messageLength,
/*in*/  TNC_VendorID messageVendorID,
/*in*/  TNC_MessageSubtype messageSubtype,
/*in*/  TNC_UInt32 destinationIMCID)
{
	MESSAGE_LONG  longTypeMessage;

    outfmt( OUT_LEVEL_NORMAL, "< TNC_TNCS_SendMessageLong: IMV %d, CID %d, "
		"msg length %d, vendor ID %#x msg subtype %#x, msg flags %#x, destIMCID %#x\n", 
        imvID, connectionID, messageLength, messageVendorID, 
		messageSubtype, messageFlags, destinationIMCID );

    outfmt( OUT_LEVEL_VERBOSE, "< IMC message data:\n" );
    outmessage( OUT_LEVEL_VERBOSE, message, messageLength );

	longTypeMessage.imcID = destinationIMCID;
	longTypeMessage.imvID = imvID;
	longTypeMessage.message = message;
	longTypeMessage.messageFlags = messageFlags;
	longTypeMessage.messageLength = messageLength;
	longTypeMessage.messageSubtype = messageSubtype;
	longTypeMessage.messageVendorID = messageVendorID;

    QueueAddMessageLong( &longTypeMessage );

    return TNC_RESULT_SUCCESS;
}
Ejemplo n.º 3
0
static void
exvwarning(int sv_errno, const char *msg, va_list ap)
{
	/* Partially emulate line buffered output so that:
	 *	printf '%d\n' 1 a 2
	 * and
	 *	printf '%d %d %d\n' 1 a 2
	 * both generate sensible text when stdout and stderr are merged.
	 */
	if (output.nextc != output.buf && output.nextc[-1] == '\n')
		flushout(&output);
	if (commandname)
		outfmt(&errout, "%s: ", commandname);
	else
		outfmt(&errout, "%s: ", getprogname());
	if (msg != NULL) {
		doformat(&errout, msg, ap);
		if (sv_errno >= 0)
			outfmt(&errout, ": ");
	}
	if (sv_errno >= 0)
		outfmt(&errout, "%s", strerror(sv_errno));
	out2c('\n');
	flushout(&errout);
}
Ejemplo n.º 4
0
STATIC void
synerror(char *msg)
{
	if (commandname)
		outfmt(&errout, "%s: %d: ", commandname, startlinno);
	outfmt(&errout, "Syntax error: %s\n", msg);
	error((char *)NULL);
}
Ejemplo n.º 5
0
void
setterm(const char *term)
{
	if (el != NULL && term != NULL)
		if (el_set(el, EL_TERMINAL, term) != 0) {
			outfmt(out2, "sh: Can't set terminal type %s\n", term);
			outfmt(out2, "sh: Using dumb terminal settings.\n");
		}
}
Ejemplo n.º 6
0
Archivo: error.c Proyecto: 0mp/freebsd
static void
vwarning(const char *msg, va_list ap)
{
	if (commandname)
		outfmt(out2, "%s: ", commandname);
	else if (arg0)
		outfmt(out2, "%s: ", arg0);
	doformat(out2, msg, ap);
	out2fmt_flush("\n");
}
Ejemplo n.º 7
0
unsigned ImvBatchEnding( TNC_ConnectionID cid )
{
    TNC_Result rc = TNC_RESULT_SUCCESS;

    if( NULL != imvFuncs.pfnBatchEnding )
    {
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_BatchEnding (IMV: %d, CID: %d)\n", IMV_ID, cid );
        rc = imvFuncs.pfnBatchEnding( IMV_ID, cid );
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_BatchEnding result: %d\n", rc );
    }

    return rc;
}
Ejemplo n.º 8
0
int LoadIMV(const char *dllPath)
{
    int err;

	outfmt( OUT_LEVEL_NORMAL, "Loading IMV DLL: \"%s\"...", dllPath );
    err = LoadImvDLL( dllPath, &imvFuncs );
    if (err) 
    {
        outfmt( OUT_LEVEL_NORMAL, " Error %d.\n", err);
        return TNC_RESULT_OTHER;
    }

    outfmt( OUT_LEVEL_NORMAL, " Ok\n" );
    return TNC_RESULT_SUCCESS;
}
Ejemplo n.º 9
0
unsigned NotifyImvConnectionState( TNC_ConnectionID cid, TNC_ConnectionState state )
{
    TNC_Result rc = TNC_RESULT_SUCCESS;
    extern char *g_pszConnStates[];

    if( NULL != imvFuncs.pfnNotifyConnectionChange )
    {
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_NotifyConnectionChange (IMV: %d, CID: %d, state: `%s')\n", 
            IMV_ID, cid, g_pszConnStates[ state ] );

        rc = imvFuncs.pfnNotifyConnectionChange( IMV_ID, cid, state );
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_NotifyConnectionChange result: %d\n", rc );
    }

    return rc;
}
Ejemplo n.º 10
0
static int
subevalvar_misc(char *p, const char *var, int subtype, int startloc,
  int varflags)
{
	char *startp;
	struct nodelist *saveargbackq = argbackq;
	int amount;

	argstr(p, EXP_TILDE, NULL);
	STACKSTRNUL(expdest);
	argbackq = saveargbackq;
	startp = stackblock() + startloc;

	switch (subtype) {
	case VSASSIGN:
		setvar(var, startp, 0);
		amount = startp - expdest;
		STADJUST(amount, expdest);
		return 1;

	case VSQUESTION:
		if (*p != CTLENDVAR) {
			outfmt(out2, "%s\n", startp);
			error((char *)NULL);
		}
		error("%.*s: parameter %snot set", (int)(p - var - 1),
		      var, (varflags & VSNUL) ? "null or " : "");
		return 0;

	default:
		abort();
	}
}
Ejemplo n.º 11
0
std::vector<std::basic_string<charT> >
gather_month_strings(const std::locale& locale, bool short_strings=true)
{
  typedef std::basic_string<charT> string_type;
  typedef std::vector<string_type> collection_type;
  typedef std::basic_ostringstream<charT> ostream_type;
  typedef std::ostreambuf_iterator<charT> ostream_iter_type;
  typedef std::basic_ostringstream<charT> stringstream_type;
  typedef std::time_put<charT>           time_put_facet_type;
  charT short_fmt[3] = { '%', 'b' };
  charT long_fmt[3]  = { '%', 'B' };
  collection_type months;
  string_type outfmt(short_fmt);
  if (!short_strings) {
    outfmt = long_fmt;
  }
  {
    //grab the needed strings by using the locale to
    //output each month
    for (int m=0; m < 12; m++) {
      tm tm_value;
      tm_value.tm_mon = m;
      stringstream_type ss;
      ostream_iter_type oitr(ss);
      std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
                                                      &tm_value,
                                                      &*outfmt.begin(),
                                                      &*outfmt.begin()+outfmt.size());
      months.push_back(ss.str());
    }
  }
  return months;
}
Ejemplo n.º 12
0
/*
 * TODO - sort output
 */
int
aliascmd(int argc, char **argv)
{
	char *n, *v;
	int ret = 0;
	struct alias *ap;

	if (argc == 1) {
		int i;

		for (i = 0; i < ATABSIZE; i++)
			for (ap = atab[i]; ap; ap = ap->next) {
				printalias(ap);
			}
		return (0);
	}
	while ((n = *++argv) != NULL) {
		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
			if ((ap = *__lookupalias(n)) == NULL) {
				outfmt(out2, "%s: %s not found\n", "alias", n);
				ret = 1;
			} else
				printalias(ap);
		} else {
			*v++ = '\0';
			setalias(n, v);
		}
	}

	return (ret);
}
Ejemplo n.º 13
0
int
aliascmd(int argc, char **argv)
{
	char *n, *v;
	int ret = 0;
	struct alias *ap;

	if (argc == 1) {
		printaliases();
		return (0);
	}
	while ((n = *++argv) != NULL) {
		if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */
			if ((ap = lookupalias(n, 0)) == NULL) {
				outfmt(out2, "alias: %s not found\n", n);
				ret = 1;
			} else
				printalias(ap);
		else {
			*v++ = '\0';
			setalias(n, v);
		}
	}

	return (ret);
}
Ejemplo n.º 14
0
void
chkmail(void)
{
	const char *mpath;
	char *p;
	char *q;
	time_t *mtp;
	struct stackmark smark;
#ifdef WINDOWS
	struct stat statb;
#else
	struct stat64 statb;
#endif

	setstackmark(&smark);
	mpath = mpathset() ? mpathval() : mailval();
	for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) {
		p = padvance(&mpath, nullstr);
		if (p == NULL)
			break;
		if (*p == '\0')
			continue;
		for (q = p ; *q ; q++);
#ifdef DEBUG
		if (q[-1] != '/')
			abort();
#endif
		q[-1] = '\0';			/* delete trailing '/' */
#ifdef WINDOWS
		if (stat(p, &statb) < 0) {
#else
		if (stat64(p, &statb) < 0) {
#endif
			*mtp = 0;
			continue;
		}
		if (!changed && statb.st_mtime != *mtp) {
			outfmt(
				&errout, snlfmt,
				pathopt ? pathopt : "you have mail"
			);
		}
		*mtp = statb.st_mtime;
	}
	changed = 0;
	popstackmark(&smark);
}


void
changemail(const char *val)
{
	changed++;
}
Ejemplo n.º 15
0
String *jnl_readprompt (const char *prompt)

{
  char *buff, header[16], *p;
  String *string;
  uLong strln;

  /* If recovery file open, read from it, otherwise read from terminal */

  if (recover_file == NULL) goto readterminal;
  if (fgets (header, sizeof header, recover_file) == NULL) goto closerecovery;
  if (header[0] != '*') goto badrecovery;
  if (strcmp (header + 1, "EOF\n") == 0) {
    string = NULL;
    goto writejournal;
  }
  strln = strtoul (header + 1, &p, 10);
  if (*p != '\n') goto badrecovery;
  buff = malloc (strln + 1);
  if (fread (buff, strln, 1, recover_file) == 0) goto closerecovery;
  string = string_create (strln, buff);
  buff[strln] = 0;
  outfmt (strlen (prompt) + strlen (buff), "%s%s\n", prompt, buff);
  free (buff);
  goto writejournal;

badrecovery:
  outerr (strlen (header), "bad recovery file format at %s\n", header);
closerecovery:
  fclose (recover_file);
  recover_file = NULL;

  /* Read from terminal screen after flushing any output */

readterminal:
  output ();
  string = os_readprompt (prompt);

  /* Write journal record */

writejournal:
  if (journal_file != NULL) {
    if (string == NULL) fprintf (journal_file, "*EOF\n");
    else {
      strln = string_getlen (string);
      fprintf (journal_file, "*%u\n", strln);
      fwrite (string_getval (string), strln, 1, journal_file);
    }
  }

  /* Return pointer to string (NULL for eof) */

  return (string);
}
Ejemplo n.º 16
0
TNC_Result TNC_TNCS_SendMessageSOH(
/*in*/  TNC_IMVID imvID,
/*in*/  TNC_ConnectionID connectionID,
/*in*/  TNC_BufferReference sohReportEntry,
/*in*/  TNC_UInt32 sohRELength)
{
	MESSAGE_SOH  sohMessage;

    outfmt( OUT_LEVEL_NORMAL, "< TNC_TNCS_SendMessageSOH: IMV %d, CID %d, msg length %d\n", 
        imvID, connectionID, sohRELength );

    outfmt( OUT_LEVEL_VERBOSE, "< IMV message data:\n" );
    outmessage( OUT_LEVEL_VERBOSE, sohReportEntry, sohRELength );

	sohMessage.sohReportEntry = sohReportEntry;
	sohMessage.sohRELength = sohRELength;

    QueueAddMessageSOH( &sohMessage );

    return TNC_RESULT_SUCCESS;
}
Ejemplo n.º 17
0
void cmd_delete (char *cp)

{

  first = 1;
  count = 0;
  if (range_multiple (cp, &cp, delete_range, &first) >= 0) eoltest (cp);
  if (count == 0) outerr (0, "no lines deleted\n");
  else outerr (12, "%u line%s deleted\n", count, (count == 1) ? "" : "s");
  if (cur_position.line != NULL) line_print (cur_position.line);
  else outfmt (strlen (buffer_name (cur_position.buffer)), "[EOB=%s]\n", buffer_name (cur_position.buffer));
}
Ejemplo n.º 18
0
Archivo: trap.c Proyecto: alimon/dash
int
trapcmd(int argc, char **argv)
{
    char *action;
    char **ap;
    int signo;

    nextopt(nullstr);
    ap = argptr;
    if (!*ap) {
        for (signo = 0 ; signo < NSIG ; signo++) {
            if (trap[signo] != NULL) {
                out1fmt(
                    "trap -- %s %s\n",
                    single_quote(trap[signo]),
                    signal_names[signo]
                );
            }
        }
        return 0;
    }
    if (!ap[1])
        action = NULL;
    else
        action = *ap++;
    while (*ap) {
        if ((signo = decode_signal(*ap, 0)) < 0) {
            outfmt(out2, "trap: %s: bad trap\n", *ap);
            return 1;
        }
        INTOFF;
        if (action) {
            if (action[0] == '-' && action[1] == '\0')
                action = NULL;
            else {
                if (*action)
                    trapcnt++;
                action = savestr(action);
            }
        }
        if (trap[signo]) {
            if (*trap[signo])
                trapcnt--;
            ckfree(trap[signo]);
        }
        trap[signo] = action;
        if (signo != 0)
            setsignal(signo);
        INTON;
        ap++;
    }
    return 0;
}
Ejemplo n.º 19
0
static void exvwarning2(const char *msg, va_list ap)
{
	struct output *errs;
	const char *name;
	const char *fmt;

	errs = out2;
	name = arg0 ? arg0 : "sh";
	fmt = "%s: %d: ";
	outfmt(errs, fmt, name, errlinno);
	doformat(errs, msg, ap);
	outc('\n', errs);
}
Ejemplo n.º 20
0
void TerminateIMV(void)
{
    TNC_Result result;

    if( NULL != imvFuncs.pfnTerminate )
    {
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_Terminate (IMV %d)\n", IMV_ID );
        result = imvFuncs.pfnTerminate( IMV_ID );
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_Terminate result: %d\n", result );
    }

    free( g_pImvMessageTypes );
    g_pImvMessageTypes = NULL;
    g_nImvMessageTypesCount = 0;

	free( g_pImvMessageLongSubtypes );
	free( g_pImvVendorIDs );
	g_pImvMessageLongSubtypes = NULL;
	g_pImvVendorIDs = NULL;
	g_nImvMessageLongSubtypesCount = 0;

    UnloadImvDLL();
}
Ejemplo n.º 21
0
TNC_Result TNC_TNCS_SendMessage(
/*in*/  TNC_IMVID imvID,
/*in*/  TNC_ConnectionID connectionID,
/*in*/  TNC_BufferReference message,
/*in*/  TNC_UInt32 messageLength,
/*in*/  TNC_MessageType messageType) 
{
	MESSAGE_BASIC  basicMessage;

    outfmt( OUT_LEVEL_NORMAL, "< TNC_TNCS_SendMessage: IMV %d, CID %d, msg length %d, msg type %#x\n", 
        imvID, connectionID, messageLength, messageType );

    outfmt( OUT_LEVEL_VERBOSE, "< IMV message data:\n" );
    outmessage( OUT_LEVEL_VERBOSE, message, messageLength );

	basicMessage.message = message;
	basicMessage.messageLength = messageLength;
	basicMessage.messageType = messageType;

    QueueAddMessage( &basicMessage );

    return TNC_RESULT_OTHER;
}
Ejemplo n.º 22
0
int InitializeIMV(void)
{
    TNC_Result result;
    TNC_Version actualVersion;

    outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_Initialize\n" );
    result = (imvFuncs.pfnInitialize)(IMV_ID, TNC_IFIMV_VERSION_1, TNC_IFIMV_VERSION_1, &actualVersion);
    outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_Initialize result = %d.\n", result);
    if (result != TNC_RESULT_SUCCESS) 
        return TNC_RESULT_OTHER;

    if (imvFuncs.pfnProvideBind != NULL) 
    {
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_ProvideBindFunction\n" );
        result = (imvFuncs.pfnProvideBind)(IMV_ID, &TNC_TNCS_BindFunction);
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_ProvideBindFunction result = %d.\n", result);
        if (result != TNC_RESULT_SUCCESS) 
            return TNC_RESULT_OTHER;
    }

    outfmt( OUT_LEVEL_NORMAL, "IMV initialized successfully\n\n" );
    return result;
}
Ejemplo n.º 23
0
/*
 * Print a list of valid signal names
 */
void
printsignals(struct output *out, int len)
{
	int n;

	if (len != 0)
		outc(' ', out);
	for (n = 1; n < NSIG; n++) {
		outfmt(out, "%s", trap_signame(n));
		if ((n == NSIG/2) ||  n == (NSIG - 1))
			outstr("\n", out);
		else
			outc(' ', out);
	}
}
Ejemplo n.º 24
0
unsigned ImvGetRecommendation( TNC_ConnectionID cid, unsigned *result )
{
    TNC_Result rc;
    static unsigned nRecommendation2ConnState[] = 
    {
        TNC_CONNECTION_STATE_ACCESS_ALLOWED, TNC_CONNECTION_STATE_ACCESS_NONE, 
        TNC_CONNECTION_STATE_ACCESS_ISOLATED, TNC_CONNECTION_STATE_ACCESS_NONE
    };

    if( ! g_bRecommendationProvided )
    {
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_SolicitRecommendation (IMV: %d, CID: %d)\n", IMV_ID, cid );
        rc = imvFuncs.pfnSolicitRecommendation( IMV_ID, cid );
        outfmt( OUT_LEVEL_NORMAL, "> TNC_IMV_SolicitRecommendation result %d\n", rc );

        if( TNC_RESULT_SUCCESS != rc )
            return -1;
    }

    if( NULL != result )
        *result = g_nEvaluation;

    return nRecommendation2ConnState[ g_nRecommendation ];
}
Ejemplo n.º 25
0
int
unaliascmd(int argc, char **argv)
{
	int i;

	while ((i = nextopt("a")) != '\0') {
		if (i == 'a') {
			rmaliases();
			return (0);
		}
	}
	for (i = 0; *argptr; argptr++) {
		if (unalias(*argptr)) {
			outfmt(out2, "%s: %s not found\n", "unalias", *argptr);
			i = 1;
		}
	}

	return (i);
}
Ejemplo n.º 26
0
int
timescmd(int argc, char **argv)
{
	struct tms tms;
	int u, s, cu, cs;
	char us[8], ss[8], cus[8], css[8];

	nextopt("");

	times(&tms);

	u = conv_time(tms.tms_utime, us, sizeof(us));
	s = conv_time(tms.tms_stime, ss, sizeof(ss));
	cu = conv_time(tms.tms_cutime, cus, sizeof(cus));
	cs = conv_time(tms.tms_cstime, css, sizeof(css));

	outfmt(out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n",
		u, us, s, ss, cu, cus, cs, css);

	return 0;
}
Ejemplo n.º 27
0
int
timescmd(shinstance *psh, int argc, char **argv)
{
	shtms tms;
	int u, s, cu, cs;
	char us[8], ss[8], cus[8], css[8];

	nextopt(psh, "");

	sh_times(psh, &tms);

	u = conv_time(tms.tms_utime, us, sizeof(us));
	s = conv_time(tms.tms_stime, ss, sizeof(ss));
	cu = conv_time(tms.tms_cutime, cus, sizeof(cus));
	cs = conv_time(tms.tms_cstime, css, sizeof(css));

	outfmt(psh->out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n",
		u, us, s, ss, cu, cus, cs, css);

	return 0;
}
std::vector<std::basic_string<charT> >
gather_weekday_strings(const std::locale& locale, bool short_strings=true)
{
  typedef std::basic_string<charT> string_type;
  typedef std::vector<string_type> collection_type;
  typedef std::basic_ostringstream<charT> ostream_type;
  typedef std::ostreambuf_iterator<charT> ostream_iter_type;
  typedef std::basic_ostringstream<charT> stringstream_type;
  typedef std::time_put<charT>           time_put_facet_type;
  charT short_fmt[3] = { '%', 'a' };
  charT long_fmt[3]  = { '%', 'A' };

  collection_type weekdays;


  string_type outfmt(short_fmt);
  if (!short_strings) {
    outfmt = long_fmt;
  }
  {
    //grab the needed strings by using the locale to
    //output each month / weekday
    const charT* p_outfmt = outfmt.c_str(), *p_outfmt_end = p_outfmt + outfmt.size();
    tm tm_value;
    memset(&tm_value, 0, sizeof(tm_value));
    for (int i=0; i < 7; i++) {
      tm_value.tm_wday = i;
      stringstream_type ss;
      ostream_iter_type oitr(ss);
      std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
                                                      &tm_value,
                                                      p_outfmt,
                                                      p_outfmt_end);

      weekdays.push_back(ss.str());
    }
  }
  return weekdays;
}
Ejemplo n.º 29
0
static void
exvwarning2(const char *msg, va_list ap)
{
	struct output *errs;
	const char *name;
	const char *fmt;

	errs = out2;
	name = arg0 ?: "sh";
	fmt = "%s: ";
	if (commandname) {
		name = commandname;
		fmt = "%s: %d: ";
	}
	outfmt(errs, fmt, name, startlinno);
	doformat(errs, msg, ap);
#if FLUSHERR
	outc('\n', errs);
#else
	outcslow('\n', errs);
#endif
}
Ejemplo n.º 30
0
/*
 * TODO - sort output
 */
int
aliascmd(int argc, char **argv)
{
	char *n, *v;
	int ret = 0;
	struct alias *ap;

	if (argc == 1) {
		int i;

		for (i = 0; i < ATABSIZE; i++)
			for (ap = atab[i]; ap; ap = ap->next) {
				if (*ap->name != '\0') {
					out1fmt("alias %s=", ap->name);
					print_quoted(ap->val);
					out1c('\n');
				}
			}
		return (0);
	}
	while ((n = *++argv) != NULL) {
		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
			if ((ap = lookupalias(n, 0)) == NULL) {
				outfmt(out2, "alias: %s not found\n", n);
				ret = 1;
			} else {
				out1fmt("alias %s=", n);
				print_quoted(ap->val);
				out1c('\n');
			}
		} else {
			*v++ = '\0';
			setalias(n, v);
		}
	}

	return (ret);
}